From 83fa0fec11c802be921b387951095e102c0f6b33 Mon Sep 17 00:00:00 2001 From: Ana Bozianu Date: Tue, 5 Jul 2016 17:58:31 +0300 Subject: [PATCH] RM-2890 - updated json structure --- .../org/alfresco/util/WebScriptUtils.java | 26 +++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/rm-community/rm-community-repo/source/java/org/alfresco/util/WebScriptUtils.java b/rm-community/rm-community-repo/source/java/org/alfresco/util/WebScriptUtils.java index 28c1fe279f..cc0ac75830 100644 --- a/rm-community/rm-community-repo/source/java/org/alfresco/util/WebScriptUtils.java +++ b/rm-community/rm-community-repo/source/java/org/alfresco/util/WebScriptUtils.java @@ -400,4 +400,30 @@ public final class WebScriptUtils final int status = e.getStatus(); return status >= lowerLimitInclusive && status < upperLimitExclusive; } + + /** + * Gets the {@link JSONObject} value of a given key from a json object + * + * @param jsonObject The json object + * @param key The key + * @return The {@link JSONObject} value of the given key from the json object + */ + public static JSONObject getValueFromJSONObject(JSONObject jsonObject, String key) + { + mandatory("jsonObject", jsonObject); + mandatoryString("key", key); + + JSONObject value = null; + + try + { + value = jsonObject.getJSONObject(key); + } + catch (JSONException error) + { + throw new WebScriptException(Status.STATUS_BAD_REQUEST, "Could not get value for the key '" + key + "'.", error); + } + + return value; + } }