From 7bf8cd0d75341d8411f69686cf0016055fba3f96 Mon Sep 17 00:00:00 2001 From: Pierre Pouchin Date: Sun, 24 Sep 2023 11:27:12 +0200 Subject: [PATCH 01/18] Bump SciJava version --- pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index 052196e7..d77fa96d 100644 --- a/pom.xml +++ b/pom.xml @@ -9,7 +9,7 @@ fr.igred simple-omero-client - 5.19.0 + 6.0.0-SNAPSHOT jar Simple OMERO Client From a8fe4dcab7bee18ce04fcd22b7f4a27500fb57fb Mon Sep 17 00:00:00 2001 From: Pierre Pouchin Date: Tue, 24 Oct 2023 16:20:48 +0200 Subject: [PATCH 02/18] Remove OMEROServerError from thrown Exceptions --- .../fr/igred/omero/AnnotatableWrapper.java | 28 ++--- src/main/java/fr/igred/omero/Browser.java | 116 ++++++++---------- src/main/java/fr/igred/omero/Client.java | 31 ++--- .../java/fr/igred/omero/GatewayWrapper.java | 30 ++--- .../annotations/FileAnnotationWrapper.java | 13 +- .../annotations/GenericAnnotationWrapper.java | 34 ++--- .../omero/annotations/TagSetWrapper.java | 7 +- .../omero/exception/ExceptionHandler.java | 3 +- .../omero/repository/DatasetWrapper.java | 51 ++++---- .../igred/omero/repository/FolderWrapper.java | 7 +- .../GenericRepositoryObjectWrapper.java | 91 +++++++++----- .../igred/omero/repository/ImageWrapper.java | 39 +++--- .../repository/PlateAcquisitionWrapper.java | 14 +-- .../igred/omero/repository/PlateWrapper.java | 4 +- .../omero/repository/ProjectWrapper.java | 10 +- .../igred/omero/repository/ScreenWrapper.java | 16 +-- .../omero/repository/WellSampleWrapper.java | 14 +-- .../igred/omero/repository/WellWrapper.java | 4 +- .../java/fr/igred/omero/roi/ROIWrapper.java | 7 +- .../omero/annotations/ImageJTableTest.java | 3 +- .../omero/exception/AccessExceptionTest.java | 7 +- 21 files changed, 224 insertions(+), 305 deletions(-) diff --git a/src/main/java/fr/igred/omero/AnnotatableWrapper.java b/src/main/java/fr/igred/omero/AnnotatableWrapper.java index 73119fe1..406c22fd 100644 --- a/src/main/java/fr/igred/omero/AnnotatableWrapper.java +++ b/src/main/java/fr/igred/omero/AnnotatableWrapper.java @@ -26,7 +26,6 @@ import fr.igred.omero.annotations.TableWrapper; import fr.igred.omero.annotations.TagAnnotationWrapper; import fr.igred.omero.exception.AccessException; -import fr.igred.omero.exception.OMEROServerError; import fr.igred.omero.exception.ServiceException; import fr.igred.omero.repository.GenericRepositoryObjectWrapper.ReplacePolicy; import omero.gateway.facility.TablesFacility; @@ -498,11 +497,10 @@ public List getRatings(Client client) * @throws ServiceException Cannot connect to OMERO. * @throws AccessException Cannot access data. * @throws ExecutionException A Facility can't be retrieved or instantiated. - * @throws OMEROServerError Server error. * @throws InterruptedException The thread was interrupted. */ public void rate(Client client, int rating) - throws ServiceException, AccessException, ExecutionException, OMEROServerError, InterruptedException { + throws ServiceException, AccessException, ExecutionException, InterruptedException { List userIds = singletonList(client.getCtx().getExperimenter()); List ratings = getRatings(client, userIds); @@ -611,10 +609,9 @@ public void addTable(Client client, TableWrapper table) * @throws AccessException Cannot access data. * @throws ExecutionException A Facility can't be retrieved or instantiated. * @throws InterruptedException The thread was interrupted. - * @throws OMEROServerError Server error. */ public void addAndReplaceTable(Client client, TableWrapper table, ReplacePolicy policy) - throws ServiceException, AccessException, ExecutionException, OMEROServerError, InterruptedException { + throws ServiceException, AccessException, ExecutionException, InterruptedException { String error = "Cannot add table to " + this; Collection tables = wrap(call(client.getTablesFacility(), t -> t.getAvailableTables(client.getCtx(), @@ -645,10 +642,9 @@ public void addAndReplaceTable(Client client, TableWrapper table, ReplacePolicy * @throws AccessException Cannot access data. * @throws ExecutionException A Facility can't be retrieved or instantiated. * @throws InterruptedException The thread was interrupted. - * @throws OMEROServerError Server error. */ public void addAndReplaceTable(Client client, TableWrapper table) - throws ServiceException, AccessException, ExecutionException, OMEROServerError, InterruptedException { + throws ServiceException, AccessException, ExecutionException, InterruptedException { addAndReplaceTable(client, table, ReplacePolicy.DELETE_ORPHANED); } @@ -752,10 +748,9 @@ public long addFile(Client client, File file) * @throws AccessException Cannot access data. * @throws ExecutionException A Facility can't be retrieved or instantiated. * @throws InterruptedException The thread was interrupted. - * @throws OMEROServerError Server error. */ public long addAndReplaceFile(Client client, File file, ReplacePolicy policy) - throws ExecutionException, InterruptedException, AccessException, ServiceException, OMEROServerError { + throws ExecutionException, InterruptedException, AccessException, ServiceException { List files = getFileAnnotations(client); FileAnnotationData uploaded = client.getDm().attachFile(client.getCtx(), @@ -792,10 +787,9 @@ public long addAndReplaceFile(Client client, File file, ReplacePolicy policy) * @throws AccessException Cannot access data. * @throws ExecutionException A Facility can't be retrieved or instantiated. * @throws InterruptedException The thread was interrupted. - * @throws OMEROServerError Server error. */ public long addAndReplaceFile(Client client, File file) - throws ExecutionException, InterruptedException, AccessException, ServiceException, OMEROServerError { + throws ExecutionException, InterruptedException, AccessException, ServiceException { return addAndReplaceFile(client, file, ReplacePolicy.DELETE_ORPHANED); } @@ -858,11 +852,10 @@ public List getFileAnnotations(Client client) * @throws ServiceException Cannot connect to OMERO. * @throws AccessException Cannot access data. * @throws ExecutionException A Facility can't be retrieved or instantiated. - * @throws OMEROServerError Server error. * @throws InterruptedException If block(long) does not return. */ public > void unlink(Client client, A annotation) - throws ServiceException, AccessException, ExecutionException, OMEROServerError, InterruptedException { + throws ServiceException, AccessException, ExecutionException, InterruptedException { removeLink(client, annotationLinkType(), annotation.getId()); } @@ -877,11 +870,10 @@ public > void unlink(Client client, A anno * @throws ServiceException Cannot connect to OMERO. * @throws AccessException Cannot access data. * @throws ExecutionException A Facility can't be retrieved or instantiated. - * @throws OMEROServerError Server error. * @throws InterruptedException If block(long) does not return. */ public > void unlink(Client client, Collection annotations) - throws ServiceException, AccessException, ExecutionException, OMEROServerError, InterruptedException { + throws ServiceException, AccessException, ExecutionException, InterruptedException { removeLinks(client, annotationLinkType(), annotations.stream() @@ -900,11 +892,10 @@ public > void unlink(Client client, Collec * @throws ServiceException Cannot connect to OMERO. * @throws AccessException Cannot access data. * @throws ExecutionException A Facility can't be retrieved or instantiated. - * @throws OMEROServerError Server error. * @throws InterruptedException If block(long) does not return. */ protected void removeLinks(Client client, String linkType, Collection childIds) - throws ServiceException, OMEROServerError, AccessException, ExecutionException, InterruptedException { + throws ServiceException, AccessException, ExecutionException, InterruptedException { String template = "select link from %s link" + " where link.parent = %d" + " and link.child.id in (:ids)"; @@ -929,11 +920,10 @@ protected void removeLinks(Client client, String linkType, Collection chil * @throws ServiceException Cannot connect to OMERO. * @throws AccessException Cannot access data. * @throws ExecutionException A Facility can't be retrieved or instantiated. - * @throws OMEROServerError Server error. * @throws InterruptedException If block(long) does not return. */ protected void removeLink(Client client, String linkType, long childId) - throws ServiceException, OMEROServerError, AccessException, ExecutionException, InterruptedException { + throws ServiceException, AccessException, ExecutionException, InterruptedException { removeLinks(client, linkType, singletonList(childId)); } diff --git a/src/main/java/fr/igred/omero/Browser.java b/src/main/java/fr/igred/omero/Browser.java index fb3ab445..de520b3a 100644 --- a/src/main/java/fr/igred/omero/Browser.java +++ b/src/main/java/fr/igred/omero/Browser.java @@ -22,8 +22,6 @@ import fr.igred.omero.annotations.MapAnnotationWrapper; import fr.igred.omero.annotations.TagAnnotationWrapper; import fr.igred.omero.exception.AccessException; -import fr.igred.omero.exception.ExceptionHandler; -import fr.igred.omero.exception.OMEROServerError; import fr.igred.omero.exception.ServiceException; import fr.igred.omero.meta.ExperimenterWrapper; import fr.igred.omero.repository.DatasetWrapper; @@ -243,11 +241,10 @@ public List getDatasets(Long... ids) * * @throws ServiceException Cannot connect to OMERO. * @throws AccessException Cannot access data. - * @throws OMEROServerError Server error. * @throws ExecutionException A Facility can't be retrieved or instantiated. */ public List getDatasets() - throws ServiceException, AccessException, OMEROServerError, ExecutionException { + throws ServiceException, AccessException, ExecutionException { Long[] ids = this.findByQuery("select d from Dataset d") .stream() .map(IObject::getId) @@ -266,11 +263,10 @@ public List getDatasets() * * @throws ServiceException Cannot connect to OMERO. * @throws AccessException Cannot access data. - * @throws OMEROServerError Server error. * @throws ExecutionException A Facility can't be retrieved or instantiated. */ public List getDatasets(ExperimenterWrapper experimenter) - throws ServiceException, AccessException, OMEROServerError, ExecutionException { + throws ServiceException, AccessException, ExecutionException { String template = "select d from Dataset d where d.details.owner.id=%d"; String query = format(template, experimenter.getId()); Long[] ids = this.findByQuery(query) @@ -313,11 +309,10 @@ public List getDatasets(String name) * * @throws ServiceException Cannot connect to OMERO. * @throws AccessException Cannot access data. - * @throws OMEROServerError Server error. * @throws ExecutionException A Facility can't be retrieved or instantiated. */ public List getOrphanedDatasets(ExperimenterWrapper experimenter) - throws ServiceException, ExecutionException, OMEROServerError, AccessException { + throws ServiceException, ExecutionException, AccessException { String template = "select dataset from Dataset as dataset" + " join fetch dataset.details.owner as o" + " where o.id = %d" + @@ -341,11 +336,10 @@ public List getOrphanedDatasets(ExperimenterWrapper experimenter * * @throws ServiceException Cannot connect to OMERO. * @throws AccessException Cannot access data. - * @throws OMEROServerError Server error. * @throws ExecutionException A Facility can't be retrieved or instantiated. */ public List getOrphanedDatasets() - throws ServiceException, ExecutionException, OMEROServerError, AccessException { + throws ServiceException, ExecutionException, AccessException { return getOrphanedDatasets(getUser()); } @@ -501,11 +495,10 @@ public abstract List getImages(String projectName, String datasetN * * @throws ServiceException Cannot connect to OMERO. * @throws AccessException Cannot access data. - * @throws OMEROServerError Server error. * @throws ExecutionException A Facility can't be retrieved or instantiated. */ public abstract List getImages(GenericAnnotationWrapper annotation) - throws ServiceException, AccessException, OMEROServerError, ExecutionException; + throws ServiceException, AccessException, ExecutionException; /** @@ -535,13 +528,12 @@ public List getImagesLike(String motif) * * @throws ServiceException Cannot connect to OMERO. * @throws AccessException Cannot access data. - * @throws OMEROServerError Server error. * @throws ExecutionException A Facility can't be retrieved or instantiated. * @deprecated Gets all images tagged with a specified tag from OMERO. */ @Deprecated public List getImagesTagged(TagAnnotationWrapper tag) - throws ServiceException, AccessException, OMEROServerError, ExecutionException { + throws ServiceException, AccessException, ExecutionException { return getImages(tag); } @@ -553,13 +545,12 @@ public List getImagesTagged(TagAnnotationWrapper tag) * * @throws ServiceException Cannot connect to OMERO. * @throws AccessException Cannot access data. - * @throws OMEROServerError Server error. * @throws ExecutionException A Facility can't be retrieved or instantiated. * @deprecated Gets all images tagged with a specified tag from OMERO. */ @Deprecated public List getImagesTagged(Long tagId) - throws ServiceException, AccessException, OMEROServerError, ExecutionException { + throws ServiceException, AccessException, ExecutionException { return getImagesTagged(getTag(tagId)); } @@ -588,11 +579,10 @@ public abstract List getImagesKey(String key) * * @throws ServiceException Cannot connect to OMERO. * @throws AccessException Cannot access data. - * @throws OMEROServerError Server error. * @throws ExecutionException A Facility can't be retrieved or instantiated. */ public List getImagesWithKey(String key) - throws ServiceException, AccessException, ExecutionException, OMEROServerError { + throws ServiceException, AccessException, ExecutionException { List maps = getMapAnnotations(key); Collection> selected = new ArrayList<>(maps.size()); @@ -630,11 +620,10 @@ public abstract List getImagesPairKeyValue(String key, String valu * * @throws ServiceException Cannot connect to OMERO. * @throws AccessException Cannot access data. - * @throws OMEROServerError Server error. * @throws ExecutionException A Facility can't be retrieved or instantiated. */ public List getImagesWithKeyValuePair(String key, String value) - throws ServiceException, AccessException, ExecutionException, OMEROServerError { + throws ServiceException, AccessException, ExecutionException { List maps = getMapAnnotations(key, value); Collection> selected = new ArrayList<>(maps.size()); @@ -826,11 +815,10 @@ public List getPlates(ExperimenterWrapper experimenter) * * @throws ServiceException Cannot connect to OMERO. * @throws AccessException Cannot access data. - * @throws OMEROServerError Server error. * @throws ExecutionException A Facility can't be retrieved or instantiated. */ public List getOrphanedPlates(ExperimenterWrapper experimenter) - throws ServiceException, ExecutionException, OMEROServerError, AccessException { + throws ServiceException, ExecutionException, AccessException { String template = "select plate from Plate as plate" + " join fetch plate.details.owner as o" + " where o.id = %d" + @@ -854,11 +842,10 @@ public List getOrphanedPlates(ExperimenterWrapper experimenter) * * @throws ServiceException Cannot connect to OMERO. * @throws AccessException Cannot access data. - * @throws OMEROServerError Server error. * @throws ExecutionException A Facility can't be retrieved or instantiated. */ public List getOrphanedPlates() - throws ServiceException, ExecutionException, OMEROServerError, AccessException { + throws ServiceException, ExecutionException, AccessException { return getOrphanedPlates(getUser()); } @@ -916,10 +903,9 @@ public List getWells(Long... ids) * @throws ServiceException Cannot connect to OMERO. * @throws AccessException Cannot access data. * @throws ExecutionException A Facility can't be retrieved or instantiated. - * @throws OMEROServerError Server error. */ public List getWells() - throws ServiceException, AccessException, ExecutionException, OMEROServerError { + throws ServiceException, AccessException, ExecutionException { Long[] ids = this.findByQuery("select w from Well w") .stream() .map(IObject::getId) @@ -939,10 +925,9 @@ public List getWells() * @throws ServiceException Cannot connect to OMERO. * @throws AccessException Cannot access data. * @throws ExecutionException A Facility can't be retrieved or instantiated. - * @throws OMEROServerError Server error. */ public List getWells(ExperimenterWrapper experimenter) - throws ServiceException, AccessException, ExecutionException, OMEROServerError { + throws ServiceException, AccessException, ExecutionException { String template = "select w from Well w where w.details.owner.id=%d"; String query = format(template, experimenter.getId()); Long[] ids = this.findByQuery(query) @@ -1044,17 +1029,16 @@ public List loadFolders(Long... ids) * * @return See above. * - * @throws OMEROServerError Server error. + * @throws AccessException Cannot access data. * @throws ServiceException Cannot connect to OMERO. */ public List getTags() - throws OMEROServerError, ServiceException { + throws AccessException, ServiceException { String klass = TagAnnotation.class.getSimpleName(); - List os = ExceptionHandler.of(getGateway(), - g -> g.getQueryService(getCtx()) - .findAll(klass, null)) - .handleServiceOrServer("Cannot get tags") - .get(); + List os = call(getGateway(), + g -> g.getQueryService(getCtx()) + .findAll(klass, null), + "Cannot get tags"); return os.stream() .map(TagAnnotation.class::cast) .map(TagAnnotationData::new) @@ -1071,11 +1055,11 @@ public List getTags() * * @return See above. * - * @throws OMEROServerError Server error. + * @throws AccessException Cannot access data. * @throws ServiceException Cannot connect to OMERO. */ public List getTags(String name) - throws OMEROServerError, ServiceException { + throws AccessException, ServiceException { List tags = getTags(); tags.removeIf(tag -> !tag.getName().equals(name)); tags.sort(Comparator.comparing(GenericObjectWrapper::getId)); @@ -1090,18 +1074,16 @@ public List getTags(String name) * * @return See above. * - * @throws OMEROServerError Server error. + * @throws AccessException Cannot access data. * @throws ServiceException Cannot connect to OMERO. * @throws NoSuchElementException No element with this ID. */ public TagAnnotationWrapper getTag(Long id) - throws OMEROServerError, ServiceException { - String klass = TagAnnotation.class.getSimpleName(); - IObject o = ExceptionHandler.of(getGateway(), - g -> g.getQueryService(getCtx()) - .find(klass, id)) - .handleServiceOrServer("Cannot get tag ID: " + id) - .get(); + throws AccessException, ServiceException { + IObject o = call(getGateway(), + g -> g.getQueryService(getCtx()) + .find(TagAnnotation.class.getSimpleName(), id), + "Cannot get tag ID: " + id); TagAnnotationData tag; if (o == null) { String msg = format("Tag %d doesn't exist in this context", id); @@ -1118,23 +1100,22 @@ public TagAnnotationWrapper getTag(Long id) * * @return See above. * - * @throws OMEROServerError Server error. + * @throws AccessException Cannot access data. * @throws ServiceException Cannot connect to OMERO. */ public List getMapAnnotations() - throws OMEROServerError, ServiceException { + throws AccessException, ServiceException { String klass = omero.model.MapAnnotation.class.getSimpleName(); - return ExceptionHandler.of(getGateway(), - g -> g.getQueryService(getCtx()) - .findAll(klass, null)) - .handleServiceOrServer("Cannot get map annotations") - .get() - .stream() - .map(omero.model.MapAnnotation.class::cast) - .map(MapAnnotationData::new) - .map(MapAnnotationWrapper::new) - .sorted(Comparator.comparing(GenericObjectWrapper::getId)) - .collect(Collectors.toList()); + List os = call(getGateway(), + g -> g.getQueryService(getCtx()) + .findAll(klass, null), + "Cannot get map annotations"); + return os.stream() + .map(omero.model.MapAnnotation.class::cast) + .map(MapAnnotationData::new) + .map(MapAnnotationWrapper::new) + .sorted(Comparator.comparing(GenericObjectWrapper::getId)) + .collect(Collectors.toList()); } @@ -1145,11 +1126,11 @@ public List getMapAnnotations() * * @return See above. * - * @throws OMEROServerError Server error. + * @throws AccessException Cannot access data. * @throws ServiceException Cannot connect to OMERO. */ public List getMapAnnotations(String key) - throws OMEROServerError, ServiceException { + throws AccessException, ServiceException { String template = "select m from MapAnnotation as m" + " join m.mapValue as mv" + " where mv.name = '%s'"; @@ -1171,11 +1152,11 @@ public List getMapAnnotations(String key) * * @return See above. * - * @throws OMEROServerError Server error. + * @throws AccessException Cannot access data. * @throws ServiceException Cannot connect to OMERO. */ public List getMapAnnotations(String key, String value) - throws OMEROServerError, ServiceException { + throws AccessException, ServiceException { String template = "select m from MapAnnotation as m" + " join m.mapValue as mv" + " where mv.name = '%s' and mv.value = '%s'"; @@ -1202,12 +1183,11 @@ public List getMapAnnotations(String key, String value) */ public MapAnnotationWrapper getMapAnnotation(Long id) throws ServiceException, ExecutionException, AccessException { - MapAnnotationData kv = ExceptionHandler.of(getBrowseFacility(), - b -> b.findObject(getCtx(), - MapAnnotationData.class, - id)) - .handleServiceOrAccess("Cannot get map annotation with ID: " + id) - .get(); + MapAnnotationData kv = call(getBrowseFacility(), + b -> b.findObject(getCtx(), + MapAnnotationData.class, + id), + "Cannot get map annotation with ID: " + id); return new MapAnnotationWrapper(kv); } diff --git a/src/main/java/fr/igred/omero/Client.java b/src/main/java/fr/igred/omero/Client.java index a02ca384..0bd356e9 100644 --- a/src/main/java/fr/igred/omero/Client.java +++ b/src/main/java/fr/igred/omero/Client.java @@ -22,7 +22,6 @@ import fr.igred.omero.annotations.TableWrapper; import fr.igred.omero.exception.AccessException; import fr.igred.omero.exception.ExceptionHandler; -import fr.igred.omero.exception.OMEROServerError; import fr.igred.omero.exception.ServiceException; import fr.igred.omero.meta.ExperimenterWrapper; import fr.igred.omero.meta.GroupWrapper; @@ -114,12 +113,11 @@ public List getImages(String projectName, String datasetName, Stri * * @throws ServiceException Cannot connect to OMERO. * @throws AccessException Cannot access data. - * @throws OMEROServerError Server error. * @throws ExecutionException A Facility can't be retrieved or instantiated. */ @Override public List getImages(GenericAnnotationWrapper annotation) - throws ServiceException, AccessException, OMEROServerError, ExecutionException { + throws ServiceException, AccessException, ExecutionException { return annotation.getImages(this); } @@ -186,11 +184,10 @@ public List getImagesPairKeyValue(String key, String value) * @throws ServiceException Cannot connect to OMERO. * @throws AccessException Cannot access data. * @throws ExecutionException A Facility can't be retrieved or instantiated. - * @throws OMEROServerError Server error. * @throws InterruptedException If block(long) does not return. */ public void delete(Collection> objects) - throws ServiceException, AccessException, ExecutionException, OMEROServerError, InterruptedException { + throws ServiceException, AccessException, ExecutionException, InterruptedException { for (GenericObjectWrapper object : objects) { if (object instanceof FolderWrapper) { ((FolderWrapper) object).unlinkAllROIs(this); @@ -213,11 +210,10 @@ public void delete(Collection> objects) * @throws ServiceException Cannot connect to OMERO. * @throws AccessException Cannot access data. * @throws ExecutionException A Facility can't be retrieved or instantiated. - * @throws OMEROServerError Server error. * @throws InterruptedException If block(long) does not return. */ public void delete(GenericObjectWrapper object) - throws ServiceException, AccessException, ExecutionException, OMEROServerError, InterruptedException { + throws ServiceException, AccessException, ExecutionException, InterruptedException { if (object instanceof FolderWrapper) { ((FolderWrapper) object).unlinkAllROIs(this); } @@ -232,13 +228,12 @@ public void delete(GenericObjectWrapper object) * @throws AccessException Cannot access data. * @throws ExecutionException A Facility can't be retrieved or instantiated. * @throws IllegalArgumentException ID not defined. - * @throws OMEROServerError Server error. * @throws InterruptedException If block(long) does not return. * @deprecated Deletes a table from OMERO. */ @Deprecated public void delete(TableWrapper table) - throws ServiceException, AccessException, ExecutionException, OMEROServerError, InterruptedException { + throws ServiceException, AccessException, ExecutionException, InterruptedException { deleteTable(table); } @@ -252,11 +247,10 @@ public void delete(TableWrapper table) * @throws AccessException Cannot access data. * @throws ExecutionException A Facility can't be retrieved or instantiated. * @throws IllegalArgumentException ID not defined. - * @throws OMEROServerError Server error. * @throws InterruptedException If block(long) does not return. */ public void deleteTable(TableWrapper table) - throws ServiceException, AccessException, ExecutionException, OMEROServerError, InterruptedException { + throws ServiceException, AccessException, ExecutionException, InterruptedException { deleteFile(table.getId()); } @@ -270,11 +264,10 @@ public void deleteTable(TableWrapper table) * @throws AccessException Cannot access data. * @throws ExecutionException A Facility can't be retrieved or instantiated. * @throws IllegalArgumentException ID not defined. - * @throws OMEROServerError Server error. * @throws InterruptedException If block(long) does not return. */ public void deleteTables(Collection tables) - throws ServiceException, AccessException, ExecutionException, OMEROServerError, InterruptedException { + throws ServiceException, AccessException, ExecutionException, InterruptedException { deleteFiles(tables.stream() .map(TableWrapper::getId) .toArray(Long[]::new)); @@ -316,18 +309,18 @@ public ExperimenterWrapper getUser(String username) * @return The user matching the user ID, or null if it does not exist. * * @throws ServiceException Cannot connect to OMERO. - * @throws OMEROServerError Server error. + * @throws AccessException Cannot access data. * @throws NoSuchElementException The requested user cannot be found. */ public ExperimenterWrapper getUser(long userId) - throws ServiceException, OMEROServerError { + throws ServiceException, AccessException { Experimenter user = ExceptionHandler.of(getGateway(), g -> g.getAdminService(getCtx()) .getExperimenter(userId)) .rethrow(ApiUsageException.class, (m, e) -> new NoSuchElementException(m), "User not found: " + userId) - .handleServiceOrServer("Cannot retrieve user: " + userId) + .handleOMEROException("Cannot retrieve user: " + userId) .get(); return new ExperimenterWrapper(new ExperimenterData(user)); } @@ -367,18 +360,18 @@ public GroupWrapper getGroup(String groupName) * @return The group with the appropriate group ID, if it exists. * * @throws ServiceException Cannot connect to OMERO. - * @throws OMEROServerError Server error. + * @throws AccessException Cannot access data. * @throws NoSuchElementException The requested group cannot be found. */ public GroupWrapper getGroup(long groupId) - throws ServiceException, OMEROServerError { + throws ServiceException, AccessException { ExperimenterGroup group = ExceptionHandler.of(getGateway(), g -> g.getAdminService(getCtx()) .getGroup(groupId)) .rethrow(ApiUsageException.class, (m, e) -> new NoSuchElementException(m), "Group not found: " + groupId) - .handleServiceOrServer("Cannot retrieve group: " + groupId) + .handleOMEROException("Cannot retrieve group: " + groupId) .get(); return new GroupWrapper(new GroupData(group)); } diff --git a/src/main/java/fr/igred/omero/GatewayWrapper.java b/src/main/java/fr/igred/omero/GatewayWrapper.java index 2ae1befc..b222022a 100644 --- a/src/main/java/fr/igred/omero/GatewayWrapper.java +++ b/src/main/java/fr/igred/omero/GatewayWrapper.java @@ -20,7 +20,6 @@ import fr.igred.omero.exception.AccessException; import fr.igred.omero.exception.ExceptionHandler; -import fr.igred.omero.exception.OMEROServerError; import fr.igred.omero.exception.ServiceException; import fr.igred.omero.meta.ExperimenterWrapper; import ome.formats.OMEROMetadataStoreClient; @@ -436,15 +435,14 @@ public void closeImport() { * @return A list of OMERO objects. * * @throws ServiceException Cannot connect to OMERO. - * @throws OMEROServerError Server error. + * @throws AccessException Cannot access data. */ public List findByQuery(String query) - throws ServiceException, OMEROServerError { - return ExceptionHandler.of(gateway, - g -> g.getQueryService(ctx) - .findAllByQuery(query, null)) - .handleServiceOrServer("Query failed: " + query) - .get(); + throws ServiceException, AccessException { + return call(gateway, + g -> g.getQueryService(ctx) + .findAllByQuery(query, null), + "Query failed: " + query); } @@ -475,16 +473,15 @@ public IObject save(IObject object) * @throws ServiceException Cannot connect to OMERO. * @throws AccessException Cannot access data. * @throws ExecutionException A Facility can't be retrieved or instantiated. - * @throws OMEROServerError Server error. * @throws InterruptedException If block(long) does not return. */ void delete(IObject object) - throws ServiceException, AccessException, ExecutionException, OMEROServerError, InterruptedException { + throws ServiceException, AccessException, ExecutionException, InterruptedException { final long wait = 500L; ExceptionHandler.ofConsumer(getDm(), d -> d.delete(ctx, object).loop(10, wait)) .rethrow(InterruptedException.class) - .handleException("Cannot delete object") + .handleOMEROException("Cannot delete object") .rethrow(); } @@ -497,16 +494,15 @@ void delete(IObject object) * @throws ServiceException Cannot connect to OMERO. * @throws AccessException Cannot access data. * @throws ExecutionException A Facility can't be retrieved or instantiated. - * @throws OMEROServerError Server error. * @throws InterruptedException If block(long) does not return. */ void delete(List objects) - throws ServiceException, AccessException, ExecutionException, OMEROServerError, InterruptedException { + throws ServiceException, AccessException, ExecutionException, InterruptedException { final long wait = 500L; ExceptionHandler.ofConsumer(getDm(), d -> d.delete(ctx, objects).loop(10, wait)) .rethrow(InterruptedException.class) - .handleException("Cannot delete objects") + .handleOMEROException("Cannot delete objects") .rethrow(); } @@ -519,11 +515,10 @@ void delete(List objects) * @throws ServiceException Cannot connect to OMERO. * @throws AccessException Cannot access data. * @throws ExecutionException A Facility can't be retrieved or instantiated. - * @throws OMEROServerError Server error. * @throws InterruptedException If block(long) does not return. */ public void deleteFile(Long id) - throws ServiceException, AccessException, ExecutionException, OMEROServerError, InterruptedException { + throws ServiceException, AccessException, ExecutionException, InterruptedException { deleteFiles(id); } @@ -536,11 +531,10 @@ public void deleteFile(Long id) * @throws ServiceException Cannot connect to OMERO. * @throws AccessException Cannot access data. * @throws ExecutionException A Facility can't be retrieved or instantiated. - * @throws OMEROServerError Server error. * @throws InterruptedException If block(long) does not return. */ public void deleteFiles(Long... ids) - throws ServiceException, AccessException, ExecutionException, OMEROServerError, InterruptedException { + throws ServiceException, AccessException, ExecutionException, InterruptedException { List files = Arrays.stream(ids) .map(id -> new FileAnnotationI(id, false)) .collect(Collectors.toList()); diff --git a/src/main/java/fr/igred/omero/annotations/FileAnnotationWrapper.java b/src/main/java/fr/igred/omero/annotations/FileAnnotationWrapper.java index 5acdd61b..18b4d857 100644 --- a/src/main/java/fr/igred/omero/annotations/FileAnnotationWrapper.java +++ b/src/main/java/fr/igred/omero/annotations/FileAnnotationWrapper.java @@ -19,8 +19,8 @@ import fr.igred.omero.Client; +import fr.igred.omero.exception.AccessException; import fr.igred.omero.exception.ExceptionHandler; -import fr.igred.omero.exception.OMEROServerError; import fr.igred.omero.exception.ServiceException; import omero.ServerError; import omero.api.RawFileStorePrx; @@ -178,27 +178,26 @@ public long getFileID() { * @return See above. * * @throws ServiceException Cannot connect to OMERO. + * @throws AccessException Cannot access data. * @throws IOException Cannot write to the file. - * @throws OMEROServerError Server error. */ public File getFile(Client client, String path) - throws IOException, ServiceException, OMEROServerError { + throws ServiceException, AccessException, IOException { File file = new File(path); RawFileStorePrx store; try (FileOutputStream stream = new FileOutputStream(file)) { String error = "Could not create RawFileService"; store = ExceptionHandler.of(client, c -> writeFile(c, stream)) - .handleServiceOrServer(error) + .handleOMEROException(error) .rethrow(IOException.class) .get(); } if (store != null) { + String error = "Could not close RawFileService"; ExceptionHandler.ofConsumer(store, RawFileStorePrx::close) - .rethrow(ServerError.class, - OMEROServerError::new, - "Could not close RawFileService") + .handleServerAndService(error) .rethrow(); } diff --git a/src/main/java/fr/igred/omero/annotations/GenericAnnotationWrapper.java b/src/main/java/fr/igred/omero/annotations/GenericAnnotationWrapper.java index e9a9e934..89ac1001 100644 --- a/src/main/java/fr/igred/omero/annotations/GenericAnnotationWrapper.java +++ b/src/main/java/fr/igred/omero/annotations/GenericAnnotationWrapper.java @@ -21,7 +21,6 @@ import fr.igred.omero.Client; import fr.igred.omero.GenericObjectWrapper; import fr.igred.omero.exception.AccessException; -import fr.igred.omero.exception.OMEROServerError; import fr.igred.omero.exception.ServiceException; import fr.igred.omero.repository.DatasetWrapper; import fr.igred.omero.repository.FolderWrapper; @@ -119,10 +118,10 @@ public void setDescription(String description) { * @return See above. * * @throws ServiceException Cannot connect to OMERO. - * @throws OMEROServerError Server error. + * @throws AccessException Cannot access data. */ public int countAnnotationLinks(Client client) - throws ServiceException, OMEROServerError { + throws ServiceException, AccessException { String q = "select link.parent from ome.model.IAnnotationLink link" + " where link.child.id=" + getId(); return client.findByQuery(q).size(); @@ -138,11 +137,10 @@ public int countAnnotationLinks(Client client) * * @throws ServiceException Cannot connect to OMERO. * @throws AccessException Cannot access data. - * @throws OMEROServerError Server error. * @throws ExecutionException A Facility can't be retrieved or instantiated. */ public List getProjects(Client client) - throws ServiceException, AccessException, OMEROServerError, ExecutionException { + throws ServiceException, AccessException, ExecutionException { List os = getLinks(client, ProjectWrapper.ANNOTATION_LINK); Long[] ids = os.stream() .map(IObject::getId) @@ -162,11 +160,10 @@ public List getProjects(Client client) * * @throws ServiceException Cannot connect to OMERO. * @throws AccessException Cannot access data. - * @throws OMEROServerError Server error. * @throws ExecutionException A Facility can't be retrieved or instantiated. */ public List getDatasets(Client client) - throws ServiceException, AccessException, OMEROServerError, ExecutionException { + throws ServiceException, AccessException, ExecutionException { List os = getLinks(client, DatasetWrapper.ANNOTATION_LINK); Long[] ids = os.stream() .map(IObject::getId) @@ -186,11 +183,10 @@ public List getDatasets(Client client) * * @throws ServiceException Cannot connect to OMERO. * @throws AccessException Cannot access data. - * @throws OMEROServerError Server error. * @throws ExecutionException A Facility can't be retrieved or instantiated. */ public List getImages(Client client) - throws ServiceException, AccessException, OMEROServerError, ExecutionException { + throws ServiceException, AccessException, ExecutionException { List os = getLinks(client, ImageWrapper.ANNOTATION_LINK); Long[] ids = os.stream() .map(IObject::getId) @@ -210,11 +206,10 @@ public List getImages(Client client) * * @throws ServiceException Cannot connect to OMERO. * @throws AccessException Cannot access data. - * @throws OMEROServerError Server error. * @throws ExecutionException A Facility can't be retrieved or instantiated. */ public List getScreens(Client client) - throws ServiceException, AccessException, OMEROServerError, ExecutionException { + throws ServiceException, AccessException, ExecutionException { List os = getLinks(client, ScreenWrapper.ANNOTATION_LINK); Long[] ids = os.stream() .map(IObject::getId) @@ -234,11 +229,10 @@ public List getScreens(Client client) * * @throws ServiceException Cannot connect to OMERO. * @throws AccessException Cannot access data. - * @throws OMEROServerError Server error. * @throws ExecutionException A Facility can't be retrieved or instantiated. */ public List getPlates(Client client) - throws ServiceException, AccessException, OMEROServerError, ExecutionException { + throws ServiceException, AccessException, ExecutionException { List os = getLinks(client, PlateWrapper.ANNOTATION_LINK); Long[] ids = os.stream() .map(IObject::getId) @@ -257,10 +251,10 @@ public List getPlates(Client client) * @return See above. * * @throws ServiceException Cannot connect to OMERO. - * @throws OMEROServerError Server error. + * @throws AccessException Cannot access data. */ public List getPlateAcquisitions(Client client) - throws ServiceException, OMEROServerError { + throws ServiceException, AccessException { List os = getLinks(client, PlateAcquisitionWrapper.ANNOTATION_LINK); return os.stream() @@ -280,11 +274,10 @@ public List getPlateAcquisitions(Client client) * * @throws ServiceException Cannot connect to OMERO. * @throws AccessException Cannot access data. - * @throws OMEROServerError Server error. * @throws ExecutionException A Facility can't be retrieved or instantiated. */ public List getWells(Client client) - throws ServiceException, AccessException, OMEROServerError, ExecutionException { + throws ServiceException, AccessException, ExecutionException { List os = getLinks(client, WellWrapper.ANNOTATION_LINK); Long[] ids = os.stream() .map(IObject::getId) @@ -304,11 +297,10 @@ public List getWells(Client client) * * @throws ServiceException Cannot connect to OMERO. * @throws AccessException Cannot access data. - * @throws OMEROServerError Server error. * @throws ExecutionException A Facility can't be retrieved or instantiated. */ public List getFolders(Client client) - throws ServiceException, AccessException, OMEROServerError, ExecutionException { + throws ServiceException, AccessException, ExecutionException { List os = getLinks(client, FolderWrapper.ANNOTATION_LINK); Long[] ids = os.stream() .map(IObject::getId) @@ -328,10 +320,10 @@ public List getFolders(Client client) * @return The list of linked objects. * * @throws ServiceException Cannot connect to OMERO. - * @throws OMEROServerError Server error. + * @throws AccessException Cannot access data. */ private List getLinks(Client client, String linkType) - throws ServiceException, OMEROServerError { + throws ServiceException, AccessException { return client.findByQuery("select link.parent from " + linkType + " link where link.child = " + getId()); } diff --git a/src/main/java/fr/igred/omero/annotations/TagSetWrapper.java b/src/main/java/fr/igred/omero/annotations/TagSetWrapper.java index 2ec224c1..79dda55d 100644 --- a/src/main/java/fr/igred/omero/annotations/TagSetWrapper.java +++ b/src/main/java/fr/igred/omero/annotations/TagSetWrapper.java @@ -21,7 +21,6 @@ import fr.igred.omero.Browser; import fr.igred.omero.Client; import fr.igred.omero.exception.AccessException; -import fr.igred.omero.exception.OMEROServerError; import fr.igred.omero.exception.ServiceException; import omero.gateway.model.TagAnnotationData; import omero.model.AnnotationAnnotationLink; @@ -88,10 +87,9 @@ public List getTags() { * @throws ServiceException Cannot connect to OMERO. * @throws AccessException Cannot access data. * @throws ExecutionException A Facility can't be retrieved or instantiated. - * @throws OMEROServerError Server error. */ public List getTags(Browser browser) - throws ExecutionException, AccessException, ServiceException, OMEROServerError { + throws ExecutionException, AccessException, ServiceException { reload(browser); return getTags(); } @@ -142,10 +140,9 @@ public void link(Client dm, TagAnnotationWrapper... tags) * @throws ServiceException Cannot connect to OMERO. * @throws AccessException Cannot access data. * @throws ExecutionException A Facility can't be retrieved or instantiated. - * @throws OMEROServerError Server error. */ public void reload(Browser browser) - throws ServiceException, AccessException, ExecutionException, OMEROServerError { + throws ServiceException, AccessException, ExecutionException { String query = "select t from TagAnnotation as t" + " left outer join fetch t.annotationLinks as l" + " left outer join fetch l.child as a" + diff --git a/src/main/java/fr/igred/omero/exception/ExceptionHandler.java b/src/main/java/fr/igred/omero/exception/ExceptionHandler.java index 64a0a922..3a63373d 100644 --- a/src/main/java/fr/igred/omero/exception/ExceptionHandler.java +++ b/src/main/java/fr/igred/omero/exception/ExceptionHandler.java @@ -468,12 +468,11 @@ public ExceptionHandler handleServiceOrAccess(String message) * @return The same ExceptionHandler. * * @throws AccessException Cannot access data. - * @throws OMEROServerError Server error. * @throws ServiceException Cannot connect to OMERO. */ @Deprecated public ExceptionHandler handleException(String message) - throws ServiceException, AccessException, OMEROServerError { + throws ServiceException, AccessException { return this.handleOMEROException(message); } diff --git a/src/main/java/fr/igred/omero/repository/DatasetWrapper.java b/src/main/java/fr/igred/omero/repository/DatasetWrapper.java index e139eee3..142431cf 100644 --- a/src/main/java/fr/igred/omero/repository/DatasetWrapper.java +++ b/src/main/java/fr/igred/omero/repository/DatasetWrapper.java @@ -23,7 +23,6 @@ import fr.igred.omero.GenericObjectWrapper; import fr.igred.omero.annotations.TagAnnotationWrapper; import fr.igred.omero.exception.AccessException; -import fr.igred.omero.exception.OMEROServerError; import fr.igred.omero.exception.ServiceException; import fr.igred.omero.roi.ROIWrapper; import omero.RLong; @@ -155,13 +154,12 @@ protected String annotationLinkType() { * * @return See above. * - * @throws OMEROServerError Server error. * @throws ServiceException Cannot connect to OMERO. * @throws AccessException Cannot access data. * @throws ExecutionException A Facility can't be retrieved or instantiated. */ public List getProjects(Client client) - throws OMEROServerError, ServiceException, AccessException, ExecutionException { + throws ServiceException, AccessException, ExecutionException { String query = "select link.parent from ProjectDatasetLink as link" + " where link.child=" + getId(); List os = client.findByQuery(query); @@ -256,11 +254,10 @@ public List getImagesLike(Client client, String motif) * * @throws ServiceException Cannot connect to OMERO. * @throws AccessException Cannot access data. - * @throws OMEROServerError Server error. * @throws ExecutionException A Facility can't be retrieved or instantiated. */ public List getImagesTagged(Client client, TagAnnotationWrapper tag) - throws ServiceException, AccessException, OMEROServerError, ExecutionException { + throws ServiceException, AccessException, ExecutionException { return getImagesTagged(client, tag.getId()); } @@ -275,11 +272,10 @@ public List getImagesTagged(Client client, TagAnnotationWrapper ta * * @throws ServiceException Cannot connect to OMERO. * @throws AccessException Cannot access data. - * @throws OMEROServerError Server error. * @throws ExecutionException A Facility can't be retrieved or instantiated. */ public List getImagesTagged(Client client, Long tagId) - throws ServiceException, AccessException, OMEROServerError, ExecutionException { + throws ServiceException, AccessException, ExecutionException { Long[] ids = client.findByQuery("select link.parent" + " from ImageAnnotationLink link" + " where link.child = " + @@ -450,11 +446,10 @@ public void addImage(Client client, ImageWrapper image) * @throws ServiceException Cannot connect to OMERO. * @throws AccessException Cannot access data. * @throws ExecutionException A Facility can't be retrieved or instantiated. - * @throws OMEROServerError Server error. * @throws InterruptedException If block(long) does not return. */ public void removeImage(Client client, ImageWrapper image) - throws ServiceException, AccessException, ExecutionException, OMEROServerError, InterruptedException { + throws ServiceException, AccessException, ExecutionException, InterruptedException { removeLink(client, "DatasetImageLink", image.getId()); } @@ -467,14 +462,13 @@ public void removeImage(Client client, ImageWrapper image) * * @return If the import did not exit because of an error. * - * @throws ServiceException Cannot connect to OMERO. - * @throws AccessException Cannot access data. - * @throws OMEROServerError Server error. - * @throws IOException Cannot read file. + * @throws ServiceException Cannot connect to OMERO. + * @throws AccessException Cannot access data. + * @throws IOException Cannot read file. * @throws ExecutionException A Facility can't be retrieved or instantiated. */ public boolean importImages(Client client, String... paths) - throws ServiceException, OMEROServerError, AccessException, IOException, ExecutionException { + throws ServiceException, AccessException, IOException, ExecutionException { return importImages(client, 1, paths); } @@ -488,14 +482,13 @@ public boolean importImages(Client client, String... paths) * * @return If the import did not exit because of an error. * - * @throws ServiceException Cannot connect to OMERO. - * @throws AccessException Cannot access data. - * @throws OMEROServerError Server error. - * @throws IOException Cannot read file. + * @throws ServiceException Cannot connect to OMERO. + * @throws AccessException Cannot access data. + * @throws IOException Cannot read file. * @throws ExecutionException A Facility can't be retrieved or instantiated. */ public boolean importImages(Client client, int threads, String... paths) - throws ServiceException, OMEROServerError, AccessException, IOException, ExecutionException { + throws ServiceException, AccessException, IOException, ExecutionException { return importImages(client, data, threads, paths); } @@ -508,13 +501,12 @@ public boolean importImages(Client client, int threads, String... paths) * * @return The list of IDs of the newly imported images. * - * @throws ServiceException Cannot connect to OMERO. - * @throws AccessException Cannot access data. - * @throws OMEROServerError Server error. - * @throws ExecutionException A Facility can't be retrieved or instantiated. + * @throws ServiceException Cannot connect to OMERO. + * @throws AccessException Cannot access data. + * @throws IOException Cannot read file. */ public List importImage(Client client, String path) - throws ServiceException, AccessException, OMEROServerError, ExecutionException { + throws ServiceException, AccessException, IOException { return importImage(client, data, path); } @@ -531,14 +523,13 @@ public List importImage(Client client, String path) * * @throws ServiceException Cannot connect to OMERO. * @throws AccessException Cannot access data. - * @throws OMEROServerError Server error. * @throws ExecutionException A Facility can't be retrieved or instantiated. * @throws InterruptedException If block(long) does not return. */ public List replaceImages(Client client, Collection oldImages, ImageWrapper newImage) - throws AccessException, ServiceException, ExecutionException, OMEROServerError, InterruptedException { + throws AccessException, ServiceException, ExecutionException, InterruptedException { Collection descriptions = new ArrayList<>(oldImages.size() + 1); List orphaned = new ArrayList<>(oldImages.size()); descriptions.add(newImage.getDescription()); @@ -576,12 +567,12 @@ public List replaceImages(Client client, * * @throws ServiceException Cannot connect to OMERO. * @throws AccessException Cannot access data. - * @throws OMEROServerError Server error. + * @throws IOException Cannot read file. * @throws ExecutionException A Facility can't be retrieved or instantiated. * @throws InterruptedException If block(long) does not return. */ public List importAndReplaceImages(Client client, String path, ReplacePolicy policy) - throws ServiceException, AccessException, OMEROServerError, ExecutionException, InterruptedException { + throws ServiceException, AccessException, IOException, ExecutionException, InterruptedException { List ids = importImage(client, path); Long[] newIds = ids.toArray(LONGS); @@ -627,12 +618,12 @@ public List importAndReplaceImages(Client client, String path, ReplacePoli * * @throws ServiceException Cannot connect to OMERO. * @throws AccessException Cannot access data. - * @throws OMEROServerError Server error. + * @throws IOException Cannot read file. * @throws ExecutionException A Facility can't be retrieved or instantiated. * @throws InterruptedException If block(long) does not return. */ public List importAndReplaceImages(Client client, String path) - throws ServiceException, AccessException, OMEROServerError, ExecutionException, InterruptedException { + throws ServiceException, AccessException, IOException, ExecutionException, InterruptedException { return importAndReplaceImages(client, path, ReplacePolicy.UNLINK); } diff --git a/src/main/java/fr/igred/omero/repository/FolderWrapper.java b/src/main/java/fr/igred/omero/repository/FolderWrapper.java index 670f0830..a10f9aea 100644 --- a/src/main/java/fr/igred/omero/repository/FolderWrapper.java +++ b/src/main/java/fr/igred/omero/repository/FolderWrapper.java @@ -23,7 +23,6 @@ import fr.igred.omero.GenericObjectWrapper; import fr.igred.omero.exception.AccessException; import fr.igred.omero.exception.ExceptionHandler; -import fr.igred.omero.exception.OMEROServerError; import fr.igred.omero.exception.ServiceException; import fr.igred.omero.roi.ROIWrapper; import omero.gateway.facility.ROIFacility; @@ -94,16 +93,16 @@ public FolderWrapper(Folder folder) { * @param name Name of the folder. * * @throws ServiceException Cannot connect to OMERO. - * @throws OMEROServerError Server error. + * @throws AccessException Cannot access data. */ public FolderWrapper(Client client, String name) - throws ServiceException, OMEROServerError { + throws ServiceException, AccessException { super(new FolderData()); data.setName(name); Folder f = (Folder) ExceptionHandler.of(client.getGateway(), g -> g.getUpdateService(client.getCtx()) .saveAndReturnObject(data.asIObject())) - .handleServiceOrServer("Could not create Folder with name: " + name) + .handleServerAndService("Could not create Folder with name: " + name) .get(); data.setFolder(f); } diff --git a/src/main/java/fr/igred/omero/repository/GenericRepositoryObjectWrapper.java b/src/main/java/fr/igred/omero/repository/GenericRepositoryObjectWrapper.java index 37ac697c..3387b07e 100644 --- a/src/main/java/fr/igred/omero/repository/GenericRepositoryObjectWrapper.java +++ b/src/main/java/fr/igred/omero/repository/GenericRepositoryObjectWrapper.java @@ -24,7 +24,6 @@ import fr.igred.omero.GatewayWrapper; import fr.igred.omero.exception.AccessException; import fr.igred.omero.exception.ExceptionHandler; -import fr.igred.omero.exception.OMEROServerError; import fr.igred.omero.exception.ServiceException; import loci.formats.in.DefaultMetadataOptions; import loci.formats.in.MetadataLevel; @@ -36,19 +35,21 @@ import ome.formats.importer.OMEROWrapper; import ome.formats.importer.cli.ErrorHandler; import ome.formats.importer.cli.LoggingImportMonitor; -import omero.ServerError; import omero.gateway.model.DataObject; import omero.gateway.util.PojoMapper; import omero.model.Pixels; import java.io.IOException; +import java.lang.invoke.MethodHandles; import java.util.ArrayList; import java.util.Collection; import java.util.List; import java.util.concurrent.ExecutionException; import java.util.concurrent.ExecutorService; import java.util.concurrent.Executors; -import java.util.stream.Collectors; +import java.util.logging.Logger; + +import static java.util.stream.Collectors.toList; /** @@ -68,6 +69,46 @@ protected GenericRepositoryObjectWrapper(T o) { } + /** + * Method used for importing a number of import candidates. + * + * @param target The import target. + * @param library The importer. + * @param config The configuration information. + * @param candidates Hosts information about the files to import. + * + * @return The list of imported pixels. + */ + private static List importCandidates(DataObject target, ImportLibrary library, ImportConfig config, ImportCandidates candidates) { + List pixels = new ArrayList<>(0); + + ExecutorService threadPool = Executors.newFixedThreadPool(config.parallelUpload.get()); + + List containers = candidates.getContainers(); + if (containers != null) { + pixels = new ArrayList<>(containers.size()); + for (int i = 0; i < containers.size(); i++) { + ImportContainer container = containers.get(i); + container.setTarget(target.asIObject()); + List imported = new ArrayList<>(1); + try { + imported = library.importImage(container, threadPool, i); + } catch (Throwable e) { + String filename = container.getFile().getName(); + String error = String.format("Error during image import for: %s", filename); + Logger.getLogger(MethodHandles.lookup().lookupClass().getName()).severe(error); + if (Boolean.FALSE.equals(config.contOnError.get())) { + return pixels; + } + } + pixels.addAll(imported); + } + } + threadPool.shutdown(); + return pixels; + } + + /** * Imports all images candidates in the paths to the target in OMERO. * @@ -79,11 +120,11 @@ protected GenericRepositoryObjectWrapper(T o) { * @return If the import did not exit because of an error. * * @throws ServiceException Cannot connect to OMERO. - * @throws OMEROServerError Server error. + * @throws AccessException Cannot access data. * @throws IOException Cannot read file. */ protected static boolean importImages(GatewayWrapper client, DataObject target, int threads, String... paths) - throws ServiceException, OMEROServerError, IOException { + throws ServiceException, AccessException, IOException { boolean success; ImportConfig config = new ImportConfig(); @@ -96,10 +137,8 @@ protected static boolean importImages(GatewayWrapper client, DataObject target, OMEROMetadataStoreClient store = client.getImportStore(); try (OMEROWrapper reader = new OMEROWrapper(config)) { - ExceptionHandler.ofConsumer(store, - s -> s.logVersionInfo(config.getIniVersionNumber())) - .rethrow(ServerError.class, OMEROServerError::new, - "Cannot log version information during import.") + ExceptionHandler.ofConsumer(store, s -> s.logVersionInfo(config.getIniVersionNumber())) + .handleServerAndService("Cannot log version information during import.") .rethrow(); reader.setMetadataOptions(new DefaultMetadataOptions(MetadataLevel.ALL)); @@ -128,21 +167,24 @@ protected static boolean importImages(GatewayWrapper client, DataObject target, * @return The list of IDs of the newly imported images. * * @throws ServiceException Cannot connect to OMERO. - * @throws OMEROServerError Server error. + * @throws AccessException Cannot access data. + * @throws IOException Cannot read file. */ protected static List importImage(GatewayWrapper client, DataObject target, String path) - throws ServiceException, OMEROServerError { + throws ServiceException, AccessException, IOException { ImportConfig config = new ImportConfig(); String type = PojoMapper.getGraphType(target.getClass()); config.target.set(type + ":" + target.getId()); config.username.set(client.getUser().getUserName()); config.email.set(client.getUser().getEmail()); - Collection pixels = new ArrayList<>(1); + Collection pixels; OMEROMetadataStoreClient store = client.getImportStore(); try (OMEROWrapper reader = new OMEROWrapper(config)) { - store.logVersionInfo(config.getIniVersionNumber()); + ExceptionHandler.ofConsumer(store, s -> s.logVersionInfo(config.getIniVersionNumber())) + .handleServerAndService("Cannot log version information during import.") + .rethrow(); reader.setMetadataOptions(new DefaultMetadataOptions(MetadataLevel.ALL)); ImportLibrary library = new ImportLibrary(store, reader); @@ -151,28 +193,15 @@ protected static List importImage(GatewayWrapper client, DataObject target ErrorHandler handler = new ErrorHandler(config); ImportCandidates candidates = new ImportCandidates(reader, new String[]{path}, handler); - - ExecutorService uploadThreadPool = Executors.newFixedThreadPool(config.parallelUpload.get()); - - List containers = candidates.getContainers(); - if (containers != null) { - for (int i = 0; i < containers.size(); i++) { - ImportContainer container = containers.get(i); - container.setTarget(target.asIObject()); - List imported = library.importImage(container, uploadThreadPool, i); - pixels.addAll(imported); - } - } - uploadThreadPool.shutdown(); - } catch (Throwable e) { - throw new OMEROServerError(e); + pixels = importCandidates(target, library, config, candidates); } finally { client.closeImport(); } - List ids = new ArrayList<>(pixels.size()); - pixels.forEach(pix -> ids.add(pix.getImage().getId().getValue())); - return ids.stream().distinct().collect(Collectors.toList()); + return pixels.stream() + .map(pix -> pix.getImage().getId().getValue()) + .distinct() + .collect(toList()); } diff --git a/src/main/java/fr/igred/omero/repository/ImageWrapper.java b/src/main/java/fr/igred/omero/repository/ImageWrapper.java index d926651f..fb1261d2 100644 --- a/src/main/java/fr/igred/omero/repository/ImageWrapper.java +++ b/src/main/java/fr/igred/omero/repository/ImageWrapper.java @@ -22,8 +22,6 @@ import fr.igred.omero.Client; import fr.igred.omero.GenericObjectWrapper; import fr.igred.omero.exception.AccessException; -import fr.igred.omero.exception.ExceptionHandler; -import fr.igred.omero.exception.OMEROServerError; import fr.igred.omero.exception.ServiceException; import fr.igred.omero.repository.PixelsWrapper.Bounds; import fr.igred.omero.repository.PixelsWrapper.Coordinates; @@ -291,13 +289,12 @@ protected String annotationLinkType() { * * @return See above. * - * @throws OMEROServerError Server error. * @throws ServiceException Cannot connect to OMERO. * @throws AccessException Cannot access data. * @throws ExecutionException A Facility can't be retrieved or instantiated. */ public List getProjects(Client client) - throws OMEROServerError, ServiceException, AccessException, ExecutionException { + throws ServiceException, AccessException, ExecutionException { List datasets = getDatasets(client); Collection projects = new ArrayList<>(datasets.size()); for (DatasetWrapper dataset : datasets) { @@ -314,13 +311,12 @@ public List getProjects(Client client) * * @return See above. * - * @throws OMEROServerError Server error. * @throws ServiceException Cannot connect to OMERO. * @throws AccessException Cannot access data. * @throws ExecutionException A Facility can't be retrieved or instantiated. */ public List getDatasets(Client client) - throws OMEROServerError, ServiceException, AccessException, ExecutionException { + throws ServiceException, AccessException, ExecutionException { String query = "select link.parent from DatasetImageLink as link" + " where link.child=" + getId(); List os = client.findByQuery(query); @@ -445,10 +441,9 @@ public List getPlates(Client client) * @throws ServiceException Cannot connect to OMERO. * @throws AccessException Cannot access data. * @throws ExecutionException A Facility can't be retrieved or instantiated. - * @throws OMEROServerError Server error. */ public List getScreens(Client client) - throws AccessException, ServiceException, ExecutionException, OMEROServerError { + throws AccessException, ServiceException, ExecutionException { List plates = getPlates(client); Collection> screens = new ArrayList<>(plates.size()); @@ -467,10 +462,10 @@ public List getScreens(Client client) * @return {@code true} if the image is orphaned, {@code false} otherwise. * * @throws ServiceException Cannot connect to OMERO. - * @throws OMEROServerError Server error. + * @throws AccessException Cannot access data. */ public boolean isOrphaned(Client client) - throws ServiceException, OMEROServerError { + throws ServiceException, AccessException { String dsQuery = "select link.parent from DatasetImageLink link" + " where link.child=" + getId(); String wsQuery = "select ws from WellSample ws where image=" + getId(); @@ -491,10 +486,9 @@ public boolean isOrphaned(Client client) * @throws AccessException Cannot access data. * @throws ServiceException Cannot connect to OMERO. * @throws ExecutionException A Facility can't be retrieved or instantiated. - * @throws OMEROServerError Server error. */ public List getFilesetImages(Client client) - throws AccessException, ServiceException, ExecutionException, OMEROServerError { + throws AccessException, ServiceException, ExecutionException { List related = new ArrayList<>(0); if (data.isFSImage()) { long fsId = this.asDataObject().getFilesetId(); @@ -638,10 +632,9 @@ public List getROIFolders(Client client) * @throws ServiceException Cannot connect to OMERO. * @throws AccessException Cannot access data. * @throws ExecutionException A Facility can't be retrieved or instantiated. - * @throws OMEROServerError Server error. */ public List getFolders(Client client) - throws ServiceException, AccessException, ExecutionException, OMEROServerError { + throws ServiceException, AccessException, ExecutionException { String template = "select link.parent from FolderImageLink as link" + " where link.child.id=%d"; String query = String.format(template, getId()); @@ -660,13 +653,13 @@ public List getFolders(Client client) * @return The folder if it exists. * * @throws ServiceException Cannot connect to OMERO. - * @throws OMEROServerError Server error. + * @throws AccessException Cannot access data. * @throws NoSuchElementException Folder does not exist. * @deprecated Gets the folder with the specified id on OMERO. */ @Deprecated public FolderWrapper getFolder(Client client, Long folderId) - throws ServiceException, OMEROServerError { + throws ServiceException, AccessException { List os = client.findByQuery("select f " + "from Folder as f " + "where f.id = " + @@ -976,17 +969,16 @@ public Color getChannelColor(Client client, int index) * @return The thumbnail as a {@link BufferedImage}. * * @throws ServiceException Cannot connect to OMERO. - * @throws OMEROServerError Server error. + * @throws AccessException Cannot access data. * @throws IOException Cannot read thumbnail from store. */ public BufferedImage getThumbnail(Client client, int size) - throws ServiceException, OMEROServerError, IOException { + throws ServiceException, AccessException, IOException { BufferedImage thumbnail = null; - byte[] arr = ExceptionHandler.of(client, - c -> getThumbnailBytes(c, size)) - .handleServiceOrServer("Error retrieving thumbnail.") - .get(); + byte[] arr = call(client, + c -> getThumbnailBytes(c, size), + "Error retrieving thumbnail."); if (arr != null) { try (ByteArrayInputStream stream = new ByteArrayInputStream(arr)) { //Create a buffered image to display @@ -1045,12 +1037,11 @@ public List getManagedRepositoriesPaths(Client client) * * @return See above. * - * @throws OMEROServerError Server error. * @throws ServiceException Cannot connect to OMERO. * @throws AccessException Cannot access data. */ public List download(Client client, String path) - throws OMEROServerError, ServiceException, AccessException { + throws ServiceException, AccessException { List files = new ArrayList<>(0); try { files = call(client.getGateway().getFacility(TransferFacility.class), diff --git a/src/main/java/fr/igred/omero/repository/PlateAcquisitionWrapper.java b/src/main/java/fr/igred/omero/repository/PlateAcquisitionWrapper.java index 27982b0d..cbccab94 100644 --- a/src/main/java/fr/igred/omero/repository/PlateAcquisitionWrapper.java +++ b/src/main/java/fr/igred/omero/repository/PlateAcquisitionWrapper.java @@ -21,7 +21,6 @@ import fr.igred.omero.Browser; import fr.igred.omero.Client; import fr.igred.omero.exception.AccessException; -import fr.igred.omero.exception.OMEROServerError; import fr.igred.omero.exception.ServiceException; import omero.gateway.model.AnnotationData; import omero.gateway.model.PlateAcquisitionData; @@ -36,8 +35,6 @@ import java.util.concurrent.ExecutionException; import java.util.stream.Collectors; -import static fr.igred.omero.exception.ExceptionHandler.call; - /** * Class containing a PlateAcquisitionData object. @@ -171,10 +168,9 @@ protected void link(Client client, A annotation) * @throws ServiceException Cannot connect to OMERO. * @throws AccessException Cannot access data. * @throws ExecutionException A Facility can't be retrieved or instantiated. - * @throws OMEROServerError Server error. */ public List getScreens(Client client) - throws ServiceException, AccessException, ExecutionException, OMEROServerError { + throws ServiceException, AccessException, ExecutionException { PlateWrapper plate = client.getPlate(getRefPlateId()); return plate.getScreens(client); } @@ -359,13 +355,7 @@ public void reload(Browser browser) " left outer join fetch img.pixels as pix" + " left outer join fetch pix.pixelsType as pt" + " where pa.id=" + getId(); - // TODO: replace with Browser::findByQuery when possible - IObject o = call(browser.getGateway(), - g -> g.getQueryService(browser.getCtx()) - .findAllByQuery(query, null) - .iterator() - .next(), - "Query failed: " + query); + IObject o = browser.findByQuery(query).iterator().next(); data = new PlateAcquisitionData((omero.model.PlateAcquisition) o); initRefPlate(); } diff --git a/src/main/java/fr/igred/omero/repository/PlateWrapper.java b/src/main/java/fr/igred/omero/repository/PlateWrapper.java index 6b413980..7f757c35 100644 --- a/src/main/java/fr/igred/omero/repository/PlateWrapper.java +++ b/src/main/java/fr/igred/omero/repository/PlateWrapper.java @@ -22,7 +22,6 @@ import fr.igred.omero.Client; import fr.igred.omero.GenericObjectWrapper; import fr.igred.omero.exception.AccessException; -import fr.igred.omero.exception.OMEROServerError; import fr.igred.omero.exception.ServiceException; import ome.model.units.BigResult; import omero.RLong; @@ -136,13 +135,12 @@ public void setDescription(String description) { * * @return See above. * - * @throws OMEROServerError Server error. * @throws ServiceException Cannot connect to OMERO. * @throws AccessException Cannot access data. * @throws ExecutionException A Facility can't be retrieved or instantiated. */ public List getScreens(Client client) - throws OMEROServerError, ServiceException, AccessException, ExecutionException { + throws ServiceException, AccessException, ExecutionException { String query = "select link.parent from ScreenPlateLink as link" + " where link.child=" + getId(); List os = client.findByQuery(query); diff --git a/src/main/java/fr/igred/omero/repository/ProjectWrapper.java b/src/main/java/fr/igred/omero/repository/ProjectWrapper.java index cfd19d0d..5fae2f57 100644 --- a/src/main/java/fr/igred/omero/repository/ProjectWrapper.java +++ b/src/main/java/fr/igred/omero/repository/ProjectWrapper.java @@ -23,7 +23,6 @@ import fr.igred.omero.GenericObjectWrapper; import fr.igred.omero.annotations.TagAnnotationWrapper; import fr.igred.omero.exception.AccessException; -import fr.igred.omero.exception.OMEROServerError; import fr.igred.omero.exception.ServiceException; import omero.gateway.model.ImageData; import omero.gateway.model.ProjectData; @@ -226,11 +225,10 @@ public DatasetWrapper addDataset(Client client, DatasetWrapper dataset) * @throws ServiceException Cannot connect to OMERO. * @throws AccessException Cannot access data. * @throws ExecutionException A Facility can't be retrieved or instantiated. - * @throws OMEROServerError Server error. * @throws InterruptedException If block(long) does not return. */ public void removeDataset(Client client, DatasetWrapper dataset) - throws ServiceException, AccessException, ExecutionException, OMEROServerError, InterruptedException { + throws ServiceException, AccessException, ExecutionException, InterruptedException { removeLink(client, "ProjectDatasetLink", dataset.getId()); reload(client); } @@ -346,11 +344,10 @@ public List getImagesLike(Client client, String motif) * * @throws ServiceException Cannot connect to OMERO. * @throws AccessException Cannot access data. - * @throws OMEROServerError Server error. * @throws ExecutionException A Facility can't be retrieved or instantiated. */ public List getImagesTagged(Client client, TagAnnotationWrapper tag) - throws ServiceException, AccessException, OMEROServerError, ExecutionException { + throws ServiceException, AccessException, ExecutionException { Collection datasets = getDatasets(); Collection> lists = new ArrayList<>(datasets.size()); @@ -371,11 +368,10 @@ public List getImagesTagged(Client client, TagAnnotationWrapper ta * * @throws ServiceException Cannot connect to OMERO. * @throws AccessException Cannot access data. - * @throws OMEROServerError Server error. * @throws ExecutionException A Facility can't be retrieved or instantiated. */ public List getImagesTagged(Client client, Long tagId) - throws ServiceException, AccessException, OMEROServerError, ExecutionException { + throws ServiceException, AccessException, ExecutionException { Collection datasets = getDatasets(); Collection> lists = new ArrayList<>(datasets.size()); diff --git a/src/main/java/fr/igred/omero/repository/ScreenWrapper.java b/src/main/java/fr/igred/omero/repository/ScreenWrapper.java index e4cfaeaa..b7e4d206 100644 --- a/src/main/java/fr/igred/omero/repository/ScreenWrapper.java +++ b/src/main/java/fr/igred/omero/repository/ScreenWrapper.java @@ -22,7 +22,6 @@ import fr.igred.omero.Client; import fr.igred.omero.GatewayWrapper; import fr.igred.omero.exception.AccessException; -import fr.igred.omero.exception.OMEROServerError; import fr.igred.omero.exception.ServiceException; import omero.gateway.model.ScreenData; @@ -369,12 +368,11 @@ public void reload(Browser browser) * * @throws ServiceException Cannot connect to OMERO. * @throws AccessException Cannot access data. - * @throws OMEROServerError Server error. * @throws IOException Cannot read file. * @throws ExecutionException A Facility can't be retrieved or instantiated. */ public boolean importImages(GatewayWrapper client, String... paths) - throws ServiceException, OMEROServerError, AccessException, IOException, ExecutionException { + throws ServiceException, AccessException, IOException, ExecutionException { return importImages(client, 1, paths); } @@ -390,12 +388,11 @@ public boolean importImages(GatewayWrapper client, String... paths) * * @throws ServiceException Cannot connect to OMERO. * @throws AccessException Cannot access data. - * @throws OMEROServerError Server error. * @throws IOException Cannot read file. * @throws ExecutionException A Facility can't be retrieved or instantiated. */ public boolean importImages(GatewayWrapper client, int threads, String... paths) - throws ServiceException, OMEROServerError, AccessException, IOException, ExecutionException { + throws ServiceException, AccessException, IOException, ExecutionException { return importImages(client, data, threads, paths); } @@ -408,13 +405,12 @@ public boolean importImages(GatewayWrapper client, int threads, String... paths) * * @return The list of IDs of the newly imported images. * - * @throws ServiceException Cannot connect to OMERO. - * @throws AccessException Cannot access data. - * @throws OMEROServerError Server error. - * @throws ExecutionException A Facility can't be retrieved or instantiated. + * @throws ServiceException Cannot connect to OMERO. + * @throws AccessException Cannot access data. + * @throws IOException Cannot read file. */ public List importImage(GatewayWrapper client, String path) - throws ServiceException, AccessException, OMEROServerError, ExecutionException { + throws ServiceException, AccessException, IOException { return importImage(client, data, path); } diff --git a/src/main/java/fr/igred/omero/repository/WellSampleWrapper.java b/src/main/java/fr/igred/omero/repository/WellSampleWrapper.java index 3310b7f0..07b4a94c 100644 --- a/src/main/java/fr/igred/omero/repository/WellSampleWrapper.java +++ b/src/main/java/fr/igred/omero/repository/WellSampleWrapper.java @@ -22,7 +22,6 @@ import fr.igred.omero.Client; import fr.igred.omero.GenericObjectWrapper; import fr.igred.omero.exception.AccessException; -import fr.igred.omero.exception.OMEROServerError; import fr.igred.omero.exception.ServiceException; import ome.model.units.BigResult; import omero.gateway.model.PlateAcquisitionData; @@ -35,8 +34,6 @@ import java.util.List; import java.util.concurrent.ExecutionException; -import static fr.igred.omero.exception.ExceptionHandler.call; - /** * Class containing a WellSampleData object. @@ -76,10 +73,9 @@ public WellSampleData asWellSampleData() { * @throws ServiceException Cannot connect to OMERO. * @throws AccessException Cannot access data. * @throws ExecutionException A Facility can't be retrieved or instantiated. - * @throws OMEROServerError Server error. */ public List getScreens(Client client) - throws ServiceException, AccessException, ExecutionException, OMEROServerError { + throws ServiceException, AccessException, ExecutionException { return getWell(client).getScreens(client); } @@ -220,13 +216,7 @@ public void reload(Browser browser) " left outer join fetch ws.image as img" + " left outer join fetch img.pixels as pix" + " where ws.id=" + getId(); - // TODO: replace with Browser::findByQuery when possible - IObject o = call(browser.getGateway(), - g -> g.getQueryService(browser.getCtx()) - .findAllByQuery(query, null) - .iterator() - .next(), - "Query failed: " + query); + IObject o = browser.findByQuery(query).iterator().next(); data = new WellSampleData((omero.model.WellSample) o); } diff --git a/src/main/java/fr/igred/omero/repository/WellWrapper.java b/src/main/java/fr/igred/omero/repository/WellWrapper.java index c22b611b..1a3050a9 100644 --- a/src/main/java/fr/igred/omero/repository/WellWrapper.java +++ b/src/main/java/fr/igred/omero/repository/WellWrapper.java @@ -21,7 +21,6 @@ import fr.igred.omero.Browser; import fr.igred.omero.Client; import fr.igred.omero.exception.AccessException; -import fr.igred.omero.exception.OMEROServerError; import fr.igred.omero.exception.ServiceException; import omero.gateway.model.WellData; @@ -140,10 +139,9 @@ public List getWellSamples() { * @throws ServiceException Cannot connect to OMERO. * @throws AccessException Cannot access data. * @throws ExecutionException A Facility can't be retrieved or instantiated. - * @throws OMEROServerError Server error. */ public List getScreens(Client client) - throws ServiceException, AccessException, ExecutionException, OMEROServerError { + throws ServiceException, AccessException, ExecutionException { reload(client); return getPlate().getScreens(client); } diff --git a/src/main/java/fr/igred/omero/roi/ROIWrapper.java b/src/main/java/fr/igred/omero/roi/ROIWrapper.java index 3b19f188..5b57edeb 100644 --- a/src/main/java/fr/igred/omero/roi/ROIWrapper.java +++ b/src/main/java/fr/igred/omero/roi/ROIWrapper.java @@ -23,7 +23,6 @@ import fr.igred.omero.GenericObjectWrapper; import fr.igred.omero.exception.AccessException; import fr.igred.omero.exception.ExceptionHandler; -import fr.igred.omero.exception.OMEROServerError; import fr.igred.omero.exception.ServiceException; import fr.igred.omero.repository.ImageWrapper; import fr.igred.omero.repository.PixelsWrapper.Bounds; @@ -472,15 +471,15 @@ public void deleteShape(int pos) { * * @param client The client handling the connection. * + * @throws AccessException Cannot access data. * @throws ServiceException Cannot connect to OMERO. - * @throws OMEROServerError Server error. */ public void saveROI(Client client) - throws OMEROServerError, ServiceException { + throws AccessException, ServiceException { Roi roi = (Roi) ExceptionHandler.of(client.getGateway(), g -> g.getUpdateService(client.getCtx()) .saveAndReturnObject(data.asIObject())) - .handleServiceOrServer("Cannot save ROI") + .handleOMEROException("Cannot save ROI") .get(); data = new ROIData(roi); } diff --git a/src/test/java/fr/igred/omero/annotations/ImageJTableTest.java b/src/test/java/fr/igred/omero/annotations/ImageJTableTest.java index 83dbcb4c..6e6412d0 100644 --- a/src/test/java/fr/igred/omero/annotations/ImageJTableTest.java +++ b/src/test/java/fr/igred/omero/annotations/ImageJTableTest.java @@ -21,7 +21,6 @@ import fr.igred.omero.Client; import fr.igred.omero.UserTest; import fr.igred.omero.exception.AccessException; -import fr.igred.omero.exception.OMEROServerError; import fr.igred.omero.exception.ServiceException; import fr.igred.omero.repository.ImageWrapper; import fr.igred.omero.roi.ROIWrapper; @@ -134,7 +133,7 @@ public void cleanUp() { String msg = "%sROIs were not properly deleted.%s"; logger.log(SEVERE, format(msg, ANSI_RED, ANSI_RESET)); } - } catch (AccessException | ServiceException | OMEROServerError | ExecutionException | + } catch (AccessException | ServiceException | ExecutionException | InterruptedException e) { String msg = "%sROIs were not properly deleted.%s"; logger.log(SEVERE, format(msg, ANSI_RED, ANSI_RESET), e); diff --git a/src/test/java/fr/igred/omero/exception/AccessExceptionTest.java b/src/test/java/fr/igred/omero/exception/AccessExceptionTest.java index 4f36cbdf..cb697f8e 100644 --- a/src/test/java/fr/igred/omero/exception/AccessExceptionTest.java +++ b/src/test/java/fr/igred/omero/exception/AccessExceptionTest.java @@ -176,10 +176,9 @@ void testSudoFailDeleteProjects() { } - // This test returns a ServiceException for a "security violation". @Test void testSudoFailGetDatasets() { - assertThrows(ServiceException.class, () -> sudo.getDatasets()); + assertThrows(AccessException.class, () -> sudo.getDatasets()); } @@ -222,13 +221,13 @@ void testSudoFailGetImagesLike() { @Test void testSudoFailGetAllTags() { - assertThrows(ServiceException.class, () -> sudo.getTags()); + assertThrows(AccessException.class, () -> sudo.getTags()); } @Test void testSudoFailGetTag() { - assertThrows(ServiceException.class, () -> sudo.getTag(TAG1.id)); + assertThrows(AccessException.class, () -> sudo.getTag(TAG1.id)); } From 4a32e0ded067e3e7c05b02d7481a9adbcd8c0cac Mon Sep 17 00:00:00 2001 From: Pierre Pouchin Date: Sat, 24 Feb 2024 01:44:18 +0100 Subject: [PATCH 03/18] Remove useless exceptions --- .../omero/annotations/TagSetWrapper.java | 14 ++++++------- .../omero/repository/DatasetWrapper.java | 6 ++---- .../repository/PlateAcquisitionWrapper.java | 21 ++++++++----------- .../igred/omero/repository/ScreenWrapper.java | 18 +++++++--------- .../omero/repository/WellSampleWrapper.java | 7 +++---- 5 files changed, 28 insertions(+), 38 deletions(-) diff --git a/src/main/java/fr/igred/omero/annotations/TagSetWrapper.java b/src/main/java/fr/igred/omero/annotations/TagSetWrapper.java index 79dda55d..41515e0a 100644 --- a/src/main/java/fr/igred/omero/annotations/TagSetWrapper.java +++ b/src/main/java/fr/igred/omero/annotations/TagSetWrapper.java @@ -84,12 +84,11 @@ public List getTags() { * * @return See above. * - * @throws ServiceException Cannot connect to OMERO. - * @throws AccessException Cannot access data. - * @throws ExecutionException A Facility can't be retrieved or instantiated. + * @throws ServiceException Cannot connect to OMERO. + * @throws AccessException Cannot access data. */ public List getTags(Browser browser) - throws ExecutionException, AccessException, ServiceException { + throws AccessException, ServiceException { reload(browser); return getTags(); } @@ -137,12 +136,11 @@ public void link(Client dm, TagAnnotationWrapper... tags) * * @param browser The data browser. * - * @throws ServiceException Cannot connect to OMERO. - * @throws AccessException Cannot access data. - * @throws ExecutionException A Facility can't be retrieved or instantiated. + * @throws ServiceException Cannot connect to OMERO. + * @throws AccessException Cannot access data. */ public void reload(Browser browser) - throws ServiceException, AccessException, ExecutionException { + throws ServiceException, AccessException { String query = "select t from TagAnnotation as t" + " left outer join fetch t.annotationLinks as l" + " left outer join fetch l.child as a" + diff --git a/src/main/java/fr/igred/omero/repository/DatasetWrapper.java b/src/main/java/fr/igred/omero/repository/DatasetWrapper.java index 142431cf..ffcc00c6 100644 --- a/src/main/java/fr/igred/omero/repository/DatasetWrapper.java +++ b/src/main/java/fr/igred/omero/repository/DatasetWrapper.java @@ -465,10 +465,9 @@ public void removeImage(Client client, ImageWrapper image) * @throws ServiceException Cannot connect to OMERO. * @throws AccessException Cannot access data. * @throws IOException Cannot read file. - * @throws ExecutionException A Facility can't be retrieved or instantiated. */ public boolean importImages(Client client, String... paths) - throws ServiceException, AccessException, IOException, ExecutionException { + throws ServiceException, AccessException, IOException { return importImages(client, 1, paths); } @@ -485,10 +484,9 @@ public boolean importImages(Client client, String... paths) * @throws ServiceException Cannot connect to OMERO. * @throws AccessException Cannot access data. * @throws IOException Cannot read file. - * @throws ExecutionException A Facility can't be retrieved or instantiated. */ public boolean importImages(Client client, int threads, String... paths) - throws ServiceException, AccessException, IOException, ExecutionException { + throws ServiceException, AccessException, IOException { return importImages(client, data, threads, paths); } diff --git a/src/main/java/fr/igred/omero/repository/PlateAcquisitionWrapper.java b/src/main/java/fr/igred/omero/repository/PlateAcquisitionWrapper.java index cbccab94..964a8d3b 100644 --- a/src/main/java/fr/igred/omero/repository/PlateAcquisitionWrapper.java +++ b/src/main/java/fr/igred/omero/repository/PlateAcquisitionWrapper.java @@ -232,12 +232,11 @@ public List getWellSamples() { * * @return See above. * - * @throws ServiceException Cannot connect to OMERO. - * @throws AccessException Cannot access data. - * @throws ExecutionException A Facility can't be retrieved or instantiated. + * @throws ServiceException Cannot connect to OMERO. + * @throws AccessException Cannot access data. */ public List getWellSamples(Browser browser) - throws AccessException, ServiceException, ExecutionException { + throws AccessException, ServiceException { reload(browser); return getWellSamples(); } @@ -262,12 +261,11 @@ public List getImages() { * * @return See above * - * @throws ServiceException Cannot connect to OMERO. - * @throws AccessException Cannot access data. - * @throws ExecutionException A Facility can't be retrieved or instantiated. + * @throws ServiceException Cannot connect to OMERO. + * @throws AccessException Cannot access data. */ public List getImages(Client client) - throws ServiceException, AccessException, ExecutionException { + throws ServiceException, AccessException { return getWellSamples(client).stream() .map(WellSampleWrapper::getImage) .collect(Collectors.toList()); @@ -339,13 +337,12 @@ public int getMaximumFieldCount() { * * @param browser The data browser. * - * @throws ServiceException Cannot connect to OMERO. - * @throws AccessException Cannot access data. - * @throws ExecutionException A Facility can't be retrieved or instantiated. + * @throws ServiceException Cannot connect to OMERO. + * @throws AccessException Cannot access data. */ @Override public void reload(Browser browser) - throws ServiceException, AccessException, ExecutionException { + throws ServiceException, AccessException { String query = "select pa from PlateAcquisition as pa " + " left outer join fetch pa.plate as p" + " left outer join fetch pa.wellSample as ws" + diff --git a/src/main/java/fr/igred/omero/repository/ScreenWrapper.java b/src/main/java/fr/igred/omero/repository/ScreenWrapper.java index b7e4d206..0686c17e 100644 --- a/src/main/java/fr/igred/omero/repository/ScreenWrapper.java +++ b/src/main/java/fr/igred/omero/repository/ScreenWrapper.java @@ -366,13 +366,12 @@ public void reload(Browser browser) * * @return If the import did not exit because of an error. * - * @throws ServiceException Cannot connect to OMERO. - * @throws AccessException Cannot access data. - * @throws IOException Cannot read file. - * @throws ExecutionException A Facility can't be retrieved or instantiated. + * @throws ServiceException Cannot connect to OMERO. + * @throws AccessException Cannot access data. + * @throws IOException Cannot read file. */ public boolean importImages(GatewayWrapper client, String... paths) - throws ServiceException, AccessException, IOException, ExecutionException { + throws ServiceException, AccessException, IOException { return importImages(client, 1, paths); } @@ -386,13 +385,12 @@ public boolean importImages(GatewayWrapper client, String... paths) * * @return If the import did not exit because of an error. * - * @throws ServiceException Cannot connect to OMERO. - * @throws AccessException Cannot access data. - * @throws IOException Cannot read file. - * @throws ExecutionException A Facility can't be retrieved or instantiated. + * @throws ServiceException Cannot connect to OMERO. + * @throws AccessException Cannot access data. + * @throws IOException Cannot read file. */ public boolean importImages(GatewayWrapper client, int threads, String... paths) - throws ServiceException, AccessException, IOException, ExecutionException { + throws ServiceException, AccessException, IOException { return importImages(client, data, threads, paths); } diff --git a/src/main/java/fr/igred/omero/repository/WellSampleWrapper.java b/src/main/java/fr/igred/omero/repository/WellSampleWrapper.java index 07b4a94c..d7fccdb2 100644 --- a/src/main/java/fr/igred/omero/repository/WellSampleWrapper.java +++ b/src/main/java/fr/igred/omero/repository/WellSampleWrapper.java @@ -204,12 +204,11 @@ public long getStartTime() { * * @param browser The data browser. * - * @throws ServiceException Cannot connect to OMERO. - * @throws AccessException Cannot access data. - * @throws ExecutionException A Facility can't be retrieved or instantiated. + * @throws ServiceException Cannot connect to OMERO. + * @throws AccessException Cannot access data. */ public void reload(Browser browser) - throws ServiceException, AccessException, ExecutionException { + throws ServiceException, AccessException { String query = "select ws from WellSample as ws" + " left outer join fetch ws.plateAcquisition as pa" + " left outer join fetch ws.well as w" + From 512f4f4ffcd1b14f73cf804beb69493595c28ed7 Mon Sep 17 00:00:00 2001 From: Pierre Pouchin Date: Sun, 24 Sep 2023 11:41:24 +0200 Subject: [PATCH 04/18] Remove deprecated methods in ExceptionHandler --- .../omero/exception/ExceptionHandler.java | 173 ------------------ .../igred/omero/exception/ExceptionTest.java | 54 ++---- 2 files changed, 11 insertions(+), 216 deletions(-) diff --git a/src/main/java/fr/igred/omero/exception/ExceptionHandler.java b/src/main/java/fr/igred/omero/exception/ExceptionHandler.java index 3a63373d..998d00c2 100644 --- a/src/main/java/fr/igred/omero/exception/ExceptionHandler.java +++ b/src/main/java/fr/igred/omero/exception/ExceptionHandler.java @@ -106,118 +106,6 @@ private static boolean shouldBeHandled(Throwable t) { } - /** - * @deprecated Helper method to convert DSOutOfServiceException to ServiceException. - * - * @param t The Exception - * @param message Short explanation of the problem. - * - * @throws ServiceException Cannot connect to OMERO. - */ - @Deprecated - private static void handleServiceException(Throwable t, String message) - throws ServiceException { - if (t instanceof Exception) { - new ExceptionHandler<>(null, (Exception) t) - .rethrow(DSOutOfServiceException.class, ServiceException::new, message); - } - } - - - /** - * @deprecated Helper method to convert ServerError to OMEROServerError. - * - * @param t The Exception - * @param message Short explanation of the problem. - * - * @throws OMEROServerError Server error. - */ - @Deprecated - private static void handleServerError(Throwable t, String message) - throws OMEROServerError { - if (t instanceof ServerError) { - new ExceptionHandler<>(null, (Exception) t).rethrow(ServerError.class, OMEROServerError::new, message); - } - } - - - /** - * @deprecated Helper method to convert DSAccessException to AccessException. - * - * @param t The Exception - * @param message Short explanation of the problem. - * - * @throws AccessException Cannot access data. - */ - @Deprecated - private static void handleAccessException(Throwable t, String message) - throws AccessException { - if (t instanceof DSAccessException) { - new ExceptionHandler<>(null, (Exception) t).rethrow(DSAccessException.class, AccessException::new, message); - } - } - - - /** - * @deprecated Helper method to convert an exception from: - *
  • DSOutOfServiceException to ServiceException
  • - *
  • ServerError to OMEROServerError
- * - * @param t The Exception - * @param message Short explanation of the problem. - * - * @throws ServiceException Cannot connect to OMERO. - * @throws OMEROServerError Server error. - */ - @Deprecated - public static void handleServiceOrServer(Throwable t, String message) - throws ServiceException, OMEROServerError { - handleServiceException(t, message); - handleServerError(t, message); - } - - - /** - * @deprecated Helper method to convert an exception from: - *
  • DSOutOfServiceException to ServiceException
  • - *
  • DSAccessException to AccessException
- * - * @param t The Exception - * @param message Short explanation of the problem. - * - * @throws ServiceException Cannot connect to OMERO. - * @throws AccessException Cannot access data. - */ - @Deprecated - public static void handleServiceOrAccess(Throwable t, String message) - throws ServiceException, AccessException { - handleServiceException(t, message); - handleAccessException(t, message); - } - - - /** - * @deprecated Helper method to convert an exception from: - *
  • DSAccessException to AccessException
  • - *
  • DSOutOfServiceException to ServiceException
  • - *
  • ServerError to OMEROServerError
- * - * @param t The Exception - * @param message Short explanation of the problem. - * - * @throws AccessException Cannot access data. - * @throws OMEROServerError Server error. - * @throws ServiceException Cannot connect to OMERO. - */ - @Deprecated - public static void handleException(Throwable t, String message) - throws ServiceException, AccessException, OMEROServerError { - handleAccessException(t, message); - handleServerError(t, message); - handleServiceException(t, message); - } - - /** * Creates an ExceptionHandler from an object and a function. * @@ -416,67 +304,6 @@ public ExceptionHandler handleServerAndService(String msg) } - /** - * @deprecated Throws: - *
  • {@link ServiceException} if {@link DSOutOfServiceException} was caught
  • - *
  • {@link OMEROServerError} if {@link ServerError} was caught
- * - * @param message Error message. - * - * @return The same ExceptionHandler. - * - * @throws ServiceException Cannot connect to OMERO. - * @throws OMEROServerError Server error. - */ - @Deprecated - public ExceptionHandler handleServiceOrServer(String message) - throws ServiceException, OMEROServerError { - return this.rethrow(DSOutOfServiceException.class, ServiceException::new, message) - .rethrow(ServerError.class, OMEROServerError::new, message); - } - - - /** - * @deprecated Throws: - *
  • {@link ServiceException} if {@link DSOutOfServiceException} was caught
  • - *
  • {@link AccessException} if {@link DSAccessException} was caught
- * - * @param message Error message. - * - * @return The same ExceptionHandler. - * - * @throws ServiceException Cannot connect to OMERO. - * @throws AccessException Cannot access data. - */ - @Deprecated - public ExceptionHandler handleServiceOrAccess(String message) - throws ServiceException, AccessException { - return this.handleOMEROException(message); - } - - - /** - * @deprecated Throws: - *
    - *
  • {@link AccessException} if {@link DSAccessException} was caught
  • - *
  • {@link ServiceException} if {@link DSOutOfServiceException} was caught
  • - *
  • The appropriate exception if {@link ServerError} was caught (see {@link #handleOMEROException})
  • - *
- * - * @param message Error message. - * - * @return The same ExceptionHandler. - * - * @throws AccessException Cannot access data. - * @throws ServiceException Cannot connect to OMERO. - */ - @Deprecated - public ExceptionHandler handleException(String message) - throws ServiceException, AccessException { - return this.handleOMEROException(message); - } - - /** * Throws: *