@Test public void fillTemplate() throws JSONException, IOException { JSONObject template = new JSONObject(readResource("org/batfish/client/goodTemplate.json", UTF_8)); JSONObject filledTempate = QuestionHelper.fillTemplate( template, ImmutableSortedMap.of("parameter1", new IntNode(2)), "qname"); QuestionHelperTestQuestion question = (QuestionHelperTestQuestion) Question.parseQuestion(filledTempate.toString()); assertThat(question.getParameterMandatory(), equalTo(2)); assertThat(question.getParameterOptional(), equalTo(QuestionHelperTestQuestion.DEFAULT_VALUE)); }
public static JSONObject fillTemplate( JSONObject questionJson, Map<String, JsonNode> parameters, String questionName) throws JSONException, IOException { JSONObject clonedQuestionJson = new JSONObject(questionJson.toString()); JSONObject instanceJson = clonedQuestionJson.getJSONObject(BfConsts.PROP_INSTANCE); instanceJson.put(BfConsts.PROP_INSTANCE_NAME, questionName); String instanceDataStr = instanceJson.toString(); InstanceData instanceData = BatfishObjectMapper.mapper() .readValue(instanceDataStr, new TypeReference<InstanceData>() {}); Map<String, Variable> variables = instanceData.getVariables(); Client.validateAndSet(parameters, variables); Client.checkVariableState(variables); JSONObject modifiedInstanceData = new JSONObject(BatfishObjectMapper.writePrettyString(instanceData)); clonedQuestionJson.put(BfConsts.PROP_INSTANCE, modifiedInstanceData); return clonedQuestionJson; }
QuestionHelper { public static JSONObject fillTemplate( JSONObject questionJson, Map<String, JsonNode> parameters, String questionName) throws JSONException, IOException { JSONObject clonedQuestionJson = new JSONObject(questionJson.toString()); JSONObject instanceJson = clonedQuestionJson.getJSONObject(BfConsts.PROP_INSTANCE); instanceJson.put(BfConsts.PROP_INSTANCE_NAME, questionName); String instanceDataStr = instanceJson.toString(); InstanceData instanceData = BatfishObjectMapper.mapper() .readValue(instanceDataStr, new TypeReference<InstanceData>() {}); Map<String, Variable> variables = instanceData.getVariables(); Client.validateAndSet(parameters, variables); Client.checkVariableState(variables); JSONObject modifiedInstanceData = new JSONObject(BatfishObjectMapper.writePrettyString(instanceData)); clonedQuestionJson.put(BfConsts.PROP_INSTANCE, modifiedInstanceData); return clonedQuestionJson; } }
QuestionHelper { public static JSONObject fillTemplate( JSONObject questionJson, Map<String, JsonNode> parameters, String questionName) throws JSONException, IOException { JSONObject clonedQuestionJson = new JSONObject(questionJson.toString()); JSONObject instanceJson = clonedQuestionJson.getJSONObject(BfConsts.PROP_INSTANCE); instanceJson.put(BfConsts.PROP_INSTANCE_NAME, questionName); String instanceDataStr = instanceJson.toString(); InstanceData instanceData = BatfishObjectMapper.mapper() .readValue(instanceDataStr, new TypeReference<InstanceData>() {}); Map<String, Variable> variables = instanceData.getVariables(); Client.validateAndSet(parameters, variables); Client.checkVariableState(variables); JSONObject modifiedInstanceData = new JSONObject(BatfishObjectMapper.writePrettyString(instanceData)); clonedQuestionJson.put(BfConsts.PROP_INSTANCE, modifiedInstanceData); return clonedQuestionJson; }  }
QuestionHelper { public static JSONObject fillTemplate( JSONObject questionJson, Map<String, JsonNode> parameters, String questionName) throws JSONException, IOException { JSONObject clonedQuestionJson = new JSONObject(questionJson.toString()); JSONObject instanceJson = clonedQuestionJson.getJSONObject(BfConsts.PROP_INSTANCE); instanceJson.put(BfConsts.PROP_INSTANCE_NAME, questionName); String instanceDataStr = instanceJson.toString(); InstanceData instanceData = BatfishObjectMapper.mapper() .readValue(instanceDataStr, new TypeReference<InstanceData>() {}); Map<String, Variable> variables = instanceData.getVariables(); Client.validateAndSet(parameters, variables); Client.checkVariableState(variables); JSONObject modifiedInstanceData = new JSONObject(BatfishObjectMapper.writePrettyString(instanceData)); clonedQuestionJson.put(BfConsts.PROP_INSTANCE, modifiedInstanceData); return clonedQuestionJson; }  static JSONObject fillTemplate(
      JSONObject questionJson, Map<String, JsonNode> parameters, String questionName); static Question getQuestion(
      String questionTypeStr, Map<String, Supplier<Question>> questions); static String getQuestionString(
      String questionTypeStr, Map<String, Supplier<Question>> questions, boolean full); }
QuestionHelper { public static JSONObject fillTemplate( JSONObject questionJson, Map<String, JsonNode> parameters, String questionName) throws JSONException, IOException { JSONObject clonedQuestionJson = new JSONObject(questionJson.toString()); JSONObject instanceJson = clonedQuestionJson.getJSONObject(BfConsts.PROP_INSTANCE); instanceJson.put(BfConsts.PROP_INSTANCE_NAME, questionName); String instanceDataStr = instanceJson.toString(); InstanceData instanceData = BatfishObjectMapper.mapper() .readValue(instanceDataStr, new TypeReference<InstanceData>() {}); Map<String, Variable> variables = instanceData.getVariables(); Client.validateAndSet(parameters, variables); Client.checkVariableState(variables); JSONObject modifiedInstanceData = new JSONObject(BatfishObjectMapper.writePrettyString(instanceData)); clonedQuestionJson.put(BfConsts.PROP_INSTANCE, modifiedInstanceData); return clonedQuestionJson; }  static JSONObject fillTemplate(
      JSONObject questionJson, Map<String, JsonNode> parameters, String questionName); static Question getQuestion(
      String questionTypeStr, Map<String, Supplier<Question>> questions); static String getQuestionString(
      String questionTypeStr, Map<String, Supplier<Question>> questions, boolean full);  }