-
Notifications
You must be signed in to change notification settings - Fork 117
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'main' into bump-meilisearch-v1.13
- Loading branch information
Showing
11 changed files
with
286 additions
and
17 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
46 changes: 46 additions & 0 deletions
46
src/main/java/com/meilisearch/sdk/enums/OperationType.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
package com.meilisearch.sdk.enums; | ||
|
||
import com.fasterxml.jackson.annotation.JsonValue; | ||
import com.google.gson.annotations.SerializedName; | ||
|
||
/** | ||
* Enum for Operation Type | ||
* | ||
* @see <a href="https://www.meilisearch.com/docs/reference/api/tasks#type">API specification</a> | ||
*/ | ||
public enum OperationType { | ||
@SerializedName("indexCreation") | ||
INDEX_CREATION("indexCreation"), | ||
@SerializedName("indexUpdate") | ||
INDEX_UPDATE("indexUpdate"), | ||
@SerializedName("indexDeletion") | ||
INDEX_DELETE("indexDeletion"), | ||
@SerializedName("indexSwap") | ||
INDEX_SWAP("indexSwap"), | ||
@SerializedName("documentAdditionOrUpdate") | ||
DOCUMENT_UPSERT("documentAdditionOrUpdate"), | ||
@SerializedName("documentDeletion") | ||
DOCUMENT_DELETE("documentDeletion"), | ||
@SerializedName("settingsUpdate") | ||
SETTINGS_UPDATE("settingsUpdate"), | ||
@SerializedName("dumpCreation") | ||
DUMP_CREATE("dumpCreation"), | ||
@SerializedName("taskCancelation") | ||
TASK_CANCEL("taskCancelation"), | ||
@SerializedName("taskDeletion") | ||
TASK_DELETE("taskDeletion"), | ||
@SerializedName("snapshotCreation") | ||
SNAPSHOT_CREATE("snapshotCreation"); | ||
|
||
public final String operationType; | ||
|
||
OperationType(String operationType) { | ||
this.operationType = operationType; | ||
} | ||
|
||
@JsonValue | ||
@Override | ||
public String toString() { | ||
return this.operationType; | ||
} | ||
} |
19 changes: 19 additions & 0 deletions
19
src/main/java/com/meilisearch/sdk/model/CursorResults.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
package com.meilisearch.sdk.model; | ||
|
||
import java.util.List; | ||
import lombok.Data; | ||
|
||
/** | ||
* Data structure paginated response Currently used in : Batches. | ||
* | ||
* @see <a href="https://www.meilisearch.com/docs/reference/api/batches#response">API | ||
* specification</a> | ||
*/ | ||
@Data | ||
public class CursorResults<T> { | ||
private List<T> results; | ||
private int limit; | ||
private int from; | ||
private Integer next; | ||
private int total; | ||
} |
51 changes: 51 additions & 0 deletions
51
src/main/java/com/meilisearch/sdk/model/batch/req/BatchesQuery.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
package com.meilisearch.sdk.model.batch.req; | ||
|
||
import com.meilisearch.sdk.http.URLBuilder; | ||
import java.util.Date; | ||
import lombok.Data; | ||
import lombok.experimental.Accessors; | ||
|
||
/** | ||
* Data structure of a query parameter for batches route | ||
* | ||
* @see <a href="https://www.meilisearch.com/docs/reference/api/batches#query-parameters">API | ||
* specification</a> | ||
*/ | ||
@Data | ||
@Accessors(chain = true) | ||
public class BatchesQuery { | ||
private int[] uids; | ||
private int[] batchUids; | ||
private String[] types; | ||
private String[] statuses; | ||
private String[] indexUids; | ||
private int[] canceledBy; | ||
private Date beforeEnqueuedAt; | ||
private Date afterEnqueuedAt; | ||
private Date beforeStartedAt; | ||
private Date afterStartedAt; | ||
private Date beforeFinishedAt; | ||
private Date afterFinishedAt; | ||
private int limit = -1; | ||
private int from = -1; | ||
|
||
public String toQuery() { | ||
URLBuilder urlb = | ||
new URLBuilder() | ||
.addParameter("uids", this.getUids()) | ||
.addParameter("batchUids", this.getBatchUids()) | ||
.addParameter("types", this.getTypes()) | ||
.addParameter("statuses", this.getStatuses()) | ||
.addParameter("indexUids", this.getIndexUids()) | ||
.addParameter("canceledBy", this.getCanceledBy()) | ||
.addParameter("beforeEnqueuedAt", this.getBeforeEnqueuedAt()) | ||
.addParameter("afterEnqueuedAt", this.getAfterEnqueuedAt()) | ||
.addParameter("beforeStartedAt", this.getBeforeStartedAt()) | ||
.addParameter("afterStartedAt", this.getAfterStartedAt()) | ||
.addParameter("beforeFinishedAt", this.getBeforeFinishedAt()) | ||
.addParameter("afterFinishedAt", this.getAfterFinishedAt()) | ||
.addParameter("limit", this.getLimit()) | ||
.addParameter("from", this.getFrom()); | ||
return urlb.getURL(); | ||
} | ||
} |
21 changes: 21 additions & 0 deletions
21
src/main/java/com/meilisearch/sdk/model/batch/res/Batch.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
package com.meilisearch.sdk.model.batch.res; | ||
|
||
import com.meilisearch.sdk.model.TaskDetails; | ||
import lombok.Data; | ||
|
||
/** | ||
* Data structure of the batch object response | ||
* | ||
* @see <a href="https://www.meilisearch.com/docs/reference/api/batches#batch-object">API | ||
* specification</a> | ||
*/ | ||
@Data | ||
public class Batch { | ||
private int uid = 0; | ||
private TaskDetails details; | ||
private BatchProgress progress; | ||
private StatDetails stats; | ||
private String startedAt; | ||
private String finishedAt; | ||
private String duration; | ||
} |
10 changes: 10 additions & 0 deletions
10
src/main/java/com/meilisearch/sdk/model/batch/res/BatchProgress.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
package com.meilisearch.sdk.model.batch.res; | ||
|
||
import java.util.List; | ||
import lombok.Data; | ||
|
||
@Data | ||
class BatchProgress { | ||
private List<StepDetails> steps; | ||
private int percentage; | ||
} |
14 changes: 14 additions & 0 deletions
14
src/main/java/com/meilisearch/sdk/model/batch/res/StatDetails.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
package com.meilisearch.sdk.model.batch.res; | ||
|
||
import com.meilisearch.sdk.enums.OperationType; | ||
import com.meilisearch.sdk.model.TaskStatus; | ||
import java.util.Map; | ||
import lombok.Data; | ||
|
||
@Data | ||
public class StatDetails { | ||
private int totalNbTasks; | ||
private Map<TaskStatus, Integer> status; | ||
private Map<OperationType, Integer> types; | ||
private Map<String, Integer> indexUids; | ||
} |
10 changes: 10 additions & 0 deletions
10
src/main/java/com/meilisearch/sdk/model/batch/res/StepDetails.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
package com.meilisearch.sdk.model.batch.res; | ||
|
||
import lombok.Data; | ||
|
||
@Data | ||
class StepDetails { | ||
private String currentStep; | ||
private int finished; | ||
private int total; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
package com.meilisearch.integration; | ||
|
||
import static org.junit.jupiter.api.Assertions.*; | ||
|
||
import com.meilisearch.integration.classes.AbstractIT; | ||
import com.meilisearch.sdk.model.CursorResults; | ||
import com.meilisearch.sdk.model.batch.req.BatchesQuery; | ||
import com.meilisearch.sdk.model.batch.res.Batch; | ||
import org.junit.jupiter.api.*; | ||
|
||
@Tag("integration") | ||
public class BatchTest extends AbstractIT { | ||
|
||
@BeforeEach | ||
void setup() throws Exception { | ||
this.setUp(); | ||
this.setUpJacksonClient(); | ||
cleanup(); | ||
} | ||
|
||
@AfterAll | ||
static void cleanMeilisearch() { | ||
cleanup(); | ||
} | ||
|
||
/** Check if able to fetch a single batch by uid */ | ||
@Test | ||
void testGetBatch() { | ||
CursorResults<Batch> allBatches = client.getAllBatches(new BatchesQuery()); | ||
assertFalse(allBatches.getResults().isEmpty(), "No batches found"); | ||
int batchUid = allBatches.getResults().get(0).getUid(); | ||
|
||
Batch batch = client.getBatch(batchUid); | ||
|
||
assertNotNull(batch); | ||
assertEquals(batchUid, batch.getUid()); | ||
assertNotNull(batch.getDetails()); | ||
assertNotNull(batch.getStats()); | ||
assertTrue(batch.getStats().getTotalNbTasks() > 0); | ||
assertNotNull(batch.getStats().getStatus()); | ||
assertNotNull(batch.getStats().getTypes()); | ||
assertNotNull(batch.getStats().getIndexUids()); | ||
assertNotNull(batch.getDuration()); | ||
assertNotNull(batch.getStartedAt()); | ||
assertNotNull(batch.getFinishedAt()); | ||
// TODO: Add Check for progress to be non-null, but response always provides null | ||
} | ||
|
||
/** Check if able to fetch all batch data as page */ | ||
@Test | ||
void testGetAllBatches() { | ||
CursorResults<Batch> allBatches = client.getAllBatches(new BatchesQuery()); | ||
|
||
assertNotNull(allBatches); | ||
assertFalse(allBatches.getResults().isEmpty(), "Batch results should not be empty"); | ||
} | ||
} |