@Test public void testMapToAgenda() throws Exception { final String expectedExpressedNodeGraph = getStringFromResourceFile("/nodegraph/AgendaExpressed.json"); final String nodeGraphTemplate = getStringFromResourceFile("/nodegraph/AgendaTemplate.json"); final AgendaTemplate agendaTemplate = jsonHelper.getObjectFromString(nodeGraphTemplate, AgendaTemplate.class); final String nodeGraphParameters = getStringFromResourceFile("/nodegraph/AgendaTemplateParameters.json"); final JsonNode paramsNode = jsonHelper.getObjectMapper().readTree(nodeGraphParameters); final Agenda agenda = new AgendaTemplateMapper().map(agendaTemplate, paramsNode); Assert.assertNotNull(agenda); final JsonNode expectedExpressed = jsonHelper.getObjectMapper().readTree(expectedExpressedNodeGraph); final JsonNode actualExpressed = jsonHelper.getObjectMapper().valueToTree(agenda); logger.info(jsonHelper.getPrettyJSONString(actualExpressed)); logger.info(jsonHelper.getPrettyJSONString(expectedExpressed)); Assert.assertEquals(actualExpressed, expectedExpressed); }
public Agenda map(AgendaTemplate agendaTemplate, JsonNode inputParams) { JsonNode agendaTemplateRoot = jsonHelper.getObjectMapper().valueToTree(agendaTemplate); Map<String, JsonNode> parameterMap = new HashMap<>(); basicParametersExtractor.updateParameterMap(parameterMap, agendaTemplateRoot.get("staticParameters")); basicParametersExtractor.updateParameterMap(parameterMap, inputParams); JsonNode agendaTemplateNode = agendaTemplateRoot.get("agenda"); referenceReplacer.replaceReferences(agendaTemplateNode, parameterMap); try { return jsonHelper.getObjectMapper().treeToValue(agendaTemplateNode, Agenda.class); } catch (Exception e) { throw new RuntimeServiceException(String.format("Failed to generate Agenda from template: [%1$s]", agendaTemplate.getTitle()), e, 500); } }
AgendaTemplateMapper { public Agenda map(AgendaTemplate agendaTemplate, JsonNode inputParams) { JsonNode agendaTemplateRoot = jsonHelper.getObjectMapper().valueToTree(agendaTemplate); Map<String, JsonNode> parameterMap = new HashMap<>(); basicParametersExtractor.updateParameterMap(parameterMap, agendaTemplateRoot.get("staticParameters")); basicParametersExtractor.updateParameterMap(parameterMap, inputParams); JsonNode agendaTemplateNode = agendaTemplateRoot.get("agenda"); referenceReplacer.replaceReferences(agendaTemplateNode, parameterMap); try { return jsonHelper.getObjectMapper().treeToValue(agendaTemplateNode, Agenda.class); } catch (Exception e) { throw new RuntimeServiceException(String.format("Failed to generate Agenda from template: [%1$s]", agendaTemplate.getTitle()), e, 500); } } }
AgendaTemplateMapper { public Agenda map(AgendaTemplate agendaTemplate, JsonNode inputParams) { JsonNode agendaTemplateRoot = jsonHelper.getObjectMapper().valueToTree(agendaTemplate); Map<String, JsonNode> parameterMap = new HashMap<>(); basicParametersExtractor.updateParameterMap(parameterMap, agendaTemplateRoot.get("staticParameters")); basicParametersExtractor.updateParameterMap(parameterMap, inputParams); JsonNode agendaTemplateNode = agendaTemplateRoot.get("agenda"); referenceReplacer.replaceReferences(agendaTemplateNode, parameterMap); try { return jsonHelper.getObjectMapper().treeToValue(agendaTemplateNode, Agenda.class); } catch (Exception e) { throw new RuntimeServiceException(String.format("Failed to generate Agenda from template: [%1$s]", agendaTemplate.getTitle()), e, 500); } } AgendaTemplateMapper(); }
AgendaTemplateMapper { public Agenda map(AgendaTemplate agendaTemplate, JsonNode inputParams) { JsonNode agendaTemplateRoot = jsonHelper.getObjectMapper().valueToTree(agendaTemplate); Map<String, JsonNode> parameterMap = new HashMap<>(); basicParametersExtractor.updateParameterMap(parameterMap, agendaTemplateRoot.get("staticParameters")); basicParametersExtractor.updateParameterMap(parameterMap, inputParams); JsonNode agendaTemplateNode = agendaTemplateRoot.get("agenda"); referenceReplacer.replaceReferences(agendaTemplateNode, parameterMap); try { return jsonHelper.getObjectMapper().treeToValue(agendaTemplateNode, Agenda.class); } catch (Exception e) { throw new RuntimeServiceException(String.format("Failed to generate Agenda from template: [%1$s]", agendaTemplate.getTitle()), e, 500); } } AgendaTemplateMapper(); Agenda map(AgendaTemplate agendaTemplate, JsonNode inputParams); AgendaTemplateMapper setJsonHelper(JsonHelper jsonHelper); AgendaTemplateMapper setReferenceReplacer(JsonReferenceReplacer referenceReplacer); AgendaTemplateMapper setBasicParametersExtractor(BasicParametersExtractor basicParametersExtractor); }
AgendaTemplateMapper { public Agenda map(AgendaTemplate agendaTemplate, JsonNode inputParams) { JsonNode agendaTemplateRoot = jsonHelper.getObjectMapper().valueToTree(agendaTemplate); Map<String, JsonNode> parameterMap = new HashMap<>(); basicParametersExtractor.updateParameterMap(parameterMap, agendaTemplateRoot.get("staticParameters")); basicParametersExtractor.updateParameterMap(parameterMap, inputParams); JsonNode agendaTemplateNode = agendaTemplateRoot.get("agenda"); referenceReplacer.replaceReferences(agendaTemplateNode, parameterMap); try { return jsonHelper.getObjectMapper().treeToValue(agendaTemplateNode, Agenda.class); } catch (Exception e) { throw new RuntimeServiceException(String.format("Failed to generate Agenda from template: [%1$s]", agendaTemplate.getTitle()), e, 500); } } AgendaTemplateMapper(); Agenda map(AgendaTemplate agendaTemplate, JsonNode inputParams); AgendaTemplateMapper setJsonHelper(JsonHelper jsonHelper); AgendaTemplateMapper setReferenceReplacer(JsonReferenceReplacer referenceReplacer); AgendaTemplateMapper setBasicParametersExtractor(BasicParametersExtractor basicParametersExtractor);  }