+
+ private static JsonArray createAnyOfArrayForCdsRecipe(JsonObject resourceDetails) {
+ JsonArray anyOfStructure = new JsonArray();
+ anyOfStructure.addAll(createAnyOfCdsRecipe(resourceDetails.getAsJsonObject("VF")));
+ anyOfStructure.addAll(createAnyOfCdsRecipe(resourceDetails.getAsJsonObject("PNF")));
+ return anyOfStructure;
+ }
+
+ private static JsonArray createAnyOfCdsRecipe(JsonObject jsonObject) {
+ JsonArray schemaArray = new JsonArray();
+ for (Entry<String, JsonElement> entry : jsonObject.entrySet()) {
+ JsonObject controllerProperties = entry.getValue().getAsJsonObject()
+ .getAsJsonObject("controllerProperties");
+
+ if (controllerProperties != null) {
+ JsonObject workflows = controllerProperties.getAsJsonObject("workflows");
+ for (Entry<String, JsonElement> workflowsEntry : workflows.entrySet()) {
+ JsonObject obj = new JsonObject();
+ obj.addProperty("title", workflowsEntry.getKey());
+ obj.add("properties", createPayloadProperty(workflowsEntry.getValue().getAsJsonObject(),
+ controllerProperties));
+ schemaArray.add(obj);
+ }
+
+ }
+ }
+ return schemaArray;
+ }
+
+ private static JsonObject createPayloadProperty(JsonObject workFlow, JsonObject controllerProperties) {
+ JsonObject type = new JsonObject();
+ type.addProperty("title", "Payload (YAML)");
+ type.addProperty("type", "string");
+ type.addProperty("default", createDefaultStringForPayload(workFlow, controllerProperties));
+ type.addProperty("format", "textarea");
+ JsonObject properties = new JsonObject();
+ properties.add("type", type);
+ return properties;
+ }
+
+ private static String createDefaultStringForPayload(JsonObject workFlow, JsonObject controllerProperties) {
+ String artifactName = controllerProperties.get("sdnc_model_name").toString();
+ String artifactVersion = controllerProperties.get("sdnc_model_version").toString();
+ String data = workFlow.getAsJsonObject("inputs").toString();
+ 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("'");
+ return builder.toString();
+ }