Skip to content

Commit

Permalink
INSIGHT-1286: dedup drop api
Browse files Browse the repository at this point in the history
  • Loading branch information
Andrei Nechaev committed Jan 19, 2022
1 parent 6162c3c commit 903c2be
Show file tree
Hide file tree
Showing 5 changed files with 36 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,12 @@ public DedupCaller(InsightClient client, API.Dedup type) {
this.type = type;
}

@Nullable
@Override
public <T> T call() throws IOException {
return call(emptyMap());
}

@Nullable
@Override
public <T> T call(Map<String, Serializable> parameters) throws IOException {
Expand All @@ -94,6 +100,8 @@ public <T> T call(Map<String, Serializable> 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());
}
Expand Down Expand Up @@ -166,6 +174,10 @@ private Boolean handleDelete(Map<String, Serializable> 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<List<String>> handleResponse(String docId, String xpath) {
return response -> {
if (!response.isSuccessful()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,11 @@
*/
public interface Resource {

@Nullable
default <T> T call() throws IOException {
throw new UnsupportedOperationException();
}

@Nullable
<T> T call(Map<String, Serializable> parameters) throws IOException;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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/";

Expand Down Expand Up @@ -183,6 +183,8 @@ public String toPath(HttpMethod method, @Nonnull String project, Map<String, Ser
url += "?xpath=" + xpath;
}
return url;
case DROP:
return API_DEDUP + project + "/drop";
default:
throw new UnsupportedPathException("Invalid API call for " + this.name());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,13 @@ public void iCanDeleteFromIndex() throws IOException {
assertThat(result).isTrue();
}

@Test
public void shouldCallDrop() throws IOException {
InsightClient client = getInsightClient();
Boolean result = client.api(Dedup.DROP).call();
assertThat(result).isTrue();
}

private TensorInstances createTensor(String docId) {
return new TensorInstances(docId, Collections.emptyList());
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
"request": {
"method": "DELETE",
"url": "/api/v1/ai/dedup/test/drop"
},
"response": {
"status": 200
}
}

0 comments on commit 903c2be

Please sign in to comment.