summaryrefslogtreecommitdiffstats
path: root/catalog-be/src/main/java/org
diff options
context:
space:
mode:
Diffstat (limited to 'catalog-be/src/main/java/org')
-rw-r--r--catalog-be/src/main/java/org/openecomp/sdc/be/components/csar/YamlTemplateParsingHandler.java33
-rw-r--r--catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/ResourceImportManager.java6
-rw-r--r--catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/ServiceImportBusinessLogic.java20
-rw-r--r--catalog-be/src/main/java/org/openecomp/sdc/be/tosca/AttributeConverter.java12
-rw-r--r--catalog-be/src/main/java/org/openecomp/sdc/be/tosca/ToscaExportHandler.java5
5 files changed, 70 insertions, 6 deletions
diff --git a/catalog-be/src/main/java/org/openecomp/sdc/be/components/csar/YamlTemplateParsingHandler.java b/catalog-be/src/main/java/org/openecomp/sdc/be/components/csar/YamlTemplateParsingHandler.java
index ed753fdd18..940363bce4 100644
--- a/catalog-be/src/main/java/org/openecomp/sdc/be/components/csar/YamlTemplateParsingHandler.java
+++ b/catalog-be/src/main/java/org/openecomp/sdc/be/components/csar/YamlTemplateParsingHandler.java
@@ -19,6 +19,7 @@
* Modifications copyright (c) 2019 Nokia
* ================================================================================
*/
+
package org.openecomp.sdc.be.components.csar;
import static java.util.stream.Collectors.toList;
@@ -29,6 +30,7 @@ import static org.openecomp.sdc.be.components.impl.ImportUtils.findFirstToscaMap
import static org.openecomp.sdc.be.components.impl.ImportUtils.findToscaElement;
import static org.openecomp.sdc.be.components.impl.ImportUtils.loadYamlAsStrictMap;
import static org.openecomp.sdc.be.utils.TypeUtils.ToscaTagNamesEnum.ARTIFACTS;
+import static org.openecomp.sdc.be.utils.TypeUtils.ToscaTagNamesEnum.ATTRIBUTES;
import static org.openecomp.sdc.be.utils.TypeUtils.ToscaTagNamesEnum.CAPABILITIES;
import static org.openecomp.sdc.be.utils.TypeUtils.ToscaTagNamesEnum.CAPABILITY;
import static org.openecomp.sdc.be.utils.TypeUtils.ToscaTagNamesEnum.DEFAULT_VALUE;
@@ -100,6 +102,7 @@ import org.openecomp.sdc.be.model.PolicyDefinition;
import org.openecomp.sdc.be.model.PolicyTypeDefinition;
import org.openecomp.sdc.be.model.PropertyDefinition;
import org.openecomp.sdc.be.model.UploadArtifactInfo;
+import org.openecomp.sdc.be.model.UploadAttributeInfo;
import org.openecomp.sdc.be.model.UploadCapInfo;
import org.openecomp.sdc.be.model.UploadComponentInstanceInfo;
import org.openecomp.sdc.be.model.UploadPropInfo;
@@ -645,6 +648,7 @@ public class YamlTemplateParsingHandler {
setCapabilities(nodeTemplateInfo, nodeTemplateJsonMap);
setArtifacts(nodeTemplateInfo, nodeTemplateJsonMap);
updateProperties(nodeTemplateInfo, nodeTemplateJsonMap);
+ updateAttributes(nodeTemplateInfo, nodeTemplateJsonMap);
setDirectives(nodeTemplateInfo, nodeTemplateJsonMap);
setNodeFilter(nodeTemplateInfo, nodeTemplateJsonMap);
setSubstitutions(substitutionMappings, nodeTemplateInfo);
@@ -682,6 +686,15 @@ public class YamlTemplateParsingHandler {
}
}
+ private void updateAttributes(UploadComponentInstanceInfo nodeTemplateInfo, Map<String, Object> nodeTemplateJsonMap) {
+ if (nodeTemplateJsonMap.containsKey(ATTRIBUTES.getElementName())) {
+ Map<String, UploadAttributeInfo> attributes = buildAttributeModuleFromYaml(nodeTemplateJsonMap);
+ if (!attributes.isEmpty()) {
+ nodeTemplateInfo.setAttributes(attributes);
+ }
+ }
+ }
+
private void setCapabilities(UploadComponentInstanceInfo nodeTemplateInfo, Map<String, Object> nodeTemplateJsonMap) {
if (nodeTemplateJsonMap.containsKey(CAPABILITIES.getElementName())) {
Map<String, List<UploadCapInfo>> eitherCapRes = createCapModuleFromYaml(nodeTemplateJsonMap);
@@ -915,6 +928,26 @@ public class YamlTemplateParsingHandler {
return regTemplateInfo;
}
+ private Map<String, UploadAttributeInfo> buildAttributeModuleFromYaml(Map<String, Object> nodeTemplateJsonMap) {
+ Map<String, UploadAttributeInfo> moduleAttribute = new HashMap<>();
+ Either<Map<String, Object>, ResultStatusEnum> toscaAttributes = findFirstToscaMapElement(nodeTemplateJsonMap, ATTRIBUTES);
+ if (toscaAttributes.isLeft()) {
+ Map<String, Object> jsonAttributes = toscaAttributes.left().value();
+ for (Map.Entry<String, Object> jsonAttributeObj : jsonAttributes.entrySet()) {
+ UploadAttributeInfo attributeDef = buildAttribute(jsonAttributeObj.getKey(), jsonAttributeObj.getValue());
+ moduleAttribute.put(attributeDef.getName(), attributeDef);
+ }
+ }
+ return moduleAttribute;
+ }
+
+ private UploadAttributeInfo buildAttribute(String attributeName, Object attributeValue) {
+ UploadAttributeInfo attributeDef = new UploadAttributeInfo();
+ attributeDef.setValue(attributeValue);
+ attributeDef.setName(attributeName);
+ return attributeDef;
+ }
+
private Map<String, List<UploadPropInfo>> buildPropModuleFromYaml(Map<String, Object> nodeTemplateJsonMap) {
Map<String, List<UploadPropInfo>> moduleProp = new HashMap<>();
Either<Map<String, Object>, ResultStatusEnum> toscaProperties = findFirstToscaMapElement(nodeTemplateJsonMap, PROPERTIES);
diff --git a/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/ResourceImportManager.java b/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/ResourceImportManager.java
index aa420673c7..d02a84f491 100644
--- a/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/ResourceImportManager.java
+++ b/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/ResourceImportManager.java
@@ -66,6 +66,7 @@ import org.openecomp.sdc.be.dao.jsongraph.GraphVertex;
import org.openecomp.sdc.be.dao.jsongraph.types.JsonParseFlagEnum;
import org.openecomp.sdc.be.dao.jsongraph.types.VertexTypeEnum;
import org.openecomp.sdc.be.datatypes.elements.PropertyDataDefinition;
+import org.openecomp.sdc.be.datatypes.elements.SchemaDefinition;
import org.openecomp.sdc.be.datatypes.enums.ComponentTypeEnum;
import org.openecomp.sdc.be.datatypes.enums.GraphPropertyEnum;
import org.openecomp.sdc.be.datatypes.enums.JsonPresentationFields;
@@ -630,6 +631,11 @@ public class ResourceImportManager {
}
final AttributeDefinition attributeDefinition = entry.getValue();
attributeDefinition.setName(name);
+ if (attributeDefinition.getEntry_schema() != null && attributeDefinition.getEntry_schema().getType() != null) {
+ attributeDefinition.setSchema(new SchemaDefinition());
+ attributeDefinition.getSchema().setProperty(new PropertyDataDefinition());
+ attributeDefinition.getSchema().getProperty().setType(entry.getValue().getEntry_schema().getType());
+ }
attributeDefinitionList.add(attributeDefinition);
}
resource.setAttributes(attributeDefinitionList);
diff --git a/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/ServiceImportBusinessLogic.java b/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/ServiceImportBusinessLogic.java
index 3c21ae16a7..225a6c4408 100644
--- a/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/ServiceImportBusinessLogic.java
+++ b/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/ServiceImportBusinessLogic.java
@@ -23,6 +23,7 @@ import static org.openecomp.sdc.be.components.impl.ImportUtils.findFirstToscaStr
import static org.openecomp.sdc.be.components.impl.ImportUtils.getPropertyJsonStringValue;
import static org.openecomp.sdc.be.tosca.CsarUtils.VF_NODE_TYPE_ARTIFACTS_PATH_PATTERN;
+import com.google.gson.Gson;
import fj.data.Either;
import java.util.ArrayList;
import java.util.Collection;
@@ -107,6 +108,7 @@ import org.openecomp.sdc.be.model.RequirementCapabilityRelDef;
import org.openecomp.sdc.be.model.RequirementDefinition;
import org.openecomp.sdc.be.model.Resource;
import org.openecomp.sdc.be.model.Service;
+import org.openecomp.sdc.be.model.UploadAttributeInfo;
import org.openecomp.sdc.be.model.UploadComponentInstanceInfo;
import org.openecomp.sdc.be.model.UploadNodeFilterInfo;
import org.openecomp.sdc.be.model.UploadPropInfo;
@@ -1447,6 +1449,7 @@ public class ServiceImportBusinessLogic {
}
if (originResource.getAttributes() != null && !originResource.getAttributes().isEmpty()) {
instAttributes.put(resourceInstanceId, originResource.getAttributes());
+ addAttributeValueToResourceInstance(instAttributes, uploadComponentInstanceInfo.getAttributes());
}
if (uploadComponentInstanceInfo.getUploadNodeFilterInfo() != null) {
instNodeFilter.put(resourceInstanceId, uploadComponentInstanceInfo.getUploadNodeFilterInfo());
@@ -1514,6 +1517,23 @@ public class ServiceImportBusinessLogic {
}
}
+ private void addAttributeValueToResourceInstance(Map<String, List<AttributeDefinition>> instAttributes,
+ Map<String, UploadAttributeInfo> attributeMap) {
+ if (attributeMap == null) {
+ return;
+ }
+ attributeMap.forEach((attributeName, attributeValue) -> instAttributes.values()
+ .forEach(value -> value.stream().filter(attr -> attr.getName().equals(attributeName)).forEach(attr -> {
+ if (attributeValue.getValue() instanceof Collection<?> || attributeValue.getValue() instanceof Map<?, ?>) {
+ Gson gson = new Gson();
+ String json = gson.toJson(attributeValue.getValue());
+ attr.setValue(json);
+ } else {
+ attr.setValue(String.valueOf(attributeValue.getValue()));
+ }
+ })));
+ }
+
protected ResponseFormat addPropertyValuesToRi(UploadComponentInstanceInfo uploadComponentInstanceInfo, Component component,
Resource originResource, ComponentInstance currentCompInstance,
Map<String, List<ComponentInstanceProperty>> instProperties,
diff --git a/catalog-be/src/main/java/org/openecomp/sdc/be/tosca/AttributeConverter.java b/catalog-be/src/main/java/org/openecomp/sdc/be/tosca/AttributeConverter.java
index 561480dd64..40d531d788 100644
--- a/catalog-be/src/main/java/org/openecomp/sdc/be/tosca/AttributeConverter.java
+++ b/catalog-be/src/main/java/org/openecomp/sdc/be/tosca/AttributeConverter.java
@@ -27,6 +27,7 @@ import java.io.StringReader;
import java.util.Map;
import org.apache.commons.lang3.StringUtils;
import org.onap.sdc.tosca.datatypes.model.EntrySchema;
+import org.openecomp.sdc.be.datatypes.elements.SchemaDefinition;
import org.openecomp.sdc.be.model.AttributeDefinition;
import org.openecomp.sdc.be.model.DataTypeDefinition;
import org.openecomp.sdc.be.model.tosca.ToscaPropertyType;
@@ -73,7 +74,14 @@ public class AttributeConverter {
final ToscaAttribute toscaAttribute = new ToscaAttribute();
LOGGER.trace("Converting attribute '{}' from type '{}' with default value '{}'", attributeDefinition.getName(), attributeDefinition.getType(),
attributeDefinition.getDefaultValue());
- toscaAttribute.setEntrySchema(convert(attributeDefinition.getEntry_schema()));
+ SchemaDefinition schema = attributeDefinition.getSchema();
+ if (schema != null && schema.getProperty() != null && schema.getProperty().getType() != null
+ && StringUtils.isNotEmpty(schema.getProperty().getType())) {
+ final ToscaSchemaDefinition toscaSchemaDefinition = new ToscaSchemaDefinition();
+ toscaSchemaDefinition.setType(schema.getProperty().getType());
+ toscaSchemaDefinition.setDescription(schema.getProperty().getDescription());
+ toscaAttribute.setEntrySchema(toscaSchemaDefinition);
+ }
toscaAttribute.setType(attributeDefinition.getType());
toscaAttribute.setDescription(attributeDefinition.getDescription());
toscaAttribute.setStatus(attributeDefinition.getStatus());
@@ -173,7 +181,7 @@ public class AttributeConverter {
public void convertAndAddValue(final Map<String, Object> attribs,
final AttributeDefinition attribute) {
- final Object convertedValue = convertToToscaObject(attribute, attribute.getDefaultValue(), false);
+ final Object convertedValue = convertToToscaObject(attribute, attribute.getValue(), false);
if (!ToscaValueBaseConverter.isEmptyObjectValue(convertedValue)) {
attribs.put(attribute.getName(), convertedValue);
}
diff --git a/catalog-be/src/main/java/org/openecomp/sdc/be/tosca/ToscaExportHandler.java b/catalog-be/src/main/java/org/openecomp/sdc/be/tosca/ToscaExportHandler.java
index 069e4f366e..a8aa6b33a9 100644
--- a/catalog-be/src/main/java/org/openecomp/sdc/be/tosca/ToscaExportHandler.java
+++ b/catalog-be/src/main/java/org/openecomp/sdc/be/tosca/ToscaExportHandler.java
@@ -1128,10 +1128,7 @@ public class ToscaExportHandler {
final Map<String, Object> attribs) {
if (isNotEmpty(componentInstancesAttributes) && componentInstancesAttributes.containsKey(instanceUniqueId)) {
- componentInstancesAttributes.get(instanceUniqueId).stream()
- // Filters out Attributes with empty default values
- .filter(attributeDefinition -> StringUtils.isNotEmpty(attributeDefinition.getDefaultValue()))
- // Converts and adds each value to attribute map
+ componentInstancesAttributes.get(instanceUniqueId)
.forEach(attributeDefinition -> attributeConverter.convertAndAddValue(attribs, attributeDefinition));
}
}