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 e2eb836a..fb3ce8ef 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; @@ -543,7 +543,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..2fba9832 100644 --- a/src/main/java/fr/igred/omero/annotations/Annotation.java +++ b/src/main/java/fr/igred/omero/annotations/Annotation.java @@ -19,6 +19,7 @@ import fr.igred.omero.RemoteObject; +import fr.igred.omero.client.BasicBrowser; import fr.igred.omero.client.Browser; import fr.igred.omero.containers.Dataset; import fr.igred.omero.containers.Folder; @@ -102,7 +103,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(); diff --git a/src/main/java/fr/igred/omero/annotations/AnnotationBrowser.java b/src/main/java/fr/igred/omero/annotations/AnnotationBrowser.java index 765e8116..5d82c051 100644 --- a/src/main/java/fr/igred/omero/annotations/AnnotationBrowser.java +++ b/src/main/java/fr/igred/omero/annotations/AnnotationBrowser.java @@ -1,31 +1,16 @@ package fr.igred.omero.annotations; +import fr.igred.omero.client.BasicBrowser; import fr.igred.omero.exception.AccessException; import fr.igred.omero.exception.ServiceException; -import omero.model.IObject; import java.util.List; import java.util.NoSuchElementException; import java.util.concurrent.ExecutionException; -public interface AnnotationBrowser { - - - /** - * 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. - */ - List findByQuery(String query) - throws ServiceException, AccessException; - +public interface AnnotationBrowser extends BasicBrowser { /** * Gets the list of tag annotations available to the user. diff --git a/src/main/java/fr/igred/omero/annotations/TagSet.java b/src/main/java/fr/igred/omero/annotations/TagSet.java index 156a1eea..bd112439 100644 --- a/src/main/java/fr/igred/omero/annotations/TagSet.java +++ b/src/main/java/fr/igred/omero/annotations/TagSet.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.DataManager; import fr.igred.omero.exception.AccessException; import fr.igred.omero.exception.ServiceException; @@ -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(); @@ -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..de75f787 100644 --- a/src/main/java/fr/igred/omero/annotations/TagSetWrapper.java +++ b/src/main/java/fr/igred/omero/annotations/TagSetWrapper.java @@ -18,7 +18,7 @@ package fr.igred.omero.annotations; -import fr.igred.omero.client.Browser; +import fr.igred.omero.client.BasicBrowser; import fr.igred.omero.client.DataManager; import fr.igred.omero.exception.AccessException; import fr.igred.omero.exception.ServiceException; @@ -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..7949ec35 100644 --- a/src/main/java/fr/igred/omero/client/AdminManager.java +++ b/src/main/java/fr/igred/omero/client/AdminManager.java @@ -21,13 +21,13 @@ import fr.igred.omero.exception.AccessException; import fr.igred.omero.exception.ExceptionHandler; import fr.igred.omero.exception.ServiceException; +import fr.igred.omero.meta.BasicAdmin; import fr.igred.omero.meta.ExperimenterWrapper; import fr.igred.omero.meta.Group; import fr.igred.omero.meta.GroupWrapper; 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 +45,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 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..32bc28d8 --- /dev/null +++ b/src/main/java/fr/igred/omero/client/BasicBrowser.java @@ -0,0 +1,70 @@ +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; + + +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. + */ + List findByQuery(String query) + throws ServiceException, AccessException; + +} 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 877956c2..32fd7694 100644 --- a/src/main/java/fr/igred/omero/client/Browser.java +++ b/src/main/java/fr/igred/omero/client/Browser.java @@ -22,7 +22,6 @@ 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; @@ -34,10 +33,7 @@ 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; @@ -59,45 +55,8 @@ public interface Browser extends fr.igred.omero.containers.ContainerBrowser, fr.igred.omero.screen.HCSBrowser, - fr.igred.omero.annotations.AnnotationBrowser, fr.igred.omero.core.CoreBrowser { - - /** - * 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; + fr.igred.omero.annotations.AnnotationBrowser, + fr.igred.omero.core.CoreBrowser { /** diff --git a/src/main/java/fr/igred/omero/client/DataManager.java b/src/main/java/fr/igred/omero/client/DataManager.java index ef9de8bb..90f5a541 100644 --- a/src/main/java/fr/igred/omero/client/DataManager.java +++ b/src/main/java/fr/igred/omero/client/DataManager.java @@ -43,44 +43,7 @@ /** * 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 +126,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/ContainerBrowser.java b/src/main/java/fr/igred/omero/containers/ContainerBrowser.java index ee511f87..d3e79e4b 100644 --- a/src/main/java/fr/igred/omero/containers/ContainerBrowser.java +++ b/src/main/java/fr/igred/omero/containers/ContainerBrowser.java @@ -1,31 +1,17 @@ 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.model.IObject; import java.util.List; import java.util.NoSuchElementException; import java.util.concurrent.ExecutionException; -public interface ContainerBrowser { - - - /** - * 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. - */ - List findByQuery(String query) - throws ServiceException, AccessException; +public interface ContainerBrowser extends BasicBrowser { /** diff --git a/src/main/java/fr/igred/omero/containers/Dataset.java b/src/main/java/fr/igred/omero/containers/Dataset.java index 16186871..d4dd4a78 100644 --- a/src/main/java/fr/igred/omero/containers/Dataset.java +++ b/src/main/java/fr/igred/omero/containers/Dataset.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.Client; import fr.igred.omero.client.ConnectionHandler; import fr.igred.omero.client.DataManager; +import fr.igred.omero.core.CoreBrowser; import fr.igred.omero.core.Image; import fr.igred.omero.core.ImageWrapper; import fr.igred.omero.exception.AccessException; @@ -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(ContainerBrowser 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(CoreBrowser 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(CoreBrowser 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(), @@ -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..9aebb05e 100644 --- a/src/main/java/fr/igred/omero/containers/Folder.java +++ b/src/main/java/fr/igred/omero/containers/Folder.java @@ -20,7 +20,8 @@ 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.client.BasicDataManager; import fr.igred.omero.client.DataManager; import fr.igred.omero.core.Image; import fr.igred.omero.exception.AccessException; @@ -77,7 +78,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 +155,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 +195,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 +213,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 +240,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 +258,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 +274,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 +291,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 +308,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 +325,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 +340,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 +357,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..e3227ba2 100644 --- a/src/main/java/fr/igred/omero/containers/Project.java +++ b/src/main/java/fr/igred/omero/containers/Project.java @@ -21,9 +21,10 @@ 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.Client; import fr.igred.omero.client.DataManager; +import fr.igred.omero.core.CoreBrowser; import fr.igred.omero.core.Image; import fr.igred.omero.exception.AccessException; import fr.igred.omero.exception.ServiceException; @@ -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(CoreBrowser 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(CoreBrowser 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..318e9eb7 100644 --- a/src/main/java/fr/igred/omero/containers/ProjectWrapper.java +++ b/src/main/java/fr/igred/omero/containers/ProjectWrapper.java @@ -19,7 +19,8 @@ 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; @@ -66,7 +67,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); @@ -197,7 +198,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 +219,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/CoreBrowser.java b/src/main/java/fr/igred/omero/core/CoreBrowser.java index 828b10d4..987a2e0a 100644 --- a/src/main/java/fr/igred/omero/core/CoreBrowser.java +++ b/src/main/java/fr/igred/omero/core/CoreBrowser.java @@ -2,31 +2,17 @@ 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 omero.model.IObject; import java.util.List; import java.util.NoSuchElementException; import java.util.concurrent.ExecutionException; -public interface CoreBrowser { - - /** - * 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. - */ - List findByQuery(String query) - throws ServiceException, AccessException; - +public interface CoreBrowser extends BasicBrowser { /** * Returns the image with the specified ID from OMERO. diff --git a/src/main/java/fr/igred/omero/core/Image.java b/src/main/java/fr/igred/omero/core/Image.java index e4acd5c7..86f6d4d1 100644 --- a/src/main/java/fr/igred/omero/core/Image.java +++ b/src/main/java/fr/igred/omero/core/Image.java @@ -19,6 +19,7 @@ import fr.igred.omero.RepositoryObject; +import fr.igred.omero.client.BasicBrowser; import fr.igred.omero.client.Browser; import fr.igred.omero.client.Client; import fr.igred.omero.client.ConnectionHandler; @@ -299,7 +300,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(); @@ -536,7 +537,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 +553,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 +571,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 +642,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 +657,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/ImageWrapper.java b/src/main/java/fr/igred/omero/core/ImageWrapper.java index ad5baad5..d86f51ac 100644 --- a/src/main/java/fr/igred/omero/core/ImageWrapper.java +++ b/src/main/java/fr/igred/omero/core/ImageWrapper.java @@ -20,7 +20,7 @@ import fr.igred.omero.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.client.DataManager; @@ -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..94f452b8 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; @@ -43,6 +43,8 @@ import java.util.function.Supplier; import java.util.stream.Collectors; +import static fr.igred.omero.exception.ExceptionHandler.call; + /** * Interface to handle ROIs on OMERO. @@ -299,7 +301,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 +367,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..c9c585ba 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; @@ -40,6 +40,7 @@ import java.util.concurrent.ExecutionException; import java.util.stream.Collectors; +import static fr.igred.omero.exception.ExceptionHandler.call; import static java.util.stream.Collectors.groupingBy; @@ -272,9 +273,11 @@ 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()); + Roi roi = (Roi) call(dm.getDMFacility(), + d -> d.saveAndReturnObject(dm.getCtx(), data.asIObject()), + "Cannot save object"); 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..b4c22e4c 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; @@ -32,6 +32,7 @@ import java.awt.Color; import java.util.concurrent.ExecutionException; +import static fr.igred.omero.exception.ExceptionHandler.call; import static java.awt.geom.AffineTransform.TYPE_IDENTITY; @@ -278,7 +279,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/HCSBrowser.java b/src/main/java/fr/igred/omero/screen/HCSBrowser.java index 08891675..7698c21c 100644 --- a/src/main/java/fr/igred/omero/screen/HCSBrowser.java +++ b/src/main/java/fr/igred/omero/screen/HCSBrowser.java @@ -1,6 +1,7 @@ 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; @@ -11,22 +12,7 @@ import java.util.concurrent.ExecutionException; -public interface HCSBrowser { - - - /** - * 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. - */ - List findByQuery(String query) - throws ServiceException, AccessException; - +public interface HCSBrowser extends BasicBrowser { /** * Gets the screen with the specified id from OMERO. diff --git a/src/main/java/fr/igred/omero/screen/Plate.java b/src/main/java/fr/igred/omero/screen/Plate.java index e4128c13..bcecf0ce 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(HCSBrowser 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 7f09615a..a049271c 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(HCSBrowser browser) throws ServiceException, AccessException, ExecutionException { Plate plate = browser.getPlate(getRefPlateId()); return plate.getScreens(browser); @@ -138,7 +138,7 @@ default List getPlates(HCSBrowser browser) * @throws AccessException Cannot access data. * @throws ExecutionException A Facility can't be retrieved or instantiated. */ - default List getWells(Browser browser) + default List getWells(HCSBrowser 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/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..bed5d62c 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(HCSBrowser 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(HCSBrowser 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 e30ebe3c..16b5f054 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(HCSBrowser browser) throws ServiceException, AccessException, ExecutionException { return getWell(browser).getScreens(browser); } @@ -100,7 +100,7 @@ default List getPlates(HCSBrowser browser) * @throws AccessException Cannot access data. * @throws ExecutionException A Facility can't be retrieved or instantiated. */ - default List getPlateAcquisitions(Browser browser) + default List getPlateAcquisitions(HCSBrowser browser) throws ServiceException, AccessException, ExecutionException { return getWell(browser).getPlateAcquisitions(browser); } @@ -179,7 +179,7 @@ default Well getWell(HCSBrowser 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..2e2c3cdf 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; @@ -131,8 +131,7 @@ public long getStartTime() { * @throws ServiceException Cannot connect to OMERO. * @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(),