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 diff --git a/src/main/java/fr/igred/omero/AnnotatableWrapper.java b/src/main/java/fr/igred/omero/AnnotatableWrapper.java index 73119fe1..6daf551c 100644 --- a/src/main/java/fr/igred/omero/AnnotatableWrapper.java +++ b/src/main/java/fr/igred/omero/AnnotatableWrapper.java @@ -19,16 +19,16 @@ import fr.igred.omero.annotations.AnnotationList; +import fr.igred.omero.annotations.AnnotationWrapper; import fr.igred.omero.annotations.FileAnnotationWrapper; -import fr.igred.omero.annotations.GenericAnnotationWrapper; import fr.igred.omero.annotations.MapAnnotationWrapper; import fr.igred.omero.annotations.RatingAnnotationWrapper; import fr.igred.omero.annotations.TableWrapper; import fr.igred.omero.annotations.TagAnnotationWrapper; +import fr.igred.omero.client.Client; 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 fr.igred.omero.RepositoryObjectWrapper.ReplacePolicy; import omero.gateway.facility.TablesFacility; import omero.gateway.model.AnnotationData; import omero.gateway.model.DataObject; @@ -56,7 +56,6 @@ import static fr.igred.omero.exception.ExceptionHandler.call; import static java.util.Collections.singletonList; import static java.util.stream.Collectors.toList; -import static java.util.stream.Collectors.toMap; /** @@ -64,12 +63,12 @@ * * @param Subclass of {@link DataObject} */ -public abstract class AnnotatableWrapper extends GenericObjectWrapper { +public abstract class AnnotatableWrapper extends ObjectWrapper { /** - * Constructor of the class GenericRepositoryObjectWrapper. + * Constructor of the class RepositoryObjectWrapper. * - * @param o The annotatable DataObject to wrap in the GenericRepositoryObjectWrapper. + * @param o The annotatable DataObject to wrap in the RepositoryObjectWrapper. */ protected AnnotatableWrapper(T o) { super(o); @@ -97,7 +96,7 @@ protected AnnotatableWrapper(T o) { * @throws AccessException Cannot access data. * @throws ExecutionException A Facility can't be retrieved or instantiated. */ - public > boolean isLinked(Client client, A annotation) + public > boolean isLinked(Client client, A annotation) throws ServiceException, AccessException, ExecutionException { return getAnnotations(client).stream().anyMatch(a -> a.getId() == annotation.getId()); } @@ -134,7 +133,7 @@ protected void link(Client client, A annotation) * @throws AccessException Cannot access data. * @throws ExecutionException A Facility can't be retrieved or instantiated. */ - public > void link(Client client, A annotation) + public > void link(Client client, A annotation) throws ServiceException, AccessException, ExecutionException { if (!(annotation instanceof TagAnnotationWrapper) || !((TagAnnotationWrapper) annotation).isTagSet()) { link(client, annotation.asDataObject()); @@ -155,9 +154,9 @@ public > void link(Client client, A annota * @throws AccessException Cannot access data. * @throws ExecutionException A Facility can't be retrieved or instantiated. */ - public void link(Client client, GenericAnnotationWrapper... annotations) + public void link(Client client, AnnotationWrapper... annotations) throws ServiceException, AccessException, ExecutionException { - for (GenericAnnotationWrapper annotation : annotations) { + for (AnnotationWrapper annotation : annotations) { link(client, annotation); } } @@ -173,14 +172,14 @@ public void link(Client client, GenericAnnotationWrapper... annotations) * @throws AccessException Cannot access data. * @throws ExecutionException A Facility can't be retrieved or instantiated. */ - public void linkIfNotLinked(Client client, GenericAnnotationWrapper... annotations) + public void linkIfNotLinked(Client client, AnnotationWrapper... annotations) throws ServiceException, AccessException, ExecutionException { List annotationIds = getAnnotationData(client).stream() .map(DataObject::getId) .collect(toList()); link(client, Arrays.stream(annotations) .filter(a -> !annotationIds.contains(a.getId())) - .toArray(GenericAnnotationWrapper[]::new)); + .toArray(AnnotationWrapper[]::new)); } @@ -203,22 +202,6 @@ public void addTag(Client client, String name, String description) } - /** - * @param client The client handling the connection. - * @param tag Tag to be added. - * - * @throws ServiceException Cannot connect to OMERO. - * @throws AccessException Cannot access data. - * @throws ExecutionException A Facility can't be retrieved or instantiated. - * @deprecated Adds a tag to the object in OMERO, if possible. Use {@link #link} instead. - */ - @Deprecated - public void addTag(Client client, TagAnnotationWrapper tag) - throws ServiceException, AccessException, ExecutionException { - link(client, tag); - } - - /** * Adds a tag to the object in OMERO, if possible. * @@ -237,23 +220,6 @@ public void addTag(Client client, Long id) } - /** - * @param client The client handling the connection. - * @param tags Array of tag annotations to add. - * - * @throws ServiceException Cannot connect to OMERO. - * @throws AccessException Cannot access data. - * @throws ExecutionException A Facility can't be retrieved or instantiated. - * @deprecated Adds multiple tag to the object in OMERO, if possible. Use - * {@link #link(Client, GenericAnnotationWrapper[])} instead. - */ - @Deprecated - public void addTags(Client client, TagAnnotationWrapper... tags) - throws ServiceException, AccessException, ExecutionException { - link(client, tags); - } - - /** * Adds multiple tags by ID to the object in OMERO, if possible. * @@ -334,23 +300,6 @@ public List getMapAnnotations(Client client) } - /** - * @param client The client handling the connection. - * @param key Name of the key. - * @param value Value associated to the key. - * - * @throws ServiceException Cannot connect to OMERO. - * @throws AccessException Cannot access data. - * @throws ExecutionException A Facility can't be retrieved or instantiated. - * @deprecated Adds a single Key-Value pair to the object. - */ - @Deprecated - public void addPairKeyValue(Client client, String key, String value) - throws ServiceException, AccessException, ExecutionException { - addKeyValuePair(client, key, value); - } - - /** * Adds a single Key-Value pair to the object. * @@ -369,27 +318,6 @@ public void addKeyValuePair(Client client, String key, String value) } - /** - * Gets the List of key-value pairs associated to an object as a map (no duplicate key should exist). - * - * @param client The client handling the connection. - * - * @return See above. - * - * @throws ServiceException Cannot connect to OMERO. - * @throws AccessException Cannot access data. - * @throws ExecutionException A Facility can't be retrieved or instantiated. - */ - public Map getKeyValuePairs(Client client) - throws ServiceException, AccessException, ExecutionException { - return getMapAnnotations(client).stream() - .map(MapAnnotationWrapper::getContent) - .flatMap(List::stream) - .collect(toMap(nv -> nv.name, - nv -> nv.value)); - } - - /** * Gets the List of Key-Value pairs associated to an object. * @@ -400,14 +328,11 @@ public Map getKeyValuePairs(Client client) * @throws ServiceException Cannot connect to OMERO. * @throws AccessException Cannot access data. * @throws ExecutionException A Facility can't be retrieved or instantiated. - * - * @deprecated This method will be renamed to {@link #getKeyValuePairs(Client)} ()} in a future version. */ - @Deprecated - public List> getKeyValuePairsAsList(Client client) + public List> getKeyValuePairs(Client client) throws ServiceException, AccessException, ExecutionException { return getMapAnnotations(client).stream() - .map(MapAnnotationWrapper::getContentAsEntryList) + .map(MapAnnotationWrapper::getContent) .flatMap(List::stream) .collect(toList()); } @@ -426,15 +351,14 @@ public List> getKeyValuePairsAsList(Client client) * @throws NoSuchElementException Key not found. * @throws ExecutionException A Facility can't be retrieved or instantiated. */ - public String getValue(Client client, String key) + public List getValues(Client client, String key) throws ServiceException, AccessException, ExecutionException { - Map keyValuePairs = getKeyValuePairs(client); - String value = keyValuePairs.get(key); - if (value != null) { - return value; - } else { - throw new NoSuchElementException("Key \"" + key + "\" not found"); - } + return getMapAnnotations(client).stream() + .map(MapAnnotationWrapper::getContentAsMap) + .map(kv -> kv.get(key)) + .filter(Objects::nonNull) + .flatMap(List::stream) + .collect(toList()); } @@ -491,6 +415,7 @@ public List getRatings(Client client) /** * Rates the object (using a rating annotation). + *

If multiple ratings are present, only one will be kept and updated. * * @param client The client handling the connection. * @param rating The rating. @@ -498,11 +423,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); @@ -545,23 +469,6 @@ public int getMyRating(Client client) } - /** - * @param client The client handling the connection. - * @param mapAnnotation The map annotation. - * - * @throws ServiceException Cannot connect to OMERO. - * @throws AccessException Cannot access data. - * @throws ExecutionException A Facility can't be retrieved or instantiated. - * @deprecated Adds a List of Key-Value pair to the object. Use {@link #link} instead. - *

The list is contained in the map annotation. - */ - @Deprecated - public void addMapAnnotation(Client client, MapAnnotationWrapper mapAnnotation) - throws ServiceException, AccessException, ExecutionException { - link(client, mapAnnotation); - } - - /** * Adds a table to the object in OMERO. * @@ -611,10 +518,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 +551,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 +657,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,30 +696,13 @@ 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); } - /** - * @param client The client handling the connection. - * @param annotation FileAnnotationWrapper to link. - * - * @throws ServiceException Cannot connect to OMERO. - * @throws AccessException Cannot access data. - * @throws ExecutionException A Facility can't be retrieved or instantiated. - * @deprecated Links a file annotation to the object. Use {@link #link} instead. - */ - @Deprecated - public void addFileAnnotation(Client client, FileAnnotationWrapper annotation) - throws AccessException, ServiceException, ExecutionException { - link(client, annotation); - } - - /** * Returns the file annotations * @@ -858,11 +745,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 { + public > void unlink(Client client, A annotation) + throws ServiceException, AccessException, ExecutionException, InterruptedException { removeLink(client, annotationLinkType(), annotation.getId()); } @@ -877,11 +763,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 { + public > void unlink(Client client, Collection annotations) + throws ServiceException, AccessException, ExecutionException, InterruptedException { removeLinks(client, annotationLinkType(), annotations.stream() @@ -900,11 +785,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 +813,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/GenericObjectWrapper.java b/src/main/java/fr/igred/omero/ObjectWrapper.java similarity index 89% rename from src/main/java/fr/igred/omero/GenericObjectWrapper.java rename to src/main/java/fr/igred/omero/ObjectWrapper.java index 4ac1e6ed..10333f38 100644 --- a/src/main/java/fr/igred/omero/GenericObjectWrapper.java +++ b/src/main/java/fr/igred/omero/ObjectWrapper.java @@ -18,11 +18,11 @@ package fr.igred.omero; +import fr.igred.omero.client.Client; import fr.igred.omero.exception.AccessException; import fr.igred.omero.exception.ServiceException; import fr.igred.omero.meta.ExperimenterWrapper; import omero.gateway.model.DataObject; -import omero.model.IObject; import java.sql.Timestamp; import java.util.Collection; @@ -42,18 +42,18 @@ * * @param Subclass of {@link DataObject} */ -public abstract class GenericObjectWrapper { +public abstract class ObjectWrapper { /** Wrapped object */ protected T data; /** - * Constructor of the class GenericObjectWrapper. + * Constructor of the class ObjectWrapper. * - * @param o The DataObject to wrap in the GenericObjectWrapper. + * @param o The DataObject to wrap in the ObjectWrapper. */ - protected GenericObjectWrapper(T o) { + protected ObjectWrapper(T o) { this.data = o; } @@ -70,7 +70,7 @@ protected GenericObjectWrapper(T o) { * * @return See above. */ - protected static , W extends Comparable> List + protected static , W extends Comparable> List wrap(Collection objects, Function mapper, Function sorter) { return objects.stream() .map(mapper) @@ -89,9 +89,9 @@ protected GenericObjectWrapper(T o) { * * @return See above. */ - protected static > List + public static > List wrap(Collection objects, Function mapper) { - return wrap(objects, mapper, GenericObjectWrapper::getId); + return wrap(objects, mapper, ObjectWrapper::getId); } @@ -103,7 +103,7 @@ protected GenericObjectWrapper(T o) { * * @return Distinct objects list, sorted by ID. */ - public static > List distinct(Collection objects) { + public static > List distinct(Collection objects) { return objects.stream() .collect(toMap(T::getId, o -> o, (o1, o2) -> o1)) .values() @@ -121,7 +121,7 @@ public static > List distinct(Collection> + public static > List flatten(Collection> lists) { return lists.stream() .flatMap(Collection::stream) @@ -143,16 +143,6 @@ public T asDataObject() { } - /** - * Returns the contained DataObject as IObject. - * - * @return See above. - */ - IObject asIObject() { - return data.asIObject(); - } - - /** * Gets the object id * diff --git a/src/main/java/fr/igred/omero/repository/GenericRepositoryObjectWrapper.java b/src/main/java/fr/igred/omero/RepositoryObjectWrapper.java similarity index 66% rename from src/main/java/fr/igred/omero/repository/GenericRepositoryObjectWrapper.java rename to src/main/java/fr/igred/omero/RepositoryObjectWrapper.java index 37ac697c..e2ae7936 100644 --- a/src/main/java/fr/igred/omero/repository/GenericRepositoryObjectWrapper.java +++ b/src/main/java/fr/igred/omero/RepositoryObjectWrapper.java @@ -15,16 +15,14 @@ * Street, Fifth Floor, Boston, MA 02110-1301, USA. */ -package fr.igred.omero.repository; +package fr.igred.omero; -import fr.igred.omero.AnnotatableWrapper; -import fr.igred.omero.Browser; -import fr.igred.omero.Client; -import fr.igred.omero.GatewayWrapper; +import fr.igred.omero.client.Browser; +import fr.igred.omero.client.Client; +import fr.igred.omero.client.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 +34,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; /** @@ -56,18 +56,58 @@ * * @param Subclass of {@link DataObject} */ -public abstract class GenericRepositoryObjectWrapper extends AnnotatableWrapper { +public abstract class RepositoryObjectWrapper extends AnnotatableWrapper { /** - * Constructor of the class GenericRepositoryObjectWrapper. + * Constructor of the class RepositoryObjectWrapper. * - * @param o The DataObject to wrap in the GenericRepositoryObjectWrapper. + * @param o The DataObject to wrap in the RepositoryObjectWrapper. */ - protected GenericRepositoryObjectWrapper(T o) { + protected RepositoryObjectWrapper(T o) { super(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 +119,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 +136,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 +166,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 +192,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()); } @@ -204,27 +232,12 @@ protected static List importImage(GatewayWrapper client, DataObject target * @throws ExecutionException A Facility can't be retrieved or instantiated. */ @SuppressWarnings("MethodOverloadsMethodOfSuperclass") - public void copyAnnotationLinks(Client client, GenericRepositoryObjectWrapper object) + public void copyAnnotationLinks(Client client, RepositoryObjectWrapper object) throws AccessException, ServiceException, ExecutionException { super.copyAnnotationLinks(client, object); } - /** - * @param client The data browser. - * - * @throws ServiceException Cannot connect to OMERO. - * @throws AccessException Cannot access data. - * @throws ExecutionException A Facility can't be retrieved or instantiated. - * @deprecated Reloads the object from OMERO. - */ - @Deprecated - public void refresh(Client client) - throws ServiceException, AccessException, ExecutionException { - reload(client); - } - - /** * Reloads the object from OMERO. * @@ -234,10 +247,8 @@ public void refresh(Client client) * @throws AccessException Cannot access data. * @throws ExecutionException A Facility can't be retrieved or instantiated. */ - public void reload(Browser browser) - throws ServiceException, AccessException, ExecutionException { - // DO NOTHING FOR API COMPATIBILITY PURPOSES - } + public abstract void reload(Browser browser) + throws ServiceException, AccessException, ExecutionException; /** diff --git a/src/main/java/fr/igred/omero/annotations/AnnotationList.java b/src/main/java/fr/igred/omero/annotations/AnnotationList.java index b3ed88ad..573a4fd3 100644 --- a/src/main/java/fr/igred/omero/annotations/AnnotationList.java +++ b/src/main/java/fr/igred/omero/annotations/AnnotationList.java @@ -27,8 +27,8 @@ import static fr.igred.omero.util.Wrapper.wrap; -/** List of GenericAnnotationWrapper objects */ -public class AnnotationList extends ArrayList> { +/** List of AnnotationWrapper objects */ +public class AnnotationList extends ArrayList> { private static final long serialVersionUID = 8792604507462788823L; @@ -57,11 +57,11 @@ public AnnotationList(int initialCapacity) { * Gets a list of elements from this list whose class is specified. * * @param clazz Class of the wanted elements. - * @param Subclass of GenericAnnotationWrapper. + * @param Subclass of AnnotationWrapper. * * @return See above. */ - public > List getElementsOf(Class clazz) { + public > List getElementsOf(Class clazz) { return stream().filter(clazz::isInstance) .map(clazz::cast) .collect(Collectors.toList()); diff --git a/src/main/java/fr/igred/omero/annotations/GenericAnnotationWrapper.java b/src/main/java/fr/igred/omero/annotations/AnnotationWrapper.java similarity index 83% rename from src/main/java/fr/igred/omero/annotations/GenericAnnotationWrapper.java rename to src/main/java/fr/igred/omero/annotations/AnnotationWrapper.java index e9a9e934..c2fa4e7c 100644 --- a/src/main/java/fr/igred/omero/annotations/GenericAnnotationWrapper.java +++ b/src/main/java/fr/igred/omero/annotations/AnnotationWrapper.java @@ -18,19 +18,18 @@ package fr.igred.omero.annotations; -import fr.igred.omero.Client; -import fr.igred.omero.GenericObjectWrapper; +import fr.igred.omero.client.Client; +import fr.igred.omero.ObjectWrapper; 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; -import fr.igred.omero.repository.ImageWrapper; -import fr.igred.omero.repository.PlateAcquisitionWrapper; -import fr.igred.omero.repository.PlateWrapper; -import fr.igred.omero.repository.ProjectWrapper; -import fr.igred.omero.repository.ScreenWrapper; -import fr.igred.omero.repository.WellWrapper; +import fr.igred.omero.containers.DatasetWrapper; +import fr.igred.omero.containers.FolderWrapper; +import fr.igred.omero.core.ImageWrapper; +import fr.igred.omero.screen.PlateAcquisitionWrapper; +import fr.igred.omero.screen.PlateWrapper; +import fr.igred.omero.containers.ProjectWrapper; +import fr.igred.omero.screen.ScreenWrapper; +import fr.igred.omero.screen.WellWrapper; import omero.RLong; import omero.gateway.model.AnnotationData; import omero.gateway.model.PlateAcquisitionData; @@ -47,15 +46,15 @@ * * @param Subclass of {@link AnnotationData} */ -public abstract class GenericAnnotationWrapper extends GenericObjectWrapper { +public abstract class AnnotationWrapper extends ObjectWrapper { /** - * Constructor of the GenericAnnotationWrapper class. + * Constructor of the AnnotationWrapper class. * * @param a The AnnotationData to wrap. */ - protected GenericAnnotationWrapper(T a) { + protected AnnotationWrapper(T a) { super(a); } @@ -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/FileAnnotationWrapper.java b/src/main/java/fr/igred/omero/annotations/FileAnnotationWrapper.java index 5acdd61b..3ca46bd6 100644 --- a/src/main/java/fr/igred/omero/annotations/FileAnnotationWrapper.java +++ b/src/main/java/fr/igred/omero/annotations/FileAnnotationWrapper.java @@ -18,9 +18,9 @@ package fr.igred.omero.annotations; -import fr.igred.omero.Client; +import fr.igred.omero.client.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; @@ -37,10 +37,10 @@ * Class containing a FileAnnotationData object. *

Wraps function calls to the FileAnnotationData contained. */ -public class FileAnnotationWrapper extends GenericAnnotationWrapper { +public class FileAnnotationWrapper extends AnnotationWrapper { /** - * Constructor of the GenericAnnotationWrapper class. + * Constructor of the AnnotationWrapper class. * * @param annotation FileAnnotationData to wrap. */ @@ -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(); } @@ -227,15 +226,4 @@ public boolean isMovieFile() { return data.isMovieFile(); } - - /** - * @return the {@link FileAnnotationData} contained. Use {@link #asDataObject()} instead. - * - * @deprecated Gets the FileAnnotationData contained. - */ - @Deprecated - public FileAnnotationData asFileAnnotationData() { - return data; - } - } diff --git a/src/main/java/fr/igred/omero/annotations/MapAnnotationWrapper.java b/src/main/java/fr/igred/omero/annotations/MapAnnotationWrapper.java index 52b5ccf2..91884f0b 100644 --- a/src/main/java/fr/igred/omero/annotations/MapAnnotationWrapper.java +++ b/src/main/java/fr/igred/omero/annotations/MapAnnotationWrapper.java @@ -37,7 +37,7 @@ * Class containing a MapAnnotationData, a MapAnnotationData contains a list of NamedValue(Key-Value pair). *

Wraps function calls to the MapAnnotationData contained. */ -public class MapAnnotationWrapper extends GenericAnnotationWrapper { +public class MapAnnotationWrapper extends AnnotationWrapper { /** * The name space used to identify MapAnnotations created be the user @@ -55,21 +55,6 @@ public MapAnnotationWrapper(MapAnnotationData data) { } - /** - * Constructor of the MapAnnotationWrapper class. Sets the content of the MapAnnotationData - * - * @param result List of NamedValue(Key-Value pair). - * - * @deprecated This constructor will be removed in a future version. - *

Use {@link #MapAnnotationWrapper(Collection)} instead. - */ - @Deprecated - public MapAnnotationWrapper(List result) { - super(new MapAnnotationData()); - data.setContent(result); - } - - /** * Constructor of the MapAnnotationWrapper class. Sets the content of the map annotation. * @@ -130,26 +115,15 @@ private static NamedValue toNamedValue(Entry entry) { /** - * Gets the List of NamedValue contained in the map annotation. + * Gets the List of Key-Value pairs contained in the map annotation. * * @return MapAnnotationData content. */ @SuppressWarnings("unchecked") - public List getContent() { - return (List) data.getContent(); - } - - - /** - * Sets the content of the map annotation. - * - * @param result List of NamedValue(Key-Value pair). - * - * @deprecated This method will be replaced by {@link #setContent(Collection)} in a future version. - */ - @Deprecated - public void setContent(List result) { - data.setContent(result); + public List> getContent() { + return ((Collection) data.getContent()).stream() + .map(MapAnnotationWrapper::toMapEntry) + .collect(toList()); } @@ -166,33 +140,15 @@ public void setContent(Collection> pairs) { } - /** - * Gets the List of Key-Value pairs contained in the map annotation. - * - * @return MapAnnotationData content. - * - * @deprecated This method will be renamed to {@link #getContent()} in a future version. - */ - @Deprecated - @SuppressWarnings("unchecked") - public List> getContentAsEntryList() { - return ((Collection) data.getContent()).stream() - .map(MapAnnotationWrapper::toMapEntry) - .collect(toList()); - } - - /** * Gets the List of Key-Value pairs contained in the map annotation as a map. - *

As keys may not be unique, the map contains values as a list.

* * @return See above. */ public Map> getContentAsMap() { - return this.getContentAsEntryList() + return this.getContent() .stream() - .collect(groupingBy(Entry::getKey, - mapping(Entry::getValue, toList()))); + .collect(groupingBy(Entry::getKey, mapping(Entry::getValue, toList()))); } @@ -205,15 +161,4 @@ public String getContentAsString() { return data.getContentAsString(); } - - /** - * @return the {@link MapAnnotationData} contained. - * - * @deprecated Gets the MapAnnotationData contained. Use {@link #asDataObject()} instead. - */ - @Deprecated - public MapAnnotationData asMapAnnotationData() { - return data; - } - } \ No newline at end of file diff --git a/src/main/java/fr/igred/omero/annotations/RatingAnnotationWrapper.java b/src/main/java/fr/igred/omero/annotations/RatingAnnotationWrapper.java index 7518724d..17102630 100644 --- a/src/main/java/fr/igred/omero/annotations/RatingAnnotationWrapper.java +++ b/src/main/java/fr/igred/omero/annotations/RatingAnnotationWrapper.java @@ -25,7 +25,7 @@ * Class containing a RatingAnnotationData object. *

Wraps function calls to the RatingAnnotationData contained. */ -public class RatingAnnotationWrapper extends GenericAnnotationWrapper { +public class RatingAnnotationWrapper extends AnnotationWrapper { /** Indicates the object is not rated. */ public static final int LEVEL_ZERO = RatingAnnotationData.LEVEL_ZERO; diff --git a/src/main/java/fr/igred/omero/annotations/TableWrapper.java b/src/main/java/fr/igred/omero/annotations/TableWrapper.java index abf75031..7190ae39 100644 --- a/src/main/java/fr/igred/omero/annotations/TableWrapper.java +++ b/src/main/java/fr/igred/omero/annotations/TableWrapper.java @@ -18,11 +18,11 @@ package fr.igred.omero.annotations; -import fr.igred.omero.Client; -import fr.igred.omero.GenericObjectWrapper; +import fr.igred.omero.ObjectWrapper; +import fr.igred.omero.client.Client; +import fr.igred.omero.core.ImageWrapper; import fr.igred.omero.exception.AccessException; import fr.igred.omero.exception.ServiceException; -import fr.igred.omero.repository.ImageWrapper; import fr.igred.omero.roi.ROIWrapper; import ij.gui.Roi; import ij.macro.Variable; @@ -137,7 +137,7 @@ public TableWrapper(TableData table) { * @throws AccessException Cannot access data. * @throws ExecutionException A Facility can't be retrieved or instantiated. */ - public TableWrapper(Client client, ResultsTable results, Long imageId, List ijRois) + public TableWrapper(Client client, ResultsTable results, Long imageId, Collection ijRois) throws ServiceException, AccessException, ExecutionException { this(client, results, imageId, ijRois, ROIWrapper.IJ_PROPERTY); } @@ -157,7 +157,7 @@ public TableWrapper(Client client, ResultsTable results, Long imageId, List ijRois, + public TableWrapper(Client client, ResultsTable results, Long imageId, Collection ijRois, String roiProperty) throws ServiceException, AccessException, ExecutionException { roiProperty = ROIWrapper.checkProperty(roiProperty); @@ -409,11 +409,11 @@ private static ROIData[] createROIColumn(ResultsTable results, Map id2roi = rois.stream() .collect(toMap(ROIWrapper::getId, - GenericObjectWrapper::asDataObject)); + ObjectWrapper::asDataObject)); Map name2roi = rois.stream() .filter(r -> !r.getName().isEmpty()) .collect(toMap(ROIWrapper::getName, - GenericObjectWrapper::asDataObject, + ObjectWrapper::asDataObject, (x1, x2) -> x1)); Map label2roi = ijRois.stream() @@ -579,7 +579,7 @@ public String toString() { * @throws AccessException Cannot access data. * @throws ExecutionException A Facility can't be retrieved or instantiated. */ - public void addRows(Client client, ResultsTable results, Long imageId, List ijRois) + public void addRows(Client client, ResultsTable results, Long imageId, Collection ijRois) throws ServiceException, AccessException, ExecutionException { this.addRows(client, results, imageId, ijRois, ROIWrapper.IJ_PROPERTY); } @@ -599,7 +599,7 @@ public void addRows(Client client, ResultsTable results, Long imageId, List ijRois, + public void addRows(Client client, ResultsTable results, Long imageId, Collection ijRois, String roiProperty) throws ServiceException, AccessException, ExecutionException { roiProperty = ROIWrapper.checkProperty(roiProperty); diff --git a/src/main/java/fr/igred/omero/annotations/TagAnnotationWrapper.java b/src/main/java/fr/igred/omero/annotations/TagAnnotationWrapper.java index bf3413f4..491f4465 100644 --- a/src/main/java/fr/igred/omero/annotations/TagAnnotationWrapper.java +++ b/src/main/java/fr/igred/omero/annotations/TagAnnotationWrapper.java @@ -18,7 +18,7 @@ package fr.igred.omero.annotations; -import fr.igred.omero.Client; +import fr.igred.omero.client.Client; import fr.igred.omero.exception.AccessException; import fr.igred.omero.exception.ServiceException; import omero.gateway.model.TagAnnotationData; @@ -30,7 +30,7 @@ * Class containing a TagAnnotationData object. *

Wraps function calls to the TagAnnotationData contained. */ -public class TagAnnotationWrapper extends GenericAnnotationWrapper { +public class TagAnnotationWrapper extends AnnotationWrapper { /** * The name space used to indicate that the tag is used a tag set. @@ -108,15 +108,4 @@ public TagSetWrapper toTagSet() { return new TagSetWrapper(data); } - - /** - * @return the {@link TagAnnotationData} contained. - * - * @deprecated Gets the TagAnnotationData contained. Use {@link #asDataObject()} instead. - */ - @Deprecated - public TagAnnotationData asTagAnnotationData() { - return data; - } - } \ No newline at end of file diff --git a/src/main/java/fr/igred/omero/annotations/TagSetWrapper.java b/src/main/java/fr/igred/omero/annotations/TagSetWrapper.java index 2ec224c1..5820012f 100644 --- a/src/main/java/fr/igred/omero/annotations/TagSetWrapper.java +++ b/src/main/java/fr/igred/omero/annotations/TagSetWrapper.java @@ -18,10 +18,9 @@ package fr.igred.omero.annotations; -import fr.igred.omero.Browser; -import fr.igred.omero.Client; +import fr.igred.omero.client.Browser; +import fr.igred.omero.client.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; @@ -85,13 +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 OMEROServerError Server error. + * @throws ServiceException Cannot connect to OMERO. + * @throws AccessException Cannot access data. */ public List getTags(Browser browser) - throws ExecutionException, AccessException, ServiceException, OMEROServerError { + throws AccessException, ServiceException { reload(browser); return getTags(); } @@ -139,13 +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 OMEROServerError Server error. + * @throws ServiceException Cannot connect to OMERO. + * @throws AccessException Cannot access data. */ public void reload(Browser browser) - throws ServiceException, AccessException, ExecutionException, OMEROServerError { + 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/annotations/TextualAnnotationWrapper.java b/src/main/java/fr/igred/omero/annotations/TextualAnnotationWrapper.java index 6bf7258b..e74d0333 100644 --- a/src/main/java/fr/igred/omero/annotations/TextualAnnotationWrapper.java +++ b/src/main/java/fr/igred/omero/annotations/TextualAnnotationWrapper.java @@ -25,7 +25,7 @@ * Class containing a TextualAnnotationData object. *

Wraps function calls to the TextualAnnotationData contained. */ -public class TextualAnnotationWrapper extends GenericAnnotationWrapper { +public class TextualAnnotationWrapper extends AnnotationWrapper { /** * Constructor of the TextualAnnotationWrapper class. diff --git a/src/main/java/fr/igred/omero/Browser.java b/src/main/java/fr/igred/omero/client/Browser.java similarity index 85% rename from src/main/java/fr/igred/omero/Browser.java rename to src/main/java/fr/igred/omero/client/Browser.java index fb3ab445..2698b706 100644 --- a/src/main/java/fr/igred/omero/Browser.java +++ b/src/main/java/fr/igred/omero/client/Browser.java @@ -15,24 +15,23 @@ * Street, Fifth Floor, Boston, MA 02110-1301, USA. */ -package fr.igred.omero; +package fr.igred.omero.client; -import fr.igred.omero.annotations.GenericAnnotationWrapper; +import fr.igred.omero.ObjectWrapper; +import fr.igred.omero.annotations.AnnotationWrapper; 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; -import fr.igred.omero.repository.FolderWrapper; -import fr.igred.omero.repository.ImageWrapper; -import fr.igred.omero.repository.PlateWrapper; -import fr.igred.omero.repository.ProjectWrapper; -import fr.igred.omero.repository.ScreenWrapper; -import fr.igred.omero.repository.WellWrapper; +import fr.igred.omero.containers.DatasetWrapper; +import fr.igred.omero.containers.FolderWrapper; +import fr.igred.omero.core.ImageWrapper; +import fr.igred.omero.screen.PlateWrapper; +import fr.igred.omero.containers.ProjectWrapper; +import fr.igred.omero.screen.ScreenWrapper; +import fr.igred.omero.screen.WellWrapper; import omero.RLong; import omero.gateway.Gateway; import omero.gateway.SecurityContext; @@ -57,8 +56,8 @@ import java.util.concurrent.ExecutionException; import java.util.stream.Collectors; -import static fr.igred.omero.GenericObjectWrapper.flatten; -import static fr.igred.omero.GenericObjectWrapper.wrap; +import static fr.igred.omero.ObjectWrapper.flatten; +import static fr.igred.omero.ObjectWrapper.wrap; import static fr.igred.omero.exception.ExceptionHandler.call; import static java.lang.String.format; import static java.util.Arrays.asList; @@ -243,11 +242,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 +264,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 +310,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 +337,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 +496,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; + public abstract List getImages(AnnotationWrapper annotation) + throws ServiceException, AccessException, ExecutionException; /** @@ -528,57 +522,6 @@ public List getImagesLike(String motif) } - /** - * @param tag The tag annotation. - * - * @return See above. - * - * @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 { - return getImages(tag); - } - - - /** - * @param tagId Id of the tag researched. - * - * @return See above. - * - * @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 { - return getImagesTagged(getTag(tagId)); - } - - - /** - * @param key Name of the key researched. - * - * @return See above. - * - * @throws ServiceException Cannot connect to OMERO. - * @throws AccessException Cannot access data. - * @throws ExecutionException A Facility can't be retrieved or instantiated. - * @deprecated Gets all images with a certain key - */ - @Deprecated - public abstract List getImagesKey(String key) - throws ServiceException, AccessException, ExecutionException; - - /** * Gets all images with a certain key. * @@ -588,11 +531,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()); @@ -604,22 +546,6 @@ public List getImagesWithKey(String key) } - /** - * @param key Name of the key researched. - * @param value Value associated with the key. - * - * @return See above. - * - * @throws ServiceException Cannot connect to OMERO. - * @throws AccessException Cannot access data. - * @throws ExecutionException A Facility can't be retrieved or instantiated. - * @deprecated Gets all images with a certain key value pair from OMERO - */ - @Deprecated - public abstract List getImagesPairKeyValue(String key, String value) - throws ServiceException, AccessException, ExecutionException; - - /** * Gets all images with a certain key value pair from OMERO * @@ -630,11 +556,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 +751,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 +778,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 +839,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 +861,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,22 +965,21 @@ 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) .map(TagAnnotationWrapper::new) - .sorted(Comparator.comparing(GenericObjectWrapper::getId)) + .sorted(Comparator.comparing(ObjectWrapper::getId)) .collect(Collectors.toList()); } @@ -1071,14 +991,14 @@ 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)); + tags.sort(Comparator.comparing(ObjectWrapper::getId)); return tags; } @@ -1090,18 +1010,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 +1036,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(ObjectWrapper::getId)) + .collect(Collectors.toList()); } @@ -1145,11 +1062,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'"; @@ -1158,7 +1075,7 @@ public List getMapAnnotations(String key) .map(omero.model.MapAnnotation.class::cast) .map(MapAnnotationData::new) .map(MapAnnotationWrapper::new) - .sorted(Comparator.comparing(GenericObjectWrapper::getId)) + .sorted(Comparator.comparing(ObjectWrapper::getId)) .collect(Collectors.toList()); } @@ -1171,11 +1088,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'"; @@ -1184,7 +1101,7 @@ public List getMapAnnotations(String key, String value) .map(omero.model.MapAnnotation.class::cast) .map(MapAnnotationData::new) .map(MapAnnotationWrapper::new) - .sorted(Comparator.comparing(GenericObjectWrapper::getId)) + .sorted(Comparator.comparing(ObjectWrapper::getId)) .collect(Collectors.toList()); } @@ -1202,12 +1119,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/Client.java similarity index 74% rename from src/main/java/fr/igred/omero/Client.java rename to src/main/java/fr/igred/omero/client/Client.java index a02ca384..4a22485a 100644 --- a/src/main/java/fr/igred/omero/Client.java +++ b/src/main/java/fr/igred/omero/client/Client.java @@ -15,20 +15,20 @@ * Street, Fifth Floor, Boston, MA 02110-1301, USA. */ -package fr.igred.omero; +package fr.igred.omero.client; -import fr.igred.omero.annotations.GenericAnnotationWrapper; +import fr.igred.omero.ObjectWrapper; +import fr.igred.omero.annotations.AnnotationWrapper; 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; -import fr.igred.omero.repository.FolderWrapper; -import fr.igred.omero.repository.ImageWrapper; -import fr.igred.omero.repository.ProjectWrapper; +import fr.igred.omero.containers.FolderWrapper; +import fr.igred.omero.core.ImageWrapper; +import fr.igred.omero.containers.ProjectWrapper; import omero.ApiUsageException; import omero.gateway.Gateway; import omero.gateway.SecurityContext; @@ -40,13 +40,12 @@ import java.util.ArrayList; import java.util.Collection; import java.util.List; -import java.util.Map; import java.util.NoSuchElementException; import java.util.Objects; import java.util.concurrent.ExecutionException; import java.util.stream.Collectors; -import static fr.igred.omero.GenericObjectWrapper.flatten; +import static fr.igred.omero.ObjectWrapper.flatten; import static fr.igred.omero.exception.ExceptionHandler.call; @@ -114,67 +113,12 @@ 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 { - return annotation.getImages(this); - } - - - /** - * @param key Name of the key researched. - * - * @return See above. - * - * @throws ServiceException Cannot connect to OMERO. - * @throws AccessException Cannot access data. - * @throws ExecutionException A Facility can't be retrieved or instantiated. - * @deprecated Gets all images with a certain key - */ - @Deprecated - @Override - public List getImagesKey(String key) - throws ServiceException, AccessException, ExecutionException { - List images = getImages(); - List selected = new ArrayList<>(images.size()); - for (ImageWrapper image : images) { - Map pairsKeyValue = image.getKeyValuePairs(this); - if (pairsKeyValue.get(key) != null) { - selected.add(image); - } - } - - return selected; - } - - - /** - * @param key Name of the key researched. - * @param value Value associated with the key. - * - * @return See above. - * - * @throws ServiceException Cannot connect to OMERO. - * @throws AccessException Cannot access data. - * @throws ExecutionException A Facility can't be retrieved or instantiated. - * @deprecated Gets all images with a certain key value pair from OMERO - */ - @Deprecated - @Override - public List getImagesPairKeyValue(String key, String value) + public List getImages(AnnotationWrapper annotation) throws ServiceException, AccessException, ExecutionException { - List images = getImages(); - List selected = new ArrayList<>(images.size()); - for (ImageWrapper image : images) { - Map pairsKeyValue = image.getKeyValuePairs(this); - if (pairsKeyValue.get(key) != null && pairsKeyValue.get(key).equals(value)) { - selected.add(image); - } - } - return selected; + return annotation.getImages(this); } @@ -186,19 +130,18 @@ 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 { - for (GenericObjectWrapper object : objects) { + public void delete(Collection> objects) + throws ServiceException, AccessException, ExecutionException, InterruptedException { + for (ObjectWrapper object : objects) { if (object instanceof FolderWrapper) { ((FolderWrapper) object).unlinkAllROIs(this); } } if (!objects.isEmpty()) { delete(objects.stream() - .map(GenericObjectWrapper::asIObject) + .map(o -> o.asDataObject().asIObject()) .collect(Collectors.toList())); } } @@ -213,33 +156,14 @@ 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 { + public void delete(ObjectWrapper object) + throws ServiceException, AccessException, ExecutionException, InterruptedException { if (object instanceof FolderWrapper) { ((FolderWrapper) object).unlinkAllROIs(this); } - delete(object.asIObject()); - } - - - /** - * @param table Table to delete. - * - * @throws ServiceException Cannot connect to OMERO. - * @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 { - deleteTable(table); + delete(object.asDataObject().asIObject()); } @@ -252,11 +176,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 +193,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 +238,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 +289,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)); } @@ -420,7 +342,7 @@ public List getGroups() * @throws ExecutionException A Facility can't be retrieved or instantiated. * @throws NoSuchElementException The requested user does not exist. */ - public Client sudoGetUser(String username) + public Client sudo(String username) throws ServiceException, AccessException, ExecutionException { ExperimenterWrapper sudoUser = getUser(username); long groupId = sudoUser.getDefaultGroup().getId(); diff --git a/src/main/java/fr/igred/omero/GatewayWrapper.java b/src/main/java/fr/igred/omero/client/GatewayWrapper.java similarity index 94% rename from src/main/java/fr/igred/omero/GatewayWrapper.java rename to src/main/java/fr/igred/omero/client/GatewayWrapper.java index 2ae1befc..ca052f60 100644 --- a/src/main/java/fr/igred/omero/GatewayWrapper.java +++ b/src/main/java/fr/igred/omero/client/GatewayWrapper.java @@ -15,12 +15,11 @@ * Street, Fifth Floor, Boston, MA 02110-1301, USA. */ -package fr.igred.omero; +package 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 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 { + public void delete(IObject object) + 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 { + public void delete(List objects) + 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/client/package-info.java b/src/main/java/fr/igred/omero/client/package-info.java new file mode 100644 index 00000000..3005b5dd --- /dev/null +++ b/src/main/java/fr/igred/omero/client/package-info.java @@ -0,0 +1,20 @@ +/* + * Copyright (C) 2020-2023 GReD + * + * This program is free software; you can redistribute it and/or modify it under + * the terms of the GNU General Public License as published by the Free Software + * Foundation; either version 2 of the License, or (at your option) any later + * version. + * + * This program is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS + * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License along with + * this program; if not, write to the Free Software Foundation, Inc., 51 Franklin + * Street, Fifth Floor, Boston, MA 02110-1301, USA. + */ +/** + * This package contains the client classes used to interact with an OMERO server. + */ +package fr.igred.omero.client; diff --git a/src/main/java/fr/igred/omero/repository/DatasetWrapper.java b/src/main/java/fr/igred/omero/containers/DatasetWrapper.java similarity index 82% rename from src/main/java/fr/igred/omero/repository/DatasetWrapper.java rename to src/main/java/fr/igred/omero/containers/DatasetWrapper.java index e139eee3..ace2e5e8 100644 --- a/src/main/java/fr/igred/omero/repository/DatasetWrapper.java +++ b/src/main/java/fr/igred/omero/containers/DatasetWrapper.java @@ -15,16 +15,17 @@ * Street, Fifth Floor, Boston, MA 02110-1301, USA. */ -package fr.igred.omero.repository; +package fr.igred.omero.containers; -import fr.igred.omero.Browser; -import fr.igred.omero.Client; -import fr.igred.omero.GenericObjectWrapper; +import fr.igred.omero.client.Browser; +import fr.igred.omero.client.Client; +import fr.igred.omero.ObjectWrapper; 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.core.ImageWrapper; +import fr.igred.omero.RepositoryObjectWrapper; import fr.igred.omero.roi.ROIWrapper; import omero.RLong; import omero.gateway.model.DatasetData; @@ -41,17 +42,19 @@ import java.util.List; import java.util.Map; import java.util.concurrent.ExecutionException; -import java.util.stream.Collectors; import static fr.igred.omero.exception.ExceptionHandler.call; import static java.util.Collections.singletonList; +import static java.util.stream.Collectors.groupingBy; +import static java.util.stream.Collectors.mapping; +import static java.util.stream.Collectors.toList; /** * Class containing a DatasetData object. *

Wraps function calls to the DatasetData contained. */ -public class DatasetWrapper extends GenericRepositoryObjectWrapper { +public class DatasetWrapper extends RepositoryObjectWrapper { /** Annotation link name for this type of object */ public static final String ANNOTATION_LINK = "DatasetAnnotationLink"; @@ -105,17 +108,6 @@ public void setName(String name) { } - /** - * @return See above. - * - * @deprecated Returns the DatasetData contained. Use {@link #asDataObject()} instead. - */ - @Deprecated - public DatasetData asDatasetData() { - return data; - } - - /** * Gets the DatasetData description * @@ -155,13 +147,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 +247,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 +265,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 = " + @@ -297,24 +286,6 @@ public List getImagesTagged(Client client, Long tagId) } - /** - * @param client The client handling the connection. - * @param key Name of the key researched. - * - * @return See above. - * - * @throws ServiceException Cannot connect to OMERO. - * @throws AccessException Cannot access data. - * @throws ExecutionException A Facility can't be retrieved or instantiated. - * @deprecated Gets all images in the dataset with a certain key - */ - @Deprecated - public List getImagesKey(Client client, String key) - throws ServiceException, AccessException, ExecutionException { - return getImagesWithKey(client, key); - } - - /** * Gets all images in the dataset with a certain key * @@ -339,36 +310,20 @@ public List getImagesWithKey(Client client, String key) for (ImageData image : images) { ImageWrapper imageWrapper = new ImageWrapper(image); - Map pairsKeyValue = imageWrapper.getKeyValuePairs(client); - if (pairsKeyValue.get(key) != null) { + Map> pairs = imageWrapper.getKeyValuePairs(client) + .stream() + .collect(groupingBy(Map.Entry::getKey, + mapping(Map.Entry::getValue, toList()))); + if (pairs.get(key) != null) { selected.add(imageWrapper); } } - selected.sort(Comparator.comparing(GenericObjectWrapper::getId)); + selected.sort(Comparator.comparing(ObjectWrapper::getId)); return selected; } - /** - * @param client The client handling the connection. - * @param key Name of the key researched. - * @param value Value associated with the key. - * - * @return See above. - * - * @throws ServiceException Cannot connect to OMERO. - * @throws AccessException Cannot access data. - * @throws ExecutionException A Facility can't be retrieved or instantiated. - * @deprecated Gets all images in the dataset with a certain key value pair from OMERO - */ - @Deprecated - public List getImagesPairKeyValue(Client client, String key, String value) - throws ServiceException, AccessException, ExecutionException { - return getImagesWithKeyValuePair(client, key, value); - } - - /** * Gets all images in the dataset with a certain key value pair from OMERO * @@ -393,12 +348,15 @@ public List getImagesWithKeyValuePair(Client client, String key, S for (ImageData image : images) { ImageWrapper imageWrapper = new ImageWrapper(image); - Map pairs = imageWrapper.getKeyValuePairs(client); - if (pairs.get(key) != null && pairs.get(key).equals(value)) { + Map> pairs = imageWrapper.getKeyValuePairs(client) + .stream() + .collect(groupingBy(Map.Entry::getKey, + mapping(Map.Entry::getValue, toList()))); + if (pairs.get(key) != null && pairs.get(key).contains(value)) { selected.add(imageWrapper); } } - selected.sort(Comparator.comparing(GenericObjectWrapper::getId)); + selected.sort(Comparator.comparing(ObjectWrapper::getId)); return selected; } @@ -414,7 +372,7 @@ public List getImagesWithKeyValuePair(Client client, String key, S * @throws AccessException Cannot access data. * @throws ExecutionException A Facility can't be retrieved or instantiated. */ - public void addImages(Client client, List images) + public void addImages(Client client, Iterable images) throws ServiceException, AccessException, ExecutionException { for (ImageWrapper image : images) { addImage(client, image); @@ -450,11 +408,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 +424,12 @@ 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 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(Client client, String... paths) - throws ServiceException, OMEROServerError, AccessException, IOException, ExecutionException { + throws ServiceException, AccessException, IOException { return importImages(client, 1, paths); } @@ -488,14 +443,12 @@ 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 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(Client client, int threads, String... paths) - throws ServiceException, OMEROServerError, AccessException, IOException, ExecutionException { + throws ServiceException, AccessException, IOException { return importImages(client, data, threads, paths); } @@ -508,13 +461,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 +483,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 +527,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); @@ -599,8 +550,8 @@ public List importAndReplaceImages(Client client, String path, ReplacePoli } if (policy == ReplacePolicy.DELETE_ORPHANED) { List idsToDelete = toDelete.stream() - .map(GenericObjectWrapper::getId) - .collect(Collectors.toList()); + .map(ObjectWrapper::getId) + .collect(toList()); Iterable orphans = new ArrayList<>(toDelete); for (ImageWrapper orphan : orphans) { @@ -627,12 +578,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/containers/FolderWrapper.java similarity index 79% rename from src/main/java/fr/igred/omero/repository/FolderWrapper.java rename to src/main/java/fr/igred/omero/containers/FolderWrapper.java index 670f0830..40788ad6 100644 --- a/src/main/java/fr/igred/omero/repository/FolderWrapper.java +++ b/src/main/java/fr/igred/omero/containers/FolderWrapper.java @@ -15,16 +15,17 @@ * Street, Fifth Floor, Boston, MA 02110-1301, USA. */ -package fr.igred.omero.repository; +package fr.igred.omero.containers; -import fr.igred.omero.Browser; -import fr.igred.omero.Client; -import fr.igred.omero.GenericObjectWrapper; +import fr.igred.omero.client.Browser; +import fr.igred.omero.client.Client; +import fr.igred.omero.ObjectWrapper; 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.core.ImageWrapper; +import fr.igred.omero.RepositoryObjectWrapper; import fr.igred.omero.roi.ROIWrapper; import omero.gateway.facility.ROIFacility; import omero.gateway.model.AnnotationData; @@ -55,7 +56,7 @@ * Class containing a FolderData object. *

Wraps function calls to the FolderData contained. */ -public class FolderWrapper extends GenericRepositoryObjectWrapper { +public class FolderWrapper extends RepositoryObjectWrapper { /** Annotation link name for this type of object */ public static final String ANNOTATION_LINK = "FolderAnnotationLink"; @@ -63,9 +64,6 @@ public class FolderWrapper extends GenericRepositoryObjectWrapper { /** Empty ROI array for fast list conversion */ private static final ROIWrapper[] EMPTY_ROI_ARRAY = new ROIWrapper[0]; - /** ID of the associated image */ - private long imageID = -1L; - /** * Constructor of the FolderWrapper class. @@ -94,16 +92,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); } @@ -164,17 +162,6 @@ public void setName(String name) { } - /** - * @return the FolderData. - * - * @deprecated Gets the folder contained in the FolderWrapper. Use {@link #asDataObject()} instead. - */ - @Deprecated - public FolderData asFolderData() { - return data; - } - - /** * Gets the folder description * @@ -196,21 +183,6 @@ public void setDescription(String description) { } - /** - * @param client The client handling the connection. - * - * @throws AccessException Cannot access data. - * @throws ServiceException Cannot connect to OMERO. - * @throws ExecutionException A Facility can't be retrieved or instantiated. - * @deprecated Reloads the folder from OMERO, to update all links. - */ - @Deprecated - public void reload(Client client) - throws AccessException, ServiceException, ExecutionException { - reload((Browser) client); - } - - /** * Retrieves the parent folders for this folder. * @@ -249,7 +221,7 @@ public void addChild(FolderWrapper folder) { public void addChildren(Collection folders) { data.asFolder() .addAllChildFoldersSet(folders.stream() - .map(GenericObjectWrapper::asDataObject) + .map(ObjectWrapper::asDataObject) .map(DataObject::asFolder) .collect(toList())); } @@ -279,7 +251,7 @@ public void addImages(Client client, ImageWrapper... images) throws ServiceException, AccessException, ExecutionException { List links = new ArrayList<>(images.length); List linkedIds = getImages().stream() - .map(GenericObjectWrapper::getId) + .map(ObjectWrapper::getId) .collect(toList()); for (ImageWrapper image : images) { if (!linkedIds.contains(image.getId())) { @@ -324,44 +296,6 @@ public List getImages(Client client) } - /** - * @param id ID of the image to associate. - * - * @deprecated Sets the image associated to the folder - */ - @Deprecated - public void setImage(long id) { - imageID = id; - } - - - /** - * @param image Image to associate. - * - * @deprecated Sets the image associated to the folder - */ - @Deprecated - public void setImage(ImageWrapper image) { - imageID = image.getId(); - } - - - /** - * @param client The client handling the connection. - * @param roi ROI to add. - * - * @throws ServiceException Cannot connect to OMERO. - * @throws AccessException Cannot access data. - * @throws ExecutionException If the ROIFacility can't be retrieved or instantiated. - * @deprecated Adds an ROI to the folder and associate it to the image id set(an image need to be associated) - */ - @Deprecated - public void addROI(Client client, ROIWrapper roi) - throws ServiceException, AccessException, ExecutionException { - addROIs(client, imageID, roi); - } - - /** * Adds ROIs to the folder and associate them to the provided image ID. * @@ -376,7 +310,7 @@ public void addROI(Client client, ROIWrapper roi) public void addROIs(Client client, long imageId, ROIWrapper... rois) throws ServiceException, AccessException, ExecutionException { List roiData = Arrays.stream(rois) - .map(GenericObjectWrapper::asDataObject) + .map(ObjectWrapper::asDataObject) .collect(toList()); ROIFacility roiFac = client.getRoiFacility(); ExceptionHandler.of(roiFac, @@ -406,24 +340,6 @@ public void addROIs(Client client, ImageWrapper image, ROIWrapper... rois) } - /** - * @param client The client handling the connection. - * - * @return List of ROIWrapper containing the ROI. - * - * @throws ServiceException Cannot connect to OMERO. - * @throws AccessException Cannot access data. - * @throws ExecutionException A Facility can't be retrieved or instantiated. - * @deprecated Gets the ROI contained in the folder associated with the image id set (an image need to be - * associated) - */ - @Deprecated - public List getROIs(Client client) - throws ServiceException, AccessException, ExecutionException { - return getROIs(client, imageID); - } - - /** * Gets the ROIs contained in the folder associated with the provided image ID. * @@ -448,7 +364,7 @@ public List getROIs(Client client, long imageId) .map(ROIResult::getROIs) .flatMap(Collection::stream) .map(ROIWrapper::new) - .sorted(Comparator.comparing(GenericObjectWrapper::getId)) + .sorted(Comparator.comparing(ObjectWrapper::getId)) .collect(toList()); return distinct(roiWrappers); @@ -473,21 +389,6 @@ public List getROIs(Client client, ImageWrapper image) } - /** - * @param client The client handling the connection. - * - * @throws ServiceException Cannot connect to OMERO. - * @throws AccessException Cannot access data. - * @throws ExecutionException A Facility can't be retrieved or instantiated. - * @deprecated Unlink all ROI, associated to the image set, in the folder. ROIs are now linked to the image directly - */ - @Deprecated - public void unlinkAllROI(Client client) - throws ServiceException, AccessException, ExecutionException { - unlinkAllROIs(client); - } - - /** * Unlink all ROIs associated to the provided image ID from the folder. *

ROIs are now linked to the image directly. @@ -540,23 +441,6 @@ public void unlinkAllROIs(Client client) } - /** - * @param client The client handling the connection. - * @param roi ROI to unlink. - * - * @throws ServiceException Cannot connect to OMERO. - * @throws AccessException Cannot access data. - * @throws ExecutionException A Facility can't be retrieved or instantiated. - * @deprecated Unlink an ROI, associated to the image set, in the folder. The ROI is now linked to the image - * directly. - */ - @Deprecated - public void unlinkROI(Client client, ROIWrapper roi) - throws ServiceException, AccessException, ExecutionException { - unlinkROIs(client, roi); - } - - /** * Unlink ROIs from the folder. *

The ROIs are now linked to the image directly. diff --git a/src/main/java/fr/igred/omero/repository/ProjectWrapper.java b/src/main/java/fr/igred/omero/containers/ProjectWrapper.java similarity index 87% rename from src/main/java/fr/igred/omero/repository/ProjectWrapper.java rename to src/main/java/fr/igred/omero/containers/ProjectWrapper.java index cfd19d0d..f1c2556c 100644 --- a/src/main/java/fr/igred/omero/repository/ProjectWrapper.java +++ b/src/main/java/fr/igred/omero/containers/ProjectWrapper.java @@ -15,16 +15,17 @@ * Street, Fifth Floor, Boston, MA 02110-1301, USA. */ -package fr.igred.omero.repository; +package fr.igred.omero.containers; -import fr.igred.omero.Browser; -import fr.igred.omero.Client; -import fr.igred.omero.GenericObjectWrapper; +import fr.igred.omero.client.Browser; +import fr.igred.omero.client.Client; +import fr.igred.omero.ObjectWrapper; 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.core.ImageWrapper; +import fr.igred.omero.RepositoryObjectWrapper; import omero.gateway.model.ImageData; import omero.gateway.model.ProjectData; import omero.model.ProjectDatasetLink; @@ -45,7 +46,7 @@ * Class containing a ProjectData object. *

Wraps function calls to the Project contained */ -public class ProjectWrapper extends GenericRepositoryObjectWrapper { +public class ProjectWrapper extends RepositoryObjectWrapper { /** Annotation link name for this type of object */ public static final String ANNOTATION_LINK = "ProjectAnnotationLink"; @@ -104,17 +105,6 @@ public void setName(String name) { } - /** - * @return See above. - * - * @deprecated Returns the ProjectData contained. Use {@link #asDataObject()} instead. - */ - @Deprecated - public ProjectData asProjectData() { - return data; - } - - /** * Gets the project description * @@ -226,11 +216,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); } @@ -305,7 +294,7 @@ public List getImages(Client client, String datasetName, String im } List images = lists.stream() .flatMap(Collection::stream) - .sorted(comparing(GenericObjectWrapper::getId)) + .sorted(comparing(ObjectWrapper::getId)) .collect(Collectors.toList()); return distinct(images); @@ -346,11 +335,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 +359,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()); @@ -386,24 +373,6 @@ public List getImagesTagged(Client client, Long tagId) } - /** - * @param client The client handling the connection. - * @param key Name of the key researched. - * - * @return See above. - * - * @throws ServiceException Cannot connect to OMERO. - * @throws AccessException Cannot access data. - * @throws ExecutionException A Facility can't be retrieved or instantiated. - * @deprecated Gets all images in the project with a certain key - */ - @Deprecated - public List getImagesKey(Client client, String key) - throws ServiceException, AccessException, ExecutionException { - return getImagesWithKey(client, key); - } - - /** * Gets all images in the project with a certain key * @@ -428,25 +397,6 @@ public List getImagesWithKey(Client client, String key) } - /** - * @param client The client handling the connection. - * @param key Name of the key researched. - * @param value Value associated with the key. - * - * @return See above. - * - * @throws ServiceException Cannot connect to OMERO. - * @throws AccessException Cannot access data. - * @throws ExecutionException A Facility can't be retrieved or instantiated. - * @deprecated Gets all images in the project with a certain key value pair from OMERO. - */ - @Deprecated - public List getImagesPairKeyValue(Client client, String key, String value) - throws ServiceException, AccessException, ExecutionException { - return getImagesWithKeyValuePair(client, key, value); - } - - /** * Gets all images in the project with a certain key value pair from OMERO. * diff --git a/src/main/java/fr/igred/omero/repository/package-info.java b/src/main/java/fr/igred/omero/containers/package-info.java similarity index 96% rename from src/main/java/fr/igred/omero/repository/package-info.java rename to src/main/java/fr/igred/omero/containers/package-info.java index 648c5d9e..044f0329 100644 --- a/src/main/java/fr/igred/omero/repository/package-info.java +++ b/src/main/java/fr/igred/omero/containers/package-info.java @@ -19,4 +19,4 @@ *

This includes containers (such as screens or projects for example), as well as data contained within images * (e.g. pixels and channels). */ -package fr.igred.omero.repository; \ No newline at end of file +package fr.igred.omero.containers; \ No newline at end of file diff --git a/src/main/java/fr/igred/omero/repository/ChannelWrapper.java b/src/main/java/fr/igred/omero/core/ChannelWrapper.java similarity index 90% rename from src/main/java/fr/igred/omero/repository/ChannelWrapper.java rename to src/main/java/fr/igred/omero/core/ChannelWrapper.java index 629ac24a..5178a745 100644 --- a/src/main/java/fr/igred/omero/repository/ChannelWrapper.java +++ b/src/main/java/fr/igred/omero/core/ChannelWrapper.java @@ -15,10 +15,10 @@ * Street, Fifth Floor, Boston, MA 02110-1301, USA. */ -package fr.igred.omero.repository; +package fr.igred.omero.core; -import fr.igred.omero.GenericObjectWrapper; +import fr.igred.omero.ObjectWrapper; import omero.gateway.model.ChannelData; import java.awt.Color; @@ -28,7 +28,7 @@ * Class containing a ChannelData object. *

Wraps function calls to the ChannelData contained. */ -public class ChannelWrapper extends GenericObjectWrapper { +public class ChannelWrapper extends ObjectWrapper { /** @@ -41,17 +41,6 @@ public ChannelWrapper(ChannelData channel) { } - /** - * @return See above. - * - * @deprecated Returns the ChannelData contained. Use {@link #asDataObject()} instead. - */ - @Deprecated - public ChannelData asChannelData() { - return data; - } - - /** * Returns whether the channel contains all the RGBA values or not. * diff --git a/src/main/java/fr/igred/omero/repository/ImageWrapper.java b/src/main/java/fr/igred/omero/core/ImageWrapper.java similarity index 90% rename from src/main/java/fr/igred/omero/repository/ImageWrapper.java rename to src/main/java/fr/igred/omero/core/ImageWrapper.java index d926651f..771cd7ee 100644 --- a/src/main/java/fr/igred/omero/repository/ImageWrapper.java +++ b/src/main/java/fr/igred/omero/core/ImageWrapper.java @@ -15,18 +15,25 @@ * Street, Fifth Floor, Boston, MA 02110-1301, USA. */ -package fr.igred.omero.repository; +package fr.igred.omero.core; -import fr.igred.omero.Browser; -import fr.igred.omero.Client; -import fr.igred.omero.GenericObjectWrapper; +import fr.igred.omero.client.Browser; +import fr.igred.omero.client.Client; +import fr.igred.omero.ObjectWrapper; +import fr.igred.omero.containers.DatasetWrapper; +import fr.igred.omero.containers.FolderWrapper; +import fr.igred.omero.containers.ProjectWrapper; 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; +import fr.igred.omero.core.PixelsWrapper.Bounds; +import fr.igred.omero.core.PixelsWrapper.Coordinates; +import fr.igred.omero.screen.PlateAcquisitionWrapper; +import fr.igred.omero.screen.PlateWrapper; +import fr.igred.omero.RepositoryObjectWrapper; +import fr.igred.omero.screen.ScreenWrapper; +import fr.igred.omero.screen.WellSampleWrapper; +import fr.igred.omero.screen.WellWrapper; import fr.igred.omero.roi.ROIWrapper; import ij.CompositeImage; import ij.IJ; @@ -48,7 +55,6 @@ import omero.gateway.model.ROIData; import omero.gateway.model.ROIResult; import omero.gateway.model.WellSampleData; -import omero.model.Folder; import omero.model.IObject; import omero.model.Length; import omero.model.Time; @@ -64,7 +70,6 @@ import java.util.Arrays; import java.util.Collection; import java.util.List; -import java.util.NoSuchElementException; import java.util.concurrent.ExecutionException; import java.util.logging.Logger; import java.util.stream.Collectors; @@ -80,7 +85,7 @@ * Class containing an ImageData. *

Wraps function calls to the ImageData contained. */ -public class ImageWrapper extends GenericRepositoryObjectWrapper { +public class ImageWrapper extends RepositoryObjectWrapper { /** Annotation link name for this type of object */ public static final String ANNOTATION_LINK = "ImageAnnotationLink"; @@ -211,17 +216,6 @@ public void setName(String name) { } - /** - * @return See above. - * - * @deprecated Returns the ImageData contained. Use {@link #asDataObject()} instead. - */ - @Deprecated - public ImageData asImageData() { - return data; - } - - /** * Gets the ImageData description * @@ -291,13 +285,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 +307,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 +437,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 +458,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 +482,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(); @@ -530,7 +520,7 @@ public List saveROIs(Client client, Collection throws ServiceException, AccessException, ExecutionException { rois.forEach(r -> r.setImage(this)); List roisData = rois.stream() - .map(GenericObjectWrapper::asDataObject) + .map(ObjectWrapper::asDataObject) .collect(Collectors.toList()); Collection results = call(client.getRoiFacility(), rf -> rf.saveROIs(client.getCtx(), @@ -560,23 +550,6 @@ public List saveROIs(Client client, ROIWrapper... rois) } - /** - * @param client The client handling the connection. - * @param roi ROI to be added. - * - * @throws ServiceException Cannot connect to OMERO. - * @throws AccessException Cannot access data. - * @throws ExecutionException A Facility can't be retrieved or instantiated. - * @deprecated Links a ROI to the image in OMERO - *

DO NOT USE IT IF A SHAPE WAS DELETED !!! - */ - @Deprecated - public void saveROI(Client client, ROIWrapper roi) - throws ServiceException, AccessException, ExecutionException { - roi.setData(saveROIs(client, roi).iterator().next().asDataObject()); - } - - /** * Gets all ROIs linked to the image in OMERO * @@ -599,7 +572,7 @@ public List getROIs(Client client) .map(ROIResult::getROIs) .flatMap(Collection::stream) .map(ROIWrapper::new) - .sorted(comparing(GenericObjectWrapper::getId)) + .sorted(comparing(ObjectWrapper::getId)) .collect(Collectors.toList()); return distinct(roiWrappers); @@ -638,10 +611,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()); @@ -653,32 +625,6 @@ public List getFolders(Client client) } - /** - * @param client The client handling the connection. - * @param folderId ID of the folder. - * - * @return The folder if it exists. - * - * @throws ServiceException Cannot connect to OMERO. - * @throws OMEROServerError Server error. - * @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 { - List os = client.findByQuery("select f " + - "from Folder as f " + - "where f.id = " + - folderId); - - FolderWrapper folderWrapper = new FolderWrapper((Folder) os.iterator().next()); - folderWrapper.setImage(data.getId()); - - return folderWrapper; - } - - /** * Gets the Pixels for this image. * @@ -976,17 +922,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,21 +990,15 @@ public List getManagedRepositoriesPaths(Client client) * * @return See above. * - * @throws OMEROServerError Server error. - * @throws ServiceException Cannot connect to OMERO. - * @throws AccessException Cannot access data. + * @throws ServiceException Cannot connect to OMERO. + * @throws AccessException Cannot access data. + * @throws ExecutionException A Facility can't be retrieved or instantiated. */ public List download(Client client, String path) - throws OMEROServerError, ServiceException, AccessException { - List files = new ArrayList<>(0); - try { - files = call(client.getGateway().getFacility(TransferFacility.class), - t -> t.downloadImage(client.getCtx(), path, getId()), - "Could not download image " + getId()); - } catch (ExecutionException e) { - // IGNORE FOR API COMPATIBILITY - } - return files; + throws ServiceException, AccessException, ExecutionException { + return call(client.getGateway().getFacility(TransferFacility.class), + t -> t.downloadImage(client.getCtx(), path, getId()), + "Could not download image " + getId()); } diff --git a/src/main/java/fr/igred/omero/repository/PixelsWrapper.java b/src/main/java/fr/igred/omero/core/PixelsWrapper.java similarity index 98% rename from src/main/java/fr/igred/omero/repository/PixelsWrapper.java rename to src/main/java/fr/igred/omero/core/PixelsWrapper.java index 82f8d9e5..5a82f167 100644 --- a/src/main/java/fr/igred/omero/repository/PixelsWrapper.java +++ b/src/main/java/fr/igred/omero/core/PixelsWrapper.java @@ -15,15 +15,14 @@ * Street, Fifth Floor, Boston, MA 02110-1301, USA. */ -package fr.igred.omero.repository; +package fr.igred.omero.core; -import fr.igred.omero.Client; -import fr.igred.omero.GenericObjectWrapper; +import fr.igred.omero.client.Client; +import fr.igred.omero.ObjectWrapper; import fr.igred.omero.exception.AccessException; import fr.igred.omero.exception.ExceptionHandler; import fr.igred.omero.exception.ServiceException; -import fr.igred.omero.meta.PlaneInfoWrapper; import ome.units.unit.Unit; import omero.gateway.exception.DataSourceException; import omero.gateway.facility.RawDataFacility; @@ -40,7 +39,7 @@ import java.util.concurrent.ExecutionException; import static fr.igred.omero.exception.ExceptionHandler.call; -import static fr.igred.omero.meta.PlaneInfoWrapper.getMinPosition; +import static fr.igred.omero.core.PlaneInfoWrapper.getMinPosition; import static ome.formats.model.UnitsFactory.convertLength; @@ -48,7 +47,7 @@ * Class containing a PixelData object. *

Wraps function calls to the PixelData contained. */ -public class PixelsWrapper extends GenericObjectWrapper { +public class PixelsWrapper extends ObjectWrapper { /** Size of tiles when retrieving pixels */ public static final int MAX_DIST = 5000; diff --git a/src/main/java/fr/igred/omero/meta/PlaneInfoWrapper.java b/src/main/java/fr/igred/omero/core/PlaneInfoWrapper.java similarity index 95% rename from src/main/java/fr/igred/omero/meta/PlaneInfoWrapper.java rename to src/main/java/fr/igred/omero/core/PlaneInfoWrapper.java index 30c7521f..dd854ccd 100644 --- a/src/main/java/fr/igred/omero/meta/PlaneInfoWrapper.java +++ b/src/main/java/fr/igred/omero/core/PlaneInfoWrapper.java @@ -15,10 +15,10 @@ * Street, Fifth Floor, Boston, MA 02110-1301, USA. */ -package fr.igred.omero.meta; +package fr.igred.omero.core; -import fr.igred.omero.GenericObjectWrapper; +import fr.igred.omero.ObjectWrapper; import ome.formats.model.UnitsFactory; import ome.units.unit.Unit; import omero.gateway.model.PlaneInfoData; @@ -39,7 +39,7 @@ import static ome.units.UNITS.SECOND; -public class PlaneInfoWrapper extends GenericObjectWrapper { +public class PlaneInfoWrapper extends ObjectWrapper { /** * Constructor of the class PlaneInfoWrapper. @@ -175,17 +175,6 @@ public static Length getMinPosition(Collection plane } - /** - * @return See above. - * - * @deprecated Returns the PlaneInfoData contained. Use {@link #asDataObject()} instead. - */ - @Deprecated - public PlaneInfoData asPlaneInfoData() { - return data; - } - - /** * Retrieves the plane deltaT. * diff --git a/src/main/java/fr/igred/omero/core/package-info.java b/src/main/java/fr/igred/omero/core/package-info.java new file mode 100644 index 00000000..922a64fe --- /dev/null +++ b/src/main/java/fr/igred/omero/core/package-info.java @@ -0,0 +1,20 @@ +/* + * Copyright (C) 2020-2023 GReD + * + * This program is free software; you can redistribute it and/or modify it under + * the terms of the GNU General Public License as published by the Free Software + * Foundation; either version 2 of the License, or (at your option) any later + * version. + * + * This program is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS + * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License along with + * this program; if not, write to the Free Software Foundation, Inc., 51 Franklin + * Street, Fifth Floor, Boston, MA 02110-1301, USA. + */ +/** + * This package contains classes to handle images and their content, such as pixels, channels or planes. + */ +package fr.igred.omero.core; \ No newline at end of file diff --git a/src/main/java/fr/igred/omero/exception/ExceptionHandler.java b/src/main/java/fr/igred/omero/exception/ExceptionHandler.java index 64a0a922..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,68 +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 OMEROServerError Server error. - * @throws ServiceException Cannot connect to OMERO. - */ - @Deprecated - public ExceptionHandler handleException(String message) - throws ServiceException, AccessException, OMEROServerError { - return this.handleOMEROException(message); - } - - /** * Throws: *