diff --git a/nuxeo-java-client-test/src/test/java/org/nuxeo/client/ITRepository.java b/nuxeo-java-client-test/src/test/java/org/nuxeo/client/ITRepository.java index 5d35de5e..365dd292 100644 --- a/nuxeo-java-client-test/src/test/java/org/nuxeo/client/ITRepository.java +++ b/nuxeo-java-client-test/src/test/java/org/nuxeo/client/ITRepository.java @@ -57,7 +57,6 @@ import java.util.function.BiFunction; import java.util.function.Consumer; import java.util.function.Function; -import java.util.stream.IntStream; import org.apache.commons.lang3.StringUtils; import org.junit.Test; diff --git a/nuxeo-java-client/src/main/java/org/nuxeo/client/objects/Document.java b/nuxeo-java-client/src/main/java/org/nuxeo/client/objects/Document.java index de669cb0..d9515f67 100644 --- a/nuxeo-java-client/src/main/java/org/nuxeo/client/objects/Document.java +++ b/nuxeo-java-client/src/main/java/org/nuxeo/client/objects/Document.java @@ -976,9 +976,10 @@ public O get(String pathSuffix, Map queryParams) { * Sends a POST request directly on adapter url. * * @param object the object to send as body + * @implNote since 3.8, this API takes an {@link Object} instead of {@link O} to allow arbitrary POST requests * @since 3.2 */ - public O post(O object) { + public O post(Object object) { return post("", object); } @@ -987,9 +988,10 @@ public O post(O object) { * * @param pathSuffix the path to append to the end of hit adapter * @param object the object to send as body + * @implNote since 3.8, this API takes an {@link Object} instead of {@link O} to allow arbitrary POST requests * @since 3.2 */ - public O post(String pathSuffix, O object) { + public O post(String pathSuffix, Object object) { return post(pathSuffix, emptyMap(), object); } @@ -998,9 +1000,10 @@ public O post(String pathSuffix, O object) { * * @param queryParams the query parameters to append to url * @param object the object to send as body + * @implNote since 3.8, this API takes an {@link Object} instead of {@link O} to allow arbitrary POST requests * @since 3.2 */ - public O post(Map queryParams, O object) { + public O post(Map queryParams, Object object) { return post("", queryParams, object); } @@ -1010,9 +1013,10 @@ public O post(Map queryParams, O object) { * @param pathSuffix the path to append to the end of hit adapter * @param queryParams the query parameters to append to url * @param object the object to send as body + * @implNote since 3.8, this API takes an {@link Object} instead of {@link O} to allow arbitrary POST requests * @since 3.2 */ - public O post(String pathSuffix, Map queryParams, O object) { + public O post(String pathSuffix, Map queryParams, Object object) { if (repositoryName == null) { return (O) fetchResponse(api.createForAdapter(documentId, adapter, pathSuffix, queryParams, object)); } diff --git a/nuxeo-java-client/src/main/java/org/nuxeo/client/objects/comment/AnnotationAdapter.java b/nuxeo-java-client/src/main/java/org/nuxeo/client/objects/comment/AnnotationAdapter.java index ad0bb27d..6ba802fd 100644 --- a/nuxeo-java-client/src/main/java/org/nuxeo/client/objects/comment/AnnotationAdapter.java +++ b/nuxeo-java-client/src/main/java/org/nuxeo/client/objects/comment/AnnotationAdapter.java @@ -24,6 +24,7 @@ import java.util.ArrayList; import java.util.List; +import org.nuxeo.client.NuxeoVersion; import org.nuxeo.client.objects.Document; import org.nuxeo.client.objects.ProxyRetrofitQueryMap; @@ -34,6 +35,8 @@ */ public class AnnotationAdapter extends Document.AbstractAdapter { + protected static final int REPLIES_BATCH_SIZE = 50; + public AnnotationAdapter(Document document) { super(document, "annotation"); } @@ -64,8 +67,22 @@ public Annotation fetchByEntityId(String entityId) { } public Comments fetchComments(List annotationIds) { - return get("comments", - new ProxyRetrofitQueryMap(singletonMap("annotationIds", new ArrayList<>(annotationIds)))); + NuxeoVersion serverVersion = nuxeoClient.getServerVersion(); + if ((serverVersion.isGreaterThan(NuxeoVersion.LTS_10_10.hotfix(32)) + && !serverVersion.isGreaterThan(NuxeoVersion.parse("11.1"))) + || serverVersion.isGreaterThan(NuxeoVersion.parse("11.3.37"))) { + return post("comments", annotationIds); + } + // do a loop on annotationIds to avoid the URI too long error + Comments comments = new Comments(); + for (int i = 0; i < (annotationIds.size() - 1) / REPLIES_BATCH_SIZE + 1; i++) { + List ids = annotationIds.subList(i * REPLIES_BATCH_SIZE, + Math.min((i + 1) * REPLIES_BATCH_SIZE, annotationIds.size())); + Comments c = get("comments", + new ProxyRetrofitQueryMap(singletonMap("annotationIds", new ArrayList<>(ids)))); + comments.getEntries().addAll(c.getEntries()); + } + return comments; } public Annotation update(Annotation annotation) {