diff --git a/src/main/java/com/meilisearch/sdk/Client.java b/src/main/java/com/meilisearch/sdk/Client.java index bd7040e2..708e3c07 100644 --- a/src/main/java/com/meilisearch/sdk/Client.java +++ b/src/main/java/com/meilisearch/sdk/Client.java @@ -11,6 +11,9 @@ import com.meilisearch.sdk.model.Results; import com.meilisearch.sdk.model.Stats; import com.meilisearch.sdk.model.Task; +import com.meilisearch.sdk.model.TaskInfo; +import com.meilisearch.sdk.model.TasksQuery; +import com.meilisearch.sdk.model.TasksResults; import java.util.Date; import java.util.Map; import java.util.TimeZone; @@ -43,10 +46,10 @@ public Client(Config config) { * https://docs.meilisearch.com/reference/api/indexes.html#create-an-index * * @param uid Unique identifier for the index to create - * @return Meilisearch API response as Task + * @return Meilisearch API response as TaskInfo * @throws MeilisearchException if an error occurs */ - public Task createIndex(String uid) throws MeilisearchException { + public TaskInfo createIndex(String uid) throws MeilisearchException { return this.createIndex(uid, null); } @@ -56,10 +59,10 @@ public Task createIndex(String uid) throws MeilisearchException { * * @param uid Unique identifier for the index to create * @param primaryKey The primary key of the documents in that index - * @return Meilisearch API response as Task + * @return Meilisearch API response as TaskInfo * @throws MeilisearchException if an error occurs */ - public Task createIndex(String uid, String primaryKey) throws MeilisearchException { + public TaskInfo createIndex(String uid, String primaryKey) throws MeilisearchException { return this.indexesHandler.create(uid, primaryKey); } @@ -137,10 +140,10 @@ public String getRawIndex(String uid) throws MeilisearchException { * * @param uid Unique identifier of the index to update * @param primaryKey Primary key of the documents in the index - * @return Meilisearch API response as Task + * @return Meilisearch API response as TaskInfo * @throws MeilisearchException if an error occurs */ - public Task updateIndex(String uid, String primaryKey) throws MeilisearchException { + public TaskInfo updateIndex(String uid, String primaryKey) throws MeilisearchException { return this.indexesHandler.updatePrimaryKey(uid, primaryKey); } @@ -149,10 +152,10 @@ public Task updateIndex(String uid, String primaryKey) throws MeilisearchExcepti * https://docs.meilisearch.com/reference/api/indexes.html#delete-one-index * * @param uid Unique identifier of the index to delete - * @return Meilisearch API response as Task + * @return Meilisearch API response as TaskInfo * @throws MeilisearchException if an error occurs */ - public Task deleteIndex(String uid) throws MeilisearchException { + public TaskInfo deleteIndex(String uid) throws MeilisearchException { return this.indexesHandler.delete(uid); } @@ -240,10 +243,21 @@ public Task getTask(int uid) throws MeilisearchException { * @return List of tasks in the Meilisearch client * @throws MeilisearchException if an error occurs */ - public Results getTasks() throws MeilisearchException { + public TasksResults getTasks() throws MeilisearchException { return this.tasksHandler.getTasks(); } + /** + * Retrieves list of tasks https://docs.meilisearch.com/reference/api/tasks.html#get-tasks + * + * @param param accept by the tasks route + * @return List of tasks in the Meilisearch client + * @throws MeilisearchException if an error occurs + */ + public TasksResults getTasks(TasksQuery param) throws MeilisearchException { + return this.tasksHandler.getTasks(param); + } + /** * Waits for a task to be processed * diff --git a/src/main/java/com/meilisearch/sdk/Documents.java b/src/main/java/com/meilisearch/sdk/Documents.java index 56f6009d..7e328901 100644 --- a/src/main/java/com/meilisearch/sdk/Documents.java +++ b/src/main/java/com/meilisearch/sdk/Documents.java @@ -3,7 +3,7 @@ import static java.util.Collections.singletonList; import com.meilisearch.sdk.exceptions.MeilisearchException; -import com.meilisearch.sdk.model.Task; +import com.meilisearch.sdk.model.TaskInfo; import java.util.List; /** @@ -106,15 +106,16 @@ String getDocuments(String uid, int limit, int offset, List attributesTo * @param uid Partial index identifier for the document * @param document String containing the document to add * @param primaryKey PrimaryKey of the document - * @return Meilisearch's Task API response + * @return Meilisearch's TaskInfo API response * @throws MeilisearchException if the client request causes an error */ - Task addDocuments(String uid, String document, String primaryKey) throws MeilisearchException { + TaskInfo addDocuments(String uid, String document, String primaryKey) + throws MeilisearchException { String urlQuery = "/indexes/" + uid + "/documents"; if (primaryKey != null) { urlQuery += "?primaryKey=" + primaryKey; } - return httpClient.post(urlQuery, document, Task.class); + return httpClient.post(urlQuery, document, TaskInfo.class); } /** @@ -123,16 +124,16 @@ Task addDocuments(String uid, String document, String primaryKey) throws Meilise * @param uid Partial index identifier for the document * @param document String containing the document to replace the existing document * @param primaryKey PrimaryKey of the document - * @return Meilisearch's Task API response + * @return Meilisearch's TaskInfo API response * @throws MeilisearchException if the client request causes an error */ - Task updateDocuments(String uid, String document, String primaryKey) + TaskInfo updateDocuments(String uid, String document, String primaryKey) throws MeilisearchException { String urlPath = "/indexes/" + uid + "/documents"; if (primaryKey != null) { urlPath += "?primaryKey=" + primaryKey; } - return httpClient.put(urlPath, document, Task.class); + return httpClient.put(urlPath, document, TaskInfo.class); } /** @@ -140,12 +141,12 @@ Task updateDocuments(String uid, String document, String primaryKey) * * @param uid Partial index identifier for the requested document * @param identifier ID of the document - * @return Meilisearch's Task API response + * @return Meilisearch's TaskInfo API response * @throws MeilisearchException if the client request causes an error */ - Task deleteDocument(String uid, String identifier) throws MeilisearchException { + TaskInfo deleteDocument(String uid, String identifier) throws MeilisearchException { String urlPath = "/indexes/" + uid + "/documents/" + identifier; - return httpClient.delete(urlPath, Task.class); + return httpClient.delete(urlPath, TaskInfo.class); } /** @@ -153,23 +154,23 @@ Task deleteDocument(String uid, String identifier) throws MeilisearchException { * * @param uid Partial index identifier for the requested documents * @param identifiers ID of documents to delete - * @return Meilisearch's Task API response + * @return Meilisearch's TaskInfo API response * @throws MeilisearchException if the client request causes an error */ - Task deleteDocuments(String uid, List identifiers) throws MeilisearchException { + TaskInfo deleteDocuments(String uid, List identifiers) throws MeilisearchException { String urlPath = "/indexes/" + uid + "/documents/" + "delete-batch"; - return httpClient.post(urlPath, identifiers, Task.class); + return httpClient.post(urlPath, identifiers, TaskInfo.class); } /** * Deletes all documents at the specified index uid * * @param uid Partial index identifier for the requested documents - * @return Meilisearch's Task API response + * @return Meilisearch's TaskInfo API response * @throws MeilisearchException if the client request causes an error */ - Task deleteAllDocuments(String uid) throws MeilisearchException { + TaskInfo deleteAllDocuments(String uid) throws MeilisearchException { String urlPath = "/indexes/" + uid + "/documents"; - return httpClient.delete(urlPath, Task.class); + return httpClient.delete(urlPath, TaskInfo.class); } } diff --git a/src/main/java/com/meilisearch/sdk/Index.java b/src/main/java/com/meilisearch/sdk/Index.java index 6444d8f8..120e3bd9 100644 --- a/src/main/java/com/meilisearch/sdk/Index.java +++ b/src/main/java/com/meilisearch/sdk/Index.java @@ -6,6 +6,9 @@ import com.meilisearch.sdk.model.SearchResult; import com.meilisearch.sdk.model.Settings; import com.meilisearch.sdk.model.Task; +import com.meilisearch.sdk.model.TaskInfo; +import com.meilisearch.sdk.model.TasksQuery; +import com.meilisearch.sdk.model.TasksResults; import com.meilisearch.sdk.model.TypoTolerance; import java.io.Serializable; import java.util.ArrayList; @@ -111,10 +114,10 @@ public String getDocuments(int limits, int offset, List attributesToRetr * https://docs.meilisearch.com/reference/api/documents.html#add-or-replace-documents * * @param document Document to add in JSON string format - * @return Task Meilisearch API response + * @return TaskInfo Meilisearch API response * @throws MeilisearchException if an error occurs */ - public Task addDocuments(String document) throws MeilisearchException { + public TaskInfo addDocuments(String document) throws MeilisearchException { return this.documents.addDocuments(this.uid, document, null); } @@ -124,10 +127,10 @@ public Task addDocuments(String document) throws MeilisearchException { * * @param document Document to add in JSON string format * @param primaryKey PrimaryKey of the document to add - * @return Task Meilisearch API response + * @return TaskInfo Meilisearch API response * @throws MeilisearchException if an error occurs */ - public Task addDocuments(String document, String primaryKey) throws MeilisearchException { + public TaskInfo addDocuments(String document, String primaryKey) throws MeilisearchException { return this.documents.addDocuments(this.uid, document, primaryKey); } @@ -138,15 +141,15 @@ public Task addDocuments(String document, String primaryKey) throws MeilisearchE * @param batchSize size of the batch of documents * @param document Document to add in JSON string format * @param primaryKey PrimaryKey of the document to add - * @return Task Meilisearch API response + * @return TaskInfo Meilisearch API response * @throws MeilisearchException if an error occurs */ - public Task[] addDocumentsInBatches(String document, Integer batchSize, String primaryKey) + public TaskInfo[] addDocumentsInBatches(String document, Integer batchSize, String primaryKey) throws MeilisearchException { JSONArray jsonDocumentsArray = new JSONArray(document); JSONArray jsonSubArray = new JSONArray(); - List arrayResponses = new ArrayList(); + List arrayResponses = new ArrayList(); batchSize = jsonDocumentsArray.length() < batchSize ? jsonDocumentsArray.length() : batchSize; @@ -158,7 +161,7 @@ public Task[] addDocumentsInBatches(String document, Integer batchSize, String p arrayResponses.add( this.documents.addDocuments(this.uid, jsonSubArray.toString(), primaryKey)); } - return arrayResponses.toArray(new Task[arrayResponses.size()]); + return arrayResponses.toArray(new TaskInfo[arrayResponses.size()]); } /** @@ -166,10 +169,10 @@ public Task[] addDocumentsInBatches(String document, Integer batchSize, String p * https://docs.meilisearch.com/reference/api/documents.html#add-or-replace-documents * * @param document Document to add in JSON string format - * @return Task Meilisearch API response + * @return TaskInfo Meilisearch API response * @throws MeilisearchException if an error occurs */ - public Task[] addDocumentsInBatches(String document) throws MeilisearchException { + public TaskInfo[] addDocumentsInBatches(String document) throws MeilisearchException { return this.addDocumentsInBatches(document, 1000, null); } @@ -178,10 +181,10 @@ public Task[] addDocumentsInBatches(String document) throws MeilisearchException * https://docs.meilisearch.com/reference/api/documents.html#add-or-update-documents * * @param document Document to update in JSON string format - * @return Task Meilisearch API response + * @return TaskInfo Meilisearch API response * @throws MeilisearchException if an error occurs */ - public Task updateDocuments(String document) throws MeilisearchException { + public TaskInfo updateDocuments(String document) throws MeilisearchException { return this.documents.updateDocuments(this.uid, document, null); } @@ -191,10 +194,11 @@ public Task updateDocuments(String document) throws MeilisearchException { * * @param document Document to update in JSON string format * @param primaryKey PrimaryKey of the document - * @return Task Meilisearch API response + * @return TaskInfo Meilisearch API response * @throws MeilisearchException if an error occurs */ - public Task updateDocuments(String document, String primaryKey) throws MeilisearchException { + public TaskInfo updateDocuments(String document, String primaryKey) + throws MeilisearchException { return this.documents.updateDocuments(this.uid, document, primaryKey); } @@ -205,15 +209,15 @@ public Task updateDocuments(String document, String primaryKey) throws Meilisear * @param document Document to add in JSON string format * @param batchSize size of the batch of documents * @param primaryKey PrimaryKey of the document to add - * @return Task Meilisearch API response + * @return TaskInfo Meilisearch API response * @throws MeilisearchException if an error occurs */ - public Task[] updateDocumentsInBatches(String document, Integer batchSize, String primaryKey) - throws MeilisearchException { + public TaskInfo[] updateDocumentsInBatches( + String document, Integer batchSize, String primaryKey) throws MeilisearchException { JSONArray jsonDocumentsArray = new JSONArray(document); JSONArray jsonSubArray = new JSONArray(); - List arrayResponses = new ArrayList(); + List arrayResponses = new ArrayList(); batchSize = jsonDocumentsArray.length() < batchSize ? jsonDocumentsArray.length() : batchSize; @@ -225,7 +229,7 @@ public Task[] updateDocumentsInBatches(String document, Integer batchSize, Strin arrayResponses.add( this.documents.updateDocuments(this.uid, jsonSubArray.toString(), primaryKey)); } - return arrayResponses.toArray(new Task[arrayResponses.size()]); + return arrayResponses.toArray(new TaskInfo[arrayResponses.size()]); } /** @@ -233,10 +237,10 @@ public Task[] updateDocumentsInBatches(String document, Integer batchSize, Strin * https://docs.meilisearch.com/reference/api/documents.html#add-or-update-documents * * @param document Document to add in JSON string format - * @return Task Meilisearch API response + * @return TaskInfo Meilisearch API response * @throws MeilisearchException if an error occurs */ - public Task[] updateDocumentsInBatches(String document) throws MeilisearchException { + public TaskInfo[] updateDocumentsInBatches(String document) throws MeilisearchException { return this.updateDocumentsInBatches(document, 1000, null); } @@ -245,10 +249,10 @@ public Task[] updateDocumentsInBatches(String document) throws MeilisearchExcept * https://docs.meilisearch.com/reference/api/documents.html#delete-one-document * * @param identifier Identifier of the document to delete - * @return Task Meilisearch API response + * @return TaskInfo Meilisearch API response * @throws MeilisearchException if an error occurs */ - public Task deleteDocument(String identifier) throws MeilisearchException { + public TaskInfo deleteDocument(String identifier) throws MeilisearchException { return this.documents.deleteDocument(this.uid, identifier); } @@ -257,10 +261,10 @@ public Task deleteDocument(String identifier) throws MeilisearchException { * https://docs.meilisearch.com/reference/api/documents.html#delete-documents-by-batch * * @param documentsIdentifiers list of identifiers of documents to delete - * @return Task Meilisearch API response + * @return TaskInfo Meilisearch API response * @throws MeilisearchException if an error occurs */ - public Task deleteDocuments(List documentsIdentifiers) throws MeilisearchException { + public TaskInfo deleteDocuments(List documentsIdentifiers) throws MeilisearchException { return this.documents.deleteDocuments(this.uid, documentsIdentifiers); } @@ -271,7 +275,7 @@ public Task deleteDocuments(List documentsIdentifiers) throws Meilisearc * @return List of tasks Meilisearch API response * @throws MeilisearchException if an error occurs */ - public Task deleteAllDocuments() throws MeilisearchException { + public TaskInfo deleteAllDocuments() throws MeilisearchException { return this.documents.deleteAllDocuments(this.uid); } @@ -323,10 +327,10 @@ public Settings getSettings() throws MeilisearchException { * https://docs.meilisearch.com/reference/api/settings.html#update-settings * * @param settings the object that contains the data with the new settings - * @return Task instance + * @return TaskInfo instance * @throws MeilisearchException if an error occurs */ - public Task updateSettings(Settings settings) throws MeilisearchException { + public TaskInfo updateSettings(Settings settings) throws MeilisearchException { return this.settingsHandler.updateSettings(this.uid, settings); } @@ -334,10 +338,10 @@ public Task updateSettings(Settings settings) throws MeilisearchException { * Resets the settings of the index Refer * https://docs.meilisearch.com/reference/api/settings.html#reset-settings * - * @return Task instance + * @return TaskInfo instance * @throws MeilisearchException if an error occurs */ - public Task resetSettings() throws MeilisearchException { + public TaskInfo resetSettings() throws MeilisearchException { return this.settingsHandler.resetSettings(this.uid); } @@ -357,10 +361,10 @@ public String[] getRankingRuleSettings() throws MeilisearchException { * https://docs.meilisearch.com/reference/api/settings.html#update-settings * * @param rankingRules array that contain the data with the new ranking rules - * @return Task instance + * @return TaskInfo instance * @throws MeilisearchException if an error occurs */ - public Task updateRankingRuleSettings(String[] rankingRules) throws MeilisearchException { + public TaskInfo updateRankingRuleSettings(String[] rankingRules) throws MeilisearchException { return this.settingsHandler.updateRankingRuleSettings(this.uid, rankingRules); } @@ -368,10 +372,10 @@ public Task updateRankingRuleSettings(String[] rankingRules) throws MeilisearchE * Resets the ranking rule settings of the index Refer * https://docs.meilisearch.com/reference/api/settings.html#reset-settings * - * @return Task instance + * @return TaskInfo instance * @throws MeilisearchException if an error occurs */ - public Task resetRankingRuleSettings() throws MeilisearchException { + public TaskInfo resetRankingRuleSettings() throws MeilisearchException { return this.settingsHandler.resetRankingRulesSettings(this.uid); } @@ -391,10 +395,11 @@ public Map getSynonymsSettings() throws MeilisearchException { * https://docs.meilisearch.com/reference/api/synonyms.html#update-synonyms * * @param synonyms key (String) value (array) pair of synonyms - * @return Task instance + * @return TaskInfo instance * @throws MeilisearchException if an error occurs */ - public Task updateSynonymsSettings(Map synonyms) throws MeilisearchException { + public TaskInfo updateSynonymsSettings(Map synonyms) + throws MeilisearchException { return this.settingsHandler.updateSynonymsSettings(this.uid, synonyms); } @@ -402,10 +407,10 @@ public Task updateSynonymsSettings(Map synonyms) throws Meilis * Resets the synonyms settings of the index Refer * https://docs.meilisearch.com/reference/api/synonyms.html#reset-synonyms * - * @return Task instance + * @return TaskInfo instance * @throws MeilisearchException if an error occurs */ - public Task resetSynonymsSettings() throws MeilisearchException { + public TaskInfo resetSynonymsSettings() throws MeilisearchException { return this.settingsHandler.resetSynonymsSettings(this.uid); } @@ -425,10 +430,10 @@ public String[] getStopWordsSettings() throws MeilisearchException { * https://docs.meilisearch.com/reference/api/stop_words.html#update-stop-words * * @param stopWords An array of strings that contains the stop-words. - * @return Task instance + * @return TaskInfo instance * @throws MeilisearchException if an error occurs */ - public Task updateStopWordsSettings(String[] stopWords) throws MeilisearchException { + public TaskInfo updateStopWordsSettings(String[] stopWords) throws MeilisearchException { return this.settingsHandler.updateStopWordsSettings(this.uid, stopWords); } @@ -436,10 +441,10 @@ public Task updateStopWordsSettings(String[] stopWords) throws MeilisearchExcept * Resets the stop-words settings of the index Refer * https://docs.meilisearch.com/reference/api/stop_words.html#reset-stop-words * - * @return Task instance + * @return TaskInfo instance * @throws MeilisearchException if an error occurs */ - public Task resetStopWordsSettings() throws MeilisearchException { + public TaskInfo resetStopWordsSettings() throws MeilisearchException { return this.settingsHandler.resetStopWordsSettings(this.uid); } @@ -459,10 +464,10 @@ public String[] getSearchableAttributesSettings() throws MeilisearchException { * https://docs.meilisearch.com/reference/api/searchable_attributes.html#update-searchable-attributes * * @param searchableAttributes An array of strings that contains the searchable attributes. - * @return Task instance + * @return TaskInfo instance * @throws MeilisearchException if an error occurs */ - public Task updateSearchableAttributesSettings(String[] searchableAttributes) + public TaskInfo updateSearchableAttributesSettings(String[] searchableAttributes) throws MeilisearchException { return this.settingsHandler.updateSearchableAttributesSettings( this.uid, searchableAttributes); @@ -472,10 +477,10 @@ public Task updateSearchableAttributesSettings(String[] searchableAttributes) * Resets the searchable attributes of the index Refer * https://docs.meilisearch.com/reference/api/searchable_attributes.html#reset-searchable-attributes * - * @return Task instance + * @return TaskInfo instance * @throws MeilisearchException if an error occurs */ - public Task resetSearchableAttributesSettings() throws MeilisearchException { + public TaskInfo resetSearchableAttributesSettings() throws MeilisearchException { return this.settingsHandler.resetSearchableAttributesSettings(this.uid); } @@ -495,10 +500,10 @@ public String[] getDisplayedAttributesSettings() throws MeilisearchException { * https://docs.meilisearch.com/reference/api/displayed_attributes.html#update-displayed-attributes * * @param displayAttributes An array of strings that contains attributes of an index to display - * @return Task instance + * @return TaskInfo instance * @throws MeilisearchException if an error occurs */ - public Task updateDisplayedAttributesSettings(String[] displayAttributes) + public TaskInfo updateDisplayedAttributesSettings(String[] displayAttributes) throws MeilisearchException { return this.settingsHandler.updateDisplayedAttributesSettings(this.uid, displayAttributes); } @@ -507,10 +512,10 @@ public Task updateDisplayedAttributesSettings(String[] displayAttributes) * Resets the displayed attributes of the index Refer * https://docs.meilisearch.com/reference/api/displayed_attributes.html#reset-displayed-attributes * - * @return Task instance + * @return TaskInfo instance * @throws MeilisearchException if an error occurs */ - public Task resetDisplayedAttributesSettings() throws MeilisearchException { + public TaskInfo resetDisplayedAttributesSettings() throws MeilisearchException { return this.settingsHandler.resetDisplayedAttributesSettings(this.uid); } @@ -532,10 +537,10 @@ public String[] getFilterableAttributesSettings() throws MeilisearchException { * * @param filterableAttributes An array of strings containing the attributes that can be used as * filters at query time. - * @return Task instance + * @return TaskInfo instance * @throws MeilisearchException if an error occurs */ - public Task updateFilterableAttributesSettings(String[] filterableAttributes) + public TaskInfo updateFilterableAttributesSettings(String[] filterableAttributes) throws MeilisearchException { return this.settingsHandler.updateFilterableAttributesSettings( this.uid, filterableAttributes); @@ -545,10 +550,10 @@ public Task updateFilterableAttributesSettings(String[] filterableAttributes) * Resets the filterable attributes of the index Refer * https://docs.meilisearch.com/reference/api/filterable_attributes.html#reset-filterable-attributes * - * @return Task instance + * @return TaskInfo instance * @throws MeilisearchException if an error occurs */ - public Task resetFilterableAttributesSettings() throws MeilisearchException { + public TaskInfo resetFilterableAttributesSettings() throws MeilisearchException { return this.settingsHandler.resetFilterableAttributesSettings(this.uid); } @@ -568,10 +573,10 @@ public String getDistinctAttributeSettings() throws MeilisearchException { * https://docs.meilisearch.com/reference/api/distinct_attribute.html#update-distinct-attribute * * @param distinctAttribute A String: the field name. - * @return Task instance + * @return TaskInfo instance * @throws MeilisearchException if an error occurs */ - public Task updateDistinctAttributeSettings(String distinctAttribute) + public TaskInfo updateDistinctAttributeSettings(String distinctAttribute) throws MeilisearchException { return this.settingsHandler.updateDistinctAttributeSettings(this.uid, distinctAttribute); } @@ -580,10 +585,10 @@ public Task updateDistinctAttributeSettings(String distinctAttribute) * Resets the distinct attribute field of the index Refer * https://docs.meilisearch.com/reference/api/distinct_attribute.html#reset-distinct-attribute * - * @return Task instance + * @return TaskInfo instance * @throws MeilisearchException if an error occurs */ - public Task resetDistinctAttributeSettings() throws MeilisearchException { + public TaskInfo resetDistinctAttributeSettings() throws MeilisearchException { return this.settingsHandler.resetDistinctAttributeSettings(this.uid); } @@ -603,10 +608,10 @@ public TypoTolerance getTypoToleranceSettings() throws MeilisearchException { * https://docs.meilisearch.com/reference/api/typo_tolerance.html#update-typo-tolerance * * @param typoTolerance A TypoTolerance instance - * @return Task instance + * @return TaskInfo instance * @throws MeilisearchException if an error occurs */ - public Task updateTypoToleranceSettings(TypoTolerance typoTolerance) + public TaskInfo updateTypoToleranceSettings(TypoTolerance typoTolerance) throws MeilisearchException { return this.settingsHandler.updateTypoToleranceSettings(this.uid, typoTolerance); } @@ -615,10 +620,10 @@ public Task updateTypoToleranceSettings(TypoTolerance typoTolerance) * Resets the typo tolerance field of the index Refer * https://docs.meilisearch.com/reference/api/typo_tolerance.html#reset-typo-tolerance * - * @return Task instance + * @return TaskInfo instance * @throws MeilisearchException if an error occurs */ - public Task resetTypoToleranceSettings() throws MeilisearchException { + public TaskInfo resetTypoToleranceSettings() throws MeilisearchException { return this.settingsHandler.resetTypoToleranceSettings(this.uid); } @@ -642,7 +647,7 @@ public IndexStats getStats() throws MeilisearchException { * @throws MeilisearchException if an error occurs */ public Task getTask(int taskId) throws MeilisearchException { - return this.tasksHandler.getTask(this.uid, taskId); + return this.tasksHandler.getTask(taskId); } /** @@ -652,10 +657,22 @@ public Task getTask(int taskId) throws MeilisearchException { * @return List of tasks in the Meilisearch index * @throws MeilisearchException if an error occurs */ - public Results getTasks() throws MeilisearchException { + public TasksResults getTasks() throws MeilisearchException { return this.tasksHandler.getTasks(this.uid); } + /** + * Retrieves list of tasks of the index Refer + * https://docs.meilisearch.com/reference/api/tasks.html#get-tasks + * + * @param param accept by the tasks route + * @return List of tasks in the Meilisearch index + * @throws MeilisearchException if an error occurs + */ + public TasksResults getTasks(TasksQuery param) throws MeilisearchException { + return this.tasksHandler.getTasks(this.uid, param); + } + /** * Waits for a task to be processed Refer * https://docs.meilisearch.com/reference/api/tasks.html#task-object diff --git a/src/main/java/com/meilisearch/sdk/IndexesHandler.java b/src/main/java/com/meilisearch/sdk/IndexesHandler.java index 533d67ca..8521e7e6 100644 --- a/src/main/java/com/meilisearch/sdk/IndexesHandler.java +++ b/src/main/java/com/meilisearch/sdk/IndexesHandler.java @@ -1,7 +1,7 @@ package com.meilisearch.sdk; import com.meilisearch.sdk.exceptions.MeilisearchException; -import com.meilisearch.sdk.model.Task; +import com.meilisearch.sdk.model.TaskInfo; import java.util.HashMap; /** @@ -29,7 +29,7 @@ class IndexesHandler { * @return Meilisearch API response * @throws MeilisearchException if an error occurs */ - Task create(String uid) throws MeilisearchException { + TaskInfo create(String uid) throws MeilisearchException { return this.create(uid, null); } @@ -41,12 +41,12 @@ Task create(String uid) throws MeilisearchException { * @return Meilisearch API response * @throws MeilisearchException if an error occurs */ - Task create(String uid, String primaryKey) throws MeilisearchException { + TaskInfo create(String uid, String primaryKey) throws MeilisearchException { HashMap index = new HashMap(); index.put("uid", uid); index.put("primaryKey", primaryKey); - return httpClient.post("/indexes", index, Task.class); + return httpClient.post("/indexes", index, TaskInfo.class); } /** @@ -79,12 +79,12 @@ String getAll() throws MeilisearchException { * @return Meilisearch API response * @throws MeilisearchException if an error occurs */ - Task updatePrimaryKey(String uid, String primaryKey) throws MeilisearchException { + TaskInfo updatePrimaryKey(String uid, String primaryKey) throws MeilisearchException { HashMap index = new HashMap(); index.put("primaryKey", primaryKey); String requestQuery = "/indexes/" + uid; - return httpClient.patch(requestQuery, index, Task.class); + return httpClient.patch(requestQuery, index, TaskInfo.class); } /** @@ -94,8 +94,8 @@ Task updatePrimaryKey(String uid, String primaryKey) throws MeilisearchException * @return Meilisearch API response * @throws MeilisearchException if an error occurs */ - Task delete(String uid) throws MeilisearchException { + TaskInfo delete(String uid) throws MeilisearchException { String requestQuery = "/indexes/" + uid; - return httpClient.delete(requestQuery, Task.class); + return httpClient.delete(requestQuery, TaskInfo.class); } } diff --git a/src/main/java/com/meilisearch/sdk/SettingsHandler.java b/src/main/java/com/meilisearch/sdk/SettingsHandler.java index 9c9fcafa..c23acaa9 100644 --- a/src/main/java/com/meilisearch/sdk/SettingsHandler.java +++ b/src/main/java/com/meilisearch/sdk/SettingsHandler.java @@ -2,7 +2,7 @@ import com.meilisearch.sdk.exceptions.MeilisearchException; import com.meilisearch.sdk.model.Settings; -import com.meilisearch.sdk.model.Task; +import com.meilisearch.sdk.model.TaskInfo; import com.meilisearch.sdk.model.TypoTolerance; import java.util.Map; @@ -40,24 +40,24 @@ Settings getSettings(String uid) throws MeilisearchException { * * @param uid Index identifier * @param settings the data that contains the new settings - * @return Task instance + * @return TaskInfo instance * @throws MeilisearchException if an error occurs */ - Task updateSettings(String uid, Settings settings) throws MeilisearchException { + TaskInfo updateSettings(String uid, Settings settings) throws MeilisearchException { String urlPath = "/indexes/" + uid + "/settings"; - return httpClient.patch(urlPath, settings, Task.class); + return httpClient.patch(urlPath, settings, TaskInfo.class); } /** * Resets the settings of the index * * @param uid Index identifier - * @return Task instance + * @return TaskInfo instance * @throws MeilisearchException if an error occurs */ - Task resetSettings(String uid) throws MeilisearchException { + TaskInfo resetSettings(String uid) throws MeilisearchException { String urlPath = "/indexes/" + uid + "/settings"; - return httpClient.delete(urlPath, Task.class); + return httpClient.delete(urlPath, TaskInfo.class); } /** @@ -77,27 +77,28 @@ String[] getRankingRuleSettings(String uid) throws MeilisearchException { * * @param uid Index identifier * @param rankingRules the data that contains the new settings - * @return Task instance + * @return TaskInfo instance * @throws MeilisearchException if an error occurs */ - Task updateRankingRuleSettings(String uid, String[] rankingRules) throws MeilisearchException { + TaskInfo updateRankingRuleSettings(String uid, String[] rankingRules) + throws MeilisearchException { String urlPath = "/indexes/" + uid + "/settings/ranking-rules"; return httpClient.put( urlPath, rankingRules == null ? httpClient.jsonHandler.encode(rankingRules) : rankingRules, - Task.class); + TaskInfo.class); } /** * Resets the ranking rules settings of the index * * @param uid Index identifier - * @return Task instance + * @return TaskInfo instance * @throws MeilisearchException if an error occurs */ - Task resetRankingRulesSettings(String uid) throws MeilisearchException { + TaskInfo resetRankingRulesSettings(String uid) throws MeilisearchException { String urlPath = "/indexes/" + uid + "/settings/ranking-rules"; - return httpClient.delete(urlPath, Task.class); + return httpClient.delete(urlPath, TaskInfo.class); } /** @@ -117,28 +118,28 @@ Map getSynonymsSettings(String uid) throws MeilisearchExceptio * * @param uid Index identifier * @param synonyms a Map that contains the new synonyms settings - * @return Task instance + * @return TaskInfo instance * @throws MeilisearchException if an error occurs */ - Task updateSynonymsSettings(String uid, Map synonyms) + TaskInfo updateSynonymsSettings(String uid, Map synonyms) throws MeilisearchException { String urlPath = "/indexes/" + uid + "/settings/synonyms"; return httpClient.put( urlPath, synonyms == null ? httpClient.jsonHandler.encode(synonyms) : synonyms, - Task.class); + TaskInfo.class); } /** * Resets the synonyms settings of the index * * @param uid Index identifier - * @return Task instance + * @return TaskInfo instance * @throws MeilisearchException if an error occurs */ - Task resetSynonymsSettings(String uid) throws MeilisearchException { + TaskInfo resetSynonymsSettings(String uid) throws MeilisearchException { String urlPath = "/indexes/" + uid + "/settings/synonyms"; - return httpClient.delete(urlPath, Task.class); + return httpClient.delete(urlPath, TaskInfo.class); } /** @@ -158,27 +159,27 @@ String[] getStopWordsSettings(String uid) throws MeilisearchException { * * @param uid Index identifier * @param stopWords an array of strings that contains the new stop-words settings - * @return Task instance + * @return TaskInfo instance * @throws MeilisearchException if an error occurs */ - Task updateStopWordsSettings(String uid, String[] stopWords) throws MeilisearchException { + TaskInfo updateStopWordsSettings(String uid, String[] stopWords) throws MeilisearchException { String urlPath = "/indexes/" + uid + "/settings/stop-words"; return httpClient.put( urlPath, stopWords == null ? httpClient.jsonHandler.encode(stopWords) : stopWords, - Task.class); + TaskInfo.class); } /** * Resets the stop-words settings of the index * * @param uid Index identifier - * @return Task instance + * @return TaskInfo instance * @throws MeilisearchException if an error occurs */ - Task resetStopWordsSettings(String uid) throws MeilisearchException { + TaskInfo resetStopWordsSettings(String uid) throws MeilisearchException { String urlPath = "/indexes/" + uid + "/settings/stop-words"; - return httpClient.delete(urlPath, Task.class); + return httpClient.delete(urlPath, TaskInfo.class); } /** @@ -199,10 +200,10 @@ String[] getSearchableAttributesSettings(String uid) throws MeilisearchException * @param uid Index identifier * @param searchableAttributes an array of strings that contains the new searchable attributes * settings - * @return Task instance + * @return TaskInfo instance * @throws MeilisearchException if an error occurs */ - Task updateSearchableAttributesSettings(String uid, String[] searchableAttributes) + TaskInfo updateSearchableAttributesSettings(String uid, String[] searchableAttributes) throws MeilisearchException { String urlPath = "/indexes/" + uid + "/settings/searchable-attributes"; return httpClient.put( @@ -210,19 +211,19 @@ Task updateSearchableAttributesSettings(String uid, String[] searchableAttribute searchableAttributes == null ? httpClient.jsonHandler.encode(searchableAttributes) : searchableAttributes, - Task.class); + TaskInfo.class); } /** * Resets the searchable attributes of the index * * @param uid Index identifier - * @return Task instance + * @return TaskInfo instance * @throws MeilisearchException if an error occurs */ - Task resetSearchableAttributesSettings(String uid) throws MeilisearchException { + TaskInfo resetSearchableAttributesSettings(String uid) throws MeilisearchException { String urlPath = "/indexes/" + uid + "/settings/searchable-attributes"; - return httpClient.delete(urlPath, Task.class); + return httpClient.delete(urlPath, TaskInfo.class); } /** @@ -243,10 +244,10 @@ String[] getDisplayedAttributesSettings(String uid) throws MeilisearchException * @param uid Index identifier * @param displayAttributes an array of strings that contains the new displayed attributes * settings - * @return Task instance + * @return TaskInfo instance * @throws MeilisearchException if an error occurs */ - Task updateDisplayedAttributesSettings(String uid, String[] displayAttributes) + TaskInfo updateDisplayedAttributesSettings(String uid, String[] displayAttributes) throws MeilisearchException { String urlPath = "/indexes/" + uid + "/settings/displayed-attributes"; return httpClient.put( @@ -254,19 +255,19 @@ Task updateDisplayedAttributesSettings(String uid, String[] displayAttributes) displayAttributes == null ? httpClient.jsonHandler.encode(displayAttributes) : displayAttributes, - Task.class); + TaskInfo.class); } /** * Resets the displayed attributes of the index * * @param uid Index identifier - * @return Task instance + * @return TaskInfo instance * @throws MeilisearchException if an error occurs */ - Task resetDisplayedAttributesSettings(String uid) throws MeilisearchException { + TaskInfo resetDisplayedAttributesSettings(String uid) throws MeilisearchException { String urlPath = "/indexes/" + uid + "/settings/displayed-attributes"; - return httpClient.delete(urlPath, Task.class); + return httpClient.delete(urlPath, TaskInfo.class); } /** @@ -287,10 +288,10 @@ String[] getFilterableAttributesSettings(String uid) throws MeilisearchException * @param uid Index identifier * @param filterableAttributes an array of strings that contains the new filterable attributes * settings - * @return Task instance + * @return TaskInfo instance * @throws MeilisearchException if an error occurs */ - Task updateFilterableAttributesSettings(String uid, String[] filterableAttributes) + TaskInfo updateFilterableAttributesSettings(String uid, String[] filterableAttributes) throws MeilisearchException { String urlPath = "/indexes/" + uid + "/settings/filterable-attributes"; return httpClient.put( @@ -298,19 +299,19 @@ Task updateFilterableAttributesSettings(String uid, String[] filterableAttribute filterableAttributes == null ? httpClient.jsonHandler.encode(filterableAttributes) : filterableAttributes, - Task.class); + TaskInfo.class); } /** * Resets the filterable attributes of the index * * @param uid Index identifier - * @return Task instance + * @return TaskInfo instance * @throws MeilisearchException if an error occurs */ - Task resetFilterableAttributesSettings(String uid) throws MeilisearchException { + TaskInfo resetFilterableAttributesSettings(String uid) throws MeilisearchException { String urlPath = "/indexes/" + uid + "/settings/filterable-attributes"; - return httpClient.delete(urlPath, Task.class); + return httpClient.delete(urlPath, TaskInfo.class); } /** @@ -331,10 +332,10 @@ String getDistinctAttributeSettings(String uid) throws MeilisearchException { * * @param uid Index identifier * @param distinctAttribute a String that contains the new distinct attributes settings - * @return Task instance + * @return TaskInfo instance * @throws MeilisearchException if an error occurs */ - Task updateDistinctAttributeSettings(String uid, String distinctAttribute) + TaskInfo updateDistinctAttributeSettings(String uid, String distinctAttribute) throws MeilisearchException { String urlPath = "/indexes/" + uid + "/settings/distinct-attribute"; return httpClient.put( @@ -342,19 +343,19 @@ Task updateDistinctAttributeSettings(String uid, String distinctAttribute) distinctAttribute == null ? httpClient.jsonHandler.encode(distinctAttribute) : "\"" + distinctAttribute + "\"", - Task.class); + TaskInfo.class); } /** * Resets the distinct attribute field of the index * * @param uid Index identifier - * @return Task instance + * @return TaskInfo instance * @throws MeilisearchException if an error occurs */ - Task resetDistinctAttributeSettings(String uid) throws MeilisearchException { + TaskInfo resetDistinctAttributeSettings(String uid) throws MeilisearchException { String urlPath = "/indexes/" + uid + "/settings/distinct-attribute"; - return httpClient.delete(urlPath, Task.class); + return httpClient.delete(urlPath, TaskInfo.class); } /** @@ -374,10 +375,10 @@ TypoTolerance getTypoToleranceSettings(String uid) throws MeilisearchException { * * @param uid Index identifier * @param typoTolerance a TypoTolerance instance that contains the new typo tolerance settings - * @return Task instance + * @return TaskInfo instance * @throws MeilisearchException if an error occurs */ - Task updateTypoToleranceSettings(String uid, TypoTolerance typoTolerance) + TaskInfo updateTypoToleranceSettings(String uid, TypoTolerance typoTolerance) throws MeilisearchException { String urlPath = "/indexes/" + uid + "/settings/typo-tolerance"; return httpClient.patch( @@ -385,18 +386,18 @@ Task updateTypoToleranceSettings(String uid, TypoTolerance typoTolerance) typoTolerance == null ? httpClient.jsonHandler.encode(typoTolerance) : typoTolerance, - Task.class); + TaskInfo.class); } /** * Resets the typo tolerance settings of the index * * @param uid Index identifier - * @return Task instance + * @return TaskInfo instance * @throws MeilisearchException if an error occurs */ - Task resetTypoToleranceSettings(String uid) throws MeilisearchException { + TaskInfo resetTypoToleranceSettings(String uid) throws MeilisearchException { String urlPath = "/indexes/" + uid + "/settings/typo-tolerance"; - return httpClient.delete(urlPath, Task.class); + return httpClient.delete(urlPath, TaskInfo.class); } } diff --git a/src/main/java/com/meilisearch/sdk/TasksHandler.java b/src/main/java/com/meilisearch/sdk/TasksHandler.java index 03538439..43d3faa6 100644 --- a/src/main/java/com/meilisearch/sdk/TasksHandler.java +++ b/src/main/java/com/meilisearch/sdk/TasksHandler.java @@ -2,8 +2,10 @@ import com.meilisearch.sdk.exceptions.MeilisearchException; import com.meilisearch.sdk.exceptions.MeilisearchTimeoutException; -import com.meilisearch.sdk.model.Results; +import com.meilisearch.sdk.http.URLBuilder; import com.meilisearch.sdk.model.Task; +import com.meilisearch.sdk.model.TasksQuery; +import com.meilisearch.sdk.model.TasksResults; import java.util.Date; /** @@ -26,53 +28,94 @@ public class TasksHandler { } /** - * Retrieves the task at the specified index uid with the specified task uid + * Retrieves one task with the specified task uid * - * @param indexUid Index identifier to the requested Task * @param taskUid Identifier of the requested Task * @return Task instance * @throws MeilisearchException if client request causes an error */ - Task getTask(String indexUid, int taskUid) throws MeilisearchException { - String urlPath = "/indexes/" + indexUid + "/tasks/" + taskUid; + Task getTask(int taskUid) throws MeilisearchException { + URLBuilder urlb = new URLBuilder(); + urlb.addSubroute("tasks").addSubroute(Integer.toString(taskUid)); + String urlPath = urlb.getURL(); return httpClient.get(urlPath, Task.class); } /** - * Retrieves all TasksHandler at the specified index uid + * Retrieves all tasks from the client * - * @param indexUid Index identifier to the requested Tasks * @return List of task instance * @throws MeilisearchException if client request causes an error */ - Results getTasks(String indexUid) throws MeilisearchException { + TasksResults getTasks() throws MeilisearchException { + String urlPath = "/tasks"; - Results result = httpClient.get(urlPath, Results.class, Task.class); + TasksResults result = httpClient.get(urlPath, TasksResults.class); return result; } /** - * Retrieves the task with the specified task uid + * Retrieves all tasks from the client * - * @param taskUid Identifier of the requested Task - * @return Task instance + * @param param accept by the tasks route + * @return List of task instance * @throws MeilisearchException if client request causes an error */ - Task getTask(int taskUid) throws MeilisearchException { - String urlPath = "/tasks/" + taskUid; - return httpClient.get(urlPath, Task.class); + TasksResults getTasks(TasksQuery param) throws MeilisearchException { + URLBuilder urlb = new URLBuilder(); + urlb.addSubroute("tasks") + .addParameter("limit", param.getLimit()) + .addParameter("from", param.getFrom()) + .addParameter("status", param.getStatus()) + .addParameter("type", param.getType()) + .addParameter("indexUid", param.getIndexUid()); + String urlQuery = urlb.getURL(); + + TasksResults result = httpClient.get(urlQuery, TasksResults.class); + return result; } /** - * Retrieves tasks from the client + * Retrieves all tasks from specified index uid * + * @param indexUid Index identifier to index of the requested Tasks * @return List of task instance * @throws MeilisearchException if client request causes an error */ - Results getTasks() throws MeilisearchException { - String urlPath = "/tasks"; + TasksResults getTasks(String indexUid) throws MeilisearchException { + URLBuilder urlb = new URLBuilder(); + urlb.addSubroute("tasks").addParameter("indexUid", indexUid); + String urlQuery = urlb.getURL(); + + TasksResults result = httpClient.get(urlQuery, TasksResults.class); + return result; + } + + /** + * Retrieves all tasks from specified index uid + * + * @param indexUid Index identifier to index of the requested Tasks + * @param param accept by the tasks route + * @return List of task instance + * @throws MeilisearchException if client request causes an error + */ + TasksResults getTasks(String indexUid, TasksQuery param) throws MeilisearchException { + String[] newIndexUid = new String[param.getIndexUid().length + 1]; + if (param != null && param.getIndexUid() != null) { + for (int i = 0; i < param.getIndexUid().length; i++) + newIndexUid[i] = param.getIndexUid()[i]; + newIndexUid[param.getIndexUid().length] = indexUid; + } + URLBuilder urlb = new URLBuilder(); + urlb.addSubroute("tasks") + .addParameter("limit", param.getLimit()) + .addParameter("from", param.getFrom()) + .addParameter("status", param.getStatus()) + .addParameter("type", param.getType()) + .addParameter("indexUid", newIndexUid); + String urlQuery = urlb.getURL(); - Results result = httpClient.get(urlPath, Results.class, Task.class); + TasksResults result = httpClient.get(urlQuery, TasksResults.class); return result; } diff --git a/src/main/java/com/meilisearch/sdk/model/TaskInfo.java b/src/main/java/com/meilisearch/sdk/model/TaskInfo.java new file mode 100644 index 00000000..dde50fc6 --- /dev/null +++ b/src/main/java/com/meilisearch/sdk/model/TaskInfo.java @@ -0,0 +1,26 @@ +package com.meilisearch.sdk.model; + +import com.meilisearch.sdk.TaskError; +import java.util.Date; +import lombok.Getter; + +/** + * Data structure of Meilisearch response for a asynchronous operation + * + *

https://docs.meilisearch.com/reference/api/tasks.html + */ +@Getter +public class TaskInfo { + protected String status = ""; + protected int taskUid = 0; + protected String indexUid = ""; + protected String type = null; + protected String duration = ""; + protected Date enqueuedAt = null; + protected Date startedAt = null; + protected Date finishedAt = null; + protected TaskError error = null; + protected TaskDetails details = null; + + public TaskInfo() {} +} diff --git a/src/main/java/com/meilisearch/sdk/model/TasksQuery.java b/src/main/java/com/meilisearch/sdk/model/TasksQuery.java new file mode 100644 index 00000000..0907b4b0 --- /dev/null +++ b/src/main/java/com/meilisearch/sdk/model/TasksQuery.java @@ -0,0 +1,23 @@ +package com.meilisearch.sdk.model; + +import lombok.Getter; +import lombok.Setter; +import lombok.experimental.Accessors; + +/** + * Data structure of a query parameter for tasks route + * + *

https://docs.meilisearch.com/reference/api/tasks.html#query-parameters + */ +@Setter +@Getter +@Accessors(chain = true) +public class TasksQuery { + private int limit = -1; + private int from = -1; + private String[] status; + private String[] type; + private String[] indexUid; + + public TasksQuery() {} +} diff --git a/src/main/java/com/meilisearch/sdk/model/TasksResults.java b/src/main/java/com/meilisearch/sdk/model/TasksResults.java new file mode 100644 index 00000000..5ee0b52e --- /dev/null +++ b/src/main/java/com/meilisearch/sdk/model/TasksResults.java @@ -0,0 +1,18 @@ +package com.meilisearch.sdk.model; + +import lombok.Getter; + +/** + * Data structure of Meilisearch response for tasks Results + * + *

https://docs.meilisearch.com/reference/api/tasks.html#response + */ +@Getter +public class TasksResults { + protected Task[] results = null; + protected int limit; + protected int from; + protected int next; + + public TasksResults() {} +} diff --git a/src/test/java/com/meilisearch/integration/ClientTest.java b/src/test/java/com/meilisearch/integration/ClientTest.java index 8c751baf..9deeeaf0 100644 --- a/src/test/java/com/meilisearch/integration/ClientTest.java +++ b/src/test/java/com/meilisearch/integration/ClientTest.java @@ -9,7 +9,7 @@ import com.meilisearch.integration.classes.TestData; import com.meilisearch.sdk.Index; import com.meilisearch.sdk.exceptions.MeilisearchApiException; -import com.meilisearch.sdk.model.Task; +import com.meilisearch.sdk.model.TaskInfo; import com.meilisearch.sdk.utils.Movie; import java.util.Arrays; import org.junit.jupiter.api.AfterAll; @@ -51,8 +51,8 @@ public void testCreateIndexWithoutPrimaryKey() throws Exception { @Test public void testCreateIndexWithoutPrimaryKeyWithJacksonJsonHandler() throws Exception { String indexUid = "CreateIndexWithoutPrimaryKeyWithJacksonJsonHandler"; - Task task = clientJackson.createIndex(indexUid); - clientJackson.waitForTask(task.getUid()); + TaskInfo task = clientJackson.createIndex(indexUid); + clientJackson.waitForTask(task.getTaskUid()); Index index = clientJackson.getIndex(indexUid); assertEquals(index.getUid(), indexUid); @@ -77,8 +77,8 @@ public void testCreateIndexWithPrimaryKey() throws Exception { @Test public void testCreateIndexWithPrimaryKeyWithJacksonJsonHandler() throws Exception { String indexUid = "CreateIndexWithPrimaryKeyWithJacksonJsonHandler"; - Task task = clientJackson.createIndex(indexUid, this.primaryKey); - clientJackson.waitForTask(task.getUid()); + TaskInfo task = clientJackson.createIndex(indexUid, this.primaryKey); + clientJackson.waitForTask(task.getTaskUid()); Index index = clientJackson.getIndex(indexUid); assertEquals(index.getUid(), indexUid); @@ -115,8 +115,8 @@ public void testUpdateIndexPrimaryKey() throws Exception { assertEquals(index.getUid(), indexUid); assertNull(index.getPrimaryKey()); - Task task = client.updateIndex(indexUid, this.primaryKey); - client.waitForTask(task.getUid()); + TaskInfo task = client.updateIndex(indexUid, this.primaryKey); + client.waitForTask(task.getTaskUid()); index = client.getIndex(indexUid); assertTrue(index instanceof Index); @@ -194,8 +194,8 @@ public void testGetRawIndexes() throws Exception { public void testDeleteIndex() throws Exception { String indexUid = "DeleteIndex"; Index index = createEmptyIndex(indexUid); - Task task = client.deleteIndex(index.getUid()); - client.waitForTask(task.getUid()); + TaskInfo task = client.deleteIndex(index.getUid()); + client.waitForTask(task.getTaskUid()); assertThrows(MeilisearchApiException.class, () -> client.getIndex(indexUid)); } diff --git a/src/test/java/com/meilisearch/integration/DocumentsTest.java b/src/test/java/com/meilisearch/integration/DocumentsTest.java index b46d9251..64bbe146 100644 --- a/src/test/java/com/meilisearch/integration/DocumentsTest.java +++ b/src/test/java/com/meilisearch/integration/DocumentsTest.java @@ -8,7 +8,7 @@ import com.meilisearch.integration.classes.TestData; import com.meilisearch.sdk.Index; import com.meilisearch.sdk.exceptions.MeilisearchApiException; -import com.meilisearch.sdk.model.Task; +import com.meilisearch.sdk.model.TaskInfo; import com.meilisearch.sdk.utils.Movie; import java.util.ArrayList; import java.util.Arrays; @@ -44,10 +44,9 @@ public void testAddDocumentsSingle() throws Exception { TestData testData = this.getTestData(MOVIES_INDEX, Movie.class); String singleDocument = this.gson.toJson(testData.getData().get(0)); - Task task = index.addDocuments("[" + singleDocument + "]"); + TaskInfo task = index.addDocuments("[" + singleDocument + "]"); - index.waitForTask(task.getUid()); - Movie[] movies = this.gson.fromJson(index.getDocuments(), Movie[].class); + index.waitForTask(task.getTaskUid()); assertEquals(1, movies.length); assertEquals("419704", movies[0].getId()); @@ -83,16 +82,16 @@ public void testAddDocumentsWithSuppliedPrimaryKey() throws Exception { String firstDocument = this.gson.toJson(firstMovie); String secondDocument = this.gson.toJson(secondMovie); - Task firstTask = index.addDocuments("[" + firstDocument + "]", "language"); - index.waitForTask(firstTask.getUid()); + TaskInfo firstTask = index.addDocuments("[" + firstDocument + "]", "language"); + index.waitForTask(firstTask.getTaskUid()); Movie[] movies = this.gson.fromJson(index.getDocuments(), Movie[].class); assertEquals(1, movies.length); assertEquals("419704", movies[0].getId()); assertEquals("Ad Astra", movies[0].getTitle()); - Task secondTask = index.addDocuments("[" + secondDocument + "]", "language"); - index.waitForTask(secondTask.getUid()); + TaskInfo secondTask = index.addDocuments("[" + secondDocument + "]", "language"); + index.waitForTask(secondTask.getTaskUid()); movies = this.gson.fromJson(index.getDocuments(), Movie[].class); assertEquals(1, movies.length); @@ -108,10 +107,9 @@ public void testAddDocumentsMultiple() throws Exception { Index index = client.index(indexUid); TestData testData = this.getTestData(MOVIES_INDEX, Movie.class); - Task task = index.addDocuments(testData.getRaw()); + TaskInfo task = index.addDocuments(testData.getRaw()); - index.waitForTask(task.getUid()); - Movie[] movies = this.gson.fromJson(index.getDocuments(), Movie[].class); + index.waitForTask(task.getTaskUid()); for (int i = 0; i < movies.length; i++) { Movie movie = this.gson.fromJson( @@ -128,10 +126,9 @@ public void testAddDocumentsMultipleWithJacksonJsonHandler() throws Exception { Index index = clientJackson.index(indexUid); TestData testData = this.getTestData(MOVIES_INDEX, Movie.class); - Task task = index.addDocuments(testData.getRaw()); + TaskInfo task = index.addDocuments(testData.getRaw()); - index.waitForTask(task.getUid()); - Movie[] movies = this.gson.fromJson(index.getDocuments(), Movie[].class); + index.waitForTask(task.getTaskUid()); for (int i = 0; i < movies.length; i++) { Movie movie = this.gson.fromJson( @@ -147,13 +144,13 @@ public void testAddDocumentsInBatches() throws Exception { Index index = client.index(indexUid); TestData testData = this.getTestData(MOVIES_INDEX, Movie.class); - Task[] taskArr = index.addDocumentsInBatches(testData.getRaw()); + TaskInfo[] taskArr = index.addDocumentsInBatches(testData.getRaw()); - for (Task task : taskArr) { - index.waitForTask(task.getUid()); + for (TaskInfo task : taskArr) { + index.waitForTask(task.getTaskUid()); - assertTrue(task instanceof Task); - assertEquals(task.getType(), "documentAddition"); + assertTrue(task instanceof TaskInfo); + assertEquals("documentAdditionOrUpdate", task.getType()); assertNotNull(task.getEnqueuedAt()); } } @@ -165,13 +162,13 @@ public void testAddDocumentsInBatchesWithBatchSize() throws Exception { Index index = client.index(indexUid); TestData testData = this.getTestData(MOVIES_INDEX, Movie.class); - Task[] taskArr = index.addDocumentsInBatches(testData.getRaw(), 15, null); + TaskInfo[] taskArr = index.addDocumentsInBatches(testData.getRaw(), 15, null); - for (Task task : taskArr) { - index.waitForTask(task.getUid()); + for (TaskInfo task : taskArr) { + index.waitForTask(task.getTaskUid()); - assertTrue(task instanceof Task); - assertEquals(task.getType(), "documentAddition"); + assertTrue(task instanceof TaskInfo); + assertEquals("documentAdditionOrUpdate", task.getType()); assertNotNull(task.getEnqueuedAt()); } } @@ -184,24 +181,23 @@ public void testUpdateDocument() throws Exception { Index index = createEmptyIndex(indexUid); TestData testData = this.getTestData(MOVIES_INDEX, Movie.class); - Task task = index.addDocuments(testData.getRaw()); + TaskInfo task = index.addDocuments(testData.getRaw()); - index.waitForTask(task.getUid()); - Movie[] movies = this.gson.fromJson(index.getDocuments(), Movie[].class); + index.waitForTask(task.getTaskUid()); Movie toUpdate = movies[0]; toUpdate.setTitle("The Perks of Being a Wallflower"); toUpdate.setOverview("The best movie I've ever seen"); task = index.updateDocuments("[" + this.gson.toJson(toUpdate) + "]"); - index.waitForTask(task.getUid()); + index.waitForTask(task.getTaskUid()); Movie responseUpdate = this.gson.fromJson(index.getDocument(toUpdate.getId()), Movie.class); assertEquals(toUpdate.getTitle(), responseUpdate.getTitle()); assertEquals(toUpdate.getOverview(), responseUpdate.getOverview()); } - /** Test update Documents with primaryKey */ + /** Test Update Documents with primaryKey */ @Test public void testUpdateDocumentsWithSuppliedPrimaryKey() throws Exception { @@ -220,18 +216,18 @@ public void testUpdateDocumentsWithSuppliedPrimaryKey() throws Exception { secondJson.remove("title"); String secondDocument = this.gson.toJson(secondJson); - Task firstTask = index.updateDocuments("[" + firstDocument + "]", "language"); - index.waitForTask(firstTask.getUid()); + TaskInfo firstTask = index.updateDocuments("[" + firstDocument + "]", "language"); + index.waitForTask(firstTask.getTaskUid()); Movie[] movies = this.gson.fromJson(index.getDocuments(), Movie[].class); assertEquals(1, movies.length); assertEquals("419704", movies[0].getId()); assertEquals("Ad Astra", movies[0].getTitle()); - Task secondTask = index.updateDocuments("[" + secondDocument + "]", "language"); - index.waitForTask(secondTask.getUid()); + TaskInfo secondTask = index.updateDocuments("[" + secondDocument + "]", "language"); + index.waitForTask(secondTask.getTaskUid()); - movies = this.gson.fromJson(index.getDocuments(), Movie[].class); + movies = (Movie[]) index.getDocuments(Movie.class).getResults(); assertEquals(1, movies.length); assertEquals("574982", movies[0].getId()); // Second movie id assertEquals("Ad Astra", movies[0].getTitle()); // First movie title @@ -244,10 +240,9 @@ public void testUpdateDocuments() throws Exception { Index index = createEmptyIndex(indexUid); TestData testData = this.getTestData(MOVIES_INDEX, Movie.class); - Task task = index.addDocuments(testData.getRaw()); + TaskInfo task = index.addDocuments(testData.getRaw()); - index.waitForTask(task.getUid()); - Movie[] movies = this.gson.fromJson(index.getDocuments(), Movie[].class); + index.waitForTask(task.getTaskUid()); List toUpdate = new ArrayList<>(); for (int i = 0; i < 5; i++) { movies[i].setTitle("Star wars episode: " + i); @@ -257,7 +252,7 @@ public void testUpdateDocuments() throws Exception { task = index.updateDocuments(this.gson.toJson(toUpdate)); - index.waitForTask(task.getUid()); + index.waitForTask(task.getTaskUid()); for (int j = 0; j < 5; j++) { Movie responseUpdate = this.gson.fromJson(index.getDocument(toUpdate.get(j).getId()), Movie.class); @@ -274,21 +269,20 @@ public void testUpdateDocumentsInBatchesWithBatchSize() throws Exception { Index index = createEmptyIndex(indexUid); TestData testData = this.getTestData(MOVIES_INDEX, Movie.class); - Task taskIndex = index.addDocuments(testData.getRaw()); + TaskInfo taskIndex = index.addDocuments(testData.getRaw()); - index.waitForTask(taskIndex.getUid()); - Movie[] movies = this.gson.fromJson(index.getDocuments(), Movie[].class); + index.waitForTask(taskIndex.getTaskUid()); List toUpdate = new ArrayList<>(); for (int i = 0; i < 5; i++) { movies[i].setTitle("Star wars episode: " + i); movies[i].setOverview("This star wars movie is for the episode: " + i); toUpdate.add(movies[i]); } - Task[] taskArr = index.updateDocumentsInBatches(this.gson.toJson(toUpdate), 2, null); + TaskInfo[] taskArr = index.updateDocumentsInBatches(this.gson.toJson(toUpdate), 2, null); - for (Task task : taskArr) { - index.waitForTask(task.getUid()); - assertEquals(task.getType(), "documentPartial"); + for (TaskInfo task : taskArr) { + index.waitForTask(task.getTaskUid()); + assertEquals(task.getType(), "documentAdditionOrUpdate"); assertNotNull(task.getEnqueuedAt()); } } @@ -301,21 +295,20 @@ public void testUpdateDocumentsInBatches() throws Exception { Index index = createEmptyIndex(indexUid); TestData testData = this.getTestData(MOVIES_INDEX, Movie.class); - Task taskIndex = index.addDocuments(testData.getRaw()); + TaskInfo taskIndex = index.addDocuments(testData.getRaw()); - index.waitForTask(taskIndex.getUid()); - Movie[] movies = this.gson.fromJson(index.getDocuments(), Movie[].class); + index.waitForTask(taskIndex.getTaskUid()); List toUpdate = new ArrayList<>(); for (int i = 0; i < 5; i++) { movies[i].setTitle("Star wars episode: " + i); movies[i].setOverview("This star wars movie is for the episode: " + i); toUpdate.add(movies[i]); } - Task[] taskArr = index.updateDocumentsInBatches(this.gson.toJson(toUpdate)); + TaskInfo[] taskArr = index.updateDocumentsInBatches(this.gson.toJson(toUpdate)); - for (Task task : taskArr) { - index.waitForTask(task.getUid()); - assertEquals(task.getType(), "documentPartial"); + for (TaskInfo task : taskArr) { + index.waitForTask(task.getTaskUid()); + assertEquals(task.getType(), "documentAdditionOrUpdate"); assertNotNull(task.getEnqueuedAt()); } } @@ -328,9 +321,9 @@ public void testGetDocument() throws Exception { Index index = client.index(indexUid); TestData testData = this.getTestData(MOVIES_INDEX, Movie.class); - Task task = index.addDocuments(testData.getRaw()); + TaskInfo task = index.addDocuments(testData.getRaw()); - index.waitForTask(task.getUid()); + index.waitForTask(task.getTaskUid()); Movie movie = this.gson.fromJson( index.getDocument(testData.getData().get(0).getId()), Movie.class); @@ -345,10 +338,9 @@ public void testGetDocuments() throws Exception { Index index = client.index(indexUid); TestData testData = this.getTestData(MOVIES_INDEX, Movie.class); - Task task = index.addDocuments(testData.getRaw()); + TaskInfo task = index.addDocuments(testData.getRaw()); - index.waitForTask(task.getUid()); - Movie[] movies = this.gson.fromJson(index.getDocuments(), Movie[].class); + index.waitForTask(task.getTaskUid()); assertEquals(20, movies.length); for (int i = 0; i < movies.length; i++) { Movie movie = @@ -372,10 +364,9 @@ public void testGetDocumentsLimit() throws Exception { Index index = client.index(indexUid); TestData testData = this.getTestData(MOVIES_INDEX, Movie.class); - Task task = index.addDocuments(testData.getRaw()); + TaskInfo task = index.addDocuments(testData.getRaw()); - index.waitForTask(task.getUid()); - Movie[] movies = this.gson.fromJson(index.getDocuments(limit), Movie[].class); + index.waitForTask(task.getTaskUid()); assertEquals(limit, movies.length); for (int i = 0; i < movies.length; i++) { Movie movie = @@ -388,19 +379,16 @@ public void testGetDocumentsLimit() throws Exception { /** Test GetDocuments with limit and offset */ @Test public void testGetDocumentsLimitAndOffset() throws Exception { - String indexUid = "GetDocumentsLimit"; + String indexUid = "GetDocumentsLimitAndOffset"; int limit = 2; int offset = 2; int secondOffset = 5; Index index = client.index(indexUid); TestData testData = this.getTestData(MOVIES_INDEX, Movie.class); - Task task = index.addDocuments(testData.getRaw()); + TaskInfo task = index.addDocuments(testData.getRaw()); - index.waitForTask(task.getUid()); - Movie[] movies = this.gson.fromJson(index.getDocuments(limit, offset), Movie[].class); - Movie[] secondMovies = - this.gson.fromJson(index.getDocuments(limit, secondOffset), Movie[].class); + index.waitForTask(task.getTaskUid()); assertEquals(limit, movies.length); assertEquals(limit, secondMovies.length); @@ -409,7 +397,7 @@ public void testGetDocumentsLimitAndOffset() throws Exception { assertNotEquals(movies[1].getTitle(), secondMovies[1].getTitle()); } - /** Test GetDocuments with limit, offset and specified attributesToRetrieve */ + /** Test GetDocuments with limit, offset and specified fields */ @Test public void testGetDocumentsLimitAndOffsetAndSpecifiedAttributesToRetrieve() throws Exception { String indexUid = "GetDocumentsLimit"; @@ -419,12 +407,9 @@ public void testGetDocumentsLimitAndOffsetAndSpecifiedAttributesToRetrieve() thr Index index = client.index(indexUid); TestData testData = this.getTestData(MOVIES_INDEX, Movie.class); - Task task = index.addDocuments(testData.getRaw()); + TaskInfo task = index.addDocuments(testData.getRaw()); - index.waitForTask(task.getUid()); - Movie[] movies = - this.gson.fromJson( - index.getDocuments(limit, offset, attributesToRetrieve), Movie[].class); + index.waitForTask(task.getTaskUid()); assertEquals(limit, movies.length); @@ -479,13 +464,13 @@ public void testDeleteDocument() throws Exception { Index index = client.index(indexUid); TestData testData = this.getTestData(MOVIES_INDEX, Movie.class); - Task task = index.addDocuments(testData.getRaw()); - index.waitForTask(task.getUid()); + TaskInfo task = index.addDocuments(testData.getRaw()); + index.waitForTask(task.getTaskUid()); Movie[] movies = this.gson.fromJson(index.getDocuments(), Movie[].class); Movie toDelete = movies[0]; task = index.deleteDocument(toDelete.getId()); - index.waitForTask(task.getUid()); + index.waitForTask(task.getTaskUid()); assertThrows(MeilisearchApiException.class, () -> index.getDocument(toDelete.getId())); } @@ -498,8 +483,8 @@ public void testDeleteDocuments() throws Exception { Index index = client.index(indexUid); TestData testData = this.getTestData(MOVIES_INDEX, Movie.class); - Task task = index.addDocuments(testData.getRaw()); - index.waitForTask(task.getUid()); + TaskInfo task = index.addDocuments(testData.getRaw()); + index.waitForTask(task.getTaskUid()); Movie[] movies = this.gson.fromJson(index.getDocuments(), Movie[].class); assertEquals(20, movies.length); @@ -507,7 +492,7 @@ public void testDeleteDocuments() throws Exception { List identifiersToDelete = getIdentifiersToDelete(movies); task = index.deleteDocuments(identifiersToDelete); - index.waitForTask(task.getUid()); + index.waitForTask(task.getTaskUid()); movies = this.gson.fromJson(index.getDocuments(), Movie[].class); @@ -531,17 +516,17 @@ public void testDeleteAllDocuments() throws Exception { Index index = client.index(indexUid); TestData testData = this.getTestData(MOVIES_INDEX, Movie.class); - Task taskIndex = index.addDocuments(testData.getRaw()); - index.waitForTask(taskIndex.getUid()); + TaskInfo taskIndex = index.addDocuments(testData.getRaw()); + index.waitForTask(taskIndex.getTaskUid()); Movie[] movies = this.gson.fromJson(index.getDocuments(), Movie[].class); assertEquals(20, movies.length); - Task task = index.deleteAllDocuments(); - index.waitForTask(task.getUid()); + TaskInfo task = index.deleteAllDocuments(); + index.waitForTask(task.getTaskUid()); - assertTrue(task instanceof Task); - assertEquals(task.getType(), "clearAll"); + assertTrue(task instanceof TaskInfo); + assertEquals(task.getType(), "documentDeletion"); assertNotNull(task.getEnqueuedAt()); movies = this.gson.fromJson(index.getDocuments(), Movie[].class); diff --git a/src/test/java/com/meilisearch/integration/InstanceTest.java b/src/test/java/com/meilisearch/integration/InstanceTest.java index 1e557481..b4c84419 100644 --- a/src/test/java/com/meilisearch/integration/InstanceTest.java +++ b/src/test/java/com/meilisearch/integration/InstanceTest.java @@ -6,7 +6,7 @@ import com.meilisearch.sdk.Index; import com.meilisearch.sdk.model.IndexStats; import com.meilisearch.sdk.model.Stats; -import com.meilisearch.sdk.model.Task; +import com.meilisearch.sdk.model.TaskInfo; import org.junit.jupiter.api.AfterAll; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Tag; @@ -64,9 +64,9 @@ public void testGetStats() throws Exception { public void testGetIndexStats() throws Exception { String indexUid = "IndexStats"; Index index = client.index(indexUid); - Task task = client.createIndex(indexUid); + TaskInfo task = client.createIndex(indexUid); - client.waitForTask(task.getUid()); + client.waitForTask(task.getTaskUid()); IndexStats stats = index.getStats(); assertNotNull(stats); diff --git a/src/test/java/com/meilisearch/integration/SearchNestedTest.java b/src/test/java/com/meilisearch/integration/SearchNestedTest.java index 511ab303..0b9bcccf 100644 --- a/src/test/java/com/meilisearch/integration/SearchNestedTest.java +++ b/src/test/java/com/meilisearch/integration/SearchNestedTest.java @@ -8,7 +8,7 @@ import com.meilisearch.sdk.SearchRequest; import com.meilisearch.sdk.json.GsonJsonHandler; import com.meilisearch.sdk.model.Settings; -import com.meilisearch.sdk.model.Task; +import com.meilisearch.sdk.model.TaskInfo; import com.meilisearch.sdk.utils.Movie; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Tag; @@ -43,8 +43,8 @@ public void testBasicSearchInNestedFields() throws Exception { GsonJsonHandler jsonGson = new GsonJsonHandler(); TestData testData = this.getTestData(NESTED_MOVIES, Movie.class); - Task task = index.addDocuments(testData.getRaw()); - index.waitForTask(task.getUid()); + TaskInfo task = index.addDocuments(testData.getRaw()); + index.waitForTask(task.getTaskUid()); Results searchResultGson = jsonGson.decode(index.rawSearch("An awesome"), Results.class); assertEquals(1, searchResultGson.hits.length); @@ -60,12 +60,12 @@ public void testSearchOnNestedFieldsWithSearchableAttributes() throws Exception String[] newSearchableAttributes = {"title", "info.comment"}; TestData testData = this.getTestData(NESTED_MOVIES, Movie.class); - Task task = index.addDocuments(testData.getRaw()); + TaskInfo task = index.addDocuments(testData.getRaw()); - index.waitForTask(task.getUid()); + index.waitForTask(task.getTaskUid()); index.waitForTask( - index.updateSearchableAttributesSettings(newSearchableAttributes).getUid()); + index.updateSearchableAttributesSettings(newSearchableAttributes).getTaskUid()); Results searchResultGson = jsonGson.decode(index.rawSearch("An awesome"), Results.class); @@ -83,9 +83,9 @@ public void testSearchOnNestedFieldsWithSortableAttributes() throws Exception { newSettings.setSortableAttributes(new String[] {"info.reviewNb"}); TestData testData = this.getTestData(NESTED_MOVIES, Movie.class); - Task task = index.addDocuments(testData.getRaw()); - index.waitForTask(task.getUid()); - index.waitForTask(index.updateSettings(newSettings).getUid()); + TaskInfo task = index.addDocuments(testData.getRaw()); + index.waitForTask(task.getTaskUid()); + index.waitForTask(index.updateSettings(newSettings).getTaskUid()); SearchRequest searchRequest = new SearchRequest("An Awesome").setSort(new String[] {"info.reviewNb:desc"}); @@ -106,9 +106,9 @@ public void testSearchOnNestedFieldsWithSortableAndSearchableAttributes() throws newSettings.setSortableAttributes(new String[] {"info.reviewNb"}); TestData testData = this.getTestData(NESTED_MOVIES, Movie.class); - Task task = index.addDocuments(testData.getRaw()); - index.waitForTask(task.getUid()); - index.waitForTask(index.updateSettings(newSettings).getUid()); + TaskInfo task = index.addDocuments(testData.getRaw()); + index.waitForTask(task.getTaskUid()); + index.waitForTask(index.updateSettings(newSettings).getTaskUid()); SearchRequest searchRequest = new SearchRequest("An Awesome").setSort(new String[] {"info.reviewNb:desc"}); Results searchResultGson = jsonGson.decode(index.rawSearch(searchRequest), Results.class); diff --git a/src/test/java/com/meilisearch/integration/SearchTest.java b/src/test/java/com/meilisearch/integration/SearchTest.java index 4c5beb37..6ef50659 100644 --- a/src/test/java/com/meilisearch/integration/SearchTest.java +++ b/src/test/java/com/meilisearch/integration/SearchTest.java @@ -11,7 +11,7 @@ import com.meilisearch.sdk.json.GsonJsonHandler; import com.meilisearch.sdk.model.SearchResult; import com.meilisearch.sdk.model.Settings; -import com.meilisearch.sdk.model.Task; +import com.meilisearch.sdk.model.TaskInfo; import com.meilisearch.sdk.utils.Movie; import org.junit.jupiter.api.AfterAll; import org.junit.jupiter.api.BeforeEach; @@ -52,9 +52,9 @@ public void testBasicSearch() throws Exception { Index index = client.index(indexUid); TestData testData = this.getTestData(MOVIES_INDEX, Movie.class); - Task task = index.addDocuments(testData.getRaw()); + TaskInfo task = index.addDocuments(testData.getRaw()); - index.waitForTask(task.getUid()); + index.waitForTask(task.getTaskUid()); SearchResult searchResult = index.search("batman"); @@ -72,9 +72,9 @@ public void testSearchOffset() throws Exception { Index index = client.index(indexUid); TestData testData = this.getTestData(MOVIES_INDEX, Movie.class); - Task task = index.addDocuments(testData.getRaw()); + TaskInfo task = index.addDocuments(testData.getRaw()); - index.waitForTask(task.getUid()); + index.waitForTask(task.getTaskUid()); SearchRequest searchRequest = new SearchRequest("a").setOffset(20); SearchResult searchResult = index.search(searchRequest); @@ -90,9 +90,9 @@ public void testSearchLimit() throws Exception { Index index = client.index(indexUid); TestData testData = this.getTestData(MOVIES_INDEX, Movie.class); - Task task = index.addDocuments(testData.getRaw()); + TaskInfo task = index.addDocuments(testData.getRaw()); - index.waitForTask(task.getUid()); + index.waitForTask(task.getTaskUid()); SearchRequest searchRequest = new SearchRequest("a").setLimit(2); SearchResult searchResult = index.search(searchRequest); @@ -109,9 +109,9 @@ public void testRawSearchAttributesToRetrieve() throws Exception { GsonJsonHandler jsonGson = new GsonJsonHandler(); TestData testData = this.getTestData(MOVIES_INDEX, Movie.class); - Task task = index.addDocuments(testData.getRaw()); + TaskInfo task = index.addDocuments(testData.getRaw()); - index.waitForTask(task.getUid()); + index.waitForTask(task.getTaskUid()); SearchRequest searchRequest = new SearchRequest("a").setAttributesToRetrieve(new String[] {"id", "title"}); @@ -136,9 +136,9 @@ public void testSearchCrop() throws Exception { GsonJsonHandler jsonGson = new GsonJsonHandler(); TestData testData = this.getTestData(MOVIES_INDEX, Movie.class); - Task task = index.addDocuments(testData.getRaw()); + TaskInfo task = index.addDocuments(testData.getRaw()); - index.waitForTask(task.getUid()); + index.waitForTask(task.getTaskUid()); SearchRequest searchRequest = new SearchRequest("and") @@ -160,9 +160,9 @@ public void testSearchCropMarker() throws Exception { GsonJsonHandler jsonGson = new GsonJsonHandler(); TestData testData = this.getTestData(MOVIES_INDEX, Movie.class); - Task task = index.addDocuments(testData.getRaw()); + TaskInfo task = index.addDocuments(testData.getRaw()); - index.waitForTask(task.getUid()); + index.waitForTask(task.getTaskUid()); SearchRequest searchRequest = new SearchRequest("and") @@ -184,9 +184,9 @@ public void testSearchHighlight() throws Exception { GsonJsonHandler jsonGson = new GsonJsonHandler(); TestData testData = this.getTestData(MOVIES_INDEX, Movie.class); - Task task = index.addDocuments(testData.getRaw()); + TaskInfo task = index.addDocuments(testData.getRaw()); - index.waitForTask(task.getUid()); + index.waitForTask(task.getTaskUid()); SearchRequest searchRequest = new SearchRequest("and").setAttributesToHighlight(new String[] {"title"}); @@ -207,9 +207,9 @@ public void testSearchWithCustomizedHighlight() throws Exception { GsonJsonHandler jsonGson = new GsonJsonHandler(); TestData testData = this.getTestData(MOVIES_INDEX, Movie.class); - Task task = index.addDocuments(testData.getRaw()); + TaskInfo task = index.addDocuments(testData.getRaw()); - index.waitForTask(task.getUid()); + index.waitForTask(task.getTaskUid()); SearchRequest searchRequest = new SearchRequest("and") @@ -233,9 +233,9 @@ public void testSearchPhrase() throws Exception { GsonJsonHandler jsonGson = new GsonJsonHandler(); TestData testData = this.getTestData(MOVIES_INDEX, Movie.class); - Task task = index.addDocuments(testData.getRaw()); + TaskInfo task = index.addDocuments(testData.getRaw()); - index.waitForTask(task.getUid()); + index.waitForTask(task.getTaskUid()); Results resGson = jsonGson.decode(index.rawSearch("coco \"harry\""), Results.class); @@ -252,14 +252,14 @@ public void testRawSearchFilter() throws Exception { GsonJsonHandler jsonGson = new GsonJsonHandler(); TestData testData = this.getTestData(MOVIES_INDEX, Movie.class); - Task task = index.addDocuments(testData.getRaw()); + TaskInfo task = index.addDocuments(testData.getRaw()); - index.waitForTask(task.getUid()); + index.waitForTask(task.getTaskUid()); Settings settings = index.getSettings(); settings.setFilterableAttributes(new String[] {"title"}); - index.waitForTask(index.updateSettings(settings).getUid()); + index.waitForTask(index.updateSettings(settings).getTaskUid()); SearchRequest searchRequest = new SearchRequest("and").setFilter(new String[] {"title = \"The Dark Knight\""}); @@ -279,14 +279,14 @@ public void testRawSearchFilterComplex() throws Exception { GsonJsonHandler jsonGson = new GsonJsonHandler(); TestData testData = this.getTestData(MOVIES_INDEX, Movie.class); - Task task = index.addDocuments(testData.getRaw()); + TaskInfo task = index.addDocuments(testData.getRaw()); - index.waitForTask(task.getUid()); + index.waitForTask(task.getTaskUid()); Settings settings = index.getSettings(); settings.setFilterableAttributes(new String[] {"title", "id"}); - index.waitForTask(index.updateSettings(settings).getUid()); + index.waitForTask(index.updateSettings(settings).getTaskUid()); SearchRequest searchRequest = new SearchRequest("and") @@ -306,14 +306,14 @@ public void testSearchFacetsDistribution() throws Exception { Index index = client.index(indexUid); TestData testData = this.getTestData(MOVIES_INDEX, Movie.class); - Task task = index.addDocuments(testData.getRaw()); + TaskInfo task = index.addDocuments(testData.getRaw()); - index.waitForTask(task.getUid()); + index.waitForTask(task.getTaskUid()); Settings settings = index.getSettings(); settings.setFilterableAttributes(new String[] {"title"}); - index.waitForTask(index.updateSettings(settings).getUid()); + index.waitForTask(index.updateSettings(settings).getTaskUid()); SearchRequest searchRequest = new SearchRequest("knight").setFacets(new String[] {"*"}); @@ -331,14 +331,14 @@ public void testRawSearchSort() throws Exception { GsonJsonHandler jsonGson = new GsonJsonHandler(); TestData testData = this.getTestData(MOVIES_INDEX, Movie.class); - Task task = index.addDocuments(testData.getRaw()); + TaskInfo task = index.addDocuments(testData.getRaw()); - index.waitForTask(task.getUid()); + index.waitForTask(task.getTaskUid()); Settings settings = index.getSettings(); settings.setSortableAttributes(new String[] {"title"}); - index.waitForTask(index.updateSettings(settings).getUid()); + index.waitForTask(index.updateSettings(settings).getTaskUid()); SearchRequest searchRequest = new SearchRequest("and").setSort(new String[] {"title:asc"}); @@ -361,14 +361,14 @@ public void testRawSearchSortWithIntParameter() throws Exception { GsonJsonHandler jsonGson = new GsonJsonHandler(); TestData testData = this.getTestData(MOVIES_INDEX, Movie.class); - Task task = index.addDocuments(testData.getRaw()); + TaskInfo task = index.addDocuments(testData.getRaw()); - index.waitForTask(task.getUid()); + index.waitForTask(task.getTaskUid()); Settings settings = index.getSettings(); settings.setSortableAttributes(new String[] {"id"}); - index.waitForTask(index.updateSettings(settings).getUid()); + index.waitForTask(index.updateSettings(settings).getTaskUid()); SearchRequest searchRequest = new SearchRequest("and").setSort(new String[] {"id:asc"}); @@ -391,14 +391,14 @@ public void testRawSearchSortWithMultipleParameter() throws Exception { GsonJsonHandler jsonGson = new GsonJsonHandler(); TestData testData = this.getTestData(MOVIES_INDEX, Movie.class); - Task task = index.addDocuments(testData.getRaw()); + TaskInfo task = index.addDocuments(testData.getRaw()); - index.waitForTask(task.getUid()); + index.waitForTask(task.getTaskUid()); Settings settings = index.getSettings(); settings.setSortableAttributes(new String[] {"id", "title"}); - index.waitForTask(index.updateSettings(settings).getUid()); + index.waitForTask(index.updateSettings(settings).getTaskUid()); SearchRequest searchRequest = new SearchRequest("dark").setSort(new String[] {"id:asc", "title:asc"}); @@ -420,14 +420,14 @@ public void testRawSearchSortWithPlaceHolder() throws Exception { GsonJsonHandler jsonGson = new GsonJsonHandler(); TestData testData = this.getTestData(MOVIES_INDEX, Movie.class); - Task task = index.addDocuments(testData.getRaw()); + TaskInfo task = index.addDocuments(testData.getRaw()); - index.waitForTask(task.getUid()); + index.waitForTask(task.getTaskUid()); Settings settings = index.getSettings(); settings.setSortableAttributes(new String[] {"id", "title"}); - index.waitForTask(index.updateSettings(settings).getUid()); + index.waitForTask(index.updateSettings(settings).getTaskUid()); SearchRequest searchRequest = new SearchRequest("").setSort(new String[] {"id:asc", "title:asc"}); @@ -448,9 +448,9 @@ public void testSearchMatches() throws Exception { Index index = client.index(indexUid); TestData testData = this.getTestData(MOVIES_INDEX, Movie.class); - Task task = index.addDocuments(testData.getRaw()); + TaskInfo task = index.addDocuments(testData.getRaw()); - index.waitForTask(task.getUid()); + index.waitForTask(task.getTaskUid()); SearchRequest searchRequest = new SearchRequest("and").setShowMatchesPosition(true); SearchResult searchResult = index.search(searchRequest); @@ -464,9 +464,9 @@ public void testPlaceHolder() throws Exception { Index index = client.index(indexUid); TestData testData = this.getTestData(MOVIES_INDEX, Movie.class); - Task task = index.addDocuments(testData.getRaw()); + TaskInfo task = index.addDocuments(testData.getRaw()); - index.waitForTask(task.getUid()); + index.waitForTask(task.getTaskUid()); SearchResult result = index.search(""); assertEquals(20, result.getLimit()); @@ -479,9 +479,9 @@ public void testPlaceHolderWithLimit() throws Exception { Index index = client.index(indexUid); TestData testData = this.getTestData(MOVIES_INDEX, Movie.class); - Task task = index.addDocuments(testData.getRaw()); + TaskInfo task = index.addDocuments(testData.getRaw()); - index.waitForTask(task.getUid()); + index.waitForTask(task.getTaskUid()); SearchResult searchResult = index.search(new SearchRequest(null).setLimit(10)); assertEquals(10, searchResult.getHits().size()); diff --git a/src/test/java/com/meilisearch/integration/SettingsTest.java b/src/test/java/com/meilisearch/integration/SettingsTest.java index b2d3695a..35bd34cf 100644 --- a/src/test/java/com/meilisearch/integration/SettingsTest.java +++ b/src/test/java/com/meilisearch/integration/SettingsTest.java @@ -12,7 +12,7 @@ import com.meilisearch.integration.classes.TestData; import com.meilisearch.sdk.Index; import com.meilisearch.sdk.model.Settings; -import com.meilisearch.sdk.model.Task; +import com.meilisearch.sdk.model.TaskInfo; import com.meilisearch.sdk.model.TypoTolerance; import com.meilisearch.sdk.utils.Movie; import java.util.Arrays; @@ -66,7 +66,7 @@ public void testUpdateSettingsRankingRules() throws Exception { "release_date:desc", "rank:desc" }); - index.waitForTask(index.updateSettings(settings).getUid()); + index.waitForTask(index.updateSettings(settings).getTaskUid()); Settings newSettings = index.getSettings(); assertEquals(8, newSettings.getRankingRules().length); } @@ -82,7 +82,7 @@ public void testUpdateSettingsSynonyms() throws Exception { synonyms.put("logan", new String[] {"wolverine"}); settings.setSynonyms(synonyms); - index.waitForTask(index.updateSettings(settings).getUid()); + index.waitForTask(index.updateSettings(settings).getTaskUid()); Settings newSettings = index.getSettings(); @@ -96,7 +96,7 @@ public void testUpdateSettingsSort() throws Exception { Settings settings = index.getSettings(); settings.setSortableAttributes(new String[] {"title", "year"}); - index.waitForTask(index.updateSettings(settings).getUid()); + index.waitForTask(index.updateSettings(settings).getTaskUid()); Settings newSettings = index.getSettings(); @@ -114,7 +114,7 @@ public void testUpdateSettingsTypoTolerance() throws Exception { typoTolerance.setDisableOnAttributes(new String[] {"title"}); settings.setTypoTolerance(typoTolerance); - index.waitForTask(index.updateSettings(settings).getUid()); + index.waitForTask(index.updateSettings(settings).getTaskUid()); Settings newSettings = index.getSettings(); @@ -130,7 +130,7 @@ public void testUpdateMultipleSettingsInARow() throws Exception { Settings settingsDisplayedAttr = new Settings(); settingsDisplayedAttr.setDisplayedAttributes( new String[] {"title", "overview", "genres", "release_date"}); - index.waitForTask(index.updateSettings(settingsDisplayedAttr).getUid()); + index.waitForTask(index.updateSettings(settingsDisplayedAttr).getTaskUid()); Settings newSettingsDisplayedAttr = index.getSettings(); Settings settingsRankingRules = new Settings(); @@ -145,7 +145,7 @@ public void testUpdateMultipleSettingsInARow() throws Exception { "release_date:desc", "rank:desc" }); - index.waitForTask(index.updateSettings(settingsRankingRules).getUid()); + index.waitForTask(index.updateSettings(settingsRankingRules).getTaskUid()); Settings newSettingsRankingRules = index.getSettings(); Settings settingsSynonyms = new Settings(); @@ -153,7 +153,7 @@ public void testUpdateMultipleSettingsInARow() throws Exception { synonyms.put("wolverine", new String[] {"xmen", "logan"}); synonyms.put("logan", new String[] {"wolverine"}); settingsSynonyms.setSynonyms(synonyms); - index.waitForTask(index.updateSettings(settingsSynonyms).getUid()); + index.waitForTask(index.updateSettings(settingsSynonyms).getTaskUid()); Settings newSettingsSynonyms = index.getSettings(); assertEquals(4, newSettingsDisplayedAttr.getDisplayedAttributes().length); @@ -179,11 +179,11 @@ public void testResetSettings() throws Exception { synonyms.put("logan", new String[] {"wolverine"}); settingsWithSynonyms.setSynonyms(synonyms); - index.waitForTask(index.updateSettings(settingsWithSynonyms).getUid()); + index.waitForTask(index.updateSettings(settingsWithSynonyms).getTaskUid()); settingsWithSynonyms = index.getSettings(); assertEquals(2, settingsWithSynonyms.getSynonyms().size()); - index.waitForTask(index.resetSettings().getUid()); + index.waitForTask(index.resetSettings().getTaskUid()); Settings settingsAfterReset = index.getSettings(); assertEquals(initialSettings.getSynonyms().size(), settingsAfterReset.getSynonyms().size()); } @@ -216,7 +216,7 @@ public void testUpdateRankingRuleSettings() throws Exception { "rank:desc" }; - index.waitForTask(index.updateRankingRuleSettings(newRankingRules).getUid()); + index.waitForTask(index.updateRankingRuleSettings(newRankingRules).getTaskUid()); String[] updatedRankingRuleSettings = index.getRankingRuleSettings(); assertEquals(newRankingRules.length, updatedRankingRuleSettings.length); @@ -240,10 +240,10 @@ public void testResetRankingRuleSettings() throws Exception { "rank:desc" }; - index.waitForTask(index.updateRankingRuleSettings(newRankingRules).getUid()); + index.waitForTask(index.updateRankingRuleSettings(newRankingRules).getTaskUid()); String[] updatedRankingRuleSettings = index.getRankingRuleSettings(); - index.waitForTask(index.resetRankingRuleSettings().getUid()); + index.waitForTask(index.resetRankingRuleSettings().getTaskUid()); String[] rankingRulesAfterReset = index.getRankingRuleSettings(); assertEquals(newRankingRules.length, updatedRankingRuleSettings.length); @@ -277,7 +277,7 @@ public void testUpdateSynonymsSettings() throws Exception { newSynonymsSettings.put("logan", new String[] {"wolverine", "xmen"}); newSynonymsSettings.put("wow", new String[] {"world of warcraft"}); - index.waitForTask(index.updateSynonymsSettings(newSynonymsSettings).getUid()); + index.waitForTask(index.updateSynonymsSettings(newSynonymsSettings).getTaskUid()); Map updatedSynonymsSettings = index.getSynonymsSettings(); assertEquals(newSynonymsSettings.size(), updatedSynonymsSettings.size()); @@ -296,10 +296,10 @@ public void testResetSynonymsSettings() throws Exception { newSynonymsSettings.put("logan", new String[] {"wolverine", "xmen"}); newSynonymsSettings.put("wow", new String[] {"world of warcraft"}); - index.waitForTask(index.updateSynonymsSettings(newSynonymsSettings).getUid()); + index.waitForTask(index.updateSynonymsSettings(newSynonymsSettings).getTaskUid()); Map updatedSynonymsSettings = index.getSynonymsSettings(); - index.waitForTask(index.resetSynonymsSettings().getUid()); + index.waitForTask(index.resetSynonymsSettings().getTaskUid()); Map synonymsSettingsAfterReset = index.getSynonymsSettings(); assertEquals(newSynonymsSettings.size(), updatedSynonymsSettings.size()); @@ -331,7 +331,7 @@ public void testUpdateStopWordsSettings() throws Exception { String[] initialStopWords = index.getStopWordsSettings(); String[] newStopWords = {"of", "the", "to"}; - index.waitForTask(index.updateStopWordsSettings(newStopWords).getUid()); + index.waitForTask(index.updateStopWordsSettings(newStopWords).getTaskUid()); String[] updatedStopWordsSettings = index.getStopWordsSettings(); assertEquals(newStopWords.length, updatedStopWordsSettings.length); @@ -346,10 +346,10 @@ public void testResetStopWordsSettings() throws Exception { String[] initialStopWords = index.getStopWordsSettings(); String[] newStopWords = {"of", "the", "to"}; - index.waitForTask(index.updateStopWordsSettings(newStopWords).getUid()); + index.waitForTask(index.updateStopWordsSettings(newStopWords).getTaskUid()); String[] updatedStopWordsSettings = index.getStopWordsSettings(); - index.waitForTask(index.resetStopWordsSettings().getUid()); + index.waitForTask(index.resetStopWordsSettings().getTaskUid()); String[] stopWordsAfterReset = index.getStopWordsSettings(); assertEquals(newStopWords.length, updatedStopWordsSettings.length); @@ -383,7 +383,7 @@ public void testUpdateSearchableAttributesSettings() throws Exception { String[] newSearchableAttributes = {"title", "description", "genre"}; index.waitForTask( - index.updateSearchableAttributesSettings(newSearchableAttributes).getUid()); + index.updateSearchableAttributesSettings(newSearchableAttributes).getTaskUid()); String[] updatedSearchableAttributes = index.getSearchableAttributesSettings(); assertEquals(newSearchableAttributes.length, updatedSearchableAttributes.length); @@ -399,10 +399,10 @@ public void testResetSearchableAttributesSettings() throws Exception { String[] newSearchableAttributes = {"title", "description", "genre"}; index.waitForTask( - index.updateSearchableAttributesSettings(newSearchableAttributes).getUid()); + index.updateSearchableAttributesSettings(newSearchableAttributes).getTaskUid()); String[] updatedSearchableAttributes = index.getSearchableAttributesSettings(); - index.waitForTask(index.resetSearchableAttributesSettings().getUid()); + index.waitForTask(index.resetSearchableAttributesSettings().getTaskUid()); String[] searchableAttributesAfterReset = index.getSearchableAttributesSettings(); assertEquals(newSearchableAttributes.length, updatedSearchableAttributes.length); @@ -435,7 +435,8 @@ public void testUpdateDisplayedAttributesSettings() throws Exception { String[] initialDisplayedAttributes = index.getDisplayedAttributesSettings(); String[] newDisplayedAttributes = {"title", "description", "genre", "release_date"}; - index.waitForTask(index.updateDisplayedAttributesSettings(newDisplayedAttributes).getUid()); + index.waitForTask( + index.updateDisplayedAttributesSettings(newDisplayedAttributes).getTaskUid()); String[] updatedDisplayedAttributes = index.getDisplayedAttributesSettings(); assertEquals(newDisplayedAttributes.length, updatedDisplayedAttributes.length); @@ -450,10 +451,11 @@ public void testResetDisplayedAttributesSettings() throws Exception { String[] initialDisplayedAttributes = index.getDisplayedAttributesSettings(); String[] newDisplayedAttributes = {"title", "description", "genre", "release_date", "cast"}; - index.waitForTask(index.updateDisplayedAttributesSettings(newDisplayedAttributes).getUid()); + index.waitForTask( + index.updateDisplayedAttributesSettings(newDisplayedAttributes).getTaskUid()); String[] updatedDisplayedAttributes = index.getDisplayedAttributesSettings(); - index.waitForTask(index.resetDisplayedAttributesSettings().getUid()); + index.waitForTask(index.resetDisplayedAttributesSettings().getTaskUid()); String[] displayedAttributesAfterReset = index.getDisplayedAttributesSettings(); assertEquals(newDisplayedAttributes.length, updatedDisplayedAttributes.length); @@ -485,7 +487,7 @@ public void testUpdateFilterableAttributesSettings() throws Exception { String[] newFilterableAttributes = {"title", "description", "genre", "release_date"}; index.waitForTask( - index.updateFilterableAttributesSettings(newFilterableAttributes).getUid()); + index.updateFilterableAttributesSettings(newFilterableAttributes).getTaskUid()); String[] updatedFilterableAttributes = index.getFilterableAttributesSettings(); assertEquals(newFilterableAttributes.length, updatedFilterableAttributes.length); @@ -505,10 +507,10 @@ public void testResetFilterableAttributesSettings() throws Exception { }; index.waitForTask( - index.updateFilterableAttributesSettings(newFilterableAttributes).getUid()); + index.updateFilterableAttributesSettings(newFilterableAttributes).getTaskUid()); String[] updatedFilterableAttributes = index.getFilterableAttributesSettings(); - index.waitForTask(index.resetFilterableAttributesSettings().getUid()); + index.waitForTask(index.resetFilterableAttributesSettings().getTaskUid()); String[] filterableAttributesAfterReset = index.getFilterableAttributesSettings(); assertEquals(newFilterableAttributes.length, updatedFilterableAttributes.length); @@ -539,7 +541,7 @@ public void testUpdateDistinctAttributeSettings() throws Exception { String initialDistinctAttribute = index.getDistinctAttributeSettings(); String newDistinctAttribute = "title"; - index.waitForTask(index.updateDistinctAttributeSettings(newDistinctAttribute).getUid()); + index.waitForTask(index.updateDistinctAttributeSettings(newDistinctAttribute).getTaskUid()); String updatedDistinctAttribute = index.getDistinctAttributeSettings(); assertEquals(newDistinctAttribute, updatedDistinctAttribute); @@ -553,10 +555,10 @@ public void testResetDistinctAttributeSettings() throws Exception { String initialDistinctAttribute = index.getDistinctAttributeSettings(); String newDistinctAttribute = "title"; - index.waitForTask(index.updateDistinctAttributeSettings(newDistinctAttribute).getUid()); + index.waitForTask(index.updateDistinctAttributeSettings(newDistinctAttribute).getTaskUid()); String updatedDistinctAttribute = index.getDistinctAttributeSettings(); - index.waitForTask(index.resetDistinctAttributeSettings().getUid()); + index.waitForTask(index.resetDistinctAttributeSettings().getTaskUid()); String distinctAttributeAfterReset = index.getDistinctAttributeSettings(); assertEquals(newDistinctAttribute, updatedDistinctAttribute); @@ -603,7 +605,7 @@ public void testUpdateTypoTolerance() throws Exception { } }; newTypoTolerance.setMinWordSizeForTypos(minWordSizeTypos); - index.waitForTask(index.updateTypoToleranceSettings(newTypoTolerance).getUid()); + index.waitForTask(index.updateTypoToleranceSettings(newTypoTolerance).getTaskUid()); TypoTolerance updatedTypoTolerance = index.getTypoToleranceSettings(); assertEquals( @@ -629,7 +631,7 @@ public void testPartialUpdateTypoTolerance() throws Exception { newTypoTolerance.setDisableOnWords(new String[] {"the"}); newTypoTolerance.setDisableOnAttributes(new String[] {"title"}); - index.waitForTask(index.updateTypoToleranceSettings(newTypoTolerance).getUid()); + index.waitForTask(index.updateTypoToleranceSettings(newTypoTolerance).getTaskUid()); TypoTolerance updatedTypoTolerance = index.getTypoToleranceSettings(); assertEquals( @@ -666,10 +668,10 @@ public void testResetTypoTolerance() throws Exception { }; newTypoTolerance.setMinWordSizeForTypos(minWordSizeTypos); - index.waitForTask(index.updateTypoToleranceSettings(newTypoTolerance).getUid()); + index.waitForTask(index.updateTypoToleranceSettings(newTypoTolerance).getTaskUid()); TypoTolerance updatedTypoTolerance = index.getTypoToleranceSettings(); - index.waitForTask(index.resetTypoToleranceSettings().getUid()); + index.waitForTask(index.resetTypoToleranceSettings().getTaskUid()); TypoTolerance typoToleranceAfterReset = index.getTypoToleranceSettings(); assertEquals( @@ -706,10 +708,10 @@ public void testUpdateSynonymsSettingsUsingNull() throws Exception { newSynonymsSettings.put("007", new String[] {"james bond", "bond"}); newSynonymsSettings.put("ironman", new String[] {"tony stark", "iron man"}); - index.waitForTask(index.updateSynonymsSettings(newSynonymsSettings).getUid()); + index.waitForTask(index.updateSynonymsSettings(newSynonymsSettings).getTaskUid()); Map updatedSynonymsSettings = index.getSynonymsSettings(); - index.waitForTask(index.updateSynonymsSettings(null).getUid()); + index.waitForTask(index.updateSynonymsSettings(null).getTaskUid()); Map resetSynonymsSettings = index.getSynonymsSettings(); assertNotEquals(initialSynonymsSettings.size(), updatedSynonymsSettings.size()); @@ -725,10 +727,10 @@ public void testUpdateStopWordsSettingsUsingNull() throws Exception { String[] initialStopWords = index.getStopWordsSettings(); String[] newStopWords = {"the", "to", "in", "on"}; - index.waitForTask(index.updateStopWordsSettings(newStopWords).getUid()); + index.waitForTask(index.updateStopWordsSettings(newStopWords).getTaskUid()); String[] updatedStopWords = index.getStopWordsSettings(); - index.waitForTask(index.updateStopWordsSettings(null).getUid()); + index.waitForTask(index.updateStopWordsSettings(null).getTaskUid()); String[] resetStopWords = index.getStopWordsSettings(); assertNotEquals(initialStopWords.length, updatedStopWords.length); @@ -753,10 +755,10 @@ public void testUpdateRankingRuleSettingsUsingNull() throws Exception { "rank:desc" }; - index.waitForTask(index.updateRankingRuleSettings(newRankingRules).getUid()); + index.waitForTask(index.updateRankingRuleSettings(newRankingRules).getTaskUid()); String[] newRankingRule = index.getRankingRuleSettings(); - index.waitForTask(index.updateRankingRuleSettings(null).getUid()); + index.waitForTask(index.updateRankingRuleSettings(null).getTaskUid()); String[] resetRankingRule = index.getRankingRuleSettings(); assertNotEquals(newRankingRule.length, resetRankingRule.length); @@ -772,10 +774,10 @@ public void testUpdateSearchableAttributesSettingssUsingNull() throws Exception String[] newSearchableAttributes = {"title", "release_date", "cast"}; index.waitForTask( - index.updateSearchableAttributesSettings(newSearchableAttributes).getUid()); + index.updateSearchableAttributesSettings(newSearchableAttributes).getTaskUid()); String[] updatedSearchableAttributes = index.getSearchableAttributesSettings(); - index.waitForTask(index.updateSearchableAttributesSettings(null).getUid()); + index.waitForTask(index.updateSearchableAttributesSettings(null).getTaskUid()); String[] resetSearchableAttributes = index.getSearchableAttributesSettings(); assertNotEquals(initialSearchableAttributes.length, updatedSearchableAttributes.length); @@ -791,10 +793,11 @@ public void testUpdateDisplayedAttributesSettingsUsingNull() throws Exception { String[] initialDisplayedAttributes = index.getDisplayedAttributesSettings(); String[] newDisplayedAttributes = {"title", "genre", "release_date"}; - index.waitForTask(index.updateDisplayedAttributesSettings(newDisplayedAttributes).getUid()); + index.waitForTask( + index.updateDisplayedAttributesSettings(newDisplayedAttributes).getTaskUid()); String[] updatedDisplayedAttributes = index.getDisplayedAttributesSettings(); - index.waitForTask(index.updateDisplayedAttributesSettings(null).getUid()); + index.waitForTask(index.updateDisplayedAttributesSettings(null).getTaskUid()); String[] resetDisplayedAttributes = index.getDisplayedAttributesSettings(); assertNotEquals(initialDisplayedAttributes.length, updatedDisplayedAttributes.length); @@ -811,10 +814,10 @@ public void testUpdateFilterableAttributesSettingsUsingNull() throws Exception { String[] newFilterableAttributes = {"title", "genres", "cast", "release_date"}; index.waitForTask( - index.updateFilterableAttributesSettings(newFilterableAttributes).getUid()); + index.updateFilterableAttributesSettings(newFilterableAttributes).getTaskUid()); String[] updatedFilterableAttributes = index.getFilterableAttributesSettings(); - index.waitForTask(index.updateFilterableAttributesSettings(null).getUid()); + index.waitForTask(index.updateFilterableAttributesSettings(null).getTaskUid()); String[] resetFilterableAttributes = index.getFilterableAttributesSettings(); assertNotEquals(updatedFilterableAttributes.length, resetFilterableAttributes.length); @@ -830,10 +833,10 @@ public void testUpdateDistinctAttributeSettingsUsingNull() throws Exception { String initialDistinctAttribute = index.getDistinctAttributeSettings(); String newDistinctAttribute = "genres"; - index.waitForTask(index.updateDistinctAttributeSettings(newDistinctAttribute).getUid()); + index.waitForTask(index.updateDistinctAttributeSettings(newDistinctAttribute).getTaskUid()); String updatedDistinctAttribute = index.getDistinctAttributeSettings(); - index.waitForTask(index.updateDistinctAttributeSettings(null).getUid()); + index.waitForTask(index.updateDistinctAttributeSettings(null).getTaskUid()); String resetDistinctAttribute = index.getDistinctAttributeSettings(); assertNotEquals(updatedDistinctAttribute, resetDistinctAttribute); @@ -843,8 +846,8 @@ public void testUpdateDistinctAttributeSettingsUsingNull() throws Exception { private Index createIndex(String indexUid) throws Exception { Index index = client.index(indexUid); - Task updateInfo = index.addDocuments(testData.getRaw()); - index.waitForTask(updateInfo.getUid()); + TaskInfo updateInfo = index.addDocuments(testData.getRaw()); + index.waitForTask(updateInfo.getTaskUid()); return index; } diff --git a/src/test/java/com/meilisearch/integration/TasksTest.java b/src/test/java/com/meilisearch/integration/TasksTest.java index 095218f5..fd25a2da 100644 --- a/src/test/java/com/meilisearch/integration/TasksTest.java +++ b/src/test/java/com/meilisearch/integration/TasksTest.java @@ -5,8 +5,10 @@ import com.meilisearch.integration.classes.AbstractIT; import com.meilisearch.integration.classes.TestData; import com.meilisearch.sdk.Index; -import com.meilisearch.sdk.model.Results; import com.meilisearch.sdk.model.Task; +import com.meilisearch.sdk.model.TaskInfo; +import com.meilisearch.sdk.model.TasksQuery; +import com.meilisearch.sdk.model.TasksResults; import com.meilisearch.sdk.utils.Movie; import org.junit.jupiter.api.AfterAll; import org.junit.jupiter.api.BeforeEach; @@ -33,10 +35,10 @@ static void cleanMeilisearch() { @Test public void testClientGetTask() throws Exception { String indexUid = "GetClientTask"; - Task response = client.createIndex(indexUid); - client.waitForTask(response.getUid()); + TaskInfo response = client.createIndex(indexUid); + client.waitForTask(response.getTaskUid()); - Task task = client.getTask(response.getUid()); + Task task = client.getTask(response.getTaskUid()); assertTrue(task instanceof Task); assertNotNull(task.getStatus()); @@ -52,7 +54,7 @@ public void testClientGetTask() throws Exception { /** Test Get Tasks */ @Test public void testClientGetTasks() throws Exception { - Results result = client.getTasks(); + TasksResults result = client.getTasks(); Task[] tasks = result.getResults(); for (Task task : tasks) { @@ -68,14 +70,62 @@ public void testClientGetTasks() throws Exception { } } + /** Test Get Tasks with limit */ + @Test + public void testClientGetTasksLimit() throws Exception { + int limit = 2; + TasksQuery query = new TasksQuery().setLimit(limit); + TasksResults result = client.getTasks(query); + + assertEquals(limit, result.getLimit()); + assertNotNull(result.getFrom()); + assertNotNull(result.getNext()); + assertNotNull(result.getResults().length); + } + + /** Test Get Tasks with limit and from */ + @Test + public void testClientGetTasksLimitAndFrom() throws Exception { + int limit = 2; + int from = 2; + TasksQuery query = new TasksQuery().setLimit(limit).setFrom(from); + TasksResults result = client.getTasks(query); + + assertEquals(limit, result.getLimit()); + assertEquals(from, result.getFrom()); + assertNotNull(result.getFrom()); + assertNotNull(result.getNext()); + assertNotNull(result.getResults().length); + } + + /** Test Get Tasks with all query parameters */ + @Test + public void testClientGetTasksAllQueryParameters() throws Exception { + int limit = 2; + int from = 2; + TasksQuery query = + new TasksQuery() + .setLimit(limit) + .setFrom(from) + .setStatus(new String[] {"enqueued", "succeeded"}) + .setType(new String[] {"indexDeletion"}); + TasksResults result = client.getTasks(query); + Task[] tasks = result.getResults(); + + assertEquals(limit, result.getLimit()); + assertEquals(from, result.getFrom()); + assertNotNull(result.getFrom()); + assertNotNull(result.getNext()); + } + /** Test waitForTask */ @Test public void testWaitForTask() throws Exception { String indexUid = "WaitForTask"; - Task response = client.createIndex(indexUid); - client.waitForTask(response.getUid()); + TaskInfo response = client.createIndex(indexUid); + client.waitForTask(response.getTaskUid()); - Task task = client.getTask(response.getUid()); + Task task = client.getTask(response.getTaskUid()); assertTrue(task.getUid() >= 0); assertNotNull(task.getEnqueuedAt()); @@ -94,9 +144,9 @@ public void testWaitForTaskTimoutInMs() throws Exception { String indexUid = "WaitForTaskTimoutInMs"; Index index = client.index(indexUid); - Task task = index.addDocuments(this.testData.getRaw()); - index.waitForTask(task.getUid()); + TaskInfo task = index.addDocuments(this.testData.getRaw()); + index.waitForTask(task.getTaskUid()); - assertThrows(Exception.class, () -> index.waitForTask(task.getUid(), 0, 50)); + assertThrows(Exception.class, () -> index.waitForTask(task.getTaskUid(), 0, 50)); } } diff --git a/src/test/java/com/meilisearch/integration/TenantTokenTest.java b/src/test/java/com/meilisearch/integration/TenantTokenTest.java index 2a9d0d2b..0f98c99a 100644 --- a/src/test/java/com/meilisearch/integration/TenantTokenTest.java +++ b/src/test/java/com/meilisearch/integration/TenantTokenTest.java @@ -12,7 +12,7 @@ import com.meilisearch.sdk.model.Key; import com.meilisearch.sdk.model.SearchResult; import com.meilisearch.sdk.model.Settings; -import com.meilisearch.sdk.model.Task; +import com.meilisearch.sdk.model.TaskInfo; import com.meilisearch.sdk.utils.Movie; import java.util.Date; import java.util.HashMap; @@ -93,18 +93,18 @@ public void testGenerateTenantTokenWithFilter() throws Exception { Index index = client.index(indexUid); TestData testData = this.getTestData(MOVIES_INDEX, Movie.class); - Task task = index.addDocuments(testData.getRaw()); - index.waitForTask(task.getUid()); + TaskInfo task = index.addDocuments(testData.getRaw()); + index.waitForTask(task.getTaskUid()); Settings settings = index.getSettings(); settings.setFilterableAttributes(new String[] {"id"}); - index.waitForTask(index.updateSettings(settings).getUid()); + index.waitForTask(index.updateSettings(settings).getTaskUid()); SearchResult searchResult = tokenClient.index(indexUid).search(""); assertEquals(20, searchResult.getHits().size()); assertEquals(20, searchResult.getLimit()); - assertEquals(30, searchResult.getNbHits()); + assertEquals(30, searchResult.getEstimatedTotalHits()); } /** Test Create Tenant Token with expiration date */ diff --git a/src/test/java/com/meilisearch/integration/classes/AbstractIT.java b/src/test/java/com/meilisearch/integration/classes/AbstractIT.java index 7d58cd55..8560bed0 100644 --- a/src/test/java/com/meilisearch/integration/classes/AbstractIT.java +++ b/src/test/java/com/meilisearch/integration/classes/AbstractIT.java @@ -8,7 +8,7 @@ import com.meilisearch.sdk.json.JacksonJsonHandler; import com.meilisearch.sdk.model.Key; import com.meilisearch.sdk.model.Results; -import com.meilisearch.sdk.model.Task; +import com.meilisearch.sdk.model.TaskInfo; import com.meilisearch.sdk.utils.Movie; import java.io.*; import java.net.URL; @@ -59,14 +59,14 @@ public static String getMeilisearchHost() { } public Index createEmptyIndex(String indexUid) throws Exception { - Task task = client.createIndex(indexUid); - client.waitForTask(task.getUid()); + TaskInfo task = client.createIndex(indexUid); + client.waitForTask(task.getTaskUid()); return client.getIndex(indexUid); } public Index createEmptyIndex(String indexUid, String primaryKey) throws Exception { - Task task = client.createIndex(indexUid, primaryKey); - client.waitForTask(task.getUid()); + TaskInfo task = client.createIndex(indexUid, primaryKey); + client.waitForTask(task.getTaskUid()); return client.getIndex(indexUid); }