Skip to content
This repository was archived by the owner on Sep 28, 2022. It is now read-only.

Add document:deleteByQuery#75

Merged
scottinet merged 4 commits into
3-devfrom
KZL-1350-document-deleteByQuery
Apr 3, 2020
Merged

Add document:deleteByQuery#75
scottinet merged 4 commits into
3-devfrom
KZL-1350-document-deleteByQuery

Conversation

@y-abs
Copy link
Copy Markdown
Contributor

@y-abs y-abs commented Mar 18, 2020

What does this PR do ?

This PR implements the deleteByQuery method with its unit tests.

How should this be manually tested?

Clone this branch and run unit tests
./gradlew test

When it succeed, compile it

./gradlew jar

Initiate another java project by adding the compiled SDK as a dependency.

Then, run Kuzzle, create an index nyc-open-data and a yellow-taxi collection in the admin console. Create 5 documents with 3 containing field {"key":"value"}.
Finally, run this code

import io.kuzzle.sdk.*;
import io.kuzzle.sdk.Options.KuzzleOptions;
import io.kuzzle.sdk.Options.Protocol.WebSocketOptions;
import io.kuzzle.sdk.Protocol.WebSocket;

import java.util.concurrent.ConcurrentHashMap;

public class deleteByQueryDocument {
    private static Kuzzle kuzzle;

    public static void main(String[] args) {
        WebSocketOptions opts = new WebSocketOptions();
        opts.setAutoReconnect(true).setConnectionTimeout(42000);

        try {
            WebSocket ws = new WebSocket("localhost", opts);

            kuzzle = new Kuzzle(ws, (KuzzleOptions) null);

            kuzzle.connect();

            ConcurrentHashMap<String, Object> searchQuery = new ConcurrentHashMap<>();
            ConcurrentHashMap<String, Object> match = new ConcurrentHashMap<>();
            match.put("key", "value");
            searchQuery.put("match", match);
            ArrayList<String> result = kuzzle.getDocumentController().deleteByQuery("nyc-open-data", "yellow-taxi", searchQuery).get();
        }  catch (Exception e) {
            e.printStackTrace();
        }

        kuzzle.disconnect();
    }
};

You should have an ArrayList as result containing the deleted documents ids.

@y-abs y-abs self-assigned this Mar 18, 2020
.put("collection", collection)
.put("controller", "document")
.put("action", "deleteByQuery")
.put("body", new KuzzleMap().put("query", searchQuery))
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why do you force the "query" object? Other SDKs don't: https://docs.kuzzle.io/sdk/csharp/2/controllers/document/delete-by-query/

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe we should do it in others SDK?
Since the query object will always be here, we could do it inside the SDK ?
With java, we can benefit from avoiding declaring one more ConcurrentHashMap. ?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's a thought for later, I removed it from this PR

@y-abs y-abs requested a review from scottinet April 2, 2020 13:00
@scottinet scottinet merged commit b411fdb into 3-dev Apr 3, 2020
@scottinet scottinet deleted the KZL-1350-document-deleteByQuery branch April 3, 2020 13:06
@jenow jenow mentioned this pull request May 11, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants