Skip to content

Commit

Permalink
Add private method to retrieve annotations
Browse files Browse the repository at this point in the history
  • Loading branch information
ppouchin committed Oct 24, 2024
1 parent 679558c commit 703b84a
Showing 1 changed file with 34 additions and 14 deletions.
48 changes: 34 additions & 14 deletions src/main/java/fr/igred/ij/plugin/OMEROMacroExtension.java
Original file line number Diff line number Diff line change
Expand Up @@ -305,26 +305,46 @@ private <T extends GenericObjectWrapper<?>> List<T> filterUser(List<T> 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);
}
return object;
}


/**
* 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.
*
Expand Down Expand Up @@ -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;
}
Expand Down

0 comments on commit 703b84a

Please sign in to comment.