Skip to content

Commit

Permalink
JAVACLIENT-209: Replace the endpoint used to fetch annotation replies
Browse files Browse the repository at this point in the history
  • Loading branch information
kevinleturc committed Sep 15, 2020
1 parent d971ff7 commit a1bcfcd
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -976,9 +976,10 @@ public <O> O get(String pathSuffix, Map<String, Serializable> 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> O post(O object) {
public <O> O post(Object object) {
return post("", object);
}

Expand All @@ -987,9 +988,10 @@ public <O> 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> O post(String pathSuffix, O object) {
public <O> O post(String pathSuffix, Object object) {
return post(pathSuffix, emptyMap(), object);
}

Expand All @@ -998,9 +1000,10 @@ public <O> 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> O post(Map<String, Serializable> queryParams, O object) {
public <O> O post(Map<String, Serializable> queryParams, Object object) {
return post("", queryParams, object);
}

Expand All @@ -1010,9 +1013,10 @@ public <O> O post(Map<String, Serializable> 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> O post(String pathSuffix, Map<String, Serializable> queryParams, O object) {
public <O> O post(String pathSuffix, Map<String, Serializable> queryParams, Object object) {
if (repositoryName == null) {
return (O) fetchResponse(api.createForAdapter(documentId, adapter, pathSuffix, queryParams, object));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -34,6 +35,8 @@
*/
public class AnnotationAdapter extends Document.AbstractAdapter<AnnotationAdapter> {

protected static final int REPLIES_BATCH_SIZE = 50;

public AnnotationAdapter(Document document) {
super(document, "annotation");
}
Expand Down Expand Up @@ -64,8 +67,22 @@ public Annotation fetchByEntityId(String entityId) {
}

public Comments fetchComments(List<String> 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<String> 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) {
Expand Down

0 comments on commit a1bcfcd

Please sign in to comment.