diff --git a/src/main/java/fr/igred/omero/AnnotatableWrapper.java b/src/main/java/fr/igred/omero/AnnotatableWrapper.java
index b7293684..aeb26016 100644
--- a/src/main/java/fr/igred/omero/AnnotatableWrapper.java
+++ b/src/main/java/fr/igred/omero/AnnotatableWrapper.java
@@ -42,6 +42,7 @@
import omero.model.IObject;
import omero.model.NamedValue;
import omero.model.TagAnnotationI;
+import omero.sys.ParametersI;
import java.io.File;
import java.util.ArrayList;
@@ -841,6 +842,53 @@ public > void unlink(Client client, A anno
}
+ /**
+ * Unlinks the given annotations from the current object.
+ *
+ * @param client The client handling the connection.
+ * @param annotations List of annotations
+ * @param The type of the annotation.
+ *
+ * @throws ServiceException Cannot connect to OMERO.
+ * @throws AccessException Cannot access data.
+ * @throws ExecutionException A Facility can't be retrieved or instantiated.
+ * @throws OMEROServerError Server error.
+ * @throws InterruptedException If block(long) does not return.
+ */
+ public > void unlink(Client client, Collection annotations)
+ throws ServiceException, AccessException, ExecutionException, OMEROServerError, InterruptedException {
+ removeLinks(client, annotationLinkType(), annotations.stream().map(A::getId).collect(Collectors.toList()));
+ }
+
+
+ /**
+ * Removes the link of the given type with the given child IDs.
+ *
+ * @param client The client handling the connection.
+ * @param linkType The link type.
+ * @param childIds List of link child 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.
+ * @throws InterruptedException If block(long) does not return.
+ */
+ protected void removeLinks(Client client, String linkType, Collection childIds)
+ throws ServiceException, OMEROServerError, AccessException, ExecutionException, InterruptedException {
+ String template = "select link from %s link where link.parent = %d and link.child.id in (:ids)";
+ String query = String.format(template, linkType, getId());
+ ParametersI param = new ParametersI();
+ param.addIds(childIds);
+ List os = ExceptionHandler.of(client.getGateway(),
+ g -> g.getQueryService(client.getCtx())
+ .findAllByQuery(query, param))
+ .handleOMEROException("Cannot get links from " + this)
+ .get();
+ client.delete(os);
+ }
+
+
/**
* Removes the link of the given type with the given child ID.
*
@@ -856,10 +904,7 @@ public > void unlink(Client client, A anno
*/
protected void removeLink(Client client, String linkType, long childId)
throws ServiceException, OMEROServerError, AccessException, ExecutionException, InterruptedException {
- List os = client.findByQuery("select link from " + linkType +
- " link where link.parent = " + getId() +
- " and link.child = " + childId);
- delete(client, os.iterator().next());
+ removeLinks(client, linkType, Collections.singletonList(childId));
}
diff --git a/src/test/java/fr/igred/omero/repository/FolderTest.java b/src/test/java/fr/igred/omero/repository/FolderTest.java
index 3c7e32d7..77573572 100644
--- a/src/test/java/fr/igred/omero/repository/FolderTest.java
+++ b/src/test/java/fr/igred/omero/repository/FolderTest.java
@@ -269,7 +269,7 @@ void testAddAndRemoveTagFromFolder() throws Exception {
List tags = folder.getTags(client);
assertEquals(1, tags.size());
- folder.unlink(client, tags.get(0));
+ folder.unlink(client, tags);
List removed = folder.getTags(client);
assertEquals(0, removed.size());