Merge "Allow to declare a property as an output" into 20.3
diff --git a/catalog-be/src/main/docker/backend/chef-repo/cookbooks/sdc-catalog-be/templates/default/BE-configuration.yaml.erb b/catalog-be/src/main/docker/backend/chef-repo/cookbooks/sdc-catalog-be/templates/default/BE-configuration.yaml.erb
index 060712d..9f7112a 100644
--- a/catalog-be/src/main/docker/backend/chef-repo/cookbooks/sdc-catalog-be/templates/default/BE-configuration.yaml.erb
+++ b/catalog-be/src/main/docker/backend/chef-repo/cookbooks/sdc-catalog-be/templates/default/BE-configuration.yaml.erb
@@ -61,12 +61,9 @@
file: groups.yml
- policies:
file: policies.yml
- - annotations:
- file: annotations.yml
# Global CSAR Import Files
globalCsarImports:
- - annotations.yml
- artifacts.yml
- capabilities.yml
- data.yml
@@ -184,6 +181,7 @@
- VL
Service:
"*":
+ - VFC
- VF
- CR
- CP
@@ -1028,11 +1026,14 @@
PNF: org.openecomp.resource.abstract.nodes.PNF
Service: org.openecomp.resource.abstract.nodes.service
ETSI Network Service: tosca.nodes.nfv.NS
- Ericsson Orchestrator.Base Service: com.ericsson.so.nodes.baseservice
- Ericsson Orchestrator Compound Service Template: com.ericsson.so.nodes.compoundservice
+
+resourceNodeTypes:
+ Ericsson Orchestrator:
+ Base Service: com.ericsson.so.nodes.baseservice
serviceNodeTypes:
ETSI Network Service: tosca.nodes.nfv.NS
+ Ericsson Orchestrator Compound Service Template: com.ericsson.so.nodes.compoundservice
workloadContext: Production
diff --git a/catalog-be/src/main/java/org/openecomp/sdc/be/components/csar/CsarBusinessLogic.java b/catalog-be/src/main/java/org/openecomp/sdc/be/components/csar/CsarBusinessLogic.java
index 15cde43..f88b0da 100644
--- a/catalog-be/src/main/java/org/openecomp/sdc/be/components/csar/CsarBusinessLogic.java
+++ b/catalog-be/src/main/java/org/openecomp/sdc/be/components/csar/CsarBusinessLogic.java
@@ -22,13 +22,12 @@
package org.openecomp.sdc.be.components.csar;
import fj.data.Either;
+import java.util.Map;
import org.apache.commons.lang3.tuple.ImmutablePair;
import org.openecomp.sdc.be.components.impl.BaseBusinessLogic;
import org.openecomp.sdc.be.components.impl.CsarValidationUtils;
-import org.openecomp.sdc.be.components.impl.GroupBusinessLogic;
import org.openecomp.sdc.be.components.impl.exceptions.ByActionStatusComponentException;
import org.openecomp.sdc.be.components.impl.exceptions.ByResponseFormatComponentException;
-import org.openecomp.sdc.be.components.impl.exceptions.ComponentException;
import org.openecomp.sdc.be.config.BeEcompErrorManager;
import org.openecomp.sdc.be.dao.api.ActionStatus;
import org.openecomp.sdc.be.model.Component;
@@ -52,8 +51,6 @@
import org.openecomp.sdc.exception.ResponseFormat;
import org.springframework.beans.factory.annotation.Autowired;
-import java.util.Map;
-
@org.springframework.stereotype.Component("csarBusinessLogic")
public class CsarBusinessLogic extends BaseBusinessLogic {
@@ -70,7 +67,6 @@
IGroupOperation groupOperation,
IGroupInstanceOperation groupInstanceOperation,
IGroupTypeOperation groupTypeOperation,
- GroupBusinessLogic groupBusinessLogic,
InterfaceOperation interfaceOperation,
InterfaceLifecycleOperation interfaceLifecycleTypeOperation,
YamlTemplateParsingHandler yamlHandler,
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 58f46bc..f74d6e6 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
@@ -21,67 +21,8 @@
*/
package org.openecomp.sdc.be.components.csar;
-import com.google.common.collect.Lists;
-import com.google.common.collect.Maps;
-import com.google.gson.Gson;
-import fj.data.Either;
-import java.util.Collections;
-import java.util.EnumMap;
-import java.util.Objects;
-import org.apache.commons.collections.CollectionUtils;
-import org.apache.commons.collections.MapUtils;
-import org.apache.commons.lang.StringUtils;
-import org.openecomp.sdc.be.components.impl.AnnotationBusinessLogic;
-import org.openecomp.sdc.be.components.impl.GroupTypeBusinessLogic;
-import org.openecomp.sdc.be.components.impl.ImportUtils;
-import org.openecomp.sdc.be.components.impl.NodeFilterUploadCreator;
-import org.openecomp.sdc.be.components.impl.PolicyTypeBusinessLogic;
-import org.openecomp.sdc.be.components.impl.exceptions.ByActionStatusComponentException;
-import org.openecomp.sdc.be.components.utils.PropertiesUtils;
-import org.openecomp.sdc.be.config.BeEcompErrorManager;
-import org.openecomp.sdc.be.dao.api.ActionStatus;
-import org.openecomp.sdc.be.dao.jsongraph.JanusGraphDao;
-import org.openecomp.sdc.be.datatypes.elements.CapabilityDataDefinition;
-import org.openecomp.sdc.be.datatypes.elements.GetInputValueDataDefinition;
-import org.openecomp.sdc.be.datatypes.elements.PolicyTargetType;
-import org.openecomp.sdc.be.datatypes.elements.PropertyDataDefinition;
-import org.openecomp.sdc.be.model.CapabilityDefinition;
-import org.openecomp.sdc.be.model.ComponentInstanceProperty;
-import org.openecomp.sdc.be.model.GroupDefinition;
-import org.openecomp.sdc.be.model.GroupTypeDefinition;
-import org.openecomp.sdc.be.model.InputDefinition;
-import org.openecomp.sdc.be.model.NodeTypeInfo;
-import org.openecomp.sdc.be.model.ParsedToscaYamlInfo;
-import org.openecomp.sdc.be.model.PolicyDefinition;
-import org.openecomp.sdc.be.model.PolicyTypeDefinition;
-import org.openecomp.sdc.be.model.Resource;
-import org.openecomp.sdc.be.model.UploadArtifactInfo;
-import org.openecomp.sdc.be.model.UploadCapInfo;
-import org.openecomp.sdc.be.model.UploadComponentInstanceInfo;
-import org.openecomp.sdc.be.model.UploadPropInfo;
-import org.openecomp.sdc.be.model.UploadReqInfo;
-import org.openecomp.sdc.be.model.tosca.ToscaPropertyType;
-import org.openecomp.sdc.be.utils.TypeUtils;
-import org.openecomp.sdc.common.log.wrappers.Logger;
-import org.springframework.stereotype.Component;
-import org.yaml.snakeyaml.parser.ParserException;
-
-import java.util.ArrayList;
-import java.util.Collection;
-import java.util.HashMap;
-import java.util.List;
-import java.util.Map;
-import java.util.Set;
-import java.util.regex.Pattern;
-import java.util.stream.Collectors;
-
import static java.util.stream.Collectors.toList;
-import static org.openecomp.sdc.be.components.impl.ImportUtils.ResultStatusEnum;
-import static org.openecomp.sdc.be.components.impl.ImportUtils.ToscaElementTypeEnum;
-import static org.openecomp.sdc.be.components.impl.ImportUtils.findFirstToscaListElement;
import static org.openecomp.sdc.be.components.impl.ImportUtils.findFirstToscaMapElement;
-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.CAPABILITIES;
import static org.openecomp.sdc.be.utils.TypeUtils.ToscaTagNamesEnum.CAPABILITY;
@@ -103,6 +44,63 @@
import static org.openecomp.sdc.be.utils.TypeUtils.ToscaTagNamesEnum.TYPE;
import static org.openecomp.sdc.be.utils.TypeUtils.ToscaTagNamesEnum.VALID_SOURCE_TYPES;
+import com.google.common.collect.Lists;
+import com.google.common.collect.Maps;
+import com.google.gson.Gson;
+import fj.data.Either;
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.Collections;
+import java.util.EnumMap;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+import java.util.Objects;
+import java.util.Set;
+import java.util.regex.Pattern;
+import java.util.stream.Collectors;
+import org.apache.commons.collections.CollectionUtils;
+import org.apache.commons.collections.MapUtils;
+import org.apache.commons.lang.StringUtils;
+import org.openecomp.sdc.be.components.impl.AnnotationBusinessLogic;
+import org.openecomp.sdc.be.components.impl.GroupTypeBusinessLogic;
+import org.openecomp.sdc.be.components.impl.ImportUtils;
+import org.openecomp.sdc.be.components.impl.ImportUtils.ResultStatusEnum;
+import org.openecomp.sdc.be.components.impl.ImportUtils.ToscaElementTypeEnum;
+import org.openecomp.sdc.be.components.impl.NodeFilterUploadCreator;
+import org.openecomp.sdc.be.components.impl.PolicyTypeBusinessLogic;
+import org.openecomp.sdc.be.components.impl.exceptions.ByActionStatusComponentException;
+import org.openecomp.sdc.be.components.utils.PropertiesUtils;
+import org.openecomp.sdc.be.config.BeEcompErrorManager;
+import org.openecomp.sdc.be.dao.api.ActionStatus;
+import org.openecomp.sdc.be.dao.jsongraph.JanusGraphDao;
+import org.openecomp.sdc.be.datatypes.elements.CapabilityDataDefinition;
+import org.openecomp.sdc.be.datatypes.elements.GetInputValueDataDefinition;
+import org.openecomp.sdc.be.datatypes.elements.PolicyTargetType;
+import org.openecomp.sdc.be.datatypes.elements.PropertyDataDefinition;
+import org.openecomp.sdc.be.model.CapabilityDefinition;
+import org.openecomp.sdc.be.model.ComponentInstanceProperty;
+import org.openecomp.sdc.be.model.DataTypeDefinition;
+import org.openecomp.sdc.be.model.GroupDefinition;
+import org.openecomp.sdc.be.model.GroupTypeDefinition;
+import org.openecomp.sdc.be.model.InputDefinition;
+import org.openecomp.sdc.be.model.NodeTypeInfo;
+import org.openecomp.sdc.be.model.ParsedToscaYamlInfo;
+import org.openecomp.sdc.be.model.PolicyDefinition;
+import org.openecomp.sdc.be.model.PolicyTypeDefinition;
+import org.openecomp.sdc.be.model.Resource;
+import org.openecomp.sdc.be.model.UploadArtifactInfo;
+import org.openecomp.sdc.be.model.UploadCapInfo;
+import org.openecomp.sdc.be.model.UploadComponentInstanceInfo;
+import org.openecomp.sdc.be.model.UploadPropInfo;
+import org.openecomp.sdc.be.model.UploadReqInfo;
+import org.openecomp.sdc.be.model.tosca.ToscaPropertyType;
+import org.openecomp.sdc.be.utils.TypeUtils;
+import org.openecomp.sdc.be.utils.TypeUtils.ToscaTagNamesEnum;
+import org.openecomp.sdc.common.log.wrappers.Logger;
+import org.springframework.stereotype.Component;
+import org.yaml.snakeyaml.parser.ParserException;
+
/**
* A handler class designed to parse the YAML file of the service template for a JAVA object
*/
@@ -115,14 +113,16 @@
private static final Logger log = Logger.getLogger(YamlTemplateParsingHandler.class);
- private Gson gson = new Gson();
- private JanusGraphDao janusGraphDao;
- private GroupTypeBusinessLogic groupTypeBusinessLogic;
- private AnnotationBusinessLogic annotationBusinessLogic;
- private PolicyTypeBusinessLogic policyTypeBusinessLogic;
+ private final Gson gson = new Gson();
+ private final JanusGraphDao janusGraphDao;
+ private final GroupTypeBusinessLogic groupTypeBusinessLogic;
+ private final AnnotationBusinessLogic annotationBusinessLogic;
+ private final PolicyTypeBusinessLogic policyTypeBusinessLogic;
- public YamlTemplateParsingHandler(JanusGraphDao janusGraphDao, GroupTypeBusinessLogic groupTypeBusinessLogic,
- AnnotationBusinessLogic annotationBusinessLogic, PolicyTypeBusinessLogic policyTypeBusinessLogic) {
+ public YamlTemplateParsingHandler(final JanusGraphDao janusGraphDao,
+ final GroupTypeBusinessLogic groupTypeBusinessLogic,
+ final AnnotationBusinessLogic annotationBusinessLogic,
+ final PolicyTypeBusinessLogic policyTypeBusinessLogic) {
this.janusGraphDao = janusGraphDao;
this.groupTypeBusinessLogic = groupTypeBusinessLogic;
this.annotationBusinessLogic = annotationBusinessLogic;
@@ -132,15 +132,16 @@
public ParsedToscaYamlInfo parseResourceInfoFromYAML(String fileName, String resourceYml, Map<String, String> createdNodesToscaResourceNames,
Map<String, NodeTypeInfo> nodeTypesInfo, String nodeName, org.openecomp.sdc.be.model.Component component) {
log.debug("#parseResourceInfoFromYAML - Going to parse yaml {} ", fileName);
- Map<String, Object> mappedToscaTemplate = getMappedToscaTemplate(fileName, resourceYml, nodeTypesInfo, nodeName);
- ParsedToscaYamlInfo parsedToscaYamlInfo = new ParsedToscaYamlInfo();
- findToscaElement(mappedToscaTemplate, TOPOLOGY_TEMPLATE, ToscaElementTypeEnum.ALL)
+ final Map<String, Object> mappedToscaTemplate = getMappedToscaTemplate(fileName, resourceYml, nodeTypesInfo, nodeName);
+ final ParsedToscaYamlInfo parsedToscaYamlInfo = new ParsedToscaYamlInfo();
+ ImportUtils.findToscaElement(mappedToscaTemplate, TOPOLOGY_TEMPLATE, ToscaElementTypeEnum.ALL)
.left()
.on(err -> failIfNotTopologyTemplate(fileName));
parsedToscaYamlInfo.setInputs(getInputs(mappedToscaTemplate));
parsedToscaYamlInfo.setInstances(getInstances(fileName, mappedToscaTemplate, createdNodesToscaResourceNames));
parsedToscaYamlInfo.setGroups(getGroups(fileName, mappedToscaTemplate));
+ parsedToscaYamlInfo.setDataTypes(getDataTypes(mappedToscaTemplate));
if(component instanceof Resource){
parsedToscaYamlInfo.setPolicies(getPolicies(fileName, mappedToscaTemplate));
}
@@ -161,7 +162,7 @@
private Map<String, Object> loadYaml(String fileName, String resourceYml) {
Map<String, Object> mappedToscaTemplate = null;
try {
- mappedToscaTemplate = loadYamlAsStrictMap(resourceYml);
+ mappedToscaTemplate = ImportUtils.loadYamlAsStrictMap(resourceYml);
} catch (ParserException e) {
log.debug("#getMappedToscaTemplate - Failed to load YAML file {}", fileName, e);
rollbackWithException(ActionStatus.TOSCA_PARSE_ERROR, fileName, e.getMessage());
@@ -181,18 +182,38 @@
return inputs;
}
+ private Map<String, DataTypeDefinition> getDataTypes(final Map<String, Object> toscaJson) {
+ try {
+ final Map<String, DataTypeDefinition> dataTypes = ImportUtils.getDataTypes(toscaJson);
+
+ if (log.isDebugEnabled()) {
+ if (MapUtils.isEmpty(dataTypes)) {
+ log.debug("No {} found.", ToscaTagNamesEnum.DATA_TYPES.getElementName());
+ } else {
+ log.debug("{} found: {}", ToscaTagNamesEnum.DATA_TYPES.getElementName(), dataTypes.keySet());
+ }
+ }
+
+ return dataTypes;
+ } catch (final Exception ex) {
+ log.error("Unable to process datatypes", ex);
+ }
+
+ return Collections.emptyMap();
+ }
+
private Map<String, PolicyDefinition> getPolicies(String fileName, Map<String, Object> toscaJson) {
Map<String, Object> foundPolicies = findFirstToscaMapElement(toscaJson, POLICIES)
- .left()
- .on(err -> logPoliciesNotFound(fileName));
+ .left()
+ .on(err -> logPoliciesNotFound(fileName));
if (MapUtils.isNotEmpty(foundPolicies)) {
return foundPolicies
- .entrySet()
- .stream()
- .map(this::createPolicy)
- .collect(Collectors.toMap(PolicyDefinition::getName, p -> p));
+ .entrySet()
+ .stream()
+ .map(this::createPolicy)
+ .collect(Collectors.toMap(PolicyDefinition::getName, p -> p));
}
return Collections.emptyMap();
}
@@ -244,23 +265,23 @@
}
private List<PropertyDataDefinition> validateFillPolicyProperties(PolicyTypeDefinition policyTypeDefinition,
- Map<String, Object> policyTemplateJsonMap) {
+ Map<String, Object> policyTemplateJsonMap) {
if (MapUtils.isEmpty(policyTemplateJsonMap) || Objects.isNull(policyTypeDefinition)) {
return Collections.emptyList();
}
List<PropertyDataDefinition> propertyDataDefinitionList = new ArrayList<>();
Map<String, Object> propertiesMap =
- (Map<String, Object>) policyTemplateJsonMap.get(PROPERTIES.getElementName());
+ (Map<String, Object>) policyTemplateJsonMap.get(PROPERTIES.getElementName());
if (MapUtils.isEmpty(propertiesMap)) {
return Collections.emptyList();
}
if (CollectionUtils.isNotEmpty(policyTypeDefinition.getProperties())) {
propertyDataDefinitionList = policyTypeDefinition
- .getProperties()
- .stream()
- .map(propertyDefinition -> setPropertyValue(propertiesMap,
- propertyDefinition))
- .collect(Collectors.toList());
+ .getProperties()
+ .stream()
+ .map(propertyDefinition -> setPropertyValue(propertiesMap,
+ propertyDefinition))
+ .collect(Collectors.toList());
}
return propertyDataDefinitionList;
}
@@ -278,16 +299,16 @@
private Map<PolicyTargetType, List<String>> validateFillPolicyTargets(Map<String, Object> policyTemplateJson) {
Map<PolicyTargetType, List<String>> targets = new EnumMap<>(PolicyTargetType.class);
if (policyTemplateJson.containsKey(TARGETS.getElementName())
- && policyTemplateJson.get(TARGETS.getElementName()) instanceof List ) {
+ && policyTemplateJson.get(TARGETS.getElementName()) instanceof List ) {
List<String> targetsElement = (List<String>) policyTemplateJson.get(TARGETS.getElementName());
targets.put(PolicyTargetType.COMPONENT_INSTANCES, targetsElement);
}
return targets;
}
- private Map<String, UploadComponentInstanceInfo> getInstances(String yamlName, Map<String, Object> toscaJson, Map<String, String> createdNodesToscaResourceNames) {
+ private Map<String, UploadComponentInstanceInfo> getInstances(final String yamlName, final Map<String, Object> toscaJson, final Map<String, String> createdNodesToscaResourceNames) {
- Map<String, Object> nodeTemlates = findFirstToscaMapElement(toscaJson, NODE_TEMPLATES)
+ final Map<String, Object> nodeTemlates = ImportUtils.findFirstToscaMapElement(toscaJson, NODE_TEMPLATES)
.left()
.on(err -> failIfNoNodeTemplates(yamlName));
@@ -306,7 +327,7 @@
private Map<String, Object> getSubstitutionMappings(Map<String, Object> toscaJson) {
Map<String, Object> substitutionMappings = null;
- Either<Map<String, Object>, ResultStatusEnum> eitherSubstitutionMappings = findFirstToscaMapElement(toscaJson, SUBSTITUTION_MAPPINGS);
+ Either<Map<String, Object>, ResultStatusEnum> eitherSubstitutionMappings = ImportUtils.findFirstToscaMapElement(toscaJson, SUBSTITUTION_MAPPINGS);
if (eitherSubstitutionMappings.isLeft()) {
substitutionMappings = eitherSubstitutionMappings.left().value();
}
@@ -316,7 +337,7 @@
@SuppressWarnings("unchecked")
private Map<String, GroupDefinition> getGroups(String fileName, Map<String, Object> toscaJson) {
- Map<String, Object> foundGroups = findFirstToscaMapElement(toscaJson, GROUPS)
+ Map<String, Object> foundGroups = ImportUtils.findFirstToscaMapElement(toscaJson, GROUPS)
.left()
.on(err -> logGroupsNotFound(fileName));
@@ -737,7 +758,7 @@
private Map<String, List<UploadReqInfo>> createReqModuleFromYaml(Map<String, Object> nodeTemplateJsonMap) {
Map<String, List<UploadReqInfo>> moduleRequirements = new HashMap<>();
Either<List<Object>, ResultStatusEnum> requirementsListRes =
- findFirstToscaListElement(nodeTemplateJsonMap, REQUIREMENTS);
+ ImportUtils.findFirstToscaListElement(nodeTemplateJsonMap, REQUIREMENTS);
if (requirementsListRes.isLeft()) {
for (Object jsonReqObj : requirementsListRes.left().value()) {
@@ -747,7 +768,7 @@
}
} else {
Either<Map<String, Object>, ResultStatusEnum> requirementsMapRes =
- findFirstToscaMapElement(nodeTemplateJsonMap, REQUIREMENTS);
+ ImportUtils.findFirstToscaMapElement(nodeTemplateJsonMap, REQUIREMENTS);
if (requirementsMapRes.isLeft()) {
for (Map.Entry<String, Object> entry : requirementsMapRes.left().value().entrySet()) {
String reqName = entry.getKey();
@@ -776,7 +797,7 @@
private Map<String, Map<String, UploadArtifactInfo>> createArtifactsModuleFromYaml(Map<String, Object> nodeTemplateJsonMap) {
Map<String, Map<String, UploadArtifactInfo>> moduleArtifacts = new HashMap<>();
Either<List<Object>, ResultStatusEnum> ArtifactsListRes =
- findFirstToscaListElement(nodeTemplateJsonMap, ARTIFACTS);
+ ImportUtils.findFirstToscaListElement(nodeTemplateJsonMap, ARTIFACTS);
if (ArtifactsListRes.isLeft()) {
for (Object jsonArtifactObj : ArtifactsListRes.left().value()) {
String key = ((Map<String, Object>) jsonArtifactObj).keySet().iterator().next();
@@ -785,7 +806,7 @@
}
} else {
Either<Map<String, Map<String, Object>>, ResultStatusEnum> ArtifactsMapRes =
- findFirstToscaMapElement(nodeTemplateJsonMap, ARTIFACTS);
+ ImportUtils.findFirstToscaMapElement(nodeTemplateJsonMap, ARTIFACTS);
if (ArtifactsMapRes.isLeft()) {
for (Map.Entry<String, Map<String, Object>> entry : ArtifactsMapRes.left().value().entrySet()) {
String artifactName = entry.getKey();
@@ -833,7 +854,7 @@
private Map<String, List<UploadCapInfo>> createCapModuleFromYaml(Map<String, Object> nodeTemplateJsonMap) {
Map<String, List<UploadCapInfo>> moduleCap = new HashMap<>();
Either<List<Object>, ResultStatusEnum> capabilitiesListRes =
- findFirstToscaListElement(nodeTemplateJsonMap, CAPABILITIES);
+ ImportUtils.findFirstToscaListElement(nodeTemplateJsonMap, CAPABILITIES);
if (capabilitiesListRes.isLeft()) {
for (Object jsonCapObj : capabilitiesListRes.left().value()) {
String key = ((Map<String, Object>) jsonCapObj).keySet().iterator().next();
@@ -842,7 +863,7 @@
}
} else {
Either<Map<String, Object>, ResultStatusEnum> capabilitiesMapRes =
- findFirstToscaMapElement(nodeTemplateJsonMap, CAPABILITIES);
+ ImportUtils.findFirstToscaMapElement(nodeTemplateJsonMap, CAPABILITIES);
if (capabilitiesMapRes.isLeft()) {
for (Map.Entry<String, Object> entry : capabilitiesMapRes.left().value().entrySet()) {
String capName = entry.getKey();
@@ -889,7 +910,7 @@
}
if (nodeTemplateJsonMap.containsKey(VALID_SOURCE_TYPES.getElementName())) {
Either<List<Object>, ResultStatusEnum> validSourceTypesRes =
- findFirstToscaListElement(nodeTemplateJsonMap, VALID_SOURCE_TYPES);
+ ImportUtils.findFirstToscaListElement(nodeTemplateJsonMap, VALID_SOURCE_TYPES);
if (validSourceTypesRes.isLeft()) {
capTemplateInfo.setValidSourceTypes(validSourceTypesRes.left().value().stream()
.map(Object::toString).collect(toList()));
@@ -928,7 +949,7 @@
Map<String, List<UploadPropInfo>> moduleProp = new HashMap<>();
Either<Map<String, Object>, ResultStatusEnum> toscaProperties =
- findFirstToscaMapElement(nodeTemplateJsonMap, PROPERTIES);
+ ImportUtils.findFirstToscaMapElement(nodeTemplateJsonMap, PROPERTIES);
if (toscaProperties.isLeft()) {
Map<String, Object> jsonProperties = toscaProperties.left().value();
for (Map.Entry<String, Object> jsonPropObj : jsonProperties.entrySet()) {
diff --git a/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/BaseBusinessLogic.java b/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/BaseBusinessLogic.java
index 646749d..4230358 100644
--- a/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/BaseBusinessLogic.java
+++ b/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/BaseBusinessLogic.java
@@ -465,7 +465,7 @@
Map<String, DataTypeDefinition> dataTypes) {
String type;
String innerType = null;
- if (!propertyOperation.isPropertyTypeValid(property)) {
+ if (!propertyOperation.isPropertyTypeValid(property, dataTypes.values())) {
log.info("Invalid type for property '{}' type '{}'", property.getName(), property.getType());
ResponseFormat responseFormat = componentsUtils
.getResponseFormat(ActionStatus.INVALID_PROPERTY_TYPE, property.getType(), property.getName());
diff --git a/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/DataTypeBusinessLogic.java b/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/DataTypeBusinessLogic.java
index 5af7cf6..40f3007 100644
--- a/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/DataTypeBusinessLogic.java
+++ b/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/DataTypeBusinessLogic.java
@@ -21,37 +21,38 @@
package org.openecomp.sdc.be.components.impl;
import fj.data.Either;
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+import java.util.Optional;
+import org.apache.commons.collections.MapUtils;
+import org.openecomp.sdc.be.components.impl.exceptions.DataTypeNotProvidedException;
import org.openecomp.sdc.be.model.Component;
import org.openecomp.sdc.be.model.ComponentParametersView;
import org.openecomp.sdc.be.model.DataTypeDefinition;
-import org.openecomp.sdc.be.model.jsonjanusgraph.operations.ArtifactsOperations;
-import org.openecomp.sdc.be.model.jsonjanusgraph.operations.InterfaceOperation;
-import org.openecomp.sdc.be.model.operations.api.IElementOperation;
-import org.openecomp.sdc.be.model.operations.api.IGroupInstanceOperation;
-import org.openecomp.sdc.be.model.operations.api.IGroupOperation;
-import org.openecomp.sdc.be.model.operations.api.IGroupTypeOperation;
+import org.openecomp.sdc.be.model.cache.ApplicationDataTypeCache;
+import org.openecomp.sdc.be.model.jsonjanusgraph.operations.ToscaOperationFacade;
+import org.openecomp.sdc.be.model.operations.StorageException;
import org.openecomp.sdc.be.model.operations.api.StorageOperationStatus;
-import org.openecomp.sdc.be.model.operations.impl.InterfaceLifecycleOperation;
+import org.openecomp.sdc.be.model.operations.impl.PropertyOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.util.CollectionUtils;
-import java.util.ArrayList;
-import java.util.List;
-import java.util.Optional;
-
@org.springframework.stereotype.Component("dataTypeBusinessLogic")
-public class DataTypeBusinessLogic extends BaseBusinessLogic {
+public class DataTypeBusinessLogic {
+
+ private final PropertyOperation propertyOperation;
+ private final ApplicationDataTypeCache applicationDataTypeCache;
+ private final ToscaOperationFacade toscaOperationFacade;
@Autowired
- public DataTypeBusinessLogic(IElementOperation elementDao,
- IGroupOperation groupOperation,
- IGroupInstanceOperation groupInstanceOperation,
- IGroupTypeOperation groupTypeOperation,
- InterfaceOperation interfaceOperation,
- InterfaceLifecycleOperation interfaceLifecycleTypeOperation,
- ArtifactsOperations artifactToscaOperation) {
- super(elementDao, groupOperation, groupInstanceOperation, groupTypeOperation,
- interfaceOperation, interfaceLifecycleTypeOperation, artifactToscaOperation);
+ public DataTypeBusinessLogic(final PropertyOperation propertyOperation,
+ final ApplicationDataTypeCache applicationDataTypeCache,
+ final ToscaOperationFacade toscaOperationFacade) {
+ this.propertyOperation = propertyOperation;
+ this.applicationDataTypeCache = applicationDataTypeCache;
+ this.toscaOperationFacade = toscaOperationFacade;
}
/**
@@ -155,4 +156,97 @@
// return deleted data type if ok
return Either.left(dataTypeResult.get());
}
+
+ /**
+ * Associates a TOSCA data_type to a component.
+ *
+ * @param componentId the component id
+ * @param dataTypeMap a map of data_type name and the data_type representation to associate to the component
+ * @return the list of associated data_type
+ */
+ public List<DataTypeDefinition> addToComponent(final String componentId,
+ final Map<String, DataTypeDefinition> dataTypeMap) {
+ final List<DataTypeDefinition> addedDataTypeList = new ArrayList<>();
+ final List<DataTypeDefinition> parsedDataTypeDefinitionList = parseToDataTypeDefinitionList(dataTypeMap);
+ for (final DataTypeDefinition dataTypeDefinition : parsedDataTypeDefinitionList) {
+ addedDataTypeList.add(addToComponent(componentId, dataTypeDefinition));
+ }
+
+ return addedDataTypeList;
+ }
+
+ /**
+ * Associates a data_type to a component. Creates the data_type if it does not exists.
+ *
+ * @param componentId the component id
+ * @param dataTypeDefinitionToAdd the data_type to add to the component
+ * @return the associated data_type
+ */
+ public DataTypeDefinition addToComponent(final String componentId, final DataTypeDefinition dataTypeDefinitionToAdd) {
+ DataTypeDefinition dataTypeDefinition = propertyOperation.findDataTypeByName(dataTypeDefinitionToAdd.getName())
+ .orElse(null);
+ if (dataTypeDefinition == null) {
+ dataTypeDefinition = dataTypeDefinitionToAdd;
+ }
+
+ final Map<String, DataTypeDefinition> dataTypesMap = new HashMap<>();
+ dataTypesMap.put(dataTypeDefinitionToAdd.getName(), dataTypeDefinition);
+
+ final Either<List<DataTypeDefinition>, StorageOperationStatus> operationResult =
+ toscaOperationFacade.addDataTypesToComponent(dataTypesMap, componentId);
+ if (operationResult.isRight()) {
+ final StorageOperationStatus storageOperationStatus = operationResult.right().value();
+ throw new StorageException(storageOperationStatus);
+ }
+
+ return dataTypeDefinition;
+ }
+
+ private List<DataTypeDefinition> parseToDataTypeDefinitionList(final Map<String, DataTypeDefinition> dataTypeMap) {
+ final List<DataTypeDefinition> dataTypeDefinitionList = new ArrayList<>();
+ dataTypeMap.forEach((key, dataTypeDefinition) -> {
+ dataTypeDefinition.setName(key);
+ dataTypeDefinitionList.add(dataTypeDefinition);
+ });
+
+ dataTypeDefinitionList.forEach(dataTypeDefinition -> loadParentHierarchy(dataTypeDefinition, dataTypeDefinitionList));
+
+ return dataTypeDefinitionList;
+ }
+
+ private void loadParentHierarchy(final DataTypeDefinition dataTypeDefinition,
+ final List<DataTypeDefinition> componentDataTypeList) {
+ if (dataTypeDefinition.getDerivedFrom() != null) {
+ return;
+ }
+ if (dataTypeDefinition.getDerivedFromName() == null) {
+ return;
+ }
+
+ DataTypeDefinition parentDataType =
+ propertyOperation.findDataTypeByName(dataTypeDefinition.getDerivedFromName()).orElse(null);
+ if (parentDataType != null) {
+ dataTypeDefinition.setDerivedFrom(parentDataType);
+ return;
+ }
+
+ parentDataType = componentDataTypeList.stream()
+ .filter(dataTypeDefinition1 -> dataTypeDefinition1.getName().equals(dataTypeDefinition.getDerivedFromName()))
+ .findFirst().orElse(null);
+ if (parentDataType == null) {
+ final String errorMsg =
+ String.format("Data type '%s' was not provided", dataTypeDefinition.getDerivedFromName());
+ throw new DataTypeNotProvidedException(errorMsg);
+ }
+ dataTypeDefinition.setDerivedFrom(parentDataType);
+ loadParentHierarchy(dataTypeDefinition.getDerivedFrom(), componentDataTypeList);
+ }
+
+ public void addToComponent(final Component component, final Map<String, DataTypeDefinition> dataTypes) {
+ if (MapUtils.isEmpty(dataTypes)) {
+ return;
+ }
+ parseToDataTypeDefinitionList(dataTypes).forEach(component::addToDataTypes);
+ }
+
}
diff --git a/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/ImportUtils.java b/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/ImportUtils.java
index f04eca1..bf98b1b 100644
--- a/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/ImportUtils.java
+++ b/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/ImportUtils.java
@@ -20,19 +20,33 @@
package org.openecomp.sdc.be.components.impl;
+import static org.apache.commons.collections.CollectionUtils.isEmpty;
+import static org.openecomp.sdc.be.components.impl.ResourceImportManager.PROPERTY_NAME_PATTERN_IGNORE_LENGTH;
+import static org.openecomp.sdc.be.datatypes.elements.Annotation.setAnnotationsName;
+
import com.google.gson.Gson;
import com.google.gson.GsonBuilder;
import com.google.gson.JsonParseException;
import com.google.gson.reflect.TypeToken;
import fj.data.Either;
+import java.lang.reflect.Type;
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.Iterator;
+import java.util.LinkedHashMap;
+import java.util.List;
+import java.util.Map;
+import java.util.Map.Entry;
+import java.util.function.Consumer;
+import java.util.function.Function;
import org.apache.commons.collections.CollectionUtils;
-import org.apache.commons.collections.MapUtils;
import org.apache.commons.lang3.StringEscapeUtils;
-import org.apache.tinkerpop.gremlin.structure.T;
import org.openecomp.sdc.be.components.impl.exceptions.ByActionStatusComponentException;
+import org.openecomp.sdc.be.components.impl.exceptions.ToscaElementException;
import org.openecomp.sdc.be.config.BeEcompErrorManager;
import org.openecomp.sdc.be.dao.api.ActionStatus;
-import org.openecomp.sdc.be.dao.janusgraph.JanusGraphOperationStatus;
import org.openecomp.sdc.be.datatypes.elements.Annotation;
import org.openecomp.sdc.be.datatypes.elements.AttributeDataDefinition;
import org.openecomp.sdc.be.datatypes.elements.PropertyDataDefinition;
@@ -70,25 +84,6 @@
import org.yaml.snakeyaml.representer.Representer;
import org.yaml.snakeyaml.resolver.Resolver;
-import java.lang.reflect.Type;
-import java.util.ArrayList;
-import java.util.Collection;
-import java.util.Collections;
-import java.util.HashMap;
-import java.util.Iterator;
-import java.util.LinkedHashMap;
-import java.util.List;
-import java.util.Map;
-import java.util.Map.Entry;
-import java.util.function.Consumer;
-import java.util.function.Function;
-
-import static org.apache.commons.collections.CollectionUtils.isEmpty;
-import static org.openecomp.sdc.be.components.impl.ResourceImportManager.PROPERTY_NAME_PATTERN_IGNORE_LENGTH;
-import static org.openecomp.sdc.be.datatypes.elements.Annotation.setAnnotationsName;
-import static org.openecomp.sdc.be.model.jsonjanusgraph.operations.ToscaElementOperation.createDataType;
-import static org.openecomp.sdc.be.model.jsonjanusgraph.operations.ToscaElementOperation.createDataTypeDefinitionWithName;
-
@Component
public final class ImportUtils {
@@ -616,6 +611,21 @@
}
+ public static Map<String, DataTypeDefinition> getDataTypes(final Map<String, Object> toscaJson)
+ throws ToscaElementException {
+ final Function<String, DataTypeDefinition> elementGenByName = ImportUtils::createDataType;
+ final Function<Map<String, Object>, DataTypeDefinition> func = ImportUtils::createDataTypeDefinitionAttribute;
+ final Either<Map<String, DataTypeDefinition>, ResultStatusEnum> elements =
+ getElements(toscaJson, ToscaTagNamesEnum.DATA_TYPES, elementGenByName, func);
+
+ if (elements.isRight()) {
+ throw new ToscaElementException(elements.right().value(),
+ String.format("Could not retrieve %s", ToscaTagNamesEnum.DATA_TYPES.getElementName()));
+ }
+
+ return elements.left().value();
+ }
+
public static Either<Map<String, AttributeDataDefinition>, ResultStatusEnum> getAttributes(
Map<String, Object> toscaJson) {
Function<String, AttributeDataDefinition> elementGenByName = ImportUtils::createAttribute;
@@ -684,6 +694,22 @@
return annotation;
}
+ private static DataTypeDefinition createDataTypeDefinitionAttribute(final Map<String, Object> attributeMap) {
+ final DataTypeDefinition dataType = new DataTypeDefinition();
+ setField(attributeMap, TypeUtils.ToscaTagNamesEnum.DESCRIPTION, dataType::setDescription);
+ setField(attributeMap, TypeUtils.ToscaTagNamesEnum.DERIVED_FROM, dataType::setDerivedFromName);
+ CommonImportManager.setProperties(attributeMap, dataType::setProperties);
+ return dataType;
+
+ }
+
+ private static DataTypeDefinition createDataType(final String dataTypeName) {
+ final DataTypeDefinition dataType = new DataTypeDefinition();
+ dataType.setName(dataTypeName);
+ return dataType;
+ }
+
+
public static Either<List<HeatParameterDefinition>, ResultStatusEnum> getHeatParameters(Map<String, Object> heatData, String artifactType) {
Either<List<HeatParameterDefinition>, ResultStatusEnum> eitherResult = Either
diff --git a/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/InputsBusinessLogic.java b/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/InputsBusinessLogic.java
index d6459f4..e5ad9af 100644
--- a/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/InputsBusinessLogic.java
+++ b/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/InputsBusinessLogic.java
@@ -23,6 +23,16 @@
package org.openecomp.sdc.be.components.impl;
import fj.data.Either;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+import java.util.Objects;
+import java.util.Optional;
+import java.util.stream.Collectors;
+import org.apache.commons.collections.CollectionUtils;
import org.apache.commons.collections4.ListUtils;
import org.apache.commons.collections4.MapUtils;
import org.apache.commons.lang.BooleanUtils;
@@ -71,16 +81,6 @@
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
-import java.util.ArrayList;
-import java.util.Arrays;
-import java.util.Collections;
-import java.util.HashMap;
-import java.util.List;
-import java.util.Map;
-import java.util.Objects;
-import java.util.Optional;
-import java.util.stream.Collectors;
-
@Component("inputsBusinessLogic")
public class InputsBusinessLogic extends BaseBusinessLogic {
@@ -621,13 +621,16 @@
List<InputDefinition> resourceProperties = component.getInputs();
- Map<String, DataTypeDefinition> dataTypes = getAllDataTypes(applicationDataTypeCache);
+ final Map<String, DataTypeDefinition> dataTypeMap = getAllDataTypes(applicationDataTypeCache);
+ if (CollectionUtils.isNotEmpty(component.getDataTypes())) {
+ component.getDataTypes().forEach(dataTypeDefinition -> dataTypeMap.put(dataTypeDefinition.getName(), dataTypeDefinition));
+ }
for (Map.Entry<String, InputDefinition> inputDefinition : inputs.entrySet()) {
String inputName = inputDefinition.getKey();
inputDefinition.getValue().setName(inputName);
- Either<InputDefinition, ResponseFormat> preparedInputEither = prepareAndValidateInputBeforeCreate(inputDefinition.getValue(), dataTypes);
+ Either<InputDefinition, ResponseFormat> preparedInputEither = prepareAndValidateInputBeforeCreate(inputDefinition.getValue(), dataTypeMap);
if(preparedInputEither.isRight()){
return Either.right(preparedInputEither.right().value());
}
diff --git a/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/ResourceBusinessLogic.java b/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/ResourceBusinessLogic.java
index 50b2941..357157d 100644
--- a/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/ResourceBusinessLogic.java
+++ b/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/ResourceBusinessLogic.java
@@ -96,6 +96,7 @@
import org.openecomp.sdc.be.datatypes.elements.ArtifactDataDefinition;
import org.openecomp.sdc.be.datatypes.elements.AttributeDataDefinition;
import org.openecomp.sdc.be.datatypes.elements.CapabilityDataDefinition;
+import org.openecomp.sdc.be.datatypes.elements.DataTypeDataDefinition;
import org.openecomp.sdc.be.datatypes.elements.GetInputValueDataDefinition;
import org.openecomp.sdc.be.datatypes.elements.GroupDataDefinition;
import org.openecomp.sdc.be.datatypes.elements.PropertyDataDefinition;
@@ -217,11 +218,12 @@
private final InputsBusinessLogic inputsBusinessLogic;
private final CompositionBusinessLogic compositionBusinessLogic;
private final ResourceDataMergeBusinessLogic resourceDataMergeBusinessLogic;
- private final CsarArtifactsAndGroupsBusinessLogic csarArtifactsAndGroupsBusinessLogic;
- private final MergeInstanceUtils mergeInstanceUtils;
- private final UiComponentDataConverter uiComponentDataConverter;
- private final CsarBusinessLogic csarBusinessLogic;
- private final PropertyBusinessLogic propertyBusinessLogic;
+ private final CsarArtifactsAndGroupsBusinessLogic csarArtifactsAndGroupsBusinessLogic;
+ private final MergeInstanceUtils mergeInstanceUtils;
+ private final UiComponentDataConverter uiComponentDataConverter;
+ private final CsarBusinessLogic csarBusinessLogic;
+ private final PropertyBusinessLogic propertyBusinessLogic;
+ private final DataTypeBusinessLogic dataTypeBusinessLogic;
private final PolicyBusinessLogic policyBusinessLogic;
@Autowired
@@ -244,7 +246,8 @@
ComponentValidator componentValidator,
ComponentIconValidator componentIconValidator,
ComponentProjectCodeValidator componentProjectCodeValidator,
- ComponentDescriptionValidator componentDescriptionValidator, PolicyBusinessLogic policyBusinessLogic) {
+ ComponentDescriptionValidator componentDescriptionValidator, DataTypeBusinessLogic dataTypeBusinessLogic,
+ PolicyBusinessLogic policyBusinessLogic) {
super(elementDao, groupOperation, groupInstanceOperation, groupTypeOperation, groupBusinessLogic,
interfaceOperation, interfaceLifecycleTypeOperation, artifactsBusinessLogic, artifactToscaOperation,
componentContactIdValidator, componentNameValidator, componentTagsValidator, componentValidator,
@@ -259,6 +262,7 @@
this.uiComponentDataConverter = uiComponentDataConverter;
this.csarBusinessLogic = csarBusinessLogic;
this.propertyBusinessLogic = propertyBusinessLogic;
+ this.dataTypeBusinessLogic = dataTypeBusinessLogic;
this.policyBusinessLogic = policyBusinessLogic;
}
@@ -1621,21 +1625,22 @@
final List<ArtifactDefinition> nodeTypesNewCreatedArtifacts = new ArrayList<>();
- if (shouldLock) {
- final Either<Boolean, ResponseFormat> lockResult = lockComponentByName(resource.getSystemName(), resource,
+ if (shouldLock) {
+ final Either<Boolean, ResponseFormat> lockResult = lockComponentByName(resource.getSystemName(), resource,
CREATE_RESOURCE);
- if (lockResult.isRight()) {
- rollback(inTransaction, resource, createdArtifacts, nodeTypesNewCreatedArtifacts);
- throw new ByResponseFormatComponentException(lockResult.right().value());
- }
- log.debug("name is locked {} status = {}", resource.getSystemName(), lockResult);
- }
- try {
- log.trace("************* createResourceFromYaml before full create resource {}", yamlName);
- loggerSupportability.log(LoggerSupportabilityActions.CREATE_INPUTS,resource.getComponentMetadataForSupportLog(), StatusCode.STARTED,"Starting to add inputs from yaml: {}",yamlName);
- final Resource genericResource = fetchAndSetDerivedFromGenericType(resource);
- resource = createResourceTransaction(resource, csarInfo.getModifier(), isNormative);
- log.trace("************* createResourceFromYaml after full create resource {}", yamlName);
+ if (lockResult.isRight()) {
+ rollback(inTransaction, resource, createdArtifacts, nodeTypesNewCreatedArtifacts);
+ throw new ByResponseFormatComponentException(lockResult.right().value());
+ }
+ log.debug("name is locked {} status = {}", resource.getSystemName(), lockResult);
+ }
+ try {
+ log.trace("************* createResourceFromYaml before full create resource {}", yamlName);
+ loggerSupportability.log(LoggerSupportabilityActions.CREATE_INPUTS,resource.getComponentMetadataForSupportLog(), StatusCode.STARTED,"Starting to add inputs from yaml: {}",yamlName);
+ final Resource genericResource = fetchAndSetDerivedFromGenericType(resource);
+ dataTypeBusinessLogic.addToComponent(resource, parsedToscaYamlInfo.getDataTypes());
+ resource = createResourceTransaction(resource, csarInfo.getModifier(), isNormative);
+ log.trace("************* createResourceFromYaml after full create resource {}", yamlName);
log.trace("************* Going to add inputs from yaml {}", yamlName);
if (resource.shouldGenerateInputs())
generateAndAddInputsFromGenericTypeProperties(resource, genericResource);
@@ -1748,7 +1753,11 @@
log.error("An error has occurred during resource and resource instance creation", e);
rollback(inTransaction, resource, createdArtifacts, nodeTypesNewCreatedArtifacts);
throw new ByResponseFormatComponentException(e.getResponseFormat());
- } finally {
+ } catch (final Exception e) {
+ log.error("An unexpected error has occurred during resource and resource instance creation", e);
+ rollback(inTransaction, resource, createdArtifacts, nodeTypesNewCreatedArtifacts);
+ throw new ByActionStatusComponentException(ActionStatus.GENERAL_ERROR);
+ } finally {
if (!inTransaction) {
janusGraphDao.commit();
}
@@ -2613,7 +2622,7 @@
return result;
}
- private Resource createResourceInstancesRelations(User user, String yamlName, Resource resource, Resource oldResource,
+ private Resource createResourceInstancesRelations(User user, String yamlName, final Resource resource, Resource oldResource,
Map<String, UploadComponentInstanceInfo> uploadResInstancesMap, Map<String, Resource> existingNodeTypesByResourceNames) {
log.debug("#createResourceInstancesRelations - Going to create relations ");
loggerSupportability.log(LoggerSupportabilityActions.CREATE_RELATIONS,resource.getComponentMetadataForSupportLog(), StatusCode.STARTED,"Start to create relations");
@@ -2639,22 +2648,9 @@
Map<String, List<ComponentInstanceInput>> instInputs = new HashMap<>();
log.debug("#createResourceInstancesRelations - Before get all datatypes. ");
- Either<Map<String, DataTypeDefinition>, JanusGraphOperationStatus> allDataTypes = dataTypeCache.getAll();
- if (allDataTypes.isRight()) {
- JanusGraphOperationStatus status = allDataTypes.right()
- .value();
- BeEcompErrorManager.getInstance()
- .logInternalFlowError("UpdatePropertyValueOnComponentInstance",
- "Failed to update property value on instance. Status is " + status, ErrorSeverity.ERROR);
- loggerSupportability.log(LoggerSupportabilityActions.CREATE_RELATIONS,resource.getComponentMetadataForSupportLog(),
- StatusCode.ERROR,"ERROR while update property value on instance. Status is: "+status);
- throw new ByActionStatusComponentException(componentsUtils.convertFromStorageResponse(
- DaoStatusConverter.convertJanusGraphStatusToStorageStatus(status)), yamlName);
-
- }
- Resource finalResource = resource;
+ final Map<String, DataTypeDefinition> allDataTypes = loadComponentDataTypes(resource);
uploadResInstancesMap.values()
- .forEach(i -> processComponentInstance(yamlName, finalResource, componentInstancesList, allDataTypes,
+ .forEach(i -> processComponentInstance(yamlName, resource, componentInstancesList, allDataTypes,
instProperties, instCapabilities, instRequirements, instDeploymentArtifacts, instArtifacts,
instAttributes, existingNodeTypesByResourceNames, instInputs, i));
resource.getComponentInstances()
@@ -2687,6 +2683,34 @@
.value();
}
+ private Map<String, DataTypeDefinition> loadComponentDataTypes(final Resource resource) {
+ final Either<Map<String, DataTypeDefinition>, JanusGraphOperationStatus> cachedDataTypeEither = dataTypeCache.getAll();
+ cachedDataTypeEither.right().map(errorStatus -> {
+ BeEcompErrorManager.getInstance()
+ .logInternalFlowError("UpdatePropertyValueOnComponentInstance",
+ "Failed to update property value on instance. Status is " + errorStatus, ErrorSeverity.ERROR);
+ loggerSupportability.log(LoggerSupportabilityActions.CREATE_RELATIONS, resource.getComponentMetadataForSupportLog(),
+ StatusCode.ERROR,"ERROR while update property value on instance. Status is: "+errorStatus);
+ throw new ByActionStatusComponentException(componentsUtils.convertFromStorageResponse(
+ DaoStatusConverter.convertJanusGraphStatusToStorageStatus(errorStatus)), "");
+ });
+ Map<String, DataTypeDefinition> dataTypeMap = cachedDataTypeEither.left().value();
+ if (dataTypeMap == null) {
+ dataTypeMap = new HashMap<>();
+ }
+
+ final List<DataTypeDefinition> resourceDataTypeList = resource.getDataTypes();
+ if (CollectionUtils.isEmpty(resourceDataTypeList)) {
+ return dataTypeMap;
+ }
+
+ final Map<String, DataTypeDefinition> resourceDataTypeMap = resourceDataTypeList.stream()
+ .collect(toMap(DataTypeDataDefinition::getName, dataTypeDefinition -> dataTypeDefinition));
+ dataTypeMap.putAll(resourceDataTypeMap);
+
+ return dataTypeMap;
+ }
+
private void processUiComponentInstance(Resource oldResource, ComponentInstance instance,
Map<ComponentInstance, Map<String, List<CapabilityDefinition>>> instCapabilities,
Map<ComponentInstance, Map<String, List<RequirementDefinition>>> instRequirements,
@@ -2900,7 +2924,7 @@
private void processComponentInstance(String yamlName, Resource resource,
List<ComponentInstance> componentInstancesList,
- Either<Map<String, DataTypeDefinition>, JanusGraphOperationStatus> allDataTypes,
+ final Map<String, DataTypeDefinition> allDataTypeMap,
Map<String, List<ComponentInstanceProperty>> instProperties,
Map<ComponentInstance, Map<String, List<CapabilityDefinition>>> instCapabilties,
Map<ComponentInstance, Map<String, List<RequirementDefinition>>> instRequirements,
@@ -2930,7 +2954,7 @@
instRequirements.put(currentCompInstance, originResource.getRequirements());
}
if (isNotEmpty(originResource.getCapabilities())) {
- processComponentInstanceCapabilities(allDataTypes, instCapabilties, uploadComponentInstanceInfo,
+ processComponentInstanceCapabilities(allDataTypeMap, instCapabilties, uploadComponentInstanceInfo,
currentCompInstance, originResource);
}
if (originResource.getDeploymentArtifacts() != null && !originResource.getDeploymentArtifacts()
@@ -2945,15 +2969,13 @@
}
if (originResource.getResourceType() != ResourceTypeEnum.CVFC) {
ResponseFormat addPropertiesValueToRiRes = addPropertyValuesToRi(uploadComponentInstanceInfo, resource,
- originResource, currentCompInstance, instProperties, allDataTypes.left()
- .value());
+ originResource, currentCompInstance, instProperties, allDataTypeMap);
if (addPropertiesValueToRiRes.getStatus() != 200) {
throw new ByResponseFormatComponentException(addPropertiesValueToRiRes);
}
} else {
addInputsValuesToRi(uploadComponentInstanceInfo, resource, originResource, currentCompInstance, instInputs,
- allDataTypes.left()
- .value());
+ allDataTypeMap);
}
}
@@ -2979,7 +3001,7 @@
}
private void processComponentInstanceCapabilities(
- Either<Map<String, DataTypeDefinition>, JanusGraphOperationStatus> allDataTypes,
+ final Map<String, DataTypeDefinition> allDataTypes,
Map<ComponentInstance, Map<String, List<CapabilityDefinition>>> instCapabilties,
UploadComponentInstanceInfo uploadComponentInstanceInfo, ComponentInstance currentCompInstance,
Resource originResource) {
@@ -3000,16 +3022,14 @@
}
private void updateCapabilityPropertiesValues(
- Either<Map<String, DataTypeDefinition>, JanusGraphOperationStatus> allDataTypes,
+ final Map<String, DataTypeDefinition> allDataTypes,
Map<String, List<CapabilityDefinition>> originCapabilities,
Map<String, Map<String, UploadPropInfo>> newPropertiesMap) {
originCapabilities.values()
.stream()
.flatMap(Collection::stream)
.filter(c -> newPropertiesMap.containsKey(c.getName()))
- .forEach(c -> updatePropertyValues(c.getProperties(), newPropertiesMap.get(c.getName()),
- allDataTypes.left()
- .value()));
+ .forEach(c -> updatePropertyValues(c.getProperties(), newPropertiesMap.get(c.getName()), allDataTypes));
}
private void addCapabilitiesProperties(Map<String, Map<String, UploadPropInfo>> newPropertiesMap,
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 4e6628c..895a77d 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
@@ -23,15 +23,25 @@
package org.openecomp.sdc.be.components.impl;
import static org.openecomp.sdc.be.components.impl.ImportUtils.Constants.QUOTE;
-import static org.openecomp.sdc.be.model.jsonjanusgraph.operations.ToscaElementOperation.createDataType;
-import static org.openecomp.sdc.be.model.jsonjanusgraph.operations.ToscaElementOperation.createDataTypeDefinitionWithName;
import static org.openecomp.sdc.be.utils.TypeUtils.setField;
import fj.data.Either;
+import java.util.ArrayList;
+import java.util.Arrays;
import java.util.Collections;
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.Iterator;
import java.util.LinkedHashMap;
+import java.util.List;
+import java.util.Map;
+import java.util.Map.Entry;
+import java.util.Set;
+import java.util.function.Function;
+import java.util.regex.Pattern;
+import java.util.stream.Collectors;
+import javax.servlet.ServletContext;
import org.apache.commons.codec.binary.Base64;
-import org.apache.commons.collections4.CollectionUtils;
import org.apache.commons.collections4.MapUtils;
import org.apache.commons.lang3.StringUtils;
import org.apache.commons.lang3.tuple.ImmutablePair;
@@ -64,7 +74,6 @@
import org.openecomp.sdc.be.model.ArtifactDefinition;
import org.openecomp.sdc.be.model.AttributeDefinition;
import org.openecomp.sdc.be.model.CapabilityDefinition;
-import org.openecomp.sdc.be.model.ComponentInstanceAttribute;
import org.openecomp.sdc.be.model.ComponentInstanceProperty;
import org.openecomp.sdc.be.model.DataTypeDefinition;
import org.openecomp.sdc.be.model.InterfaceDefinition;
@@ -76,6 +85,7 @@
import org.openecomp.sdc.be.model.User;
import org.openecomp.sdc.be.model.category.CategoryDefinition;
import org.openecomp.sdc.be.model.category.SubCategoryDefinition;
+import org.openecomp.sdc.be.model.jsonjanusgraph.operations.NodeTypeOperation;
import org.openecomp.sdc.be.model.jsonjanusgraph.operations.ToscaOperationFacade;
import org.openecomp.sdc.be.model.operations.api.IGraphLockOperation;
import org.openecomp.sdc.be.model.operations.api.StorageOperationStatus;
@@ -96,20 +106,6 @@
import org.springframework.web.context.WebApplicationContext;
import org.yaml.snakeyaml.Yaml;
-import javax.servlet.ServletContext;
-import java.util.ArrayList;
-import java.util.Arrays;
-import java.util.HashMap;
-import java.util.HashSet;
-import java.util.Iterator;
-import java.util.List;
-import java.util.Map;
-import java.util.Map.Entry;
-import java.util.Set;
-import java.util.function.Function;
-import java.util.regex.Pattern;
-import java.util.stream.Collectors;
-
@Component("resourceImportManager")
public class ResourceImportManager {
@@ -128,6 +124,8 @@
private AuditingManager auditingManager;
private ResourceBusinessLogic resourceBusinessLogic;
+ private final NodeTypeOperation nodeTypeOperation;
+
public ServiceBusinessLogic getServiceBusinessLogic() {
return serviceBusinessLogic;
}
@@ -149,9 +147,12 @@
private ResponseFormatManager responseFormatManager;
@Autowired
- public ResourceImportManager(ComponentsUtils componentsUtils, CapabilityTypeOperation capabilityTypeOperation) {
+ public ResourceImportManager(ComponentsUtils componentsUtils,
+ CapabilityTypeOperation capabilityTypeOperation,
+ NodeTypeOperation nodeTypeOperation) {
this.componentsUtils = componentsUtils;
this.capabilityTypeOperation = capabilityTypeOperation;
+ this.nodeTypeOperation = nodeTypeOperation;
}
@Autowired
@@ -1225,14 +1226,14 @@
final Object value = attributeNameValue.getValue();
if (value instanceof Map) {
final DataTypeDefinition dataTypeDefinition =
- createDataTypeDefinitionWithName(attributeNameValue);
+ nodeTypeOperation.createDataTypeDefinitionFromJson(attributeNameValue);
final DataTypeDefinition dataTypeDefinitionParent =
dataTypeCacheAll.left().value().get(dataTypeDefinition.getDerivedFromName());
dataTypeDefinition.setDerivedFrom(dataTypeDefinitionParent);
dataTypeDefinitionList.add(dataTypeDefinition);
} else {
- dataTypeDefinitionList.add(createDataType(String.valueOf(value)));
+ dataTypeDefinitionList.add(nodeTypeOperation.createDataType(String.valueOf(value)));
}
}
}
diff --git a/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/exceptions/DataTypeNotProvidedException.java b/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/exceptions/DataTypeNotProvidedException.java
new file mode 100644
index 0000000..8b995c3
--- /dev/null
+++ b/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/exceptions/DataTypeNotProvidedException.java
@@ -0,0 +1,27 @@
+/*
+ * ============LICENSE_START=======================================================
+ * Copyright (C) 2020 Nordix Foundation
+ * ================================================================================
+ * 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.
+ *
+ * SPDX-License-Identifier: Apache-2.0
+ * ============LICENSE_END=========================================================
+ */
+
+package org.openecomp.sdc.be.components.impl.exceptions;
+
+public class DataTypeNotProvidedException extends RuntimeException {
+
+ public DataTypeNotProvidedException(final String s) {
+ super(s);
+ }
+}
diff --git a/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/exceptions/ToscaElementException.java b/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/exceptions/ToscaElementException.java
new file mode 100644
index 0000000..b0ce043
--- /dev/null
+++ b/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/exceptions/ToscaElementException.java
@@ -0,0 +1,35 @@
+/*
+ * ============LICENSE_START=======================================================
+ * Copyright (C) 2020 Nordix Foundation
+ * ================================================================================
+ * 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.
+ *
+ * SPDX-License-Identifier: Apache-2.0
+ * ============LICENSE_END=========================================================
+ */
+
+package org.openecomp.sdc.be.components.impl.exceptions;
+
+import lombok.Getter;
+import org.openecomp.sdc.be.components.impl.ImportUtils.ResultStatusEnum;
+
+@Getter
+public class ToscaElementException extends Exception {
+
+ private final ResultStatusEnum resultStatus;
+
+ public ToscaElementException(ResultStatusEnum resultStatus, String msg) {
+ super(msg);
+ this.resultStatus = resultStatus;
+ }
+
+}
diff --git a/catalog-be/src/main/java/org/openecomp/sdc/be/tosca/PropertyConvertor.java b/catalog-be/src/main/java/org/openecomp/sdc/be/tosca/PropertyConvertor.java
index 64d7a76..ee256f9 100644
--- a/catalog-be/src/main/java/org/openecomp/sdc/be/tosca/PropertyConvertor.java
+++ b/catalog-be/src/main/java/org/openecomp/sdc/be/tosca/PropertyConvertor.java
@@ -113,6 +113,7 @@
if (propertyType.equals(PropertyType.CAPABILITY)) {
prop.setStatus(property.getStatus());
}
+
return prop;
}
diff --git a/catalog-be/src/test/java/org/openecomp/sdc/be/components/csar/CsarBusinessLogicTest.java b/catalog-be/src/test/java/org/openecomp/sdc/be/components/csar/CsarBusinessLogicTest.java
index 91ec895..3721988 100644
--- a/catalog-be/src/test/java/org/openecomp/sdc/be/components/csar/CsarBusinessLogicTest.java
+++ b/catalog-be/src/test/java/org/openecomp/sdc/be/components/csar/CsarBusinessLogicTest.java
@@ -30,7 +30,22 @@
package org.openecomp.sdc.be.components.csar;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertTrue;
+import static org.mockito.ArgumentMatchers.any;
+import static org.mockito.ArgumentMatchers.anyString;
+import static org.mockito.Mockito.when;
+
import fj.data.Either;
+import java.io.IOException;
+import java.net.URISyntaxException;
+import java.nio.file.Files;
+import java.nio.file.Path;
+import java.nio.file.Paths;
+import java.util.Arrays;
+import java.util.HashMap;
+import java.util.Map;
import org.junit.Before;
import org.junit.Test;
import org.mockito.Mockito;
@@ -48,22 +63,6 @@
import org.openecomp.sdc.common.zip.exception.ZipException;
import org.openecomp.sdc.exception.ResponseFormat;
-import java.io.IOException;
-import java.net.URISyntaxException;
-import java.nio.file.Files;
-import java.nio.file.Path;
-import java.nio.file.Paths;
-import java.util.Arrays;
-import java.util.HashMap;
-import java.util.Map;
-
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertNotNull;
-import static org.junit.Assert.assertTrue;
-import static org.mockito.ArgumentMatchers.any;
-import static org.mockito.ArgumentMatchers.anyString;
-import static org.mockito.Mockito.when;
-
public class CsarBusinessLogicTest extends BaseBusinessLogicMock {
@@ -73,8 +72,9 @@
private User user = Mockito.mock(User.class);
private YamlTemplateParsingHandler yamlHandler = Mockito.mock(YamlTemplateParsingHandler.class);
- private CsarBusinessLogic test = new CsarBusinessLogic(elementDao, groupOperation, groupInstanceOperation, groupTypeOperation,
- groupBusinessLogic, interfaceOperation, interfaceLifecycleTypeOperation, yamlHandler, artifactToscaOperation);
+ private CsarBusinessLogic csarBusinessLogic = new CsarBusinessLogic(elementDao, groupOperation,
+ groupInstanceOperation, groupTypeOperation, interfaceOperation, interfaceLifecycleTypeOperation, yamlHandler,
+ artifactToscaOperation);
private static final String CSAR_UUID = "csarUUID";
private static final String CSAR_ENTRY = "Definitions/tosca_mock_vf.yaml";
@@ -90,9 +90,9 @@
@Before
public void setUp() throws Exception {
- test.setCsarOperation(csarOperation);
- test.setToscaOperationFacade(toscaOperationFacade);
- test.setComponentsUtils(componentsUtils);
+ csarBusinessLogic.setCsarOperation(csarOperation);
+ csarBusinessLogic.setToscaOperationFacade(toscaOperationFacade);
+ csarBusinessLogic.setComponentsUtils(componentsUtils);
}
@Test()
@@ -107,7 +107,7 @@
when(csarOperation.getCsar(anyString(), any(User.class))).thenReturn(Either.left(csar_data));
// when
- CsarInfo csarInfo = test.getCsarInfo(resource, null, user, null, CSAR_UUID);
+ CsarInfo csarInfo = csarBusinessLogic.getCsarInfo(resource, null, user, null, CSAR_UUID);
// then
assertNotNull(csarInfo);
@@ -129,7 +129,7 @@
Map<String, byte[]> payload = loadPayload(PAYLOAD_NAME);
// when
- CsarInfo csarInfo = test.getCsarInfo(resource, null, user, payload, CSAR_UUID);
+ CsarInfo csarInfo = csarBusinessLogic.getCsarInfo(resource, null, user, payload, CSAR_UUID);
// then
assertNotNull(csarInfo);
@@ -152,7 +152,7 @@
when(csarOperation.getCsar(anyString(), any(User.class))).thenReturn(Either.left(csar_data));
// when
- test.getCsarInfo(resource, null, user, null, CSAR_UUID);
+ csarBusinessLogic.getCsarInfo(resource, null, user, null, CSAR_UUID);
}
@Test
@@ -160,7 +160,7 @@
Resource resource = new Resource();
StorageOperationStatus status = StorageOperationStatus.OK;
when(toscaOperationFacade.validateCsarUuidUniqueness(CSAR_UUID)).thenReturn(status);
- test.validateCsarBeforeCreate(resource, AuditingActionEnum.ARTIFACT_DOWNLOAD, user, CSAR_UUID);
+ csarBusinessLogic.validateCsarBeforeCreate(resource, AuditingActionEnum.ARTIFACT_DOWNLOAD, user, CSAR_UUID);
}
@Test(expected = ComponentException.class)
@@ -170,7 +170,7 @@
StorageOperationStatus status = StorageOperationStatus.ENTITY_ALREADY_EXISTS;
when(toscaOperationFacade.validateCsarUuidUniqueness(CSAR_UUID)).thenReturn(status);
when(componentsUtils.getResponseFormat(ActionStatus.VSP_ALREADY_EXISTS, CSAR_UUID)).thenReturn(responseFormat);
- test.validateCsarBeforeCreate(resource, AuditingActionEnum.ARTIFACT_DOWNLOAD, user, "csarUUID");
+ csarBusinessLogic.validateCsarBeforeCreate(resource, AuditingActionEnum.ARTIFACT_DOWNLOAD, user, "csarUUID");
}
@Test(expected = ComponentException.class)
@@ -179,7 +179,7 @@
String csarUUID = "csarUUID";
when(toscaOperationFacade.validateCsarUuidUniqueness(csarUUID)).thenReturn(StorageOperationStatus.EXEUCTION_FAILED);
when(componentsUtils.convertFromStorageResponse(StorageOperationStatus.EXEUCTION_FAILED)).thenReturn(ActionStatus.GENERAL_ERROR);
- test.validateCsarBeforeCreate(resource, AuditingActionEnum.ARTIFACT_DOWNLOAD, user, "csarUUID");
+ csarBusinessLogic.validateCsarBeforeCreate(resource, AuditingActionEnum.ARTIFACT_DOWNLOAD, user, "csarUUID");
}
public Map<String, byte[]> loadPayload(String payloadName) throws IOException, URISyntaxException, ZipException {
diff --git a/catalog-be/src/test/java/org/openecomp/sdc/be/components/impl/AttributeBusinessLogicTest.java b/catalog-be/src/test/java/org/openecomp/sdc/be/components/impl/AttributeBusinessLogicTest.java
index db4c699..a507721 100644
--- a/catalog-be/src/test/java/org/openecomp/sdc/be/components/impl/AttributeBusinessLogicTest.java
+++ b/catalog-be/src/test/java/org/openecomp/sdc/be/components/impl/AttributeBusinessLogicTest.java
@@ -21,20 +21,29 @@
*/
package org.openecomp.sdc.be.components.impl;
+import static org.junit.Assert.assertTrue;
+import static org.mockito.ArgumentMatchers.any;
+import static org.mockito.Mockito.when;
+
import fj.data.Either;
-import junit.framework.Assert;
+import java.lang.reflect.Field;
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
import org.junit.Before;
import org.junit.Test;
import org.mockito.Mockito;
import org.openecomp.sdc.be.components.validation.UserValidations;
import org.openecomp.sdc.be.dao.janusgraph.JanusGraphOperationStatus;
import org.openecomp.sdc.be.dao.jsongraph.JanusGraphDao;
+import org.openecomp.sdc.be.datatypes.elements.AttributeDataDefinition;
import org.openecomp.sdc.be.impl.ComponentsUtils;
+import org.openecomp.sdc.be.model.AttributeDefinition;
import org.openecomp.sdc.be.model.Component;
+import org.openecomp.sdc.be.model.DataTypeDefinition;
import org.openecomp.sdc.be.model.LifecycleStateEnum;
import org.openecomp.sdc.be.model.PropertyDefinition;
-import org.openecomp.sdc.be.datatypes.elements.AttributeDataDefinition;
-import org.openecomp.sdc.be.model.AttributeDefinition;
import org.openecomp.sdc.be.model.Resource;
import org.openecomp.sdc.be.model.cache.ApplicationDataTypeCache;
import org.openecomp.sdc.be.model.jsonjanusgraph.operations.ToscaOperationFacade;
@@ -44,54 +53,40 @@
import org.openecomp.sdc.be.model.tosca.ToscaPropertyType;
import org.openecomp.sdc.exception.ResponseFormat;
-import java.lang.reflect.Field;
-import java.util.ArrayList;
-import java.util.HashMap;
-import java.util.List;
-import java.util.Map;
-
-import static org.mockito.ArgumentMatchers.any;
-import static org.mockito.ArgumentMatchers.anyObject;
-import static org.mockito.Mockito.when;
-
-import org.openecomp.sdc.be.model.DataTypeDefinition;
-
-public class AttributeBusinessLogicTest extends BaseBusinessLogicMock{
+public class AttributeBusinessLogicTest extends BaseBusinessLogicMock {
private AttributeBusinessLogic createTestSubject() {
return new AttributeBusinessLogic(elementDao, groupOperation, groupInstanceOperation, groupTypeOperation,
interfaceOperation, interfaceLifecycleTypeOperation, artifactToscaOperation );
}
- UserValidations userValidations = Mockito.mock(UserValidations.class);
- ComponentsUtils componentsUtils = Mockito.mock(ComponentsUtils.class);
- JanusGraphDao janusGraphDao = Mockito.mock(JanusGraphDao.class);
- ToscaOperationFacade toscaOperationFacade = Mockito.mock(ToscaOperationFacade.class);
- ApplicationDataTypeCache applicationDataTypeCache = Mockito.mock(ApplicationDataTypeCache.class);
- PropertyOperation propertyOperation = Mockito.mock(PropertyOperation.class);
- Field baseBusinessLogic;
- Field baseBusinessLogic1;
- Field baseBusinessLogic2;
- Field baseBusinessLogic3;
- AttributeBusinessLogic attributeBusinessLogic=createTestSubject();
- IGraphLockOperation igraphLockOperation = Mockito.mock(IGraphLockOperation.class);
+ private UserValidations userValidations = Mockito.mock(UserValidations.class);
+ private ComponentsUtils componentsUtils = Mockito.mock(ComponentsUtils.class);
+ private JanusGraphDao janusGraphDao = Mockito.mock(JanusGraphDao.class);
+ private ToscaOperationFacade toscaOperationFacade = Mockito.mock(ToscaOperationFacade.class);
+ private ApplicationDataTypeCache applicationDataTypeCache = Mockito.mock(ApplicationDataTypeCache.class);
+ private PropertyOperation propertyOperation = Mockito.mock(PropertyOperation.class);
+ private Field baseBusinessLogic;
+ private AttributeBusinessLogic attributeBusinessLogic=createTestSubject();
+ private IGraphLockOperation igraphLockOperation = Mockito.mock(IGraphLockOperation.class);
@Before
- public void setup() throws Exception{
-
+ public void setup() throws Exception {
baseBusinessLogic = attributeBusinessLogic.getClass().getSuperclass().getDeclaredField("graphLockOperation");
baseBusinessLogic.setAccessible(true);
baseBusinessLogic.set(attributeBusinessLogic, igraphLockOperation);
- baseBusinessLogic1 = attributeBusinessLogic.getClass().getSuperclass().getDeclaredField("userValidations");
+ final Field baseBusinessLogic1 = attributeBusinessLogic.getClass().getSuperclass()
+ .getDeclaredField("userValidations");
baseBusinessLogic1.setAccessible(true);
baseBusinessLogic1.set(attributeBusinessLogic, userValidations);
- baseBusinessLogic2 = attributeBusinessLogic.getClass().getSuperclass().getDeclaredField("componentsUtils");
+ final Field baseBusinessLogic2 = attributeBusinessLogic.getClass().getSuperclass()
+ .getDeclaredField("componentsUtils");
baseBusinessLogic2.setAccessible(true);
baseBusinessLogic2.set(attributeBusinessLogic, componentsUtils);
- baseBusinessLogic3 = attributeBusinessLogic.getClass().getSuperclass().getDeclaredField("janusGraphDao");
+ final Field baseBusinessLogic3 = attributeBusinessLogic.getClass().getSuperclass().getDeclaredField("janusGraphDao");
baseBusinessLogic3.setAccessible(true);
baseBusinessLogic3.set(attributeBusinessLogic, janusGraphDao);
@@ -109,79 +104,17 @@
}
@Test
- public void testCreateAttribute() throws Exception {
- AttributeBusinessLogic testSubject;
- String resourceId = "";
- PropertyDefinition newAttributeDef = null;
- String userId = "";
- Either<AttributeDataDefinition, ResponseFormat> result;
-
- // default test
- testSubject = createTestSubject();
- }
-
- @Test
- public void testIsAttributeExist() throws Exception {
- AttributeBusinessLogic testSubject;List<AttributeDataDefinition> attributes = null;
- String resourceUid = "";
- String propertyName = "";
- boolean result;
-
- // test 1
- testSubject=createTestSubject();attributes = null;
- }
-
- @Test
- public void testGetAttribute() throws Exception {
- AttributeBusinessLogic testSubject;
- String resourceId = "";
- String attributeId = "";
- String userId = "";
- Either<PropertyDefinition, ResponseFormat> result;
-
- // default test
- testSubject = createTestSubject();
- }
-
- @Test
- public void testUpdateAttribute() throws Exception {
- AttributeBusinessLogic testSubject;
- String resourceId = "";
- String attributeId = "";
- PropertyDefinition newAttDef = null;
- String userId = "";
- Either<PropertyDefinition, ResponseFormat> result;
-
- // default test
- testSubject = createTestSubject();
- }
-
- @Test
- public void testDeleteAttribute() throws Exception {
- AttributeBusinessLogic testSubject;
- String resourceId = "";
- String attributeId = "";
- String userId = "";
- Either<PropertyDefinition, ResponseFormat> result;
-
- // default test
- testSubject = createTestSubject();
- }
-
- @Test
- public void createAttribute_lockfail() throws Exception {
- Either<AttributeDataDefinition, ResponseFormat> response;
- AttributeDataDefinition prop= new AttributeDataDefinition();
+ public void createAttribute_lockfail() {
+ Either<PropertyDefinition, ResponseFormat> response;
+ PropertyDefinition prop= new PropertyDefinition();
response = attributeBusinessLogic.createAttribute("RES01", prop, "USR01");
- Assert.assertEquals(true,response.isRight());
-
+ assertTrue(response.isRight());
}
@Test
- public void createAttribute_Success() throws Exception {
-
+ public void createAttribute_Success() {
Component resource = new Resource();
resource.setLifecycleState(LifecycleStateEnum.NOT_CERTIFIED_CHECKOUT);
resource.setIsDeleted(false);
@@ -192,32 +125,29 @@
when(igraphLockOperation.lockComponent(any(), any())).thenReturn(StorageOperationStatus.OK);
- //Either<Component, StorageOperationStatus> toscastatus=Either.right(StorageOperationStatus.INVALID_PROPERTY);
Either<Component, StorageOperationStatus> toscastatus = Either.left(resource);
when(toscaOperationFacade.getToscaElement("RES01")).thenReturn(toscastatus);
AttributeDataDefinition attributeDataDefinition = new AttributeDataDefinition();
Either<AttributeDataDefinition, StorageOperationStatus> either = Either.left(attributeDataDefinition);
- when(toscaOperationFacade.addAttributeOfResource(anyObject(), anyObject())).thenReturn(either);
+ when(toscaOperationFacade.addAttributeOfResource(any(), any())).thenReturn(either);
- when(propertyOperation.isPropertyTypeValid(anyObject())).thenReturn(true);
+ when(propertyOperation.isPropertyTypeValid(any(), any())).thenReturn(true);
Map<String, DataTypeDefinition> data = new HashMap<>();
data.put("ONE", new DataTypeDefinition());
Either<Map<String, DataTypeDefinition>, JanusGraphOperationStatus> allDataTypes = Either.left(data);
when(applicationDataTypeCache.getAll()).thenReturn(allDataTypes);
- when(propertyOperation.isPropertyDefaultValueValid(anyObject(), anyObject())).thenReturn(true);
+ when(propertyOperation.isPropertyDefaultValueValid(any(), any())).thenReturn(true);
Either<AttributeDataDefinition, ResponseFormat> response;
response = attributeBusinessLogic.createAttribute("RES01", attrib, "USR01");
- Assert.assertEquals(true, response.isLeft());
-
+ assertTrue( response.isLeft());
}
@Test
- public void createAttribute_failtogettoscaelement() throws Exception {
-
+ public void createAttribute_failtogettoscaelement() throws NoSuchFieldException, IllegalAccessException {
Component resource= new Resource();
resource.setLifecycleState(LifecycleStateEnum.NOT_CERTIFIED_CHECKOUT);
resource.setIsDeleted(false);
@@ -231,19 +161,16 @@
baseBusinessLogic = attributeBusinessLogic.getClass().getSuperclass().getDeclaredField("toscaOperationFacade");
baseBusinessLogic.setAccessible(true);
baseBusinessLogic.set(attributeBusinessLogic, toscaOperationFacade);
- //Either<Component, StorageOperationStatus> toscastatus=Either.right(StorageOperationStatus.INVALID_PROPERTY);
Either<Component, StorageOperationStatus> toscastatus=Either.right(StorageOperationStatus.GENERAL_ERROR);
when(toscaOperationFacade.getToscaElement("RES01")).thenReturn(toscastatus);
response = attributeBusinessLogic.createAttribute("RES01", prop, "USR01");
- Assert.assertEquals(true,response.isRight());
-
+ assertTrue(response.isRight());
}
@Test
- public void createAttribute_componentvalidationfails() throws Exception {
-
+ public void createAttribute_componentvalidationfails() {
Component resource= new Resource();
resource.setLifecycleState(LifecycleStateEnum.CERTIFIED);
resource.setIsDeleted(false);
@@ -254,19 +181,16 @@
Either<AttributeDataDefinition, ResponseFormat> response;
AttributeDataDefinition prop= new AttributeDataDefinition();
- //Either<Component, StorageOperationStatus> toscastatus=Either.right(StorageOperationStatus.INVALID_PROPERTY);
Either<Component, StorageOperationStatus> toscastatus=Either.left(resource);
when(toscaOperationFacade.getToscaElement("RES01")).thenReturn(toscastatus);
response = attributeBusinessLogic.createAttribute("RES01", prop, "USR01");
- Assert.assertEquals(true,response.isRight());
-
+ assertTrue(response.isRight());
}
@Test
- public void createAttribute_componentalreadyexist_fails() throws Exception {
-
+ public void createAttribute_componentalreadyexist_fails() {
Either<AttributeDataDefinition, ResponseFormat> response;
AttributeDefinition attrib = new AttributeDefinition();
attrib.setName("RES01");
@@ -275,26 +199,24 @@
List<AttributeDataDefinition> attributes = new ArrayList<>();
attributes.add(attrib);
- Component resource = new Resource();
+ final Resource resource = new Resource();
resource.setLifecycleState(LifecycleStateEnum.NOT_CERTIFIED_CHECKOUT);
resource.setIsDeleted(false);
resource.setLastUpdaterUserId("USR01");
- ((Resource) resource).setAttributes(attributes);
+ resource.setAttributes(attributes);
when(igraphLockOperation.lockComponent(any(), any())).thenReturn(StorageOperationStatus.OK);
- //Either<Component, StorageOperationStatus> toscastatus=Either.right(StorageOperationStatus.INVALID_PROPERTY);
Either<Component, StorageOperationStatus> toscastatus = Either.left(resource);
when(toscaOperationFacade.getToscaElement("RES01")).thenReturn(toscastatus);
response = attributeBusinessLogic.createAttribute("RES01", attrib, "USR01");
- Assert.assertEquals(true, response.isRight());
-
+ assertTrue(response.isRight());
}
@Test
- public void createAttribute_addresourcetostoragefails() throws Exception {
+ public void createAttribute_addresourcetostoragefails() {
Component resource = new Resource();
resource.setLifecycleState(LifecycleStateEnum.NOT_CERTIFIED_CHECKOUT);
@@ -304,33 +226,32 @@
IGraphLockOperation igraphLockOperation = Mockito.mock(IGraphLockOperation.class);
when(igraphLockOperation.lockComponent(any(), any())).thenReturn(StorageOperationStatus.OK);
- //Either<Component, StorageOperationStatus> toscastatus=Either.right(StorageOperationStatus.INVALID_PROPERTY);
Either<Component, StorageOperationStatus> toscastatus = Either.left(resource);
when(toscaOperationFacade.getToscaElement("RES01")).thenReturn(toscastatus);
AttributeDataDefinition attributeDataDefinition = new AttributeDataDefinition();
Either<AttributeDataDefinition, StorageOperationStatus> either = Either
.right(StorageOperationStatus.CONNECTION_FAILURE);
- when(toscaOperationFacade.addAttributeOfResource(anyObject(), anyObject())).thenReturn(either);
+ when(toscaOperationFacade.addAttributeOfResource(any(),any())).thenReturn(either);
- when(propertyOperation.isPropertyTypeValid(anyObject())).thenReturn(true);
+ when(propertyOperation.isPropertyTypeValid(any())).thenReturn(true);
Map<String, DataTypeDefinition> data = new HashMap<>();
data.put("ONE", new DataTypeDefinition());
Either<Map<String, DataTypeDefinition>, JanusGraphOperationStatus> allDataTypes = Either.left(data);
when(applicationDataTypeCache.getAll()).thenReturn(allDataTypes);
- when(propertyOperation.isPropertyDefaultValueValid(anyObject(), anyObject())).thenReturn(true);
+ when(propertyOperation.isPropertyDefaultValueValid(any(),any())).thenReturn(true);
Either<AttributeDataDefinition, ResponseFormat> response;
AttributeDataDefinition attrib = new AttributeDefinition();
response = attributeBusinessLogic.createAttribute("RES01", attrib, "USR01");
- Assert.assertEquals(true, response.isRight());
+ assertTrue( response.isRight());
}
@Test
- public void testgetAttribute_ATTRIBUTE_NOT_FOUND() throws Exception {
+ public void testgetAttribute_ATTRIBUTE_NOT_FOUND() {
Either<AttributeDataDefinition, ResponseFormat> result;
Component resource= new Resource();
@@ -341,14 +262,14 @@
when(toscaOperationFacade.getToscaElement("RES01")).thenReturn(toscastatus);
result=attributeBusinessLogic.getAttribute("RES01","ATTR01", "USR01");
- Assert.assertEquals(true,result.isRight());
+ assertTrue(result.isRight());
}
@Test
- public void testgetAttribute_success() throws Exception {
+ public void testgetAttribute_success() {
Either<AttributeDataDefinition, ResponseFormat> result;
- Component resource = new Resource();
+ final Resource resource = new Resource();
resource.setLifecycleState(LifecycleStateEnum.NOT_CERTIFIED_CHECKOUT);
resource.setIsDeleted(false);
resource.setLastUpdaterUserId("USR01");
@@ -360,69 +281,60 @@
List<AttributeDataDefinition> attr = new ArrayList<>();
attr.add(attrib);
- ((Resource) resource).setAttributes(attr);
+ resource.setAttributes(attr);
Either<Component, StorageOperationStatus> toscastatus = Either.left(resource);
when(toscaOperationFacade.getToscaElement("RES01")).thenReturn(toscastatus);
result = attributeBusinessLogic.getAttribute("RES01", "ATTR01", "USR01");
- Assert.assertEquals(true, result.isLeft());
+ assertTrue( result.isLeft());
}
@Test
- public void testgetAttribute_RESOURCE_NOT_FOUND() throws Exception {
+ public void testgetAttribute_RESOURCE_NOT_FOUND() {
Either<AttributeDataDefinition, ResponseFormat> result;
Either<Component, StorageOperationStatus> toscastatus=Either.right(StorageOperationStatus.PARENT_RESOURCE_NOT_FOUND);
when(toscaOperationFacade.getToscaElement("RES01")).thenReturn(toscastatus);
result=attributeBusinessLogic.getAttribute("RES01","ATTR01", "USR01");
- Assert.assertEquals(true,result.isRight());
+ assertTrue(result.isRight());
}
@Test
- public void testdeleteAttribute_FAILED_TO_LOCK_COMPONENT() throws Exception {
+ public void testdeleteAttribute_FAILED_TO_LOCK_COMPONENT() {
Either<AttributeDataDefinition, ResponseFormat> result;
result=attributeBusinessLogic.deleteAttribute("RES01","ATTR01", "USR01");
- Assert.assertEquals(true,result.isRight());
+ assertTrue(result.isRight());
}
@Test
- public void testdeleteAttribute_get_RESOURCE_from_DB_failed() throws Exception {
+ public void testdeleteAttribute_get_RESOURCE_from_DB_failed() {
Either<AttributeDataDefinition, ResponseFormat> result;
Either<Component, StorageOperationStatus> toscastatus=Either.right(StorageOperationStatus.CONNECTION_FAILURE);
when(toscaOperationFacade.getToscaElement("RES01")).thenReturn(toscastatus);
result=attributeBusinessLogic.deleteAttribute("RES01","ATTR01", "USR01");
- Assert.assertEquals(true,result.isRight());
+ assertTrue(result.isRight());
}
@Test
- public void testdeleteAttribute_get_RESOURCE_verification_failed() throws Exception {
+ public void testdeleteAttribute_get_RESOURCE_verification_failed() {
Either<AttributeDataDefinition, ResponseFormat> result;
-
-
Component resource= new Resource();
resource.setLifecycleState(LifecycleStateEnum.NOT_CERTIFIED_CHECKOUT);
resource.setIsDeleted(true);
resource.setLastUpdaterUserId("USR01");
-
-
when(igraphLockOperation.lockComponent(any(),any())).thenReturn(StorageOperationStatus.OK);
-
-
-
-
Either<Component, StorageOperationStatus> toscastatus=Either.left(resource);
when(toscaOperationFacade.getToscaElement("RES01")).thenReturn(toscastatus);
-
result=attributeBusinessLogic.deleteAttribute("RES01","ATTR01", "USR01");
- Assert.assertEquals(true,result.isRight());
+ assertTrue(result.isRight());
}
@Test
- public void testdeleteAttribute_nonexistingresource() throws Exception {
+ public void testdeleteAttribute_nonexistingresource() {
Either<AttributeDataDefinition, ResponseFormat> result;
@@ -437,15 +349,13 @@
when(toscaOperationFacade.getToscaElement("RES01")).thenReturn(toscastatus);
result=attributeBusinessLogic.deleteAttribute("RES01","ATTR01", "USR01");
- Assert.assertEquals(true,result.isRight());
+ assertTrue(result.isRight());
}
@Test
- public void testdeleteAttribute_success() throws Exception {
+ public void testdeleteAttribute_success() {
Either<AttributeDataDefinition, ResponseFormat> result;
-
-
- Component resource= new Resource();
+ final Resource resource = new Resource();
resource.setLifecycleState(LifecycleStateEnum.NOT_CERTIFIED_CHECKOUT);
resource.setIsDeleted(false);
resource.setLastUpdaterUserId("USR01");
@@ -461,10 +371,10 @@
attrib.setParentUniqueId("RES01");
List<AttributeDataDefinition> attributes = new ArrayList<>();
attributes.add(attrib);
- ((Resource) resource).setAttributes(attributes);
+ resource.setAttributes(attributes);
result = attributeBusinessLogic.deleteAttribute("RES01", "ATTR01", "USR01");
- Assert.assertEquals(true, result.isLeft());
+ assertTrue( result.isLeft());
}
}
diff --git a/catalog-be/src/test/java/org/openecomp/sdc/be/components/impl/DataTypeBusinessLogicTest.java b/catalog-be/src/test/java/org/openecomp/sdc/be/components/impl/DataTypeBusinessLogicTest.java
index cc05eaf..9a05c0c 100644
--- a/catalog-be/src/test/java/org/openecomp/sdc/be/components/impl/DataTypeBusinessLogicTest.java
+++ b/catalog-be/src/test/java/org/openecomp/sdc/be/components/impl/DataTypeBusinessLogicTest.java
@@ -20,37 +20,50 @@
package org.openecomp.sdc.be.components.impl;
+import static org.hamcrest.CoreMatchers.is;
+import static org.hamcrest.MatcherAssert.assertThat;
+import static org.hamcrest.Matchers.containsInAnyOrder;
+import static org.hamcrest.Matchers.empty;
+import static org.hamcrest.Matchers.not;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertTrue;
+import static org.mockito.ArgumentMatchers.argThat;
+import static org.mockito.ArgumentMatchers.eq;
+import static org.mockito.Mockito.when;
+
+import com.google.common.collect.ImmutableMap;
import fj.data.Either;
+import java.util.Arrays;
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+import java.util.Optional;
+import java.util.function.BiFunction;
import org.junit.Before;
+import org.junit.Rule;
import org.junit.Test;
+import org.junit.rules.ExpectedException;
import org.mockito.InjectMocks;
import org.mockito.Mock;
import org.mockito.Mockito;
import org.mockito.MockitoAnnotations;
+import org.openecomp.sdc.be.components.impl.exceptions.DataTypeNotProvidedException;
import org.openecomp.sdc.be.components.validation.UserValidations;
-import org.openecomp.sdc.be.impl.ComponentsUtils;
import org.openecomp.sdc.be.model.ComponentInstance;
import org.openecomp.sdc.be.model.ComponentInstanceInput;
import org.openecomp.sdc.be.model.ComponentParametersView;
import org.openecomp.sdc.be.model.DataTypeDefinition;
import org.openecomp.sdc.be.model.Service;
import org.openecomp.sdc.be.model.User;
+import org.openecomp.sdc.be.model.cache.ApplicationDataTypeCache;
import org.openecomp.sdc.be.model.jsonjanusgraph.operations.ToscaOperationFacade;
+import org.openecomp.sdc.be.model.operations.StorageException;
import org.openecomp.sdc.be.model.operations.api.StorageOperationStatus;
+import org.openecomp.sdc.be.model.operations.impl.PropertyOperation;
import org.openecomp.sdc.be.model.tosca.ToscaPropertyType;
import org.openecomp.sdc.be.user.UserBusinessLogic;
-import java.util.Arrays;
-import java.util.Collections;
-import java.util.HashMap;
-import java.util.List;
-import java.util.Map;
-
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertTrue;
-import static org.mockito.ArgumentMatchers.eq;
-import static org.mockito.Mockito.when;
-
public class DataTypeBusinessLogicTest {
private static final String COMPONENT_INSTANCE_ID = "instanceId";
@@ -59,8 +72,8 @@
private static final String INSTANCE_INPUT_ID = "inputId";
private static final String DATATYPE_NAME = "org.onap.datatypes.mytype";
- @Mock
- private ComponentsUtils componentsUtilsMock;
+ @Rule
+ public ExpectedException exceptionRule = ExpectedException.none();
@Mock
private UserBusinessLogic userAdminMock;
@@ -69,13 +82,16 @@
private ToscaOperationFacade toscaOperationFacadeMock;
@Mock
- private UserValidations userValidations;
+ private UserValidations userValidationsMock;
@Mock
- private ComponentInstanceBusinessLogic componentInstanceBusinessLogic;
+ private PropertyOperation propertyOperationMock;
+
+ @Mock
+ private ApplicationDataTypeCache applicationDataTypeCacheMock;
@InjectMocks
- private DataTypeBusinessLogic testInstance;
+ private DataTypeBusinessLogic dataTypeBusinessLogic;
private Service service;
@@ -83,16 +99,12 @@
public void setUp() throws Exception {
MockitoAnnotations.initMocks(this);
- testInstance.setToscaOperationFacade(toscaOperationFacadeMock);
-
service = new Service();
service.setUniqueId(COMPONENT_INSTANCE_ID);
ComponentInstance componentInstance = new ComponentInstance();
componentInstance.setUniqueId(COMPONENT_INSTANCE_ID);
service.setComponentInstances(Collections.singletonList(componentInstance));
- DataTypeDefinition dataType = new DataTypeDefinition();
- dataType.setName(DATATYPE_NAME);
- dataType.setDerivedFromName(ToscaPropertyType.ROOT.getType());
+ final DataTypeDefinition dataType = createDataTypeDefinition(DATATYPE_NAME, ToscaPropertyType.ROOT.getType());
List<DataTypeDefinition> dataTypes = Arrays.asList(dataType);
service.setDataTypes(dataTypes);
@@ -102,56 +114,141 @@
instanceInputMap.put(COMPONENT_INSTANCE_ID, Collections.singletonList(componentInstanceInput));
instanceInputMap.put("someInputId", Collections.singletonList(new ComponentInstanceInput()));
service.setComponentInstancesInputs(instanceInputMap);
- when(userValidations.validateUserExists(eq(USER_ID))).thenReturn(new User());
+ when(userValidationsMock.validateUserExists(eq(USER_ID))).thenReturn(new User());
when(userAdminMock.getUser(USER_ID, false)).thenReturn(new User());
}
+ private DataTypeDefinition createDataTypeDefinition(final String name, final String derivedFrom) {
+ DataTypeDefinition dataType = new DataTypeDefinition();
+ dataType.setName(name);
+ dataType.setDerivedFromName(derivedFrom);
+ return dataType;
+ }
+
@Test
- public void test_getPrivateDataTypes() throws Exception {
+ public void test_getPrivateDataTypes() {
setMockitoWhenGetToscaElementCalled();
- Either<List<DataTypeDefinition>, StorageOperationStatus> result = testInstance.getPrivateDataTypes(COMPONENT_ID);
+ Either<List<DataTypeDefinition>, StorageOperationStatus> result = dataTypeBusinessLogic.getPrivateDataTypes(COMPONENT_ID);
assertTrue(result.isLeft());
List<DataTypeDefinition> dataTypes = result.left().value();
assertEquals(service.getDataTypes(), dataTypes);
}
@Test
- public void test_getPrivateDataType() throws Exception {
+ public void test_getPrivateDataType() {
setMockitoWhenGetToscaElementCalled();
Either<DataTypeDefinition, StorageOperationStatus> result =
- testInstance.getPrivateDataType(COMPONENT_ID, DATATYPE_NAME);
+ dataTypeBusinessLogic.getPrivateDataType(COMPONENT_ID, DATATYPE_NAME);
assertTrue(result.isLeft());
DataTypeDefinition dataType = result.left().value();
assertEquals(service.getDataTypes().get(0), dataType);
}
@Test
- public void test_deletePrivateDataType1() throws Exception {
+ public void test_deletePrivateDataType1() {
setMockitoWhenGetToscaElementCalled();
when(toscaOperationFacadeMock.deleteDataTypeOfComponent(service, DATATYPE_NAME))
.thenReturn(StorageOperationStatus.OK);
Either<DataTypeDefinition, StorageOperationStatus> result =
- testInstance.deletePrivateDataType(COMPONENT_ID, DATATYPE_NAME);
+ dataTypeBusinessLogic.deletePrivateDataType(COMPONENT_ID, DATATYPE_NAME);
assertTrue(result.isLeft());
DataTypeDefinition dataType = result.left().value();
assertEquals(service.getDataTypes().get(0), dataType);
}
@Test
- public void test_deletePrivateDataType2() throws Exception {
+ public void test_deletePrivateDataType2() {
when(toscaOperationFacadeMock.deleteDataTypeOfComponent(service, DATATYPE_NAME))
.thenReturn(StorageOperationStatus.OK);
Either<DataTypeDefinition, StorageOperationStatus> result =
- testInstance.deletePrivateDataType(service, DATATYPE_NAME);
+ dataTypeBusinessLogic.deletePrivateDataType(service, DATATYPE_NAME);
assertTrue(result.isLeft());
DataTypeDefinition dataType = result.left().value();
assertEquals(service.getDataTypes().get(0), dataType);
}
+ @Test
+ public void testAddToComponent() {
+ //given
+ final DataTypeDefinition dataTypeDefinition1 =
+ createDataTypeDefinition("data.type.1", ToscaPropertyType.ROOT.getType());
+ final DataTypeDefinition dataTypeDefinition2 =
+ createDataTypeDefinition("data.type.2", ToscaPropertyType.ROOT.getType());
+ final DataTypeDefinition dataTypeDefinition3 =
+ createDataTypeDefinition("data.type.child", dataTypeDefinition2.getName());
+
+ final DataTypeDefinition dataTypeDefinitionRoot =
+ createDataTypeDefinition(ToscaPropertyType.ROOT.getType(), null);
+
+
+ final List<DataTypeDefinition> expectedDataTypeDefinitionList
+ = Arrays.asList(dataTypeDefinition1, dataTypeDefinition2, dataTypeDefinition3);
+
+ final ImmutableMap<String, DataTypeDefinition> dataTypeDefinitionMap =
+ ImmutableMap.of(dataTypeDefinition1.getName(), dataTypeDefinition1,
+ dataTypeDefinition2.getName(), dataTypeDefinition2,
+ dataTypeDefinition3.getName(), dataTypeDefinition3);
+
+ when(propertyOperationMock.addDataType(dataTypeDefinition2)).thenReturn(Either.left(dataTypeDefinition2));
+ when(propertyOperationMock.findDataTypeByName(ToscaPropertyType.ROOT.getType()))
+ .thenReturn(Optional.of(dataTypeDefinitionRoot));
+ when(propertyOperationMock.findDataTypeByName(dataTypeDefinition1.getName())).thenReturn(Optional.of(dataTypeDefinition1));
+ when(propertyOperationMock.findDataTypeByName(dataTypeDefinition2.getName())).thenReturn(Optional.empty());
+ when(propertyOperationMock.findDataTypeByName(dataTypeDefinition3.getName())).thenReturn(Optional.empty());
+ final BiFunction<Map<String, DataTypeDefinition>, DataTypeDefinition, Boolean> keyMatcher =
+ (argument, dataTypeDefinition) -> argument != null && argument.containsKey(dataTypeDefinition.getName());
+ when(toscaOperationFacadeMock
+ .addDataTypesToComponent(argThat(map -> keyMatcher.apply(map, dataTypeDefinition1)),
+ eq(service.getUniqueId())))
+ .thenReturn(Either.left(Collections.singletonList(dataTypeDefinition1)));
+ when(toscaOperationFacadeMock
+ .addDataTypesToComponent(argThat(map -> keyMatcher.apply(map, dataTypeDefinition2)),
+ eq(service.getUniqueId())))
+ .thenReturn(Either.left(Collections.singletonList(dataTypeDefinition2)));
+ when(toscaOperationFacadeMock
+ .addDataTypesToComponent(argThat(map -> keyMatcher.apply(map, dataTypeDefinition3)),
+ eq(service.getUniqueId())))
+ .thenReturn(Either.left(Collections.singletonList(dataTypeDefinition3)));
+ //when
+ final List<DataTypeDefinition> actualDataTypeDefinitionList =
+ dataTypeBusinessLogic.addToComponent(service.getUniqueId(), dataTypeDefinitionMap);
+
+ //then
+ assertThat("Result should not be empty", actualDataTypeDefinitionList, is(not(empty())));
+ assertThat("Result should contains expected data type definitions",
+ actualDataTypeDefinitionList, containsInAnyOrder(expectedDataTypeDefinitionList.toArray()));
+
+ //given
+ when(toscaOperationFacadeMock
+ .addDataTypesToComponent(argThat(map -> keyMatcher.apply(map, dataTypeDefinition2)),
+ eq(service.getUniqueId())))
+ .thenReturn(Either.right(StorageOperationStatus.GENERAL_ERROR));
+ //then
+ exceptionRule.expect(StorageException.class);
+ //when
+ dataTypeBusinessLogic.addToComponent(service.getUniqueId(), dataTypeDefinitionMap);
+ }
+
+ @Test
+ public void testAddToComponentDataTypeNotProvidedException() {
+ //given
+ final DataTypeDefinition dataTypeDefinition =
+ createDataTypeDefinition("data.type.child", "not.provided.data.type");
+ final ImmutableMap<String, DataTypeDefinition> dataTypeDefinitionMap =
+ ImmutableMap.of(dataTypeDefinition.getName(), dataTypeDefinition);
+
+ //then
+ exceptionRule.expect(DataTypeNotProvidedException.class);
+ //when
+ when(propertyOperationMock.findDataTypeByName(dataTypeDefinition.getName())).thenReturn(Optional.empty());
+ dataTypeBusinessLogic.addToComponent(service.getUniqueId(), dataTypeDefinitionMap);
+ }
+
+
private void setMockitoWhenGetToscaElementCalled() {
when(toscaOperationFacadeMock.getToscaElement(eq(COMPONENT_ID), Mockito.any(ComponentParametersView.class)))
.thenReturn(Either.left(service));
diff --git a/catalog-be/src/test/java/org/openecomp/sdc/be/components/impl/InputsBusinessLogicTest.java b/catalog-be/src/test/java/org/openecomp/sdc/be/components/impl/InputsBusinessLogicTest.java
index 4b021c3..f421705 100644
--- a/catalog-be/src/test/java/org/openecomp/sdc/be/components/impl/InputsBusinessLogicTest.java
+++ b/catalog-be/src/test/java/org/openecomp/sdc/be/components/impl/InputsBusinessLogicTest.java
@@ -21,6 +21,7 @@
import org.apache.commons.collections.CollectionUtils;
import org.apache.commons.lang3.tuple.ImmutablePair;
import org.junit.Before;
+import org.junit.BeforeClass;
import org.junit.Test;
import org.mockito.ArgumentCaptor;
import org.mockito.Captor;
@@ -148,6 +149,13 @@
private Map<String, List<ComponentInstanceInput>> instanceInputMap;
private List<ComponentInstanceInput> inputsList;
+ @BeforeClass
+ public static void beforeClassSetup() {
+ final ConfigurationSource configurationSource = new FSConfigurationSource(
+ ExternalConfiguration.getChangeListener(), "src/test/resources/config/catalog-be");
+ new ConfigurationManager(configurationSource);
+ }
+
@Before
public void setUp() {
MockitoAnnotations.initMocks(this);
@@ -452,7 +460,7 @@
}
@Test
- public void test_createListInput_success() throws Exception {
+ public void test_createListInput_success() {
ComponentInstListInput createListInputParams = setUpCreateListInputParams();
ComponentInstInputsMap componentInstInputsMap = createListInputParams.getComponentInstInputsMap();
List<ComponentInstancePropInput> propInputsList = componentInstInputsMap.getComponentInstanceInputsMap().get(COMPONENT_INSTANCE_ID);
@@ -469,7 +477,7 @@
// for BaseOperation.getAllDataTypes:
when(applicationDataTypeCache.getAll()).thenReturn(Either.left(new HashMap<>())); // don't use Collections.emptyMap
// for BaseOperation.validatePropertyDefaultValue:
- when(propertyOperation.isPropertyTypeValid(any())).thenReturn(true);
+ when(propertyOperation.isPropertyTypeValid(any(), any())).thenReturn(true);
when(propertyOperation.isPropertyInnerTypeValid(any(),any())).thenReturn(new ImmutablePair<>(listInput.getSchemaType(), true));
when(propertyOperation.isPropertyDefaultValueValid(any(), any())).thenReturn(true);
// for createListInputsInGraph:
@@ -554,18 +562,20 @@
}
@Test
- public void test_createListInput_fail_prepareAndValidateInput() throws Exception {
- ComponentInstListInput createListInputParams = setUpCreateListInputParams();
- ComponentInstInputsMap componentInstInputsMap = createListInputParams.getComponentInstInputsMap();
- InputDefinition listInput = createListInputParams.getListInput();
+ public void test_createListInput_fail_prepareAndValidateInput() {
+ final ComponentInstListInput createListInputParams = setUpCreateListInputParams();
+ final ComponentInstInputsMap componentInstInputsMap = createListInputParams.getComponentInstInputsMap();
- when(toscaOperationFacadeMock.getToscaElement(eq(COMPONENT_ID), any(ComponentParametersView.class))).thenReturn(Either.left(service));
- when(graphLockOperation.lockComponent(COMPONENT_ID, NodeTypeEnum.Service)).thenReturn(StorageOperationStatus.OK);
- when(toscaOperationFacadeMock.addDataTypesToComponent(dataTypesMapCaptor.capture(), eq(COMPONENT_ID))).thenReturn(Either.left(new ArrayList<>()));
+ when(toscaOperationFacadeMock.getToscaElement(eq(COMPONENT_ID), any(ComponentParametersView.class)))
+ .thenReturn(Either.left(service));
+ when(graphLockOperation.lockComponent(COMPONENT_ID, NodeTypeEnum.Service))
+ .thenReturn(StorageOperationStatus.OK);
+ when(toscaOperationFacadeMock.addDataTypesToComponent(dataTypesMapCaptor.capture(), eq(COMPONENT_ID)))
+ .thenReturn(Either.left(new ArrayList<>()));
when(propertyDeclarationOrchestrator.getPropOwnerId(componentInstInputsMap)).thenReturn(COMPONENT_INSTANCE_ID);
- when(applicationDataTypeCache.getAll()).thenReturn(Either.left(new HashMap<>())); // don't use Collections.emptyMap
- // for BaseOperation.validatePropertyDefaultValue:
- when(propertyOperation.isPropertyTypeValid(any())).thenReturn(false);
+ when(applicationDataTypeCache.getAll())
+ .thenReturn(Either.left(new HashMap<>())); // don't use Collections.emptyMap
+ when(propertyOperation.isPropertyTypeValid(any(), any())).thenReturn(false);
Either<List<InputDefinition>, ResponseFormat> result =
testInstance.createListInput(USER_ID, COMPONENT_ID, ComponentTypeEnum.SERVICE, createListInputParams, true, false);
@@ -574,21 +584,26 @@
}
@Test
- public void test_createListInput_fail_addInputsToComponent() throws Exception {
- ComponentInstListInput createListInputParams = setUpCreateListInputParams();
- ComponentInstInputsMap componentInstInputsMap = createListInputParams.getComponentInstInputsMap();
- InputDefinition listInput = createListInputParams.getListInput();
+ public void test_createListInput_fail_addInputsToComponent() {
+ final ComponentInstListInput createListInputParams = setUpCreateListInputParams();
+ final ComponentInstInputsMap componentInstInputsMap = createListInputParams.getComponentInstInputsMap();
+ final InputDefinition listInput = createListInputParams.getListInput();
- when(toscaOperationFacadeMock.getToscaElement(eq(COMPONENT_ID), any(ComponentParametersView.class))).thenReturn(Either.left(service));
- when(graphLockOperation.lockComponent(COMPONENT_ID, NodeTypeEnum.Service)).thenReturn(StorageOperationStatus.OK);
- when(toscaOperationFacadeMock.addDataTypesToComponent(dataTypesMapCaptor.capture(), eq(COMPONENT_ID))).thenReturn(Either.left(new ArrayList<>()));
+ when(toscaOperationFacadeMock.getToscaElement(eq(COMPONENT_ID), any(ComponentParametersView.class)))
+ .thenReturn(Either.left(service));
+ when(graphLockOperation.lockComponent(COMPONENT_ID, NodeTypeEnum.Service))
+ .thenReturn(StorageOperationStatus.OK);
+ when(toscaOperationFacadeMock.addDataTypesToComponent(dataTypesMapCaptor.capture(), eq(COMPONENT_ID)))
+ .thenReturn(Either.left(new ArrayList<>()));
when(propertyDeclarationOrchestrator.getPropOwnerId(componentInstInputsMap)).thenReturn(COMPONENT_INSTANCE_ID);
- when(applicationDataTypeCache.getAll()).thenReturn(Either.left(new HashMap<>())); // don't use Collections.emptyMap
- // for BaseOperation.validatePropertyDefaultValue:
- when(propertyOperation.isPropertyTypeValid(any())).thenReturn(true);
- when(propertyOperation.isPropertyInnerTypeValid(any(),any())).thenReturn(new ImmutablePair<>(listInput.getSchemaType(), true));
+ when(applicationDataTypeCache.getAll())
+ .thenReturn(Either.left(new HashMap<>())); // don't use Collections.emptyMap
+ when(propertyOperation.isPropertyTypeValid(any(), any())).thenReturn(true);
+ when(propertyOperation.isPropertyInnerTypeValid(any(), any()))
+ .thenReturn(new ImmutablePair<>(listInput.getSchemaType(), true));
when(propertyOperation.isPropertyDefaultValueValid(any(), any())).thenReturn(true);
- when(toscaOperationFacadeMock.addInputsToComponent(anyMap(), eq(COMPONENT_ID))).thenReturn(Either.right(StorageOperationStatus.NOT_FOUND));
+ when(toscaOperationFacadeMock.addInputsToComponent(anyMap(), eq(COMPONENT_ID)))
+ .thenReturn(Either.right(StorageOperationStatus.NOT_FOUND));
Either<List<InputDefinition>, ResponseFormat> result =
testInstance.createListInput(USER_ID, COMPONENT_ID, ComponentTypeEnum.SERVICE, createListInputParams, true, false);
diff --git a/catalog-be/src/test/java/org/openecomp/sdc/be/components/impl/ResourceBusinessLogicTest.java b/catalog-be/src/test/java/org/openecomp/sdc/be/components/impl/ResourceBusinessLogicTest.java
index 4d773a5..ac61f31 100644
--- a/catalog-be/src/test/java/org/openecomp/sdc/be/components/impl/ResourceBusinessLogicTest.java
+++ b/catalog-be/src/test/java/org/openecomp/sdc/be/components/impl/ResourceBusinessLogicTest.java
@@ -187,6 +187,7 @@
InterfaceOperation interfaceOperation = Mockito.mock(InterfaceOperation.class);
ArtifactsOperations artifactToscaOperation = Mockito.mock(ArtifactsOperations.class);
private PropertyBusinessLogic propertyBusinessLogic = Mockito.mock(PropertyBusinessLogic.class);
+ private DataTypeBusinessLogic dataTypeBusinessLogic = Mockito.mock(DataTypeBusinessLogic.class);
ArtifactsResolver artifactsResolver = Mockito.mock(ArtifactsResolver.class);
InterfaceLifecycleOperation interfaceLifecycleTypeOperation = Mockito.mock(InterfaceLifecycleOperation.class);
ComponentInstanceBusinessLogic componentInstanceBusinessLogic = Mockito.mock(ComponentInstanceBusinessLogic.class);
@@ -319,7 +320,7 @@
csarArtifactsAndGroupsBusinessLogic, mergeInstanceUtils, uiComponentDataConverter, csarBusinessLogic,
artifactToscaOperation, propertyBusinessLogic, componentContactIdValidator, componentNameValidator,
componentTagsValidator, componentValidator, componentIconValidator, componentProjectCodeValidator,
- componentDescriptionValidator, policyBusinessLogic);
+ componentDescriptionValidator, dataTypeBusinessLogic, policyBusinessLogic);
bl.setElementDao(mockElementDao);
bl.setUserAdmin(mockUserAdmin);
bl.setCapabilityTypeOperation(capabilityTypeOperation);
diff --git a/catalog-be/src/test/java/org/openecomp/sdc/be/components/lifecycle/CheckoutTest.java b/catalog-be/src/test/java/org/openecomp/sdc/be/components/lifecycle/CheckoutTest.java
index 48c2c9c..9c55b6f 100644
--- a/catalog-be/src/test/java/org/openecomp/sdc/be/components/lifecycle/CheckoutTest.java
+++ b/catalog-be/src/test/java/org/openecomp/sdc/be/components/lifecycle/CheckoutTest.java
@@ -20,6 +20,8 @@
package org.openecomp.sdc.be.components.lifecycle;
+import static org.junit.Assert.assertTrue;
+
import fj.data.Either;
import org.junit.Before;
import org.junit.Test;
@@ -29,6 +31,7 @@
import org.openecomp.sdc.be.components.csar.CsarBusinessLogic;
import org.openecomp.sdc.be.components.impl.ComponentInstanceBusinessLogic;
import org.openecomp.sdc.be.components.impl.CompositionBusinessLogic;
+import org.openecomp.sdc.be.components.impl.DataTypeBusinessLogic;
import org.openecomp.sdc.be.components.impl.InputsBusinessLogic;
import org.openecomp.sdc.be.components.impl.PolicyBusinessLogic;
import org.openecomp.sdc.be.components.impl.PropertyBusinessLogic;
@@ -48,8 +51,6 @@
import org.openecomp.sdc.be.user.Role;
import org.openecomp.sdc.exception.ResponseFormat;
-import static org.junit.Assert.assertTrue;
-
public class CheckoutTest extends LifecycleTestBase {
private CheckoutTransition checkoutObj = null;
@@ -65,7 +66,9 @@
private final PropertyBusinessLogic propertyBusinessLogic = Mockito.mock(PropertyBusinessLogic.class);
protected ComponentContactIdValidator componentContactIdValidator = new ComponentContactIdValidator(componentsUtils);
protected ComponentNameValidator componentNameValidator = new ComponentNameValidator(componentsUtils, toscaOperationFacade);
+ private final DataTypeBusinessLogic dataTypeBusinessLogic = Mockito.mock(DataTypeBusinessLogic.class);
private final PolicyBusinessLogic policyBusinessLogic = Mockito.mock(PolicyBusinessLogic.class);
+
@InjectMocks
ResourceBusinessLogic bl = new ResourceBusinessLogic(elementDao, groupOperation, groupInstanceOperation, groupTypeOperation,
groupBusinessLogic, interfaceOperation, interfaceLifecycleTypeOperation, artifactsBusinessLogic,
@@ -73,7 +76,8 @@
resourceDataMergeBusinessLogic, csarArtifactsAndGroupsBusinessLogic, mergeInstanceUtils,
uiComponentDataConverter, csarBusinessLogic, artifactToscaOperation, propertyBusinessLogic,
componentContactIdValidator, componentNameValidator, componentTagsValidator, componentValidator,
- componentIconValidator, componentProjectCodeValidator, componentDescriptionValidator ,policyBusinessLogic);
+ componentIconValidator, componentProjectCodeValidator, componentDescriptionValidator, dataTypeBusinessLogic
+ , policyBusinessLogic);
@Before
public void setup() {
diff --git a/catalog-model/src/main/java/org/openecomp/sdc/be/config/CatalogModelSpringConfig.java b/catalog-model/src/main/java/org/openecomp/sdc/be/config/CatalogModelSpringConfig.java
index 061975b..0b495e1 100644
--- a/catalog-model/src/main/java/org/openecomp/sdc/be/config/CatalogModelSpringConfig.java
+++ b/catalog-model/src/main/java/org/openecomp/sdc/be/config/CatalogModelSpringConfig.java
@@ -28,6 +28,7 @@
@Configuration
@ComponentScan({"org.openecomp.sdc.be.model.operations.impl",
"org.openecomp.sdc.be.model.cache",
+ "org.openecomp.sdc.be.model.converter",
"org.openecomp.sdc.be.model.jsonjanusgraph.utils",
"org.openecomp.sdc.be.model.jsonjanusgraph.operations",
"org.openecomp.sdc.be.model.jsonjanusgraph.config",
diff --git a/catalog-model/src/main/java/org/openecomp/sdc/be/model/Component.java b/catalog-model/src/main/java/org/openecomp/sdc/be/model/Component.java
index 6149929..26820b1 100644
--- a/catalog-model/src/main/java/org/openecomp/sdc/be/model/Component.java
+++ b/catalog-model/src/main/java/org/openecomp/sdc/be/model/Component.java
@@ -715,4 +715,26 @@
return componentMetadata;
}
+ /**
+ * Adds a list of data type definition to the internal data type list.
+ *
+ * @param dataTypeDefinitionList the list of data type definition to be added
+ */
+ public void addToDataTypes(final List<DataTypeDefinition> dataTypeDefinitionList) {
+ dataTypeDefinitionList.forEach(this::addToDataTypes);
+ }
+
+ /**
+ * Add a data type to the list of data types. Initializes the list if not yet initialized.
+ *
+ * @param dataTypeDefinition the data type definition to add
+ */
+ public void addToDataTypes(final DataTypeDefinition dataTypeDefinition) {
+ if (dataTypes == null) {
+ dataTypes = new ArrayList<>();
+ }
+ dataTypes.add(dataTypeDefinition);
+ }
+
+
}
diff --git a/catalog-model/src/main/java/org/openecomp/sdc/be/model/ParsedToscaYamlInfo.java b/catalog-model/src/main/java/org/openecomp/sdc/be/model/ParsedToscaYamlInfo.java
index a6f4165..ad0db66 100644
--- a/catalog-model/src/main/java/org/openecomp/sdc/be/model/ParsedToscaYamlInfo.java
+++ b/catalog-model/src/main/java/org/openecomp/sdc/be/model/ParsedToscaYamlInfo.java
@@ -20,17 +20,21 @@
package org.openecomp.sdc.be.model;
+import java.util.HashMap;
import java.util.Map;
import lombok.Getter;
import lombok.Setter;
import lombok.ToString;
-@ToString
@Getter
@Setter
+@ToString
public class ParsedToscaYamlInfo {
- Map<String, InputDefinition> inputs;
- Map<String, UploadComponentInstanceInfo> instances;
- Map<String, GroupDefinition> groups;
- Map<String, PolicyDefinition> policies;
+
+ private Map<String, InputDefinition> inputs;
+ private Map<String, UploadComponentInstanceInfo> instances;
+ private Map<String, GroupDefinition> groups;
+ private Map<String, DataTypeDefinition> dataTypes = new HashMap<>();
+ private Map<String, PolicyDefinition> policies;
+
}
diff --git a/catalog-model/src/main/java/org/openecomp/sdc/be/model/converter/PropertyDataConverter.java b/catalog-model/src/main/java/org/openecomp/sdc/be/model/converter/PropertyDataConverter.java
new file mode 100644
index 0000000..ffd5947
--- /dev/null
+++ b/catalog-model/src/main/java/org/openecomp/sdc/be/model/converter/PropertyDataConverter.java
@@ -0,0 +1,147 @@
+/*
+ * ============LICENSE_START=======================================================
+ * Copyright (C) 2020 Nordix Foundation
+ * ================================================================================
+ * 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.
+ *
+ * SPDX-License-Identifier: Apache-2.0
+ * ============LICENSE_END=========================================================
+ */
+
+package org.openecomp.sdc.be.model.converter;
+
+import static org.openecomp.sdc.be.datatypes.enums.JsonPresentationFields.DEFAULT_VALUE;
+import static org.openecomp.sdc.be.datatypes.enums.JsonPresentationFields.DEFINITION;
+import static org.openecomp.sdc.be.datatypes.enums.JsonPresentationFields.DESCRIPTION;
+import static org.openecomp.sdc.be.datatypes.enums.JsonPresentationFields.HIDDEN;
+import static org.openecomp.sdc.be.datatypes.enums.JsonPresentationFields.IMMUTABLE;
+import static org.openecomp.sdc.be.datatypes.enums.JsonPresentationFields.INPUT_ID;
+import static org.openecomp.sdc.be.datatypes.enums.JsonPresentationFields.INPUT_PATH;
+import static org.openecomp.sdc.be.datatypes.enums.JsonPresentationFields.INSTANCE_UNIQUE_ID;
+import static org.openecomp.sdc.be.datatypes.enums.JsonPresentationFields.LABEL;
+import static org.openecomp.sdc.be.datatypes.enums.JsonPresentationFields.NAME;
+import static org.openecomp.sdc.be.datatypes.enums.JsonPresentationFields.PARENT_PROPERTY_TYPE;
+import static org.openecomp.sdc.be.datatypes.enums.JsonPresentationFields.PASSWORD;
+import static org.openecomp.sdc.be.datatypes.enums.JsonPresentationFields.PROPERTY_CONSTRAINTS;
+import static org.openecomp.sdc.be.datatypes.enums.JsonPresentationFields.PROPERTY_ID;
+import static org.openecomp.sdc.be.datatypes.enums.JsonPresentationFields.REQUIRED;
+import static org.openecomp.sdc.be.datatypes.enums.JsonPresentationFields.SCHEMA;
+import static org.openecomp.sdc.be.datatypes.enums.JsonPresentationFields.STATUS;
+import static org.openecomp.sdc.be.datatypes.enums.JsonPresentationFields.SUB_PROPERTY_INPUT_PATH;
+import static org.openecomp.sdc.be.datatypes.enums.JsonPresentationFields.TYPE;
+import static org.openecomp.sdc.be.datatypes.enums.JsonPresentationFields.UNIQUE_ID;
+import static org.openecomp.sdc.be.datatypes.enums.JsonPresentationFields.VALUE;
+
+import java.util.Collections;
+import java.util.List;
+import java.util.Map;
+import java.util.function.Consumer;
+import java.util.stream.Collectors;
+import org.apache.commons.collections.CollectionUtils;
+import org.openecomp.sdc.be.datatypes.elements.PropertyDataDefinition;
+import org.openecomp.sdc.be.datatypes.enums.JsonPresentationFields;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.stereotype.Component;
+
+/**
+ * Converter to create {@link PropertyDataDefinition} instances from other data sources.
+ */
+@Component("propertyDataConverter")
+public class PropertyDataConverter {
+
+ private SchemaDefinitionConverter schemaDefinitionConverter;
+
+ /**
+ * Parses all property data JSON entry map the given list to {@link PropertyDataDefinition}.
+ *
+ * @param propertiesDataList the list of property data JSON entry map
+ * @return a list with all property data JSON entry map parsed as a PropertyDataDefinition
+ */
+ public List<PropertyDataDefinition> parseProperties(final List<Map<String, Object>> propertiesDataList) {
+ if (CollectionUtils.isEmpty(propertiesDataList)) {
+ return Collections.emptyList();
+ }
+
+ return propertiesDataList.stream()
+ .map(this::createPropertyData)
+ .collect(Collectors.toList());
+ }
+
+ /**
+ * Creates a {@link PropertyDataDefinition} from JSON entry map.
+ *
+ * @param propertyToscaMap the JSON entry map representing a {@link PropertyDataDefinition}
+ * @return a new instance of {@link PropertyDataDefinition}
+ */
+ public PropertyDataDefinition createPropertyData(final Map<String, Object> propertyToscaMap) {
+ final PropertyDataDefinition propertyData = new PropertyDataDefinition();
+ setPropertyValue(UNIQUE_ID, String.class, propertyToscaMap, propertyData::setUniqueId);
+ setPropertyValue(TYPE, String.class, propertyToscaMap, propertyData::setType);
+ setPropertyValue(REQUIRED, Boolean.class, propertyToscaMap, propertyData::setRequired);
+ setPropertyValue(NAME, String.class, propertyToscaMap, propertyData::setName);
+ setPropertyValue(VALUE, String.class, propertyToscaMap, propertyData::setValue);
+ setPropertyValue(LABEL, String.class, propertyToscaMap, propertyData::setLabel);
+ setPropertyValue(HIDDEN, Boolean.class, propertyToscaMap, propertyData::setHidden);
+ setPropertyValue(IMMUTABLE, Boolean.class, propertyToscaMap, propertyData::setImmutable);
+ setPropertyValue(PASSWORD, Boolean.class, propertyToscaMap, propertyData::setPassword);
+ setPropertyValue(DEFINITION, Boolean.class, propertyToscaMap, propertyData::setDefinition);
+ setPropertyValue(DESCRIPTION, String.class, propertyToscaMap, propertyData::setDescription);
+ setPropertyValue(DEFAULT_VALUE, String.class, propertyToscaMap, propertyData::setDefaultValue);
+ setPropertyValue(INPUT_PATH, String.class, propertyToscaMap, propertyData::setInputPath);
+ setPropertyValue(STATUS, String.class, propertyToscaMap, propertyData::setStatus);
+ setPropertyValue(INPUT_ID, String.class, propertyToscaMap, propertyData::setInputId);
+ setPropertyValue(INSTANCE_UNIQUE_ID, String.class, propertyToscaMap, propertyData::setInstanceUniqueId);
+ setPropertyValue(PROPERTY_ID, String.class, propertyToscaMap, propertyData::setPropertyId);
+ setPropertyValue(PARENT_PROPERTY_TYPE, String.class, propertyToscaMap, propertyData::setParentPropertyType);
+ setPropertyValue(SUB_PROPERTY_INPUT_PATH,
+ String.class, propertyToscaMap, propertyData::setSubPropertyInputPath);
+ setSchema(propertyToscaMap, propertyData);
+ setPropertyConstraints(propertyToscaMap, propertyData);
+
+ return propertyData;
+ }
+
+ private <T> void setPropertyValue(final JsonPresentationFields propertyField, final Class<T> propertyClass,
+ final Map<String, Object> propertyToscaMap, final Consumer<T> setter) {
+ final Object valueObj = propertyToscaMap.get(propertyField.getPresentation());
+ if (propertyClass.isInstance(valueObj)) {
+ setter.accept((T) valueObj);
+ }
+ }
+
+ private void setPropertyConstraints(final Map<String, Object> propertyValue,
+ final PropertyDataDefinition property) {
+ final String propertyConstraintsEntry = PROPERTY_CONSTRAINTS.getPresentation();
+ if (!propertyValue.containsKey(propertyConstraintsEntry)) {
+ return;
+ }
+ final Object constraintListObj = propertyValue.get(propertyConstraintsEntry);
+ if (constraintListObj instanceof List) {
+ property.setPropertyConstraints((List<String>) constraintListObj);
+ }
+ }
+
+ private void setSchema(final Map<String, Object> propertyValue, final PropertyDataDefinition propertyDefinition) {
+ final Object schemaObj = propertyValue.get(SCHEMA.getPresentation());
+ if (schemaObj == null) {
+ return;
+ }
+ schemaDefinitionConverter.parseTo(schemaObj).ifPresent(propertyDefinition::setSchema);
+ }
+
+ //circular dependency
+ @Autowired
+ public void setSchemaDefinitionConverter(final SchemaDefinitionConverter schemaDefinitionConverter) {
+ this.schemaDefinitionConverter = schemaDefinitionConverter;
+ }
+
+}
diff --git a/catalog-model/src/main/java/org/openecomp/sdc/be/model/converter/SchemaDefinitionConverter.java b/catalog-model/src/main/java/org/openecomp/sdc/be/model/converter/SchemaDefinitionConverter.java
new file mode 100644
index 0000000..2ca9ede
--- /dev/null
+++ b/catalog-model/src/main/java/org/openecomp/sdc/be/model/converter/SchemaDefinitionConverter.java
@@ -0,0 +1,62 @@
+/*
+ * ============LICENSE_START=======================================================
+ * Copyright (C) 2020 Nordix Foundation
+ * ================================================================================
+ * 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.
+ *
+ * SPDX-License-Identifier: Apache-2.0
+ * ============LICENSE_END=========================================================
+ */
+
+package org.openecomp.sdc.be.model.converter;
+
+import static org.openecomp.sdc.be.datatypes.enums.JsonPresentationFields.PROPERTY;
+
+import java.util.Map;
+import java.util.Optional;
+import org.openecomp.sdc.be.datatypes.elements.SchemaDefinition;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.stereotype.Component;
+
+/**
+ * Converter to create {@link SchemaDefinition} instances from other data sources.
+ */
+@Component("schemaDefinitionConverter")
+public class SchemaDefinitionConverter {
+
+ private PropertyDataConverter propertyDataConverter;
+
+ /**
+ * Parses a json object as map to a {@link SchemaDefinition} instance.
+ *
+ * @param schemaJsonAsMapObj the json map representing the {@link SchemaDefinition}
+ * @return an instance of {@link SchemaDefinition}
+ */
+ public Optional<SchemaDefinition> parseTo(final Object schemaJsonAsMapObj) {
+ if (schemaJsonAsMapObj instanceof Map) {
+ final Map<String, Object> schemaMap = (Map<String, Object>) schemaJsonAsMapObj;
+ final Object schemaPropertyObj = schemaMap.get(PROPERTY.getPresentation());
+ if (schemaPropertyObj instanceof Map) {
+ final SchemaDefinition schema = new SchemaDefinition();
+ schema.setProperty(propertyDataConverter.createPropertyData((Map<String, Object>) schemaPropertyObj));
+ return Optional.of(schema);
+ }
+ }
+ return Optional.empty();
+ }
+
+ //circular dependency
+ @Autowired
+ public void setPropertyDataConverter(final PropertyDataConverter propertyDataConverter) {
+ this.propertyDataConverter = propertyDataConverter;
+ }
+}
diff --git a/catalog-model/src/main/java/org/openecomp/sdc/be/model/jsonjanusgraph/operations/NodeTypeOperation.java b/catalog-model/src/main/java/org/openecomp/sdc/be/model/jsonjanusgraph/operations/NodeTypeOperation.java
index 004451c..fb149c1 100644
--- a/catalog-model/src/main/java/org/openecomp/sdc/be/model/jsonjanusgraph/operations/NodeTypeOperation.java
+++ b/catalog-model/src/main/java/org/openecomp/sdc/be/model/jsonjanusgraph/operations/NodeTypeOperation.java
@@ -21,6 +21,17 @@
package org.openecomp.sdc.be.model.jsonjanusgraph.operations;
import fj.data.Either;
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.EnumSet;
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.LinkedHashMap;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+import java.util.regex.Pattern;
+import java.util.stream.Collectors;
import org.apache.tinkerpop.gremlin.structure.Direction;
import org.apache.tinkerpop.gremlin.structure.Edge;
import org.openecomp.sdc.be.dao.janusgraph.JanusGraphOperationStatus;
@@ -28,7 +39,13 @@
import org.openecomp.sdc.be.dao.jsongraph.types.EdgeLabelEnum;
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.*;
+import org.openecomp.sdc.be.datatypes.elements.AdditionalInfoParameterDataDefinition;
+import org.openecomp.sdc.be.datatypes.elements.AttributeDataDefinition;
+import org.openecomp.sdc.be.datatypes.elements.InterfaceDataDefinition;
+import org.openecomp.sdc.be.datatypes.elements.ListCapabilityDataDefinition;
+import org.openecomp.sdc.be.datatypes.elements.ListRequirementDataDefinition;
+import org.openecomp.sdc.be.datatypes.elements.MapPropertiesDataDefinition;
+import org.openecomp.sdc.be.datatypes.elements.PropertyDataDefinition;
import org.openecomp.sdc.be.datatypes.enums.GraphPropertyEnum;
import org.openecomp.sdc.be.datatypes.enums.JsonPresentationFields;
import org.openecomp.sdc.be.datatypes.tosca.ToscaDataDefinition;
@@ -46,10 +63,6 @@
import org.openecomp.sdc.common.log.wrappers.Logger;
import org.springframework.beans.factory.annotation.Qualifier;
-import java.util.*;
-import java.util.regex.Pattern;
-import java.util.stream.Collectors;
-
@org.springframework.stereotype.Component("node-type-operation")
public class NodeTypeOperation extends ToscaElementOperation {
public static final Pattern uuidNewVersion = Pattern.compile("^\\d+.1");
@@ -68,7 +81,7 @@
nodeType.generateUUID();
- nodeType = getResourceMetaDataFromResource(nodeType);
+ setResourceMetaDataFromResource(nodeType);
String resourceUniqueId = nodeType.getUniqueId();
if (resourceUniqueId == null) {
resourceUniqueId = UniqueIdBuilder.buildResourceUniqueId();
diff --git a/catalog-model/src/main/java/org/openecomp/sdc/be/model/jsonjanusgraph/operations/TopologyTemplateOperation.java b/catalog-model/src/main/java/org/openecomp/sdc/be/model/jsonjanusgraph/operations/TopologyTemplateOperation.java
index 703466c..7bc9e4a 100644
--- a/catalog-model/src/main/java/org/openecomp/sdc/be/model/jsonjanusgraph/operations/TopologyTemplateOperation.java
+++ b/catalog-model/src/main/java/org/openecomp/sdc/be/model/jsonjanusgraph/operations/TopologyTemplateOperation.java
@@ -103,8 +103,7 @@
public Either<TopologyTemplate, StorageOperationStatus> createTopologyTemplate(TopologyTemplate topologyTemplate) {
topologyTemplate.generateUUID();
-
- topologyTemplate = getResourceMetaDataFromResource(topologyTemplate);
+ setResourceMetaDataFromResource(topologyTemplate);
String resourceUniqueId = topologyTemplate.getUniqueId();
if (resourceUniqueId == null) {
resourceUniqueId = UniqueIdBuilder.buildResourceUniqueId();
@@ -112,7 +111,7 @@
}
GraphVertex topologyTemplateVertex = new GraphVertex();
- topologyTemplateVertex = fillMetadata(topologyTemplateVertex, topologyTemplate, JsonParseFlagEnum.ParseAll);
+ fillMetadata(topologyTemplateVertex, topologyTemplate, JsonParseFlagEnum.ParseAll);
Either<GraphVertex, JanusGraphOperationStatus> createdVertex = janusGraphDao.createVertex(topologyTemplateVertex);
if (createdVertex.isRight()) {
@@ -597,17 +596,22 @@
return StorageOperationStatus.OK;
}
- private GraphVertex fillMetadata(GraphVertex nodeTypeVertex, TopologyTemplate topologyTemplate, JsonParseFlagEnum flag) {
+ private void fillMetadata(GraphVertex nodeTypeVertex, TopologyTemplate topologyTemplate, JsonParseFlagEnum flag) {
nodeTypeVertex.setLabel(VertexTypeEnum.TOPOLOGY_TEMPLATE);
fillCommonMetadata(nodeTypeVertex, topologyTemplate);
+ fillDataTypes(nodeTypeVertex, topologyTemplate);
if (flag == JsonParseFlagEnum.ParseAll || flag == JsonParseFlagEnum.ParseJson) {
nodeTypeVertex.setJson(topologyTemplate.getCompositions());
}
nodeTypeVertex.addMetadataProperty(GraphPropertyEnum.CSAR_UUID, topologyTemplate.getMetadataValue(JsonPresentationFields.CSAR_UUID));
nodeTypeVertex.addMetadataProperty(GraphPropertyEnum.DISTRIBUTION_STATUS, topologyTemplate.getMetadataValue(JsonPresentationFields.DISTRIBUTION_STATUS));
+ }
- return nodeTypeVertex;
-
+ private void fillDataTypes(final GraphVertex nodeTypeVertex, final TopologyTemplate topologyTemplate) {
+ if (MapUtils.isEmpty(topologyTemplate.getDataTypes())) {
+ return;
+ }
+ nodeTypeVertex.setJsonMetadataField(JsonPresentationFields.DATA_TYPES, topologyTemplate.getDataTypes());
}
private StorageOperationStatus assosiateMetadataToCategory(GraphVertex nodeTypeVertex, TopologyTemplate topologyTemplate) {
diff --git a/catalog-model/src/main/java/org/openecomp/sdc/be/model/jsonjanusgraph/operations/ToscaElementOperation.java b/catalog-model/src/main/java/org/openecomp/sdc/be/model/jsonjanusgraph/operations/ToscaElementOperation.java
index 6798af4..18bd0ec 100644
--- a/catalog-model/src/main/java/org/openecomp/sdc/be/model/jsonjanusgraph/operations/ToscaElementOperation.java
+++ b/catalog-model/src/main/java/org/openecomp/sdc/be/model/jsonjanusgraph/operations/ToscaElementOperation.java
@@ -22,9 +22,21 @@
import static org.openecomp.sdc.be.utils.TypeUtils.setField;
+import com.google.gson.Gson;
+import com.google.gson.reflect.TypeToken;
+import fj.data.Either;
import java.lang.reflect.Type;
-import java.util.*;
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.EnumMap;
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Map;
import java.util.Map.Entry;
+import java.util.Optional;
+import java.util.Set;
import java.util.stream.Collectors;
import org.apache.commons.collections4.CollectionUtils;
import org.apache.commons.collections4.MapUtils;
@@ -59,6 +71,7 @@
import org.openecomp.sdc.be.model.catalog.CatalogComponent;
import org.openecomp.sdc.be.model.category.CategoryDefinition;
import org.openecomp.sdc.be.model.category.SubCategoryDefinition;
+import org.openecomp.sdc.be.model.converter.PropertyDataConverter;
import org.openecomp.sdc.be.model.jsonjanusgraph.datamodel.NodeType;
import org.openecomp.sdc.be.model.jsonjanusgraph.datamodel.TopologyTemplate;
import org.openecomp.sdc.be.model.jsonjanusgraph.datamodel.ToscaElement;
@@ -75,11 +88,6 @@
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.util.StopWatch;
-import com.google.gson.Gson;
-import com.google.gson.reflect.TypeToken;
-
-import fj.data.Either;
-
public abstract class ToscaElementOperation extends BaseOperation {
private static final String FAILED_TO_FETCH_FOR_TOSCA_ELEMENT_WITH_ID_ERROR = "failed to fetch {} for tosca element with id {}, error {}";
@@ -95,6 +103,7 @@
@Autowired
protected CategoryOperation categoryOperation;
+ protected PropertyDataConverter propertyDataConverter;
protected Gson getGson() {
return gson;
@@ -283,7 +292,7 @@
return JanusGraphOperationStatus.OK;
}
- protected <T extends ToscaElement> T getResourceMetaDataFromResource(T toscaElement) {
+ protected <T extends ToscaElement> void setResourceMetaDataFromResource(T toscaElement) {
if (toscaElement.getNormalizedName() == null || toscaElement.getNormalizedName().isEmpty()) {
toscaElement.setNormalizedName(ValidationUtils.normaliseComponentName(toscaElement.getName()));
}
@@ -291,7 +300,7 @@
toscaElement.setSystemName(ValidationUtils.convertToSystemName(toscaElement.getName()));
}
- LifecycleStateEnum lifecycleStateEnum = toscaElement.getLifecycleState();
+ final LifecycleStateEnum lifecycleStateEnum = toscaElement.getLifecycleState();
if (lifecycleStateEnum == null) {
toscaElement.setLifecycleState(LifecycleStateEnum.NOT_CERTIFIED_CHECKOUT);
}
@@ -300,8 +309,6 @@
toscaElement.setCreationDate(currentDate);
}
toscaElement.setLastUpdateDate(currentDate);
-
- return toscaElement;
}
protected void fillCommonMetadata(GraphVertex nodeTypeVertex, ToscaElement toscaElement) {
@@ -917,79 +924,93 @@
}
@SuppressWarnings("unchecked")
- protected <T extends ToscaElement> T convertToComponent(GraphVertex componentV) {
- ToscaElement toscaElement = null;
- VertexTypeEnum label = componentV.getLabel();
+ protected <T extends ToscaElement> T convertToComponent(final GraphVertex componentV) {
+ final ToscaElement toscaElement;
+ final VertexTypeEnum label = componentV.getLabel();
switch (label) {
case NODE_TYPE:
toscaElement = new NodeType();
((NodeType) toscaElement).setAttributes(getAttributesFromComponentV(componentV));
break;
case TOPOLOGY_TEMPLATE:
- toscaElement = new TopologyTemplate();
+ toscaElement = handleTopologyTemplate(componentV);
break;
default:
- log.debug("Not supported tosca type {}", label);
- break;
+ log.debug("Not supported tosca type '{}'", label);
+ return null;
}
- if (toscaElement != null) {
- final Map<String, Object> jsonMetada = componentV.getMetadataJson();
- if (MapUtils.isNotEmpty(jsonMetada)) {
- toscaElement.setMetadata(jsonMetada);
- final Object toscaVersion = jsonMetada.get(ToscaTagNamesEnum.TOSCA_VERSION.getElementName());
- if (toscaVersion != null) {
- toscaElement.setToscaVersion((String) toscaVersion);
- }
- final Object dataTypes = jsonMetada.get(ToscaTagNamesEnum.DATA_TYPES.getElementName());
- if (dataTypes != null) {
- final Map<String, DataTypeDataDefinition> dataTypeDefinitionMap = new HashMap<>();
-
- final Map<String, Object> toscaAttributes = (Map<String, Object>) dataTypes;
-
- for (final Entry<String, Object> attributeNameValue : toscaAttributes.entrySet()) {
- final Object value = attributeNameValue.getValue();
- final String key = attributeNameValue.getKey();
- if (value instanceof Map) {
- final DataTypeDefinition dataTypeDefinition =
- createDataTypeDefinitionWithName(attributeNameValue);
- dataTypeDefinitionMap.put(dataTypeDefinition.getName(), dataTypeDefinition);
- } else {
- dataTypeDefinitionMap.put(key, createDataType(String.valueOf(value)));
- }
- }
- toscaElement.setDataTypes(dataTypeDefinitionMap);
- }
+ final Map<String, Object> jsonMetadata = componentV.getMetadataJson();
+ toscaElement.setMetadata(jsonMetadata);
+ if (jsonMetadata != null) {
+ final Object toscaVersion = jsonMetadata.get(ToscaTagNamesEnum.TOSCA_VERSION.getElementName());
+ if (toscaVersion != null) {
+ toscaElement.setToscaVersion((String) toscaVersion);
}
}
return (T) toscaElement;
}
- public static DataTypeDefinition createDataType(final String dataTypeName) {
+ private TopologyTemplate handleTopologyTemplate(final GraphVertex componentVertex) {
+ final TopologyTemplate topologyTemplate = new TopologyTemplate();
+ handleDataTypes(topologyTemplate, componentVertex);
+ return topologyTemplate;
+ }
+
+ private void handleDataTypes(final TopologyTemplate topologyTemplate, final GraphVertex componentVertex) {
+ final Object dataTypeEntryObj = componentVertex.getJsonMetadataField(JsonPresentationFields.DATA_TYPES);
+ if (dataTypeEntryObj == null) {
+ return;
+ }
+ if (!(dataTypeEntryObj instanceof Map)) {
+ log.error("Invalid '{}' metadata type. Expected {}.",
+ JsonPresentationFields.DATA_TYPES.getPresentation(), Map.class);
+ return;
+ }
+ @SuppressWarnings("unchecked")
+ final Map<String, Object> dataTypeMap = (Map<String, Object>) dataTypeEntryObj;
+ if (MapUtils.isEmpty(dataTypeMap)) {
+ return;
+ }
+
+ final Map<String, DataTypeDataDefinition> dataTypeDefinitionMap = new HashMap<>();
+ for (final Entry<String, Object> dataTypeEntry : dataTypeMap.entrySet()) {
+ final String dataTypeName = dataTypeEntry.getKey();
+ final Object dataTypeObj = dataTypeEntry.getValue();
+ if (dataTypeObj instanceof Map) {
+ final DataTypeDefinition dataTypeDefinition = createDataTypeDefinitionFromJson(dataTypeEntry);
+ dataTypeDefinitionMap.put(dataTypeDefinition.getName(), dataTypeDefinition);
+ } else {
+ final DataTypeDefinition dataType = new DataTypeDefinition();
+ dataType.setName(String.valueOf(dataType));
+ dataTypeDefinitionMap.put(dataTypeName, dataType);
+ }
+ }
+ topologyTemplate.setDataTypes(dataTypeDefinitionMap);
+ }
+
+ public DataTypeDefinition createDataType(final String dataTypeName) {
final DataTypeDefinition dataType = new DataTypeDefinition();
dataType.setName(dataTypeName);
return dataType;
}
- public static DataTypeDefinition createDataTypeDefinitionWithName(final Entry<String, Object> attributeNameValue) {
- final Map<String, Object> attributeMap = (Map<String, Object>) attributeNameValue.getValue();
- final DataTypeDefinition dataType = createDataType(attributeNameValue.getKey());
+ public DataTypeDefinition createDataTypeDefinitionFromJson(final Entry<String, Object> dataTypeMap) {
+ final DataTypeDefinition dataType = new DataTypeDefinition();
+ dataType.setName(dataTypeMap.getKey());
+ final Map<String, Object> attributeMap = (Map<String, Object>) dataTypeMap.getValue();
setField(attributeMap, TypeUtils.ToscaTagNamesEnum.DESCRIPTION, dataType::setDescription);
setField(attributeMap, TypeUtils.ToscaTagNamesEnum.DERIVED_FROM_NAME, dataType::setDerivedFromName);
- // TODO - find the way to set the properties
-// CommonImportManager.setProperties(attributeMap, dataType::setProperties);
+ final List<PropertyDataDefinition> propertyDataDefinitionList = handlePropertiesDataFromJson(attributeMap);
+ dataType.setPropertiesData(propertyDataDefinitionList);
final Object derivedFrom = attributeMap.get(JsonPresentationFields.DERIVED_FROM.getPresentation());
- if (derivedFrom instanceof Map) {
+ if (derivedFrom instanceof Map){
final Map<String, Object> derivedFromMap = (Map<String, Object>) derivedFrom;
final DataTypeDefinition parentDataTypeDataDefinition = new DataTypeDefinition();
- parentDataTypeDataDefinition
- .setName((String) derivedFromMap.get(JsonPresentationFields.NAME.getPresentation()));
- parentDataTypeDataDefinition
- .setUniqueId((String) derivedFromMap.get(JsonPresentationFields.UNIQUE_ID.getPresentation()));
- parentDataTypeDataDefinition
- .setCreationTime((Long) derivedFromMap.get(JsonPresentationFields.CREATION_TIME.getPresentation()));
- parentDataTypeDataDefinition.setModificationTime(
- (Long) derivedFromMap.get(JsonPresentationFields.MODIFICATION_TIME.getPresentation()));
+ parentDataTypeDataDefinition.setName((String) derivedFromMap.get(JsonPresentationFields.NAME.getPresentation()));
+ parentDataTypeDataDefinition.setUniqueId((String) derivedFromMap.get(JsonPresentationFields.UNIQUE_ID.getPresentation()));
+ parentDataTypeDataDefinition.setCreationTime((Long) derivedFromMap.get(JsonPresentationFields.CREATION_TIME.getPresentation()));
+ parentDataTypeDataDefinition.setModificationTime((Long) derivedFromMap.get(JsonPresentationFields.MODIFICATION_TIME.getPresentation()));
dataType.setDerivedFrom(parentDataTypeDataDefinition);
}
return dataType;
@@ -1017,6 +1038,17 @@
return attributeDataDefinitionMap;
}
+ protected List<PropertyDataDefinition> handlePropertiesDataFromJson(final Map<String, Object> attributeMap) {
+ final Object propertiesDataObj = attributeMap.get("propertiesData");
+ if (!(propertiesDataObj instanceof List)) {
+ return Collections.emptyList();
+ }
+ @SuppressWarnings("unchecked")
+ final List<Map<String, Object>> propertiesDataList = (List<Map<String, Object>>) propertiesDataObj;
+ return propertyDataConverter.parseProperties(propertiesDataList);
+ }
+
+
protected JanusGraphOperationStatus setResourceCategoryFromGraphV(Vertex vertex, CatalogComponent catalogComponent) {
List<CategoryDefinition> categories = new ArrayList<>();
SubCategoryDefinition subcategory;
@@ -1538,4 +1570,8 @@
public abstract <T extends ToscaElement> void fillToscaElementVertexData(GraphVertex elementV, T
toscaElementToUpdate, JsonParseFlagEnum flag);
+ @Autowired
+ public void setPropertyDataConverter(final PropertyDataConverter propertyDataConverter) {
+ this.propertyDataConverter = propertyDataConverter;
+ }
}
diff --git a/catalog-model/src/main/java/org/openecomp/sdc/be/model/jsonjanusgraph/utils/ModelConverter.java b/catalog-model/src/main/java/org/openecomp/sdc/be/model/jsonjanusgraph/utils/ModelConverter.java
index 5031d37..b0051f6 100644
--- a/catalog-model/src/main/java/org/openecomp/sdc/be/model/jsonjanusgraph/utils/ModelConverter.java
+++ b/catalog-model/src/main/java/org/openecomp/sdc/be/model/jsonjanusgraph/utils/ModelConverter.java
@@ -1169,11 +1169,44 @@
convertPolicies(component, topologyTemplate);
convertRequirements(component, topologyTemplate);
convertRelationsToComposition(component, topologyTemplate);
+ convertDataTypes(component, topologyTemplate);
return topologyTemplate;
}
- private static void convertTopologyTemplateInterfaces(Resource resource, TopologyTemplate topologyTemplate) {
+ private static void convertDataTypes(final Component component, final TopologyTemplate topologyTemplate) {
+ final List<DataTypeDefinition> dataTypeDefinitionList = component.getDataTypes();
+ if (CollectionUtils.isEmpty(dataTypeDefinitionList)) {
+ return;
+ }
+ final Map<String, DataTypeDataDefinition> dataTypeMap = dataTypeDefinitionList.stream()
+ .collect(
+ Collectors.toMap(DataTypeDataDefinition::getName,
+ ModelConverter::parseTo,
+ (dataTypeDataDefinition, dataTypeDataDefinition2) -> dataTypeDataDefinition)
+ );
+ topologyTemplate.setDataTypes(dataTypeMap);
+ }
+
+ private static DataTypeDataDefinition parseTo(final DataTypeDefinition dataTypeDefinition) {
+ final DataTypeDataDefinition dataTypeDataDefinition = new DataTypeDataDefinition(dataTypeDefinition);
+ final List<PropertyDataDefinition> propertyDataList = new ArrayList<>();
+ DataTypeDefinition currentDataType = dataTypeDefinition;
+
+ do {
+ if (CollectionUtils.isNotEmpty(currentDataType.getProperties())) {
+ propertyDataList.addAll(currentDataType.getProperties().stream()
+ .map(PropertyDataDefinition::new)
+ .collect(Collectors.toList()));
+ }
+ currentDataType = currentDataType.getDerivedFrom();
+ } while (currentDataType != null);
+
+ dataTypeDataDefinition.setPropertiesData(propertyDataList);
+ return dataTypeDataDefinition;
+ }
+
+ private static void convertTopologyTemplateInterfaces(Resource resource, TopologyTemplate topologyTemplate) {
Map<String, InterfaceDefinition> interfaces = resource.getInterfaces();
if (interfaces != null && !interfaces.isEmpty()) {
Map<String, InterfaceDataDefinition> copy = interfaces.entrySet().stream()
diff --git a/catalog-model/src/main/java/org/openecomp/sdc/be/model/operations/impl/PropertyOperation.java b/catalog-model/src/main/java/org/openecomp/sdc/be/model/operations/impl/PropertyOperation.java
index 2eeb55c..c5555ef 100644
--- a/catalog-model/src/main/java/org/openecomp/sdc/be/model/operations/impl/PropertyOperation.java
+++ b/catalog-model/src/main/java/org/openecomp/sdc/be/model/operations/impl/PropertyOperation.java
@@ -33,9 +33,6 @@
import com.google.gson.JsonParser;
import com.google.gson.JsonSerializationContext;
import com.google.gson.JsonSerializer;
-import org.janusgraph.core.JanusGraph;
-import org.janusgraph.core.JanusGraphVertex;
-import org.janusgraph.core.JanusGraphVertexProperty;
import fj.data.Either;
import java.io.IOException;
import java.lang.reflect.Type;
@@ -46,6 +43,7 @@
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
+import java.util.Optional;
import java.util.Set;
import java.util.StringJoiner;
import java.util.function.Consumer;
@@ -59,6 +57,9 @@
import org.apache.tinkerpop.gremlin.structure.Edge;
import org.apache.tinkerpop.gremlin.structure.Vertex;
import org.apache.tinkerpop.gremlin.structure.VertexProperty;
+import org.janusgraph.core.JanusGraph;
+import org.janusgraph.core.JanusGraphVertex;
+import org.janusgraph.core.JanusGraphVertexProperty;
import org.openecomp.sdc.be.config.BeEcompErrorManager;
import org.openecomp.sdc.be.config.BeEcompErrorManager.ErrorSeverity;
import org.openecomp.sdc.be.dao.graph.GraphElementFactory;
@@ -66,11 +67,11 @@
import org.openecomp.sdc.be.dao.graph.datatype.GraphElementTypeEnum;
import org.openecomp.sdc.be.dao.graph.datatype.GraphNode;
import org.openecomp.sdc.be.dao.graph.datatype.GraphRelation;
+import org.openecomp.sdc.be.dao.janusgraph.HealingJanusGraphGenericDao;
import org.openecomp.sdc.be.dao.janusgraph.JanusGraphGenericDao;
import org.openecomp.sdc.be.dao.janusgraph.JanusGraphOperationStatus;
import org.openecomp.sdc.be.dao.neo4j.GraphEdgeLabels;
import org.openecomp.sdc.be.dao.neo4j.GraphPropertiesDictionary;
-import org.openecomp.sdc.be.dao.janusgraph.HealingJanusGraphGenericDao;
import org.openecomp.sdc.be.datatypes.elements.PropertyDataDefinition;
import org.openecomp.sdc.be.datatypes.elements.PropertyRule;
import org.openecomp.sdc.be.datatypes.elements.SchemaDefinition;
@@ -80,6 +81,7 @@
import org.openecomp.sdc.be.model.IComplexDefaultValue;
import org.openecomp.sdc.be.model.PropertyConstraint;
import org.openecomp.sdc.be.model.PropertyDefinition;
+import org.openecomp.sdc.be.model.operations.StorageException;
import org.openecomp.sdc.be.model.operations.api.DerivedFromOperation;
import org.openecomp.sdc.be.model.operations.api.IPropertyOperation;
import org.openecomp.sdc.be.model.operations.api.StorageOperationStatus;
@@ -1120,25 +1122,36 @@
return isValid;
}
- public boolean isPropertyTypeValid(IComplexDefaultValue property) {
+ public boolean isPropertyTypeValid(final IComplexDefaultValue property) {
+ return isPropertyTypeValid(property, null);
+ }
- if (property == null) {
+ public boolean isPropertyTypeValid(final IComplexDefaultValue property,
+ final Collection<DataTypeDefinition> componentDataTypeCollection) {
+ if (property == null || property.getType() == null) {
return false;
}
- if (ToscaPropertyType.isValidType(property.getType()) == null) {
-
- Either<Boolean, JanusGraphOperationStatus> definedInDataTypes = isDefinedInDataTypes(property.getType());
-
- if (definedInDataTypes.isRight()) {
- return false;
- } else {
- Boolean isExist = definedInDataTypes.left().value();
- return isExist.booleanValue();
- }
-
+ final ToscaPropertyType toscaPropertyType = ToscaPropertyType.isValidType(property.getType());
+ if (toscaPropertyType != null) {
+ return true;
}
- return true;
+
+ if (CollectionUtils.isNotEmpty(componentDataTypeCollection)) {
+ final boolean matches = componentDataTypeCollection.stream()
+ .anyMatch(dataTypeDefinition -> dataTypeDefinition.getName().equals(property.getType()));
+ if (matches) {
+ return true;
+ }
+ }
+
+ final Either<Boolean, JanusGraphOperationStatus> definedInDataTypes = isDefinedInDataTypes(property.getType());
+
+ if (definedInDataTypes.isLeft()) {
+ return definedInDataTypes.left().value();
+ }
+
+ return false;
}
@Override
@@ -1502,9 +1515,10 @@
return Either.right(operationStatus);
}
- DataTypeData resultCTD = createDataTypeResult.left().value();
- List<PropertyDefinition> properties = dataTypeDefinition.getProperties();
- Either<Map<String, PropertyData>, JanusGraphOperationStatus> addPropertiesToDataType = addPropertiesToDataType(resultCTD.getUniqueId(), properties);
+ final DataTypeData createdDataType = createDataTypeResult.left().value();
+ final List<PropertyDefinition> properties = dataTypeDefinition.getProperties();
+ final Either<Map<String, PropertyData>, JanusGraphOperationStatus> addPropertiesToDataType =
+ addPropertiesToDataType(createdDataType.getUniqueId(), properties);
if (addPropertiesToDataType.isRight()) {
log.debug("Failed add properties {} to data type {}", properties, dataTypeDefinition.getName());
return Either.right(addPropertiesToDataType.right().value());
@@ -1525,7 +1539,7 @@
}
}
- return Either.left(createDataTypeResult.left().value());
+ return Either.left(createdDataType);
}
@@ -2012,9 +2026,17 @@
return result;
}
- private Either<DataTypeDefinition, JanusGraphOperationStatus> getDataTypeUsingName(String name) {
- String uid = UniqueIdBuilder.buildDataTypeUid(name);
- return getDataTypeByUid(uid);
+ public Optional<DataTypeDefinition> findDataTypeByName(final String name) {
+ final String uid = UniqueIdBuilder.buildDataTypeUid(name);
+ final Either<DataTypeDefinition, JanusGraphOperationStatus> operationResult = getDataTypeByUid(uid);
+ if (operationResult.isRight()) {
+ final JanusGraphOperationStatus janusGraphOperationStatus = operationResult.right().value();
+ if (janusGraphOperationStatus == JanusGraphOperationStatus.NOT_FOUND) {
+ return Optional.empty();
+ }
+ throw new StorageException(janusGraphOperationStatus);
+ }
+ return Optional.of(operationResult.left().value());
}
public Either<String, JanusGraphOperationStatus> checkInnerType(PropertyDataDefinition propDataDef) {
diff --git a/catalog-model/src/test/java/org/openecomp/sdc/be/model/converter/PropertyDataConverterTest.java b/catalog-model/src/test/java/org/openecomp/sdc/be/model/converter/PropertyDataConverterTest.java
new file mode 100644
index 0000000..e4bdac8
--- /dev/null
+++ b/catalog-model/src/test/java/org/openecomp/sdc/be/model/converter/PropertyDataConverterTest.java
@@ -0,0 +1,244 @@
+/*
+ * ============LICENSE_START=======================================================
+ * Copyright (C) 2020 Nordix Foundation
+ * ================================================================================
+ * 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.
+ *
+ * SPDX-License-Identifier: Apache-2.0
+ * ============LICENSE_END=========================================================
+ */
+
+package org.openecomp.sdc.be.model.converter;
+
+import static org.hamcrest.MatcherAssert.assertThat;
+import static org.hamcrest.Matchers.containsInAnyOrder;
+import static org.hamcrest.Matchers.empty;
+import static org.hamcrest.Matchers.is;
+import static org.hamcrest.Matchers.notNullValue;
+import static org.hamcrest.Matchers.nullValue;
+import static org.mockito.Mockito.when;
+import static org.openecomp.sdc.be.datatypes.enums.JsonPresentationFields.DEFAULT_VALUE;
+import static org.openecomp.sdc.be.datatypes.enums.JsonPresentationFields.DEFINITION;
+import static org.openecomp.sdc.be.datatypes.enums.JsonPresentationFields.DESCRIPTION;
+import static org.openecomp.sdc.be.datatypes.enums.JsonPresentationFields.HIDDEN;
+import static org.openecomp.sdc.be.datatypes.enums.JsonPresentationFields.IMMUTABLE;
+import static org.openecomp.sdc.be.datatypes.enums.JsonPresentationFields.INPUT_ID;
+import static org.openecomp.sdc.be.datatypes.enums.JsonPresentationFields.INPUT_PATH;
+import static org.openecomp.sdc.be.datatypes.enums.JsonPresentationFields.INSTANCE_UNIQUE_ID;
+import static org.openecomp.sdc.be.datatypes.enums.JsonPresentationFields.LABEL;
+import static org.openecomp.sdc.be.datatypes.enums.JsonPresentationFields.NAME;
+import static org.openecomp.sdc.be.datatypes.enums.JsonPresentationFields.PARENT_PROPERTY_TYPE;
+import static org.openecomp.sdc.be.datatypes.enums.JsonPresentationFields.PASSWORD;
+import static org.openecomp.sdc.be.datatypes.enums.JsonPresentationFields.PROPERTY;
+import static org.openecomp.sdc.be.datatypes.enums.JsonPresentationFields.PROPERTY_CONSTRAINTS;
+import static org.openecomp.sdc.be.datatypes.enums.JsonPresentationFields.PROPERTY_ID;
+import static org.openecomp.sdc.be.datatypes.enums.JsonPresentationFields.REQUIRED;
+import static org.openecomp.sdc.be.datatypes.enums.JsonPresentationFields.SCHEMA;
+import static org.openecomp.sdc.be.datatypes.enums.JsonPresentationFields.STATUS;
+import static org.openecomp.sdc.be.datatypes.enums.JsonPresentationFields.SUB_PROPERTY_INPUT_PATH;
+import static org.openecomp.sdc.be.datatypes.enums.JsonPresentationFields.TYPE;
+import static org.openecomp.sdc.be.datatypes.enums.JsonPresentationFields.UNIQUE_ID;
+import static org.openecomp.sdc.be.datatypes.enums.JsonPresentationFields.VALUE;
+
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+import java.util.Optional;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Test;
+import org.mockito.Mock;
+import org.mockito.MockitoAnnotations;
+import org.openecomp.sdc.be.datatypes.elements.PropertyDataDefinition;
+import org.openecomp.sdc.be.datatypes.elements.SchemaDefinition;
+
+class PropertyDataConverterTest {
+
+ private PropertyDataConverter propertyDataConverter;
+ @Mock
+ private SchemaDefinitionConverter schemaDefinitionConverter;
+
+ @BeforeEach
+ void setUp() {
+ MockitoAnnotations.initMocks(this);
+ propertyDataConverter = new PropertyDataConverter();
+ propertyDataConverter.setSchemaDefinitionConverter(schemaDefinitionConverter);
+ }
+
+ @Test
+ void parsePropertiesSuccessTest() {
+ final List<Map<String, Object>> propertyDataList = new ArrayList<>();
+ final HashMap<String, Object> propertyJsonMap1 = new HashMap<>();
+ propertyJsonMap1.put("type", "string");
+ propertyDataList.add(propertyJsonMap1);
+ final HashMap<String, Object> propertyJsonMap2 = new HashMap<>();
+ propertyJsonMap2.put("type", "boolean");
+ propertyDataList.add(propertyJsonMap2);
+ final HashMap<String, Object> propertyJsonMap3 = new HashMap<>();
+ propertyJsonMap3.put("type", "a.tosca.type");
+ propertyDataList.add(propertyJsonMap3);
+ final List<PropertyDataDefinition> actualPropertyDataList = propertyDataConverter
+ .parseProperties(propertyDataList);
+ assertThat(actualPropertyDataList, is(notNullValue()));
+ assertThat(actualPropertyDataList.size(), is(propertyDataList.size()));
+ }
+
+ @Test
+ void parseEmptyPropertiesListTest() {
+ List<PropertyDataDefinition> propertyDataDefinitions =
+ propertyDataConverter.parseProperties(null);
+ assertThat("Should not be null", propertyDataDefinitions, is(notNullValue()));
+ assertThat("Should be empty", propertyDataDefinitions, is(empty()));
+ propertyDataDefinitions =
+ propertyDataConverter.parseProperties(Collections.emptyList());
+ assertThat("Should not be null", propertyDataDefinitions, is(notNullValue()));
+ assertThat("Should be empty", propertyDataDefinitions, is(empty()));
+ }
+
+ @Test
+ void createPropertyDataSuccessTest() {
+ final Map<String, Object> propertyJsonMap = new HashMap<>();
+ final PropertyDataDefinition expectedPropertyData = new PropertyDataDefinition();
+
+ final String uniqueId = "uniqueId";
+ expectedPropertyData.setUniqueId(uniqueId);
+ propertyJsonMap.put(UNIQUE_ID.getPresentation(), uniqueId);
+
+ final String type = "type";
+ expectedPropertyData.setType(type);
+ propertyJsonMap.put(TYPE.getPresentation(), type);
+
+ final Boolean required = Boolean.FALSE;
+ expectedPropertyData.setRequired(required);
+ propertyJsonMap.put(REQUIRED.getPresentation(), required);
+
+ final String name = "name";
+ expectedPropertyData.setName(name);
+ propertyJsonMap.put(NAME.getPresentation(), name);
+
+ final String label = "label";
+ expectedPropertyData.setLabel(label);
+ propertyJsonMap.put(LABEL.getPresentation(), label);
+
+ final String value = "value";
+ expectedPropertyData.setValue(value);
+ propertyJsonMap.put(VALUE.getPresentation(), value);
+
+ final Boolean hidden = Boolean.FALSE;
+ expectedPropertyData.setHidden(hidden);
+ propertyJsonMap.put(HIDDEN.getPresentation(), hidden);
+
+ final Boolean immutable = Boolean.TRUE;
+ expectedPropertyData.setImmutable(immutable);
+ propertyJsonMap.put(IMMUTABLE.getPresentation(), immutable);
+
+ final boolean password = false;
+ expectedPropertyData.setPassword(password);
+ propertyJsonMap.put(PASSWORD.getPresentation(), password);
+
+ final boolean definition = false;
+ expectedPropertyData.setDefinition(definition);
+ propertyJsonMap.put(DEFINITION.getPresentation(), definition);
+
+ final String description = "description";
+ expectedPropertyData.setDescription(description);
+ propertyJsonMap.put(DESCRIPTION.getPresentation(), description);
+
+ final String defaultValue = "defaultValue";
+ expectedPropertyData.setDefaultValue(defaultValue);
+ propertyJsonMap.put(DEFAULT_VALUE.getPresentation(), defaultValue);
+
+ final String inputPath = "inputPath";
+ expectedPropertyData.setInputPath(inputPath);
+ propertyJsonMap.put(INPUT_PATH.getPresentation(), inputPath);
+
+ final String status = "status";
+ expectedPropertyData.setStatus(status);
+ propertyJsonMap.put(STATUS.getPresentation(), status);
+
+ final String inputId = "inputId";
+ expectedPropertyData.setInputId(inputId);
+ propertyJsonMap.put(INPUT_ID.getPresentation(), inputId);
+
+ final String instanceUniqueId = "instanceUniqueId";
+ expectedPropertyData.setInstanceUniqueId(instanceUniqueId);
+ propertyJsonMap.put(INSTANCE_UNIQUE_ID.getPresentation(), instanceUniqueId);
+
+ final String propertyId = "propertyId";
+ expectedPropertyData.setPropertyId(propertyId);
+ propertyJsonMap.put(PROPERTY_ID.getPresentation(), propertyId);
+
+ final String parentPropertyType = "parentPropertyType";
+ expectedPropertyData.setParentPropertyType(parentPropertyType);
+ propertyJsonMap.put(PARENT_PROPERTY_TYPE.getPresentation(), parentPropertyType);
+
+ final String subPropertyType = "subPropertyType";
+ expectedPropertyData.setSubPropertyInputPath(subPropertyType);
+ propertyJsonMap.put(SUB_PROPERTY_INPUT_PATH.getPresentation(), subPropertyType);
+
+ PropertyDataDefinition actualPropertyData = propertyDataConverter.createPropertyData(propertyJsonMap);
+ assertThat(actualPropertyData.getUniqueId(), is(expectedPropertyData.getUniqueId()));
+ assertThat(actualPropertyData.getRequired(), is(expectedPropertyData.getRequired()));
+ assertThat(actualPropertyData.getName(), is(expectedPropertyData.getName()));
+ assertThat(actualPropertyData.getLabel(), is(expectedPropertyData.getLabel()));
+ assertThat(actualPropertyData.getValue(), is(expectedPropertyData.getValue()));
+ assertThat(actualPropertyData.getHidden(), is(expectedPropertyData.getHidden()));
+ assertThat(actualPropertyData.getImmutable(), is(expectedPropertyData.getImmutable()));
+ assertThat(actualPropertyData.isPassword(), is(expectedPropertyData.isPassword()));
+ assertThat(actualPropertyData.getDefinition(), is(expectedPropertyData.getDefinition()));
+ assertThat(actualPropertyData.getDescription(), is(expectedPropertyData.getDescription()));
+ assertThat(actualPropertyData.getDefaultValue(), is(expectedPropertyData.getDefaultValue()));
+ assertThat(actualPropertyData.getInputPath(), is(expectedPropertyData.getInputPath()));
+ assertThat(actualPropertyData.getStatus(), is(expectedPropertyData.getStatus()));
+ assertThat(actualPropertyData.getInputId(), is(expectedPropertyData.getInputId()));
+ assertThat(actualPropertyData.getInstanceUniqueId(), is(expectedPropertyData.getInstanceUniqueId()));
+ assertThat(actualPropertyData.getPropertyId(), is(expectedPropertyData.getPropertyId()));
+ assertThat(actualPropertyData.getParentPropertyType(), is(expectedPropertyData.getParentPropertyType()));
+ assertThat(actualPropertyData.getSubPropertyInputPath(), is(expectedPropertyData.getSubPropertyInputPath()));
+ assertThat(actualPropertyData.getSchema(), is(nullValue()));
+ assertThat(actualPropertyData.getPropertyConstraints(), is(nullValue()));
+
+ //schema
+ final Map<String, Object> propertySchemaMap = new HashMap<>();
+ propertySchemaMap.put(TYPE.getPresentation(), "string");
+ final Map<String, Object> schemaMap = new HashMap<>();
+ schemaMap.put(PROPERTY.getPresentation(), propertySchemaMap);
+ propertyJsonMap.put(SCHEMA.getPresentation(), schemaMap);
+ final SchemaDefinition schemaDefinition = new SchemaDefinition();
+ final PropertyDataDefinition schemaPropertyData = new PropertyDataDefinition();
+ schemaPropertyData.setType("string");
+ schemaDefinition.setProperty(schemaPropertyData);
+ expectedPropertyData.setSchema(schemaDefinition);
+ when(schemaDefinitionConverter.parseTo(schemaMap)).thenReturn(Optional.of(schemaDefinition));
+ //constraints
+ final List<String> propertyConstraintList = new ArrayList<>();
+ propertyConstraintList.add("constraint1");
+ propertyConstraintList.add("constraint2");
+ expectedPropertyData.setPropertyConstraints(propertyConstraintList);
+ propertyJsonMap.put(PROPERTY_CONSTRAINTS.getPresentation(), propertyConstraintList);
+ actualPropertyData = propertyDataConverter.createPropertyData(propertyJsonMap);
+ assertThat(actualPropertyData.getSchema(), is(notNullValue()));
+ assertThat(actualPropertyData.getSchema().getType(), is(expectedPropertyData.getSchema().getType()));
+ assertThat(actualPropertyData.getPropertyConstraints(), is(notNullValue()));
+ assertThat(actualPropertyData.getPropertyConstraints().size(), is(expectedPropertyData.getPropertyConstraints().size()));
+ assertThat(actualPropertyData.getPropertyConstraints(), containsInAnyOrder(propertyConstraintList.toArray()));
+ }
+
+ @Test
+ void createEmptyPropertyDataTest() {
+ final Map<String, Object> propertyJsonMap = new HashMap<>();
+ final PropertyDataDefinition propertyData = propertyDataConverter.createPropertyData(propertyJsonMap);
+ final PropertyDataDefinition expectedPropertyData = new PropertyDataDefinition();
+ assertThat("Should be the equal", propertyData, is(expectedPropertyData));
+ }
+}
\ No newline at end of file
diff --git a/catalog-model/src/test/java/org/openecomp/sdc/be/model/converter/SchemaDefinitionConverterTest.java b/catalog-model/src/test/java/org/openecomp/sdc/be/model/converter/SchemaDefinitionConverterTest.java
new file mode 100644
index 0000000..420ced2
--- /dev/null
+++ b/catalog-model/src/test/java/org/openecomp/sdc/be/model/converter/SchemaDefinitionConverterTest.java
@@ -0,0 +1,79 @@
+/*
+ * ============LICENSE_START=======================================================
+ * Copyright (C) 2020 Nordix Foundation
+ * ================================================================================
+ * 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.
+ *
+ * SPDX-License-Identifier: Apache-2.0
+ * ============LICENSE_END=========================================================
+ */
+
+package org.openecomp.sdc.be.model.converter;
+
+import static org.hamcrest.MatcherAssert.assertThat;
+import static org.hamcrest.Matchers.is;
+import static org.hamcrest.Matchers.notNullValue;
+import static org.mockito.Mockito.when;
+import static org.openecomp.sdc.be.datatypes.enums.JsonPresentationFields.PROPERTY;
+import static org.openecomp.sdc.be.datatypes.enums.JsonPresentationFields.TYPE;
+
+import java.util.HashMap;
+import java.util.Map;
+import java.util.Optional;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Test;
+import org.mockito.Mock;
+import org.mockito.MockitoAnnotations;
+import org.openecomp.sdc.be.datatypes.elements.PropertyDataDefinition;
+import org.openecomp.sdc.be.datatypes.elements.SchemaDefinition;
+
+class SchemaDefinitionConverterTest {
+
+ private SchemaDefinitionConverter schemaDefinitionConverter;
+ @Mock
+ private PropertyDataConverter propertyDataConverter;
+
+ @BeforeEach
+ void setUp() {
+ MockitoAnnotations.initMocks(this);
+ schemaDefinitionConverter = new SchemaDefinitionConverter();
+ schemaDefinitionConverter.setPropertyDataConverter(propertyDataConverter);
+ }
+
+ @Test
+ void parseToSuccessTest() {
+ //given
+ final Map<String, Object> propertySchemaMap = new HashMap<>();
+ propertySchemaMap.put(TYPE.getPresentation(), "string");
+ final Map<String, Object> schemaMap = new HashMap<>();
+ schemaMap.put(PROPERTY.getPresentation(), propertySchemaMap);
+ final PropertyDataDefinition schemaPropertyData = new PropertyDataDefinition();
+ schemaPropertyData.setType("string");
+ //when
+ when(propertyDataConverter.createPropertyData(propertySchemaMap)).thenReturn(schemaPropertyData);
+ final SchemaDefinition actualSchemaDefinition = schemaDefinitionConverter.parseTo(schemaMap).orElse(null);
+ //then
+ assertThat(actualSchemaDefinition, is(notNullValue()));
+ assertThat(actualSchemaDefinition.getProperty(), is(notNullValue()));
+ assertThat(actualSchemaDefinition.getProperty().getType(), is(schemaPropertyData.getType()));
+ }
+
+ @Test
+ void parseToEmptyJsonMap() {
+ //given
+ final Map<String, Object> schemaMap = new HashMap<>();
+ //when
+ final Optional<SchemaDefinition> actualSchemaDefinition = schemaDefinitionConverter.parseTo(schemaMap);
+ //then
+ assertThat(actualSchemaDefinition.isPresent(), is(false));
+ }
+}
\ No newline at end of file
diff --git a/catalog-model/src/test/java/org/openecomp/sdc/be/model/operations/impl/PropertyOperationTest.java b/catalog-model/src/test/java/org/openecomp/sdc/be/model/operations/impl/PropertyOperationTest.java
index e3d69fd..9512d8a 100644
--- a/catalog-model/src/test/java/org/openecomp/sdc/be/model/operations/impl/PropertyOperationTest.java
+++ b/catalog-model/src/test/java/org/openecomp/sdc/be/model/operations/impl/PropertyOperationTest.java
@@ -20,13 +20,29 @@
package org.openecomp.sdc.be.model.operations.impl;
-import org.janusgraph.core.JanusGraphVertex;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertNull;
+import static org.junit.Assert.assertTrue;
+import static org.mockito.ArgumentMatchers.any;
+import static org.mockito.Mockito.doCallRealMethod;
+import static org.mockito.Mockito.doReturn;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.spy;
+
import fj.data.Either;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
import org.apache.commons.lang3.tuple.ImmutablePair;
+import org.janusgraph.core.JanusGraphVertex;
import org.junit.Assert;
import org.junit.Before;
import org.junit.Test;
-import org.openecomp.sdc.be.dao.impl.HealingPipelineDao;
import org.openecomp.sdc.be.dao.janusgraph.HealingJanusGraphGenericDao;
import org.openecomp.sdc.be.dao.janusgraph.JanusGraphClient;
import org.openecomp.sdc.be.dao.janusgraph.JanusGraphGenericDao;
@@ -34,7 +50,12 @@
import org.openecomp.sdc.be.datatypes.elements.PropertyDataDefinition;
import org.openecomp.sdc.be.datatypes.elements.PropertyRule;
import org.openecomp.sdc.be.datatypes.enums.NodeTypeEnum;
-import org.openecomp.sdc.be.model.*;
+import org.openecomp.sdc.be.model.ComponentInstanceProperty;
+import org.openecomp.sdc.be.model.DataTypeDefinition;
+import org.openecomp.sdc.be.model.IComplexDefaultValue;
+import org.openecomp.sdc.be.model.ModelTestBase;
+import org.openecomp.sdc.be.model.PropertyConstraint;
+import org.openecomp.sdc.be.model.PropertyDefinition;
import org.openecomp.sdc.be.model.operations.api.StorageOperationStatus;
import org.openecomp.sdc.be.model.tosca.ToscaPropertyType;
import org.openecomp.sdc.be.model.tosca.ToscaType;
@@ -45,11 +66,6 @@
import org.openecomp.sdc.be.resources.data.PropertyData;
import org.openecomp.sdc.be.resources.data.PropertyValueData;
-import java.util.*;
-
-import static org.junit.Assert.*;
-import static org.mockito.Mockito.mock;
-
public class PropertyOperationTest extends ModelTestBase {
HealingJanusGraphGenericDao janusGraphGenericDao = mock(HealingJanusGraphGenericDao.class);
@@ -62,27 +78,6 @@
}
- /*
- * @Test public void addPropertyToResourceTest() {
- *
- * String propName = "myProp"; PropertyDefinition property = buildPropertyDefinition(); List<PropertyConstraint> constraints = buildConstraints(); property.setConstraints(constraints);
- *
- * PropertyData propertyData = new PropertyData(property, propertyOperation.convertConstraintsToString(constraints));
- *
- * Either<PropertyData, JanusGraphOperationStatus> either = Either.left(propertyData); //when(propertyDao.create((GraphNeighbourTable)anyObject(), eq(PropertyData.class), eq(NodeTypeEnum.Property))).thenReturn(either); GraphRelation graphRelation =
- * new GraphRelation(); Either<GraphRelation, JanusGraphOperationStatus> relationResult = Either.left(graphRelation);
- *
- * when(janusGraphGenericDao.createNode((PropertyData)anyObject(), eq(PropertyData.class))).thenReturn(either); when(janusGraphGenericDao.createRelation((GraphNode)anyObject(), (GraphNode)anyObject(), eq(GraphEdgeLabels.PROPERTY),
- * anyMap())).thenReturn(relationResult);
- *
- * Either<PropertyDefinition, StorageOperationStatus> result = propertyOperation.addPropertyToResource(propName, property, NodeTypeEnum.Resource, "my-resource.1.0");
- *
- * assertTrue(result.isLeft()); System.out.println(result.left().value()); PropertyDefinition propertyDefinition = result.left().value();
- *
- * List<PropertyConstraint> originalConstraints = property.getConstraints(); List<PropertyConstraint> propertyConstraintsResult = propertyDefinition.getConstraints(); assertEquals(propertyConstraintsResult.size(), originalConstraints.size());
- *
- * }
- */
private PropertyDefinition buildPropertyDefinition() {
PropertyDefinition property = new PropertyDefinition();
property.setDefaultValue("10");
@@ -92,60 +87,6 @@
}
@Test
- public void addPropertiesToGraphTableTest() {
-
- // Map<String, PropertyDefinition> properties = new HashMap<String,
- // PropertyDefinition>();
- // String propName = "myProp";
- // PropertyDefinition property = buildPropertyDefinition();
- //
- // List<PropertyConstraint> constraints = buildConstraints();
- // property.setConstraints(constraints);
- //
- // properties.put(propName, property);
- //
- // GraphNeighbourTable graphNeighbourTable = new GraphNeighbourTable();
- // ResourceData resourceData = new ResourceData();
- // String resourceName = "my-resource";
- // String resourceVersion = "1.0";
- // String resourceId = resourceName + "." + resourceVersion;
- // resourceData.setUniqueId(resourceId);
- // int resourceIndex = graphNeighbourTable.addNode(resourceData);
- //
- // heatParametersOperation.addPropertiesToGraphTable(properties,
- // graphNeighbourTable, resourceIndex, resourceId);
- //
- // assertEquals(2, graphNeighbourTable.getNodes().size());
- // assertEquals(1, graphNeighbourTable.getDirectedEdges().size());
- // List<GraphNode> nodes = graphNeighbourTable.getNodes();
- // boolean nodeFound = false;
- // for (GraphNode neo4jNode : nodes) {
- // if (neo4jNode instanceof PropertyData) {
- // PropertyData propertyData = (PropertyData)neo4jNode;
- // assertEquals("check property unique id", resourceId + "." + propName,
- // propertyData.getUniqueId());
- // assertEquals(property.getDescription(),
- // propertyData.getPropertyDataDefinition().getDescription());
- // nodeFound = true;
- // }
- // }
- // assertEquals("looking for PropertyData object in table", true,
- // nodeFound);
- //
- // NodeRelation nodeRelation =
- // graphNeighbourTable.getDirectedEdges().get(0);
- // assertEquals("check from index to index edge", 0,
- // nodeRelation.getFromIndex());
- // assertEquals("check from index to index edge", 1,
- // nodeRelation.getToIndex());
- // assertEquals("check edge type",
- // GraphEdgePropertiesDictionary.PROPERTY,
- // nodeRelation.getEdge().getEdgeType());
- // assertEquals("check propert name on edge", true,
- // nodeRelation.getEdge().getProperties().values().contains(propName));
- }
-
- @Test
public void convertConstraintsTest() {
List<PropertyConstraint> constraints = buildConstraints();
@@ -849,21 +790,75 @@
Assert.assertEquals(false, result);
}
-
- @Test
- public void testIsPropertyTypeValid() throws Exception {
- PropertyOperation testSubject;
- IComplexDefaultValue property = null;
- boolean result;
+ @Test
+ public void testIsPropertyTypeValidForNullPropertyOrPropertyType() {
+ final PropertyOperation propertyOperation = createTestSubject();
+ assertFalse("Property type should not be valid", propertyOperation.isPropertyTypeValid(null));
+ assertFalse("Property type should not be valid",
+ propertyOperation.isPropertyTypeValid(new PropertyDefinition()));
+ assertFalse("Property type should not be valid", propertyOperation.isPropertyTypeValid(null, null));
+ assertFalse("Property type should not be valid",
+ propertyOperation.isPropertyTypeValid(new PropertyDefinition(), null));
+ }
- // test 1
- testSubject = createTestSubject();
- property = null;
- result = testSubject.isPropertyTypeValid(property);
- Assert.assertEquals(false, result);
- }
+ @Test
+ public void testIsPropertyTypeValidForFoundType() {
+ final PropertyOperation propertyOperation = spy(createTestSubject());
+ final String nonToscaType = "non.tosca.type";
+ final PropertyDefinition propertyDefinition = buildPropertyDefinition();
+ propertyDefinition.setType(nonToscaType);
+ doCallRealMethod().when(propertyOperation).isPropertyTypeValid(any());
+ doReturn(Either.left(true)).when(propertyOperation).isDefinedInDataTypes(any());
+ assertTrue("Property type should be valid", propertyOperation.isPropertyTypeValid(propertyDefinition));
+ assertTrue("Property type should be valid", propertyOperation.isPropertyTypeValid(propertyDefinition, null));
+ }
-
+ @Test
+ public void testIsPropertyTypeValidForNotFoundType() {
+ final PropertyOperation propertyOperation = spy(createTestSubject());
+ final String nonToscaType = "non.tosca.type";
+ final PropertyDefinition propertyDefinition = buildPropertyDefinition();
+ propertyDefinition.setType(nonToscaType);
+ doReturn(Either.right(JanusGraphOperationStatus.NOT_FOUND))
+ .when(propertyOperation).isDefinedInDataTypes(any());
+ assertFalse("Property type should not be valid", propertyOperation.isPropertyTypeValid(propertyDefinition));
+ assertFalse("Property type should not be valid",
+ propertyOperation.isPropertyTypeValid(propertyDefinition, null));
+ doReturn(Either.left(false)).when(propertyOperation).isDefinedInDataTypes(any());
+ assertFalse("Property type should not be valid", propertyOperation.isPropertyTypeValid(propertyDefinition));
+ assertFalse("Property type should not be valid",
+ propertyOperation.isPropertyTypeValid(propertyDefinition, null));
+ }
+
+ @Test
+ public void testIsPropertyTypeValidForValidToscaType() {
+ final PropertyOperation propertyOperation = createTestSubject();
+ final PropertyDefinition propertyDefinition = buildPropertyDefinition();
+ assertTrue("Property type should be valid",
+ propertyOperation.isPropertyTypeValid(propertyDefinition));
+ assertTrue("Property type should be valid",
+ propertyOperation.isPropertyTypeValid(propertyDefinition, null));
+ }
+
+ @Test
+ public void testIsPropertyTypeValidForNonToscaTypeProvidedInList() {
+ final PropertyOperation propertyOperation = spy(createTestSubject());
+ final String nonToscaType = "non.tosca.type";
+ final PropertyDefinition propertyDefinition = buildPropertyDefinition();
+ propertyDefinition.setType(nonToscaType);
+ doCallRealMethod().when(propertyOperation).isPropertyTypeValid(any());
+ doReturn(Either.right(JanusGraphOperationStatus.NOT_FOUND)).when(propertyOperation).isDefinedInDataTypes(any());
+ final List<DataTypeDefinition> dataTypeDefinitionList = new ArrayList<>();
+ final DataTypeDefinition dataTypeDefinition = new DataTypeDefinition();
+ dataTypeDefinition.setName(nonToscaType);
+ dataTypeDefinitionList.add(dataTypeDefinition);
+ assertTrue("Property type should match a data type in list",
+ propertyOperation.isPropertyTypeValid(propertyDefinition, dataTypeDefinitionList));
+ dataTypeDefinition.setName(nonToscaType + "dummyValue");
+ assertFalse("Property type should match a data type in list",
+ propertyOperation.isPropertyTypeValid(propertyDefinition, dataTypeDefinitionList));
+ }
+
@Test
public void testIsPropertyInnerTypeValid() throws Exception {
PropertyOperation testSubject;
diff --git a/catalog-ui/src/app/models/componentsInstances/fullComponentInstance.ts b/catalog-ui/src/app/models/componentsInstances/fullComponentInstance.ts
index 5cb1288..f2293c9 100644
--- a/catalog-ui/src/app/models/componentsInstances/fullComponentInstance.ts
+++ b/catalog-ui/src/app/models/componentsInstances/fullComponentInstance.ts
@@ -67,7 +67,7 @@
this.directives = componentInstance.directives;
- if(originComponent.componentType === ComponentType.SERVICE || originComponent.componentType === ComponentType.SERVICE_PROXY || ComponentType.SERVICE_SUBSTITUTION){
+ if(originComponent.componentType === ComponentType.SERVICE || originComponent.componentType === ComponentType.SERVICE_PROXY || originComponent.componentType === ComponentType.SERVICE_SUBSTITUTION){
this.isServiceInstance = true;
this.serviceApiArtifacts = (<Service>originComponent).serviceApiArtifacts;
this.serviceType = (<Service>originComponent).serviceType;
@@ -93,4 +93,4 @@
return this.isServiceInstance;
}
-}
\ No newline at end of file
+}
diff --git a/common-app-api/src/main/java/org/openecomp/sdc/common/util/JsonUtils.java b/common-app-api/src/main/java/org/openecomp/sdc/common/util/JsonUtils.java
index fbf94ea..c2f9580 100644
--- a/common-app-api/src/main/java/org/openecomp/sdc/common/util/JsonUtils.java
+++ b/common-app-api/src/main/java/org/openecomp/sdc/common/util/JsonUtils.java
@@ -20,6 +20,7 @@
package org.openecomp.sdc.common.util;
+import com.google.gson.JsonArray;
import com.google.gson.JsonElement;
import com.google.gson.JsonObject;
@@ -51,8 +52,18 @@
return json.entrySet().isEmpty();
}
- public static boolean isEmptyJson(JsonElement json) {
- return json.isJsonPrimitive() ? false : JsonUtils.isEmptyJson(json.getAsJsonObject());
+ public static boolean isEmptyJson(JsonArray json) {
+ return json.size() == 0;
+ }
+
+ public static boolean isEmptyJson(final JsonElement json) {
+ if (json.isJsonObject()) {
+ return isEmptyJson(json.getAsJsonObject());
+ } else if (json.isJsonArray()) {
+ return isEmptyJson(json.getAsJsonArray());
+ }
+
+ return false;
}
public static boolean isJsonNullOrEmpty(JsonObject json) {
diff --git a/common-app-api/src/test/java/org/openecomp/sdc/common/util/JsonUtilsTest.java b/common-app-api/src/test/java/org/openecomp/sdc/common/util/JsonUtilsTest.java
index 6021b75..c59329b 100644
--- a/common-app-api/src/test/java/org/openecomp/sdc/common/util/JsonUtilsTest.java
+++ b/common-app-api/src/test/java/org/openecomp/sdc/common/util/JsonUtilsTest.java
@@ -91,9 +91,8 @@
@Test
public void validateIsEmptyJsonReturnsFalseIfInputIsNotEmpty() {
- boolean result = JsonUtils.isEmptyJson(generateJsonArray().get(0));
-
- assertFalse(result);
+ assertFalse(JsonUtils.isEmptyJson(generateJsonArray()));
+ assertFalse(JsonUtils.isEmptyJson(generateJsonArray().get(0)));
}
@Test
diff --git a/common-be/src/main/java/org/openecomp/sdc/be/datatypes/enums/JsonPresentationFields.java b/common-be/src/main/java/org/openecomp/sdc/be/datatypes/enums/JsonPresentationFields.java
index 3da0d38..ab0c8d9 100644
--- a/common-be/src/main/java/org/openecomp/sdc/be/datatypes/enums/JsonPresentationFields.java
+++ b/common-be/src/main/java/org/openecomp/sdc/be/datatypes/enums/JsonPresentationFields.java
@@ -117,6 +117,16 @@
SCHEMA("schema", null),
VALUE("value", null),
PARENT_UNIQUE_ID("parentUniqueId", null),
+ LABEL("label", null),
+ IMMUTABLE("immutable", null),
+ HIDDEN("hidden", null),
+ INPUT_PATH("inputPath", null),
+ INPUT_ID("inputId", null),
+ INSTANCE_UNIQUE_ID("instanceUniqueId", null),
+ PROPERTY_CONSTRAINTS("propertyConstraints", null),
+ PROPERTY_ID("propertyId", null),
+ PARENT_PROPERTY_TYPE("parentPropertyType", null),
+ SUB_PROPERTY_INPUT_PATH("subPropertyInputPath", null),
COMPONENT_INSTANCES("componentInstances", null),
RELATIONS("relations", null),
diff --git a/common-be/src/main/java/org/openecomp/sdc/be/utils/TypeUtils.java b/common-be/src/main/java/org/openecomp/sdc/be/utils/TypeUtils.java
index 66c64bd..b95b27e 100644
--- a/common-be/src/main/java/org/openecomp/sdc/be/utils/TypeUtils.java
+++ b/common-be/src/main/java/org/openecomp/sdc/be/utils/TypeUtils.java
@@ -43,7 +43,7 @@
@Getter
@AllArgsConstructor
public enum ToscaTagNamesEnum {
- DERIVED_FROM("derived_from"), IS_PASSWORD("is_password"),
+ DERIVED_FROM("derived_from"), IS_PASSWORD("is_password"), DERIVED_FROM_NAME("derivedFromName"),
// Properties
PROPERTIES("properties"), TYPE("type"), STATUS("status"), ENTRY_SCHEMA("entry_schema"), REQUIRED("required"), DESCRIPTION("description"), DEFAULT_VALUE("default"), VALUE("value"), CONSTRAINTS("constraints"),
// Group Types
@@ -68,9 +68,7 @@
//functions
GET_INPUT("get_input"),
// Definitions
- DATA_TYPES("data_types"), NODE_TYPES("node_types"), IMPORTS("imports"),
-
- DERIVED_FROM_NAME("derivedFromName");
+ DATA_TYPES("data_types"), NODE_TYPES("node_types"), IMPORTS("imports");
private final String elementName;
diff --git a/integration-tests/src/test/resources/Files/VNFs/not-known-data-types.csar b/integration-tests/src/test/resources/Files/VNFs/not-known-data-types.csar
new file mode 100644
index 0000000..b0f57c9
--- /dev/null
+++ b/integration-tests/src/test/resources/Files/VNFs/not-known-data-types.csar
Binary files differ