Add document:create#55
Conversation
| final String collection, | ||
| final ConcurrentHashMap<String, Object> document, | ||
| final String _id, | ||
| final ConcurrentHashMap<String, Object> options) throws NotConnectedException, InternalException |
There was a problem hiding this comment.
A couple weeks ago, @jenow and I decided to amend our confluence document detailing how optional parameters should be handled by SDKs. Long story short: overloads must be used for methods taking only 1 optional argument, and option objects should only be used when there are 2 or more options.
This has been decided because this greatly simplifies the API exposed by SDKs, as well as our code base.
|
|
||
| | Option | Type | Description | ||
| | ---------- | ----------- | ---------------------------------------------------------------------------------- | | ||
| | `refresh` | string | If set to `wait_for`, Kuzzle will wait for the persistence layer to finish indexing| |
There was a problem hiding this comment.
New SDKs have a waitForRefresh (boolean) option instead of that "refresh = 'wait_for'" one. This is easier to understand, and we'll probably make that update in Kuzzle's API in the future.
Check the query method in this SDK.
| .put("action", "create") | ||
| .put("_id", _id) | ||
| .put("body", document) | ||
| .put("options", options); |
There was a problem hiding this comment.
that's not how options should be handled, check the query method
There was a problem hiding this comment.
Obviously, that was a mistake, sorry
| document.put("nickname", "El angel de la muerte que hace el JAVA"); | ||
|
|
||
| ConcurrentHashMap<String, Object> options = new ConcurrentHashMap<>(); | ||
| options.put("refresh", "wait_for"); |
There was a problem hiding this comment.
if you put the option, then you need to verify that it is properly passed to the API object being sent to kuzzle (and if my remarks above are right, then it isn't)
Co-Authored-By: Adrien Maret <amaret93@gmail.com>
Co-Authored-By: Adrien Maret <amaret93@gmail.com>
…o/sdk-java into KZL-1350-document-create
| final KuzzleMap query = new KuzzleMap(); | ||
| final KuzzleMap _options = KuzzleMap | ||
| .from(options); | ||
| final String _id = _options.getString("_id") == null ? UUID.randomUUID().toString() : _options.getString("_id"); |
There was a problem hiding this comment.
You don't have to generate the document ID on the client side.
| final String _id) throws NotConnectedException, InternalException { | ||
| return this.create(index, collection, document, _id, false); | ||
| final ConcurrentHashMap<String, Object> options = new ConcurrentHashMap<>(); | ||
| options.put("_id", UUID.randomUUID().toString()); |
There was a problem hiding this comment.
Same, you don't have to generate the ID on client side
| return this.create(index, collection, document, _id, false); | ||
| final ConcurrentHashMap<String, Object> options = new ConcurrentHashMap<>(); | ||
| options.put("_id", UUID.randomUUID().toString()); | ||
| options.put("waitForRefresh", false); |
There was a problem hiding this comment.
The default value for waitFoRefresh must handled only on Kuzzle side
| ## Arguments | ||
|
|
||
| ```java | ||
| public CompletableFuture<ConcurrentHashMap<String, Object>> create( |
There was a problem hiding this comment.
You should put the 2 possible signatures here
| | ------------------ | -------------------------------------------- | --------------------------------- | | ||
| | `index` | <pre>string</pre> | Index | | ||
| | `collection` | <pre>string</pre> | Collection | | ||
| | `content` | <pre>ConcurrentHashMap<String, Object></pre> | Content of the document to create | |
There was a problem hiding this comment.
Should be document, as in the signature and the options should also be present in the tab
|
|
||
| --- | ||
|
|
||
| # options |
|
|
||
| | Arguments | Type | Description | | ||
| | ------------------ | -------------------------------------------- | --------------------------------- | | ||
| | `id` | <pre>string</pre> (optional) | Document identifier. Auto-generated if not specified | |
| document.put("firstname", "John"); | ||
| document.put("lastname", "Smith"); | ||
|
|
||
| kuzzle.getDocumentController().create("nyc-open-data", "yellow-taxi", document) |
There was a problem hiding this comment.
Can you do the snippet test on something from the result as well as for the other methods?
Also can you add the result of the println in comment?
It helps developer to better apprehend the structure of the response object they have. We try to do this for every method (Look the Javascript SDK and Doc)
Co-Authored-By: Adrien Maret <amaret93@gmail.com>
| final String index, | ||
| final String collection, | ||
| final ConcurrentHashMap<String, Object> document, | ||
| final ConcurrentHashMap<String, Object> options) |
There was a problem hiding this comment.
We should have a DocumentOptions class containing id and waitForRefresh
76ea0f7 to
fbbea5c
Compare
What does this PR do ?
This PR initiate the
documentcontroller and implements thecreatemethod with its unit tests.How should this be manually tested?
Clone this branch and run unit tests
./gradlew testWhen it succeed, compile it
./gradlew jarInitiate another java project by adding the compiled SDK as a dependency.
Then, run Kuzzle, create an index
nyc-open-dataand ayellow-taxicollection in the admin console.Finally, run this code
You should see the document in your collection.
You can test without options as well
Other changes
Update
.travis.yml-> Add a stage for the Unit TestsBoyscout
remove useless import