From ef85f510ee4d9541e3f953b4e4e0449d971a63a8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?R=C3=A9my=20Dornier?= Date: Tue, 16 Jan 2024 15:04:23 +0100 Subject: [PATCH 1/7] fix typos --- src/main/java/fr/igred/omero/repository/ScreenWrapper.java | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) 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. From 63a50b95896c0c4bd7c996efe6be061a32534b2d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?R=C3=A9my=20Dornier?= Date: Tue, 16 Jan 2024 15:11:37 +0100 Subject: [PATCH 2/7] add a method to get the entire list of groups --- src/main/java/fr/igred/omero/Client.java | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/src/main/java/fr/igred/omero/Client.java b/src/main/java/fr/igred/omero/Client.java index 766e1ebf..1de1b53f 100644 --- a/src/main/java/fr/igred/omero/Client.java +++ b/src/main/java/fr/igred/omero/Client.java @@ -371,6 +371,30 @@ public GroupWrapper getGroup(long groupId) return new GroupWrapper(new GroupData(group)); } + /** + * Returns all the groups on the OMERO database (for admins only) + * + * @return The list of groups on OMERO. + * + * @throws ServiceException Cannot connect to OMERO. + * @throws OMEROServerError Server error. + * @throws NoSuchElementException The requested group cannot be found. + */ + public List getGroups() + throws ServiceException, OMEROServerError, AccessException, ExecutionException { + if(getUser().isAdmin(this)) { + List groups = ExceptionHandler.of(getGateway(), + g -> g.getAdminService(getCtx()).lookupGroups()) + .rethrow(ApiUsageException.class, + (m, e) -> new NoSuchElementException(m), + "Groups not found") + .handleServiceOrServer("Cannot retrieve the groups on OMERO") + .get(); + return groups.stream().map(GroupData::new).map(GroupWrapper::new).collect(Collectors.toList()); + }else{ + throw new NoSuchElementException("You don't have admin rights to get the list of all the groups on OMERO"); + } + } /** * Gets the client associated with the username in the parameters. The user calling this function needs to have From 9f0cc68b38ea712ee0e63d1e723543c3773e397e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?R=C3=A9my=20Dornier?= Date: Tue, 16 Jan 2024 15:12:04 +0100 Subject: [PATCH 3/7] fix typo --- src/main/java/fr/igred/omero/Client.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/fr/igred/omero/Client.java b/src/main/java/fr/igred/omero/Client.java index 1de1b53f..cfe46f5b 100644 --- a/src/main/java/fr/igred/omero/Client.java +++ b/src/main/java/fr/igred/omero/Client.java @@ -365,7 +365,7 @@ 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)); From c3bc546a8d36cb998405f9373adcf8bf335f9bd0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?R=C3=A9my=20Dornier?= Date: Tue, 16 Jan 2024 15:14:45 +0100 Subject: [PATCH 4/7] Add exception in java doc2 --- src/main/java/fr/igred/omero/Client.java | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/main/java/fr/igred/omero/Client.java b/src/main/java/fr/igred/omero/Client.java index cfe46f5b..eb2e19f3 100644 --- a/src/main/java/fr/igred/omero/Client.java +++ b/src/main/java/fr/igred/omero/Client.java @@ -378,10 +378,12 @@ public GroupWrapper getGroup(long groupId) * * @throws ServiceException Cannot connect to OMERO. * @throws OMEROServerError Server error. + * @throws AccessException Cannot access data. * @throws NoSuchElementException The requested group cannot be found. + * @throws ExecutionException A Facility can't be retrieved or instantiated. */ public List getGroups() - throws ServiceException, OMEROServerError, AccessException, ExecutionException { + throws ServiceException, OMEROServerError, AccessException, ExecutionException, NoSuchElementException { if(getUser().isAdmin(this)) { List groups = ExceptionHandler.of(getGateway(), g -> g.getAdminService(getCtx()).lookupGroups()) From 5f970f7b8b94d8c4c47f02a767d3564e66a90edd Mon Sep 17 00:00:00 2001 From: Pierre Pouchin Date: Fri, 23 Feb 2024 15:25:07 +0100 Subject: [PATCH 5/7] Remove deprecated exception and admin check --- src/main/java/fr/igred/omero/Client.java | 30 ++++++++++++------------ 1 file changed, 15 insertions(+), 15 deletions(-) diff --git a/src/main/java/fr/igred/omero/Client.java b/src/main/java/fr/igred/omero/Client.java index eb2e19f3..a855a903 100644 --- a/src/main/java/fr/igred/omero/Client.java +++ b/src/main/java/fr/igred/omero/Client.java @@ -371,33 +371,33 @@ public GroupWrapper getGroup(long groupId) return new GroupWrapper(new GroupData(group)); } + /** * Returns all the groups on the OMERO database (for admins only) * * @return The list of groups on OMERO. * * @throws ServiceException Cannot connect to OMERO. - * @throws OMEROServerError Server error. * @throws AccessException Cannot access data. * @throws NoSuchElementException The requested group cannot be found. - * @throws ExecutionException A Facility can't be retrieved or instantiated. */ public List getGroups() - throws ServiceException, OMEROServerError, AccessException, ExecutionException, NoSuchElementException { - if(getUser().isAdmin(this)) { - List groups = ExceptionHandler.of(getGateway(), - g -> g.getAdminService(getCtx()).lookupGroups()) - .rethrow(ApiUsageException.class, - (m, e) -> new NoSuchElementException(m), - "Groups not found") - .handleServiceOrServer("Cannot retrieve the groups on OMERO") - .get(); - return groups.stream().map(GroupData::new).map(GroupWrapper::new).collect(Collectors.toList()); - }else{ - throw new NoSuchElementException("You don't have admin rights to get the list of all the groups on OMERO"); - } + throws ServiceException, AccessException { + String error = "Cannot retrieve the groups on OMERO"; + return ExceptionHandler.of(getGateway(), + g -> g.getAdminService(getCtx()).lookupGroups()) + .rethrow(ApiUsageException.class, + (m, e) -> new NoSuchElementException(m), + "Groups not found") + .handleOMEROException(error) + .get() + .stream() + .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. From 98d1c3326488a355202482c6bae9c3f16276bb14 Mon Sep 17 00:00:00 2001 From: Pierre Pouchin Date: Fri, 23 Feb 2024 15:25:17 +0100 Subject: [PATCH 6/7] Add test --- src/test/java/fr/igred/omero/ClientTest.java | 8 ++++++++ 1 file changed, 8 insertions(+) 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()); + } + } From d5431b105ad14adf7e7e5e90adaf7af00a57d3d4 Mon Sep 17 00:00:00 2001 From: Pierre Pouchin Date: Fri, 23 Feb 2024 22:44:30 +0100 Subject: [PATCH 7/7] Remove redundant exception --- src/main/java/fr/igred/omero/Client.java | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/src/main/java/fr/igred/omero/Client.java b/src/main/java/fr/igred/omero/Client.java index a855a903..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; @@ -373,25 +374,22 @@ public GroupWrapper getGroup(long groupId) /** - * Returns all the groups on the OMERO database (for admins only) + * Returns all the groups on OMERO. * - * @return The list of groups on OMERO. + * @return See above. * * @throws ServiceException Cannot connect to OMERO. * @throws AccessException Cannot access data. - * @throws NoSuchElementException The requested group cannot be found. */ public List getGroups() throws ServiceException, AccessException { String error = "Cannot retrieve the groups on OMERO"; return ExceptionHandler.of(getGateway(), g -> g.getAdminService(getCtx()).lookupGroups()) - .rethrow(ApiUsageException.class, - (m, e) -> new NoSuchElementException(m), - "Groups not found") .handleOMEROException(error) .get() .stream() + .filter(Objects::nonNull) .map(GroupData::new) .map(GroupWrapper::new) .collect(Collectors.toList());