Skip to content

Commit ae6f5c4

Browse files
authored
Merge pull request #41 from meilisearch/get_update_returns_update_status_object
GetUpdate returns a StatusUpdate instance instead of String
2 parents 5e0cf0e + 893e66b commit ae6f5c4

File tree

2 files changed

+14
-14
lines changed

2 files changed

+14
-14
lines changed

src/main/java/com/meilisearch/sdk/Index.java

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,8 @@ public class Index implements Serializable {
3232
@ToString.Exclude
3333
Documents documents;
3434

35+
Gson gson = new Gson();
36+
3537
/**
3638
* Set the Meilisearch configuration for the index
3739
*
@@ -124,8 +126,11 @@ public String search(String q) throws Exception {
124126
* @return Meilisearch API response
125127
* @throws Exception If something goes wrong
126128
*/
127-
public String getUpdate(int updateId) throws Exception {
128-
return this.documents.getUpdate(this.uid, updateId);
129+
public UpdateStatus getUpdate(int updateId) throws Exception {
130+
return this.gson.fromJson(
131+
this.documents.getUpdate(this.uid, updateId),
132+
UpdateStatus.class
133+
);
129134
}
130135

131136
/**
@@ -135,8 +140,10 @@ public String getUpdate(int updateId) throws Exception {
135140
* @throws Exception If something goes wrong
136141
*/
137142
public UpdateStatus[] getUpdates() throws Exception {
138-
Gson gson = new Gson();
139-
return gson.fromJson(this.documents.getUpdates(this.uid), UpdateStatus[].class);
143+
return this.gson.fromJson(
144+
this.documents.getUpdates(this.uid),
145+
UpdateStatus[].class
146+
);
140147
}
141148

142149
/**
@@ -160,7 +167,6 @@ public void waitForPendingUpdate(int updateId) throws Exception {
160167
* @throws Exception if timeout is reached
161168
*/
162169
public void waitForPendingUpdate(int updateId, int timeoutInMs, int intervalInMs) throws Exception {
163-
Gson gson = new Gson();
164170
UpdateStatus updateStatus;
165171
String status = "";
166172
long startTime = new Date().getTime();
@@ -170,10 +176,7 @@ public void waitForPendingUpdate(int updateId, int timeoutInMs, int intervalInMs
170176
if (elapsedTime >= timeoutInMs){
171177
throw new Exception();
172178
}
173-
updateStatus = gson.fromJson(
174-
this.getUpdate(updateId),
175-
UpdateStatus.class
176-
);
179+
updateStatus = this.getUpdate(updateId);
177180
status = updateStatus.getStatus();
178181
Thread.sleep(intervalInMs);
179182
elapsedTime = new Date().getTime() - startTime;

src/test/java/com/meilisearch/integration/IndexesTest.java

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -101,11 +101,8 @@ public void testWaitForPendingUpdate() throws Exception {
101101

102102
index.waitForPendingUpdate(updateInfo.getUpdateId());
103103

104-
UpdateStatus updateStatus = this.gson.fromJson(
105-
index.getUpdate(updateInfo.getUpdateId()),
106-
UpdateStatus.class
107-
);
108-
104+
UpdateStatus updateStatus = index.getUpdate(updateInfo.getUpdateId());
105+
109106
assertEquals("processed", updateStatus.getStatus());
110107

111108
client.deleteIndex(index.getUid());

0 commit comments

Comments
 (0)