+ private static JsonObject createRecipeForCdsWorkflow(String workflow) {
+ JsonObject recipe = new JsonObject();
+ recipe.addProperty(TITLE, RECIPE);
+ recipe.addProperty(TYPE, STRING);
+ recipe.addProperty(DEFAULT, workflow);
+ JsonObject options = new JsonObject();
+ options.addProperty("hidden", true);
+ recipe.add("options", options);
+ return recipe;
+ }
+
+ /**
+ * Returns the properties of payload based on the cds work flows.
+ *
+ * @param workFlow cds work flows to update payload
+ * @param controllerProperties cds properties to get blueprint name and
+ * version
+ * @param workFlowName work flow name
+ * @return returns the properties of payload
+ */
+ public static JsonObject createInputPropertiesForPayload(JsonObject workFlow,
+ JsonObject controllerProperties,
+ String workFlowName) {
+ String artifactName = controllerProperties.get("sdnc_model_name").getAsString();
+ String artifactVersion = controllerProperties.get("sdnc_model_version").getAsString();
+ JsonObject inputs = workFlow.getAsJsonObject("inputs");
+ JsonObject jsonObject = new JsonObject();
+ jsonObject.add("artifact_name", createSchemaProperty(
+ "artifact name", STRING, artifactName, "True", null));
+ jsonObject.add("artifact_version", createSchemaProperty(
+ "artifact version", STRING, artifactVersion, "True", null));
+ jsonObject.add("mode", createCdsInputProperty(
+ "mode", STRING, "async" ,null));
+ jsonObject.add("data", createDataProperty(inputs, workFlowName));
+ return jsonObject;
+ }
+
+ private static JsonObject createDataProperty(JsonObject inputs, String workflowName) {
+ JsonObject data = new JsonObject();
+ data.addProperty(TITLE, "data");
+ JsonObject dataObj = new JsonObject();
+ addDataFields(inputs, dataObj, workflowName);
+ data.add(PROPERTIES, dataObj);
+ return data;
+ }
+
+ private static void addDataFields(JsonObject inputs,
+ JsonObject dataObj,
+ String workFlowName) {
+ Set<Map.Entry<String, JsonElement>> entrySet = inputs.entrySet();
+ for (Map.Entry<String, JsonElement> entry : entrySet) {
+ String key = entry.getKey();
+ JsonObject inputProperty = inputs.getAsJsonObject(key);
+ if (key.equalsIgnoreCase(workFlowName + "-properties")) {
+ addDataFields(entry.getValue().getAsJsonObject().get("properties").getAsJsonObject(),
+ dataObj, workFlowName);
+ } else {
+ dataObj.add(entry.getKey(),
+ createCdsInputProperty(key, inputProperty.get(TYPE).getAsString(),null,
+ entry.getValue().getAsJsonObject()));
+ }
+ }
+ }
+
+ private static JsonObject createCdsInputProperty(String title,
+ String type,
+ String defaultValue,
+ JsonObject cdsProperty) {
+ JsonObject property = new JsonObject();
+ property.addProperty(TITLE, title);
+
+ if (TYPE_LIST.equalsIgnoreCase(type)) {
+ property.addProperty(TYPE, TYPE_ARRAY);
+ if (cdsProperty != null && cdsProperty.get(PROPERTIES) != null) {
+ JsonObject listProperties = new JsonObject();
+ listProperties.add(PROPERTIES, getProperties(cdsProperty.get(PROPERTIES).getAsJsonObject()));
+ property.add(ITEMS, listProperties);
+ }
+ } else if (TYPE_OBJECT.equalsIgnoreCase(type)) {
+ property.addProperty(TYPE, TYPE_OBJECT);
+ property.add(PROPERTIES, getProperties(cdsProperty.get(PROPERTIES).getAsJsonObject()));
+ } else {
+ property.addProperty(TYPE, type);
+ }
+
+ if (defaultValue != null) {
+ property.addProperty(DEFAULT, defaultValue);
+ }
+ return property;
+ }
+
+ private static JsonObject getProperties(JsonObject inputProperties) {
+ if (inputProperties == null) {
+ return null;
+ }
+ JsonObject dataObject = new JsonObject();
+ addDataFields(inputProperties, dataObject, null);
+ return dataObject;