aboutsummaryrefslogtreecommitdiffstats
path: root/src/main
diff options
context:
space:
mode:
Diffstat (limited to 'src/main')
-rw-r--r--src/main/java/org/onap/clamp/clds/client/CdsServices.java24
-rw-r--r--src/main/java/org/onap/clamp/clds/exception/cds/CdsParametersException.java53
-rw-r--r--src/main/java/org/onap/clamp/clds/tosca/update/execution/cds/ToscaMetadataCdsProcess.java31
3 files changed, 100 insertions, 8 deletions
diff --git a/src/main/java/org/onap/clamp/clds/client/CdsServices.java b/src/main/java/org/onap/clamp/clds/client/CdsServices.java
index f25e8b80..b8eb4194 100644
--- a/src/main/java/org/onap/clamp/clds/client/CdsServices.java
+++ b/src/main/java/org/onap/clamp/clds/client/CdsServices.java
@@ -34,6 +34,7 @@ import java.util.Map;
import org.apache.camel.CamelContext;
import org.apache.camel.Exchange;
import org.apache.camel.builder.ExchangeBuilder;
+import org.onap.clamp.clds.exception.cds.CdsParametersException;
import org.onap.clamp.clds.model.cds.CdsBpWorkFlowListResponse;
import org.onap.clamp.clds.util.JsonUtils;
import org.onap.clamp.clds.util.LoggingUtils;
@@ -117,7 +118,7 @@ public class CdsServices {
return null;
}
- private JsonObject parseCdsResponse(String response) {
+ protected JsonObject parseCdsResponse(String response) {
JsonObject root = JsonParser.parseString(response).getAsJsonObject();
JsonObject inputs = root.getAsJsonObject("workFlowData").getAsJsonObject("inputs");
JsonObject dataTypes = root.getAsJsonObject("dataTypes");
@@ -135,6 +136,9 @@ public class CdsServices {
String type = inputProperty.get("type").getAsString();
if (isComplexType(type, dataTypes)) {
inputObject.add(key, handleComplexType(type, dataTypes));
+ } else if (type.equalsIgnoreCase("list")) {
+ inputObject.add(key, handleListType(key, inputProperty,
+ dataTypes));
} else {
inputObject.add(key, entry.getValue());
}
@@ -142,6 +146,24 @@ public class CdsServices {
return inputObject;
}
+ private JsonObject handleListType(String propertyName,
+ JsonObject inputProperty,
+ JsonObject dataTypes) {
+ if (inputProperty.get("entry_schema") != null) {
+ String type = inputProperty.get("entry_schema").getAsJsonObject().get(
+ "type").getAsString();
+ if (dataTypes.get(type) != null) {
+ JsonObject jsonObject = new JsonObject();
+ jsonObject.addProperty("type", "list");
+ jsonObject.add("properties", handleComplexType(type, dataTypes));
+ return jsonObject;
+ } else {
+ return inputProperty;
+ }
+ }
+ throw new CdsParametersException("Entry schema is null for " + propertyName);
+ }
+
private JsonObject handleComplexType(String key, JsonObject dataTypes) {
JsonObject properties = dataTypes.get(key).getAsJsonObject().get("properties").getAsJsonObject();
return getInputProperties(properties, dataTypes);
diff --git a/src/main/java/org/onap/clamp/clds/exception/cds/CdsParametersException.java b/src/main/java/org/onap/clamp/clds/exception/cds/CdsParametersException.java
new file mode 100644
index 00000000..73ce31f8
--- /dev/null
+++ b/src/main/java/org/onap/clamp/clds/exception/cds/CdsParametersException.java
@@ -0,0 +1,53 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * ONAP CLAMP
+ * ================================================================================
+ * Copyright (C) 2020 Huawei Technologies Co., Ltd.
+ * ================================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * ============LICENSE_END=========================================================
+ * ================================================================================
+ *
+ */
+
+package org.onap.clamp.clds.exception.cds;
+
+/**
+ * Exception while parsing CDS response.
+ */
+public class CdsParametersException extends RuntimeException {
+
+ /**
+ * serialization id.
+ */
+ private static final long serialVersionUID = 8425657297510362736L;
+
+ /**
+ * This constructor can be used to create a new CdsParametersException.
+ *
+ * @param message The message to dump
+ */
+ public CdsParametersException(final String message) {
+ super(message);
+ }
+
+ /**
+ * This constructor can be used to create a new CdsParametersException.
+ *
+ * @param message The message to dump
+ * @param cause The Throwable cause object
+ */
+ public CdsParametersException(final String message, final Throwable cause) {
+ super(message, cause);
+ }
+}
diff --git a/src/main/java/org/onap/clamp/clds/tosca/update/execution/cds/ToscaMetadataCdsProcess.java b/src/main/java/org/onap/clamp/clds/tosca/update/execution/cds/ToscaMetadataCdsProcess.java
index ce1f9469..c1564141 100644
--- a/src/main/java/org/onap/clamp/clds/tosca/update/execution/cds/ToscaMetadataCdsProcess.java
+++ b/src/main/java/org/onap/clamp/clds/tosca/update/execution/cds/ToscaMetadataCdsProcess.java
@@ -23,6 +23,10 @@
package org.onap.clamp.clds.tosca.update.execution.cds;
+import static org.onap.clamp.clds.tosca.ToscaSchemaConstants.PROPERTIES;
+import static org.onap.clamp.clds.tosca.ToscaSchemaConstants.TYPE;
+import static org.onap.clamp.clds.tosca.ToscaSchemaConstants.TYPE_LIST;
+
import com.google.gson.JsonArray;
import com.google.gson.JsonElement;
import com.google.gson.JsonObject;
@@ -173,7 +177,7 @@ public class ToscaMetadataCdsProcess extends ToscaMetadataProcess {
jsonObject.add("artifact_version", createAnyOfJsonProperty(
"artifact version", artifactVersion));
jsonObject.add("mode", createCdsInputProperty(
- "mode", "string", "async"));
+ "mode", "string", "async", null));
jsonObject.add("data", createDataProperty(inputs));
return jsonObject;
@@ -182,7 +186,7 @@ public class ToscaMetadataCdsProcess extends ToscaMetadataProcess {
private static JsonObject createDataProperty(JsonObject inputs) {
JsonObject data = new JsonObject();
data.addProperty("title", "data");
- data.add("properties", addDataFields(inputs));
+ data.add(PROPERTIES, addDataFields(inputs));
return data;
}
@@ -192,7 +196,7 @@ public class ToscaMetadataCdsProcess extends ToscaMetadataProcess {
for (Map.Entry<String, JsonElement> entry : entrySet) {
String key = entry.getKey();
JsonObject inputProperty = inputs.getAsJsonObject(key);
- if (inputProperty.get("type") == null) {
+ if (inputProperty.get(TYPE) == null) {
jsonObject.add(entry.getKey(),
createAnyOfJsonObject(key,
addDataFields(entry.getValue().getAsJsonObject())));
@@ -200,7 +204,8 @@ public class ToscaMetadataCdsProcess extends ToscaMetadataProcess {
jsonObject.add(entry.getKey(),
createCdsInputProperty(key,
inputProperty.get("type").getAsString(),
- null));
+ null,
+ entry.getValue().getAsJsonObject()));
}
}
return jsonObject;
@@ -208,14 +213,26 @@ public class ToscaMetadataCdsProcess extends ToscaMetadataProcess {
private static JsonObject createCdsInputProperty(String title,
String type,
- String defaultValue) {
+ String defaultValue,
+ JsonObject cdsProperty) {
JsonObject property = new JsonObject();
property.addProperty("title", title);
- property.addProperty("type", type);
+
+ if (TYPE_LIST.equalsIgnoreCase(type)) {
+ property.addProperty(TYPE, "array");
+ if (cdsProperty.get(PROPERTIES) != null) {
+ JsonObject listProperties = new JsonObject();
+ listProperties.add(PROPERTIES,
+ addDataFields(cdsProperty.get(PROPERTIES).getAsJsonObject()));
+ property.add("items", listProperties);
+ }
+ } else {
+ property.addProperty(TYPE, type);
+ }
+
if (defaultValue != null) {
property.addProperty("default", defaultValue);
}
- property.addProperty("format", "textarea");
return property;
}
}