From 703b84aac34294b431827c05ff25dd4be6116a52 Mon Sep 17 00:00:00 2001 From: Pierre Pouchin Date: Thu, 24 Oct 2024 14:44:16 +0200 Subject: [PATCH] Add private method to retrieve annotations --- .../igred/ij/plugin/OMEROMacroExtension.java | 48 +++++++++++++------ 1 file changed, 34 insertions(+), 14 deletions(-) diff --git a/src/main/java/fr/igred/ij/plugin/OMEROMacroExtension.java b/src/main/java/fr/igred/ij/plugin/OMEROMacroExtension.java index 37a8d6b..e9a810d 100644 --- a/src/main/java/fr/igred/ij/plugin/OMEROMacroExtension.java +++ b/src/main/java/fr/igred/ij/plugin/OMEROMacroExtension.java @@ -305,19 +305,9 @@ private > List filterUser(List list) { private GenericObjectWrapper getObject(String type, long id) { String singularType = singularType(type); - GenericObjectWrapper object = null; - if (TAG.equals(singularType)) { - try { - object = client.getTag(id); - } catch (OMEROServerError | ServiceException e) { - IJ.error("Could not retrieve tag: " + e.getMessage()); - } - } else if (MAP.equals(singularType)) { - try { - object = client.getMapAnnotation(id); - } catch (ServiceException | ExecutionException | AccessException e) { - IJ.error("Could not retrieve tag: " + e.getMessage()); - } + GenericObjectWrapper object; + if (TAG.equals(singularType) || MAP.equals(singularType)) { + object = getAnnotation(singularType, id); } else { object = getRepositoryObject(type, id); } @@ -325,6 +315,36 @@ private GenericObjectWrapper getObject(String type, long id) { } + /** + * Retrieves the annotation of the specified type with the specified ID. + * + * @param type The type of annotation. + * @param id The object ID. + * + * @return The object. + */ + private GenericAnnotationWrapper getAnnotation(String type, long id) { + String singularType = singularType(type); + + GenericAnnotationWrapper annotation = null; + try { + switch (singularType) { + case TAG: + annotation = client.getTag(id); + break; + case MAP: + annotation = client.getMapAnnotation(id); + break; + default: + IJ.error(INVALID + ": " + type + "."); + } + } catch (OMEROServerError | ServiceException | ExecutionException | AccessException e) { + IJ.error(String.format("Could not retrieve %s: %s", singularType, e.getMessage())); + } + return annotation; + } + + /** * Retrieves the repository object of the specified type with the specified ID. * @@ -361,7 +381,7 @@ private GenericRepositoryObjectWrapper getRepositoryObject(String type, long IJ.error(INVALID + ": " + type + "."); } } catch (ServiceException | AccessException | ExecutionException e) { - IJ.error("Could not retrieve object: " + e.getMessage()); + IJ.error(String.format("Could not retrieve %s: %s", singularType, e.getMessage())); } return object; }