From 588a95c609a4e898172bc06f31a31a3420733a2e Mon Sep 17 00:00:00 2001 From: alallema Date: Wed, 28 Dec 2022 12:51:58 +0100 Subject: [PATCH 1/9] Apply keys changes --- src/main/java/com/meilisearch/sdk/Client.java | 17 +- .../java/com/meilisearch/sdk/KeysHandler.java | 36 +++- .../meilisearch/sdk/json/GsonJsonHandler.java | 18 +- .../java/com/meilisearch/sdk/model/Key.java | 8 +- .../com/meilisearch/sdk/model/KeyUpdate.java | 23 +++ .../com/meilisearch/sdk/model/KeysQuery.java | 20 +++ .../com/meilisearch/integration/KeysTest.java | 162 +++++++++++++++--- 7 files changed, 252 insertions(+), 32 deletions(-) create mode 100644 src/main/java/com/meilisearch/sdk/model/KeyUpdate.java create mode 100644 src/main/java/com/meilisearch/sdk/model/KeysQuery.java diff --git a/src/main/java/com/meilisearch/sdk/Client.java b/src/main/java/com/meilisearch/sdk/Client.java index 936a9719..22fa195b 100644 --- a/src/main/java/com/meilisearch/sdk/Client.java +++ b/src/main/java/com/meilisearch/sdk/Client.java @@ -8,6 +8,8 @@ import com.meilisearch.sdk.exceptions.MeilisearchException; import com.meilisearch.sdk.json.JsonHandler; import com.meilisearch.sdk.model.Key; +import com.meilisearch.sdk.model.KeyUpdate; +import com.meilisearch.sdk.model.KeysQuery; import com.meilisearch.sdk.model.Results; import com.meilisearch.sdk.model.Stats; import com.meilisearch.sdk.model.Task; @@ -280,6 +282,17 @@ public Results getKeys() throws MeilisearchException { return this.keysHandler.getKeys(); } + /** + * Retrieves list of keys https://docs.meilisearch.com/reference/api/keys.html#get-all-keys + * + * @param param accept by the keys route + * @return List of keys in the Meilisearch client + * @throws MeilisearchException if an error occurs + */ + public Results getKeys(KeysQuery param) throws MeilisearchException { + return this.keysHandler.getKeys(param); + } + /** * Creates a key https://docs.meilisearch.com/reference/api/keys.html#create-a-key * @@ -297,9 +310,9 @@ public Key createKey(Key options) throws MeilisearchException { * @param key String containing the key * @param options String containing the options to update * @return Key Instance - * @throws Exception if client request causes an error + * @throws MeilisearchException if client request causes an error */ - public Key updateKey(String key, Key options) throws Exception { + public Key updateKey(String key, KeyUpdate options) throws MeilisearchException { return this.keysHandler.updateKey(key, options); } diff --git a/src/main/java/com/meilisearch/sdk/KeysHandler.java b/src/main/java/com/meilisearch/sdk/KeysHandler.java index d3d52f8f..7e2ce341 100644 --- a/src/main/java/com/meilisearch/sdk/KeysHandler.java +++ b/src/main/java/com/meilisearch/sdk/KeysHandler.java @@ -1,7 +1,10 @@ package com.meilisearch.sdk; import com.meilisearch.sdk.exceptions.MeilisearchException; +import com.meilisearch.sdk.http.URLBuilder; import com.meilisearch.sdk.model.Key; +import com.meilisearch.sdk.model.KeyUpdate; +import com.meilisearch.sdk.model.KeysQuery; import com.meilisearch.sdk.model.Results; /** @@ -29,7 +32,9 @@ public class KeysHandler { * @throws MeilisearchException if client request causes an error */ Key getKey(String uid) throws MeilisearchException { - String urlPath = "/keys/" + uid; + URLBuilder urlb = new URLBuilder(); + urlb.addSubroute("keys").addSubroute(uid); + String urlPath = urlb.getURL(); return httpClient.get(urlPath, Key.class); } @@ -45,6 +50,23 @@ Results getKeys() throws MeilisearchException { return result; } + /** + * Retrieves keys from the client + * + * @param param accept by the keys route + * @return List of key instance + * @throws MeilisearchException if client request causes an error + */ + Results getKeys(KeysQuery param) throws MeilisearchException { + URLBuilder urlb = new URLBuilder(); + urlb.addSubroute("keys") + .addParameter("limit", param.getLimit()) + .addParameter("offset", param.getOffset()); + String urlQuery = urlb.getURL(); + Results result = httpClient.get(urlQuery, Results.class, Key.class); + return result; + } + /** * Creates a key * @@ -63,10 +85,12 @@ Key createKey(Key options) throws MeilisearchException { * @param key String containing the key * @param options String containing the options of the key * @return Key Instance - * @throws Exception if client request causes an error + * @throws MeilisearchException if client request causes an error */ - Key updateKey(String key, Key options) throws Exception { - String urlPath = "/keys/" + key; + Key updateKey(String key, KeyUpdate options) throws MeilisearchException { + URLBuilder urlb = new URLBuilder(); + urlb.addSubroute("keys").addSubroute(key); + String urlPath = urlb.getURL(); return httpClient.patch(urlPath, options, Key.class); } @@ -77,7 +101,9 @@ Key updateKey(String key, Key options) throws Exception { * @throws MeilisearchException if client request causes an error */ void deleteKey(String key) throws MeilisearchException { - String urlPath = "/keys/" + key; + URLBuilder urlb = new URLBuilder(); + urlb.addSubroute("keys").addSubroute(key); + String urlPath = urlb.getURL(); httpClient.delete(urlPath, String.class); } } diff --git a/src/main/java/com/meilisearch/sdk/json/GsonJsonHandler.java b/src/main/java/com/meilisearch/sdk/json/GsonJsonHandler.java index 3c9eeee5..10cbf1e4 100644 --- a/src/main/java/com/meilisearch/sdk/json/GsonJsonHandler.java +++ b/src/main/java/com/meilisearch/sdk/json/GsonJsonHandler.java @@ -2,6 +2,9 @@ import com.google.gson.Gson; import com.google.gson.GsonBuilder; +import com.google.gson.JsonElement; +import com.google.gson.JsonNull; +import com.google.gson.JsonObject; import com.google.gson.JsonSyntaxException; import com.google.gson.reflect.TypeToken; import com.meilisearch.sdk.exceptions.JsonDecodingException; @@ -26,9 +29,20 @@ public String encode(Object o) throws MeilisearchException { return (String) o; } // TODO: review later + // This is a workaround to encode the Key class properly if (o != null && o.getClass() == Key.class) { GsonBuilder builder = new GsonBuilder(); - this.gson = builder.serializeNulls().setDateFormat("yyyy-MM-dd'T'HH:mm:ss'Z'").create(); + this.gson = builder.setDateFormat("yyyy-MM-dd'T'HH:mm:ss'Z'").create(); + + Key key = (Key) o; + if (key.getExpiresAt() == null) { + JsonElement jsonElement = gson.toJsonTree(o); + JsonObject jsonObject = jsonElement.getAsJsonObject(); + jsonObject.add("expiresAt", JsonNull.INSTANCE); + o = jsonObject; + this.gson = + builder.serializeNulls().setDateFormat("yyyy-MM-dd'T'HH:mm:ss'Z'").create(); + } } try { return gson.toJson(o); @@ -52,7 +66,7 @@ public T decode(Object o, Class targetClass, Class... parameters) return gson.fromJson((String) o, targetClass); } else { TypeToken parameterized = TypeToken.getParameterized(targetClass, parameters); - return gson.fromJson((String) o, parameterized.getType()); + return gson.fromJson((String) o, parameterized.getType()); } } catch (JsonSyntaxException e) { throw new JsonDecodingException(e); diff --git a/src/main/java/com/meilisearch/sdk/model/Key.java b/src/main/java/com/meilisearch/sdk/model/Key.java index 110a91ea..7a3d8a8e 100644 --- a/src/main/java/com/meilisearch/sdk/model/Key.java +++ b/src/main/java/com/meilisearch/sdk/model/Key.java @@ -12,11 +12,17 @@ */ @Getter public class Key { + @Setter + @Accessors(chain = true) + protected String name = null; + @Setter @Accessors(chain = true) protected String description = null; - protected String key = ""; + protected String uid = null; + + protected String key = null; @Setter @Accessors(chain = true) diff --git a/src/main/java/com/meilisearch/sdk/model/KeyUpdate.java b/src/main/java/com/meilisearch/sdk/model/KeyUpdate.java new file mode 100644 index 00000000..22d1c997 --- /dev/null +++ b/src/main/java/com/meilisearch/sdk/model/KeyUpdate.java @@ -0,0 +1,23 @@ +package com.meilisearch.sdk.model; + +import lombok.Getter; +import lombok.Setter; +import lombok.experimental.Accessors; + +/** + * Data structure of Meilisearch response for a Key + * + *

https://docs.meilisearch.com/reference/api/keys.html + */ +@Getter +public class KeyUpdate { + @Setter + @Accessors(chain = true) + protected String name = null; + + @Setter + @Accessors(chain = true) + protected String description = null; + + public KeyUpdate() {} +} diff --git a/src/main/java/com/meilisearch/sdk/model/KeysQuery.java b/src/main/java/com/meilisearch/sdk/model/KeysQuery.java new file mode 100644 index 00000000..3c010bee --- /dev/null +++ b/src/main/java/com/meilisearch/sdk/model/KeysQuery.java @@ -0,0 +1,20 @@ +package com.meilisearch.sdk.model; + +import lombok.Getter; +import lombok.Setter; +import lombok.experimental.Accessors; + +/** + * Data structure of a query parameter for keys route + * + *

https://docs.meilisearch.com/reference/api/keys.html#query-parameters + */ +@Setter +@Getter +@Accessors(chain = true) +public class KeysQuery { + private int offset = -1; + private int limit = -1; + + public KeysQuery() {} +} diff --git a/src/test/java/com/meilisearch/integration/KeysTest.java b/src/test/java/com/meilisearch/integration/KeysTest.java index 4b0bbd30..a45d4824 100644 --- a/src/test/java/com/meilisearch/integration/KeysTest.java +++ b/src/test/java/com/meilisearch/integration/KeysTest.java @@ -3,11 +3,13 @@ import static org.junit.jupiter.api.Assertions.*; import com.meilisearch.integration.classes.AbstractIT; +import com.meilisearch.sdk.exceptions.MeilisearchApiException; import com.meilisearch.sdk.model.Key; +import com.meilisearch.sdk.model.KeyUpdate; +import com.meilisearch.sdk.model.KeysQuery; import com.meilisearch.sdk.model.Results; import java.text.SimpleDateFormat; import java.util.Date; -import org.junit.jupiter.api.AfterAll; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Tag; import org.junit.jupiter.api.Test; @@ -19,10 +21,6 @@ public class KeysTest extends AbstractIT { public void initialize() { this.setUp(); this.setUpJacksonClient(); - } - - @AfterAll - static void cleanMeilisearch() { cleanup(); deleteAllKeys(); } @@ -37,6 +35,7 @@ public void testClientGetKeys() throws Exception { for (Key key : keys) { assertNotNull(key.getKey()); + assertNotNull(key.getUid()); assertNotNull(key.getActions()); assertNotNull(key.getIndexes()); assertNotNull(key.getDescription()); @@ -52,7 +51,7 @@ public void testClientGetKeysWithJacksonJsonHandler() throws Exception { Results result = clientJackson.getKeys(); Key[] keys = result.getResults(); - assertEquals(5, keys.length); + assertEquals(2, keys.length); for (Key key : keys) { assertNotNull(key.getKey()); @@ -63,36 +62,104 @@ public void testClientGetKeysWithJacksonJsonHandler() throws Exception { } } + /** Test Get Keys With Limit */ + @Test + public void testClientGetKeysLimit() throws Exception { + int limit = 24; + KeysQuery query = new KeysQuery().setLimit(limit); + + Results result = client.getKeys(query); + + assertEquals(limit, result.getLimit()); + assertNotNull(result.getOffset()); + assertNotNull(result.getTotal()); + assertNotNull(result.getResults().length); + } + + /** Test Get Keys With Limit and Offset */ + @Test + public void testClientGetKeysLimitAndOffset() throws Exception { + int limit = 24; + int offset = 2; + KeysQuery query = new KeysQuery().setLimit(limit).setOffset(offset); + + Results result = client.getKeys(query); + + assertEquals(limit, result.getLimit()); + assertEquals(offset, result.getOffset()); + assertNotNull(result.getTotal()); + assertNotNull(result.getResults().length); + } + /** Test Get Key */ @Test public void testClientGetKey() throws Exception { + Results result = client.getKeys(); + Key[] keys = result.getResults(); + + Key key = client.getKey(keys[0].getKey()); + + assertTrue(key instanceof Key); + assertNotNull(key.getKey()); + assertNotNull(key.getActions()); + assertNotNull(key.getIndexes()); + assertNotNull(key.getDescription()); + assertNotNull(key.getCreatedAt()); + assertNotNull(key.getUpdatedAt()); + } + + /** Test Get Key With Uid */ + @Test + public void testClientGetKeyWithUid() throws Exception { + Results result = client.getKeys(); + Key[] keys = result.getResults(); + + Key key = client.getKey(keys[0].getUid()); + + assertTrue(key instanceof Key); + assertNotNull(key.getKey()); + assertNotNull(key.getActions()); + assertNotNull(key.getIndexes()); + assertNotNull(key.getDescription()); + assertNotNull(key.getCreatedAt()); + assertNotNull(key.getUpdatedAt()); + } + + /** Test Get Key */ + @Test + public void testClientGetKeyDoesNotExist() throws Exception { + assertThrows(MeilisearchApiException.class, () -> client.getKey("KeyDoesNotExist")); + } + + /** Test Create a simple API Key without description */ + @Test + public void testClientCreateDefaultKey() throws Exception { Key keyInfo = new Key(); keyInfo.setIndexes(new String[] {"*"}); keyInfo.setActions(new String[] {"*"}); keyInfo.setExpiresAt(null); - Key createKey = client.createKey(keyInfo); - Key key = client.getKey(createKey.getKey()); + Key key = client.createKey(keyInfo); assertTrue(key instanceof Key); assertNotNull(key.getKey()); - assertNotNull(key.getActions()); - assertNotNull(key.getIndexes()); + assertEquals("*", key.getActions()[0]); + assertEquals("*", key.getIndexes()[0]); assertNull(key.getDescription()); assertNull(key.getExpiresAt()); assertNotNull(key.getCreatedAt()); assertNotNull(key.getUpdatedAt()); } - /** Test Create a simple API Key without description */ + /** Test Create a simple API Key without description with Jackson Json Handler */ @Test - public void testClientCreateDefaultKey() throws Exception { + public void testClientCreateDefaultKeyWithJacksonJsonHandler() throws Exception { Key keyInfo = new Key(); keyInfo.setIndexes(new String[] {"*"}); keyInfo.setActions(new String[] {"*"}); keyInfo.setExpiresAt(null); - Key key = client.createKey(keyInfo); + Key key = clientJackson.createKey(keyInfo); assertTrue(key instanceof Key); assertNotNull(key.getKey()); @@ -155,13 +222,15 @@ public void testClientUpdateKey() throws Exception { Date dateParsed = format.parse("2042-01-30T00:00:00Z"); Key keyInfo = new Key(); + keyInfo.setName("Key"); + keyInfo.setDescription("Description Key To Update - test"); keyInfo.setIndexes(new String[] {"*"}); - keyInfo.setActions(new String[] {"*"}); + keyInfo.setActions(new String[] {"search"}); + keyInfo.setExpiresAt(dateParsed); - Key keyChanges = new Key(); - keyChanges.setIndexes(new String[] {"testUpdateKey"}); - keyChanges.setActions(new String[] {"search"}); - keyChanges.setExpiresAt(dateParsed); + KeyUpdate keyChanges = new KeyUpdate(); + keyInfo.setName("Key After Update"); + keyInfo.setDescription("Description Key After Update - test"); Key createKey = client.createKey(keyInfo); Key updateKey = client.updateKey(createKey.getKey(), keyChanges); @@ -169,11 +238,46 @@ public void testClientUpdateKey() throws Exception { assertTrue(createKey instanceof Key); assertTrue(updateKey instanceof Key); assertNotNull(updateKey.getKey()); - assertEquals("*", createKey.getActions()[0]); - assertEquals("search", updateKey.getActions()[0]); assertEquals("*", createKey.getIndexes()[0]); - assertEquals("testUpdateKey", updateKey.getIndexes()[0]); - assertNull(createKey.getExpiresAt()); + assertEquals("search", createKey.getActions()[0]); + assertEquals("Key After Update", createKey.getName()); + assertEquals("Description Key After Update - test", updateKey.getDescription()); + assertEquals(createKey.getIndexes()[0], updateKey.getIndexes()[0]); + assertEquals(createKey.getActions()[0], updateKey.getActions()[0]); + assertEquals(dateParsed, updateKey.getExpiresAt()); + assertNotNull(updateKey.getCreatedAt()); + assertNotNull(updateKey.getUpdatedAt()); + } + + /** Test Update an API Key with Jackson Json Handler */ + @Test + public void testClientUpdateKeyWithJacksonJsonHandler() throws Exception { + SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss'Z'"); + Date dateParsed = format.parse("2042-01-30T00:00:00Z"); + + Key keyInfo = new Key(); + keyInfo.setName("Key"); + keyInfo.setDescription("Description Key To Update - test"); + keyInfo.setIndexes(new String[] {"*"}); + keyInfo.setActions(new String[] {"search"}); + keyInfo.setExpiresAt(dateParsed); + + KeyUpdate keyChanges = new KeyUpdate(); + keyInfo.setName("Key After Update"); + keyInfo.setDescription("Description Key After Update - test"); + + Key createKey = clientJackson.createKey(keyInfo); + Key updateKey = clientJackson.updateKey(createKey.getKey(), keyChanges); + + assertTrue(createKey instanceof Key); + assertTrue(updateKey instanceof Key); + assertNotNull(updateKey.getKey()); + assertEquals("*", createKey.getIndexes()[0]); + assertEquals("search", createKey.getActions()[0]); + assertEquals("Key After Update", createKey.getName()); + assertEquals("Description Key After Update - test", updateKey.getDescription()); + assertEquals(createKey.getIndexes()[0], updateKey.getIndexes()[0]); + assertEquals(createKey.getActions()[0], updateKey.getActions()[0]); assertEquals(dateParsed, updateKey.getExpiresAt()); assertNotNull(updateKey.getCreatedAt()); assertNotNull(updateKey.getUpdatedAt()); @@ -192,4 +296,18 @@ public void testClientDeleteKey() throws Exception { assertThrows(Exception.class, () -> client.getKey(createKey.getKey())); } + + /** Test Delete an API Key With Uid */ + @Test + public void testClientDeleteKeyWithUid() throws Exception { + Key keyInfo = new Key(); + keyInfo.setIndexes(new String[] {"*"}); + keyInfo.setActions(new String[] {"*"}); + keyInfo.setExpiresAt(null); + + Key createKey = client.createKey(keyInfo); + client.deleteKey(createKey.getUid()); + + assertThrows(Exception.class, () -> client.getKey(createKey.getUid())); + } } From a4f18a95666a9b7a5ec345d687b5162d51a6bcdb Mon Sep 17 00:00:00 2001 From: alallema Date: Tue, 3 Jan 2023 10:38:17 +0100 Subject: [PATCH 2/9] Add toQuery method to KeysQuery --- .../java/com/meilisearch/sdk/KeysHandler.java | 23 ++++--------------- .../com/meilisearch/sdk/model/KeysQuery.java | 15 ++++++++++++ 2 files changed, 19 insertions(+), 19 deletions(-) diff --git a/src/main/java/com/meilisearch/sdk/KeysHandler.java b/src/main/java/com/meilisearch/sdk/KeysHandler.java index 7e2ce341..88896fbc 100644 --- a/src/main/java/com/meilisearch/sdk/KeysHandler.java +++ b/src/main/java/com/meilisearch/sdk/KeysHandler.java @@ -1,7 +1,6 @@ package com.meilisearch.sdk; import com.meilisearch.sdk.exceptions.MeilisearchException; -import com.meilisearch.sdk.http.URLBuilder; import com.meilisearch.sdk.model.Key; import com.meilisearch.sdk.model.KeyUpdate; import com.meilisearch.sdk.model.KeysQuery; @@ -32,10 +31,7 @@ public class KeysHandler { * @throws MeilisearchException if client request causes an error */ Key getKey(String uid) throws MeilisearchException { - URLBuilder urlb = new URLBuilder(); - urlb.addSubroute("keys").addSubroute(uid); - String urlPath = urlb.getURL(); - return httpClient.get(urlPath, Key.class); + return httpClient.get(new KeysQuery().toQuery(uid), Key.class); } /** @@ -58,12 +54,7 @@ Results getKeys() throws MeilisearchException { * @throws MeilisearchException if client request causes an error */ Results getKeys(KeysQuery param) throws MeilisearchException { - URLBuilder urlb = new URLBuilder(); - urlb.addSubroute("keys") - .addParameter("limit", param.getLimit()) - .addParameter("offset", param.getOffset()); - String urlQuery = urlb.getURL(); - Results result = httpClient.get(urlQuery, Results.class, Key.class); + Results result = httpClient.get(param.toQuery(param), Results.class, Key.class); return result; } @@ -88,10 +79,7 @@ Key createKey(Key options) throws MeilisearchException { * @throws MeilisearchException if client request causes an error */ Key updateKey(String key, KeyUpdate options) throws MeilisearchException { - URLBuilder urlb = new URLBuilder(); - urlb.addSubroute("keys").addSubroute(key); - String urlPath = urlb.getURL(); - return httpClient.patch(urlPath, options, Key.class); + return httpClient.patch(new KeysQuery().toQuery(key), options, Key.class); } /** @@ -101,9 +89,6 @@ Key updateKey(String key, KeyUpdate options) throws MeilisearchException { * @throws MeilisearchException if client request causes an error */ void deleteKey(String key) throws MeilisearchException { - URLBuilder urlb = new URLBuilder(); - urlb.addSubroute("keys").addSubroute(key); - String urlPath = urlb.getURL(); - httpClient.delete(urlPath, String.class); + httpClient.delete(new KeysQuery().toQuery(key), String.class); } } diff --git a/src/main/java/com/meilisearch/sdk/model/KeysQuery.java b/src/main/java/com/meilisearch/sdk/model/KeysQuery.java index 3c010bee..cbdc7b05 100644 --- a/src/main/java/com/meilisearch/sdk/model/KeysQuery.java +++ b/src/main/java/com/meilisearch/sdk/model/KeysQuery.java @@ -1,5 +1,6 @@ package com.meilisearch.sdk.model; +import com.meilisearch.sdk.http.URLBuilder; import lombok.Getter; import lombok.Setter; import lombok.experimental.Accessors; @@ -17,4 +18,18 @@ public class KeysQuery { private int limit = -1; public KeysQuery() {} + + public String toQuery(String key) { + URLBuilder urlb = new URLBuilder(); + urlb.addSubroute("keys").addSubroute(key); + return urlb.getURL(); + } + + public String toQuery(KeysQuery param) { + URLBuilder urlb = new URLBuilder(); + urlb.addSubroute("keys") + .addParameter("limit", param.getLimit()) + .addParameter("offset", param.getOffset()); + return urlb.getURL(); + } } From 29106758b4d4e1b6db81a0e5cf3cd31196ded359 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Am=C3=A9lie?= Date: Wed, 4 Jan 2023 16:25:22 +0100 Subject: [PATCH 3/9] Update src/main/java/com/meilisearch/sdk/Client.java Co-authored-by: cvermand <33010418+bidoubiwa@users.noreply.github.com> --- src/main/java/com/meilisearch/sdk/Client.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/com/meilisearch/sdk/Client.java b/src/main/java/com/meilisearch/sdk/Client.java index 22fa195b..5fcf8aa2 100644 --- a/src/main/java/com/meilisearch/sdk/Client.java +++ b/src/main/java/com/meilisearch/sdk/Client.java @@ -283,7 +283,7 @@ public Results getKeys() throws MeilisearchException { } /** - * Retrieves list of keys https://docs.meilisearch.com/reference/api/keys.html#get-all-keys + * Get list of all API keys https://docs.meilisearch.com/reference/api/keys.html#get-all-keys * * @param param accept by the keys route * @return List of keys in the Meilisearch client From 5c5ce8d7b08d5de5bb8b85b99b16ca8c058a720f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Am=C3=A9lie?= Date: Wed, 4 Jan 2023 16:25:29 +0100 Subject: [PATCH 4/9] Update src/main/java/com/meilisearch/sdk/Client.java Co-authored-by: cvermand <33010418+bidoubiwa@users.noreply.github.com> --- src/main/java/com/meilisearch/sdk/Client.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/com/meilisearch/sdk/Client.java b/src/main/java/com/meilisearch/sdk/Client.java index 5fcf8aa2..1ea2304a 100644 --- a/src/main/java/com/meilisearch/sdk/Client.java +++ b/src/main/java/com/meilisearch/sdk/Client.java @@ -285,7 +285,7 @@ public Results getKeys() throws MeilisearchException { /** * Get list of all API keys https://docs.meilisearch.com/reference/api/keys.html#get-all-keys * - * @param param accept by the keys route + * @param query parameters accepted by the get keys route * @return List of keys in the Meilisearch client * @throws MeilisearchException if an error occurs */ From 1c7b8cfd5c66d8a4fb1e340414f78f13c702aa99 Mon Sep 17 00:00:00 2001 From: alallema Date: Wed, 4 Jan 2023 16:31:16 +0100 Subject: [PATCH 5/9] Improve Key's method description --- src/main/java/com/meilisearch/sdk/Client.java | 18 +++++++++--------- .../java/com/meilisearch/sdk/KeysHandler.java | 14 ++++++-------- 2 files changed, 15 insertions(+), 17 deletions(-) diff --git a/src/main/java/com/meilisearch/sdk/Client.java b/src/main/java/com/meilisearch/sdk/Client.java index 1ea2304a..768ae872 100644 --- a/src/main/java/com/meilisearch/sdk/Client.java +++ b/src/main/java/com/meilisearch/sdk/Client.java @@ -265,7 +265,7 @@ public void waitForTask(int uid) throws MeilisearchException { * https://docs.meilisearch.com/reference/api/keys.html#get-one-key * * @param uid Identifier of the requested Key - * @return Key Instance + * @return Meilisearch API response as Key Instance * @throws MeilisearchException if an error occurs */ public Key getKey(String uid) throws MeilisearchException { @@ -275,7 +275,7 @@ public Key getKey(String uid) throws MeilisearchException { /** * Retrieves list of keys https://docs.meilisearch.com/reference/api/keys.html#get-all-keys * - * @return List of keys in the Meilisearch client + * @return Results containing a list of Key from the Meilisearch API * @throws MeilisearchException if an error occurs */ public Results getKeys() throws MeilisearchException { @@ -285,19 +285,19 @@ public Results getKeys() throws MeilisearchException { /** * Get list of all API keys https://docs.meilisearch.com/reference/api/keys.html#get-all-keys * - * @param query parameters accepted by the get keys route - * @return List of keys in the Meilisearch client + * @param params query parameters accepted by the get keys route + * @return Results containing a list of Key from the Meilisearch API * @throws MeilisearchException if an error occurs */ - public Results getKeys(KeysQuery param) throws MeilisearchException { - return this.keysHandler.getKeys(param); + public Results getKeys(KeysQuery params) throws MeilisearchException { + return this.keysHandler.getKeys(params); } /** * Creates a key https://docs.meilisearch.com/reference/api/keys.html#create-a-key * * @param options Key containing the options of the key - * @return Key Instance + * @return Meilisearch API response as Key Instance * @throws MeilisearchException if an error occurs */ public Key createKey(Key options) throws MeilisearchException { @@ -309,8 +309,8 @@ public Key createKey(Key options) throws MeilisearchException { * * @param key String containing the key * @param options String containing the options to update - * @return Key Instance - * @throws MeilisearchException if client request causes an error + * @return Meilisearch API response as Key Instance + * @throws MeilisearchException if an error occurs */ public Key updateKey(String key, KeyUpdate options) throws MeilisearchException { return this.keysHandler.updateKey(key, options); diff --git a/src/main/java/com/meilisearch/sdk/KeysHandler.java b/src/main/java/com/meilisearch/sdk/KeysHandler.java index 88896fbc..9ffa47e5 100644 --- a/src/main/java/com/meilisearch/sdk/KeysHandler.java +++ b/src/main/java/com/meilisearch/sdk/KeysHandler.java @@ -37,25 +37,23 @@ Key getKey(String uid) throws MeilisearchException { /** * Retrieves keys from the client * - * @return List of key instance + * @return Results containing a list of Key instance * @throws MeilisearchException if client request causes an error */ Results getKeys() throws MeilisearchException { String urlPath = "/keys"; - Results result = httpClient.get(urlPath, Results.class, Key.class); - return result; + return httpClient.get(urlPath, Results.class, Key.class); } /** * Retrieves keys from the client * - * @param param accept by the keys route - * @return List of key instance + * @param params accept by the keys route + * @return Results containing a list of Key instance * @throws MeilisearchException if client request causes an error */ - Results getKeys(KeysQuery param) throws MeilisearchException { - Results result = httpClient.get(param.toQuery(param), Results.class, Key.class); - return result; + Results getKeys(KeysQuery params) throws MeilisearchException { + return httpClient.get(params.toQuery(params), Results.class, Key.class); } /** From c121bd76ea1e2f38464ee2c36fb6d9b0a0ceabda Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Am=C3=A9lie?= Date: Thu, 5 Jan 2023 13:54:15 +0100 Subject: [PATCH 6/9] Update src/main/java/com/meilisearch/sdk/model/KeysQuery.java Co-authored-by: cvermand <33010418+bidoubiwa@users.noreply.github.com> --- src/main/java/com/meilisearch/sdk/model/KeysQuery.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/com/meilisearch/sdk/model/KeysQuery.java b/src/main/java/com/meilisearch/sdk/model/KeysQuery.java index cbdc7b05..0b22c199 100644 --- a/src/main/java/com/meilisearch/sdk/model/KeysQuery.java +++ b/src/main/java/com/meilisearch/sdk/model/KeysQuery.java @@ -6,7 +6,7 @@ import lombok.experimental.Accessors; /** - * Data structure of a query parameter for keys route + * Data structure of the query parameters for the keys routes * *

https://docs.meilisearch.com/reference/api/keys.html#query-parameters */ From fc137ae417abeda2deeb0a8be4d21c6b29e5c14f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Am=C3=A9lie?= Date: Thu, 5 Jan 2023 13:54:30 +0100 Subject: [PATCH 7/9] Update src/test/java/com/meilisearch/integration/KeysTest.java Co-authored-by: cvermand <33010418+bidoubiwa@users.noreply.github.com> --- src/test/java/com/meilisearch/integration/KeysTest.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/test/java/com/meilisearch/integration/KeysTest.java b/src/test/java/com/meilisearch/integration/KeysTest.java index a45d4824..4ae69e32 100644 --- a/src/test/java/com/meilisearch/integration/KeysTest.java +++ b/src/test/java/com/meilisearch/integration/KeysTest.java @@ -125,7 +125,7 @@ public void testClientGetKeyWithUid() throws Exception { assertNotNull(key.getUpdatedAt()); } - /** Test Get Key */ + /** Test Get Key when the key does not exist*/ @Test public void testClientGetKeyDoesNotExist() throws Exception { assertThrows(MeilisearchApiException.class, () -> client.getKey("KeyDoesNotExist")); From c95847cf28c671d02e2e0fb6efb8441d1e57ef46 Mon Sep 17 00:00:00 2001 From: alallema Date: Thu, 5 Jan 2023 13:57:19 +0100 Subject: [PATCH 8/9] Modify KeyUpdate class definition --- src/main/java/com/meilisearch/sdk/model/KeyUpdate.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/com/meilisearch/sdk/model/KeyUpdate.java b/src/main/java/com/meilisearch/sdk/model/KeyUpdate.java index 22d1c997..42c02802 100644 --- a/src/main/java/com/meilisearch/sdk/model/KeyUpdate.java +++ b/src/main/java/com/meilisearch/sdk/model/KeyUpdate.java @@ -5,7 +5,7 @@ import lombok.experimental.Accessors; /** - * Data structure of Meilisearch response for a Key + * Data structure for updating a Key * *

https://docs.meilisearch.com/reference/api/keys.html */ From 4a6c382b943a5cd80c094d7afeec128dbfa49171 Mon Sep 17 00:00:00 2001 From: alallema Date: Thu, 5 Jan 2023 13:59:06 +0100 Subject: [PATCH 9/9] Changes du to review and linter --- src/test/java/com/meilisearch/integration/KeysTest.java | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/src/test/java/com/meilisearch/integration/KeysTest.java b/src/test/java/com/meilisearch/integration/KeysTest.java index 4ae69e32..a2c3d4b6 100644 --- a/src/test/java/com/meilisearch/integration/KeysTest.java +++ b/src/test/java/com/meilisearch/integration/KeysTest.java @@ -10,6 +10,7 @@ import com.meilisearch.sdk.model.Results; import java.text.SimpleDateFormat; import java.util.Date; +import org.junit.jupiter.api.AfterAll; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Tag; import org.junit.jupiter.api.Test; @@ -25,6 +26,12 @@ public void initialize() { deleteAllKeys(); } + @AfterAll + static void cleanMeilisearch() { + cleanup(); + deleteAllKeys(); + } + /** Test Get Keys */ @Test public void testClientGetKeys() throws Exception { @@ -125,7 +132,7 @@ public void testClientGetKeyWithUid() throws Exception { assertNotNull(key.getUpdatedAt()); } - /** Test Get Key when the key does not exist*/ + /** Test Get Key when the key does not exist */ @Test public void testClientGetKeyDoesNotExist() throws Exception { assertThrows(MeilisearchApiException.class, () -> client.getKey("KeyDoesNotExist"));