@Test public void testUpdateActionValue() throws Exception { final String jsonPathQuery = "$.store.book[0].category"; final Map<String, String> result = editJson.execute(jsonFile, jsonPathQuery, "update", "", "newCategory", VALIDATE_VALUE_FALSE); assertEquals("{\"store\":{\"book\":[{\"category\":\"newCategory\",\"author\":\"Nigel Rees\",\"title\":" + "\"Sayings of the Century\",\"price\":8.95},{\"category\":\"fiction\",\"author\":\"Evelyn Waugh\"," + "\"title\":\"Sword of Honour\",\"price\":12.99}],\"bicycle\":{\"color\":\"red\",\"price\":19.95}}," + "\"arrayTest\":[1,2,3]}", result.get(RETURN_RESULT)); }
@Action(name = "Edit Json", outputs = { @Output(OutputNames.RETURN_RESULT), @Output(OutputNames.RETURN_CODE), @Output(OutputNames.EXCEPTION) }, responses = { @Response(text = ResponseNames.SUCCESS, field = OutputNames.RETURN_CODE, value = ReturnCodes.SUCCESS, matchType = MatchType.COMPARE_EQUAL, responseType = ResponseType.RESOLVED), @Response(text = ResponseNames.FAILURE, field = OutputNames.RETURN_CODE, value = ReturnCodes.FAILURE, matchType = MatchType.COMPARE_EQUAL, responseType = ResponseType.ERROR, isOnFail = true) }) public Map<String, String> execute(@Param(value = Constants.InputNames.JSON_OBJECT, required = true) String jsonObject, @Param(value = Constants.InputNames.JSON_PATH, required = true) String jsonPath, @Param(value = Constants.InputNames.ACTION, required = true) String action, @Param(value = Constants.InputNames.NAME) String name, @Param(value = Constants.InputNames.VALUE) String value, @Param(value = Constants.InputNames.VALIDATE_VALUE) String validateValue) { Map<String, String> returnResult = new HashMap<>(); JsonContext jsonContext; boolean validateValueBoolean = JsonUtils.parseBooleanWithDefault(validateValue, true); try { JsonUtils.validateEditJsonInputs(jsonObject, jsonPath, action, name, value); jsonContext = JsonUtils.getValidJsonContext(jsonObject); } catch (Exception e) { return populateResult(returnResult, e); } final ActionsEnum actionEnum = ActionsEnum.valueOf(action); String result; try { Object valueObject; JsonContext valueJsonContext; try { valueJsonContext = JsonUtils.getValidJsonContext(value); valueObject = valueJsonContext.json(); } catch (Exception e) { if (!validateValueBoolean || !actionEnum.getNeedValue()) { valueObject = value; } else { throw e; } } Object json = editJson(jsonPath, action, name, valueObject, jsonContext); result = json.toString(); } catch (Exception e) { return populateResult(returnResult, e); } return populateResult(returnResult, result, null); }
EditJson { @Action(name = "Edit Json", outputs = { @Output(OutputNames.RETURN_RESULT), @Output(OutputNames.RETURN_CODE), @Output(OutputNames.EXCEPTION) }, responses = { @Response(text = ResponseNames.SUCCESS, field = OutputNames.RETURN_CODE, value = ReturnCodes.SUCCESS, matchType = MatchType.COMPARE_EQUAL, responseType = ResponseType.RESOLVED), @Response(text = ResponseNames.FAILURE, field = OutputNames.RETURN_CODE, value = ReturnCodes.FAILURE, matchType = MatchType.COMPARE_EQUAL, responseType = ResponseType.ERROR, isOnFail = true) }) public Map<String, String> execute(@Param(value = Constants.InputNames.JSON_OBJECT, required = true) String jsonObject, @Param(value = Constants.InputNames.JSON_PATH, required = true) String jsonPath, @Param(value = Constants.InputNames.ACTION, required = true) String action, @Param(value = Constants.InputNames.NAME) String name, @Param(value = Constants.InputNames.VALUE) String value, @Param(value = Constants.InputNames.VALIDATE_VALUE) String validateValue) { Map<String, String> returnResult = new HashMap<>(); JsonContext jsonContext; boolean validateValueBoolean = JsonUtils.parseBooleanWithDefault(validateValue, true); try { JsonUtils.validateEditJsonInputs(jsonObject, jsonPath, action, name, value); jsonContext = JsonUtils.getValidJsonContext(jsonObject); } catch (Exception e) { return populateResult(returnResult, e); } final ActionsEnum actionEnum = ActionsEnum.valueOf(action); String result; try { Object valueObject; JsonContext valueJsonContext; try { valueJsonContext = JsonUtils.getValidJsonContext(value); valueObject = valueJsonContext.json(); } catch (Exception e) { if (!validateValueBoolean || !actionEnum.getNeedValue()) { valueObject = value; } else { throw e; } } Object json = editJson(jsonPath, action, name, valueObject, jsonContext); result = json.toString(); } catch (Exception e) { return populateResult(returnResult, e); } return populateResult(returnResult, result, null); } }
EditJson { @Action(name = "Edit Json", outputs = { @Output(OutputNames.RETURN_RESULT), @Output(OutputNames.RETURN_CODE), @Output(OutputNames.EXCEPTION) }, responses = { @Response(text = ResponseNames.SUCCESS, field = OutputNames.RETURN_CODE, value = ReturnCodes.SUCCESS, matchType = MatchType.COMPARE_EQUAL, responseType = ResponseType.RESOLVED), @Response(text = ResponseNames.FAILURE, field = OutputNames.RETURN_CODE, value = ReturnCodes.FAILURE, matchType = MatchType.COMPARE_EQUAL, responseType = ResponseType.ERROR, isOnFail = true) }) public Map<String, String> execute(@Param(value = Constants.InputNames.JSON_OBJECT, required = true) String jsonObject, @Param(value = Constants.InputNames.JSON_PATH, required = true) String jsonPath, @Param(value = Constants.InputNames.ACTION, required = true) String action, @Param(value = Constants.InputNames.NAME) String name, @Param(value = Constants.InputNames.VALUE) String value, @Param(value = Constants.InputNames.VALIDATE_VALUE) String validateValue) { Map<String, String> returnResult = new HashMap<>(); JsonContext jsonContext; boolean validateValueBoolean = JsonUtils.parseBooleanWithDefault(validateValue, true); try { JsonUtils.validateEditJsonInputs(jsonObject, jsonPath, action, name, value); jsonContext = JsonUtils.getValidJsonContext(jsonObject); } catch (Exception e) { return populateResult(returnResult, e); } final ActionsEnum actionEnum = ActionsEnum.valueOf(action); String result; try { Object valueObject; JsonContext valueJsonContext; try { valueJsonContext = JsonUtils.getValidJsonContext(value); valueObject = valueJsonContext.json(); } catch (Exception e) { if (!validateValueBoolean || !actionEnum.getNeedValue()) { valueObject = value; } else { throw e; } } Object json = editJson(jsonPath, action, name, valueObject, jsonContext); result = json.toString(); } catch (Exception e) { return populateResult(returnResult, e); } return populateResult(returnResult, result, null); }  }
EditJson { @Action(name = "Edit Json", outputs = { @Output(OutputNames.RETURN_RESULT), @Output(OutputNames.RETURN_CODE), @Output(OutputNames.EXCEPTION) }, responses = { @Response(text = ResponseNames.SUCCESS, field = OutputNames.RETURN_CODE, value = ReturnCodes.SUCCESS, matchType = MatchType.COMPARE_EQUAL, responseType = ResponseType.RESOLVED), @Response(text = ResponseNames.FAILURE, field = OutputNames.RETURN_CODE, value = ReturnCodes.FAILURE, matchType = MatchType.COMPARE_EQUAL, responseType = ResponseType.ERROR, isOnFail = true) }) public Map<String, String> execute(@Param(value = Constants.InputNames.JSON_OBJECT, required = true) String jsonObject, @Param(value = Constants.InputNames.JSON_PATH, required = true) String jsonPath, @Param(value = Constants.InputNames.ACTION, required = true) String action, @Param(value = Constants.InputNames.NAME) String name, @Param(value = Constants.InputNames.VALUE) String value, @Param(value = Constants.InputNames.VALIDATE_VALUE) String validateValue) { Map<String, String> returnResult = new HashMap<>(); JsonContext jsonContext; boolean validateValueBoolean = JsonUtils.parseBooleanWithDefault(validateValue, true); try { JsonUtils.validateEditJsonInputs(jsonObject, jsonPath, action, name, value); jsonContext = JsonUtils.getValidJsonContext(jsonObject); } catch (Exception e) { return populateResult(returnResult, e); } final ActionsEnum actionEnum = ActionsEnum.valueOf(action); String result; try { Object valueObject; JsonContext valueJsonContext; try { valueJsonContext = JsonUtils.getValidJsonContext(value); valueObject = valueJsonContext.json(); } catch (Exception e) { if (!validateValueBoolean || !actionEnum.getNeedValue()) { valueObject = value; } else { throw e; } } Object json = editJson(jsonPath, action, name, valueObject, jsonContext); result = json.toString(); } catch (Exception e) { return populateResult(returnResult, e); } return populateResult(returnResult, result, null); }  @Action(name = "Edit Json", outputs = { @Output(OutputNames.RETURN_RESULT), @Output(OutputNames.RETURN_CODE), @Output(OutputNames.EXCEPTION) }, responses = { @Response(text = ResponseNames.SUCCESS, field = OutputNames.RETURN_CODE, value = ReturnCodes.SUCCESS, matchType = MatchType.COMPARE_EQUAL, responseType = ResponseType.RESOLVED), @Response(text = ResponseNames.FAILURE, field = OutputNames.RETURN_CODE, value = ReturnCodes.FAILURE, matchType = MatchType.COMPARE_EQUAL, responseType = ResponseType.ERROR, isOnFail = true) }) Map<String, String> execute(@Param(value = Constants.InputNames.JSON_OBJECT, required = true) String jsonObject,
                                       @Param(value = Constants.InputNames.JSON_PATH, required = true) String jsonPath,
                                       @Param(value = Constants.InputNames.ACTION, required = true) String action,
                                       @Param(value = Constants.InputNames.NAME) String name,
                                       @Param(value = Constants.InputNames.VALUE) String value,
                                       @Param(value = Constants.InputNames.VALIDATE_VALUE) String validateValue); }
EditJson { @Action(name = "Edit Json", outputs = { @Output(OutputNames.RETURN_RESULT), @Output(OutputNames.RETURN_CODE), @Output(OutputNames.EXCEPTION) }, responses = { @Response(text = ResponseNames.SUCCESS, field = OutputNames.RETURN_CODE, value = ReturnCodes.SUCCESS, matchType = MatchType.COMPARE_EQUAL, responseType = ResponseType.RESOLVED), @Response(text = ResponseNames.FAILURE, field = OutputNames.RETURN_CODE, value = ReturnCodes.FAILURE, matchType = MatchType.COMPARE_EQUAL, responseType = ResponseType.ERROR, isOnFail = true) }) public Map<String, String> execute(@Param(value = Constants.InputNames.JSON_OBJECT, required = true) String jsonObject, @Param(value = Constants.InputNames.JSON_PATH, required = true) String jsonPath, @Param(value = Constants.InputNames.ACTION, required = true) String action, @Param(value = Constants.InputNames.NAME) String name, @Param(value = Constants.InputNames.VALUE) String value, @Param(value = Constants.InputNames.VALIDATE_VALUE) String validateValue) { Map<String, String> returnResult = new HashMap<>(); JsonContext jsonContext; boolean validateValueBoolean = JsonUtils.parseBooleanWithDefault(validateValue, true); try { JsonUtils.validateEditJsonInputs(jsonObject, jsonPath, action, name, value); jsonContext = JsonUtils.getValidJsonContext(jsonObject); } catch (Exception e) { return populateResult(returnResult, e); } final ActionsEnum actionEnum = ActionsEnum.valueOf(action); String result; try { Object valueObject; JsonContext valueJsonContext; try { valueJsonContext = JsonUtils.getValidJsonContext(value); valueObject = valueJsonContext.json(); } catch (Exception e) { if (!validateValueBoolean || !actionEnum.getNeedValue()) { valueObject = value; } else { throw e; } } Object json = editJson(jsonPath, action, name, valueObject, jsonContext); result = json.toString(); } catch (Exception e) { return populateResult(returnResult, e); } return populateResult(returnResult, result, null); }  @Action(name = "Edit Json", outputs = { @Output(OutputNames.RETURN_RESULT), @Output(OutputNames.RETURN_CODE), @Output(OutputNames.EXCEPTION) }, responses = { @Response(text = ResponseNames.SUCCESS, field = OutputNames.RETURN_CODE, value = ReturnCodes.SUCCESS, matchType = MatchType.COMPARE_EQUAL, responseType = ResponseType.RESOLVED), @Response(text = ResponseNames.FAILURE, field = OutputNames.RETURN_CODE, value = ReturnCodes.FAILURE, matchType = MatchType.COMPARE_EQUAL, responseType = ResponseType.ERROR, isOnFail = true) }) Map<String, String> execute(@Param(value = Constants.InputNames.JSON_OBJECT, required = true) String jsonObject,
                                       @Param(value = Constants.InputNames.JSON_PATH, required = true) String jsonPath,
                                       @Param(value = Constants.InputNames.ACTION, required = true) String action,
                                       @Param(value = Constants.InputNames.NAME) String name,
                                       @Param(value = Constants.InputNames.VALUE) String value,
                                       @Param(value = Constants.InputNames.VALIDATE_VALUE) String validateValue);  }