From 712820b2bb7f2946b359d7217601ef59c0666aea Mon Sep 17 00:00:00 2001 From: Hai Liang Wang Date: Wed, 24 May 2023 13:52:12 +0800 Subject: [PATCH] Fix status check and return --- pom.xml | 2 +- src/main/java/com/chatopera/bot/sdk/Chatbot.java | 13 ++++++++----- src/main/java/com/chatopera/bot/sdk/TrainMgr.java | 2 +- 3 files changed, 10 insertions(+), 7 deletions(-) diff --git a/pom.xml b/pom.xml index bbcc16a..6a7668d 100644 --- a/pom.xml +++ b/pom.xml @@ -6,7 +6,7 @@ com.chatopera.bot sdk - 3.5.3 + 3.5.4 sdk Java SDK for Chatopera Bot Service. Get Java API Docs at https://chatopera.github.io/chatopera-sample-java/apidocs/ diff --git a/src/main/java/com/chatopera/bot/sdk/Chatbot.java b/src/main/java/com/chatopera/bot/sdk/Chatbot.java index a62ff81..c9a5fb8 100644 --- a/src/main/java/com/chatopera/bot/sdk/Chatbot.java +++ b/src/main/java/com/chatopera/bot/sdk/Chatbot.java @@ -200,7 +200,7 @@ public Response command(final String method, String path, final JSONObject paylo } break; case "DELETE": - if(payload != null){ + if (payload != null) { result = RestAPI.delete(url.toString(), auth(method, fullPath.toString()), payload); } else { result = RestAPI.delete(url.toString(), auth(method, fullPath.toString())); @@ -232,8 +232,8 @@ public Response command(final String method, String path, final JSONObject paylo } } - if (result.has("msg")){ - if(result.isNull("msg")){ + if (result.has("msg")) { + if (result.isNull("msg")) { resp.setMsg(""); } else { resp.setMsg(result.getString("msg")); @@ -253,8 +253,11 @@ public Response command(final String method, String path, final JSONObject paylo if (result.has("total_page")) resp.setTotal_page(result.getInt("total_page")); - resp.setStatus(result.optJSONObject("status", new JSONObject())); - + if (result.has("status")) { + resp.setStatus(result.optJSONObject("status", new JSONObject())); + } else { + resp.setStatus(null); + } return resp; } diff --git a/src/main/java/com/chatopera/bot/sdk/TrainMgr.java b/src/main/java/com/chatopera/bot/sdk/TrainMgr.java index 52a7bb7..c484b2c 100644 --- a/src/main/java/com/chatopera/bot/sdk/TrainMgr.java +++ b/src/main/java/com/chatopera/bot/sdk/TrainMgr.java @@ -53,7 +53,7 @@ public TrainMgr(final String clientId, final String clientSecret) throws Malform */ public Status getStatus() throws ChatbotException, ResourceInvalidException { Response resp = this.chatbot.command("GET", "/clause/devver/build"); - if (resp.getRc() == 0) { + if (resp.getStatus() != null && resp.getStatus().has("retrain")) { Status status = new Status(resp.getStatus()); return status; } else {