package org.onap.clamp.policy.operational;
+import com.att.eelf.configuration.EELFLogger;
+import com.att.eelf.configuration.EELFManager;
import com.google.gson.JsonArray;
import com.google.gson.JsonElement;
import com.google.gson.JsonObject;
-import com.google.gson.JsonSyntaxException;
-
import java.io.IOException;
import java.util.Map.Entry;
-
import org.onap.clamp.clds.util.JsonUtils;
import org.onap.clamp.clds.util.ResourceFileUtil;
import org.onap.clamp.loop.service.Service;
public class OperationalPolicyRepresentationBuilder {
+ private static final EELFLogger logger =
+ EELFManager.getInstance().getLogger(OperationalPolicyRepresentationBuilder.class);
+
/**
* This method generates the operational policy json representation that will be
* used by ui for rendering. It uses the model (VF and VFModule) defined in the
*
* @param modelJson The loop model json
* @return The json representation
- * @throws JsonSyntaxException If the schema template cannot be parsed
- * @throws IOException In case of issue when opening the schema template
*/
- public static JsonObject generateOperationalPolicySchema(Service modelJson)
- throws JsonSyntaxException, IOException {
- JsonObject jsonSchema = JsonUtils.GSON.fromJson(
- ResourceFileUtil.getResourceAsString("clds/json-schema/operational_policies/operational_policy.json"),
- JsonObject.class);
- jsonSchema.get("schema").getAsJsonObject().get("items").getAsJsonObject().get("properties").getAsJsonObject()
- .get("configurationsJson").getAsJsonObject().get("properties").getAsJsonObject()
- .get("operational_policy").getAsJsonObject().get("properties").getAsJsonObject().get("policies")
- .getAsJsonObject().get("items").getAsJsonObject().get("properties").getAsJsonObject().get("target")
- .getAsJsonObject().get("anyOf").getAsJsonArray().addAll(createAnyOfArray(modelJson));
-
- // update CDS recipe and payload information to schema
- JsonArray actors = jsonSchema.get("schema").getAsJsonObject().get("items").getAsJsonObject().get("properties")
- .getAsJsonObject().get("configurationsJson").getAsJsonObject().get("properties").getAsJsonObject()
- .get("operational_policy").getAsJsonObject().get("properties").getAsJsonObject().get("policies")
- .getAsJsonObject().get("items").getAsJsonObject().get("properties").getAsJsonObject().get("actor")
- .getAsJsonObject().get("anyOf").getAsJsonArray();
-
- for (JsonElement actor : actors) {
- if ("CDS".equalsIgnoreCase(actor.getAsJsonObject().get("title").getAsString())) {
- actor.getAsJsonObject().get("properties").getAsJsonObject().get("type").getAsJsonObject()
- .get("anyOf").getAsJsonArray()
- .addAll(createAnyOfArrayForCdsRecipe(modelJson.getResourceDetails()));
+ public static JsonObject generateOperationalPolicySchema(Service modelJson) {
+
+ JsonObject jsonSchema = null;
+ try {
+ jsonSchema = JsonUtils.GSON.fromJson(
+ ResourceFileUtil
+ .getResourceAsString("clds/json-schema/operational_policies/operational_policy.json"),
+ JsonObject.class);
+ jsonSchema.get("properties").getAsJsonObject()
+ .get("operational_policy").getAsJsonObject().get("properties").getAsJsonObject().get("policies")
+ .getAsJsonObject().get("items").getAsJsonObject().get("properties").getAsJsonObject().get("target")
+ .getAsJsonObject().get("anyOf").getAsJsonArray().addAll(createAnyOfArray(modelJson));
+
+ // update CDS recipe and payload information to schema
+ JsonArray actors = jsonSchema.get("properties").getAsJsonObject()
+ .get("operational_policy").getAsJsonObject().get("properties").getAsJsonObject().get("policies")
+ .getAsJsonObject().get("items").getAsJsonObject().get("properties").getAsJsonObject().get("actor")
+ .getAsJsonObject().get("anyOf").getAsJsonArray();
+
+ for (JsonElement actor : actors) {
+ if ("CDS".equalsIgnoreCase(actor.getAsJsonObject().get("title").getAsString())) {
+ actor.getAsJsonObject().get("properties").getAsJsonObject().get("type").getAsJsonObject()
+ .get("anyOf").getAsJsonArray()
+ .addAll(createAnyOfArrayForCdsRecipe(modelJson.getResourceDetails()));
+ }
}
+ return jsonSchema;
+ } catch (IOException e) {
+ logger.error("Unable to generate the json schema because of an exception",e);
+ return new JsonObject();
}
-
- return jsonSchema;
}
private static JsonObject createSchemaProperty(String title, String type, String defaultValue, String readOnlyFlag,
- String[] enumArray) {
+ String[] enumArray) {
JsonObject property = new JsonObject();
property.addProperty("title", title);
property.addProperty("type", type);
modelVfModules.get(entry.getKey()).getAsJsonObject().get("vfModuleModelName").getAsString(),
"True", null));
properties.add("modelInvariantId",
- createSchemaProperty("Model Invariant Id (ModelInvariantUUID)", "string", modelVfModules
- .get(entry.getKey()).getAsJsonObject().get("vfModuleModelInvariantUUID").getAsString(),
+ createSchemaProperty("Model Invariant Id (ModelInvariantUUID)", "string",
+ modelVfModules.get(entry.getKey()).getAsJsonObject().get("vfModuleModelInvariantUUID")
+ .getAsString(),
"True", null));
properties.add("modelVersionId",
createSchemaProperty("Model Version Id (ModelUUID)", "string",
"True", null));
properties
.add("modelCustomizationId",
- createSchemaProperty("Customization ID", "string", modelVfModules.get(entry.getKey())
- .getAsJsonObject().get("vfModuleModelCustomizationUUID").getAsString(), "True",
+ createSchemaProperty("Customization ID", "string",
+ modelVfModules.get(entry.getKey()).getAsJsonObject()
+ .get("vfModuleModelCustomizationUUID").getAsString(), "True",
null));
vfModuleOneOfSchema.add("properties", properties);
JsonObject obj = new JsonObject();
obj.addProperty("title", workflowsEntry.getKey());
obj.add("properties", createPayloadProperty(workflowsEntry.getValue().getAsJsonObject(),
- controllerProperties));
+ controllerProperties));
schemaArray.add(obj);
}
StringBuilder builder = new StringBuilder("'").append("artifact_name : ").append(artifactName).append("\n")
.append("artifact_version : ").append(artifactVersion).append("\n")
.append("mode : async").append("\n")
- .append("data : ").append("'").append("\\").append("'").append(data).append("\\").append("'").append("'");
+ .append("data : ").append("'").append("\\").append("'").append(data).append("\\").append("'")
+ .append("'");
return builder.toString();
}
}