Skip to content

Commit

Permalink
List all groups on OMERO (#78)
Browse files Browse the repository at this point in the history
* Add a method to get the entire list of groups
* Fix typos
* Add test
  • Loading branch information
Rdornier authored Feb 23, 2024
1 parent 0303c4b commit 892500a
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 4 deletions.
26 changes: 25 additions & 1 deletion src/main/java/fr/igred/omero/Client.java
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@
import java.util.List;
import java.util.Map;
import java.util.NoSuchElementException;
import java.util.Objects;
import java.util.concurrent.ExecutionException;
import java.util.stream.Collectors;

Expand Down Expand Up @@ -365,13 +366,36 @@ public GroupWrapper getGroup(long groupId)
ExperimenterGroup group = ExceptionHandler.of(getGateway(), g -> g.getAdminService(getCtx()).getGroup(groupId))
.rethrow(ApiUsageException.class,
(m, e) -> new NoSuchElementException(m),
"User not found: " + groupId)
"Group not found: " + groupId)
.handleServiceOrServer("Cannot retrieve group: " + groupId)
.get();
return new GroupWrapper(new GroupData(group));
}


/**
* Returns all the groups on OMERO.
*
* @return See above.
*
* @throws ServiceException Cannot connect to OMERO.
* @throws AccessException Cannot access data.
*/
public List<GroupWrapper> getGroups()
throws ServiceException, AccessException {
String error = "Cannot retrieve the groups on OMERO";
return ExceptionHandler.of(getGateway(),
g -> g.getAdminService(getCtx()).lookupGroups())
.handleOMEROException(error)
.get()
.stream()
.filter(Objects::nonNull)
.map(GroupData::new)
.map(GroupWrapper::new)
.collect(Collectors.toList());
}


/**
* Gets the client associated with the username in the parameters. The user calling this function needs to have
* administrator rights. All action realized with the client returned will be considered as his.
Expand Down
6 changes: 3 additions & 3 deletions src/main/java/fr/igred/omero/repository/ScreenWrapper.java
Original file line number Diff line number Diff line change
Expand Up @@ -50,11 +50,11 @@ public class ScreenWrapper extends GenericRepositoryObjectWrapper<ScreenData> {


/**
* Constructor of the ProjectWrapper class. Creates a new project and saves it to OMERO.
* Constructor of the ScreenWrapper class. Creates a new screen and saves it to OMERO.
*
* @param client The client handling the connection.
* @param name Project name.
* @param description Project description.
* @param name Screen name.
* @param description Screen description.
*
* @throws ServiceException Cannot connect to OMERO.
* @throws AccessException Cannot access data.
Expand Down
8 changes: 8 additions & 0 deletions src/test/java/fr/igred/omero/ClientTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@


import fr.igred.omero.meta.ExperimenterWrapper;
import fr.igred.omero.meta.GroupWrapper;
import fr.igred.omero.repository.DatasetWrapper;
import fr.igred.omero.repository.ImageWrapper;
import fr.igred.omero.repository.PlateWrapper;
Expand Down Expand Up @@ -372,4 +373,11 @@ void testGetAllWellsForUser2() throws Exception {
assertEquals(0, wells.size());
}


@Test
void testGetAllGroups() throws Exception {
List<GroupWrapper> groups = client.getGroups();
assertEquals(7, groups.size());
}

}

0 comments on commit 892500a

Please sign in to comment.