private static void validateInstanceData(InstanceData instanceData) { String description = instanceData.getDescription(); String q = "Question: '" + instanceData.getInstanceName() + "'"; if (description == null || description.length() == 0) { throw new BatfishException(q + " is missing question description"); } for (Entry<String, Variable> e : instanceData.getVariables().entrySet()) { String variableName = e.getKey(); Variable variable = e.getValue(); String v = "Variable: '" + variableName + "' in " + q; String variableDescription = variable.getDescription(); if (variableDescription == null || variableDescription.length() == 0) { throw new BatfishException(v + " is missing description"); } } }
BatfishObjectMapper.mapper() .readValue(instanceJson.toString(), new TypeReference<InstanceData>() {}); Map<String, Variable> variables = instanceData.getVariables();
BatfishObjectMapper.mapper() .readValue(instanceDataStr, new TypeReference<InstanceData>() {}); for (Entry<String, Variable> e : instanceData.getVariables().entrySet()) { String varName = e.getKey(); Variable variable = e.getValue(); for (Entry<String, Variable> e : instanceData.getVariables().entrySet()) { String varName = e.getKey(); Variable variable = e.getValue();
/** * Given the JSON representation of a question template and desired values of some parameters in * the template, this functions fills out the template with those values. It also fills the * template with the provided name. * * @param questionJson The question template to modify * @param parameters The parameters and values to fill * @param questionName The name to embed in the template * @return A JSONObject representation of the filled out template */ public static JSONObject fillTemplate( JSONObject questionJson, Map<String, JsonNode> parameters, String questionName) throws JSONException, IOException { JSONObject clonedQuestionJson = new JSONObject(questionJson.toString()); // deep copy 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; }
currentAnswer.getQuestion().getDataPlane(), BatfishObjectMapper.writeString( currentAnswer.getQuestion().getInstance().getVariables())); } catch (JsonProcessingException e) { throw new BatfishException(