From f0ebb8526844d9299bae1522d33a14c3a798cb79 Mon Sep 17 00:00:00 2001 From: Pierre Pouchin Date: Wed, 27 Nov 2024 11:11:46 +0100 Subject: [PATCH] Refactor BrowserWrapper --- .../fr/igred/omero/client/BrowserWrapper.java | 92 +++++++++++++++---- .../java/fr/igred/omero/client/Client.java | 2 +- .../fr/igred/omero/client/GatewayWrapper.java | 21 +---- 3 files changed, 77 insertions(+), 38 deletions(-) diff --git a/src/main/java/fr/igred/omero/client/BrowserWrapper.java b/src/main/java/fr/igred/omero/client/BrowserWrapper.java index 987158b2..f973bfff 100644 --- a/src/main/java/fr/igred/omero/client/BrowserWrapper.java +++ b/src/main/java/fr/igred/omero/client/BrowserWrapper.java @@ -33,8 +33,10 @@ import fr.igred.omero.screen.ScreenWrapper; import fr.igred.omero.screen.WellWrapper; import omero.RLong; -import omero.gateway.Gateway; +import omero.api.IQueryPrx; import omero.gateway.SecurityContext; +import omero.gateway.facility.BrowseFacility; +import omero.gateway.facility.MetadataFacility; import omero.gateway.model.DatasetData; import omero.gateway.model.FolderData; import omero.gateway.model.ImageData; @@ -67,21 +69,80 @@ /** * Abstract class to browse data on an OMERO server in a given {@link SecurityContext} and wrap DataObjects. */ -public abstract class BrowserWrapper extends GatewayWrapper { +public abstract class BrowserWrapper { /** - * Constructor of the BrowserWrapper class. + * Abstract constructor of the BrowserWrapper class. + */ + protected BrowserWrapper() { + } + + + /** + * Returns the current user. + * + * @return See above. + */ + protected abstract ExperimenterWrapper getUser(); + + /** + * Returns the current {@link SecurityContext}. + * + * @return See above + */ + abstract SecurityContext getCtx(); + + + /** + * Gets the {@link BrowseFacility} used to access the data from OMERO. + * + * @return See above. * - * @param gateway The gateway - * @param ctx The security context - * @param user The user + * @throws ExecutionException A Facility can't be retrieved or instantiated. */ - protected BrowserWrapper(Gateway gateway, SecurityContext ctx, ExperimenterWrapper user) { - super(gateway, ctx, user); + abstract BrowseFacility getBrowseFacility() throws ExecutionException; + + + /** + * Gets the {@link MetadataFacility} used to retrieve annotations from OMERO. + * + * @return See above. + * + * @throws ExecutionException If the MetadataFacility can't be retrieved or instantiated. + */ + abstract MetadataFacility getMetadata() throws ExecutionException; + + + /** + * Finds objects on OMERO through a database query. + * + * @param query The database query. + * + * @return A list of OMERO objects. + * + * @throws ServiceException Cannot connect to OMERO. + * @throws AccessException Cannot access data. + */ + public List findByQuery(String query) + throws ServiceException, AccessException { + return call(getQueryService(), + qs -> qs.findAllByQuery(query, null), + "Query failed: " + query); } + /** + * Returns the {@link IQueryPrx} used to find objects on OMERO. + * + * @return See above. + * + * @throws ServiceException Cannot connect to OMERO. + * @throws AccessException Cannot access data. + */ + abstract IQueryPrx getQueryService() throws ServiceException, AccessException; + + /** * Gets the project with the specified id from OMERO. * @@ -971,9 +1032,8 @@ public List loadFolders(Long... ids) public List getTags() throws AccessException, ServiceException { String klass = TagAnnotation.class.getSimpleName(); - List os = call(getGateway(), - g -> g.getQueryService(getCtx()) - .findAll(klass, null), + List os = call(getQueryService(), + qs -> qs.findAll(klass, null), "Cannot get tags"); return os.stream() .map(TagAnnotation.class::cast) @@ -1016,9 +1076,8 @@ public List getTags(String name) */ public TagAnnotationWrapper getTag(Long id) throws AccessException, ServiceException { - IObject o = call(getGateway(), - g -> g.getQueryService(getCtx()) - .find(TagAnnotation.class.getSimpleName(), id), + IObject o = call(getQueryService(), + qs -> qs.find(TagAnnotation.class.getSimpleName(), id), "Cannot get tag ID: " + id); TagAnnotationData tag; if (o == null) { @@ -1042,9 +1101,8 @@ public TagAnnotationWrapper getTag(Long id) public List getMapAnnotations() throws AccessException, ServiceException { String klass = omero.model.MapAnnotation.class.getSimpleName(); - List os = call(getGateway(), - g -> g.getQueryService(getCtx()) - .findAll(klass, null), + List os = call(getQueryService(), + qs -> qs.findAll(klass, null), "Cannot get map annotations"); return os.stream() .map(omero.model.MapAnnotation.class::cast) diff --git a/src/main/java/fr/igred/omero/client/Client.java b/src/main/java/fr/igred/omero/client/Client.java index 24e7d5f6..aa0e6696 100644 --- a/src/main/java/fr/igred/omero/client/Client.java +++ b/src/main/java/fr/igred/omero/client/Client.java @@ -54,7 +54,7 @@ *

* Allows the user to connect to OMERO and browse through all the data accessible to the user. */ -public class Client extends BrowserWrapper { +public class Client extends GatewayWrapper { /** diff --git a/src/main/java/fr/igred/omero/client/GatewayWrapper.java b/src/main/java/fr/igred/omero/client/GatewayWrapper.java index ca052f60..7aa3e654 100644 --- a/src/main/java/fr/igred/omero/client/GatewayWrapper.java +++ b/src/main/java/fr/igred/omero/client/GatewayWrapper.java @@ -55,7 +55,7 @@ *

* Allows the user to connect to OMERO and browse through all the data accessible to the user. */ -public abstract class GatewayWrapper { +public abstract class GatewayWrapper extends BrowserWrapper { /** Number of requested import stores */ private final AtomicInteger storeUses = new AtomicInteger(0); @@ -427,25 +427,6 @@ public void closeImport() { } - /** - * Finds objects on OMERO through a database query. - * - * @param query The database query. - * - * @return A list of OMERO objects. - * - * @throws ServiceException Cannot connect to OMERO. - * @throws AccessException Cannot access data. - */ - public List findByQuery(String query) - throws ServiceException, AccessException { - return call(gateway, - g -> g.getQueryService(ctx) - .findAllByQuery(query, null), - "Query failed: " + query); - } - - /** * Saves an object on OMERO. *