From 903c2beb33052fd72bceb79a59e8a9a849e8d72c Mon Sep 17 00:00:00 2001 From: Andrei Nechaev Date: Wed, 19 Jan 2022 12:17:51 +0300 Subject: [PATCH] INSIGHT-1286: dedup drop api --- .../java/org/nuxeo/ai/sdk/rest/api/DedupCaller.java | 12 ++++++++++++ .../java/org/nuxeo/ai/sdk/rest/api/Resource.java | 5 +++++ .../main/java/org/nuxeo/ai/sdk/rest/client/API.java | 4 +++- .../org/nuxeo/ai/sdk/rest/api/TestDedupCaller.java | 7 +++++++ .../test/resources/mappings/insight_dedup_drop.json | 9 +++++++++ 5 files changed, 36 insertions(+), 1 deletion(-) create mode 100644 insight-rest-client/src/test/resources/mappings/insight_dedup_drop.json diff --git a/insight-rest-client/src/main/java/org/nuxeo/ai/sdk/rest/api/DedupCaller.java b/insight-rest-client/src/main/java/org/nuxeo/ai/sdk/rest/api/DedupCaller.java index d48315a..a1ff015 100644 --- a/insight-rest-client/src/main/java/org/nuxeo/ai/sdk/rest/api/DedupCaller.java +++ b/insight-rest-client/src/main/java/org/nuxeo/ai/sdk/rest/api/DedupCaller.java @@ -73,6 +73,12 @@ public DedupCaller(InsightClient client, API.Dedup type) { this.type = type; } + @Nullable + @Override + public T call() throws IOException { + return call(emptyMap()); + } + @Nullable @Override public T call(Map parameters) throws IOException { @@ -94,6 +100,8 @@ public T call(Map parameters, Serializable payload) th return (T) handleRecalculateTuples(parameters); case DELETE: return (T) handleDelete(parameters); + case DROP: + return (T) handleDrop(); default: throw new InvalidEndpointException("No such endpoint " + this.type.name()); } @@ -166,6 +174,10 @@ private Boolean handleDelete(Map parameters) { return client.delete(this.type.toPath(DELETE, client.getProjectId(), parameters), "{}", Response::isSuccessful); } + private Boolean handleDrop() { + return client.delete(this.type.toPath(DELETE, client.getProjectId()), "{}", Response::isSuccessful); + } + protected ResponseHandler> handleResponse(String docId, String xpath) { return response -> { if (!response.isSuccessful()) { diff --git a/insight-rest-client/src/main/java/org/nuxeo/ai/sdk/rest/api/Resource.java b/insight-rest-client/src/main/java/org/nuxeo/ai/sdk/rest/api/Resource.java index 8fa6150..d3ad09d 100644 --- a/insight-rest-client/src/main/java/org/nuxeo/ai/sdk/rest/api/Resource.java +++ b/insight-rest-client/src/main/java/org/nuxeo/ai/sdk/rest/api/Resource.java @@ -30,6 +30,11 @@ */ public interface Resource { + @Nullable + default T call() throws IOException { + throw new UnsupportedOperationException(); + } + @Nullable T call(Map parameters) throws IOException; diff --git a/insight-rest-client/src/main/java/org/nuxeo/ai/sdk/rest/client/API.java b/insight-rest-client/src/main/java/org/nuxeo/ai/sdk/rest/client/API.java index de9856d..66aeca4 100644 --- a/insight-rest-client/src/main/java/org/nuxeo/ai/sdk/rest/client/API.java +++ b/insight-rest-client/src/main/java/org/nuxeo/ai/sdk/rest/client/API.java @@ -131,7 +131,7 @@ public String toPath(@Nonnull String project, @Nullable String id, @Nullable Str * Endpoints available for Deduplication */ public enum Dedup implements Endpoint { - INDEX, FIND, ALL, RECALCULATETUPLES, DELETE; + INDEX, FIND, ALL, RECALCULATETUPLES, DELETE, DROP; public static final String API_DEDUP = "ai/dedup/"; @@ -183,6 +183,8 @@ public String toPath(HttpMethod method, @Nonnull String project, Map