From 3ed4b84b3a0cb3dc5c7ea8eb8cd7dc3e2b2cacfd Mon Sep 17 00:00:00 2001 From: Stanley Peng Date: Thu, 7 Nov 2024 23:51:13 -0800 Subject: [PATCH 1/4] serialize task errror object --- .../java/io/constructor/client/models/Task.java | 14 ++++++++++++++ .../io/constructor/client/TaskResponseTest.java | 14 ++++++++++++++ .../src/test/resources/response.task.error.json | 14 ++++++++++++++ 3 files changed, 42 insertions(+) create mode 100644 constructorio-client/src/test/resources/response.task.error.json diff --git a/constructorio-client/src/main/java/io/constructor/client/models/Task.java b/constructorio-client/src/main/java/io/constructor/client/models/Task.java index dd27092c..ca7e1f6b 100644 --- a/constructorio-client/src/main/java/io/constructor/client/models/Task.java +++ b/constructorio-client/src/main/java/io/constructor/client/models/Task.java @@ -32,6 +32,9 @@ public class Task { @SerializedName("result") private Object result; + @SerializedName("error") + private Object error; + /** * @return the id */ @@ -95,6 +98,13 @@ public Object getResult() { return result; } + /** + * @return the error + */ + public Object getError() { + return error; + } + public void setId(int id) { this.id = id; } @@ -130,4 +140,8 @@ public void setProtocol(String protocol) { public void setResult(Object result) { this.result = result; } + + public void setError(Object error) { + this.error = error; + } } diff --git a/constructorio-client/src/test/java/io/constructor/client/TaskResponseTest.java b/constructorio-client/src/test/java/io/constructor/client/TaskResponseTest.java index c1b30830..2cc3b8a5 100644 --- a/constructorio-client/src/test/java/io/constructor/client/TaskResponseTest.java +++ b/constructorio-client/src/test/java/io/constructor/client/TaskResponseTest.java @@ -30,6 +30,20 @@ public void createTaskResponseWithQueuedTaskShouldReturnAResult() throws Excepti assertNull(response.getResult()); } + @Test + public void createTaskResponseWithErrorTaskShouldReturnAResult() throws Exception { + String string = Utils.getTestResource("response.task.error.json"); + Task response = ConstructorIO.createTaskResponse(string); + JsonObject jsonObj = new Gson().toJsonTree(response.getError()).getAsJsonObject(); + + assertEquals("id exists", 100721281, response.getId()); + assertEquals("status exists", "FAILED", response.getStatus()); + assertEquals( + "Error message exists", + "IngestionError: The items file you have uploaded is empty. Please fix it and try again.", + jsonObj.get("message").getAsString()); + } + @Test public void createTaskResponseWithDoneTaskShouldReturnAResult() throws Exception { String string = Utils.getTestResource("response.task.done.json"); diff --git a/constructorio-client/src/test/resources/response.task.error.json b/constructorio-client/src/test/resources/response.task.error.json new file mode 100644 index 00000000..7114d3ea --- /dev/null +++ b/constructorio-client/src/test/resources/response.task.error.json @@ -0,0 +1,14 @@ +{ + "id": 100721281, + "status": "FAILED", + "submission_time": "2024-08-21T18:11:49", + "last_update": "2024-08-21T18:11:53", + "start_time": "2024-08-21T18:11:51", + "type": "ingestion", + "error": { + "message": "IngestionError: The items file you have uploaded is empty. Please fix it and try again." + }, + "filename": "filename", + "protocol": "http", + "ingestion_type": "patchdelta" +} \ No newline at end of file From 4bd7f61ee742066ab74735ba0da503c8b14e6755 Mon Sep 17 00:00:00 2001 From: Stanley Peng Date: Fri, 8 Nov 2024 00:00:05 -0800 Subject: [PATCH 2/4] lint --- .../src/test/java/io/constructor/client/TaskResponseTest.java | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/constructorio-client/src/test/java/io/constructor/client/TaskResponseTest.java b/constructorio-client/src/test/java/io/constructor/client/TaskResponseTest.java index 2cc3b8a5..49ea7bf4 100644 --- a/constructorio-client/src/test/java/io/constructor/client/TaskResponseTest.java +++ b/constructorio-client/src/test/java/io/constructor/client/TaskResponseTest.java @@ -40,7 +40,8 @@ public void createTaskResponseWithErrorTaskShouldReturnAResult() throws Exceptio assertEquals("status exists", "FAILED", response.getStatus()); assertEquals( "Error message exists", - "IngestionError: The items file you have uploaded is empty. Please fix it and try again.", + "IngestionError: The items file you have uploaded is empty. Please fix it and try" + + " again.", jsonObj.get("message").getAsString()); } From dac2619fa0945ce91ec7b2372368c1a9ef2fade3 Mon Sep 17 00:00:00 2001 From: Stanley Peng Date: Tue, 10 Dec 2024 12:02:50 -0800 Subject: [PATCH 3/4] add task error object --- .../io/constructor/client/models/Task.java | 6 +++--- .../constructor/client/models/TaskError.java | 21 +++++++++++++++++++ .../constructor/client/TaskResponseTest.java | 3 +-- 3 files changed, 25 insertions(+), 5 deletions(-) create mode 100644 constructorio-client/src/main/java/io/constructor/client/models/TaskError.java diff --git a/constructorio-client/src/main/java/io/constructor/client/models/Task.java b/constructorio-client/src/main/java/io/constructor/client/models/Task.java index ca7e1f6b..c5d18c1c 100644 --- a/constructorio-client/src/main/java/io/constructor/client/models/Task.java +++ b/constructorio-client/src/main/java/io/constructor/client/models/Task.java @@ -33,7 +33,7 @@ public class Task { private Object result; @SerializedName("error") - private Object error; + private TaskError error; /** * @return the id @@ -101,7 +101,7 @@ public Object getResult() { /** * @return the error */ - public Object getError() { + public TaskError getError() { return error; } @@ -141,7 +141,7 @@ public void setResult(Object result) { this.result = result; } - public void setError(Object error) { + public void setError(TaskError error) { this.error = error; } } diff --git a/constructorio-client/src/main/java/io/constructor/client/models/TaskError.java b/constructorio-client/src/main/java/io/constructor/client/models/TaskError.java new file mode 100644 index 00000000..7d68c007 --- /dev/null +++ b/constructorio-client/src/main/java/io/constructor/client/models/TaskError.java @@ -0,0 +1,21 @@ +package io.constructor.client.models; + +import com.google.gson.annotations.SerializedName; + +/** Constructor.io Task Error... uses Gson/Reflection to load data in */ +public class TaskError { + + @SerializedName("message") + private String message; + + /** + * @return the error message + */ + public String getMessage() { + return message; + } + public void setMessage(String message) { + this.message = message; + } + +} diff --git a/constructorio-client/src/test/java/io/constructor/client/TaskResponseTest.java b/constructorio-client/src/test/java/io/constructor/client/TaskResponseTest.java index 49ea7bf4..2f85b733 100644 --- a/constructorio-client/src/test/java/io/constructor/client/TaskResponseTest.java +++ b/constructorio-client/src/test/java/io/constructor/client/TaskResponseTest.java @@ -34,7 +34,6 @@ public void createTaskResponseWithQueuedTaskShouldReturnAResult() throws Excepti public void createTaskResponseWithErrorTaskShouldReturnAResult() throws Exception { String string = Utils.getTestResource("response.task.error.json"); Task response = ConstructorIO.createTaskResponse(string); - JsonObject jsonObj = new Gson().toJsonTree(response.getError()).getAsJsonObject(); assertEquals("id exists", 100721281, response.getId()); assertEquals("status exists", "FAILED", response.getStatus()); @@ -42,7 +41,7 @@ public void createTaskResponseWithErrorTaskShouldReturnAResult() throws Exceptio "Error message exists", "IngestionError: The items file you have uploaded is empty. Please fix it and try" + " again.", - jsonObj.get("message").getAsString()); + response.getError().getMessage()); } @Test From 8bd32f072a06271da081ef504e75565e91dff2bd Mon Sep 17 00:00:00 2001 From: Stanley Peng Date: Tue, 24 Dec 2024 09:59:50 -0800 Subject: [PATCH 4/4] lint --- .../src/main/java/io/constructor/client/models/TaskError.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/constructorio-client/src/main/java/io/constructor/client/models/TaskError.java b/constructorio-client/src/main/java/io/constructor/client/models/TaskError.java index 7d68c007..a9884e17 100644 --- a/constructorio-client/src/main/java/io/constructor/client/models/TaskError.java +++ b/constructorio-client/src/main/java/io/constructor/client/models/TaskError.java @@ -14,8 +14,8 @@ public class TaskError { public String getMessage() { return message; } + public void setMessage(String message) { this.message = message; } - }