aboutsummaryrefslogtreecommitdiffstats
path: root/src/main/java/org/onap
diff options
context:
space:
mode:
Diffstat (limited to 'src/main/java/org/onap')
-rw-r--r--src/main/java/org/onap/clamp/clds/Application.java3
-rw-r--r--src/main/java/org/onap/clamp/clds/client/CdsServices.java24
-rw-r--r--src/main/java/org/onap/clamp/clds/config/EncodedPasswordBasicDataSource.java58
-rw-r--r--src/main/java/org/onap/clamp/clds/config/spring/CldsConfiguration.java14
-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/JsonEditorSchemaConstants.java15
-rw-r--r--src/main/java/org/onap/clamp/clds/tosca/ToscaSchemaConstants.java5
-rw-r--r--src/main/java/org/onap/clamp/clds/tosca/ToscaYamlToJsonConvertor.java106
-rw-r--r--src/main/java/org/onap/clamp/clds/tosca/update/execution/cds/ToscaMetadataCdsProcess.java60
-rw-r--r--src/main/java/org/onap/clamp/loop/LoopService.java6
-rw-r--r--src/main/java/org/onap/clamp/policy/operational/LegacyOperationalPolicy.java5
-rw-r--r--src/main/java/org/onap/clamp/policy/operational/OperationalPolicyRepresentationBuilder.java88
12 files changed, 294 insertions, 143 deletions
diff --git a/src/main/java/org/onap/clamp/clds/Application.java b/src/main/java/org/onap/clamp/clds/Application.java
index 63320d2fe..84232999e 100644
--- a/src/main/java/org/onap/clamp/clds/Application.java
+++ b/src/main/java/org/onap/clamp/clds/Application.java
@@ -65,8 +65,7 @@ import org.springframework.scheduling.annotation.EnableScheduling;
import org.springframework.transaction.annotation.EnableTransactionManagement;
@ComponentScan(basePackages = { "org.onap.clamp" })
-@SpringBootApplication(exclude = { DataSourceAutoConfiguration.class, SecurityAutoConfiguration.class,
- UserDetailsServiceAutoConfiguration.class })
+@SpringBootApplication(exclude = { SecurityAutoConfiguration.class, UserDetailsServiceAutoConfiguration.class })
@EnableJpaRepositories(basePackages = { "org.onap.clamp" })
@EntityScan(basePackages = { "org.onap.clamp" })
@EnableTransactionManagement
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 f25e8b80f..b8eb41946 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/config/EncodedPasswordBasicDataSource.java b/src/main/java/org/onap/clamp/clds/config/EncodedPasswordBasicDataSource.java
deleted file mode 100644
index 0d39cd54d..000000000
--- a/src/main/java/org/onap/clamp/clds/config/EncodedPasswordBasicDataSource.java
+++ /dev/null
@@ -1,58 +0,0 @@
-/*-
- * ============LICENSE_START=======================================================
- * ONAP CLAMP
- * ================================================================================
- * Copyright (C) 2017 AT&T Intellectual Property. All rights
- * reserved.
- * ================================================================================
- * 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.config;
-
-import com.att.eelf.configuration.EELFLogger;
-import com.att.eelf.configuration.EELFManager;
-
-import java.security.GeneralSecurityException;
-
-import org.apache.commons.codec.DecoderException;
-import org.apache.commons.dbcp.BasicDataSource;
-import org.onap.clamp.clds.util.CryptoUtils;
-
-/**
- * This class is an extension of the standard datasource, it will be used to
- * decode the encoded password defined in the application.properties.
- *
- */
-public class EncodedPasswordBasicDataSource extends BasicDataSource {
- protected static final EELFLogger logger = EELFManager.getInstance()
- .getLogger(EncodedPasswordBasicDataSource.class);
- protected static final EELFLogger metricsLogger = EELFManager.getInstance().getMetricsLogger();
-
- /**
- * This method is used automatically by Spring to decode the password.
- */
- @Override
- public synchronized void setPassword(String encodedPassword) {
- try {
- this.password = CryptoUtils.decrypt(encodedPassword);
- } catch (GeneralSecurityException e) {
- logger.error("Unable to decrypt the DB password", e);
- } catch (DecoderException e) {
- logger.error("Exception caught when decoding the HEX String Key for encryption", e);
- }
- }
-} \ No newline at end of file
diff --git a/src/main/java/org/onap/clamp/clds/config/spring/CldsConfiguration.java b/src/main/java/org/onap/clamp/clds/config/spring/CldsConfiguration.java
index b2478462f..14c08c800 100644
--- a/src/main/java/org/onap/clamp/clds/config/spring/CldsConfiguration.java
+++ b/src/main/java/org/onap/clamp/clds/config/spring/CldsConfiguration.java
@@ -23,13 +23,9 @@
package org.onap.clamp.clds.config.spring;
-import javax.sql.DataSource;
-
import org.onap.clamp.clds.config.ClampProperties;
-import org.onap.clamp.clds.config.EncodedPasswordBasicDataSource;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.config.PropertiesFactoryBean;
-import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.context.ApplicationContext;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
@@ -44,16 +40,6 @@ public class CldsConfiguration {
@Autowired
private ClampProperties refProp;
- /**
- * Clds Identity database DataSource configuration.
- *
- * @return encoded password data source
- */
- @Bean(name = "cldsDataSource")
- @ConfigurationProperties(prefix = "spring.datasource.cldsdb")
- public DataSource cldsDataSource() {
- return new EncodedPasswordBasicDataSource();
- }
/**
* This loads the file system.properties.
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 000000000..73ce31f89
--- /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/JsonEditorSchemaConstants.java b/src/main/java/org/onap/clamp/clds/tosca/JsonEditorSchemaConstants.java
index fdc94231f..e3c661698 100644
--- a/src/main/java/org/onap/clamp/clds/tosca/JsonEditorSchemaConstants.java
+++ b/src/main/java/org/onap/clamp/clds/tosca/JsonEditorSchemaConstants.java
@@ -28,8 +28,10 @@ public class JsonEditorSchemaConstants {
//Data types in JSON Schema
public static final String TYPE_OBJECT = "object";
public static final String TYPE_ARRAY = "array";
+ public static final String TYPE_MAP = "map";
public static final String TYPE_STRING = "string";
public static final String TYPE_INTEGER = "integer";
+ public static final String TYPE_DATE_TIME = "datetime";
//Key elements in JSON Schema
public static final String TYPE = "type";
@@ -43,6 +45,9 @@ public class JsonEditorSchemaConstants {
public static final String ITEMS = "items";
public static final String PROPERTIES = "properties";
public static final String PROPERTY_ORDER = "propertyOrder";
+ public static final String VALUES = "values";
+ public static final String HEADER_TEMPLATE = "headerTemplate";
+ public static final String HEADER_TEMPLATE_VALUE = "{{self.name}}";
public static final String MINIMUM = "minimum";
public static final String MAXIMUM = "maximum";
@@ -50,9 +55,13 @@ public class JsonEditorSchemaConstants {
public static final String MAX_LENGTH = "maxLength";
public static final String EXCLUSIVE_MINIMUM = "exclusiveMinimum";
public static final String EXCLUSIVE_MAXIMUM = "exclusiveMaximum";
+ public static final String MINITEMS = "minItems";
+ public static final String MAXITEMS = "maxItems";
public static final String CUSTOM_KEY_FORMAT = "format";
public static final String CUSTOM_KEY_FORMAT_TABS_TOP = "tabs-top";
+ public static final String CUSTOM_KEY_FORMAT_TABS = "tabs";
+ public static final String CUSTOM_KEY_FORMAT_INPUT = "input";
public static final String FORMAT_SELECT = "select";
public static final String UNIQUE_ITEMS = "uniqueItems";
public static final String TRUE = "true";
@@ -67,5 +76,11 @@ public class JsonEditorSchemaConstants {
public static final String SCHEMA = "schema";
public static final String CURRENT_VALUES = "currentValues";
+ public static final String PLUGIN = "plugin";
+ public static final String DATE_TIME_PICKER = "datetimepicker";
+ public static final String VALIDATION = "validation";
+ public static final String DATE_TIME_FORMAT = "YYYY/MM/DD HH:mm:ss";
+ public static final String INPUT_EVENT = "input_event";
+ public static final String DP_CHANGE = "dp.change";
}
diff --git a/src/main/java/org/onap/clamp/clds/tosca/ToscaSchemaConstants.java b/src/main/java/org/onap/clamp/clds/tosca/ToscaSchemaConstants.java
index 9601649c9..d00c431c8 100644
--- a/src/main/java/org/onap/clamp/clds/tosca/ToscaSchemaConstants.java
+++ b/src/main/java/org/onap/clamp/clds/tosca/ToscaSchemaConstants.java
@@ -30,8 +30,11 @@ public class ToscaSchemaConstants {
public static final String TYPE_MAP = "map";
public static final String TYPE_STRING = "string";
public static final String TYPE_INTEGER = "integer";
+ public static final String TYPE_NUMBER = "number";
+ public static final String TYPE_DATE_TIME = "datetime";
public static final String TYPE_FLOAT = "float";
public static final String TYPE_BOOLEAN = "boolean";
+ public static final String TYPE_USER_DEFINED = "userDefined";
// Key elements in Tosca
public static final String NODE_TYPES = "policy_types";
@@ -46,6 +49,8 @@ public class ToscaSchemaConstants {
public static final String METADATA = "metadata";
public static final String METADATA_POLICY_MODEL_TYPE = "policy_model_type";
public static final String METADATA_ACRONYM = "acronym";
+ public static final String METADATA_ELEMENT_NAME = "element_name";
+ public static final String METADATA_HEADER_TEMPLATE = "header_template";
public static final String METADATA_CLAMP_POSSIBLE_VALUES = "clamp_possible_values";
// Constraints
diff --git a/src/main/java/org/onap/clamp/clds/tosca/ToscaYamlToJsonConvertor.java b/src/main/java/org/onap/clamp/clds/tosca/ToscaYamlToJsonConvertor.java
index 666ca6702..45bb87ed8 100644
--- a/src/main/java/org/onap/clamp/clds/tosca/ToscaYamlToJsonConvertor.java
+++ b/src/main/java/org/onap/clamp/clds/tosca/ToscaYamlToJsonConvertor.java
@@ -38,6 +38,7 @@ import java.util.stream.Collectors;
import org.json.JSONArray;
import org.json.JSONObject;
import org.onap.clamp.clds.config.ClampProperties;
+import org.onap.clamp.tosca.Dictionary;
import org.onap.clamp.tosca.DictionaryElement;
import org.onap.clamp.tosca.DictionaryService;
import org.springframework.beans.factory.annotation.Autowired;
@@ -142,6 +143,13 @@ public class ToscaYamlToJsonConvertor {
parseNodeAndDataType(loadedYaml, nodeTypes, dataNodes);
populateJsonEditorObject(loadedYaml, nodeTypes, dataNodes, jsonParentObject, jsonTempObject,
modelTypeToUse);
+
+ String headerTemplate = getValueFromMetadata(validateAndConvertToJson(yamlString),
+ ToscaSchemaConstants.METADATA_HEADER_TEMPLATE);
+ if (headerTemplate != null) {
+ jsonParentObject.put(JsonEditorSchemaConstants.HEADER_TEMPLATE,
+ JsonEditorSchemaConstants.HEADER_TEMPLATE_VALUE);
+ }
if (jsonTempObject.length() > 0) {
jsonParentObject = jsonTempObject;
}
@@ -234,7 +242,7 @@ public class ToscaYamlToJsonConvertor {
jsonTempObject.put(JsonEditorSchemaConstants.ITEMS,
jsonParentObject);
jsonTempObject.put(JsonEditorSchemaConstants.FORMAT,
- JsonEditorSchemaConstants.CUSTOM_KEY_FORMAT_TABS_TOP);
+ JsonEditorSchemaConstants.CUSTOM_KEY_FORMAT_TABS);
jsonTempObject.put(JsonEditorSchemaConstants.UNIQUE_ITEMS,
JsonEditorSchemaConstants.TRUE);
}
@@ -652,12 +660,43 @@ public class ToscaYamlToJsonConvertor {
Optional.ofNullable(cldsDictionaryElements).get().stream().forEach(c -> {
JSONObject jsonObject = new JSONObject();
+ if (c.getSubDictionary() != null) {
+ Dictionary subDictionary =
+ dictionaryService.getDictionary(c.getSubDictionary());
+ if (subDictionary != null
+ && !subDictionary.getDictionaryElements().isEmpty()) {
+
+ jsonObject.put(JsonEditorSchemaConstants.CUSTOM_KEY_FORMAT_INPUT,
+ JsonEditorSchemaConstants.FORMAT_SELECT);
+
+ List<String> shortNames = new ArrayList<>();
+ subDictionary.getDictionaryElements().stream().forEach(c1 -> {
+ shortNames.add(c1.getShortName());
+ });
+ jsonObject.put(JsonEditorSchemaConstants.VALUES, shortNames);
+ }
+ }
jsonObject.put(JsonEditorSchemaConstants.TYPE, getJsonType(c.getType()));
+
if (c.getType() != null
- && c.getType().equalsIgnoreCase(ToscaSchemaConstants.TYPE_STRING)) {
+ && (c.getType().equalsIgnoreCase(ToscaSchemaConstants.TYPE_STRING)
+ || c.getType().equalsIgnoreCase(ToscaSchemaConstants.TYPE_DATE_TIME)
+ || c.getType().equalsIgnoreCase(ToscaSchemaConstants.TYPE_MAP))) {
jsonObject.put(JsonEditorSchemaConstants.MIN_LENGTH, 1);
+ if (c.getType().equalsIgnoreCase(ToscaSchemaConstants.TYPE_DATE_TIME)) {
+ jsonObject.put(JsonEditorSchemaConstants.PLUGIN,
+ JsonEditorSchemaConstants.DATE_TIME_PICKER);
+ jsonObject.put(JsonEditorSchemaConstants.INPUT_EVENT,
+ JsonEditorSchemaConstants.DP_CHANGE);
+ JSONObject formatJsonObject = new JSONObject();
+ formatJsonObject.put(JsonEditorSchemaConstants.FORMAT,
+ JsonEditorSchemaConstants.DATE_TIME_FORMAT);
+ jsonObject.put(JsonEditorSchemaConstants.VALIDATION,
+ formatJsonObject);
+ }
}
+
jsonObject.put(JsonEditorSchemaConstants.ID, c.getName());
jsonObject.put(JsonEditorSchemaConstants.LABEL, c.getShortName());
jsonObject.put(JsonEditorSchemaConstants.OPERATORS, subCldsDictionaryNames);
@@ -678,32 +717,44 @@ public class ToscaYamlToJsonConvertor {
String dictionaryKey = dictionaryReference.substring(
dictionaryReference.indexOf(ToscaSchemaConstants.DICTIONARY) + 11,
dictionaryReference.length());
+
if (dictionaryKey != null) {
- List<DictionaryElement> cldsDictionaryElements =
- dictionaryService.getDictionary(dictionaryKey).getDictionaryElements().stream()
- .collect(Collectors.toList());
- if (cldsDictionaryElements != null) {
- List<String> cldsDictionaryNames = new ArrayList<>();
- List<String> cldsDictionaryFullNames = new ArrayList<>();
- cldsDictionaryElements.stream().forEach(c -> {
- // Json type will be translated before Policy creation
- if (c.getType() != null && !c.getType().equalsIgnoreCase("json")) {
- cldsDictionaryFullNames.add(c.getName());
+ if (dictionaryKey.contains(ToscaSchemaConstants.TYPE_USER_DEFINED)) {
+ childObject.put(JsonEditorSchemaConstants.ENUM, new ArrayList<>());
+ // Add Enum titles for generated translated values during
+ // JSON instance generation
+ JSONObject enumTitles = new JSONObject();
+ enumTitles.put(JsonEditorSchemaConstants.ENUM_TITLES, new ArrayList<>());
+ childObject.put(JsonEditorSchemaConstants.OPTIONS, enumTitles);
+ } else {
+ List<DictionaryElement> cldsDictionaryElements =
+ dictionaryService.getDictionary(dictionaryKey).getDictionaryElements()
+ .stream().collect(Collectors.toList());
+ if (cldsDictionaryElements != null) {
+ List<String> cldsDictionaryNames = new ArrayList<>();
+ List<String> cldsDictionaryFullNames = new ArrayList<>();
+ cldsDictionaryElements.stream().forEach(c -> {
+ // Json type will be translated before Policy creation
+ if (c.getType() != null && !c.getType().equalsIgnoreCase("json")) {
+ cldsDictionaryFullNames.add(c.getName());
+ }
+ cldsDictionaryNames.add(c.getShortName());
+ });
+
+ if (!cldsDictionaryFullNames.isEmpty()) {
+ childObject.put(JsonEditorSchemaConstants.ENUM,
+ cldsDictionaryFullNames);
+ // Add Enum titles for generated translated values during JSON instance
+ // generation
+ JSONObject enumTitles = new JSONObject();
+ enumTitles.put(JsonEditorSchemaConstants.ENUM_TITLES,
+ cldsDictionaryNames);
+ childObject.put(JsonEditorSchemaConstants.OPTIONS, enumTitles);
+ } else {
+ childObject.put(JsonEditorSchemaConstants.ENUM, cldsDictionaryNames);
}
- cldsDictionaryNames.add(c.getShortName());
- });
- if (!cldsDictionaryFullNames.isEmpty()) {
- childObject.put(JsonEditorSchemaConstants.ENUM, cldsDictionaryFullNames);
- // Add Enum titles for generated translated values during JSON instance
- // generation
- JSONObject enumTitles = new JSONObject();
- enumTitles.put(JsonEditorSchemaConstants.ENUM_TITLES, cldsDictionaryNames);
- childObject.put(JsonEditorSchemaConstants.OPTIONS, enumTitles);
- } else {
- childObject.put(JsonEditorSchemaConstants.ENUM, cldsDictionaryNames);
}
-
}
}
}
@@ -711,10 +762,15 @@ public class ToscaYamlToJsonConvertor {
private String getJsonType(String toscaType) {
String jsonType = null;
- if (toscaType.equalsIgnoreCase(ToscaSchemaConstants.TYPE_INTEGER)) {
+ if (toscaType.equalsIgnoreCase(ToscaSchemaConstants.TYPE_INTEGER)
+ || toscaType.equalsIgnoreCase(ToscaSchemaConstants.TYPE_NUMBER)) {
jsonType = JsonEditorSchemaConstants.TYPE_INTEGER;
+ } else if (toscaType.equalsIgnoreCase(ToscaSchemaConstants.TYPE_DATE_TIME)) {
+ jsonType = JsonEditorSchemaConstants.TYPE_DATE_TIME;
} else if (toscaType.equalsIgnoreCase(ToscaSchemaConstants.TYPE_LIST)) {
jsonType = JsonEditorSchemaConstants.TYPE_ARRAY;
+ } else if (toscaType.equalsIgnoreCase(ToscaSchemaConstants.TYPE_MAP)) {
+ jsonType = JsonEditorSchemaConstants.TYPE_MAP;
} else {
jsonType = JsonEditorSchemaConstants.TYPE_STRING;
}
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 ce1f94699..c92cad1f5 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,8 @@
package org.onap.clamp.clds.tosca.update.execution.cds;
+import static org.onap.clamp.clds.tosca.ToscaSchemaConstants.TYPE;
+
import com.google.gson.JsonArray;
import com.google.gson.JsonElement;
import com.google.gson.JsonObject;
@@ -129,20 +131,14 @@ public class ToscaMetadataCdsProcess extends ToscaMetadataProcess {
return result;
}
- private static JsonObject createAnyOfJsonProperty(String name, String defaultValue) {
+ private static JsonObject createAnyOfJsonProperty(String name,
+ String defaultValue,
+ boolean readOnlyFlag) {
JsonObject result = new JsonObject();
result.addProperty("title", name);
result.addProperty("type", "string");
result.addProperty("default", defaultValue);
- result.addProperty("readOnly", "True");
- return result;
- }
-
- private static JsonObject createAnyOfJsonObject(String name, JsonObject allProperties) {
- JsonObject result = new JsonObject();
- result.addProperty("title", name);
- result.addProperty("type", "object");
- result.add("properties", allProperties);
+ result.addProperty("readOnly", readOnlyFlag);
return result;
}
@@ -169,53 +165,37 @@ public class ToscaMetadataCdsProcess extends ToscaMetadataProcess {
JsonObject inputs = workFlow.getAsJsonObject("inputs");
JsonObject jsonObject = new JsonObject();
jsonObject.add("artifact_name", createAnyOfJsonProperty(
- "artifact name", artifactName));
+ "artifact name", artifactName, true));
jsonObject.add("artifact_version", createAnyOfJsonProperty(
- "artifact version", artifactVersion));
- jsonObject.add("mode", createCdsInputProperty(
- "mode", "string", "async"));
+ "artifact version", artifactVersion, true));
+ jsonObject.add("mode", createAnyOfJsonProperty(
+ "mode", "async", false));
jsonObject.add("data", createDataProperty(inputs));
-
return jsonObject;
}
private static JsonObject createDataProperty(JsonObject inputs) {
JsonObject data = new JsonObject();
data.addProperty("title", "data");
- data.add("properties", addDataFields(inputs));
+ data.addProperty("type", "string");
+ data.addProperty("format", "textarea");
+ JsonObject defaultValue = new JsonObject();
+ addDefaultValueForData(inputs, defaultValue);
+ data.addProperty("default", defaultValue.toString());
return data;
}
- private static JsonObject addDataFields(JsonObject inputs) {
- JsonObject jsonObject = new JsonObject();
+ private static void addDefaultValueForData(JsonObject inputs,
+ JsonObject defaultValue) {
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 (inputProperty.get("type") == null) {
- jsonObject.add(entry.getKey(),
- createAnyOfJsonObject(key,
- addDataFields(entry.getValue().getAsJsonObject())));
+ if (inputProperty.get(TYPE) == null) {
+ addDefaultValueForData(entry.getValue().getAsJsonObject(), defaultValue);
} else {
- jsonObject.add(entry.getKey(),
- createCdsInputProperty(key,
- inputProperty.get("type").getAsString(),
- null));
+ defaultValue.addProperty(entry.getKey(), "");
}
}
- return jsonObject;
- }
-
- private static JsonObject createCdsInputProperty(String title,
- String type,
- String defaultValue) {
- JsonObject property = new JsonObject();
- property.addProperty("title", title);
- property.addProperty("type", type);
- if (defaultValue != null) {
- property.addProperty("default", defaultValue);
- }
- property.addProperty("format", "textarea");
- return property;
}
}
diff --git a/src/main/java/org/onap/clamp/loop/LoopService.java b/src/main/java/org/onap/clamp/loop/LoopService.java
index ca3681b62..3f568a331 100644
--- a/src/main/java/org/onap/clamp/loop/LoopService.java
+++ b/src/main/java/org/onap/clamp/loop/LoopService.java
@@ -118,6 +118,12 @@ public class LoopService {
Loop addOperationalPolicy(String loopName, String policyType, String policyVersion) throws IOException {
Loop loop = getLoop(loopName);
PolicyModel policyModel = policyModelsService.getPolicyModel(policyType, policyVersion);
+ Set<OperationalPolicy> opPolicySet = loop.getOperationalPolicies();
+ for (OperationalPolicy opPolicy : opPolicySet) {
+ if (opPolicy.getPolicyModel().equals(policyModel)) {
+ throw new IllegalArgumentException("This type of Operational Policy is already added to the loop. Please choose another one.");
+ }
+ }
if (policyModel == null) {
return null;
}
diff --git a/src/main/java/org/onap/clamp/policy/operational/LegacyOperationalPolicy.java b/src/main/java/org/onap/clamp/policy/operational/LegacyOperationalPolicy.java
index 3765277d8..a7a344df2 100644
--- a/src/main/java/org/onap/clamp/policy/operational/LegacyOperationalPolicy.java
+++ b/src/main/java/org/onap/clamp/policy/operational/LegacyOperationalPolicy.java
@@ -234,6 +234,11 @@ public class LegacyOperationalPolicy {
JsonObject payloadObject = payloadElem != null ?
payloadElem.getAsJsonObject() : null;
if (payloadObject != null) {
+ /* Since policy expects payload to be map of string,
+ converting data object to string. */
+ JsonObject dataObject = payloadObject.get("data").getAsJsonObject();
+ payloadObject.remove("data");
+ payloadObject.addProperty("data", dataObject.toString());
policy.getAsJsonObject().add(PAYLOAD,
payloadObject);
} else {
diff --git a/src/main/java/org/onap/clamp/policy/operational/OperationalPolicyRepresentationBuilder.java b/src/main/java/org/onap/clamp/policy/operational/OperationalPolicyRepresentationBuilder.java
index 4e362d841..57d13ef17 100644
--- a/src/main/java/org/onap/clamp/policy/operational/OperationalPolicyRepresentationBuilder.java
+++ b/src/main/java/org/onap/clamp/policy/operational/OperationalPolicyRepresentationBuilder.java
@@ -24,8 +24,6 @@
package org.onap.clamp.policy.operational;
-import static org.onap.clamp.clds.tosca.update.execution.cds.ToscaMetadataCdsProcess.createInputPropertiesForPayload;
-
import com.att.eelf.configuration.EELFLogger;
import com.att.eelf.configuration.EELFManager;
import com.google.gson.JsonArray;
@@ -33,7 +31,9 @@ import com.google.gson.JsonElement;
import com.google.gson.JsonObject;
import java.io.IOException;
+import java.util.Map;
import java.util.Map.Entry;
+import java.util.Set;
import org.onap.clamp.clds.util.JsonUtils;
import org.onap.clamp.clds.util.ResourceFileUtil;
@@ -44,6 +44,10 @@ public class OperationalPolicyRepresentationBuilder {
private static final EELFLogger logger =
EELFManager.getInstance().getLogger(OperationalPolicyRepresentationBuilder.class);
+ public static final String PROPERTIES = "properties";
+ public static final String TYPE = "type";
+ public static final String TYPE_LIST = "list";
+
/**
* 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
@@ -213,7 +217,7 @@ public class OperationalPolicyRepresentationBuilder {
private static JsonObject createPayloadProperty(JsonObject workFlow,
JsonObject controllerProperties, String workFlowName) {
JsonObject payload = new JsonObject();
- payload.addProperty("title", "Payload (YAML)");
+ payload.addProperty("title", "Payload");
payload.addProperty("type", "object");
payload.add("properties", createInputPropertiesForPayload(workFlow,
controllerProperties));
@@ -233,4 +237,82 @@ public class OperationalPolicyRepresentationBuilder {
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
+ * @return returns the properties of payload
+ */
+ public static JsonObject createInputPropertiesForPayload(JsonObject workFlow,
+ JsonObject controllerProperties) {
+ 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));
+ return jsonObject;
+ }
+
+ private static JsonObject createDataProperty(JsonObject inputs) {
+ JsonObject data = new JsonObject();
+ data.addProperty("title", "data");
+ JsonObject dataObj = new JsonObject();
+ addDataFields(inputs, dataObj);
+ data.add(PROPERTIES, dataObj);
+ return data;
+ }
+
+ private static void addDataFields(JsonObject inputs,
+ JsonObject dataObj) {
+ 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 (inputProperty.get(TYPE) == null) {
+ addDataFields(entry.getValue().getAsJsonObject(), dataObj);
+ } 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, "array");
+ if (cdsProperty.get(PROPERTIES) != null) {
+ JsonObject dataObject = new JsonObject();
+ addDataFields(cdsProperty.get(PROPERTIES).getAsJsonObject(),
+ dataObject);
+ JsonObject listProperties = new JsonObject();
+ listProperties.add(PROPERTIES, dataObject);
+ property.add("items", listProperties);
+ }
+ } else {
+ property.addProperty(TYPE, type);
+ }
+
+ if (defaultValue != null) {
+ property.addProperty("default", defaultValue);
+ }
+ return property;
+ }
}