summaryrefslogtreecommitdiffstats
path: root/catalog-model/src/main/java/org
diff options
context:
space:
mode:
authorAvi Ziv <avi.ziv@amdocs.com>2017-07-31 15:50:46 +0300
committerMichael Lando <ml636r@att.com>2017-08-02 21:18:34 +0300
commitf5854fd32c19c44d32a3e6739b30271d4dccd393 (patch)
tree6e7420dd3d82200849e51c2af3f2696f11815d12 /catalog-model/src/main/java/org
parente280d7229f42210719b76775cd47bddb675c3c53 (diff)
[SDC] code rebase for sdc resync to LF
Change-Id: If6d87c9e324f508a8a6b80b10a03d1843901472e Signed-off-by: Michael Lando <ml636r@att.com>
Diffstat (limited to 'catalog-model/src/main/java/org')
-rw-r--r--catalog-model/src/main/java/org/openecomp/sdc/be/model/jsontitan/operations/BaseOperation.java57
-rw-r--r--catalog-model/src/main/java/org/openecomp/sdc/be/model/jsontitan/operations/NodeTemplateOperation.java10
-rw-r--r--catalog-model/src/main/java/org/openecomp/sdc/be/model/jsontitan/operations/TopologyTemplateOperation.java12
-rw-r--r--catalog-model/src/main/java/org/openecomp/sdc/be/model/jsontitan/operations/ToscaElementLifecycleOperation.java6
-rw-r--r--catalog-model/src/main/java/org/openecomp/sdc/be/model/jsontitan/operations/ToscaElementOperation.java8
-rw-r--r--catalog-model/src/main/java/org/openecomp/sdc/be/model/jsontitan/operations/ToscaOperationFacade.java43
-rw-r--r--catalog-model/src/main/java/org/openecomp/sdc/be/model/tosca/ToscaFunctions.java19
-rw-r--r--catalog-model/src/main/java/org/openecomp/sdc/be/model/tosca/converters/DataTypePropertyConverter.java130
-rw-r--r--catalog-model/src/main/java/org/openecomp/sdc/be/model/tosca/converters/HeatJsonConverter.java13
-rw-r--r--catalog-model/src/main/java/org/openecomp/sdc/be/model/tosca/converters/ToscaConverterUtils.java13
-rw-r--r--catalog-model/src/main/java/org/openecomp/sdc/be/model/tosca/converters/ToscaMapValueConverter.java18
11 files changed, 271 insertions, 58 deletions
diff --git a/catalog-model/src/main/java/org/openecomp/sdc/be/model/jsontitan/operations/BaseOperation.java b/catalog-model/src/main/java/org/openecomp/sdc/be/model/jsontitan/operations/BaseOperation.java
index 0b60a07a28..1726c397ad 100644
--- a/catalog-model/src/main/java/org/openecomp/sdc/be/model/jsontitan/operations/BaseOperation.java
+++ b/catalog-model/src/main/java/org/openecomp/sdc/be/model/jsontitan/operations/BaseOperation.java
@@ -53,8 +53,6 @@ import org.openecomp.sdc.be.datatypes.enums.ComponentTypeEnum;
import org.openecomp.sdc.be.datatypes.enums.GraphPropertyEnum;
import org.openecomp.sdc.be.datatypes.enums.JsonPresentationFields;
import org.openecomp.sdc.be.datatypes.tosca.ToscaDataDefinition;
-import org.openecomp.sdc.be.model.ComponentInstance;
-import org.openecomp.sdc.be.model.GroupDefinition;
import org.openecomp.sdc.be.model.User;
import org.openecomp.sdc.be.model.jsontitan.datamodel.ToscaElementTypeEnum;
import org.openecomp.sdc.be.model.operations.api.StorageOperationStatus;
@@ -1189,13 +1187,8 @@ public abstract class BaseOperation {
}
if (result == null) {
toscaDataVertex = toscaDataVertexRes.left().value();
- existingToscaDataMap = (Map<String, ToscaDataDefinition>) getDeepElements(toscaDataVertexRes.left().value(), pathKeys);
- for (String uniqueKey : uniqueKeys) {
- result = removeToscaDataElement(toscaElement, edgeLabel, uniqueKey, toscaDataVertex, existingToscaDataMap);
- if (result != StorageOperationStatus.OK) {
- break;
- }
- }
+ existingToscaDataMap = getDeepElements(toscaDataVertexRes.left().value(), pathKeys);
+ result = deleteElementsFromDataVertex(toscaElement, edgeLabel, uniqueKeys, toscaDataVertex, existingToscaDataMap);
}
if (result == null) {
result = StorageOperationStatus.OK;
@@ -1203,6 +1196,19 @@ public abstract class BaseOperation {
return result;
}
+ private StorageOperationStatus deleteElementsFromDataVertex(GraphVertex toscaElement, EdgeLabelEnum edgeLabel, List<String> uniqueKeys, GraphVertex toscaDataVertex, Map<String, ToscaDataDefinition> existingToscaDataMap) {
+ StorageOperationStatus result;
+ for (String uniqueKey : uniqueKeys) {
+ result = removeKeyFromDataVertex(uniqueKey, existingToscaDataMap);
+ if (result != StorageOperationStatus.OK) {
+ CommonUtility.addRecordToLog(logger, LogLevelEnum.DEBUG, "Failed to delete tosca data element of the tosca element {} by label {}. Status is {}. ", toscaElement.getUniqueId(), edgeLabel, result);
+ break;
+ }
+ }
+ result = updateToscaDataElement(toscaElement, edgeLabel, toscaDataVertex);
+ return result;
+ }
+
/**
* Deletes tosca data element belonging to tosca element according label
*
@@ -1229,7 +1235,6 @@ public abstract class BaseOperation {
* @return
*/
public StorageOperationStatus deleteToscaDataElements(GraphVertex toscaElement, EdgeLabelEnum edgeLabel, List<String> uniqueKeys) {
-
StorageOperationStatus result = null;
GraphVertex toscaDataVertex;
Map<String, ToscaDataDefinition> existingToscaDataMap;
@@ -1242,12 +1247,7 @@ public abstract class BaseOperation {
if (result == null) {
toscaDataVertex = toscaDataVertexRes.left().value();
existingToscaDataMap = (Map<String, ToscaDataDefinition>) toscaDataVertex.getJson();
- for (String uniqueKey : uniqueKeys) {
- result = removeToscaDataElement(toscaElement, edgeLabel, uniqueKey, toscaDataVertex, existingToscaDataMap);
- if (result != StorageOperationStatus.OK) {
- break;
- }
- }
+ result = deleteElementsFromDataVertex(toscaElement, edgeLabel, uniqueKeys, toscaDataVertex, existingToscaDataMap);
}
if (result == null) {
result = StorageOperationStatus.OK;
@@ -1255,23 +1255,24 @@ public abstract class BaseOperation {
return result;
}
- private <T extends ToscaDataDefinition> StorageOperationStatus removeToscaDataElement(GraphVertex toscaElement, EdgeLabelEnum edgeLabel, String uniqueKey, GraphVertex toscaDataVertex, Map<String, T> existingToscaDataMap) {
-
+ private <T extends ToscaDataDefinition> StorageOperationStatus updateToscaDataElement(GraphVertex toscaElement, EdgeLabelEnum edgeLabel, GraphVertex toscaDataVertex) {
StorageOperationStatus result = StorageOperationStatus.OK;
- if (!existingToscaDataMap.containsKey(uniqueKey)) {
- result = StorageOperationStatus.NOT_FOUND;
- CommonUtility.addRecordToLog(logger, LogLevelEnum.DEBUG, "Failed to delete tosca data element of the tosca element {} by label {}. Status is {}. ", toscaElement.getUniqueId(), edgeLabel, result);
- } else {
- existingToscaDataMap.remove(uniqueKey);
- Either<GraphVertex, TitanOperationStatus> updateOrCopyRes = updateOrCopyOnUpdate(toscaDataVertex, toscaElement, edgeLabel);
- if (updateOrCopyRes.isRight()) {
- result = DaoStatusConverter.convertTitanStatusToStorageStatus(updateOrCopyRes.right().value());
- CommonUtility.addRecordToLog(logger, LogLevelEnum.DEBUG, "Failed to update tosca data {} of the tosca element {}. Status is {}. ", edgeLabel, toscaElement.getUniqueId(), result);
- }
+ Either<GraphVertex, TitanOperationStatus> updateOrCopyRes = updateOrCopyOnUpdate(toscaDataVertex, toscaElement, edgeLabel);
+ if (updateOrCopyRes.isRight()) {
+ result = DaoStatusConverter.convertTitanStatusToStorageStatus(updateOrCopyRes.right().value());
+ CommonUtility.addRecordToLog(logger, LogLevelEnum.DEBUG, "Failed to update tosca data {} of the tosca element {}. Status is {}. ", edgeLabel, toscaElement.getUniqueId(), result);
}
return result;
}
+ private <T extends ToscaDataDefinition> StorageOperationStatus removeKeyFromDataVertex(String uniqueKey, Map<String, T> existingToscaDataMap) {
+ if (!existingToscaDataMap.containsKey(uniqueKey)) {
+ return StorageOperationStatus.NOT_FOUND;
+ }
+ existingToscaDataMap.remove(uniqueKey);
+ return StorageOperationStatus.OK;
+ }
+
protected <K extends ToscaDataDefinition> StorageOperationStatus handleToscaData(GraphVertex toscaElement, VertexTypeEnum vertexLabel, EdgeLabelEnum edgeLabel, GraphVertex toscaDataVertex, Map<String, K> mergedToscaDataMap) {
StorageOperationStatus result = StorageOperationStatus.OK;
diff --git a/catalog-model/src/main/java/org/openecomp/sdc/be/model/jsontitan/operations/NodeTemplateOperation.java b/catalog-model/src/main/java/org/openecomp/sdc/be/model/jsontitan/operations/NodeTemplateOperation.java
index 66d26c748f..b642410548 100644
--- a/catalog-model/src/main/java/org/openecomp/sdc/be/model/jsontitan/operations/NodeTemplateOperation.java
+++ b/catalog-model/src/main/java/org/openecomp/sdc/be/model/jsontitan/operations/NodeTemplateOperation.java
@@ -1620,6 +1620,14 @@ public class NodeTemplateOperation extends BaseOperation {
}
public StorageOperationStatus addDeploymentArtifactsToInstance(String toscaElementId, String instanceId, Map<String, ArtifactDataDefinition> instDeplArtifacts) {
+ return addArtifactsToInstance(toscaElementId, instanceId, instDeplArtifacts, EdgeLabelEnum.INST_DEPLOYMENT_ARTIFACTS, VertexTypeEnum.INST_DEPLOYMENT_ARTIFACTS);
+ }
+
+ public StorageOperationStatus addInformationalArtifactsToInstance(String toscaElementId, String instanceId, Map<String, ArtifactDataDefinition> instDeplArtifacts) {
+ return addArtifactsToInstance(toscaElementId, instanceId, instDeplArtifacts, EdgeLabelEnum.INSTANCE_ARTIFACTS, VertexTypeEnum.INSTANCE_ARTIFACTS);
+ }
+
+ public StorageOperationStatus addArtifactsToInstance(String toscaElementId, String instanceId, Map<String, ArtifactDataDefinition> instDeplArtifacts, EdgeLabelEnum edgeLabel, VertexTypeEnum vertexType) {
Either<GraphVertex, TitanOperationStatus> metadataVertex = titanDao.getVertexById(toscaElementId, JsonParseFlagEnum.NoParse);
if (metadataVertex.isRight()) {
TitanOperationStatus status = metadataVertex.right().value();
@@ -1629,7 +1637,7 @@ public class NodeTemplateOperation extends BaseOperation {
return DaoStatusConverter.convertTitanStatusToStorageStatus(status);
}
MapArtifactDataDefinition instArtifacts = new MapArtifactDataDefinition(instDeplArtifacts);
- return addToscaDataDeepElementsBlockToToscaElement(metadataVertex.left().value(), EdgeLabelEnum.INST_DEPLOYMENT_ARTIFACTS, VertexTypeEnum.INST_DEPLOYMENT_ARTIFACTS, instArtifacts, instanceId);
+ return addToscaDataDeepElementsBlockToToscaElement(metadataVertex.left().value(),edgeLabel, vertexType, instArtifacts, instanceId);
}
diff --git a/catalog-model/src/main/java/org/openecomp/sdc/be/model/jsontitan/operations/TopologyTemplateOperation.java b/catalog-model/src/main/java/org/openecomp/sdc/be/model/jsontitan/operations/TopologyTemplateOperation.java
index 2d160bfc82..989707bf0c 100644
--- a/catalog-model/src/main/java/org/openecomp/sdc/be/model/jsontitan/operations/TopologyTemplateOperation.java
+++ b/catalog-model/src/main/java/org/openecomp/sdc/be/model/jsontitan/operations/TopologyTemplateOperation.java
@@ -349,9 +349,17 @@ public class TopologyTemplateOperation extends ToscaElementOperation {
return StorageOperationStatus.OK;
}
- public StorageOperationStatus associateInstArtifactToComponent(GraphVertex nodeTypeVertex, Map<String, MapArtifactDataDefinition> instProps) {
+ public StorageOperationStatus associateInstDeploymentArtifactsToComponent(GraphVertex nodeTypeVertex, Map<String, MapArtifactDataDefinition> instArtifacts) {
+ return associateInstanceArtifactsToComponent(nodeTypeVertex, instArtifacts, VertexTypeEnum.INST_DEPLOYMENT_ARTIFACTS, EdgeLabelEnum.INST_DEPLOYMENT_ARTIFACTS);
+ }
+
+ public StorageOperationStatus associateInstArtifactsToComponent(GraphVertex nodeTypeVertex, Map<String, MapArtifactDataDefinition> instArtifacts) {
+ return associateInstanceArtifactsToComponent(nodeTypeVertex, instArtifacts, VertexTypeEnum.INSTANCE_ARTIFACTS, EdgeLabelEnum.INSTANCE_ARTIFACTS);
+ }
+
+ private StorageOperationStatus associateInstanceArtifactsToComponent(GraphVertex nodeTypeVertex, Map<String, MapArtifactDataDefinition> instProps, VertexTypeEnum vertexType, EdgeLabelEnum edgeLabel) {
if (instProps != null && !instProps.isEmpty()) {
- Either<GraphVertex, StorageOperationStatus> assosiateElementToData = assosiateElementToData(nodeTypeVertex, VertexTypeEnum.INST_DEPLOYMENT_ARTIFACTS, EdgeLabelEnum.INST_DEPLOYMENT_ARTIFACTS, instProps);
+ Either<GraphVertex, StorageOperationStatus> assosiateElementToData = assosiateElementToData(nodeTypeVertex, vertexType, edgeLabel, instProps);
if (assosiateElementToData.isRight()) {
return assosiateElementToData.right().value();
}
diff --git a/catalog-model/src/main/java/org/openecomp/sdc/be/model/jsontitan/operations/ToscaElementLifecycleOperation.java b/catalog-model/src/main/java/org/openecomp/sdc/be/model/jsontitan/operations/ToscaElementLifecycleOperation.java
index d34d3aa9f9..51d122524c 100644
--- a/catalog-model/src/main/java/org/openecomp/sdc/be/model/jsontitan/operations/ToscaElementLifecycleOperation.java
+++ b/catalog-model/src/main/java/org/openecomp/sdc/be/model/jsontitan/operations/ToscaElementLifecycleOperation.java
@@ -767,6 +767,12 @@ public class ToscaElementLifecycleOperation extends BaseOperation {
}
}
if (result == null) {
+ Either<GraphVertex, StorageOperationStatus> updateRelationsRes = updateLastModifierEdge(toscaElement, owner, modifier);
+ if (updateRelationsRes.isRight()) {
+ result = updateRelationsRes.right().value();
+ }
+ }
+ if (result == null) {
result = StorageOperationStatus.OK;
}
return result;
diff --git a/catalog-model/src/main/java/org/openecomp/sdc/be/model/jsontitan/operations/ToscaElementOperation.java b/catalog-model/src/main/java/org/openecomp/sdc/be/model/jsontitan/operations/ToscaElementOperation.java
index 5aceb2ffd2..708ef783f1 100644
--- a/catalog-model/src/main/java/org/openecomp/sdc/be/model/jsontitan/operations/ToscaElementOperation.java
+++ b/catalog-model/src/main/java/org/openecomp/sdc/be/model/jsontitan/operations/ToscaElementOperation.java
@@ -1068,7 +1068,7 @@ public abstract class ToscaElementOperation extends BaseOperation {
public <T extends ToscaElement> Either<List<T>, StorageOperationStatus> getElementCatalogData(ComponentTypeEnum componentType, List<ResourceTypeEnum> excludeTypes, boolean isHighestVersions) {
Either<List<GraphVertex>, TitanOperationStatus> listOfComponents;
if (isHighestVersions) {
- listOfComponents = getListOfHighestComponents(componentType, excludeTypes);
+ listOfComponents = getListOfHighestComponents(componentType, excludeTypes, JsonParseFlagEnum.NoParse);
}
else {
listOfComponents = getListOfHighestAndAllCertifiedComponents(componentType, excludeTypes);
@@ -1095,7 +1095,7 @@ public abstract class ToscaElementOperation extends BaseOperation {
return Either.left(result);
}
- private Either<List<GraphVertex>, TitanOperationStatus> getListOfHighestComponents(ComponentTypeEnum componentType, List<ResourceTypeEnum> excludeTypes) {
+ private Either<List<GraphVertex>, TitanOperationStatus> getListOfHighestComponents(ComponentTypeEnum componentType, List<ResourceTypeEnum> excludeTypes, JsonParseFlagEnum parseFlag) {
Map<GraphPropertyEnum, Object> propertiesToMatch = new HashMap<>();
Map<GraphPropertyEnum, Object> propertiesHasNotToMatch = new HashMap<>();
propertiesToMatch.put(GraphPropertyEnum.COMPONENT_TYPE, componentType.name());
@@ -1107,13 +1107,13 @@ public abstract class ToscaElementOperation extends BaseOperation {
}
propertiesHasNotToMatch.put(GraphPropertyEnum.IS_DELETED, true);
- return titanDao.getByCriteria(null, propertiesToMatch, propertiesHasNotToMatch, JsonParseFlagEnum.ParseMetadata);
+ return titanDao.getByCriteria(null, propertiesToMatch, propertiesHasNotToMatch, parseFlag);
}
// highest + (certified && !highest)
public Either<List<GraphVertex>, TitanOperationStatus> getListOfHighestAndAllCertifiedComponents(ComponentTypeEnum componentType, List<ResourceTypeEnum> excludeTypes) {
long startFetchAllStates = System.currentTimeMillis();
- Either<List<GraphVertex>, TitanOperationStatus> highestNodes = getListOfHighestComponents(componentType, excludeTypes);
+ Either<List<GraphVertex>, TitanOperationStatus> highestNodes = getListOfHighestComponents(componentType, excludeTypes, JsonParseFlagEnum.ParseMetadata);
Map<GraphPropertyEnum, Object> propertiesToMatchCertified = new HashMap<>();
Map<GraphPropertyEnum, Object> propertiesHasNotToMatchCertified = new HashMap<>();
diff --git a/catalog-model/src/main/java/org/openecomp/sdc/be/model/jsontitan/operations/ToscaOperationFacade.java b/catalog-model/src/main/java/org/openecomp/sdc/be/model/jsontitan/operations/ToscaOperationFacade.java
index 45a1f2bd31..e3ed9d6471 100644
--- a/catalog-model/src/main/java/org/openecomp/sdc/be/model/jsontitan/operations/ToscaOperationFacade.java
+++ b/catalog-model/src/main/java/org/openecomp/sdc/be/model/jsontitan/operations/ToscaOperationFacade.java
@@ -25,6 +25,7 @@ import fj.data.Either;
import java.util.Map.Entry;
import java.util.stream.Collectors;
import org.apache.commons.collections.CollectionUtils;
+import org.apache.commons.collections.MapUtils;
import org.apache.commons.lang3.StringUtils;
import org.apache.commons.lang3.tuple.ImmutablePair;
import org.apache.commons.lang3.tuple.Pair;
@@ -1097,7 +1098,34 @@ public class ToscaOperationFacade {
}
- public StorageOperationStatus associateArtifactToInstances(Map<String, Map<String, ArtifactDefinition>> instArtifacts, String componentId, User user) {
+ public StorageOperationStatus associateDeploymentArtifactsToInstances(Map<String, Map<String, ArtifactDefinition>> instDeploymentArtifacts, String componentId, User user) {
+
+ Either<GraphVertex, TitanOperationStatus> getVertexEither = titanDao.getVertexById(componentId, JsonParseFlagEnum.NoParse);
+ if (getVertexEither.isRight()) {
+ log.debug("Couldn't fetch component with and unique id {}, error: {}", componentId, getVertexEither.right().value());
+ return DaoStatusConverter.convertTitanStatusToStorageStatus(getVertexEither.right().value());
+
+ }
+
+ GraphVertex vertex = getVertexEither.left().value();
+ Map<String, MapArtifactDataDefinition> instArtMap = new HashMap<>();
+ if (instDeploymentArtifacts != null) {
+
+ MapArtifactDataDefinition artifactsMap;
+ for (Entry<String, Map<String, ArtifactDefinition>> entry : instDeploymentArtifacts.entrySet()) {
+ Map<String, ArtifactDefinition> artList = entry.getValue();
+ Map<String, ArtifactDataDefinition> artifacts = artList.entrySet().stream().collect(Collectors.toMap(Map.Entry::getKey, e -> new ArtifactDataDefinition(e.getValue())));
+ artifactsMap = nodeTemplateOperation.prepareInstDeploymentArtifactPerInstance(artifacts, entry.getKey(), user, NodeTemplateOperation.HEAT_VF_ENV_NAME);
+
+ instArtMap.put(entry.getKey(), artifactsMap);
+ }
+ }
+
+ return topologyTemplateOperation.associateInstDeploymentArtifactsToComponent(vertex, instArtMap);
+
+ }
+
+ public StorageOperationStatus associateArtifactsToInstances(Map<String, Map<String, ArtifactDefinition>> instArtifacts, String componentId, User user) {
Either<GraphVertex, TitanOperationStatus> getVertexEither = titanDao.getVertexById(componentId, JsonParseFlagEnum.NoParse);
if (getVertexEither.isRight()) {
@@ -1114,13 +1142,13 @@ public class ToscaOperationFacade {
for (Entry<String, Map<String, ArtifactDefinition>> entry : instArtifacts.entrySet()) {
Map<String, ArtifactDefinition> artList = entry.getValue();
Map<String, ArtifactDataDefinition> artifacts = artList.entrySet().stream().collect(Collectors.toMap(Map.Entry::getKey, e -> new ArtifactDataDefinition(e.getValue())));
- artifactsMap = nodeTemplateOperation.prepareInstDeploymentArtifactPerInstance(artifacts, entry.getKey(), user, NodeTemplateOperation.HEAT_VF_ENV_NAME);
+ artifactsMap = new MapArtifactDataDefinition(artifacts);
instArtMap.put(entry.getKey(), artifactsMap);
}
}
- return topologyTemplateOperation.associateInstArtifactToComponent(vertex, instArtMap);
+ return topologyTemplateOperation.associateInstArtifactsToComponent(vertex, instArtMap);
}
@@ -1913,6 +1941,15 @@ public class ToscaOperationFacade {
return nodeTemplateOperation.addDeploymentArtifactsToInstance(componentId, componentInstance.getUniqueId(), instDeplArtifacts);
}
+
+ public StorageOperationStatus addInformationalArtifactsToInstance(String componentId, ComponentInstance componentInstance, Map<String, ArtifactDefinition> artifacts) {
+ StorageOperationStatus status = StorageOperationStatus.OK;
+ if(MapUtils.isNotEmpty(artifacts)){
+ Map<String, ArtifactDataDefinition> instDeplArtifacts = artifacts.entrySet().stream().collect(Collectors.toMap(Map.Entry::getKey, e -> new ArtifactDataDefinition(e.getValue())));
+ status= nodeTemplateOperation.addInformationalArtifactsToInstance(componentId, componentInstance.getUniqueId(), instDeplArtifacts);
+ }
+ return status;
+ }
public StorageOperationStatus generateCustomizationUUIDOnInstance(String componentId, String instanceId) {
return nodeTemplateOperation.generateCustomizationUUIDOnInstance(componentId, instanceId);
diff --git a/catalog-model/src/main/java/org/openecomp/sdc/be/model/tosca/ToscaFunctions.java b/catalog-model/src/main/java/org/openecomp/sdc/be/model/tosca/ToscaFunctions.java
new file mode 100644
index 0000000000..e6969bc5c2
--- /dev/null
+++ b/catalog-model/src/main/java/org/openecomp/sdc/be/model/tosca/ToscaFunctions.java
@@ -0,0 +1,19 @@
+package org.openecomp.sdc.be.model.tosca;
+
+/**
+ * tosca functions supported by sdc
+ */
+public enum ToscaFunctions {
+
+ GET_INPUT("get_input");
+
+ private String functionName;
+
+ ToscaFunctions(String functionName) {
+ this.functionName = functionName;
+ }
+
+ public String getFunctionName() {
+ return functionName;
+ }
+}
diff --git a/catalog-model/src/main/java/org/openecomp/sdc/be/model/tosca/converters/DataTypePropertyConverter.java b/catalog-model/src/main/java/org/openecomp/sdc/be/model/tosca/converters/DataTypePropertyConverter.java
new file mode 100644
index 0000000000..2d389f5fe5
--- /dev/null
+++ b/catalog-model/src/main/java/org/openecomp/sdc/be/model/tosca/converters/DataTypePropertyConverter.java
@@ -0,0 +1,130 @@
+package org.openecomp.sdc.be.model.tosca.converters;
+
+import com.google.gson.Gson;
+import com.google.gson.JsonElement;
+import com.google.gson.JsonObject;
+import com.google.gson.JsonParser;
+import com.google.gson.stream.JsonReader;
+import org.openecomp.sdc.be.model.DataTypeDefinition;
+import org.openecomp.sdc.be.model.PropertyDefinition;
+import org.openecomp.sdc.common.util.JsonUtils;
+
+import java.io.StringReader;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+public class DataTypePropertyConverter {
+
+ private static final DataTypePropertyConverter INSTANCE = new DataTypePropertyConverter();
+ private static final JsonParser jsonParser = new JsonParser();
+ private static final Gson gson = new Gson();
+
+ private DataTypePropertyConverter() {
+ }
+
+ public static DataTypePropertyConverter getInstance() {
+ return INSTANCE;
+ }
+
+ /**
+ *
+ * @param propertyDataType the data type
+ * @param dataTypes all data types in the system mapped by their name
+ * @return a json representation of all the given data type properties default values and recursively their data type properties
+ */
+ public String getDataTypePropertiesDefaultValuesRec(String propertyDataType, Map<String, DataTypeDefinition> dataTypes) {
+ JsonObject defaultValues = getDataTypePropsDefaultValuesRec(propertyDataType, dataTypes);
+ return !defaultValues.isJsonNull() ? gson.toJson(defaultValues) : null;
+ }
+
+ /**
+ * Takes a json representation of a tosca property value and merges all the default values of the property data type
+ * @param value the json representation of a tosca property value
+ * @param propertyDataType data type from which to merge default values
+ * @param dataTypes all data types in the system mapped by their name
+ * for example: for value {a: {b: c}} we could have a default value {a: {d: e}} (property a has two sub properties but only b was overridden)
+ * so the complete value is {a: {b: c, d: e}}
+ */
+ public void mergeDataTypeDefaultValuesWithPropertyValue(JsonObject value, String propertyDataType, Map<String, DataTypeDefinition> dataTypes) {
+ JsonObject dataTypeDefaultValues = getDataTypePropsDefaultValuesRec(propertyDataType, dataTypes);
+ mergeDefaultValuesRec(dataTypeDefaultValues, value);
+ }
+
+ private void mergeDefaultValuesRec(JsonObject defaultValue, JsonObject value) {
+ if (ToscaConverterUtils.isGetInputValue(value)) {
+ return;
+ }
+ for (Map.Entry<String, JsonElement> defVal : defaultValue.entrySet()) {
+ mergeDefaultValue(value, defVal.getKey(), defVal.getValue());
+ }
+ }
+
+ private void mergeDefaultValue(JsonObject value, String propName, JsonElement defValue) {
+ if (defValueWasNotOverridden(value, propName)) {
+ value.add(propName, defValue);
+ } else if (notPrimitivePropValue(value, defValue, propName)) {
+ JsonElement propValue = value.get(propName);
+ mergeDefaultValuesRec(defValue.getAsJsonObject(), propValue.getAsJsonObject());
+ }
+ }
+
+ private boolean notPrimitivePropValue(JsonObject value, JsonElement defValue, String propName) {
+ return value.get(propName).isJsonObject() && defValue.isJsonObject();
+ }
+
+ private boolean defValueWasNotOverridden(JsonObject value, String propName) {
+ return !value.has(propName);
+ }
+
+ private JsonObject getDataTypePropsDefaultValuesRec(String propertyDataType, Map<String, DataTypeDefinition> dataTypes) {
+ Map<String, PropertyDefinition> allParentsProps = getAllDataTypeProperties(dataTypes.get(propertyDataType));
+ JsonObject dataTypeDefaultsJson = new JsonObject();
+ for (Map.Entry<String, PropertyDefinition> propertyEntry : allParentsProps.entrySet()) {
+ PropertyDefinition propertyDefinition = propertyEntry.getValue();
+ addDefaultValueToJson(dataTypes, dataTypeDefaultsJson, propertyDefinition);
+ }
+ return dataTypeDefaultsJson;
+ }
+
+ private void addDefaultValueToJson(Map<String, DataTypeDefinition> dataTypes, JsonObject dataTypePropsDefaults, PropertyDefinition propertyDefinition) {
+ String propName = propertyDefinition.getName();
+ JsonElement defVal = getDefaultValue(dataTypes, dataTypePropsDefaults, propertyDefinition);
+ if (!JsonUtils.isEmptyJson(defVal)) {
+ dataTypePropsDefaults.add(propName, defVal);
+ }
+ }
+
+ private JsonElement getDefaultValue(Map<String, DataTypeDefinition> dataTypes, JsonObject dataTypePropsDefaults, PropertyDefinition propertyDefinition) {
+ JsonElement defVal = new JsonObject();
+ String propName = propertyDefinition.getName();
+ String propDefaultVal = propertyDefinition.getDefaultValue();
+ if(!JsonUtils.containsEntry(dataTypePropsDefaults, propName) && propDefaultVal != null){
+ defVal = convertToJson(propDefaultVal);
+ } else if (!JsonUtils.containsEntry(dataTypePropsDefaults, propName)) {
+ defVal = getDataTypePropsDefaultValuesRec(propertyDefinition.getType(), dataTypes);
+ }
+ return defVal;
+ }
+
+ private JsonElement convertToJson(String propDefaultVal) {
+ JsonReader jsonReader = new JsonReader(new StringReader(propDefaultVal));
+ jsonReader.setLenient(true);
+ return jsonParser.parse(jsonReader);
+ }
+
+ private Map<String, PropertyDefinition> getAllDataTypeProperties(DataTypeDefinition dataTypeDefinition) {
+ Map<String, PropertyDefinition> allParentsProps = new HashMap<>();
+ while (dataTypeDefinition != null) {
+
+ List<PropertyDefinition> currentParentsProps = dataTypeDefinition.getProperties();
+ if (currentParentsProps != null) {
+ currentParentsProps.stream().forEach(p -> allParentsProps.put(p.getName(), p));
+ }
+
+ dataTypeDefinition = dataTypeDefinition.getDerivedFrom();
+ }
+ return allParentsProps;
+ }
+
+}
diff --git a/catalog-model/src/main/java/org/openecomp/sdc/be/model/tosca/converters/HeatJsonConverter.java b/catalog-model/src/main/java/org/openecomp/sdc/be/model/tosca/converters/HeatJsonConverter.java
index 6e077d60a1..9922c0f05d 100644
--- a/catalog-model/src/main/java/org/openecomp/sdc/be/model/tosca/converters/HeatJsonConverter.java
+++ b/catalog-model/src/main/java/org/openecomp/sdc/be/model/tosca/converters/HeatJsonConverter.java
@@ -39,12 +39,15 @@ public class HeatJsonConverter implements PropertyValueConverter {
@Override
public String convert(String original, String innerType, Map<String, DataTypeDefinition> dataTypes) {
- String coverted = ValidationUtils.removeNoneUtf8Chars(original);
- coverted = ValidationUtils.removeHtmlTagsOnly(coverted);
- coverted = ValidationUtils.normaliseWhitespace(coverted);
- coverted = ValidationUtils.stripOctets(coverted);
+ if (original == null) {
+ return null;
+ }
+ String converted = ValidationUtils.removeNoneUtf8Chars(original);
+ converted = ValidationUtils.removeHtmlTagsOnly(converted);
+ converted = ValidationUtils.normaliseWhitespace(converted);
+ converted = ValidationUtils.stripOctets(converted);
// As opposed to string converter, keeping the " and ' symbols
- return coverted;
+ return converted;
}
}
diff --git a/catalog-model/src/main/java/org/openecomp/sdc/be/model/tosca/converters/ToscaConverterUtils.java b/catalog-model/src/main/java/org/openecomp/sdc/be/model/tosca/converters/ToscaConverterUtils.java
new file mode 100644
index 0000000000..159addcbc9
--- /dev/null
+++ b/catalog-model/src/main/java/org/openecomp/sdc/be/model/tosca/converters/ToscaConverterUtils.java
@@ -0,0 +1,13 @@
+package org.openecomp.sdc.be.model.tosca.converters;
+
+import com.google.gson.JsonElement;
+import com.google.gson.JsonObject;
+import org.openecomp.sdc.be.model.tosca.ToscaFunctions;
+
+public class ToscaConverterUtils {
+
+ public static boolean isGetInputValue(JsonObject value) {
+ return value.get(ToscaFunctions.GET_INPUT.getFunctionName()) != null;
+ }
+
+}
diff --git a/catalog-model/src/main/java/org/openecomp/sdc/be/model/tosca/converters/ToscaMapValueConverter.java b/catalog-model/src/main/java/org/openecomp/sdc/be/model/tosca/converters/ToscaMapValueConverter.java
index 0673033546..5b565bf62a 100644
--- a/catalog-model/src/main/java/org/openecomp/sdc/be/model/tosca/converters/ToscaMapValueConverter.java
+++ b/catalog-model/src/main/java/org/openecomp/sdc/be/model/tosca/converters/ToscaMapValueConverter.java
@@ -193,22 +193,8 @@ public class ToscaMapValueConverter extends ToscaValueBaseConverter implements T
}
JsonObject asJsonObjectIn = entryValue.getAsJsonObject();
- DataTypeDefinition dataTypeDefinition = dataTypes.get(innerType);
- Map<String, PropertyDefinition> allProperties = getAllProperties(dataTypeDefinition);
+ DataTypePropertyConverter.getInstance().mergeDataTypeDefaultValuesWithPropertyValue(asJsonObjectIn, innerType, dataTypes);
Map<String, Object> toscaObjectPresentation = new HashMap<>();
-
- for (Entry<String, PropertyDefinition> entry : allProperties.entrySet()) {
- String propName = entry.getKey();
- PropertyDefinition propertyDefinition = entry.getValue();
- JsonElement elementValue = asJsonObjectIn.get(propName);
- if(elementValue == null && propertyDefinition.getDefaultValue() != null){
- JsonReader jsonReader = new JsonReader(new StringReader(propertyDefinition.getDefaultValue()));
- jsonReader.setLenient(true);
- elementValue = jsonParser.parse(jsonReader);
- asJsonObjectIn.add(propName, elementValue);
- }
- }
-
Set<Entry<String, JsonElement>> entrySetIn = asJsonObjectIn.entrySet();
for (Entry<String, JsonElement> entry : entrySetIn) {
@@ -217,6 +203,8 @@ public class ToscaMapValueConverter extends ToscaValueBaseConverter implements T
JsonElement elementValue = entry.getValue();
Object convValue;
if (isScalarF == false) {
+ DataTypeDefinition dataTypeDefinition = dataTypes.get(innerType);
+ Map<String, PropertyDefinition> allProperties = getAllProperties(dataTypeDefinition);
PropertyDefinition propertyDefinition = allProperties.get(propName);
if (propertyDefinition == null) {
log.trace("The property {} was not found under data type . Parse as map", propName);