diff --git a/src/main/java/fr/igred/omero/Client.java b/src/main/java/fr/igred/omero/Client.java index 766e1ebf..4e448634 100644 --- a/src/main/java/fr/igred/omero/Client.java +++ b/src/main/java/fr/igred/omero/Client.java @@ -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; @@ -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 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. diff --git a/src/main/java/fr/igred/omero/repository/ScreenWrapper.java b/src/main/java/fr/igred/omero/repository/ScreenWrapper.java index 25c617be..028bcb8a 100644 --- a/src/main/java/fr/igred/omero/repository/ScreenWrapper.java +++ b/src/main/java/fr/igred/omero/repository/ScreenWrapper.java @@ -50,11 +50,11 @@ public class ScreenWrapper extends GenericRepositoryObjectWrapper { /** - * 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. diff --git a/src/test/java/fr/igred/omero/ClientTest.java b/src/test/java/fr/igred/omero/ClientTest.java index 1be2b7c2..f984c577 100644 --- a/src/test/java/fr/igred/omero/ClientTest.java +++ b/src/test/java/fr/igred/omero/ClientTest.java @@ -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; @@ -372,4 +373,11 @@ void testGetAllWellsForUser2() throws Exception { assertEquals(0, wells.size()); } + + @Test + void testGetAllGroups() throws Exception { + List groups = client.getGroups(); + assertEquals(7, groups.size()); + } + }