From 04761d09b9000d249387c4531ff36c5a88db0228 Mon Sep 17 00:00:00 2001 From: Ryan Doherty Date: Fri, 19 Jan 2024 10:59:54 -0500 Subject: [PATCH 1/3] Add check for empty request and missing properties so 400s are returned instead of NPEs/500s --- .../java/org/gusdb/wdk/service/service/AnswerService.java | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/Service/src/main/java/org/gusdb/wdk/service/service/AnswerService.java b/Service/src/main/java/org/gusdb/wdk/service/service/AnswerService.java index 74497498b..d284af881 100644 --- a/Service/src/main/java/org/gusdb/wdk/service/service/AnswerService.java +++ b/Service/src/main/java/org/gusdb/wdk/service/service/AnswerService.java @@ -277,6 +277,11 @@ static AnswerRequest parseAnswerRequest(Question question, String reporterName, JSONObject requestBody, WdkModel wdkModel, User sessionUser, boolean avoidCacheHit) throws RequestMisformatException, DataValidationException, WdkModelException { + if (requestBody == null || !requestBody.has(JsonKeys.SEARCH_CONFIG) || !requestBody.has(JsonKeys.REPORT_CONFIG)) { + throw new RequestMisformatException("Request body must not be null and must contain '" + + JsonKeys.SEARCH_CONFIG + "' and '" + JsonKeys.REPORT_CONFIG + "' properties."); + } + // parse view filters FilterOptionListBuilder viewFilters = AnswerSpecServiceFormat.parseViewFilters(requestBody); From a4fbdca0c59064998e77469d46415851df5cd35c Mon Sep 17 00:00:00 2001 From: Jeremy Myers Date: Wed, 24 Jan 2024 13:23:11 -0500 Subject: [PATCH 2/3] Add isMultiLine property to stringParam response --- .../gusdb/wdk/service/formatter/param/StringParamFormatter.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Service/src/main/java/org/gusdb/wdk/service/formatter/param/StringParamFormatter.java b/Service/src/main/java/org/gusdb/wdk/service/formatter/param/StringParamFormatter.java index aeb9074ba..935d3881b 100644 --- a/Service/src/main/java/org/gusdb/wdk/service/formatter/param/StringParamFormatter.java +++ b/Service/src/main/java/org/gusdb/wdk/service/formatter/param/StringParamFormatter.java @@ -15,7 +15,7 @@ public class StringParamFormatter extends ParamFormatter { @Override public > JSONObject getJson(DisplayablyValid spec) throws WdkModelException { - return getBaseJson(spec).put(JsonKeys.LENGTH, _param.getLength()); + return getBaseJson(spec).put(JsonKeys.LENGTH, _param.getLength()).put(JsonKeys.IS_MULTILINE, _param.getMultiLine()); } @Override From 2ce99dd8f430bac26a7e69e6f8a4a946ae544fe7 Mon Sep 17 00:00:00 2001 From: Jeremy Myers Date: Wed, 24 Jan 2024 16:36:32 -0500 Subject: [PATCH 3/3] Add isNumber property to stringParam response --- Model/src/main/java/org/gusdb/wdk/core/api/JsonKeys.java | 1 + .../wdk/service/formatter/param/StringParamFormatter.java | 5 ++++- 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/Model/src/main/java/org/gusdb/wdk/core/api/JsonKeys.java b/Model/src/main/java/org/gusdb/wdk/core/api/JsonKeys.java index b3d1d446c..cef857d65 100644 --- a/Model/src/main/java/org/gusdb/wdk/core/api/JsonKeys.java +++ b/Model/src/main/java/org/gusdb/wdk/core/api/JsonKeys.java @@ -69,6 +69,7 @@ public class JsonKeys { public static final String IS_REMOVABLE = "isRemovable"; public static final String IS_REQUIRED = "isRequired"; public static final String IS_MULTILINE = "isMultiLine"; + public static final String IS_NUMBER = "isNumber"; public static final String IS_PUBLIC = "isPublic"; public static final String USE_BASKET = "useBasket"; public static final String SCOPES = "scopes"; diff --git a/Service/src/main/java/org/gusdb/wdk/service/formatter/param/StringParamFormatter.java b/Service/src/main/java/org/gusdb/wdk/service/formatter/param/StringParamFormatter.java index 935d3881b..2b7886ae6 100644 --- a/Service/src/main/java/org/gusdb/wdk/service/formatter/param/StringParamFormatter.java +++ b/Service/src/main/java/org/gusdb/wdk/service/formatter/param/StringParamFormatter.java @@ -15,7 +15,10 @@ public class StringParamFormatter extends ParamFormatter { @Override public > JSONObject getJson(DisplayablyValid spec) throws WdkModelException { - return getBaseJson(spec).put(JsonKeys.LENGTH, _param.getLength()).put(JsonKeys.IS_MULTILINE, _param.getMultiLine()); + return getBaseJson(spec) + .put(JsonKeys.LENGTH, _param.getLength()) + .put(JsonKeys.IS_MULTILINE, _param.getMultiLine()) + .put(JsonKeys.IS_NUMBER, _param.isNumber()); } @Override