@Test public void testSimpleStringArray() throws Exception { String array1 = "[\"one\",\"two\",\"three\"]"; String array2 = "[\"one\",\"two\",\"three\"]"; final Map<String, String> returnResult = mergeArrays.execute(array1, array2); assertEquals("[\"one\",\"two\",\"three\",\"one\",\"two\",\"three\"]", returnResult.get(RETURN_RESULT)); }
@Action(name = "Merge Arrays", 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.ARRAY, required = true) String array1, @Param(value = Constants.InputNames.ARRAY, required = true) String array2) { Map<String, String> returnResult = new HashMap<>(); if (StringUtilities.isBlank(array1)) { final String exceptionValue = NOT_A_VALID_JSON_ARRAY_MESSAGE + ARRAY1_MESSAGE.replaceFirst("=", EMPTY_STRING); return populateResult(returnResult, exceptionValue, new Exception(exceptionValue)); } if (StringUtilities.isBlank(array2)) { final String exceptionValue = NOT_A_VALID_JSON_ARRAY_MESSAGE + ARRAY2_MESSAGE.replaceFirst("=", EMPTY_STRING); return populateResult(returnResult, new Exception(exceptionValue)); } JsonNode jsonNode1; JsonNode jsonNode2; ObjectMapper mapper = new ObjectMapper(); try { jsonNode1 = mapper.readTree(array1); } catch (IOException exception) { final String value = INVALID_JSON_OBJECT_PROVIDED_EXCEPTION_MESSAGE + ARRAY1_MESSAGE + array1; return populateResult(returnResult, value, exception); } try { jsonNode2 = mapper.readTree(array2); } catch (IOException exception) { final String value = INVALID_JSON_OBJECT_PROVIDED_EXCEPTION_MESSAGE + ARRAY2_MESSAGE + array2; return populateResult(returnResult, value, exception); } final String result; if (jsonNode1 instanceof ArrayNode && jsonNode2 instanceof ArrayNode) { final ArrayNode asJsonArray1 = (ArrayNode) jsonNode1; final ArrayNode asJsonArray2 = (ArrayNode) jsonNode2; final ArrayNode asJsonArrayResult = new ArrayNode(mapper.getNodeFactory()); asJsonArrayResult.addAll(asJsonArray1); asJsonArrayResult.addAll(asJsonArray2); result = asJsonArrayResult.toString(); } else { result = NOT_A_VALID_JSON_ARRAY_MESSAGE + ARRAY1_MESSAGE + array1 + ARRAY2_MESSAGE + array2; return populateResult(returnResult, new Exception(result)); } return populateResult(returnResult, result, null); }
MergeArrays { @Action(name = "Merge Arrays", 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.ARRAY, required = true) String array1, @Param(value = Constants.InputNames.ARRAY, required = true) String array2) { Map<String, String> returnResult = new HashMap<>(); if (StringUtilities.isBlank(array1)) { final String exceptionValue = NOT_A_VALID_JSON_ARRAY_MESSAGE + ARRAY1_MESSAGE.replaceFirst("=", EMPTY_STRING); return populateResult(returnResult, exceptionValue, new Exception(exceptionValue)); } if (StringUtilities.isBlank(array2)) { final String exceptionValue = NOT_A_VALID_JSON_ARRAY_MESSAGE + ARRAY2_MESSAGE.replaceFirst("=", EMPTY_STRING); return populateResult(returnResult, new Exception(exceptionValue)); } JsonNode jsonNode1; JsonNode jsonNode2; ObjectMapper mapper = new ObjectMapper(); try { jsonNode1 = mapper.readTree(array1); } catch (IOException exception) { final String value = INVALID_JSON_OBJECT_PROVIDED_EXCEPTION_MESSAGE + ARRAY1_MESSAGE + array1; return populateResult(returnResult, value, exception); } try { jsonNode2 = mapper.readTree(array2); } catch (IOException exception) { final String value = INVALID_JSON_OBJECT_PROVIDED_EXCEPTION_MESSAGE + ARRAY2_MESSAGE + array2; return populateResult(returnResult, value, exception); } final String result; if (jsonNode1 instanceof ArrayNode && jsonNode2 instanceof ArrayNode) { final ArrayNode asJsonArray1 = (ArrayNode) jsonNode1; final ArrayNode asJsonArray2 = (ArrayNode) jsonNode2; final ArrayNode asJsonArrayResult = new ArrayNode(mapper.getNodeFactory()); asJsonArrayResult.addAll(asJsonArray1); asJsonArrayResult.addAll(asJsonArray2); result = asJsonArrayResult.toString(); } else { result = NOT_A_VALID_JSON_ARRAY_MESSAGE + ARRAY1_MESSAGE + array1 + ARRAY2_MESSAGE + array2; return populateResult(returnResult, new Exception(result)); } return populateResult(returnResult, result, null); } }
MergeArrays { @Action(name = "Merge Arrays", 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.ARRAY, required = true) String array1, @Param(value = Constants.InputNames.ARRAY, required = true) String array2) { Map<String, String> returnResult = new HashMap<>(); if (StringUtilities.isBlank(array1)) { final String exceptionValue = NOT_A_VALID_JSON_ARRAY_MESSAGE + ARRAY1_MESSAGE.replaceFirst("=", EMPTY_STRING); return populateResult(returnResult, exceptionValue, new Exception(exceptionValue)); } if (StringUtilities.isBlank(array2)) { final String exceptionValue = NOT_A_VALID_JSON_ARRAY_MESSAGE + ARRAY2_MESSAGE.replaceFirst("=", EMPTY_STRING); return populateResult(returnResult, new Exception(exceptionValue)); } JsonNode jsonNode1; JsonNode jsonNode2; ObjectMapper mapper = new ObjectMapper(); try { jsonNode1 = mapper.readTree(array1); } catch (IOException exception) { final String value = INVALID_JSON_OBJECT_PROVIDED_EXCEPTION_MESSAGE + ARRAY1_MESSAGE + array1; return populateResult(returnResult, value, exception); } try { jsonNode2 = mapper.readTree(array2); } catch (IOException exception) { final String value = INVALID_JSON_OBJECT_PROVIDED_EXCEPTION_MESSAGE + ARRAY2_MESSAGE + array2; return populateResult(returnResult, value, exception); } final String result; if (jsonNode1 instanceof ArrayNode && jsonNode2 instanceof ArrayNode) { final ArrayNode asJsonArray1 = (ArrayNode) jsonNode1; final ArrayNode asJsonArray2 = (ArrayNode) jsonNode2; final ArrayNode asJsonArrayResult = new ArrayNode(mapper.getNodeFactory()); asJsonArrayResult.addAll(asJsonArray1); asJsonArrayResult.addAll(asJsonArray2); result = asJsonArrayResult.toString(); } else { result = NOT_A_VALID_JSON_ARRAY_MESSAGE + ARRAY1_MESSAGE + array1 + ARRAY2_MESSAGE + array2; return populateResult(returnResult, new Exception(result)); } return populateResult(returnResult, result, null); }  }
MergeArrays { @Action(name = "Merge Arrays", 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.ARRAY, required = true) String array1, @Param(value = Constants.InputNames.ARRAY, required = true) String array2) { Map<String, String> returnResult = new HashMap<>(); if (StringUtilities.isBlank(array1)) { final String exceptionValue = NOT_A_VALID_JSON_ARRAY_MESSAGE + ARRAY1_MESSAGE.replaceFirst("=", EMPTY_STRING); return populateResult(returnResult, exceptionValue, new Exception(exceptionValue)); } if (StringUtilities.isBlank(array2)) { final String exceptionValue = NOT_A_VALID_JSON_ARRAY_MESSAGE + ARRAY2_MESSAGE.replaceFirst("=", EMPTY_STRING); return populateResult(returnResult, new Exception(exceptionValue)); } JsonNode jsonNode1; JsonNode jsonNode2; ObjectMapper mapper = new ObjectMapper(); try { jsonNode1 = mapper.readTree(array1); } catch (IOException exception) { final String value = INVALID_JSON_OBJECT_PROVIDED_EXCEPTION_MESSAGE + ARRAY1_MESSAGE + array1; return populateResult(returnResult, value, exception); } try { jsonNode2 = mapper.readTree(array2); } catch (IOException exception) { final String value = INVALID_JSON_OBJECT_PROVIDED_EXCEPTION_MESSAGE + ARRAY2_MESSAGE + array2; return populateResult(returnResult, value, exception); } final String result; if (jsonNode1 instanceof ArrayNode && jsonNode2 instanceof ArrayNode) { final ArrayNode asJsonArray1 = (ArrayNode) jsonNode1; final ArrayNode asJsonArray2 = (ArrayNode) jsonNode2; final ArrayNode asJsonArrayResult = new ArrayNode(mapper.getNodeFactory()); asJsonArrayResult.addAll(asJsonArray1); asJsonArrayResult.addAll(asJsonArray2); result = asJsonArrayResult.toString(); } else { result = NOT_A_VALID_JSON_ARRAY_MESSAGE + ARRAY1_MESSAGE + array1 + ARRAY2_MESSAGE + array2; return populateResult(returnResult, new Exception(result)); } return populateResult(returnResult, result, null); }  @Action(name = "Merge Arrays", 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.ARRAY, required = true) String array1,
                                       @Param(value = Constants.InputNames.ARRAY, required = true) String array2); }
MergeArrays { @Action(name = "Merge Arrays", 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.ARRAY, required = true) String array1, @Param(value = Constants.InputNames.ARRAY, required = true) String array2) { Map<String, String> returnResult = new HashMap<>(); if (StringUtilities.isBlank(array1)) { final String exceptionValue = NOT_A_VALID_JSON_ARRAY_MESSAGE + ARRAY1_MESSAGE.replaceFirst("=", EMPTY_STRING); return populateResult(returnResult, exceptionValue, new Exception(exceptionValue)); } if (StringUtilities.isBlank(array2)) { final String exceptionValue = NOT_A_VALID_JSON_ARRAY_MESSAGE + ARRAY2_MESSAGE.replaceFirst("=", EMPTY_STRING); return populateResult(returnResult, new Exception(exceptionValue)); } JsonNode jsonNode1; JsonNode jsonNode2; ObjectMapper mapper = new ObjectMapper(); try { jsonNode1 = mapper.readTree(array1); } catch (IOException exception) { final String value = INVALID_JSON_OBJECT_PROVIDED_EXCEPTION_MESSAGE + ARRAY1_MESSAGE + array1; return populateResult(returnResult, value, exception); } try { jsonNode2 = mapper.readTree(array2); } catch (IOException exception) { final String value = INVALID_JSON_OBJECT_PROVIDED_EXCEPTION_MESSAGE + ARRAY2_MESSAGE + array2; return populateResult(returnResult, value, exception); } final String result; if (jsonNode1 instanceof ArrayNode && jsonNode2 instanceof ArrayNode) { final ArrayNode asJsonArray1 = (ArrayNode) jsonNode1; final ArrayNode asJsonArray2 = (ArrayNode) jsonNode2; final ArrayNode asJsonArrayResult = new ArrayNode(mapper.getNodeFactory()); asJsonArrayResult.addAll(asJsonArray1); asJsonArrayResult.addAll(asJsonArray2); result = asJsonArrayResult.toString(); } else { result = NOT_A_VALID_JSON_ARRAY_MESSAGE + ARRAY1_MESSAGE + array1 + ARRAY2_MESSAGE + array2; return populateResult(returnResult, new Exception(result)); } return populateResult(returnResult, result, null); }  @Action(name = "Merge Arrays", 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.ARRAY, required = true) String array1,
                                       @Param(value = Constants.InputNames.ARRAY, required = true) String array2); static final String NOT_A_VALID_JSON_ARRAY_MESSAGE; static final String INVALID_JSON_OBJECT_PROVIDED_EXCEPTION_MESSAGE; static final String ARRAY1_MESSAGE; static final String ARRAY2_MESSAGE; }