Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
47 changes: 39 additions & 8 deletions .code-samples.meilisearch.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -260,6 +260,18 @@ update_displayed_attributes_1: |-
});
reset_displayed_attributes_1: |-
client.index("movies").resetDisplayedAttributesSettings();
getting_started_typo_tolerance: |-
HashMap<String, Integer> minWordSizeTypos =
new HashMap<String, Integer>() {
{
put("oneTypo", 4);
}
};

TypoTolerance typoTolerance = new TypoTolerance();
typoTolerance.setMinWordSizeForTypos(minWordSizeTypos);

client.index("movies").updateTypoToleranceSettings(typoTolerance);
get_typo_tolerance_1:
client.index("books").getTypoToleranceSettings();
update_typo_tolerance_1: |-
Expand Down Expand Up @@ -311,7 +323,7 @@ update_non_separator_tokens_1: |-
String[] newSeparatorTokens = { "@", "#" };
client.index("articles").updateNonSeparatorTokensSettings(newSeparatorTokens);
reset_non_separator_tokens_1: |-
client.index("articles").resetNonSeparatorTokensSettings();
client.index("articles").resetNonSeparatorTokensSettings();
get_dictionary_1: |-
client.index("books").getDictionarySettings();
update_dictionary_1: |-
Expand Down Expand Up @@ -511,9 +523,9 @@ search_parameter_guide_facet_stats_1: |-
faceted_search_update_settings_1:
client.index("movie_ratings").updateFilterableAttributesSettings(new String[]
{
"genres",
"director",
"language"
"genres",
"director",
"language"
});
faceted_search_walkthrough_filter_1: |-
SearchRequest searchRequest =
Expand Down Expand Up @@ -681,10 +693,9 @@ multi_search_1: |-
multiIndexSearch.addQuery(new IndexSearchRequest("movie_ratings").setQuery("us"));

client.multiSearch(multiSearchRequest);
get_similar_post_1:
SimilarDocumentRequest query = new SimilarDocumentRequest()
.setId("143")
.setEmbedder("manual");
get_similar_post_1: SimilarDocumentRequest query = new SimilarDocumentRequest()
.setId("143")
.setEmbedder("manual");
client.index("movies").searchSimilarDocuments(query)
search_parameter_reference_distinct_1: |-
SearchRequest searchRequest = SearchRequest.builder().q("QUERY TERMS").distinct("ATTRIBUTE_A").build();
Expand Down Expand Up @@ -720,3 +731,23 @@ compact_index_1: |-
client.index("INDEX_NAME").compact();
rename_an_index_1: |-
client.updateIndex("indexA", null, "indexB");
get_webhooks_1: |-
client.getWebhook();
get_webhook_1: |-
client.getWebhook();
create_webhook_1: |-
HashMap<String, Object> headers = new HashMap<>();
headers.put("authorization", "MASTER_KEY");
headers.put("referer", "http://example.com");
CreateUpdateWebhookRequest webhookReq1 = new CreateUpdateWebhookRequest("http://webiste.com", headers);

Webhook webhook = client.createWebhook();
update_webhook_1: |-
Webhook webhook = this.client.createWebhook(webhookReq1);
HashMap<String, Object> headers = new HashMap<>();
headers.put("referer", null);
CreateUpdateWebhookRequest webhookReq2 = new CreateUpdateWebhookRequest(webhook.getUrl(), headers);

Webhook updated_webhook = this.client.updateWebhook(webhook.getUuid(), webhookReq2);
delete_webhook_1: |-
this.client.deleteWebhook("WEBHOOK_UUID");
60 changes: 60 additions & 0 deletions src/main/java/com/meilisearch/sdk/Client.java
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ public class Client {
private TasksHandler tasksHandler;
private KeysHandler keysHandler;
private JsonHandler jsonHandler;
private WebHooksHandler webHooksHandler;

/**
* Calls instance for Meilisearch client
Expand All @@ -33,6 +34,7 @@ public Client(Config config) {
this.tasksHandler = new TasksHandler(config);
this.keysHandler = new KeysHandler(config);
this.jsonHandler = config.jsonHandler;
this.webHooksHandler = new WebHooksHandler(config);
}

/**
Expand Down Expand Up @@ -544,6 +546,64 @@ public String generateTenantToken(
return jwtToken;
}

/**
* Get a list of all webhooks configured in the current Meilisearch instance.
*
* @return List of all webhooks.
* @throws MeilisearchException if an error occurs.
*/
public Results<Webhook> getWebhooks() throws MeilisearchException {
return this.webHooksHandler.getWebhooks();
}

/**
* Get a webhook specified by its unique Uuid.
*
* @return A single Webhook instance.
* @param webhookUuid Uuid v4 identifier of a webhook.
* @throws MeilisearchException if an error occurs.
*/
public Webhook getWebhook(UUID webhookUuid) throws MeilisearchException {
return this.webHooksHandler.getWebhook(webhookUuid);
}

/**
* Create a new webhook. When Meilisearch finishes processing a task, it sends the relevant task
* object to all configured webhooks
*
* @return A single Webhook instance.
* @param createUpdateWebhookRequest Request body containing headers and url for the new
* webhook.
* @throws MeilisearchException If an error occurs.
*/
public Webhook createWebhook(CreateUpdateWebhookRequest createUpdateWebhookRequest)
throws MeilisearchException {
return this.webHooksHandler.createWebhook(createUpdateWebhookRequest);
}

/**
* Update the configuration for the specified webhook. To remove a field, set its value to null.
*
* @param webhook_uuid Uuid v4 identifier of a webhook.
* @param createUpdateWebhookRequest Request body containing new header or url.
* @return A single webhook instance.
* @throws MeilisearchException If an error occurs.
*/
public Webhook updateWebhook(
UUID webhook_uuid, CreateUpdateWebhookRequest createUpdateWebhookRequest)
throws MeilisearchException {
return this.webHooksHandler.updateWebhook(webhook_uuid, createUpdateWebhookRequest);
}

/**
* Delete a webhook and stop sending task completion data to the target URL.
*
* @param webhook_uuid Uuid v4 identifier of a webhook.
*/
public void deleteWebhook(UUID webhook_uuid) throws MeilisearchException {
this.webHooksHandler.deleteWebhook(webhook_uuid);
}
Comment on lines +587 to +605
Copy link
Contributor

Choose a reason for hiding this comment

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

⚠️ Potential issue | 🟡 Minor

Inconsistent parameter naming: webhook_uuid (snake_case) vs webhookUuid (camelCase).

updateWebhook and deleteWebhook use webhook_uuid while getWebhook (line 566) uses webhookUuid. Java convention is camelCase, and other Client methods follow this (e.g., apiKeyUid). Additionally, deleteWebhook Javadoc is missing the @throws MeilisearchException tag even though the signature declares it.

Proposed fix
     /**
      * Update the configuration for the specified webhook. To remove a field, set its value to null.
      *
-     * `@param` webhook_uuid Uuid v4 identifier of a webhook.
+     * `@param` webhookUuid Uuid v4 identifier of a webhook.
      * `@param` createUpdateWebhookRequest Request body containing new header or url.
      * `@return` A single webhook instance.
      * `@throws` MeilisearchException If an error occurs.
      */
     public Webhook updateWebhook(
-            UUID webhook_uuid, CreateUpdateWebhookRequest createUpdateWebhookRequest)
+            UUID webhookUuid, CreateUpdateWebhookRequest createUpdateWebhookRequest)
             throws MeilisearchException {
-        return this.webHooksHandler.updateWebhook(webhook_uuid, createUpdateWebhookRequest);
+        return this.webHooksHandler.updateWebhook(webhookUuid, createUpdateWebhookRequest);
     }
 
     /**
      * Delete a webhook and stop sending task completion data to the target URL.
      *
-     * `@param` webhook_uuid Uuid v4 identifier of a webhook.
+     * `@param` webhookUuid Uuid v4 identifier of a webhook.
+     * `@throws` MeilisearchException If an error occurs.
      */
-    public void deleteWebhook(UUID webhook_uuid) throws MeilisearchException {
-        this.webHooksHandler.deleteWebhook(webhook_uuid);
+    public void deleteWebhook(UUID webhookUuid) throws MeilisearchException {
+        this.webHooksHandler.deleteWebhook(webhookUuid);
     }
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@src/main/java/com/meilisearch/sdk/Client.java` around lines 587 - 605, Rename
the parameters webhook_uuid to camelCase webhookUuid in the Client methods
updateWebhook(UUID webhook_uuid, CreateUpdateWebhookRequest ...) and
deleteWebhook(UUID webhook_uuid) to follow Java conventions and match
getWebhook/getters; update the method signatures and all internal references to
use webhookUuid (including the calls to this.webHooksHandler.updateWebhook(...)
and this.webHooksHandler.deleteWebhook(...)). Also add the missing Javadoc
`@throws` MeilisearchException tag to deleteWebhook to match the method signature
and other methods' docs. Ensure any callers/tests are updated to use the new
parameter name if they reference it by name (method call sites need no change),
and run a compile to catch any remaining references.


private Boolean isValidUUID(String apiKeyUid) {
try {
UUID uuid = UUID.fromString(apiKeyUid);
Expand Down
1 change: 0 additions & 1 deletion src/main/java/com/meilisearch/sdk/HttpClient.java
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,6 @@ <T> T delete(String api, Class<T> targetClass) throws MeilisearchException {
HttpRequest requestConfig = request.create(HttpMethod.DELETE, api, this.headers, null);
HttpResponse<T> httpRequest = this.client.delete(requestConfig);
HttpResponse<T> httpResponse = response.create(httpRequest, targetClass);

if (httpResponse.getStatusCode() >= 400) {
throw new MeilisearchApiException(
jsonHandler.decode(httpRequest.getContent(), APIError.class));
Expand Down
82 changes: 82 additions & 0 deletions src/main/java/com/meilisearch/sdk/WebHooksHandler.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
package com.meilisearch.sdk;

import com.meilisearch.sdk.exceptions.MeilisearchException;
import com.meilisearch.sdk.http.URLBuilder;
import com.meilisearch.sdk.model.CreateUpdateWebhookRequest;
import com.meilisearch.sdk.model.Results;
import com.meilisearch.sdk.model.Webhook;
import java.util.UUID;

public class WebHooksHandler {
private final HttpClient httpClient;

protected WebHooksHandler(Config config) {
this.httpClient = config.httpClient;
}

/**
* Gets a list of webhooks
*
* @return List of webhooks.
* @throws MeilisearchException if an error occurs
*/
Results<Webhook> getWebhooks() throws MeilisearchException {
return this.httpClient.get(webhooksPath().getURL(), Results.class, Webhook.class);
}

/**
* Gets a webhook from its uuid
*
* @param uuid Unique identifier of the webhook to get
* @return Meilisearch API response as Webhook instance
* @throws MeilisearchException if an error occurs
*/
Webhook getWebhook(UUID uuid) throws MeilisearchException {
return this.httpClient.get(
webhooksPath().addSubroute(uuid.toString()).getURL(), Webhook.class);
}

/**
* Create a new webhook
*
* @param createUpdateWebhookRequest Request body for creating a new webhook
* @return Meilisearch API response as Webhook instance
* @throws MeilisearchException if an error occurs
*/
Webhook createWebhook(CreateUpdateWebhookRequest createUpdateWebhookRequest)
throws MeilisearchException {
return this.httpClient.post(
webhooksPath().getURL(), createUpdateWebhookRequest, Webhook.class);
}

/**
* Update a webhook
*
* @param webhookUuid Unique identifier of a webhook to update
* @param createUpdateWebhookRequest Request body for updating a webhook
* @return Meilisearch API response as Webhook instance
* @throws MeilisearchException if an error occurs
*/
Webhook updateWebhook(UUID webhookUuid, CreateUpdateWebhookRequest createUpdateWebhookRequest)
throws MeilisearchException {
return this.httpClient.patch(
webhooksPath().addSubroute(webhookUuid.toString()).getURL(),
createUpdateWebhookRequest,
Webhook.class);
}

/**
* Delete a webhook
*
* @param webhookUuid Unique identifier of a webhook to update
* @throws MeilisearchException if an error occurs
*/
void deleteWebhook(UUID webhookUuid) throws MeilisearchException {
this.httpClient.delete(
webhooksPath().addSubroute(webhookUuid.toString()).getURL(), String.class);
}

private URLBuilder webhooksPath() {
return new URLBuilder("/webhooks");
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
package com.meilisearch.sdk.model;

import java.io.Serializable;
import java.util.HashMap;
import lombok.NonNull;

/**
* Data structure used in request body while creating or updating a webhook.
*
* @see <a href="https://www.meilisearch.com/docs/reference/api/webhooks">API Specification</a>
*/
public class CreateUpdateWebhookRequest implements Serializable {
final String url;
final HashMap<String, Object> headers;

public CreateUpdateWebhookRequest(
@NonNull String url, @NonNull HashMap<String, Object> headers) {
this.url = url;
this.headers = headers;
}
}
25 changes: 25 additions & 0 deletions src/main/java/com/meilisearch/sdk/model/Webhook.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
package com.meilisearch.sdk.model;

import java.io.Serializable;
import java.util.HashMap;
import java.util.UUID;
import lombok.Getter;

/**
* Webhook data structure.
*
* @see <a href="https://www.meilisearch.com/docs/reference/api/webhooks">API specification</a>
*/
public class Webhook implements Serializable {
@Getter protected final UUID uuid;
@Getter protected final String url;
@Getter protected final HashMap<String, String> headers;
@Getter protected final boolean isEditable;

public Webhook(UUID uuid, String url, HashMap<String, String> headers, boolean isEditable) {
this.uuid = uuid;
this.url = url;
this.headers = headers;
this.isEditable = isEditable;
}
}
Loading