-
Notifications
You must be signed in to change notification settings - Fork 133
Add support for export API #882
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 1 commit
0926b22
6778982
071fb72
7359dff
b1e21b1
ea1c43c
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,28 @@ | ||
| package com.meilisearch.sdk; | ||
|
|
||
| import lombok.*; | ||
| import org.json.JSONObject; | ||
|
|
||
| @Builder | ||
| @AllArgsConstructor(access = AccessLevel.PACKAGE) | ||
| @NoArgsConstructor(access = AccessLevel.PACKAGE) | ||
| @Getter | ||
| @Setter | ||
| public class ExportIndexFilter { | ||
| private String filter; | ||
| @Builder.Default private boolean overrideSettings = false; | ||
|
|
||
| /** | ||
| * Method that returns the JSON String of the ExportRequest | ||
| * | ||
| * @return JSON String of the ExportRequest query | ||
| */ | ||
| @Override | ||
| public String toString() { | ||
| JSONObject jsonObject = | ||
| new JSONObject() | ||
| .putOpt("filter", this.filter) | ||
| .putOpt("overrideSettings", this.overrideSettings); | ||
| return jsonObject.toString(); | ||
| } | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,33 @@ | ||
| package com.meilisearch.sdk; | ||
|
|
||
| import java.util.Map; | ||
| import lombok.*; | ||
| import org.json.JSONObject; | ||
|
|
||
| @Builder | ||
| @AllArgsConstructor(access = AccessLevel.PACKAGE) | ||
| @NoArgsConstructor(access = AccessLevel.PACKAGE) | ||
| @Getter | ||
| @Setter | ||
| public class ExportRequest { | ||
| private String url; | ||
| private String apiKey; | ||
| private String payloadSize; | ||
| private Map<String, ExportIndexFilter> indexes; | ||
|
|
||
| /** | ||
| * Method that returns the JSON String of the ExportRequest | ||
| * | ||
| * @return JSON String of the ExportRequest query | ||
| */ | ||
| @Override | ||
| public String toString() { | ||
| JSONObject jsonObject = | ||
| new JSONObject() | ||
| .put("url", this.url) | ||
| .putOpt("apiKey", this.apiKey) | ||
| .putOpt("payloadSize", this.payloadSize) | ||
| .putOpt("indexes", this.indexes); | ||
| return jsonObject.toString(); | ||
|
Comment on lines
+25
to
+31
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Do not expose secrets in
Apply this diff to redact the key: - JSONObject jsonObject =
- new JSONObject()
- .put("url", this.url)
- .putOpt("apiKey", this.apiKey)
- .putOpt("payloadSize", this.payloadSize)
- .putOpt("indexes", this.indexes);
+ String redactedApiKey = (this.apiKey == null) ? null : "REDACTED";
+ JSONObject jsonObject =
+ new JSONObject()
+ .put("url", this.url)
+ .putOpt("apiKey", redactedApiKey)
+ .putOpt("payloadSize", this.payloadSize)
+ .putOpt("indexes", this.indexes);
return jsonObject.toString();If you need an unredacted JSON string for tests, consider adding a dedicated method like 🤖 Prompt for AI Agents |
||
| } | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,100 @@ | ||
| package com.meilisearch.sdk; | ||
|
|
||
| import static org.hamcrest.MatcherAssert.assertThat; | ||
| import static org.hamcrest.Matchers.equalTo; | ||
| import static org.hamcrest.Matchers.is; | ||
| import static org.hamcrest.Matchers.nullValue; | ||
|
|
||
| import java.util.HashMap; | ||
| import java.util.Map; | ||
| import org.json.JSONObject; | ||
| import org.junit.jupiter.api.Test; | ||
|
|
||
| public class ExportRequestTest { | ||
|
|
||
| @Test | ||
| void toStringSimpleExportIndexFilter() { | ||
| ExportIndexFilter filter = ExportIndexFilter.builder().build(); | ||
| String expected = "{\"overrideSettings\":false}"; | ||
| assertThat(filter.toString(), is(equalTo(expected))); | ||
| assertThat(filter.getFilter(), is(nullValue())); | ||
| assertThat(filter.isOverrideSettings(), is(false)); | ||
| } | ||
|
|
||
| @Test | ||
| void toStringExportIndexFilterWithOverride() { | ||
| ExportIndexFilter filter = ExportIndexFilter.builder().overrideSettings(true).build(); | ||
| String expected = "{\"overrideSettings\":true}"; | ||
| assertThat(filter.toString(), is(equalTo(expected))); | ||
| assertThat(filter.isOverrideSettings(), is(true)); | ||
| } | ||
|
|
||
| @Test | ||
| void toStringExportIndexFilterWithFilter() { | ||
| ExportIndexFilter filter = ExportIndexFilter.builder().filter("status = 'active'").build(); | ||
| String expected = "{\"filter\":\"status = 'active'\",\"overrideSettings\":false}"; | ||
| assertThat(filter.toString(), is(equalTo(expected))); | ||
| assertThat(filter.getFilter(), is(equalTo("status = 'active'"))); | ||
| } | ||
|
|
||
| @Test | ||
| void toStringSimpleExportRequest() { | ||
| ExportRequest request = | ||
| ExportRequest.builder().url("http://localhost:7711").payloadSize("123 MiB").build(); | ||
| JSONObject json = new JSONObject(request.toString()); | ||
| assertThat(json.getString("url"), is(equalTo("http://localhost:7711"))); | ||
| assertThat(json.getString("payloadSize"), is(equalTo("123 MiB"))); | ||
| assertThat(json.isNull("apiKey"), is(true)); | ||
| assertThat(json.isNull("indexes"), is(true)); | ||
| } | ||
|
|
||
| @Test | ||
| void toStringExportRequestWithIndexes() { | ||
| Map<String, ExportIndexFilter> indexes = new HashMap<>(); | ||
| indexes.put("*", ExportIndexFilter.builder().overrideSettings(true).build()); | ||
|
|
||
| ExportRequest request = | ||
| ExportRequest.builder() | ||
| .url("http://localhost:7711") | ||
| .payloadSize("123 MiB") | ||
| .indexes(indexes) | ||
| .build(); | ||
|
|
||
| String expected = | ||
| "{\"url\":\"http://localhost:7711\",\"payloadSize\":\"123 MiB\",\"indexes\":{\"*\":{\"overrideSettings\":true}}}"; | ||
| JSONObject expectedJson = new JSONObject(expected); | ||
| JSONObject json = new JSONObject(request.toString()); | ||
|
|
||
| assertThat(expectedJson.toString(), is(json.toString())); | ||
|
|
||
| assertThat(json.getString("url"), is(equalTo("http://localhost:7711"))); | ||
| assertThat(json.getString("payloadSize"), is(equalTo("123 MiB"))); | ||
| assertThat(json.isNull("apiKey"), is(true)); | ||
| JSONObject indexesJson = json.getJSONObject("indexes"); | ||
| JSONObject starIndex = indexesJson.getJSONObject("*"); | ||
| assertThat(starIndex.isNull("filter"), is(true)); | ||
| assertThat(starIndex.getBoolean("overrideSettings"), is(true)); | ||
| } | ||
|
|
||
| @Test | ||
| void gettersExportRequest() { | ||
| Map<String, ExportIndexFilter> indexes = new HashMap<>(); | ||
| indexes.put( | ||
| "myindex", | ||
| ExportIndexFilter.builder().filter("id > 10").overrideSettings(false).build()); | ||
|
|
||
| ExportRequest request = | ||
| ExportRequest.builder() | ||
| .url("http://localhost:7711") | ||
| .apiKey("mykey") | ||
| .payloadSize("50 MiB") | ||
| .indexes(indexes) | ||
| .build(); | ||
|
|
||
| assertThat(request.getUrl(), is(equalTo("http://localhost:7711"))); | ||
| assertThat(request.getApiKey(), is(equalTo("mykey"))); | ||
| assertThat(request.getPayloadSize(), is(equalTo("50 MiB"))); | ||
| assertThat(request.getIndexes().get("myindex").getFilter(), is(equalTo("id > 10"))); | ||
| assertThat(request.getIndexes().get("myindex").isOverrideSettings(), is(false)); | ||
| } | ||
| } |
Uh oh!
There was an error while loading. Please reload this page.