From c95d937d44ef705adc03e56f38d1ca7fb1df1542 Mon Sep 17 00:00:00 2001 From: Pierre Pouchin Date: Sun, 1 Dec 2024 23:09:44 +0100 Subject: [PATCH] Extract more interfaces --- src/main/java/fr/igred/omero/Annotatable.java | 48 +- .../fr/igred/omero/AnnotatableWrapper.java | 24 +- .../java/fr/igred/omero/ObjectWrapper.java | 4 +- .../java/fr/igred/omero/RemoteObject.java | 4 +- .../java/fr/igred/omero/RepositoryObject.java | 4 +- .../igred/omero/annotations/Annotation.java | 23 +- .../omero/annotations/AnnotationWrapper.java | 23 +- .../omero/annotations/AnnotationsBrowser.java | 118 +++ .../annotations/TagAnnotationWrapper.java | 4 +- .../fr/igred/omero/annotations/TagSet.java | 12 +- .../omero/annotations/TagSetWrapper.java | 8 +- .../fr/igred/omero/client/AdminManager.java | 31 +- .../fr/igred/omero/client/BasicBrowser.java | 76 ++ .../igred/omero/client/BasicDataManager.java | 157 ++++ .../java/fr/igred/omero/client/Browser.java | 818 +----------------- .../fr/igred/omero/client/DataManager.java | 145 +--- .../omero/containers/ContainersBrowser.java | 305 +++++++ .../fr/igred/omero/containers/Dataset.java | 27 +- .../omero/containers/DatasetWrapper.java | 6 +- .../fr/igred/omero/containers/Folder.java | 28 +- .../igred/omero/containers/FolderWrapper.java | 10 +- .../fr/igred/omero/containers/Project.java | 25 +- .../omero/containers/ProjectWrapper.java | 12 +- src/main/java/fr/igred/omero/core/Image.java | 44 +- .../fr/igred/omero/core/ImageBrowser.java | 188 ++++ .../fr/igred/omero/core/ImageWrapper.java | 18 +- src/main/java/fr/igred/omero/core/Pixels.java | 16 +- .../fr/igred/omero/core/PixelsWrapper.java | 16 +- .../java/fr/igred/omero/meta/BasicAdmin.java | 43 + .../fr/igred/omero/meta/Experimenter.java | 3 +- .../igred/omero/meta/ExperimenterWrapper.java | 3 +- src/main/java/fr/igred/omero/roi/ROI.java | 6 +- .../java/fr/igred/omero/roi/ROIWrapper.java | 4 +- src/main/java/fr/igred/omero/roi/Shape.java | 4 +- .../java/fr/igred/omero/screen/Plate.java | 8 +- .../igred/omero/screen/PlateAcquisition.java | 18 +- .../omero/screen/PlateAcquisitionWrapper.java | 4 +- .../fr/igred/omero/screen/PlateWrapper.java | 6 +- .../java/fr/igred/omero/screen/Screen.java | 8 +- .../fr/igred/omero/screen/ScreenBrowser.java | 275 ++++++ .../fr/igred/omero/screen/ScreenWrapper.java | 8 +- src/main/java/fr/igred/omero/screen/Well.java | 5 +- .../fr/igred/omero/screen/WellSample.java | 12 +- .../igred/omero/screen/WellSampleWrapper.java | 4 +- .../fr/igred/omero/screen/WellWrapper.java | 4 +- .../omero/annotations/ImageJTableTest.java | 4 +- 46 files changed, 1408 insertions(+), 1205 deletions(-) create mode 100644 src/main/java/fr/igred/omero/annotations/AnnotationsBrowser.java create mode 100644 src/main/java/fr/igred/omero/client/BasicBrowser.java create mode 100644 src/main/java/fr/igred/omero/client/BasicDataManager.java create mode 100644 src/main/java/fr/igred/omero/containers/ContainersBrowser.java create mode 100644 src/main/java/fr/igred/omero/core/ImageBrowser.java create mode 100644 src/main/java/fr/igred/omero/meta/BasicAdmin.java create mode 100644 src/main/java/fr/igred/omero/screen/ScreenBrowser.java diff --git a/src/main/java/fr/igred/omero/Annotatable.java b/src/main/java/fr/igred/omero/Annotatable.java index 4e528202..ed725bac 100644 --- a/src/main/java/fr/igred/omero/Annotatable.java +++ b/src/main/java/fr/igred/omero/Annotatable.java @@ -24,9 +24,9 @@ import fr.igred.omero.annotations.RatingAnnotation; import fr.igred.omero.annotations.TableWrapper; import fr.igred.omero.annotations.TagAnnotation; -import fr.igred.omero.client.Browser; +import fr.igred.omero.client.BasicBrowser; +import fr.igred.omero.client.BasicDataManager; import fr.igred.omero.client.Client; -import fr.igred.omero.client.DataManager; import fr.igred.omero.exception.AccessException; import fr.igred.omero.exception.ServiceException; import fr.igred.omero.util.ReplacePolicy; @@ -68,7 +68,7 @@ public interface Annotatable extends RemoteObject { * @throws AccessException Cannot access data. * @throws ExecutionException A Facility can't be retrieved or instantiated. */ - default boolean isLinked(Browser browser, A annotation) + default boolean isLinked(BasicBrowser browser, A annotation) throws ServiceException, AccessException, ExecutionException { return getAnnotations(browser).stream().anyMatch(a -> a.getId() == annotation.getId()); } @@ -85,7 +85,7 @@ default boolean isLinked(Browser browser, A annotation) * @throws AccessException Cannot access data. * @throws ExecutionException A Facility can't be retrieved or instantiated. */ - default void link(DataManager dm, A annotation) + default void link(BasicDataManager dm, A annotation) throws ServiceException, AccessException, ExecutionException { String error = String.format("Cannot add %s to %s", annotation, this); call(dm.getDMFacility(), @@ -105,7 +105,7 @@ default void link(DataManager dm, A annotation) * @throws AccessException Cannot access data. * @throws ExecutionException A Facility can't be retrieved or instantiated. */ - default void link(DataManager dm, A annotation) + default void link(BasicDataManager dm, A annotation) throws ServiceException, AccessException, ExecutionException { if (!(annotation instanceof TagAnnotation) || !((TagAnnotation) annotation).isTagSet()) { link(dm, annotation.asDataObject()); @@ -126,7 +126,7 @@ default void link(DataManager dm, A annotation) * @throws AccessException Cannot access data. * @throws ExecutionException A Facility can't be retrieved or instantiated. */ - default void link(DataManager dm, Annotation... annotations) + default void link(BasicDataManager dm, Annotation... annotations) throws ServiceException, AccessException, ExecutionException { for (Annotation annotation : annotations) { link(dm, annotation); @@ -166,7 +166,7 @@ default void linkIfNotLinked(Client client, Annotation... annotations) * @throws AccessException Cannot access data. * @throws ExecutionException A Facility can't be retrieved or instantiated. */ - void addTag(DataManager dm, String name, String description) + void addTag(BasicDataManager dm, String name, String description) throws ServiceException, AccessException, ExecutionException; @@ -180,7 +180,7 @@ void addTag(DataManager dm, String name, String description) * @throws AccessException Cannot access data. * @throws ExecutionException A Facility can't be retrieved or instantiated. */ - void addTag(DataManager dm, Long id) + void addTag(BasicDataManager dm, Long id) throws ServiceException, AccessException, ExecutionException; @@ -194,7 +194,7 @@ void addTag(DataManager dm, Long id) * @throws AccessException Cannot access data. * @throws ExecutionException A Facility can't be retrieved or instantiated. */ - default void addTags(DataManager dm, Long... ids) + default void addTags(BasicDataManager dm, Long... ids) throws ServiceException, AccessException, ExecutionException { for (Long id : ids) { addTag(dm, id); @@ -213,7 +213,7 @@ default void addTags(DataManager dm, Long... ids) * @throws AccessException Cannot access data. * @throws ExecutionException A Facility can't be retrieved or instantiated. */ - List getTags(Browser browser) + List getTags(BasicBrowser browser) throws ServiceException, AccessException, ExecutionException; @@ -228,7 +228,7 @@ List getTags(Browser browser) * @throws AccessException Cannot access data. * @throws ExecutionException A Facility can't be retrieved or instantiated. */ - List getMapAnnotations(Browser browser) + List getMapAnnotations(BasicBrowser browser) throws ServiceException, AccessException, ExecutionException; @@ -243,7 +243,7 @@ List getMapAnnotations(Browser browser) * @throws AccessException Cannot access data. * @throws ExecutionException A Facility can't be retrieved or instantiated. */ - void addKeyValuePair(DataManager dm, String key, String value) + void addKeyValuePair(BasicDataManager dm, String key, String value) throws ServiceException, AccessException, ExecutionException; @@ -258,7 +258,7 @@ void addKeyValuePair(DataManager dm, String key, String value) * @throws AccessException Cannot access data. * @throws ExecutionException A Facility can't be retrieved or instantiated. */ - default List> getKeyValuePairs(Browser browser) + default List> getKeyValuePairs(BasicBrowser browser) throws ServiceException, AccessException, ExecutionException { return getMapAnnotations(browser).stream() .map(MapAnnotation::getContent) @@ -280,7 +280,7 @@ default List> getKeyValuePairs(Browser browser) * @throws NoSuchElementException Key not found. * @throws ExecutionException A Facility can't be retrieved or instantiated. */ - default List getValues(Browser browser, String key) + default List getValues(BasicBrowser browser, String key) throws ServiceException, AccessException, ExecutionException { return getMapAnnotations(browser).stream() .map(MapAnnotation::getContentAsMap) @@ -303,7 +303,7 @@ default List getValues(Browser browser, String key) * @throws AccessException Cannot access data. * @throws ExecutionException A Facility can't be retrieved or instantiated. */ - List getRatings(Browser browser, List userIds) + List getRatings(BasicBrowser browser, List userIds) throws ServiceException, AccessException, ExecutionException; @@ -318,7 +318,7 @@ List getRatings(Browser browser, List userIds) * @throws AccessException Cannot access data. * @throws ExecutionException A Facility can't be retrieved or instantiated. */ - default List getRatings(Browser browser) + default List getRatings(BasicBrowser browser) throws ServiceException, AccessException, ExecutionException { return getRatings(browser, null); } @@ -351,7 +351,7 @@ void rate(Client client, int rating) * @throws AccessException Cannot access data. * @throws ExecutionException A Facility can't be retrieved or instantiated. */ - int getMyRating(Browser browser) + int getMyRating(BasicBrowser browser) throws ServiceException, AccessException, ExecutionException; @@ -365,7 +365,7 @@ int getMyRating(Browser browser) * @throws AccessException Cannot access data. * @throws ExecutionException A Facility can't be retrieved or instantiated. */ - default void addTable(DataManager dm, TableWrapper table) + default void addTable(BasicDataManager dm, TableWrapper table) throws ServiceException, AccessException, ExecutionException { String error = "Cannot add table to " + this; @@ -439,7 +439,7 @@ default void addAndReplaceTable(Client client, TableWrapper table) * @throws AccessException Cannot access data. * @throws ExecutionException A Facility can't be retrieved or instantiated. */ - TableWrapper getTable(DataManager dm, Long fileId) + TableWrapper getTable(BasicDataManager dm, Long fileId) throws ServiceException, AccessException, ExecutionException; @@ -454,7 +454,7 @@ TableWrapper getTable(DataManager dm, Long fileId) * @throws AccessException Cannot access data. * @throws ExecutionException A Facility can't be retrieved or instantiated. */ - default List getTables(DataManager dm) + default List getTables(BasicDataManager dm) throws ServiceException, AccessException, ExecutionException { Collection tables = call(dm.getTablesFacility(), tf -> tf.getAvailableTables(dm.getCtx(), asDataObject()), @@ -482,7 +482,7 @@ default List getTables(DataManager dm) * @throws ExecutionException A Facility can't be retrieved or instantiated. * @throws InterruptedException The thread was interrupted. */ - default long addFile(DataManager dm, File file) + default long addFile(BasicDataManager dm, File file) throws ExecutionException, InterruptedException { String name = file.getName(); return dm.getDMFacility() @@ -541,7 +541,7 @@ default long addAndReplaceFile(Client client, File file) * @throws AccessException Cannot access data. * @throws ExecutionException A Facility can't be retrieved or instantiated. */ - List getFileAnnotations(Browser browser) + List getFileAnnotations(BasicBrowser browser) throws ExecutionException, ServiceException, AccessException; @@ -588,7 +588,7 @@ void unlink(Client client, Collection annotations) * @throws AccessException Cannot access data. * @throws ExecutionException A Facility can't be retrieved or instantiated. */ - default List getAnnotationData(Browser browser) + default List getAnnotationData(BasicBrowser browser) throws AccessException, ServiceException, ExecutionException { return call(browser.getMetadataFacility(), m -> m.getAnnotations(browser.getCtx(), asDataObject()), @@ -607,7 +607,7 @@ default List getAnnotationData(Browser browser) * @throws AccessException Cannot access data. * @throws ExecutionException A Facility can't be retrieved or instantiated. */ - List getAnnotations(Browser browser) + List getAnnotations(BasicBrowser browser) throws AccessException, ServiceException, ExecutionException; diff --git a/src/main/java/fr/igred/omero/AnnotatableWrapper.java b/src/main/java/fr/igred/omero/AnnotatableWrapper.java index 2b5612bb..686f6551 100644 --- a/src/main/java/fr/igred/omero/AnnotatableWrapper.java +++ b/src/main/java/fr/igred/omero/AnnotatableWrapper.java @@ -28,9 +28,9 @@ import fr.igred.omero.annotations.TableWrapper; import fr.igred.omero.annotations.TagAnnotation; import fr.igred.omero.annotations.TagAnnotationWrapper; -import fr.igred.omero.client.Browser; +import fr.igred.omero.client.BasicBrowser; +import fr.igred.omero.client.BasicDataManager; import fr.igred.omero.client.Client; -import fr.igred.omero.client.DataManager; import fr.igred.omero.exception.AccessException; import fr.igred.omero.exception.ServiceException; import fr.igred.omero.util.ReplacePolicy; @@ -96,7 +96,7 @@ protected AnnotatableWrapper(T o) { * @throws ExecutionException A Facility can't be retrieved or instantiated. */ @Override - public void addTag(DataManager dm, String name, String description) + public void addTag(BasicDataManager dm, String name, String description) throws ServiceException, AccessException, ExecutionException { TagAnnotation tag = new TagAnnotationWrapper(new TagAnnotationData(name)); tag.setDescription(description); @@ -115,7 +115,7 @@ public void addTag(DataManager dm, String name, String description) * @throws ExecutionException A Facility can't be retrieved or instantiated. */ @Override - public void addTag(DataManager dm, Long id) + public void addTag(BasicDataManager dm, Long id) throws ServiceException, AccessException, ExecutionException { TagAnnotationI tag = new TagAnnotationI(id, false); TagAnnotationData tagData = new TagAnnotationData(tag); @@ -135,7 +135,7 @@ public void addTag(DataManager dm, Long id) * @throws ExecutionException A Facility can't be retrieved or instantiated. */ @Override - public List getTags(Browser browser) + public List getTags(BasicBrowser browser) throws ServiceException, AccessException, ExecutionException { List> types = singletonList(TagAnnotationData.class); @@ -167,7 +167,7 @@ public List getTags(Browser browser) * @throws ExecutionException A Facility can't be retrieved or instantiated. */ @Override - public List getMapAnnotations(Browser browser) + public List getMapAnnotations(BasicBrowser browser) throws ServiceException, AccessException, ExecutionException { List> types = singletonList(MapAnnotationData.class); List annotations = call(browser.getMetadataFacility(), @@ -199,7 +199,7 @@ public List getMapAnnotations(Browser browser) * @throws ExecutionException A Facility can't be retrieved or instantiated. */ @Override - public void addKeyValuePair(DataManager dm, String key, String value) + public void addKeyValuePair(BasicDataManager dm, String key, String value) throws ServiceException, AccessException, ExecutionException { MapAnnotation pkv = new MapAnnotationWrapper(key, value); link(dm, pkv); @@ -218,7 +218,7 @@ public void addKeyValuePair(DataManager dm, String key, String value) * @throws AccessException Cannot access data. * @throws ExecutionException A Facility can't be retrieved or instantiated. */ - public List getRatings(Browser browser, List userIds) + public List getRatings(BasicBrowser browser, List userIds) throws ServiceException, AccessException, ExecutionException { String error = "Cannot retrieve rating annotations from " + this; @@ -285,7 +285,7 @@ public void rate(Client client, int rating) * @throws ExecutionException A Facility can't be retrieved or instantiated. */ @Override - public int getMyRating(Browser browser) + public int getMyRating(BasicBrowser browser) throws ServiceException, AccessException, ExecutionException { List userIds = singletonList(browser.getCtx().getExperimenter()); @@ -345,7 +345,7 @@ public void addAndReplaceTable(Client client, TableWrapper table, ReplacePolicy * @throws ExecutionException A Facility can't be retrieved or instantiated. */ @Override - public TableWrapper getTable(DataManager dm, Long fileId) + public TableWrapper getTable(BasicDataManager dm, Long fileId) throws ServiceException, AccessException, ExecutionException { TableData info = call(dm.getTablesFacility(), tf -> tf.getTableInfo(dm.getCtx(), fileId), @@ -423,7 +423,7 @@ public long addAndReplaceFile(Client client, File file, ReplacePolicy policy) * @throws ExecutionException A Facility can't be retrieved or instantiated. */ @Override - public List getFileAnnotations(Browser browser) + public List getFileAnnotations(BasicBrowser browser) throws ExecutionException, ServiceException, AccessException { String error = "Cannot retrieve file annotations from " + this; @@ -544,7 +544,7 @@ protected void removeLink(Client client, String linkType, long childId) * @throws ExecutionException A Facility can't be retrieved or instantiated. */ @Override - public List getAnnotations(Browser browser) + public List getAnnotations(BasicBrowser browser) throws AccessException, ServiceException, ExecutionException { return wrap(getAnnotationData(browser), Wrapper::wrap); } diff --git a/src/main/java/fr/igred/omero/ObjectWrapper.java b/src/main/java/fr/igred/omero/ObjectWrapper.java index 8922c260..5cb96c20 100644 --- a/src/main/java/fr/igred/omero/ObjectWrapper.java +++ b/src/main/java/fr/igred/omero/ObjectWrapper.java @@ -18,7 +18,7 @@ package fr.igred.omero; -import fr.igred.omero.client.DataManager; +import fr.igred.omero.client.BasicDataManager; import fr.igred.omero.exception.AccessException; import fr.igred.omero.exception.ServiceException; import fr.igred.omero.meta.Experimenter; @@ -181,7 +181,7 @@ public String toString() { */ @Override @SuppressWarnings("unchecked") - public void saveAndUpdate(DataManager dm) + public void saveAndUpdate(BasicDataManager dm) throws ExecutionException, ServiceException, AccessException { data = (T) call(dm.getDMFacility(), d -> d.saveAndReturnObject(dm.getCtx(), data), diff --git a/src/main/java/fr/igred/omero/RemoteObject.java b/src/main/java/fr/igred/omero/RemoteObject.java index 20ce5f8b..51731a05 100644 --- a/src/main/java/fr/igred/omero/RemoteObject.java +++ b/src/main/java/fr/igred/omero/RemoteObject.java @@ -18,7 +18,7 @@ package fr.igred.omero; -import fr.igred.omero.client.DataManager; +import fr.igred.omero.client.BasicDataManager; import fr.igred.omero.exception.AccessException; import fr.igred.omero.exception.ServiceException; import fr.igred.omero.meta.Experimenter; @@ -155,7 +155,7 @@ List flatten(Collection> lists) { * @throws AccessException Cannot access data. * @throws ExecutionException A Facility can't be retrieved or instantiated. */ - void saveAndUpdate(DataManager dm) + void saveAndUpdate(BasicDataManager dm) throws ExecutionException, ServiceException, AccessException; diff --git a/src/main/java/fr/igred/omero/RepositoryObject.java b/src/main/java/fr/igred/omero/RepositoryObject.java index 966c90ec..7643443e 100644 --- a/src/main/java/fr/igred/omero/RepositoryObject.java +++ b/src/main/java/fr/igred/omero/RepositoryObject.java @@ -18,7 +18,7 @@ package fr.igred.omero; -import fr.igred.omero.client.Browser; +import fr.igred.omero.client.BasicBrowser; import fr.igred.omero.exception.AccessException; import fr.igred.omero.exception.ServiceException; @@ -55,7 +55,7 @@ public interface RepositoryObject extends Annotatable { * @throws AccessException Cannot access data. * @throws ExecutionException A Facility can't be retrieved or instantiated. */ - void reload(Browser browser) + void reload(BasicBrowser browser) throws ServiceException, AccessException, ExecutionException; } diff --git a/src/main/java/fr/igred/omero/annotations/Annotation.java b/src/main/java/fr/igred/omero/annotations/Annotation.java index 2cb1adbe..10d9804b 100644 --- a/src/main/java/fr/igred/omero/annotations/Annotation.java +++ b/src/main/java/fr/igred/omero/annotations/Annotation.java @@ -19,16 +19,19 @@ import fr.igred.omero.RemoteObject; -import fr.igred.omero.client.Browser; +import fr.igred.omero.client.BasicBrowser; +import fr.igred.omero.containers.ContainersBrowser; import fr.igred.omero.containers.Dataset; import fr.igred.omero.containers.Folder; import fr.igred.omero.containers.Project; import fr.igred.omero.core.Image; +import fr.igred.omero.core.ImageBrowser; import fr.igred.omero.exception.AccessException; import fr.igred.omero.exception.ServiceException; import fr.igred.omero.screen.Plate; import fr.igred.omero.screen.PlateAcquisition; import fr.igred.omero.screen.Screen; +import fr.igred.omero.screen.ScreenBrowser; import fr.igred.omero.screen.Well; import omero.gateway.model.AnnotationData; @@ -102,7 +105,7 @@ public interface Annotation extends RemoteObject { * @throws ServiceException Cannot connect to OMERO. * @throws AccessException Cannot access data. */ - default int countAnnotationLinks(Browser browser) + default int countAnnotationLinks(BasicBrowser browser) throws ServiceException, AccessException { String q = "select link.parent from ome.model.IAnnotationLink link" + " where link.child.id=" + getId(); @@ -121,7 +124,7 @@ default int countAnnotationLinks(Browser browser) * @throws AccessException Cannot access data. * @throws ExecutionException A Facility can't be retrieved or instantiated. */ - List getProjects(Browser browser) + List getProjects(ContainersBrowser browser) throws ServiceException, AccessException, ExecutionException; @@ -136,7 +139,7 @@ List getProjects(Browser browser) * @throws AccessException Cannot access data. * @throws ExecutionException A Facility can't be retrieved or instantiated. */ - List getDatasets(Browser browser) + List getDatasets(ContainersBrowser browser) throws ServiceException, AccessException, ExecutionException; @@ -151,7 +154,7 @@ List getDatasets(Browser browser) * @throws AccessException Cannot access data. * @throws ExecutionException A Facility can't be retrieved or instantiated. */ - List getImages(Browser browser) + List getImages(ImageBrowser browser) throws ServiceException, AccessException, ExecutionException; @@ -166,7 +169,7 @@ List getImages(Browser browser) * @throws AccessException Cannot access data. * @throws ExecutionException A Facility can't be retrieved or instantiated. */ - List getScreens(Browser browser) + List getScreens(ScreenBrowser browser) throws ServiceException, AccessException, ExecutionException; @@ -181,7 +184,7 @@ List getScreens(Browser browser) * @throws AccessException Cannot access data. * @throws ExecutionException A Facility can't be retrieved or instantiated. */ - List getPlates(Browser browser) + List getPlates(ScreenBrowser browser) throws ServiceException, AccessException, ExecutionException; @@ -195,7 +198,7 @@ List getPlates(Browser browser) * @throws ServiceException Cannot connect to OMERO. * @throws AccessException Cannot access data. */ - List getPlateAcquisitions(Browser browser) + List getPlateAcquisitions(BasicBrowser browser) throws ServiceException, AccessException; @@ -210,7 +213,7 @@ List getPlateAcquisitions(Browser browser) * @throws AccessException Cannot access data. * @throws ExecutionException A Facility can't be retrieved or instantiated. */ - List getWells(Browser browser) + List getWells(ScreenBrowser browser) throws ServiceException, AccessException, ExecutionException; @@ -225,7 +228,7 @@ List getWells(Browser browser) * @throws AccessException Cannot access data. * @throws ExecutionException A Facility can't be retrieved or instantiated. */ - List getFolders(Browser browser) + List getFolders(ContainersBrowser browser) throws ServiceException, AccessException, ExecutionException; } diff --git a/src/main/java/fr/igred/omero/annotations/AnnotationWrapper.java b/src/main/java/fr/igred/omero/annotations/AnnotationWrapper.java index 1841c51b..bdd8c65d 100644 --- a/src/main/java/fr/igred/omero/annotations/AnnotationWrapper.java +++ b/src/main/java/fr/igred/omero/annotations/AnnotationWrapper.java @@ -19,17 +19,20 @@ import fr.igred.omero.ObjectWrapper; -import fr.igred.omero.client.Browser; +import fr.igred.omero.client.BasicBrowser; +import fr.igred.omero.containers.ContainersBrowser; import fr.igred.omero.containers.Dataset; import fr.igred.omero.containers.Folder; import fr.igred.omero.containers.Project; import fr.igred.omero.core.Image; +import fr.igred.omero.core.ImageBrowser; import fr.igred.omero.exception.AccessException; import fr.igred.omero.exception.ServiceException; import fr.igred.omero.screen.Plate; import fr.igred.omero.screen.PlateAcquisition; import fr.igred.omero.screen.PlateAcquisitionWrapper; import fr.igred.omero.screen.Screen; +import fr.igred.omero.screen.ScreenBrowser; import fr.igred.omero.screen.Well; import omero.RLong; import omero.gateway.model.AnnotationData; @@ -128,7 +131,7 @@ public void setDescription(String description) { * @throws ExecutionException A Facility can't be retrieved or instantiated. */ @Override - public List getProjects(Browser browser) + public List getProjects(ContainersBrowser browser) throws ServiceException, AccessException, ExecutionException { List os = getLinks(browser, Project.ANNOTATION_LINK); Long[] ids = os.stream() @@ -152,7 +155,7 @@ public List getProjects(Browser browser) * @throws ExecutionException A Facility can't be retrieved or instantiated. */ @Override - public List getDatasets(Browser browser) + public List getDatasets(ContainersBrowser browser) throws ServiceException, AccessException, ExecutionException { List os = getLinks(browser, Dataset.ANNOTATION_LINK); Long[] ids = os.stream() @@ -176,7 +179,7 @@ public List getDatasets(Browser browser) * @throws ExecutionException A Facility can't be retrieved or instantiated. */ @Override - public List getImages(Browser browser) + public List getImages(ImageBrowser browser) throws ServiceException, AccessException, ExecutionException { List os = getLinks(browser, Image.ANNOTATION_LINK); Long[] ids = os.stream() @@ -200,7 +203,7 @@ public List getImages(Browser browser) * @throws ExecutionException A Facility can't be retrieved or instantiated. */ @Override - public List getScreens(Browser browser) + public List getScreens(ScreenBrowser browser) throws ServiceException, AccessException, ExecutionException { List os = getLinks(browser, Screen.ANNOTATION_LINK); Long[] ids = os.stream() @@ -224,7 +227,7 @@ public List getScreens(Browser browser) * @throws ExecutionException A Facility can't be retrieved or instantiated. */ @Override - public List getPlates(Browser browser) + public List getPlates(ScreenBrowser browser) throws ServiceException, AccessException, ExecutionException { List os = getLinks(browser, Plate.ANNOTATION_LINK); Long[] ids = os.stream() @@ -247,7 +250,7 @@ public List getPlates(Browser browser) * @throws AccessException Cannot access data. */ @Override - public List getPlateAcquisitions(Browser browser) + public List getPlateAcquisitions(BasicBrowser browser) throws ServiceException, AccessException { List os = getLinks(browser, PlateAcquisition.ANNOTATION_LINK); @@ -271,7 +274,7 @@ public List getPlateAcquisitions(Browser browser) * @throws ExecutionException A Facility can't be retrieved or instantiated. */ @Override - public List getWells(Browser browser) + public List getWells(ScreenBrowser browser) throws ServiceException, AccessException, ExecutionException { List os = getLinks(browser, Well.ANNOTATION_LINK); Long[] ids = os.stream() @@ -295,7 +298,7 @@ public List getWells(Browser browser) * @throws ExecutionException A Facility can't be retrieved or instantiated. */ @Override - public List getFolders(Browser browser) + public List getFolders(ContainersBrowser browser) throws ServiceException, AccessException, ExecutionException { List os = getLinks(browser, Folder.ANNOTATION_LINK); Long[] ids = os.stream() @@ -318,7 +321,7 @@ public List getFolders(Browser browser) * @throws ServiceException Cannot connect to OMERO. * @throws AccessException Cannot access data. */ - private List getLinks(Browser browser, String linkType) + private List getLinks(BasicBrowser browser, String linkType) throws ServiceException, AccessException { return browser.findByQuery("select link.parent from " + linkType + " link where link.child = " + getId()); diff --git a/src/main/java/fr/igred/omero/annotations/AnnotationsBrowser.java b/src/main/java/fr/igred/omero/annotations/AnnotationsBrowser.java new file mode 100644 index 00000000..78a5f4f6 --- /dev/null +++ b/src/main/java/fr/igred/omero/annotations/AnnotationsBrowser.java @@ -0,0 +1,118 @@ +package fr.igred.omero.annotations; + + +import fr.igred.omero.RemoteObject; +import fr.igred.omero.client.BasicBrowser; +import fr.igred.omero.exception.AccessException; +import fr.igred.omero.exception.ServiceException; + +import java.util.Comparator; +import java.util.List; +import java.util.NoSuchElementException; +import java.util.concurrent.ExecutionException; + + +public interface AnnotationsBrowser extends BasicBrowser { + + /** + * Gets the list of tag annotations available to the user. + * + * @return See above. + * + * @throws AccessException Cannot access data. + * @throws ServiceException Cannot connect to OMERO. + */ + List getTags() + throws AccessException, ServiceException; + + + /** + * Gets the list of tag annotations with the specified name available to the user. + * + * @param name Name of the tag searched. + * + * @return See above. + * + * @throws AccessException Cannot access data. + * @throws ServiceException Cannot connect to OMERO. + */ + default List getTags(String name) + throws AccessException, ServiceException { + List tags = getTags(); + tags.removeIf(tag -> !tag.getName().equals(name)); + tags.sort(Comparator.comparing(RemoteObject::getId)); + return tags; + } + + + /** + * Gets a specific tag from the OMERO database. + * + * @param id ID of the tag. + * + * @return See above. + * + * @throws AccessException Cannot access data. + * @throws ServiceException Cannot connect to OMERO. + * @throws NoSuchElementException No element with this ID. + */ + TagAnnotationWrapper getTag(Long id) + throws AccessException, ServiceException; + + + /** + * Gets the list of map annotations available to the user. + * + * @return See above. + * + * @throws AccessException Cannot access data. + * @throws ServiceException Cannot connect to OMERO. + */ + List getMapAnnotations() + throws AccessException, ServiceException; + + + /** + * Gets the list of map annotations with the specified key available to the user. + * + * @param key Name of the tag searched. + * + * @return See above. + * + * @throws AccessException Cannot access data. + * @throws ServiceException Cannot connect to OMERO. + */ + List getMapAnnotations(String key) + throws AccessException, ServiceException; + + + /** + * Gets the list of map annotations with the specified key and value available to the user. + * + * @param key The required key. + * @param value The required value. + * + * @return See above. + * + * @throws AccessException Cannot access data. + * @throws ServiceException Cannot connect to OMERO. + */ + List getMapAnnotations(String key, String value) + throws AccessException, ServiceException; + + + /** + * Gets a specific map annotation (key/value pairs) from the OMERO database. + * + * @param id ID of the map annotation. + * + * @return See above. + * + * @throws ServiceException Cannot connect to OMERO. + * @throws AccessException Cannot access data. + * @throws ExecutionException A Facility can't be retrieved or instantiated. + */ + MapAnnotation getMapAnnotation(Long id) + throws ServiceException, ExecutionException, AccessException; + +} diff --git a/src/main/java/fr/igred/omero/annotations/TagAnnotationWrapper.java b/src/main/java/fr/igred/omero/annotations/TagAnnotationWrapper.java index 53aa8b50..71475252 100644 --- a/src/main/java/fr/igred/omero/annotations/TagAnnotationWrapper.java +++ b/src/main/java/fr/igred/omero/annotations/TagAnnotationWrapper.java @@ -18,7 +18,7 @@ package fr.igred.omero.annotations; -import fr.igred.omero.client.DataManager; +import fr.igred.omero.client.BasicDataManager; import fr.igred.omero.exception.AccessException; import fr.igred.omero.exception.ServiceException; import omero.gateway.model.TagAnnotationData; @@ -53,7 +53,7 @@ public TagAnnotationWrapper(TagAnnotationData tag) { * @throws AccessException Cannot access data. * @throws ExecutionException A Facility can't be retrieved or instantiated. */ - public TagAnnotationWrapper(DataManager dm, String name, String description) + public TagAnnotationWrapper(BasicDataManager dm, String name, String description) throws ServiceException, AccessException, ExecutionException { super(new TagAnnotationData(name, description)); super.saveAndUpdate(dm); diff --git a/src/main/java/fr/igred/omero/annotations/TagSet.java b/src/main/java/fr/igred/omero/annotations/TagSet.java index 156a1eea..483b599a 100644 --- a/src/main/java/fr/igred/omero/annotations/TagSet.java +++ b/src/main/java/fr/igred/omero/annotations/TagSet.java @@ -19,8 +19,8 @@ import fr.igred.omero.RemoteObject; -import fr.igred.omero.client.Browser; -import fr.igred.omero.client.DataManager; +import fr.igred.omero.client.BasicBrowser; +import fr.igred.omero.client.BasicDataManager; import fr.igred.omero.exception.AccessException; import fr.igred.omero.exception.ServiceException; import omero.gateway.model.TagAnnotationData; @@ -100,7 +100,7 @@ public interface TagSet extends RemoteObject { * @throws ServiceException Cannot connect to OMERO. * @throws AccessException Cannot access data. */ - default List getTags(Browser browser) + default List getTags(BasicBrowser browser) throws AccessException, ServiceException { reload(browser); return getTags(); @@ -117,7 +117,7 @@ default List getTags(Browser browser) * @throws AccessException Cannot access data. * @throws ExecutionException A Facility can't be retrieved or instantiated. */ - default void link(DataManager dm, TagAnnotation tag) + default void link(BasicDataManager dm, TagAnnotation tag) throws AccessException, ServiceException, ExecutionException { AnnotationAnnotationLink link = new AnnotationAnnotationLinkI(); link.setParent(new TagAnnotationI(getId(), false)); @@ -136,7 +136,7 @@ default void link(DataManager dm, TagAnnotation tag) * @throws AccessException Cannot access data. * @throws ExecutionException A Facility can't be retrieved or instantiated. */ - default void link(DataManager dm, TagAnnotation... tags) + default void link(BasicDataManager dm, TagAnnotation... tags) throws AccessException, ServiceException, ExecutionException { for (TagAnnotation tag : tags) { link(dm, tag); @@ -152,7 +152,7 @@ default void link(DataManager dm, TagAnnotation... tags) * @throws ServiceException Cannot connect to OMERO. * @throws AccessException Cannot access data. */ - void reload(Browser browser) + void reload(BasicBrowser browser) throws ServiceException, AccessException; } diff --git a/src/main/java/fr/igred/omero/annotations/TagSetWrapper.java b/src/main/java/fr/igred/omero/annotations/TagSetWrapper.java index 10c8458d..141621bb 100644 --- a/src/main/java/fr/igred/omero/annotations/TagSetWrapper.java +++ b/src/main/java/fr/igred/omero/annotations/TagSetWrapper.java @@ -18,8 +18,8 @@ package fr.igred.omero.annotations; -import fr.igred.omero.client.Browser; -import fr.igred.omero.client.DataManager; +import fr.igred.omero.client.BasicBrowser; +import fr.igred.omero.client.BasicDataManager; import fr.igred.omero.exception.AccessException; import fr.igred.omero.exception.ServiceException; import omero.gateway.model.TagAnnotationData; @@ -57,7 +57,7 @@ public TagSetWrapper(TagAnnotationData tag) { * @throws AccessException Cannot access data. * @throws ExecutionException A Facility can't be retrieved or instantiated. */ - public TagSetWrapper(DataManager dm, String name, String description) + public TagSetWrapper(BasicDataManager dm, String name, String description) throws ServiceException, AccessException, ExecutionException { this(new TagAnnotationData(name, description)); super.saveAndUpdate(dm); @@ -84,7 +84,7 @@ public List getTags() { * @throws AccessException Cannot access data. */ @Override - public void reload(Browser browser) + public void reload(BasicBrowser 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/AdminManager.java b/src/main/java/fr/igred/omero/client/AdminManager.java index 62bfd59a..355923f8 100644 --- a/src/main/java/fr/igred/omero/client/AdminManager.java +++ b/src/main/java/fr/igred/omero/client/AdminManager.java @@ -27,7 +27,6 @@ import omero.ApiUsageException; import omero.api.IAdminPrx; import omero.gateway.SecurityContext; -import omero.gateway.facility.AdminFacility; import omero.gateway.model.ExperimenterData; import omero.gateway.model.GroupData; import omero.model.Experimenter; @@ -45,35 +44,7 @@ /** * Interface to handle admin functions on an OMERO server in a given {@link SecurityContext}. */ -public interface AdminManager { - - /** - * Returns the current {@link SecurityContext}. - * - * @return See above - */ - SecurityContext getCtx(); - - - /** - * Gets the {@link AdminFacility} to use admin specific function. - * - * @return See above. - * - * @throws ExecutionException If the AdminFacility can't be retrieved or instantiated. - */ - AdminFacility getAdminFacility() throws ExecutionException; - - - /** - * Returns the {@link IAdminPrx} to use admin specific function. - * - * @return See above. - * - * @throws AccessException Cannot access data. - * @throws ServiceException Cannot connect to OMERO. - */ - IAdminPrx getAdminService() throws AccessException, ServiceException; +public interface AdminManager extends fr.igred.omero.meta.BasicAdmin { /** diff --git a/src/main/java/fr/igred/omero/client/BasicBrowser.java b/src/main/java/fr/igred/omero/client/BasicBrowser.java new file mode 100644 index 00000000..e2f2de11 --- /dev/null +++ b/src/main/java/fr/igred/omero/client/BasicBrowser.java @@ -0,0 +1,76 @@ +package fr.igred.omero.client; + + +import fr.igred.omero.exception.AccessException; +import fr.igred.omero.exception.ServiceException; +import omero.api.IQueryPrx; +import omero.gateway.SecurityContext; +import omero.gateway.facility.BrowseFacility; +import omero.gateway.facility.MetadataFacility; +import omero.model.IObject; + +import java.util.List; +import java.util.concurrent.ExecutionException; + +import static fr.igred.omero.exception.ExceptionHandler.call; + + +public interface BasicBrowser { + + /** + * Returns the current {@link SecurityContext}. + * + * @return See above + */ + SecurityContext getCtx(); + + + /** + * Gets the {@link BrowseFacility} used to access the data from OMERO. + * + * @return See above. + * + * @throws ExecutionException A Facility can't be retrieved or instantiated. + */ + BrowseFacility getBrowseFacility() throws ExecutionException; + + + /** + * Returns the {@link IQueryPrx} used to find objects on OMERO. + * + * @return See above. + * + * @throws ServiceException Cannot connect to OMERO. + * @throws AccessException Cannot access data. + */ + IQueryPrx getQueryService() throws ServiceException, AccessException; + + + /** + * Gets the {@link MetadataFacility} used to retrieve annotations from OMERO. + * + * @return See above. + * + * @throws ExecutionException If the MetadataFacility can't be retrieved or instantiated. + */ + MetadataFacility getMetadataFacility() 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. + */ + default List findByQuery(String query) + throws ServiceException, AccessException { + return call(getQueryService(), + qs -> qs.findAllByQuery(query, null), + "Query failed: " + query); + } + +} diff --git a/src/main/java/fr/igred/omero/client/BasicDataManager.java b/src/main/java/fr/igred/omero/client/BasicDataManager.java new file mode 100644 index 00000000..cb5d501b --- /dev/null +++ b/src/main/java/fr/igred/omero/client/BasicDataManager.java @@ -0,0 +1,157 @@ +package fr.igred.omero.client; + + +import fr.igred.omero.exception.AccessException; +import fr.igred.omero.exception.ExceptionHandler; +import fr.igred.omero.exception.ServiceException; +import omero.gateway.SecurityContext; +import omero.gateway.facility.DataManagerFacility; +import omero.gateway.facility.ROIFacility; +import omero.gateway.facility.TablesFacility; +import omero.model.FileAnnotationI; +import omero.model.IObject; + +import java.util.Arrays; +import java.util.List; +import java.util.concurrent.ExecutionException; +import java.util.stream.Collectors; + +import static fr.igred.omero.exception.ExceptionHandler.call; + + +public interface BasicDataManager { + + /** + * Returns the current {@link SecurityContext}. + * + * @return See above + */ + SecurityContext getCtx(); + + + /** + * Gets the {@link DataManagerFacility} to handle/write data on OMERO. A + * + * @return See above. + * + * @throws ExecutionException If the DataManagerFacility can't be retrieved or instantiated. + */ + DataManagerFacility getDMFacility() throws ExecutionException; + + + /** + * Gets the {@link ROIFacility} used to manipulate ROIs from OMERO. + * + * @return See above. + * + * @throws ExecutionException If the ROIFacility can't be retrieved or instantiated. + */ + ROIFacility getRoiFacility() throws ExecutionException; + + + /** + * Gets the {@link TablesFacility} used to manipulate tables on OMERO. + * + * @return See above. + * + * @throws ExecutionException If the TablesFacility can't be retrieved or instantiated. + */ + TablesFacility getTablesFacility() throws ExecutionException; + + + /** + * Saves an object on OMERO. + * + * @param object The OMERO object. + * + * @return The saved OMERO object + * + * @throws ServiceException Cannot connect to OMERO. + * @throws AccessException Cannot access data. + * @throws ExecutionException A Facility can't be retrieved or instantiated. + */ + default IObject save(IObject object) + throws ServiceException, AccessException, ExecutionException { + return call(getDMFacility(), + d -> d.saveAndReturnObject(getCtx(), object), + "Cannot save object"); + } + + + /** + * Deletes an object from OMERO. + * + * @param object The OMERO object. + * + * @throws ServiceException Cannot connect to OMERO. + * @throws AccessException Cannot access data. + * @throws ExecutionException A Facility can't be retrieved or instantiated. + * @throws InterruptedException If block(long) does not return. + */ + default void delete(IObject object) + throws ServiceException, AccessException, ExecutionException, InterruptedException { + final long wait = 500L; + ExceptionHandler.ofConsumer(getDMFacility(), + d -> d.delete(getCtx(), object).loop(10, wait)) + .rethrow(InterruptedException.class) + .handleOMEROException("Cannot delete object") + .rethrow(); + } + + + /** + * Deletes multiple objects from OMERO. + * + * @param objects The OMERO objects. + * + * @throws ServiceException Cannot connect to OMERO. + * @throws AccessException Cannot access data. + * @throws ExecutionException A Facility can't be retrieved or instantiated. + * @throws InterruptedException If block(long) does not return. + */ + default void delete(List objects) + throws ServiceException, AccessException, ExecutionException, InterruptedException { + final long wait = 500L; + ExceptionHandler.ofConsumer(getDMFacility(), + d -> d.delete(getCtx(), objects).loop(10, wait)) + .rethrow(InterruptedException.class) + .handleOMEROException("Cannot delete objects") + .rethrow(); + } + + + /** + * Deletes a file from OMERO + * + * @param id ID of the file to delete. + * + * @throws ServiceException Cannot connect to OMERO. + * @throws AccessException Cannot access data. + * @throws ExecutionException A Facility can't be retrieved or instantiated. + * @throws InterruptedException If block(long) does not return. + */ + default void deleteFile(Long id) + throws ServiceException, AccessException, ExecutionException, InterruptedException { + deleteFiles(id); + } + + + /** + * Deletes files from OMERO. + * + * @param ids List of files IDs to delete. + * + * @throws ServiceException Cannot connect to OMERO. + * @throws AccessException Cannot access data. + * @throws ExecutionException A Facility can't be retrieved or instantiated. + * @throws InterruptedException If block(long) does not return. + */ + default void deleteFiles(Long... ids) + throws ServiceException, AccessException, ExecutionException, InterruptedException { + List files = Arrays.stream(ids) + .map(id -> new FileAnnotationI(id, false)) + .collect(Collectors.toList()); + delete(files); + } + +} diff --git a/src/main/java/fr/igred/omero/client/Browser.java b/src/main/java/fr/igred/omero/client/Browser.java index 1f4304b7..c221f8b0 100644 --- a/src/main/java/fr/igred/omero/client/Browser.java +++ b/src/main/java/fr/igred/omero/client/Browser.java @@ -18,84 +18,31 @@ package fr.igred.omero.client; -import fr.igred.omero.RemoteObject; -import fr.igred.omero.annotations.Annotation; import fr.igred.omero.annotations.MapAnnotation; -import fr.igred.omero.annotations.TagAnnotation; -import fr.igred.omero.annotations.TagAnnotationWrapper; import fr.igred.omero.containers.Dataset; -import fr.igred.omero.containers.Folder; import fr.igred.omero.containers.Project; import fr.igred.omero.core.Image; import fr.igred.omero.exception.AccessException; import fr.igred.omero.exception.ServiceException; import fr.igred.omero.meta.Experimenter; import fr.igred.omero.screen.Plate; -import fr.igred.omero.screen.Screen; -import fr.igred.omero.screen.Well; -import omero.RLong; -import omero.api.IQueryPrx; import omero.gateway.SecurityContext; -import omero.gateway.facility.BrowseFacility; -import omero.gateway.facility.MetadataFacility; -import omero.model.IObject; import java.util.ArrayList; import java.util.Collection; -import java.util.Comparator; import java.util.List; -import java.util.NoSuchElementException; import java.util.concurrent.ExecutionException; import static fr.igred.omero.RemoteObject.flatten; -import static fr.igred.omero.exception.ExceptionHandler.call; -import static java.lang.String.format; /** * Interface to browse data on an OMERO server in a given {@link SecurityContext}. */ -@SuppressWarnings("ClassWithTooManyMethods") -//Fewer methods than counted because of polymorphism. -public interface Browser { - - /** - * Returns the current {@link SecurityContext}. - * - * @return See above - */ - SecurityContext getCtx(); - - - /** - * Gets the {@link BrowseFacility} used to access the data from OMERO. - * - * @return See above. - * - * @throws ExecutionException A Facility can't be retrieved or instantiated. - */ - BrowseFacility getBrowseFacility() throws ExecutionException; - - - /** - * Returns the {@link IQueryPrx} used to find objects on OMERO. - * - * @return See above. - * - * @throws ServiceException Cannot connect to OMERO. - * @throws AccessException Cannot access data. - */ - IQueryPrx getQueryService() throws ServiceException, AccessException; - - - /** - * Gets the {@link MetadataFacility} used to retrieve annotations from OMERO. - * - * @return See above. - * - * @throws ExecutionException If the MetadataFacility can't be retrieved or instantiated. - */ - MetadataFacility getMetadataFacility() throws ExecutionException; +public interface Browser extends fr.igred.omero.containers.ContainersBrowser, + fr.igred.omero.core.ImageBrowser, + fr.igred.omero.screen.ScreenBrowser, + fr.igred.omero.annotations.AnnotationsBrowser { /** @@ -106,231 +53,6 @@ public interface Browser { Experimenter getUser(); - /** - * 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. - */ - default List findByQuery(String query) - throws ServiceException, AccessException { - return call(getQueryService(), - qs -> qs.findAllByQuery(query, null), - "Query failed: " + query); - } - - - /** - * Gets the project with the specified id from OMERO. - * - * @param id ID of the project. - * - * @return See above. - * - * @throws ServiceException Cannot connect to OMERO. - * @throws AccessException Cannot access data. - * @throws NoSuchElementException No element with this ID. - * @throws ExecutionException A Facility can't be retrieved or instantiated. - */ - default Project getProject(Long id) - throws ServiceException, AccessException, ExecutionException { - List projects = getProjects(id); - if (projects.isEmpty()) { - String msg = format("Project %d doesn't exist in this context", id); - throw new NoSuchElementException(msg); - } - return projects.iterator().next(); - } - - - /** - * Gets the projects with the specified ids from OMERO. - * - * @param ids Project IDs - * - * @return See above. - * - * @throws ServiceException Cannot connect to OMERO. - * @throws AccessException Cannot access data. - * @throws ExecutionException A Facility can't be retrieved or instantiated. - */ - List getProjects(Long... ids) - throws ServiceException, AccessException, ExecutionException; - - - /** - * Gets all projects available from OMERO. - * - * @return See above. - * - * @throws ServiceException Cannot connect to OMERO. - * @throws AccessException Cannot access data. - * @throws ExecutionException A Facility can't be retrieved or instantiated. - */ - List getProjects() - throws ServiceException, AccessException, ExecutionException; - - - /** - * Gets all projects available from OMERO owned by a given user. - * - * @param experimenter The user. - * - * @return See above. - * - * @throws ServiceException Cannot connect to OMERO. - * @throws AccessException Cannot access data. - * @throws ExecutionException A Facility can't be retrieved or instantiated. - */ - List getProjects(Experimenter experimenter) - throws ServiceException, AccessException, ExecutionException; - - - /** - * Gets all projects with a certain name from OMERO. - * - * @param name Name searched. - * - * @return See above. - * - * @throws ServiceException Cannot connect to OMERO. - * @throws AccessException Cannot access data. - * @throws ExecutionException A Facility can't be retrieved or instantiated. - */ - List getProjects(String name) - throws ServiceException, AccessException, ExecutionException; - - - /** - * Gets the dataset with the specified id from OMERO. - * - * @param id ID of the dataset. - * - * @return See above. - * - * @throws ServiceException Cannot connect to OMERO. - * @throws AccessException Cannot access data. - * @throws NoSuchElementException No element with this ID. - * @throws ExecutionException A Facility can't be retrieved or instantiated. - */ - default Dataset getDataset(Long id) - throws ServiceException, AccessException, ExecutionException { - List datasets = getDatasets(id); - if (datasets.isEmpty()) { - String msg = format("Dataset %d doesn't exist in this context", id); - throw new NoSuchElementException(msg); - } - return datasets.iterator().next(); - } - - - /** - * Gets the datasets with the specified ids from OMERO. - * - * @param ids Dataset IDs - * - * @return See above. - * - * @throws ServiceException Cannot connect to OMERO. - * @throws AccessException Cannot access data. - * @throws ExecutionException A Facility can't be retrieved or instantiated. - */ - List getDatasets(Long... ids) - throws ServiceException, AccessException, ExecutionException; - - - /** - * Gets all datasets available from OMERO. - * - * @return See above. - * - * @throws ServiceException Cannot connect to OMERO. - * @throws AccessException Cannot access data. - * @throws ExecutionException A Facility can't be retrieved or instantiated. - */ - default List getDatasets() - throws ServiceException, AccessException, ExecutionException { - Long[] ids = this.findByQuery("select d from Dataset d") - .stream() - .map(IObject::getId) - .map(RLong::getValue) - .toArray(Long[]::new); - return getDatasets(ids); - } - - - /** - * Gets all datasets available from OMERO owned by a given user. - * - * @param experimenter The user. - * - * @return See above. - * - * @throws ServiceException Cannot connect to OMERO. - * @throws AccessException Cannot access data. - * @throws ExecutionException A Facility can't be retrieved or instantiated. - */ - default List getDatasets(Experimenter experimenter) - throws ServiceException, AccessException, ExecutionException { - String template = "select d from Dataset d where d.details.owner.id=%d"; - String query = format(template, experimenter.getId()); - Long[] ids = this.findByQuery(query) - .stream() - .map(IObject::getId) - .map(RLong::getValue) - .toArray(Long[]::new); - return getDatasets(ids); - } - - - /** - * Gets all datasets with a certain name from OMERO. - * - * @param name Name searched. - * - * @return See above. - * - * @throws ServiceException Cannot connect to OMERO. - * @throws AccessException Cannot access data. - * @throws ExecutionException A Facility can't be retrieved or instantiated. - */ - List getDatasets(String name) - throws ServiceException, AccessException, ExecutionException; - - - /** - * Gets all orphaned datasets available from OMERO owned by a given user. - * - * @param experimenter The user. - * - * @return See above. - * - * @throws ServiceException Cannot connect to OMERO. - * @throws AccessException Cannot access data. - * @throws ExecutionException A Facility can't be retrieved or instantiated. - */ - default List getOrphanedDatasets(Experimenter experimenter) - throws ServiceException, ExecutionException, AccessException { - String template = "select dataset from Dataset as dataset" + - " join fetch dataset.details.owner as o" + - " where o.id = %d" + - " and not exists" + - " (select obl from ProjectDatasetLink as obl" + - " where obl.child = dataset.id)"; - String query = format(template, experimenter.getId()); - Long[] ids = this.findByQuery(query) - .stream() - .map(IObject::getId) - .map(RLong::getValue) - .toArray(Long[]::new); - return getDatasets(ids); - } - - /** * Gets all orphaned datasets available from OMERO owned by the current user. * @@ -340,101 +62,13 @@ default List getOrphanedDatasets(Experimenter experimenter) * @throws AccessException Cannot access data. * @throws ExecutionException A Facility can't be retrieved or instantiated. */ + @Override default List getOrphanedDatasets() throws ServiceException, ExecutionException, AccessException { return getOrphanedDatasets(getUser()); } - /** - * Returns the image with the specified ID from OMERO. - * - * @param id ID of the image. - * - * @return See above. - * - * @throws ServiceException Cannot connect to OMERO. - * @throws AccessException Cannot access data. - * @throws NoSuchElementException No element with this ID. - * @throws ExecutionException A Facility can't be retrieved or instantiated. - */ - Image getImage(Long id) - throws ServiceException, AccessException, ExecutionException; - - - /** - * Gets the images with the specified ids from OMERO - * - * @param ids Image IDs - * - * @return See above. - * - * @throws ServiceException Cannot connect to OMERO. - * @throws AccessException Cannot access data. - * @throws ExecutionException A Facility can't be retrieved or instantiated. - */ - List getImages(Long... ids) - throws ServiceException, AccessException, ExecutionException; - - - /** - * Gets all images owned by the current user. - * - * @return See above. - * - * @throws ServiceException Cannot connect to OMERO. - * @throws AccessException Cannot access data. - * @throws ExecutionException A Facility can't be retrieved or instantiated. - */ - List getImages() - throws ServiceException, AccessException, ExecutionException; - - - /** - * Gets all images with a certain name from OMERO. - * - * @param name Name searched. - * - * @return See above. - * - * @throws ServiceException Cannot connect to OMERO. - * @throws AccessException Cannot access data. - * @throws ExecutionException A Facility can't be retrieved or instantiated. - */ - List getImages(String name) - throws ServiceException, AccessException, ExecutionException; - - - /** - * Gets all orphaned images owned by the specified user. - * - * @param experimenter The user. - * - * @return See above. - * - * @throws ServiceException Cannot connect to OMERO. - * @throws AccessException Cannot access data. - * @throws ExecutionException A Facility can't be retrieved or instantiated. - */ - List getOrphanedImages(Experimenter experimenter) - throws ServiceException, AccessException, ExecutionException; - - - /** - * Gets all orphaned images owned by the current user. - * - * @return See above. - * - * @throws ServiceException Cannot connect to OMERO. - * @throws AccessException Cannot access data. - * @throws ExecutionException A Facility can't be retrieved or instantiated. - */ - default List getOrphanedImages() - throws ServiceException, AccessException, ExecutionException { - return getOrphanedImages(getUser()); - } - - /** * Gets all images with the name specified inside projects and datasets with the given names. * @@ -448,6 +82,7 @@ default List getOrphanedImages() * @throws AccessException Cannot access data. * @throws ExecutionException A Facility can't be retrieved or instantiated. */ + @Override default List getImages(String projectName, String datasetName, String imageName) throws ServiceException, AccessException, ExecutionException { List projects = getProjects(projectName); @@ -461,43 +96,6 @@ default List getImages(String projectName, String datasetName, String ima } - /** - * Gets all images with the specified annotation from OMERO. - * - * @param annotation TagAnnotation containing the tag researched. - * - * @return See above. - * - * @throws ServiceException Cannot connect to OMERO. - * @throws AccessException Cannot access data. - * @throws ExecutionException A Facility can't be retrieved or instantiated. - */ - default List getImages(Annotation annotation) - throws ServiceException, AccessException, ExecutionException { - return annotation.getImages(this); - } - - - /** - * Gets all images with a certain motif in their name from OMERO. - * - * @param motif Motif searched in an image name. - * - * @return See above. - * - * @throws ServiceException Cannot connect to OMERO. - * @throws AccessException Cannot access data. - * @throws ExecutionException A Facility can't be retrieved or instantiated. - */ - default List getImagesLike(String motif) - throws ServiceException, AccessException, ExecutionException { - List images = getImages(); - String regexp = ".*" + motif + ".*"; - images.removeIf(image -> !image.getName().matches(regexp)); - return images; - } - - /** * Gets all images with a certain key. * @@ -509,6 +107,7 @@ default List getImagesLike(String motif) * @throws AccessException Cannot access data. * @throws ExecutionException A Facility can't be retrieved or instantiated. */ + @Override default List getImagesWithKey(String key) throws ServiceException, AccessException, ExecutionException { List maps = getMapAnnotations(key); @@ -534,6 +133,7 @@ default List getImagesWithKey(String key) * @throws AccessException Cannot access data. * @throws ExecutionException A Facility can't be retrieved or instantiated. */ + @Override default List getImagesWithKeyValuePair(String key, String value) throws ServiceException, AccessException, ExecutionException { List maps = getMapAnnotations(key, value); @@ -548,60 +148,7 @@ default List getImagesWithKeyValuePair(String key, String value) /** - * Gets the screen with the specified id from OMERO. - * - * @param id ID of the screen. - * - * @return See above. - * - * @throws ServiceException Cannot connect to OMERO. - * @throws AccessException Cannot access data. - * @throws NoSuchElementException No element with this ID. - * @throws ExecutionException A Facility can't be retrieved or instantiated. - */ - default Screen getScreen(Long id) - throws ServiceException, AccessException, ExecutionException { - List screens = getScreens(id); - if (screens.isEmpty()) { - String msg = format("Screen %d doesn't exist in this context", id); - throw new NoSuchElementException(msg); - } - return screens.iterator().next(); - } - - - /** - * Gets the screens with the specified ids from OMERO. - * - * @param ids A list of screen ids - * - * @return See above. - * - * @throws ServiceException Cannot connect to OMERO. - * @throws AccessException Cannot access data. - * @throws ExecutionException A Facility can't be retrieved or instantiated. - */ - List getScreens(Long... ids) - throws ServiceException, AccessException, ExecutionException; - - - /** - * Gets all screens available from OMERO. - * - * @return See above. - * - * @throws ServiceException Cannot connect to OMERO. - * @throws AccessException Cannot access data. - * @throws ExecutionException A Facility can't be retrieved or instantiated. - */ - List getScreens() - throws ServiceException, AccessException, ExecutionException; - - - /** - * Gets all screens available from OMERO owned by a given user. - * - * @param experimenter The user. + * Gets all orphaned images owned by the current user. * * @return See above. * @@ -609,102 +156,10 @@ List getScreens() * @throws AccessException Cannot access data. * @throws ExecutionException A Facility can't be retrieved or instantiated. */ - List getScreens(Experimenter experimenter) - throws ServiceException, AccessException, ExecutionException; - - - /** - * Gets the plate with the specified id from OMERO. - * - * @param id ID of the plate. - * - * @return See above. - * - * @throws ServiceException Cannot connect to OMERO. - * @throws AccessException Cannot access data. - * @throws NoSuchElementException No element with this ID. - * @throws ExecutionException A Facility can't be retrieved or instantiated. - */ - default Plate getPlate(Long id) + @Override + default List getOrphanedImages() throws ServiceException, AccessException, ExecutionException { - List plates = getPlates(id); - if (plates.isEmpty()) { - String msg = format("Plate %d doesn't exist in this context", id); - throw new NoSuchElementException(msg); - } - return plates.iterator().next(); - } - - - /** - * Gets the plates with the specified ids from OMERO. - * - * @param ids A list of plate ids - * - * @return See above. - * - * @throws ServiceException Cannot connect to OMERO. - * @throws AccessException Cannot access data. - * @throws ExecutionException A Facility can't be retrieved or instantiated. - */ - List getPlates(Long... ids) - throws ServiceException, AccessException, ExecutionException; - - - /** - * Gets all plates available from OMERO. - * - * @return See above. - * - * @throws ServiceException Cannot connect to OMERO. - * @throws AccessException Cannot access data. - * @throws ExecutionException A Facility can't be retrieved or instantiated. - */ - List getPlates() - throws ServiceException, AccessException, ExecutionException; - - - /** - * Gets all plates available from OMERO owned by a given user. - * - * @param experimenter The user. - * - * @return See above. - * - * @throws ServiceException Cannot connect to OMERO. - * @throws AccessException Cannot access data. - * @throws ExecutionException A Facility can't be retrieved or instantiated. - */ - List getPlates(Experimenter experimenter) - throws ServiceException, AccessException, ExecutionException; - - - /** - * Gets all orphaned plates available from OMERO owned by a given user. - * - * @param experimenter The user. - * - * @return See above. - * - * @throws ServiceException Cannot connect to OMERO. - * @throws AccessException Cannot access data. - * @throws ExecutionException A Facility can't be retrieved or instantiated. - */ - default List getOrphanedPlates(Experimenter experimenter) - throws ServiceException, ExecutionException, AccessException { - String template = "select plate from Plate as plate" + - " join fetch plate.details.owner as o" + - " where o.id = %d" + - " and not exists" + - " (select obl from ScreenPlateLink as obl" + - " where obl.child = plate.id)"; - String query = format(template, experimenter.getId()); - Long[] ids = this.findByQuery(query) - .stream() - .map(IObject::getId) - .map(RLong::getValue) - .toArray(Long[]::new); - return getPlates(ids); + return getOrphanedImages(getUser()); } @@ -723,253 +178,4 @@ default List getOrphanedPlates() } - /** - * Gets the well with the specified id from OMERO. - * - * @param id ID of the well. - * - * @return See above. - * - * @throws ServiceException Cannot connect to OMERO. - * @throws AccessException Cannot access data. - * @throws NoSuchElementException No element with this ID. - * @throws ExecutionException A Facility can't be retrieved or instantiated. - */ - default Well getWell(Long id) - throws ServiceException, AccessException, ExecutionException { - List wells = getWells(id); - if (wells.isEmpty()) { - String msg = format("Plate %d doesn't exist in this context", id); - throw new NoSuchElementException(msg); - } - return wells.iterator().next(); - } - - - /** - * Gets the wells with the specified ids from OMERO. - * - * @param ids A list of well ids - * - * @return See above. - * - * @throws ServiceException Cannot connect to OMERO. - * @throws AccessException Cannot access data. - * @throws ExecutionException A Facility can't be retrieved or instantiated. - */ - List getWells(Long... ids) - throws ServiceException, AccessException, ExecutionException; - - - /** - * Gets all wells available from OMERO. - * - * @return See above. - * - * @throws ServiceException Cannot connect to OMERO. - * @throws AccessException Cannot access data. - * @throws ExecutionException A Facility can't be retrieved or instantiated. - */ - default List getWells() - throws ServiceException, AccessException, ExecutionException { - Long[] ids = this.findByQuery("select w from Well w") - .stream() - .map(IObject::getId) - .map(RLong::getValue) - .toArray(Long[]::new); - return getWells(ids); - } - - - /** - * Gets all wells available from OMERO owned by a given user. - * - * @param experimenter The user. - * - * @return See above. - * - * @throws ServiceException Cannot connect to OMERO. - * @throws AccessException Cannot access data. - * @throws ExecutionException A Facility can't be retrieved or instantiated. - */ - default List getWells(Experimenter experimenter) - throws ServiceException, AccessException, ExecutionException { - String template = "select w from Well w where w.details.owner.id=%d"; - String query = format(template, experimenter.getId()); - Long[] ids = this.findByQuery(query) - .stream() - .map(IObject::getId) - .map(RLong::getValue) - .toArray(Long[]::new); - return getWells(ids); - } - - - /** - * Gets the folder with the specified ID from OMERO, fully loaded. - * - * @param id ID of the folder. - * - * @return See above. - * - * @throws ServiceException Cannot connect to OMERO. - * @throws AccessException Cannot access data. - * @throws NoSuchElementException No element with this ID. - * @throws ExecutionException A Facility can't be retrieved or instantiated. - */ - default Folder getFolder(long id) - throws ServiceException, AccessException, ExecutionException { - List folders = getFolders(id); - if (folders.isEmpty()) { - String msg = format("Folder %d doesn't exist in this context", id); - throw new NoSuchElementException(msg); - } - return folders.iterator().next(); - } - - - /** - * Gets all folders available from OMERO. - * - * @return See above. - * - * @throws ServiceException Cannot connect to OMERO. - * @throws AccessException Cannot access data. - * @throws ExecutionException A Facility can't be retrieved or instantiated. - */ - List getFolders() - throws ExecutionException, AccessException, ServiceException; - - - /** - * Gets all the folders owned by a given user from OMERO. - * - * @param experimenter The user. - * - * @return See above. - * - * @throws ServiceException Cannot connect to OMERO. - * @throws AccessException Cannot access data. - * @throws ExecutionException A Facility can't be retrieved or instantiated. - */ - List getFolders(Experimenter experimenter) - throws ExecutionException, AccessException, ServiceException; - - - /** - * Gets the folders with the specified IDs from OMERO (fully loaded). - * - * @param ids Project IDs - * - * @return See above. - * - * @throws ServiceException Cannot connect to OMERO. - * @throws AccessException Cannot access data. - * @throws ExecutionException A Facility can't be retrieved or instantiated. - */ - List getFolders(Long... ids) - throws ServiceException, AccessException, ExecutionException; - - - /** - * Gets the list of tag annotations available to the user. - * - * @return See above. - * - * @throws AccessException Cannot access data. - * @throws ServiceException Cannot connect to OMERO. - */ - List getTags() - throws AccessException, ServiceException; - - - /** - * Gets the list of tag annotations with the specified name available to the user. - * - * @param name Name of the tag searched. - * - * @return See above. - * - * @throws AccessException Cannot access data. - * @throws ServiceException Cannot connect to OMERO. - */ - default List getTags(String name) - throws AccessException, ServiceException { - List tags = getTags(); - tags.removeIf(tag -> !tag.getName().equals(name)); - tags.sort(Comparator.comparing(RemoteObject::getId)); - return tags; - } - - - /** - * Gets a specific tag from the OMERO database. - * - * @param id ID of the tag. - * - * @return See above. - * - * @throws AccessException Cannot access data. - * @throws ServiceException Cannot connect to OMERO. - * @throws NoSuchElementException No element with this ID. - */ - TagAnnotationWrapper getTag(Long id) - throws AccessException, ServiceException; - - - /** - * Gets the list of map annotations available to the user. - * - * @return See above. - * - * @throws AccessException Cannot access data. - * @throws ServiceException Cannot connect to OMERO. - */ - List getMapAnnotations() - throws AccessException, ServiceException; - - - /** - * Gets the list of map annotations with the specified key available to the user. - * - * @param key Name of the tag searched. - * - * @return See above. - * - * @throws AccessException Cannot access data. - * @throws ServiceException Cannot connect to OMERO. - */ - List getMapAnnotations(String key) - throws AccessException, ServiceException; - - - /** - * Gets the list of map annotations with the specified key and value available to the user. - * - * @param key The required key. - * @param value The required value. - * - * @return See above. - * - * @throws AccessException Cannot access data. - * @throws ServiceException Cannot connect to OMERO. - */ - List getMapAnnotations(String key, String value) - throws AccessException, ServiceException; - - - /** - * Gets a specific map annotation (key/value pairs) from the OMERO database. - * - * @param id ID of the map annotation. - * - * @return See above. - * - * @throws ServiceException Cannot connect to OMERO. - * @throws AccessException Cannot access data. - * @throws ExecutionException A Facility can't be retrieved or instantiated. - */ - MapAnnotation getMapAnnotation(Long id) - throws ServiceException, ExecutionException, AccessException; - } diff --git a/src/main/java/fr/igred/omero/client/DataManager.java b/src/main/java/fr/igred/omero/client/DataManager.java index ef9de8bb..ce33c14c 100644 --- a/src/main/java/fr/igred/omero/client/DataManager.java +++ b/src/main/java/fr/igred/omero/client/DataManager.java @@ -22,65 +22,18 @@ import fr.igred.omero.annotations.TableWrapper; import fr.igred.omero.containers.Folder; import fr.igred.omero.exception.AccessException; -import fr.igred.omero.exception.ExceptionHandler; import fr.igred.omero.exception.ServiceException; import omero.gateway.SecurityContext; -import omero.gateway.facility.DataManagerFacility; -import omero.gateway.facility.ROIFacility; -import omero.gateway.facility.TablesFacility; -import omero.model.FileAnnotationI; -import omero.model.IObject; -import java.util.Arrays; import java.util.Collection; -import java.util.List; import java.util.concurrent.ExecutionException; import java.util.stream.Collectors; -import static fr.igred.omero.exception.ExceptionHandler.call; - /** * Interface to add or remove data on an OMERO server in a given {@link SecurityContext}. */ -public interface DataManager { - - /** - * Returns the current {@link SecurityContext}. - * - * @return See above - */ - SecurityContext getCtx(); - - - /** - * Gets the {@link DataManagerFacility} to handle/write data on OMERO. A - * - * @return See above. - * - * @throws ExecutionException If the DataManagerFacility can't be retrieved or instantiated. - */ - DataManagerFacility getDMFacility() throws ExecutionException; - - - /** - * Gets the {@link ROIFacility} used to manipulate ROIs from OMERO. - * - * @return See above. - * - * @throws ExecutionException If the ROIFacility can't be retrieved or instantiated. - */ - ROIFacility getRoiFacility() throws ExecutionException; - - - /** - * Gets the {@link TablesFacility} used to manipulate tables on OMERO. - * - * @return See above. - * - * @throws ExecutionException If the TablesFacility can't be retrieved or instantiated. - */ - TablesFacility getTablesFacility() throws ExecutionException; +public interface DataManager extends BasicDataManager { /** @@ -163,100 +116,4 @@ default void deleteTables(Collection tables) .toArray(Long[]::new)); } - - /** - * Saves an object on OMERO. - * - * @param object The OMERO object. - * - * @return The saved OMERO object - * - * @throws ServiceException Cannot connect to OMERO. - * @throws AccessException Cannot access data. - * @throws ExecutionException A Facility can't be retrieved or instantiated. - */ - default IObject save(IObject object) - throws ServiceException, AccessException, ExecutionException { - return call(getDMFacility(), - d -> d.saveAndReturnObject(getCtx(), object), - "Cannot save object"); - } - - - /** - * Deletes an object from OMERO. - * - * @param object The OMERO object. - * - * @throws ServiceException Cannot connect to OMERO. - * @throws AccessException Cannot access data. - * @throws ExecutionException A Facility can't be retrieved or instantiated. - * @throws InterruptedException If block(long) does not return. - */ - default void delete(IObject object) - throws ServiceException, AccessException, ExecutionException, InterruptedException { - final long wait = 500L; - ExceptionHandler.ofConsumer(getDMFacility(), - d -> d.delete(getCtx(), object).loop(10, wait)) - .rethrow(InterruptedException.class) - .handleOMEROException("Cannot delete object") - .rethrow(); - } - - - /** - * Deletes multiple objects from OMERO. - * - * @param objects The OMERO objects. - * - * @throws ServiceException Cannot connect to OMERO. - * @throws AccessException Cannot access data. - * @throws ExecutionException A Facility can't be retrieved or instantiated. - * @throws InterruptedException If block(long) does not return. - */ - default void delete(List objects) - throws ServiceException, AccessException, ExecutionException, InterruptedException { - final long wait = 500L; - ExceptionHandler.ofConsumer(getDMFacility(), - d -> d.delete(getCtx(), objects).loop(10, wait)) - .rethrow(InterruptedException.class) - .handleOMEROException("Cannot delete objects") - .rethrow(); - } - - - /** - * Deletes a file from OMERO - * - * @param id ID of the file to delete. - * - * @throws ServiceException Cannot connect to OMERO. - * @throws AccessException Cannot access data. - * @throws ExecutionException A Facility can't be retrieved or instantiated. - * @throws InterruptedException If block(long) does not return. - */ - default void deleteFile(Long id) - throws ServiceException, AccessException, ExecutionException, InterruptedException { - deleteFiles(id); - } - - - /** - * Deletes files from OMERO. - * - * @param ids List of files IDs to delete. - * - * @throws ServiceException Cannot connect to OMERO. - * @throws AccessException Cannot access data. - * @throws ExecutionException A Facility can't be retrieved or instantiated. - * @throws InterruptedException If block(long) does not return. - */ - default void deleteFiles(Long... ids) - throws ServiceException, AccessException, ExecutionException, InterruptedException { - List files = Arrays.stream(ids) - .map(id -> new FileAnnotationI(id, false)) - .collect(Collectors.toList()); - delete(files); - } - } diff --git a/src/main/java/fr/igred/omero/containers/ContainersBrowser.java b/src/main/java/fr/igred/omero/containers/ContainersBrowser.java new file mode 100644 index 00000000..1347096d --- /dev/null +++ b/src/main/java/fr/igred/omero/containers/ContainersBrowser.java @@ -0,0 +1,305 @@ +package fr.igred.omero.containers; + + +import fr.igred.omero.client.BasicBrowser; +import fr.igred.omero.exception.AccessException; +import fr.igred.omero.exception.ServiceException; +import fr.igred.omero.meta.Experimenter; +import omero.RLong; +import omero.model.IObject; + +import java.util.List; +import java.util.NoSuchElementException; +import java.util.concurrent.ExecutionException; + +import static java.lang.String.format; + + +public interface ContainersBrowser extends BasicBrowser { + + /** + * Gets the project with the specified id from OMERO. + * + * @param id ID of the project. + * + * @return See above. + * + * @throws ServiceException Cannot connect to OMERO. + * @throws AccessException Cannot access data. + * @throws NoSuchElementException No element with this ID. + * @throws ExecutionException A Facility can't be retrieved or instantiated. + */ + default Project getProject(Long id) + throws ServiceException, AccessException, ExecutionException { + List projects = getProjects(id); + if (projects.isEmpty()) { + String msg = format("Project %d doesn't exist in this context", id); + throw new NoSuchElementException(msg); + } + return projects.iterator().next(); + } + + + /** + * Gets the projects with the specified ids from OMERO. + * + * @param ids Project IDs + * + * @return See above. + * + * @throws ServiceException Cannot connect to OMERO. + * @throws AccessException Cannot access data. + * @throws ExecutionException A Facility can't be retrieved or instantiated. + */ + List getProjects(Long... ids) + throws ServiceException, AccessException, ExecutionException; + + + /** + * Gets all projects available from OMERO. + * + * @return See above. + * + * @throws ServiceException Cannot connect to OMERO. + * @throws AccessException Cannot access data. + * @throws ExecutionException A Facility can't be retrieved or instantiated. + */ + List getProjects() + throws ServiceException, AccessException, ExecutionException; + + + /** + * Gets all projects available from OMERO owned by a given user. + * + * @param experimenter The user. + * + * @return See above. + * + * @throws ServiceException Cannot connect to OMERO. + * @throws AccessException Cannot access data. + * @throws ExecutionException A Facility can't be retrieved or instantiated. + */ + List getProjects(Experimenter experimenter) + throws ServiceException, AccessException, ExecutionException; + + + /** + * Gets all projects with a certain name from OMERO. + * + * @param name Name searched. + * + * @return See above. + * + * @throws ServiceException Cannot connect to OMERO. + * @throws AccessException Cannot access data. + * @throws ExecutionException A Facility can't be retrieved or instantiated. + */ + List getProjects(String name) + throws ServiceException, AccessException, ExecutionException; + + + /** + * Gets the dataset with the specified id from OMERO. + * + * @param id ID of the dataset. + * + * @return See above. + * + * @throws ServiceException Cannot connect to OMERO. + * @throws AccessException Cannot access data. + * @throws NoSuchElementException No element with this ID. + * @throws ExecutionException A Facility can't be retrieved or instantiated. + */ + default Dataset getDataset(Long id) + throws ServiceException, AccessException, ExecutionException { + List datasets = getDatasets(id); + if (datasets.isEmpty()) { + String msg = format("Dataset %d doesn't exist in this context", id); + throw new NoSuchElementException(msg); + } + return datasets.iterator().next(); + } + + + /** + * Gets the datasets with the specified ids from OMERO. + * + * @param ids Dataset IDs + * + * @return See above. + * + * @throws ServiceException Cannot connect to OMERO. + * @throws AccessException Cannot access data. + * @throws ExecutionException A Facility can't be retrieved or instantiated. + */ + List getDatasets(Long... ids) + throws ServiceException, AccessException, ExecutionException; + + + /** + * Gets all datasets available from OMERO. + * + * @return See above. + * + * @throws ServiceException Cannot connect to OMERO. + * @throws AccessException Cannot access data. + * @throws ExecutionException A Facility can't be retrieved or instantiated. + */ + default List getDatasets() + throws ServiceException, AccessException, ExecutionException { + Long[] ids = this.findByQuery("select d from Dataset d") + .stream() + .map(IObject::getId) + .map(RLong::getValue) + .toArray(Long[]::new); + return getDatasets(ids); + } + + + /** + * Gets all datasets available from OMERO owned by a given user. + * + * @param experimenter The user. + * + * @return See above. + * + * @throws ServiceException Cannot connect to OMERO. + * @throws AccessException Cannot access data. + * @throws ExecutionException A Facility can't be retrieved or instantiated. + */ + default List getDatasets(Experimenter experimenter) + throws ServiceException, AccessException, ExecutionException { + String template = "select d from Dataset d where d.details.owner.id=%d"; + String query = format(template, experimenter.getId()); + Long[] ids = this.findByQuery(query) + .stream() + .map(IObject::getId) + .map(RLong::getValue) + .toArray(Long[]::new); + return getDatasets(ids); + } + + + /** + * Gets all datasets with a certain name from OMERO. + * + * @param name Name searched. + * + * @return See above. + * + * @throws ServiceException Cannot connect to OMERO. + * @throws AccessException Cannot access data. + * @throws ExecutionException A Facility can't be retrieved or instantiated. + */ + List getDatasets(String name) + throws ServiceException, AccessException, ExecutionException; + + + /** + * Gets all orphaned datasets available from OMERO owned by a given user. + * + * @param experimenter The user. + * + * @return See above. + * + * @throws ServiceException Cannot connect to OMERO. + * @throws AccessException Cannot access data. + * @throws ExecutionException A Facility can't be retrieved or instantiated. + */ + default List getOrphanedDatasets(Experimenter experimenter) + throws ServiceException, ExecutionException, AccessException { + String template = "select dataset from Dataset as dataset" + + " join fetch dataset.details.owner as o" + + " where o.id = %d" + + " and not exists" + + " (select obl from ProjectDatasetLink as obl" + + " where obl.child = dataset.id)"; + String query = format(template, experimenter.getId()); + Long[] ids = this.findByQuery(query) + .stream() + .map(IObject::getId) + .map(RLong::getValue) + .toArray(Long[]::new); + return getDatasets(ids); + } + + + /** + * Gets all orphaned datasets available from OMERO owned by the current user. + * + * @return See above. + * + * @throws ServiceException Cannot connect to OMERO. + * @throws AccessException Cannot access data. + * @throws ExecutionException A Facility can't be retrieved or instantiated. + */ + List getOrphanedDatasets() + throws ServiceException, ExecutionException, AccessException; + + + /** + * Gets the folder with the specified ID from OMERO, fully loaded. + * + * @param id ID of the folder. + * + * @return See above. + * + * @throws ServiceException Cannot connect to OMERO. + * @throws AccessException Cannot access data. + * @throws NoSuchElementException No element with this ID. + * @throws ExecutionException A Facility can't be retrieved or instantiated. + */ + default Folder getFolder(long id) + throws ServiceException, AccessException, ExecutionException { + List folders = getFolders(id); + if (folders.isEmpty()) { + String msg = format("Folder %d doesn't exist in this context", id); + throw new NoSuchElementException(msg); + } + return folders.iterator().next(); + } + + + /** + * Gets all folders available from OMERO. + * + * @return See above. + * + * @throws ServiceException Cannot connect to OMERO. + * @throws AccessException Cannot access data. + * @throws ExecutionException A Facility can't be retrieved or instantiated. + */ + List getFolders() + throws ExecutionException, AccessException, ServiceException; + + + /** + * Gets all the folders owned by a given user from OMERO. + * + * @param experimenter The user. + * + * @return See above. + * + * @throws ServiceException Cannot connect to OMERO. + * @throws AccessException Cannot access data. + * @throws ExecutionException A Facility can't be retrieved or instantiated. + */ + List getFolders(Experimenter experimenter) + throws ExecutionException, AccessException, ServiceException; + + + /** + * Gets the folders with the specified IDs from OMERO (fully loaded). + * + * @param ids Project IDs + * + * @return See above. + * + * @throws ServiceException Cannot connect to OMERO. + * @throws AccessException Cannot access data. + * @throws ExecutionException A Facility can't be retrieved or instantiated. + */ + List getFolders(Long... ids) + throws ServiceException, AccessException, ExecutionException; + +} diff --git a/src/main/java/fr/igred/omero/containers/Dataset.java b/src/main/java/fr/igred/omero/containers/Dataset.java index 16186871..3a0dd844 100644 --- a/src/main/java/fr/igred/omero/containers/Dataset.java +++ b/src/main/java/fr/igred/omero/containers/Dataset.java @@ -21,11 +21,12 @@ import fr.igred.omero.RemoteObject; import fr.igred.omero.RepositoryObject; import fr.igred.omero.annotations.TagAnnotation; -import fr.igred.omero.client.Browser; +import fr.igred.omero.client.BasicBrowser; +import fr.igred.omero.client.BasicDataManager; import fr.igred.omero.client.Client; import fr.igred.omero.client.ConnectionHandler; -import fr.igred.omero.client.DataManager; import fr.igred.omero.core.Image; +import fr.igred.omero.core.ImageBrowser; import fr.igred.omero.core.ImageWrapper; import fr.igred.omero.exception.AccessException; import fr.igred.omero.exception.ServiceException; @@ -101,7 +102,7 @@ public interface Dataset extends RepositoryObject { * @throws AccessException Cannot access data. * @throws ExecutionException A Facility can't be retrieved or instantiated. */ - default List getProjects(Browser browser) + default List getProjects(ContainersBrowser browser) throws ServiceException, AccessException, ExecutionException { String query = "select link.parent from ProjectDatasetLink as link" + " where link.child=" + getId(); @@ -133,7 +134,7 @@ default List getProjects(Browser browser) * @throws AccessException Cannot access data. * @throws ExecutionException A Facility can't be retrieved or instantiated. */ - List getImages(Browser browser) + List getImages(BasicBrowser browser) throws ServiceException, AccessException, ExecutionException; @@ -149,7 +150,7 @@ List getImages(Browser browser) * @throws AccessException Cannot access data. * @throws ExecutionException A Facility can't be retrieved or instantiated. */ - default List getImages(Browser browser, String name) + default List getImages(BasicBrowser browser, String name) throws ServiceException, AccessException, ExecutionException { List images = getImages(browser); images.removeIf(image -> !image.getName().equals(name)); @@ -169,7 +170,7 @@ default List getImages(Browser browser, String name) * @throws AccessException Cannot access data. * @throws ExecutionException A Facility can't be retrieved or instantiated. */ - default List getImagesLike(Browser browser, String motif) + default List getImagesLike(BasicBrowser browser, String motif) throws ServiceException, AccessException, ExecutionException { List images = getImages(browser); @@ -191,7 +192,7 @@ default List getImagesLike(Browser browser, String motif) * @throws AccessException Cannot access data. * @throws ExecutionException A Facility can't be retrieved or instantiated. */ - default List getImagesTagged(Browser browser, TagAnnotation tag) + default List getImagesTagged(ImageBrowser browser, TagAnnotation tag) throws ServiceException, AccessException, ExecutionException { return getImagesTagged(browser, tag.getId()); } @@ -209,7 +210,7 @@ default List getImagesTagged(Browser browser, TagAnnotation tag) * @throws AccessException Cannot access data. * @throws ExecutionException A Facility can't be retrieved or instantiated. */ - default List getImagesTagged(Browser browser, Long tagId) + default List getImagesTagged(ImageBrowser browser, Long tagId) throws ServiceException, AccessException, ExecutionException { Long[] ids = browser.findByQuery("select link.parent" + " from ImageAnnotationLink link" + @@ -240,7 +241,7 @@ default List getImagesTagged(Browser browser, Long tagId) * @throws AccessException Cannot access data. * @throws ExecutionException A Facility can't be retrieved or instantiated. */ - default List getImagesWithKey(Browser browser, String key) + default List getImagesWithKey(BasicBrowser browser, String key) throws ServiceException, AccessException, ExecutionException { String error = "Cannot get images with key \"" + key + "\" from " + this; Collection images = call(browser.getBrowseFacility(), @@ -279,7 +280,7 @@ default List getImagesWithKey(Browser browser, String key) * @throws AccessException Cannot access data. * @throws ExecutionException A Facility can't be retrieved or instantiated. */ - default List getImagesWithKeyValuePair(Browser browser, String key, String value) + default List getImagesWithKeyValuePair(BasicBrowser browser, String key, String value) throws ServiceException, AccessException, ExecutionException { Collection images = call(browser.getBrowseFacility(), bf -> bf.getImagesForDatasets(browser.getCtx(), @@ -314,7 +315,7 @@ default List getImagesWithKeyValuePair(Browser browser, String key, Strin * @throws AccessException Cannot access data. * @throws ExecutionException A Facility can't be retrieved or instantiated. */ - default void addImages(DataManager dm, Iterable images) + default void addImages(BasicDataManager dm, Iterable images) throws ServiceException, AccessException, ExecutionException { for (Image image : images) { addImage(dm, image); @@ -332,7 +333,7 @@ default void addImages(DataManager dm, Iterable images) * @throws AccessException Cannot access data. * @throws ExecutionException A Facility can't be retrieved or instantiated. */ - default void addImage(DataManager dm, Image image) + default void addImage(BasicDataManager dm, Image image) throws ServiceException, AccessException, ExecutionException { DatasetImageLink link = new DatasetImageLinkI(); link.setChild(image.asDataObject().asImage()); @@ -502,7 +503,7 @@ default List importAndReplaceImages(Client client, String path) * @throws ExecutionException A Facility can't be retrieved or instantiated. */ @Override - void reload(Browser browser) + void reload(BasicBrowser browser) throws ServiceException, AccessException, ExecutionException; } diff --git a/src/main/java/fr/igred/omero/containers/DatasetWrapper.java b/src/main/java/fr/igred/omero/containers/DatasetWrapper.java index cdf8fd1c..5e27ba36 100644 --- a/src/main/java/fr/igred/omero/containers/DatasetWrapper.java +++ b/src/main/java/fr/igred/omero/containers/DatasetWrapper.java @@ -20,7 +20,7 @@ import fr.igred.omero.RemoteObject; import fr.igred.omero.RepositoryObjectWrapper; -import fr.igred.omero.client.Browser; +import fr.igred.omero.client.BasicBrowser; import fr.igred.omero.client.Client; import fr.igred.omero.client.ConnectionHandler; import fr.igred.omero.core.Image; @@ -154,7 +154,7 @@ public List getImages() { * @throws ExecutionException A Facility can't be retrieved or instantiated. */ @Override - public List getImages(Browser browser) + public List getImages(BasicBrowser browser) throws ServiceException, AccessException, ExecutionException { Collection images = call(browser.getBrowseFacility(), bf -> bf.getImagesForDatasets(browser.getCtx(), @@ -284,7 +284,7 @@ public List importAndReplaceImages(Client client, String path, ReplacePoli * @throws ExecutionException A Facility can't be retrieved or instantiated. */ @Override - public void reload(Browser browser) + public void reload(BasicBrowser browser) throws ServiceException, AccessException, ExecutionException { data = call(browser.getBrowseFacility(), bf -> bf.getDatasets(browser.getCtx(), diff --git a/src/main/java/fr/igred/omero/containers/Folder.java b/src/main/java/fr/igred/omero/containers/Folder.java index 795abf13..bfb47da6 100644 --- a/src/main/java/fr/igred/omero/containers/Folder.java +++ b/src/main/java/fr/igred/omero/containers/Folder.java @@ -20,8 +20,8 @@ import fr.igred.omero.RemoteObject; import fr.igred.omero.RepositoryObject; -import fr.igred.omero.client.Browser; -import fr.igred.omero.client.DataManager; +import fr.igred.omero.client.BasicBrowser; +import fr.igred.omero.client.BasicDataManager; import fr.igred.omero.core.Image; import fr.igred.omero.exception.AccessException; import fr.igred.omero.exception.ExceptionHandler; @@ -77,7 +77,7 @@ public interface Folder extends RepositoryObject { * @throws ExecutionException A Facility can't be retrieved or instantiated. */ @Override - default void link(DataManager dm, A annotation) + default void link(BasicDataManager dm, A annotation) throws ServiceException, AccessException, ExecutionException { FolderAnnotationLink link = new FolderAnnotationLinkI(); link.setChild(annotation.asAnnotation()); @@ -154,7 +154,7 @@ default void link(DataManager dm, A annotation) * @throws AccessException Cannot access data. * @throws ExecutionException A Facility can't be retrieved or instantiated. */ - default void addImages(DataManager dm, Image... images) + default void addImages(BasicDataManager dm, Image... images) throws ServiceException, AccessException, ExecutionException { List links = new ArrayList<>(images.length); List linkedIds = getImages().stream() @@ -194,7 +194,7 @@ default void addImages(DataManager dm, Image... images) * @throws AccessException Cannot access data. * @throws ExecutionException A Facility can't be retrieved or instantiated. */ - default List getImages(Browser browser) + default List getImages(BasicBrowser browser) throws AccessException, ServiceException, ExecutionException { reload(browser); return getImages(); @@ -212,7 +212,7 @@ default List getImages(Browser browser) * @throws AccessException Cannot access data. * @throws ExecutionException If the ROIFacility can't be retrieved or instantiated. */ - default void addROIs(DataManager dm, long imageId, ROI... rois) + default void addROIs(BasicDataManager dm, long imageId, ROI... rois) throws ServiceException, AccessException, ExecutionException { List roiData = Arrays.stream(rois) .map(ROI::asDataObject) @@ -239,7 +239,7 @@ default void addROIs(DataManager dm, long imageId, ROI... rois) * @throws AccessException Cannot access data. * @throws ExecutionException If the ROIFacility can't be retrieved or instantiated. */ - default void addROIs(DataManager dm, Image image, ROI... rois) + default void addROIs(BasicDataManager dm, Image image, ROI... rois) throws ServiceException, AccessException, ExecutionException { addROIs(dm, image.getId(), rois); } @@ -257,7 +257,7 @@ default void addROIs(DataManager dm, Image image, ROI... rois) * @throws AccessException Cannot access data. * @throws ExecutionException A Facility can't be retrieved or instantiated. */ - List getROIs(DataManager dm, long imageId) + List getROIs(BasicDataManager dm, long imageId) throws ServiceException, AccessException, ExecutionException; @@ -273,7 +273,7 @@ List getROIs(DataManager dm, long imageId) * @throws AccessException Cannot access data. * @throws ExecutionException A Facility can't be retrieved or instantiated. */ - default List getROIs(DataManager dm, Image image) + default List getROIs(BasicDataManager dm, Image image) throws ServiceException, AccessException, ExecutionException { return getROIs(dm, image.getId()); } @@ -290,7 +290,7 @@ default List getROIs(DataManager dm, Image image) * @throws AccessException Cannot access data. * @throws ExecutionException A Facility can't be retrieved or instantiated. */ - default void unlinkAllROIs(DataManager dm, long imageId) + default void unlinkAllROIs(BasicDataManager dm, long imageId) throws ServiceException, AccessException, ExecutionException { unlinkROIs(dm, getROIs(dm, imageId)); } @@ -307,7 +307,7 @@ default void unlinkAllROIs(DataManager dm, long imageId) * @throws AccessException Cannot access data. * @throws ExecutionException A Facility can't be retrieved or instantiated. */ - default void unlinkAllROIs(DataManager dm, Image image) + default void unlinkAllROIs(BasicDataManager dm, Image image) throws ServiceException, AccessException, ExecutionException { unlinkAllROIs(dm, image.getId()); } @@ -324,7 +324,7 @@ default void unlinkAllROIs(DataManager dm, Image image) * @throws AccessException Cannot access data. * @throws ExecutionException A Facility can't be retrieved or instantiated. */ - void unlinkAllROIs(DataManager dm) + void unlinkAllROIs(BasicDataManager dm) throws ServiceException, AccessException, ExecutionException; @@ -339,7 +339,7 @@ void unlinkAllROIs(DataManager dm) * @throws AccessException Cannot access data. * @throws ExecutionException A Facility can't be retrieved or instantiated. */ - default void unlinkROIs(DataManager dm, ROI... rois) + default void unlinkROIs(BasicDataManager dm, ROI... rois) throws ServiceException, AccessException, ExecutionException { unlinkROIs(dm, Arrays.asList(rois)); } @@ -356,7 +356,7 @@ default void unlinkROIs(DataManager dm, ROI... rois) * @throws AccessException Cannot access data. * @throws ExecutionException A Facility can't be retrieved or instantiated. */ - default void unlinkROIs(DataManager dm, Collection rois) + default void unlinkROIs(BasicDataManager dm, Collection rois) throws ServiceException, AccessException, ExecutionException { List roiData = rois.stream() .map(ROI::asDataObject) diff --git a/src/main/java/fr/igred/omero/containers/FolderWrapper.java b/src/main/java/fr/igred/omero/containers/FolderWrapper.java index c3413ec6..b20c8572 100644 --- a/src/main/java/fr/igred/omero/containers/FolderWrapper.java +++ b/src/main/java/fr/igred/omero/containers/FolderWrapper.java @@ -20,9 +20,9 @@ import fr.igred.omero.RemoteObject; import fr.igred.omero.RepositoryObjectWrapper; -import fr.igred.omero.client.Browser; +import fr.igred.omero.client.BasicBrowser; +import fr.igred.omero.client.BasicDataManager; import fr.igred.omero.client.ConnectionHandler; -import fr.igred.omero.client.DataManager; import fr.igred.omero.core.Image; import fr.igred.omero.core.ImageWrapper; import fr.igred.omero.exception.AccessException; @@ -238,7 +238,7 @@ public List getImages() { * @throws ExecutionException A Facility can't be retrieved or instantiated. */ @Override - public List getROIs(DataManager dm, long imageId) + public List getROIs(BasicDataManager dm, long imageId) throws ServiceException, AccessException, ExecutionException { Collection roiResults = call(dm.getRoiFacility(), rf -> rf.loadROIsForFolder(dm.getCtx(), @@ -269,7 +269,7 @@ public List getROIs(DataManager dm, long imageId) * @throws ExecutionException A Facility can't be retrieved or instantiated. */ @Override - public void unlinkAllROIs(DataManager dm) + public void unlinkAllROIs(BasicDataManager dm) throws ServiceException, AccessException, ExecutionException { Collection rois = wrap(data.copyROILinks(), ROIWrapper::new); unlinkROIs(dm, rois.toArray(EMPTY_ROI_ARRAY)); @@ -286,7 +286,7 @@ public void unlinkAllROIs(DataManager dm) * @throws ExecutionException A Facility can't be retrieved or instantiated. */ @Override - public void reload(Browser browser) + public void reload(BasicBrowser browser) throws AccessException, ServiceException, ExecutionException { data = call(browser.getBrowseFacility(), bf -> bf.loadFolders(browser.getCtx(), diff --git a/src/main/java/fr/igred/omero/containers/Project.java b/src/main/java/fr/igred/omero/containers/Project.java index 44f0a0be..7ef7dffe 100644 --- a/src/main/java/fr/igred/omero/containers/Project.java +++ b/src/main/java/fr/igred/omero/containers/Project.java @@ -21,10 +21,11 @@ import fr.igred.omero.RemoteObject; import fr.igred.omero.RepositoryObject; import fr.igred.omero.annotations.TagAnnotation; -import fr.igred.omero.client.Browser; +import fr.igred.omero.client.BasicBrowser; +import fr.igred.omero.client.BasicDataManager; import fr.igred.omero.client.Client; -import fr.igred.omero.client.DataManager; import fr.igred.omero.core.Image; +import fr.igred.omero.core.ImageBrowser; import fr.igred.omero.exception.AccessException; import fr.igred.omero.exception.ServiceException; import omero.gateway.model.ProjectData; @@ -114,7 +115,7 @@ default List getDatasets(String name) { * @throws AccessException Cannot access data. * @throws ExecutionException A Facility can't be retrieved or instantiated. */ - Dataset addDataset(DataManager dm, String name, String description) + Dataset addDataset(BasicDataManager dm, String name, String description) throws ServiceException, AccessException, ExecutionException; @@ -130,7 +131,7 @@ Dataset addDataset(DataManager dm, String name, String description) * @throws AccessException Cannot access data. * @throws ExecutionException A Facility can't be retrieved or instantiated. */ - default Dataset addDataset(DataManager dm, Dataset dataset) + default Dataset addDataset(BasicDataManager dm, Dataset dataset) throws ServiceException, AccessException, ExecutionException { dataset.saveAndUpdate(dm); ProjectDatasetLink link = new ProjectDatasetLinkI(); @@ -168,7 +169,7 @@ void removeDataset(Client client, Dataset dataset) * @throws AccessException Cannot access data. * @throws ExecutionException A Facility can't be retrieved or instantiated. */ - List getImages(Browser browser) + List getImages(BasicBrowser browser) throws ServiceException, AccessException, ExecutionException; @@ -184,7 +185,7 @@ List getImages(Browser browser) * @throws AccessException Cannot access data. * @throws ExecutionException A Facility can't be retrieved or instantiated. */ - default List getImages(Browser browser, String name) + default List getImages(BasicBrowser browser, String name) throws ServiceException, AccessException, ExecutionException { Collection datasets = getDatasets(); @@ -209,7 +210,7 @@ default List getImages(Browser browser, String name) * @throws AccessException Cannot access data. * @throws ExecutionException A Facility can't be retrieved or instantiated. */ - default List getImages(Browser browser, String datasetName, String imageName) + default List getImages(BasicBrowser browser, String datasetName, String imageName) throws ServiceException, AccessException, ExecutionException { Collection datasets = getDatasets(datasetName); @@ -238,7 +239,7 @@ default List getImages(Browser browser, String datasetName, String imageN * @throws AccessException Cannot access data. * @throws ExecutionException A Facility can't be retrieved or instantiated. */ - default List getImagesLike(Browser browser, String motif) + default List getImagesLike(BasicBrowser browser, String motif) throws ServiceException, AccessException, ExecutionException { Collection datasets = getDatasets(); @@ -262,7 +263,7 @@ default List getImagesLike(Browser browser, String motif) * @throws AccessException Cannot access data. * @throws ExecutionException A Facility can't be retrieved or instantiated. */ - default List getImagesTagged(Browser browser, TagAnnotation tag) + default List getImagesTagged(ImageBrowser browser, TagAnnotation tag) throws ServiceException, AccessException, ExecutionException { Collection datasets = getDatasets(); @@ -286,7 +287,7 @@ default List getImagesTagged(Browser browser, TagAnnotation tag) * @throws AccessException Cannot access data. * @throws ExecutionException A Facility can't be retrieved or instantiated. */ - default List getImagesTagged(Browser browser, Long tagId) + default List getImagesTagged(ImageBrowser browser, Long tagId) throws ServiceException, AccessException, ExecutionException { Collection datasets = getDatasets(); @@ -310,7 +311,7 @@ default List getImagesTagged(Browser browser, Long tagId) * @throws AccessException Cannot access data. * @throws ExecutionException A Facility can't be retrieved or instantiated. */ - default List getImagesWithKey(Browser browser, String key) + default List getImagesWithKey(BasicBrowser browser, String key) throws ServiceException, AccessException, ExecutionException { Collection datasets = getDatasets(); @@ -335,7 +336,7 @@ default List getImagesWithKey(Browser browser, String key) * @throws AccessException Cannot access data. * @throws ExecutionException A Facility can't be retrieved or instantiated. */ - default List getImagesWithKeyValuePair(Browser browser, String key, String value) + default List getImagesWithKeyValuePair(BasicBrowser browser, String key, String value) throws ServiceException, AccessException, ExecutionException { Collection datasets = getDatasets(); diff --git a/src/main/java/fr/igred/omero/containers/ProjectWrapper.java b/src/main/java/fr/igred/omero/containers/ProjectWrapper.java index 4b3edf6d..5d2437a1 100644 --- a/src/main/java/fr/igred/omero/containers/ProjectWrapper.java +++ b/src/main/java/fr/igred/omero/containers/ProjectWrapper.java @@ -19,9 +19,9 @@ import fr.igred.omero.RepositoryObjectWrapper; -import fr.igred.omero.client.Browser; +import fr.igred.omero.client.BasicBrowser; +import fr.igred.omero.client.BasicDataManager; import fr.igred.omero.client.Client; -import fr.igred.omero.client.DataManager; import fr.igred.omero.core.Image; import fr.igred.omero.core.ImageWrapper; import fr.igred.omero.exception.AccessException; @@ -66,7 +66,7 @@ public ProjectWrapper(ProjectData project) { * @throws AccessException Cannot access data. * @throws ExecutionException A Facility can't be retrieved or instantiated. */ - public ProjectWrapper(DataManager dm, String name, String description) + public ProjectWrapper(BasicDataManager dm, String name, String description) throws ServiceException, AccessException, ExecutionException { super(new ProjectData()); data.setName(name); @@ -158,7 +158,7 @@ public List getDatasets() { * @throws ExecutionException A Facility can't be retrieved or instantiated. */ @Override - public Dataset addDataset(DataManager dm, String name, String description) + public Dataset addDataset(BasicDataManager dm, String name, String description) throws ServiceException, AccessException, ExecutionException { Dataset dataset = new DatasetWrapper(name, description); dataset.saveAndUpdate(dm); @@ -197,7 +197,7 @@ public void removeDataset(Client client, Dataset dataset) * @throws ExecutionException A Facility can't be retrieved or instantiated. */ @Override - public List getImages(Browser browser) + public List getImages(BasicBrowser browser) throws ServiceException, AccessException, ExecutionException { List projectIds = singletonList(getId()); Collection images = call(browser.getBrowseFacility(), @@ -218,7 +218,7 @@ public List getImages(Browser browser) * @throws ExecutionException A Facility can't be retrieved or instantiated. */ @Override - public void reload(Browser browser) + public void reload(BasicBrowser browser) throws ServiceException, AccessException, ExecutionException { data = call(browser.getBrowseFacility(), bf -> bf.getProjects(browser.getCtx(), diff --git a/src/main/java/fr/igred/omero/core/Image.java b/src/main/java/fr/igred/omero/core/Image.java index e4acd5c7..4b22057b 100644 --- a/src/main/java/fr/igred/omero/core/Image.java +++ b/src/main/java/fr/igred/omero/core/Image.java @@ -19,10 +19,11 @@ import fr.igred.omero.RepositoryObject; -import fr.igred.omero.client.Browser; +import fr.igred.omero.client.BasicBrowser; +import fr.igred.omero.client.BasicDataManager; import fr.igred.omero.client.Client; import fr.igred.omero.client.ConnectionHandler; -import fr.igred.omero.client.DataManager; +import fr.igred.omero.containers.ContainersBrowser; import fr.igred.omero.containers.Dataset; import fr.igred.omero.containers.Folder; import fr.igred.omero.containers.Project; @@ -32,6 +33,7 @@ import fr.igred.omero.screen.Plate; import fr.igred.omero.screen.PlateAcquisition; import fr.igred.omero.screen.Screen; +import fr.igred.omero.screen.ScreenBrowser; import fr.igred.omero.screen.Well; import fr.igred.omero.screen.WellSample; import fr.igred.omero.util.Bounds; @@ -135,7 +137,7 @@ public interface Image extends RepositoryObject { * @throws AccessException Cannot access data. * @throws ExecutionException A Facility can't be retrieved or instantiated. */ - default List getProjects(Browser browser) + default List getProjects(ContainersBrowser browser) throws ServiceException, AccessException, ExecutionException { List datasets = getDatasets(browser); Collection projects = new ArrayList<>(datasets.size()); @@ -157,7 +159,7 @@ default List getProjects(Browser browser) * @throws AccessException Cannot access data. * @throws ExecutionException A Facility can't be retrieved or instantiated. */ - default List getDatasets(Browser browser) + default List getDatasets(ContainersBrowser browser) throws ServiceException, AccessException, ExecutionException { String query = "select link.parent from DatasetImageLink as link" + " where link.child=" + getId(); @@ -190,7 +192,7 @@ default List getDatasets(Browser browser) * @throws AccessException Cannot access data. * @throws ExecutionException A Facility can't be retrieved or instantiated. */ - default List getWellSamples(Browser browser) + default List getWellSamples(BasicBrowser browser) throws AccessException, ServiceException, ExecutionException { reload(browser); List samples = getWellSamples(); @@ -212,7 +214,7 @@ default List getWellSamples(Browser browser) * @throws AccessException Cannot access data. * @throws ExecutionException A Facility can't be retrieved or instantiated. */ - default List getWells(Browser browser) + default List getWells(ScreenBrowser browser) throws AccessException, ServiceException, ExecutionException { List wellSamples = getWellSamples(browser); @@ -235,7 +237,7 @@ default List getWells(Browser browser) * @throws AccessException Cannot access data. * @throws ExecutionException A Facility can't be retrieved or instantiated. */ - default List getPlateAcquisitions(Browser browser) + default List getPlateAcquisitions(BasicBrowser browser) throws AccessException, ServiceException, ExecutionException { List wellSamples = getWellSamples(browser); @@ -258,7 +260,7 @@ default List getPlateAcquisitions(Browser browser) * @throws AccessException Cannot access data. * @throws ExecutionException A Facility can't be retrieved or instantiated. */ - default List getPlates(Browser browser) + default List getPlates(ScreenBrowser browser) throws AccessException, ServiceException, ExecutionException { return distinct(getWells(browser).stream() .map(Well::getPlate) @@ -277,7 +279,7 @@ default List getPlates(Browser browser) * @throws AccessException Cannot access data. * @throws ExecutionException A Facility can't be retrieved or instantiated. */ - default List getScreens(Browser browser) + default List getScreens(ScreenBrowser browser) throws AccessException, ServiceException, ExecutionException { List plates = getPlates(browser); @@ -299,7 +301,7 @@ default List getScreens(Browser browser) * @throws ServiceException Cannot connect to OMERO. * @throws AccessException Cannot access data. */ - default boolean isOrphaned(Browser browser) + default boolean isOrphaned(BasicBrowser browser) throws ServiceException, AccessException { String dsQuery = "select link.parent from DatasetImageLink link" + " where link.child=" + getId(); @@ -322,7 +324,7 @@ default boolean isOrphaned(Browser browser) * @throws ServiceException Cannot connect to OMERO. * @throws ExecutionException A Facility can't be retrieved or instantiated. */ - default List getFilesetImages(Browser browser) + default List getFilesetImages(ImageBrowser browser) throws AccessException, ServiceException, ExecutionException { List related = new ArrayList<>(0); if (asDataObject().isFSImage()) { @@ -355,7 +357,7 @@ default List getFilesetImages(Browser browser) * @throws AccessException Cannot access data. * @throws ExecutionException A Facility can't be retrieved or instantiated. */ - List saveROIs(DataManager dm, Collection rois) + List saveROIs(BasicDataManager dm, Collection rois) throws ServiceException, AccessException, ExecutionException; @@ -372,7 +374,7 @@ List saveROIs(DataManager dm, Collection rois) * @throws AccessException Cannot access data. * @throws ExecutionException A Facility can't be retrieved or instantiated. */ - default List saveROIs(DataManager dm, ROI... rois) + default List saveROIs(BasicDataManager dm, ROI... rois) throws ServiceException, AccessException, ExecutionException { return saveROIs(dm, Arrays.asList(rois)); } @@ -389,7 +391,7 @@ default List saveROIs(DataManager dm, ROI... rois) * @throws AccessException Cannot access data. * @throws ExecutionException A Facility can't be retrieved or instantiated. */ - List getROIs(DataManager dm) + List getROIs(BasicDataManager dm) throws ServiceException, AccessException, ExecutionException; @@ -404,7 +406,7 @@ List getROIs(DataManager dm) * @throws AccessException Cannot access data. * @throws ExecutionException A Facility can't be retrieved or instantiated. */ - List getROIFolders(DataManager dm) + List getROIFolders(BasicDataManager dm) throws ServiceException, AccessException, ExecutionException; @@ -419,7 +421,7 @@ List getROIFolders(DataManager dm) * @throws AccessException Cannot access data. * @throws ExecutionException A Facility can't be retrieved or instantiated. */ - default List getFolders(Browser browser) + default List getFolders(ContainersBrowser browser) throws ServiceException, AccessException, ExecutionException { String template = "select link.parent from FolderImageLink as link" + " where link.child.id=%d"; @@ -536,7 +538,7 @@ default ImagePlus toImagePlus(Client client, Bounds bounds) * @throws AccessException Cannot access data. * @throws ExecutionException A Facility can't be retrieved or instantiated. */ - List getChannels(Browser browser) + List getChannels(BasicBrowser browser) throws ServiceException, AccessException, ExecutionException; @@ -552,7 +554,7 @@ List getChannels(Browser browser) * @throws AccessException Cannot access data. * @throws ExecutionException A Facility can't be retrieved or instantiated. */ - default String getChannelName(Browser browser, int index) + default String getChannelName(BasicBrowser browser, int index) throws ServiceException, AccessException, ExecutionException { return getChannels(browser).get(index).getChannelLabeling(); } @@ -570,7 +572,7 @@ default String getChannelName(Browser browser, int index) * @throws AccessException Cannot access data. * @throws ExecutionException A Facility can't be retrieved or instantiated. */ - default Color getChannelImportedColor(Browser browser, int index) + default Color getChannelImportedColor(BasicBrowser browser, int index) throws ServiceException, AccessException, ExecutionException { return getChannels(browser).get(index).getColor(); } @@ -641,7 +643,7 @@ BufferedImage getThumbnail(ConnectionHandler conn, int size) * @throws AccessException Cannot access data. * @throws ExecutionException A Facility can't be retrieved or instantiated. */ - List getOriginalPaths(Browser browser) + List getOriginalPaths(BasicBrowser browser) throws ExecutionException, AccessException, ServiceException; @@ -656,7 +658,7 @@ List getOriginalPaths(Browser browser) * @throws AccessException Cannot access data. * @throws ExecutionException A Facility can't be retrieved or instantiated. */ - List getManagedRepositoriesPaths(Browser browser) + List getManagedRepositoriesPaths(BasicBrowser browser) throws ExecutionException, AccessException, ServiceException; diff --git a/src/main/java/fr/igred/omero/core/ImageBrowser.java b/src/main/java/fr/igred/omero/core/ImageBrowser.java new file mode 100644 index 00000000..f1749e87 --- /dev/null +++ b/src/main/java/fr/igred/omero/core/ImageBrowser.java @@ -0,0 +1,188 @@ +package fr.igred.omero.core; + + +import fr.igred.omero.annotations.Annotation; +import fr.igred.omero.client.BasicBrowser; +import fr.igred.omero.exception.AccessException; +import fr.igred.omero.exception.ServiceException; +import fr.igred.omero.meta.Experimenter; + +import java.util.List; +import java.util.NoSuchElementException; +import java.util.concurrent.ExecutionException; + + +public interface ImageBrowser extends BasicBrowser { + + /** + * Returns the image with the specified ID from OMERO. + * + * @param id ID of the image. + * + * @return See above. + * + * @throws ServiceException Cannot connect to OMERO. + * @throws AccessException Cannot access data. + * @throws NoSuchElementException No element with this ID. + * @throws ExecutionException A Facility can't be retrieved or instantiated. + */ + Image getImage(Long id) + throws ServiceException, AccessException, ExecutionException; + + + /** + * Gets the images with the specified ids from OMERO + * + * @param ids Image IDs + * + * @return See above. + * + * @throws ServiceException Cannot connect to OMERO. + * @throws AccessException Cannot access data. + * @throws ExecutionException A Facility can't be retrieved or instantiated. + */ + List getImages(Long... ids) + throws ServiceException, AccessException, ExecutionException; + + + /** + * Gets all images owned by the current user. + * + * @return See above. + * + * @throws ServiceException Cannot connect to OMERO. + * @throws AccessException Cannot access data. + * @throws ExecutionException A Facility can't be retrieved or instantiated. + */ + List getImages() + throws ServiceException, AccessException, ExecutionException; + + + /** + * Gets all images with a certain name from OMERO. + * + * @param name Name searched. + * + * @return See above. + * + * @throws ServiceException Cannot connect to OMERO. + * @throws AccessException Cannot access data. + * @throws ExecutionException A Facility can't be retrieved or instantiated. + */ + List getImages(String name) + throws ServiceException, AccessException, ExecutionException; + + + /** + * Gets all orphaned images owned by the specified user. + * + * @param experimenter The user. + * + * @return See above. + * + * @throws ServiceException Cannot connect to OMERO. + * @throws AccessException Cannot access data. + * @throws ExecutionException A Facility can't be retrieved or instantiated. + */ + List getOrphanedImages(Experimenter experimenter) + throws ServiceException, AccessException, ExecutionException; + + + /** + * Gets all orphaned images owned by the current user. + * + * @return See above. + * + * @throws ServiceException Cannot connect to OMERO. + * @throws AccessException Cannot access data. + * @throws ExecutionException A Facility can't be retrieved or instantiated. + */ + List getOrphanedImages() + throws ServiceException, AccessException, ExecutionException; + + + /** + * Gets all images with the name specified inside projects and datasets with the given names. + * + * @param projectName Expected project name. + * @param datasetName Expected dataset name. + * @param imageName Expected image name. + * + * @return See above. + * + * @throws ServiceException Cannot connect to OMERO. + * @throws AccessException Cannot access data. + * @throws ExecutionException A Facility can't be retrieved or instantiated. + */ + List getImages(String projectName, String datasetName, String imageName) + throws ServiceException, AccessException, ExecutionException; + + + /** + * Gets all images with the specified annotation from OMERO. + * + * @param annotation TagAnnotation containing the tag researched. + * + * @return See above. + * + * @throws ServiceException Cannot connect to OMERO. + * @throws AccessException Cannot access data. + * @throws ExecutionException A Facility can't be retrieved or instantiated. + */ + default List getImages(Annotation annotation) + throws ServiceException, AccessException, ExecutionException { + return annotation.getImages(this); + } + + + /** + * Gets all images with a certain motif in their name from OMERO. + * + * @param motif Motif searched in an image name. + * + * @return See above. + * + * @throws ServiceException Cannot connect to OMERO. + * @throws AccessException Cannot access data. + * @throws ExecutionException A Facility can't be retrieved or instantiated. + */ + default List getImagesLike(String motif) + throws ServiceException, AccessException, ExecutionException { + List images = getImages(); + String regexp = ".*" + motif + ".*"; + images.removeIf(image -> !image.getName().matches(regexp)); + return images; + } + + + /** + * Gets all images with a certain key. + * + * @param key Name of the key researched. + * + * @return See above. + * + * @throws ServiceException Cannot connect to OMERO. + * @throws AccessException Cannot access data. + * @throws ExecutionException A Facility can't be retrieved or instantiated. + */ + List getImagesWithKey(String key) + throws ServiceException, AccessException, ExecutionException; + + + /** + * Gets all images with a certain key value pair from OMERO + * + * @param key Name of the key researched. + * @param value Value associated with the key. + * + * @return See above. + * + * @throws ServiceException Cannot connect to OMERO. + * @throws AccessException Cannot access data. + * @throws ExecutionException A Facility can't be retrieved or instantiated. + */ + List getImagesWithKeyValuePair(String key, String value) + throws ServiceException, AccessException, ExecutionException; + +} diff --git a/src/main/java/fr/igred/omero/core/ImageWrapper.java b/src/main/java/fr/igred/omero/core/ImageWrapper.java index ad5baad5..d1b7c568 100644 --- a/src/main/java/fr/igred/omero/core/ImageWrapper.java +++ b/src/main/java/fr/igred/omero/core/ImageWrapper.java @@ -20,10 +20,10 @@ import fr.igred.omero.RemoteObject; import fr.igred.omero.RepositoryObjectWrapper; -import fr.igred.omero.client.Browser; +import fr.igred.omero.client.BasicBrowser; +import fr.igred.omero.client.BasicDataManager; import fr.igred.omero.client.Client; import fr.igred.omero.client.ConnectionHandler; -import fr.igred.omero.client.DataManager; import fr.igred.omero.containers.Folder; import fr.igred.omero.containers.FolderWrapper; import fr.igred.omero.exception.AccessException; @@ -299,7 +299,7 @@ public List getWellSamples() { * @throws ExecutionException A Facility can't be retrieved or instantiated. */ @Override - public List saveROIs(DataManager dm, Collection rois) + public List saveROIs(BasicDataManager dm, Collection rois) throws ServiceException, AccessException, ExecutionException { rois.forEach(r -> r.setImage(this)); List roisData = rois.stream() @@ -326,7 +326,7 @@ public List saveROIs(DataManager dm, Collection rois) * @throws ExecutionException A Facility can't be retrieved or instantiated. */ @Override - public List getROIs(DataManager dm) + public List getROIs(BasicDataManager dm) throws ServiceException, AccessException, ExecutionException { List roiResults = call(dm.getRoiFacility(), rf -> rf.loadROIs(dm.getCtx(), @@ -356,7 +356,7 @@ public List getROIs(DataManager dm) * @throws ExecutionException A Facility can't be retrieved or instantiated. */ @Override - public List getROIFolders(DataManager dm) + public List getROIFolders(BasicDataManager dm) throws ServiceException, AccessException, ExecutionException { Collection folders = call(dm.getRoiFacility(), rf -> rf.getROIFolders(dm.getCtx(), @@ -510,7 +510,7 @@ public ImagePlus toImagePlus(Client client, * @throws ExecutionException A Facility can't be retrieved or instantiated. */ @Override - public List getChannels(Browser browser) + public List getChannels(BasicBrowser browser) throws ServiceException, AccessException, ExecutionException { String error = "Cannot get the channel name for " + this; List channels = call(browser.getMetadataFacility(), @@ -567,7 +567,7 @@ public BufferedImage getThumbnail(ConnectionHandler conn, int size) * @throws ExecutionException A Facility can't be retrieved or instantiated. */ @Override - public List getOriginalPaths(Browser browser) + public List getOriginalPaths(BasicBrowser browser) throws ExecutionException, AccessException, ServiceException { String error = "Cannot get original paths for " + this; return call(browser.getMetadataFacility(), @@ -588,7 +588,7 @@ public List getOriginalPaths(Browser browser) * @throws ExecutionException A Facility can't be retrieved or instantiated. */ @Override - public List getManagedRepositoriesPaths(Browser browser) + public List getManagedRepositoriesPaths(BasicBrowser browser) throws ExecutionException, AccessException, ServiceException { String error = "Cannot get managed repositories paths for " + this; return call(browser.getMetadataFacility(), @@ -628,7 +628,7 @@ public List download(ConnectionHandler conn, String path) * @throws ExecutionException A Facility can't be retrieved or instantiated. */ @Override - public void reload(Browser browser) + public void reload(BasicBrowser browser) throws ServiceException, AccessException, ExecutionException { data = call(browser.getBrowseFacility(), b -> b.getImage(browser.getCtx(), getId()), diff --git a/src/main/java/fr/igred/omero/core/Pixels.java b/src/main/java/fr/igred/omero/core/Pixels.java index 41bcd959..0fa004f9 100644 --- a/src/main/java/fr/igred/omero/core/Pixels.java +++ b/src/main/java/fr/igred/omero/core/Pixels.java @@ -19,7 +19,7 @@ import fr.igred.omero.RemoteObject; -import fr.igred.omero.client.Browser; +import fr.igred.omero.client.BasicBrowser; import fr.igred.omero.client.ConnectionHandler; import fr.igred.omero.exception.AccessException; import fr.igred.omero.exception.ServiceException; @@ -54,12 +54,12 @@ public interface Pixels extends RemoteObject { * @throws AccessException Cannot access data. * @throws ExecutionException A Facility can't be retrieved or instantiated. */ - void loadPlanesInfo(Browser browser) + void loadPlanesInfo(BasicBrowser browser) throws ServiceException, AccessException, ExecutionException; /** - * Retrieves the planes information (which need to be {@link #loadPlanesInfo(Browser) loaded} first). + * Retrieves the planes information (which need to be {@link #loadPlanesInfo(BasicBrowser) loaded} first). * * @return See above. */ @@ -108,7 +108,7 @@ void loadPlanesInfo(Browser browser) /** * Computes the mean time interval from the planes deltaTs. - *

Planes information needs to be {@link #loadPlanesInfo(Browser) loaded} first.

+ *

Planes information needs to be {@link #loadPlanesInfo(BasicBrowser) loaded} first.

* * @return See above. */ @@ -117,7 +117,7 @@ void loadPlanesInfo(Browser browser) /** * Computes the mean exposure time for a given channel from the planes exposureTime. - *

Planes information needs to be {@link #loadPlanesInfo(Browser) loaded} first.

+ *

Planes information needs to be {@link #loadPlanesInfo(BasicBrowser) loaded} first.

* * @param channel The channel index. * @@ -128,7 +128,7 @@ void loadPlanesInfo(Browser browser) /** * Retrieves the X stage position, using the same unit as {@link #getPixelSizeX()} if possible. - *

Planes information needs to be {@link #loadPlanesInfo(Browser) loaded} first.

+ *

Planes information needs to be {@link #loadPlanesInfo(BasicBrowser) loaded} first.

* * @return See above. */ @@ -137,7 +137,7 @@ void loadPlanesInfo(Browser browser) /** * Retrieves the Y stage position, using the same unit as {@link #getPixelSizeY()} if possible. - *

Planes information needs to be {@link #loadPlanesInfo(Browser) loaded} first.

+ *

Planes information needs to be {@link #loadPlanesInfo(BasicBrowser) loaded} first.

* * @return See above. */ @@ -146,7 +146,7 @@ void loadPlanesInfo(Browser browser) /** * Retrieves the Z stage position, using the same unit as {@link #getPixelSizeZ()} if possible. - *

Planes information needs to be {@link #loadPlanesInfo(Browser) loaded} first.

+ *

Planes information needs to be {@link #loadPlanesInfo(BasicBrowser) loaded} first.

* * @return See above. */ diff --git a/src/main/java/fr/igred/omero/core/PixelsWrapper.java b/src/main/java/fr/igred/omero/core/PixelsWrapper.java index d525a7ac..142b1b80 100644 --- a/src/main/java/fr/igred/omero/core/PixelsWrapper.java +++ b/src/main/java/fr/igred/omero/core/PixelsWrapper.java @@ -19,7 +19,7 @@ import fr.igred.omero.ObjectWrapper; -import fr.igred.omero.client.Browser; +import fr.igred.omero.client.BasicBrowser; import fr.igred.omero.client.ConnectionHandler; import fr.igred.omero.exception.AccessException; import fr.igred.omero.exception.ExceptionHandler; @@ -148,7 +148,7 @@ private static int[] checkBounds(int[] bounds, int imageSize) { * @throws ExecutionException A Facility can't be retrieved or instantiated. */ @Override - public void loadPlanesInfo(Browser browser) + public void loadPlanesInfo(BasicBrowser browser) throws ServiceException, AccessException, ExecutionException { List planes = call(browser.getMetadataFacility(), m -> m.getPlaneInfos(browser.getCtx(), @@ -159,7 +159,7 @@ public void loadPlanesInfo(Browser browser) /** - * Retrieves the planes information (which need to be {@link #loadPlanesInfo(Browser) loaded} first). + * Retrieves the planes information (which need to be {@link #loadPlanesInfo(BasicBrowser) loaded} first). * * @return See above. */ @@ -226,7 +226,7 @@ public Time getTimeIncrement() { /** * Computes the mean time interval from the planes deltaTs. - *

Planes information needs to be {@link #loadPlanesInfo(Browser) loaded} first.

+ *

Planes information needs to be {@link #loadPlanesInfo(BasicBrowser) loaded} first.

* * @return See above. */ @@ -238,7 +238,7 @@ public Time getMeanTimeInterval() { /** * Computes the mean exposure time for a given channel from the planes exposureTime. - *

Planes information needs to be {@link #loadPlanesInfo(Browser) loaded} first.

+ *

Planes information needs to be {@link #loadPlanesInfo(BasicBrowser) loaded} first.

* * @param channel The channel index. * @@ -252,7 +252,7 @@ public Time getMeanExposureTime(int channel) { /** * Retrieves the X stage position, using the same unit as {@link #getPixelSizeX()} if possible. - *

Planes information needs to be {@link #loadPlanesInfo(Browser) loaded} first.

+ *

Planes information needs to be {@link #loadPlanesInfo(BasicBrowser) loaded} first.

* * @return See above. */ @@ -276,7 +276,7 @@ public Length getPositionX() { /** * Retrieves the Y stage position, using the same unit as {@link #getPixelSizeY()} if possible. - *

Planes information needs to be {@link #loadPlanesInfo(Browser) loaded} first.

+ *

Planes information needs to be {@link #loadPlanesInfo(BasicBrowser) loaded} first.

* * @return See above. */ @@ -300,7 +300,7 @@ public Length getPositionY() { /** * Retrieves the Z stage position, using the same unit as {@link #getPixelSizeZ()} if possible. - *

Planes information needs to be {@link #loadPlanesInfo(Browser) loaded} first.

+ *

Planes information needs to be {@link #loadPlanesInfo(BasicBrowser) loaded} first.

* * @return See above. */ diff --git a/src/main/java/fr/igred/omero/meta/BasicAdmin.java b/src/main/java/fr/igred/omero/meta/BasicAdmin.java new file mode 100644 index 00000000..19552870 --- /dev/null +++ b/src/main/java/fr/igred/omero/meta/BasicAdmin.java @@ -0,0 +1,43 @@ +package fr.igred.omero.meta; + + +import fr.igred.omero.exception.AccessException; +import fr.igred.omero.exception.ServiceException; +import omero.api.IAdminPrx; +import omero.gateway.SecurityContext; +import omero.gateway.facility.AdminFacility; + +import java.util.concurrent.ExecutionException; + + +public interface BasicAdmin { + + /** + * Returns the current {@link SecurityContext}. + * + * @return See above + */ + SecurityContext getCtx(); + + + /** + * Gets the {@link AdminFacility} to use admin specific function. + * + * @return See above. + * + * @throws ExecutionException If the AdminFacility can't be retrieved or instantiated. + */ + AdminFacility getAdminFacility() throws ExecutionException; + + + /** + * Returns the {@link IAdminPrx} to use admin specific function. + * + * @return See above. + * + * @throws AccessException Cannot access data. + * @throws ServiceException Cannot connect to OMERO. + */ + IAdminPrx getAdminService() throws AccessException, ServiceException; + +} diff --git a/src/main/java/fr/igred/omero/meta/Experimenter.java b/src/main/java/fr/igred/omero/meta/Experimenter.java index e447913e..a56df79f 100644 --- a/src/main/java/fr/igred/omero/meta/Experimenter.java +++ b/src/main/java/fr/igred/omero/meta/Experimenter.java @@ -19,7 +19,6 @@ import fr.igred.omero.RemoteObject; -import fr.igred.omero.client.AdminManager; import fr.igred.omero.exception.AccessException; import fr.igred.omero.exception.ServiceException; import omero.gateway.model.ExperimenterData; @@ -193,7 +192,7 @@ public interface Experimenter extends RemoteObject { * @throws AccessException Cannot access data. * @throws ExecutionException A Facility can't be retrieved or instantiated. */ - boolean isAdmin(AdminManager admin) + boolean isAdmin(BasicAdmin admin) throws ServiceException, AccessException, ExecutionException; } diff --git a/src/main/java/fr/igred/omero/meta/ExperimenterWrapper.java b/src/main/java/fr/igred/omero/meta/ExperimenterWrapper.java index 2c8f891b..7ff58a64 100644 --- a/src/main/java/fr/igred/omero/meta/ExperimenterWrapper.java +++ b/src/main/java/fr/igred/omero/meta/ExperimenterWrapper.java @@ -19,7 +19,6 @@ import fr.igred.omero.ObjectWrapper; -import fr.igred.omero.client.AdminManager; import fr.igred.omero.exception.AccessException; import fr.igred.omero.exception.ServiceException; import omero.gateway.model.ExperimenterData; @@ -251,7 +250,7 @@ public boolean isLeader(Group group) { * @throws ExecutionException A Facility can't be retrieved or instantiated. */ @Override - public boolean isAdmin(AdminManager admin) + public boolean isAdmin(BasicAdmin admin) throws ServiceException, AccessException, ExecutionException { return !call(admin.getAdminFacility(), a -> a.getAdminPrivileges(admin.getCtx(), data), diff --git a/src/main/java/fr/igred/omero/roi/ROI.java b/src/main/java/fr/igred/omero/roi/ROI.java index 42e8932e..1dab7300 100644 --- a/src/main/java/fr/igred/omero/roi/ROI.java +++ b/src/main/java/fr/igred/omero/roi/ROI.java @@ -19,7 +19,7 @@ import fr.igred.omero.Annotatable; -import fr.igred.omero.client.DataManager; +import fr.igred.omero.client.BasicDataManager; import fr.igred.omero.core.Image; import fr.igred.omero.exception.AccessException; import fr.igred.omero.exception.ServiceException; @@ -299,7 +299,7 @@ default void addShapes(Iterable shapes) { * @throws ServiceException Cannot connect to OMERO. * @throws ExecutionException A Facility can't be retrieved or instantiated. */ - void saveROI(DataManager dm) + void saveROI(BasicDataManager dm) throws AccessException, ServiceException, ExecutionException; @@ -365,7 +365,7 @@ default List toImageJ() { * @throws ExecutionException A Facility can't be retrieved or instantiated. */ @Override - default
void link(DataManager dm, A annotation) + default void link(BasicDataManager dm, A annotation) throws ServiceException, AccessException, ExecutionException { RoiAnnotationLink link = new RoiAnnotationLinkI(); link.setChild(annotation.asAnnotation()); diff --git a/src/main/java/fr/igred/omero/roi/ROIWrapper.java b/src/main/java/fr/igred/omero/roi/ROIWrapper.java index bb37f834..a0775edc 100644 --- a/src/main/java/fr/igred/omero/roi/ROIWrapper.java +++ b/src/main/java/fr/igred/omero/roi/ROIWrapper.java @@ -19,7 +19,7 @@ import fr.igred.omero.AnnotatableWrapper; -import fr.igred.omero.client.DataManager; +import fr.igred.omero.client.BasicDataManager; import fr.igred.omero.core.Image; import fr.igred.omero.exception.AccessException; import fr.igred.omero.exception.ServiceException; @@ -272,7 +272,7 @@ public void deleteShape(int pos) { * @throws ExecutionException A Facility can't be retrieved or instantiated. */ @Override - public void saveROI(DataManager dm) + public void saveROI(BasicDataManager dm) throws AccessException, ServiceException, ExecutionException { Roi roi = (Roi) dm.save(data.asIObject()); data = new ROIData(roi); diff --git a/src/main/java/fr/igred/omero/roi/Shape.java b/src/main/java/fr/igred/omero/roi/Shape.java index 277a054f..b8d0d066 100644 --- a/src/main/java/fr/igred/omero/roi/Shape.java +++ b/src/main/java/fr/igred/omero/roi/Shape.java @@ -19,7 +19,7 @@ import fr.igred.omero.Annotatable; -import fr.igred.omero.client.DataManager; +import fr.igred.omero.client.BasicDataManager; import fr.igred.omero.exception.AccessException; import fr.igred.omero.exception.ServiceException; import ij.gui.Roi; @@ -278,7 +278,7 @@ default java.awt.Shape createTransformedAWTShape() { * @throws ExecutionException A Facility can't be retrieved or instantiated. */ @Override - default void link(DataManager dm, A annotation) + default void link(BasicDataManager dm, A annotation) throws ServiceException, AccessException, ExecutionException { ShapeAnnotationLink link = new ShapeAnnotationLinkI(); link.setChild(annotation.asAnnotation()); diff --git a/src/main/java/fr/igred/omero/screen/Plate.java b/src/main/java/fr/igred/omero/screen/Plate.java index e4128c13..acf471c1 100644 --- a/src/main/java/fr/igred/omero/screen/Plate.java +++ b/src/main/java/fr/igred/omero/screen/Plate.java @@ -20,7 +20,7 @@ import fr.igred.omero.RemoteObject; import fr.igred.omero.RepositoryObject; -import fr.igred.omero.client.Browser; +import fr.igred.omero.client.BasicBrowser; import fr.igred.omero.core.Image; import fr.igred.omero.exception.AccessException; import fr.igred.omero.exception.ServiceException; @@ -87,7 +87,7 @@ public interface Plate extends RepositoryObject { * @throws AccessException Cannot access data. * @throws ExecutionException A Facility can't be retrieved or instantiated. */ - default List getScreens(Browser browser) + default List getScreens(ScreenBrowser browser) throws ServiceException, AccessException, ExecutionException { String query = "select link.parent from ScreenPlateLink as link" + " where link.child=" + getId(); @@ -119,7 +119,7 @@ default List getScreens(Browser browser) * @throws AccessException Cannot access data. * @throws ExecutionException A Facility can't be retrieved or instantiated. */ - List getWells(Browser browser) + List getWells(BasicBrowser browser) throws ServiceException, AccessException, ExecutionException; @@ -134,7 +134,7 @@ List getWells(Browser browser) * @throws AccessException Cannot access data. * @throws ExecutionException A Facility can't be retrieved or instantiated. */ - default List getImages(Browser browser) + default List getImages(BasicBrowser browser) throws ServiceException, AccessException, ExecutionException { return getWells(browser).stream() .map(Well::getImages) diff --git a/src/main/java/fr/igred/omero/screen/PlateAcquisition.java b/src/main/java/fr/igred/omero/screen/PlateAcquisition.java index 116e2e2d..51329a96 100644 --- a/src/main/java/fr/igred/omero/screen/PlateAcquisition.java +++ b/src/main/java/fr/igred/omero/screen/PlateAcquisition.java @@ -19,8 +19,8 @@ import fr.igred.omero.RepositoryObject; -import fr.igred.omero.client.Browser; -import fr.igred.omero.client.DataManager; +import fr.igred.omero.client.BasicBrowser; +import fr.igred.omero.client.BasicDataManager; import fr.igred.omero.core.Image; import fr.igred.omero.exception.AccessException; import fr.igred.omero.exception.ServiceException; @@ -83,7 +83,7 @@ public interface PlateAcquisition extends RepositoryObject { * @throws ExecutionException A Facility can't be retrieved or instantiated. */ @Override - default void link(DataManager dm, A annotation) + default void link(BasicDataManager dm, A annotation) throws ServiceException, AccessException, ExecutionException { PlateAcquisitionAnnotationLink link = new PlateAcquisitionAnnotationLinkI(); link.setChild(annotation.asAnnotation()); @@ -103,7 +103,7 @@ default void link(DataManager dm, A annotation) * @throws AccessException Cannot access data. * @throws ExecutionException A Facility can't be retrieved or instantiated. */ - default List getScreens(Browser browser) + default List getScreens(ScreenBrowser browser) throws ServiceException, AccessException, ExecutionException { Plate plate = browser.getPlate(getRefPlateId()); return plate.getScreens(browser); @@ -121,7 +121,7 @@ default List getScreens(Browser browser) * @throws AccessException Cannot access data. * @throws ExecutionException A Facility can't be retrieved or instantiated. */ - default List getPlates(Browser browser) + default List getPlates(ScreenBrowser browser) throws ServiceException, AccessException, ExecutionException { return browser.getPlates(getRefPlateId()); } @@ -138,7 +138,7 @@ default List getPlates(Browser browser) * @throws AccessException Cannot access data. * @throws ExecutionException A Facility can't be retrieved or instantiated. */ - default List getWells(Browser browser) + default List getWells(ScreenBrowser browser) throws ServiceException, AccessException, ExecutionException { return getPlates(browser).iterator().next().getWells(browser); } @@ -162,7 +162,7 @@ default List getWells(Browser browser) * @throws ServiceException Cannot connect to OMERO. * @throws AccessException Cannot access data. */ - default List getWellSamples(Browser browser) + default List getWellSamples(BasicBrowser browser) throws AccessException, ServiceException { reload(browser); return getWellSamples(); @@ -191,7 +191,7 @@ default List getImages() { * @throws ServiceException Cannot connect to OMERO. * @throws AccessException Cannot access data. */ - default List getImages(Browser browser) + default List getImages(BasicBrowser browser) throws ServiceException, AccessException { return getWellSamples(browser).stream() .map(WellSample::getImage) @@ -256,7 +256,7 @@ default List getImages(Browser browser) * @throws AccessException Cannot access data. */ @Override - void reload(Browser browser) + void reload(BasicBrowser browser) throws ServiceException, AccessException; } diff --git a/src/main/java/fr/igred/omero/screen/PlateAcquisitionWrapper.java b/src/main/java/fr/igred/omero/screen/PlateAcquisitionWrapper.java index 69365829..75eaea6a 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.BasicBrowser; import fr.igred.omero.exception.AccessException; import fr.igred.omero.exception.ServiceException; import omero.gateway.model.PlateAcquisitionData; @@ -212,7 +212,7 @@ public int getMaximumFieldCount() { * @throws AccessException Cannot access data. */ @Override - public void reload(Browser browser) + public void reload(BasicBrowser 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 c154973b..dab5be9c 100644 --- a/src/main/java/fr/igred/omero/screen/PlateWrapper.java +++ b/src/main/java/fr/igred/omero/screen/PlateWrapper.java @@ -19,7 +19,7 @@ import fr.igred.omero.RepositoryObjectWrapper; -import fr.igred.omero.client.Browser; +import fr.igred.omero.client.BasicBrowser; import fr.igred.omero.exception.AccessException; import fr.igred.omero.exception.ServiceException; import ome.model.units.BigResult; @@ -135,7 +135,7 @@ public List getPlateAcquisitions() { * @throws ExecutionException A Facility can't be retrieved or instantiated. */ @Override - public List getWells(Browser browser) + public List getWells(BasicBrowser browser) throws ServiceException, AccessException, ExecutionException { Collection wells = call(browser.getBrowseFacility(), bf -> bf.getWells(browser.getCtx(), @@ -289,7 +289,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(BasicBrowser 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/Screen.java b/src/main/java/fr/igred/omero/screen/Screen.java index 0fa823f1..e53262dd 100644 --- a/src/main/java/fr/igred/omero/screen/Screen.java +++ b/src/main/java/fr/igred/omero/screen/Screen.java @@ -19,7 +19,7 @@ import fr.igred.omero.RepositoryObject; -import fr.igred.omero.client.Browser; +import fr.igred.omero.client.BasicBrowser; import fr.igred.omero.client.ConnectionHandler; import fr.igred.omero.core.Image; import fr.igred.omero.exception.AccessException; @@ -107,7 +107,7 @@ default List getPlates(String name) { * @throws AccessException Cannot access data. * @throws ExecutionException A Facility can't be retrieved or instantiated. */ - default List getPlateAcquisitions(Browser browser) + default List getPlateAcquisitions(BasicBrowser browser) throws ServiceException, AccessException, ExecutionException { reload(browser); return getPlates().stream() @@ -133,7 +133,7 @@ default List getPlateAcquisitions(Browser browser) * @throws AccessException Cannot access data. * @throws ExecutionException A Facility can't be retrieved or instantiated. */ - default List getWells(Browser browser) + default List getWells(BasicBrowser browser) throws ServiceException, AccessException, ExecutionException { List plates = getPlates(); Collection> wells = new ArrayList<>(plates.size()); @@ -155,7 +155,7 @@ default List getWells(Browser browser) * @throws AccessException Cannot access data. * @throws ExecutionException A Facility can't be retrieved or instantiated. */ - default List getImages(Browser browser) + default List getImages(BasicBrowser browser) throws ServiceException, AccessException, ExecutionException { List plates = getPlates(); Collection> images = new ArrayList<>(plates.size()); diff --git a/src/main/java/fr/igred/omero/screen/ScreenBrowser.java b/src/main/java/fr/igred/omero/screen/ScreenBrowser.java new file mode 100644 index 00000000..83594060 --- /dev/null +++ b/src/main/java/fr/igred/omero/screen/ScreenBrowser.java @@ -0,0 +1,275 @@ +package fr.igred.omero.screen; + + +import fr.igred.omero.client.BasicBrowser; +import fr.igred.omero.exception.AccessException; +import fr.igred.omero.exception.ServiceException; +import fr.igred.omero.meta.Experimenter; +import omero.RLong; +import omero.model.IObject; + +import java.util.List; +import java.util.NoSuchElementException; +import java.util.concurrent.ExecutionException; + +import static java.lang.String.format; + + +public interface ScreenBrowser extends BasicBrowser { + + /** + * Gets the screen with the specified id from OMERO. + * + * @param id ID of the screen. + * + * @return See above. + * + * @throws ServiceException Cannot connect to OMERO. + * @throws AccessException Cannot access data. + * @throws NoSuchElementException No element with this ID. + * @throws ExecutionException A Facility can't be retrieved or instantiated. + */ + default Screen getScreen(Long id) + throws ServiceException, AccessException, ExecutionException { + List screens = getScreens(id); + if (screens.isEmpty()) { + String msg = format("Screen %d doesn't exist in this context", id); + throw new NoSuchElementException(msg); + } + return screens.iterator().next(); + } + + + /** + * Gets the screens with the specified ids from OMERO. + * + * @param ids A list of screen ids + * + * @return See above. + * + * @throws ServiceException Cannot connect to OMERO. + * @throws AccessException Cannot access data. + * @throws ExecutionException A Facility can't be retrieved or instantiated. + */ + List getScreens(Long... ids) + throws ServiceException, AccessException, ExecutionException; + + + /** + * Gets all screens available from OMERO. + * + * @return See above. + * + * @throws ServiceException Cannot connect to OMERO. + * @throws AccessException Cannot access data. + * @throws ExecutionException A Facility can't be retrieved or instantiated. + */ + List getScreens() + throws ServiceException, AccessException, ExecutionException; + + + /** + * Gets all screens available from OMERO owned by a given user. + * + * @param experimenter The user. + * + * @return See above. + * + * @throws ServiceException Cannot connect to OMERO. + * @throws AccessException Cannot access data. + * @throws ExecutionException A Facility can't be retrieved or instantiated. + */ + List getScreens(Experimenter experimenter) + throws ServiceException, AccessException, ExecutionException; + + + /** + * Gets the plate with the specified id from OMERO. + * + * @param id ID of the plate. + * + * @return See above. + * + * @throws ServiceException Cannot connect to OMERO. + * @throws AccessException Cannot access data. + * @throws NoSuchElementException No element with this ID. + * @throws ExecutionException A Facility can't be retrieved or instantiated. + */ + default Plate getPlate(Long id) + throws ServiceException, AccessException, ExecutionException { + List plates = getPlates(id); + if (plates.isEmpty()) { + String msg = format("Plate %d doesn't exist in this context", id); + throw new NoSuchElementException(msg); + } + return plates.iterator().next(); + } + + + /** + * Gets the plates with the specified ids from OMERO. + * + * @param ids A list of plate ids + * + * @return See above. + * + * @throws ServiceException Cannot connect to OMERO. + * @throws AccessException Cannot access data. + * @throws ExecutionException A Facility can't be retrieved or instantiated. + */ + List getPlates(Long... ids) + throws ServiceException, AccessException, ExecutionException; + + + /** + * Gets all plates available from OMERO. + * + * @return See above. + * + * @throws ServiceException Cannot connect to OMERO. + * @throws AccessException Cannot access data. + * @throws ExecutionException A Facility can't be retrieved or instantiated. + */ + List getPlates() + throws ServiceException, AccessException, ExecutionException; + + + /** + * Gets all plates available from OMERO owned by a given user. + * + * @param experimenter The user. + * + * @return See above. + * + * @throws ServiceException Cannot connect to OMERO. + * @throws AccessException Cannot access data. + * @throws ExecutionException A Facility can't be retrieved or instantiated. + */ + List getPlates(Experimenter experimenter) + throws ServiceException, AccessException, ExecutionException; + + + /** + * Gets all orphaned plates available from OMERO owned by a given user. + * + * @param experimenter The user. + * + * @return See above. + * + * @throws ServiceException Cannot connect to OMERO. + * @throws AccessException Cannot access data. + * @throws ExecutionException A Facility can't be retrieved or instantiated. + */ + default List getOrphanedPlates(Experimenter experimenter) + throws ServiceException, ExecutionException, AccessException { + String template = "select plate from Plate as plate" + + " join fetch plate.details.owner as o" + + " where o.id = %d" + + " and not exists" + + " (select obl from ScreenPlateLink as obl" + + " where obl.child = plate.id)"; + String query = format(template, experimenter.getId()); + Long[] ids = this.findByQuery(query) + .stream() + .map(IObject::getId) + .map(RLong::getValue) + .toArray(Long[]::new); + return getPlates(ids); + } + + + /** + * Gets all orphaned plates available from OMERO for the current user. + * + * @return See above. + * + * @throws ServiceException Cannot connect to OMERO. + * @throws AccessException Cannot access data. + * @throws ExecutionException A Facility can't be retrieved or instantiated. + */ + List getOrphanedPlates() + throws ServiceException, ExecutionException, AccessException; + + + /** + * Gets the well with the specified id from OMERO. + * + * @param id ID of the well. + * + * @return See above. + * + * @throws ServiceException Cannot connect to OMERO. + * @throws AccessException Cannot access data. + * @throws NoSuchElementException No element with this ID. + * @throws ExecutionException A Facility can't be retrieved or instantiated. + */ + default Well getWell(Long id) + throws ServiceException, AccessException, ExecutionException { + List wells = getWells(id); + if (wells.isEmpty()) { + String msg = format("Plate %d doesn't exist in this context", id); + throw new NoSuchElementException(msg); + } + return wells.iterator().next(); + } + + + /** + * Gets the wells with the specified ids from OMERO. + * + * @param ids A list of well ids + * + * @return See above. + * + * @throws ServiceException Cannot connect to OMERO. + * @throws AccessException Cannot access data. + * @throws ExecutionException A Facility can't be retrieved or instantiated. + */ + List getWells(Long... ids) + throws ServiceException, AccessException, ExecutionException; + + + /** + * Gets all wells available from OMERO. + * + * @return See above. + * + * @throws ServiceException Cannot connect to OMERO. + * @throws AccessException Cannot access data. + * @throws ExecutionException A Facility can't be retrieved or instantiated. + */ + default List getWells() + throws ServiceException, AccessException, ExecutionException { + Long[] ids = this.findByQuery("select w from Well w") + .stream() + .map(IObject::getId) + .map(RLong::getValue) + .toArray(Long[]::new); + return getWells(ids); + } + + + /** + * Gets all wells available from OMERO owned by a given user. + * + * @param experimenter The user. + * + * @return See above. + * + * @throws ServiceException Cannot connect to OMERO. + * @throws AccessException Cannot access data. + * @throws ExecutionException A Facility can't be retrieved or instantiated. + */ + default List getWells(Experimenter experimenter) + throws ServiceException, AccessException, ExecutionException { + String template = "select w from Well w where w.details.owner.id=%d"; + String query = format(template, experimenter.getId()); + Long[] ids = this.findByQuery(query) + .stream() + .map(IObject::getId) + .map(RLong::getValue) + .toArray(Long[]::new); + return getWells(ids); + } + +} diff --git a/src/main/java/fr/igred/omero/screen/ScreenWrapper.java b/src/main/java/fr/igred/omero/screen/ScreenWrapper.java index 56e148fa..f752a2f5 100644 --- a/src/main/java/fr/igred/omero/screen/ScreenWrapper.java +++ b/src/main/java/fr/igred/omero/screen/ScreenWrapper.java @@ -19,9 +19,9 @@ import fr.igred.omero.RepositoryObjectWrapper; -import fr.igred.omero.client.Browser; +import fr.igred.omero.client.BasicBrowser; +import fr.igred.omero.client.BasicDataManager; import fr.igred.omero.client.ConnectionHandler; -import fr.igred.omero.client.DataManager; import fr.igred.omero.exception.AccessException; import fr.igred.omero.exception.ServiceException; import omero.gateway.model.ScreenData; @@ -52,7 +52,7 @@ public class ScreenWrapper extends RepositoryObjectWrapper implement * @throws AccessException Cannot access data. * @throws ExecutionException A Facility can't be retrieved or instantiated. */ - public ScreenWrapper(DataManager dm, String name, String description) + public ScreenWrapper(BasicDataManager dm, String name, String description) throws ServiceException, AccessException, ExecutionException { super(new ScreenData()); data.setName(name); @@ -237,7 +237,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(BasicBrowser browser) throws ServiceException, AccessException, ExecutionException { data = call(browser.getBrowseFacility(), bf -> bf.getScreens(browser.getCtx(), diff --git a/src/main/java/fr/igred/omero/screen/Well.java b/src/main/java/fr/igred/omero/screen/Well.java index d3f0c0a7..f5a0f90c 100644 --- a/src/main/java/fr/igred/omero/screen/Well.java +++ b/src/main/java/fr/igred/omero/screen/Well.java @@ -19,7 +19,6 @@ import fr.igred.omero.RepositoryObject; -import fr.igred.omero.client.Browser; import fr.igred.omero.core.Image; import fr.igred.omero.exception.AccessException; import fr.igred.omero.exception.ServiceException; @@ -67,7 +66,7 @@ public interface Well extends RepositoryObject { * @throws AccessException Cannot access data. * @throws ExecutionException A Facility can't be retrieved or instantiated. */ - default List getScreens(Browser browser) + default List getScreens(ScreenBrowser browser) throws ServiceException, AccessException, ExecutionException { reload(browser); return getPlate().getScreens(browser); @@ -93,7 +92,7 @@ default List getScreens(Browser browser) * @throws AccessException Cannot access data. * @throws ExecutionException A Facility can't be retrieved or instantiated. */ - default List getPlateAcquisitions(Browser browser) + default List getPlateAcquisitions(ScreenBrowser browser) throws ServiceException, AccessException, ExecutionException { reload(browser); return browser.getPlate(getPlate().getId()).getPlateAcquisitions(); diff --git a/src/main/java/fr/igred/omero/screen/WellSample.java b/src/main/java/fr/igred/omero/screen/WellSample.java index 891a59c8..729327fa 100644 --- a/src/main/java/fr/igred/omero/screen/WellSample.java +++ b/src/main/java/fr/igred/omero/screen/WellSample.java @@ -19,7 +19,7 @@ import fr.igred.omero.RemoteObject; -import fr.igred.omero.client.Browser; +import fr.igred.omero.client.BasicBrowser; import fr.igred.omero.core.Image; import fr.igred.omero.exception.AccessException; import fr.igred.omero.exception.ServiceException; @@ -58,7 +58,7 @@ public interface WellSample extends RemoteObject { * @throws AccessException Cannot access data. * @throws ExecutionException A Facility can't be retrieved or instantiated. */ - default List getScreens(Browser browser) + default List getScreens(ScreenBrowser browser) throws ServiceException, AccessException, ExecutionException { return getWell(browser).getScreens(browser); } @@ -75,7 +75,7 @@ default List getScreens(Browser browser) * @throws AccessException Cannot access data. * @throws ExecutionException A Facility can't be retrieved or instantiated. */ - default List getPlates(Browser browser) + default List getPlates(ScreenBrowser browser) throws ServiceException, AccessException, ExecutionException { return Collections.singletonList(getWell(browser).getPlate()); } @@ -100,7 +100,7 @@ default List getPlates(Browser browser) * @throws AccessException Cannot access data. * @throws ExecutionException A Facility can't be retrieved or instantiated. */ - default List getPlateAcquisitions(Browser browser) + default List getPlateAcquisitions(ScreenBrowser browser) throws ServiceException, AccessException, ExecutionException { return getWell(browser).getPlateAcquisitions(browser); } @@ -117,7 +117,7 @@ default List getPlateAcquisitions(Browser browser) * @throws AccessException Cannot access data. * @throws ExecutionException A Facility can't be retrieved or instantiated. */ - default Well getWell(Browser browser) + default Well getWell(ScreenBrowser browser) throws AccessException, ServiceException, ExecutionException { return browser.getWell(asDataObject().asWellSample().getWell().getId().getValue()); } @@ -179,7 +179,7 @@ default Well getWell(Browser browser) * @throws ServiceException Cannot connect to OMERO. * @throws AccessException Cannot access data. */ - void reload(Browser browser) + void reload(BasicBrowser browser) throws ServiceException, AccessException; } diff --git a/src/main/java/fr/igred/omero/screen/WellSampleWrapper.java b/src/main/java/fr/igred/omero/screen/WellSampleWrapper.java index 23b1e738..7ddcf292 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.BasicBrowser; import fr.igred.omero.core.Image; import fr.igred.omero.core.ImageWrapper; import fr.igred.omero.exception.AccessException; @@ -132,7 +132,7 @@ public long getStartTime() { * @throws AccessException Cannot access data. */ @Override - public void reload(Browser browser) + public void reload(BasicBrowser 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 b097d1d0..5bbb9abb 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.BasicBrowser; import fr.igred.omero.exception.AccessException; import fr.igred.omero.exception.ServiceException; import omero.gateway.model.WellData; @@ -290,7 +290,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(BasicBrowser browser) throws ServiceException, AccessException, ExecutionException { data = call(browser.getBrowseFacility(), bf -> bf.getWells(browser.getCtx(), diff --git a/src/test/java/fr/igred/omero/annotations/ImageJTableTest.java b/src/test/java/fr/igred/omero/annotations/ImageJTableTest.java index bcc7b8a7..3d43e82d 100644 --- a/src/test/java/fr/igred/omero/annotations/ImageJTableTest.java +++ b/src/test/java/fr/igred/omero/annotations/ImageJTableTest.java @@ -19,7 +19,7 @@ import fr.igred.omero.UserTest; -import fr.igred.omero.client.DataManager; +import fr.igred.omero.client.BasicDataManager; import fr.igred.omero.core.Image; import fr.igred.omero.core.ImageWrapper; import fr.igred.omero.exception.AccessException; @@ -64,7 +64,7 @@ class ImageJTableTest extends UserTest { protected Image image = new ImageWrapper(new ImageData()); - private static List createAndSaveROI(DataManager dm, Image image, String name) + private static List createAndSaveROI(BasicDataManager dm, Image image, String name) throws AccessException, ServiceException, ExecutionException { ROI roi = new ROIWrapper(); roi.setImage(image);