From 3273cf204024dcbb525d9c77ac53edb84a710d11 Mon Sep 17 00:00:00 2001 From: Pierre Pouchin Date: Wed, 27 Nov 2024 10:59:04 +0100 Subject: [PATCH 1/2] Rename Browser to BrowserWrapper --- src/main/java/fr/igred/omero/RepositoryObjectWrapper.java | 4 ++-- src/main/java/fr/igred/omero/annotations/TagSetWrapper.java | 6 +++--- .../omero/client/{Browser.java => BrowserWrapper.java} | 6 +++--- src/main/java/fr/igred/omero/client/Client.java | 2 +- src/main/java/fr/igred/omero/containers/DatasetWrapper.java | 4 ++-- src/main/java/fr/igred/omero/containers/FolderWrapper.java | 4 ++-- src/main/java/fr/igred/omero/containers/ProjectWrapper.java | 4 ++-- src/main/java/fr/igred/omero/core/ImageWrapper.java | 4 ++-- .../java/fr/igred/omero/screen/PlateAcquisitionWrapper.java | 6 +++--- src/main/java/fr/igred/omero/screen/PlateWrapper.java | 4 ++-- src/main/java/fr/igred/omero/screen/ScreenWrapper.java | 4 ++-- src/main/java/fr/igred/omero/screen/WellSampleWrapper.java | 4 ++-- src/main/java/fr/igred/omero/screen/WellWrapper.java | 4 ++-- 13 files changed, 28 insertions(+), 28 deletions(-) rename src/main/java/fr/igred/omero/client/{Browser.java => BrowserWrapper.java} (99%) diff --git a/src/main/java/fr/igred/omero/RepositoryObjectWrapper.java b/src/main/java/fr/igred/omero/RepositoryObjectWrapper.java index 4e6d3ba9..a5718f6d 100644 --- a/src/main/java/fr/igred/omero/RepositoryObjectWrapper.java +++ b/src/main/java/fr/igred/omero/RepositoryObjectWrapper.java @@ -18,7 +18,7 @@ package fr.igred.omero; -import fr.igred.omero.client.Browser; +import fr.igred.omero.client.BrowserWrapper; import fr.igred.omero.client.Client; import fr.igred.omero.client.GatewayWrapper; import fr.igred.omero.exception.AccessException; @@ -248,7 +248,7 @@ public void copyAnnotationLinks(Client client, RepositoryObjectWrapper object * @throws AccessException Cannot access data. * @throws ExecutionException A Facility can't be retrieved or instantiated. */ - public abstract void reload(Browser browser) + public abstract void reload(BrowserWrapper browser) throws ServiceException, AccessException, ExecutionException; } diff --git a/src/main/java/fr/igred/omero/annotations/TagSetWrapper.java b/src/main/java/fr/igred/omero/annotations/TagSetWrapper.java index 5820012f..2166f63a 100644 --- a/src/main/java/fr/igred/omero/annotations/TagSetWrapper.java +++ b/src/main/java/fr/igred/omero/annotations/TagSetWrapper.java @@ -18,7 +18,7 @@ package fr.igred.omero.annotations; -import fr.igred.omero.client.Browser; +import fr.igred.omero.client.BrowserWrapper; import fr.igred.omero.client.Client; import fr.igred.omero.exception.AccessException; import fr.igred.omero.exception.ServiceException; @@ -87,7 +87,7 @@ public List getTags() { * @throws ServiceException Cannot connect to OMERO. * @throws AccessException Cannot access data. */ - public List getTags(Browser browser) + public List getTags(BrowserWrapper browser) throws AccessException, ServiceException { reload(browser); return getTags(); @@ -139,7 +139,7 @@ public void link(Client dm, TagAnnotationWrapper... tags) * @throws ServiceException Cannot connect to OMERO. * @throws AccessException Cannot access data. */ - public void reload(Browser browser) + public void reload(BrowserWrapper browser) throws ServiceException, AccessException { String query = "select t from TagAnnotation as t" + " left outer join fetch t.annotationLinks as l" + diff --git a/src/main/java/fr/igred/omero/client/Browser.java b/src/main/java/fr/igred/omero/client/BrowserWrapper.java similarity index 99% rename from src/main/java/fr/igred/omero/client/Browser.java rename to src/main/java/fr/igred/omero/client/BrowserWrapper.java index bb201c9e..987158b2 100644 --- a/src/main/java/fr/igred/omero/client/Browser.java +++ b/src/main/java/fr/igred/omero/client/BrowserWrapper.java @@ -67,17 +67,17 @@ /** * Abstract class to browse data on an OMERO server in a given {@link SecurityContext} and wrap DataObjects. */ -public abstract class Browser extends GatewayWrapper { +public abstract class BrowserWrapper extends GatewayWrapper { /** - * Constructor of the Browser class. + * Constructor of the BrowserWrapper class. * * @param gateway The gateway * @param ctx The security context * @param user The user */ - protected Browser(Gateway gateway, SecurityContext ctx, ExperimenterWrapper user) { + protected BrowserWrapper(Gateway gateway, SecurityContext ctx, ExperimenterWrapper user) { super(gateway, ctx, user); } diff --git a/src/main/java/fr/igred/omero/client/Client.java b/src/main/java/fr/igred/omero/client/Client.java index 13135c59..24e7d5f6 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 Browser { +public class Client extends BrowserWrapper { /** diff --git a/src/main/java/fr/igred/omero/containers/DatasetWrapper.java b/src/main/java/fr/igred/omero/containers/DatasetWrapper.java index 11669445..2ded9885 100644 --- a/src/main/java/fr/igred/omero/containers/DatasetWrapper.java +++ b/src/main/java/fr/igred/omero/containers/DatasetWrapper.java @@ -21,7 +21,7 @@ import fr.igred.omero.ObjectWrapper; import fr.igred.omero.RepositoryObjectWrapper; import fr.igred.omero.annotations.TagAnnotationWrapper; -import fr.igred.omero.client.Browser; +import fr.igred.omero.client.BrowserWrapper; import fr.igred.omero.client.Client; import fr.igred.omero.core.ImageWrapper; import fr.igred.omero.exception.AccessException; @@ -599,7 +599,7 @@ public List importAndReplaceImages(Client client, String path) * @throws ExecutionException A Facility can't be retrieved or instantiated. */ @Override - public void reload(Browser browser) + public void reload(BrowserWrapper browser) throws ServiceException, AccessException, ExecutionException { data = call(browser.getBrowseFacility(), bf -> bf.getDatasets(browser.getCtx(), diff --git a/src/main/java/fr/igred/omero/containers/FolderWrapper.java b/src/main/java/fr/igred/omero/containers/FolderWrapper.java index c62d8b6d..bbc9f20e 100644 --- a/src/main/java/fr/igred/omero/containers/FolderWrapper.java +++ b/src/main/java/fr/igred/omero/containers/FolderWrapper.java @@ -20,7 +20,7 @@ import fr.igred.omero.ObjectWrapper; import fr.igred.omero.RepositoryObjectWrapper; -import fr.igred.omero.client.Browser; +import fr.igred.omero.client.BrowserWrapper; import fr.igred.omero.client.Client; import fr.igred.omero.core.ImageWrapper; import fr.igred.omero.exception.AccessException; @@ -494,7 +494,7 @@ public void unlinkROIs(Client client, Collection rois) * @throws ExecutionException A Facility can't be retrieved or instantiated. */ @Override - public void reload(Browser browser) + public void reload(BrowserWrapper browser) throws AccessException, ServiceException, ExecutionException { data = call(browser.getBrowseFacility(), bf -> bf.loadFolders(browser.getCtx(), diff --git a/src/main/java/fr/igred/omero/containers/ProjectWrapper.java b/src/main/java/fr/igred/omero/containers/ProjectWrapper.java index 04ff6363..6a16cf6f 100644 --- a/src/main/java/fr/igred/omero/containers/ProjectWrapper.java +++ b/src/main/java/fr/igred/omero/containers/ProjectWrapper.java @@ -21,7 +21,7 @@ import fr.igred.omero.ObjectWrapper; import fr.igred.omero.RepositoryObjectWrapper; import fr.igred.omero.annotations.TagAnnotationWrapper; -import fr.igred.omero.client.Browser; +import fr.igred.omero.client.BrowserWrapper; import fr.igred.omero.client.Client; import fr.igred.omero.core.ImageWrapper; import fr.igred.omero.exception.AccessException; @@ -432,7 +432,7 @@ public List getImagesWithKeyValuePair(Client client, String key, S * @throws ExecutionException A Facility can't be retrieved or instantiated. */ @Override - public void reload(Browser browser) + public void reload(BrowserWrapper browser) throws ServiceException, AccessException, ExecutionException { data = call(browser.getBrowseFacility(), bf -> bf.getProjects(browser.getCtx(), diff --git a/src/main/java/fr/igred/omero/core/ImageWrapper.java b/src/main/java/fr/igred/omero/core/ImageWrapper.java index 493d4358..d2a7c8c3 100644 --- a/src/main/java/fr/igred/omero/core/ImageWrapper.java +++ b/src/main/java/fr/igred/omero/core/ImageWrapper.java @@ -20,7 +20,7 @@ import fr.igred.omero.ObjectWrapper; import fr.igred.omero.RepositoryObjectWrapper; -import fr.igred.omero.client.Browser; +import fr.igred.omero.client.BrowserWrapper; import fr.igred.omero.client.Client; import fr.igred.omero.containers.DatasetWrapper; import fr.igred.omero.containers.FolderWrapper; @@ -1012,7 +1012,7 @@ public List download(Client client, String path) * @throws ExecutionException A Facility can't be retrieved or instantiated. */ @Override - public void reload(Browser browser) + public void reload(BrowserWrapper browser) throws ServiceException, AccessException, ExecutionException { data = call(browser.getBrowseFacility(), b -> b.getImage(browser.getCtx(), getId()), diff --git a/src/main/java/fr/igred/omero/screen/PlateAcquisitionWrapper.java b/src/main/java/fr/igred/omero/screen/PlateAcquisitionWrapper.java index d9a32f28..9201221b 100644 --- a/src/main/java/fr/igred/omero/screen/PlateAcquisitionWrapper.java +++ b/src/main/java/fr/igred/omero/screen/PlateAcquisitionWrapper.java @@ -19,7 +19,7 @@ import fr.igred.omero.RepositoryObjectWrapper; -import fr.igred.omero.client.Browser; +import fr.igred.omero.client.BrowserWrapper; import fr.igred.omero.client.Client; import fr.igred.omero.core.ImageWrapper; import fr.igred.omero.exception.AccessException; @@ -226,7 +226,7 @@ public List getWellSamples() { * @throws ServiceException Cannot connect to OMERO. * @throws AccessException Cannot access data. */ - public List getWellSamples(Browser browser) + public List getWellSamples(BrowserWrapper browser) throws AccessException, ServiceException { reload(browser); return getWellSamples(); @@ -332,7 +332,7 @@ public int getMaximumFieldCount() { * @throws AccessException Cannot access data. */ @Override - public void reload(Browser browser) + public void reload(BrowserWrapper browser) throws ServiceException, AccessException { String query = "select pa from PlateAcquisition as pa " + " left outer join fetch pa.plate as p" + diff --git a/src/main/java/fr/igred/omero/screen/PlateWrapper.java b/src/main/java/fr/igred/omero/screen/PlateWrapper.java index 2f219251..e63511dc 100644 --- a/src/main/java/fr/igred/omero/screen/PlateWrapper.java +++ b/src/main/java/fr/igred/omero/screen/PlateWrapper.java @@ -20,7 +20,7 @@ import fr.igred.omero.ObjectWrapper; import fr.igred.omero.RepositoryObjectWrapper; -import fr.igred.omero.client.Browser; +import fr.igred.omero.client.BrowserWrapper; import fr.igred.omero.client.Client; import fr.igred.omero.core.ImageWrapper; import fr.igred.omero.exception.AccessException; @@ -332,7 +332,7 @@ public Length getWellOriginY(UnitsLength unit) throws BigResult { * @throws ExecutionException A Facility can't be retrieved or instantiated. */ @Override - public void reload(Browser browser) + public void reload(BrowserWrapper browser) throws ServiceException, AccessException, ExecutionException { data = call(browser.getBrowseFacility(), bf -> bf.getPlates(browser.getCtx(), singletonList(getId())) diff --git a/src/main/java/fr/igred/omero/screen/ScreenWrapper.java b/src/main/java/fr/igred/omero/screen/ScreenWrapper.java index 1400c4dd..47fbb514 100644 --- a/src/main/java/fr/igred/omero/screen/ScreenWrapper.java +++ b/src/main/java/fr/igred/omero/screen/ScreenWrapper.java @@ -19,7 +19,7 @@ import fr.igred.omero.RepositoryObjectWrapper; -import fr.igred.omero.client.Browser; +import fr.igred.omero.client.BrowserWrapper; import fr.igred.omero.client.Client; import fr.igred.omero.client.GatewayWrapper; import fr.igred.omero.core.ImageWrapper; @@ -319,7 +319,7 @@ public void setReagentSetIdentifier(String value) { * @throws ExecutionException A Facility can't be retrieved or instantiated. */ @Override - public void reload(Browser browser) + public void reload(BrowserWrapper browser) throws ServiceException, AccessException, ExecutionException { data = call(browser.getBrowseFacility(), bf -> bf.getScreens(browser.getCtx(), diff --git a/src/main/java/fr/igred/omero/screen/WellSampleWrapper.java b/src/main/java/fr/igred/omero/screen/WellSampleWrapper.java index 5c8e16a0..098e6710 100644 --- a/src/main/java/fr/igred/omero/screen/WellSampleWrapper.java +++ b/src/main/java/fr/igred/omero/screen/WellSampleWrapper.java @@ -19,7 +19,7 @@ import fr.igred.omero.ObjectWrapper; -import fr.igred.omero.client.Browser; +import fr.igred.omero.client.BrowserWrapper; import fr.igred.omero.client.Client; import fr.igred.omero.core.ImageWrapper; import fr.igred.omero.exception.AccessException; @@ -197,7 +197,7 @@ public long getStartTime() { * @throws ServiceException Cannot connect to OMERO. * @throws AccessException Cannot access data. */ - public void reload(Browser browser) + public void reload(BrowserWrapper browser) throws ServiceException, AccessException { String query = "select ws from WellSample as ws" + " left outer join fetch ws.plateAcquisition as pa" + diff --git a/src/main/java/fr/igred/omero/screen/WellWrapper.java b/src/main/java/fr/igred/omero/screen/WellWrapper.java index 647724f4..b1527c4c 100644 --- a/src/main/java/fr/igred/omero/screen/WellWrapper.java +++ b/src/main/java/fr/igred/omero/screen/WellWrapper.java @@ -19,7 +19,7 @@ import fr.igred.omero.RepositoryObjectWrapper; -import fr.igred.omero.client.Browser; +import fr.igred.omero.client.BrowserWrapper; import fr.igred.omero.client.Client; import fr.igred.omero.core.ImageWrapper; import fr.igred.omero.exception.AccessException; @@ -328,7 +328,7 @@ public void setAlpha(Integer alpha) { * @throws ExecutionException A Facility can't be retrieved or instantiated. */ @Override - public void reload(Browser browser) + public void reload(BrowserWrapper browser) throws ServiceException, AccessException, ExecutionException { data = call(browser.getBrowseFacility(), bf -> bf.getWells(browser.getCtx(), From f0ebb8526844d9299bae1522d33a14c3a798cb79 Mon Sep 17 00:00:00 2001 From: Pierre Pouchin Date: Wed, 27 Nov 2024 11:11:46 +0100 Subject: [PATCH 2/2] 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. *