summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/ArtifactsBusinessLogic.java3
-rw-r--r--catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/ResourceBusinessLogic.java29
-rw-r--r--catalog-be/src/main/java/org/openecomp/sdc/be/tosca/CsarUtils.java3
-rw-r--r--catalog-be/src/main/java/org/openecomp/sdc/be/tosca/PropertyConvertor.java20
-rw-r--r--catalog-be/src/main/webapp/WEB-INF/web.xml4
-rw-r--r--catalog-be/src/test/java/org/openecomp/sdc/be/components/impl/ResourceBusinessLogicTest.java10
-rw-r--r--catalog-be/src/test/java/org/openecomp/sdc/be/tosca/PropertyConvertorTest.java131
-rw-r--r--catalog-model/src/main/java/org/openecomp/sdc/be/model/jsontitan/operations/BaseOperation.java71
-rw-r--r--catalog-model/src/main/java/org/openecomp/sdc/be/model/jsontitan/operations/NodeTemplateOperation.java2
-rw-r--r--catalog-model/src/main/java/org/openecomp/sdc/be/model/jsontitan/operations/ToscaElementLifecycleOperation.java2
-rw-r--r--catalog-model/src/main/java/org/openecomp/sdc/be/model/tosca/converters/DataTypePropertyConverter.java2
-rw-r--r--catalog-model/src/test/java/org/openecomp/sdc/be/model/tosca/converters/DataTypePropertyConverterTest.java366
-rw-r--r--common-app-api/src/main/java/org/openecomp/sdc/common/util/JsonUtils.java5
13 files changed, 336 insertions, 312 deletions
diff --git a/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/ArtifactsBusinessLogic.java b/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/ArtifactsBusinessLogic.java
index 74bb55b63d..1ee3bc61c8 100644
--- a/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/ArtifactsBusinessLogic.java
+++ b/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/ArtifactsBusinessLogic.java
@@ -3648,12 +3648,13 @@ public class ArtifactsBusinessLogic extends BaseBusinessLogic {
Either<ESArtifactData, CassandraOperationStatus> artifactfromES;
ESArtifactData esArtifactData;
if (esArtifactId != null && !esArtifactId.isEmpty() && artifactDefinition.getPayloadData() == null) {
+ log.debug("Try to fetch artifact from cassandra with id : {}", esArtifactId);
artifactfromES = artifactCassandraDao.getArtifact(esArtifactId);
if (artifactfromES.isRight()) {
CassandraOperationStatus resourceUploadStatus = artifactfromES.right().value();
StorageOperationStatus storageResponse = DaoStatusConverter.convertCassandraStatusToStorageStatus(resourceUploadStatus);
ActionStatus actionStatus = componentsUtils.convertFromStorageResponse(storageResponse);
- log.debug("Error when getting artifact from ES, error: {}", actionStatus.name());
+ log.debug("Error when getting artifact from ES, error: {} esid : {}", actionStatus.name(), esArtifactId);
return Either.right(componentsUtils.getResponseFormatByArtifactId(actionStatus, artifactDefinition.getArtifactDisplayName()));
}
esArtifactData = artifactfromES.left().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 b0feffdd42..08d377c7db 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
@@ -917,6 +917,9 @@ public class ResourceBusinessLogic extends ComponentBusinessLogic {
vfcToscaNames.put(nodeType.getKey(), toscaResourceName);
}
}
+ for(NodeTypeInfo cvfc : nodeTypesInfo.values()){
+ vfcToscaNames.put(cvfc.getType(), buildNestedToscaResourceName(ResourceTypeEnum.CVFC.name(), vfResourceName, cvfc.getType()));
+ }
return vfcToscaNames;
}
@@ -1461,7 +1464,8 @@ public class ResourceBusinessLogic extends ComponentBusinessLogic {
String nameWithouNamespacePrefix = nodeName.substring(Constants.USER_DEFINED_RESOURCE_NAMESPACE_PREFIX.length());
String[] findTypes = nameWithouNamespacePrefix.split("\\.");
String resourceType = findTypes[0];
- return resourceVfName + "-" + nameWithouNamespacePrefix.substring(resourceType.length() + 1) + "Cvfc";
+ String resourceName = resourceVfName + "-" + nameWithouNamespacePrefix.substring(resourceType.length() + 1);
+ return addCvfcSuffixToResourceName(resourceName);
}
private Either<Resource, ResponseFormat> createResourceAndRIsFromYaml(String yamlName, Resource resource, ParsedToscaYamlInfo parsedToscaYamlInfo, AuditingActionEnum actionEnum, boolean isNormative,
@@ -1987,6 +1991,7 @@ public class ResourceBusinessLogic extends ComponentBusinessLogic {
if (eitherCreateResult.isRight()) {
return Either.right(eitherCreateResult.right().value());
}
+ resource = eitherCreateResult.left().value();
Either<ImmutablePair<String, String>, ResponseFormat> artifacsMetaCsarStatus = CsarValidationUtils.getArtifactsMeta(csarInfo.getCsar(), csarInfo.getCsarUUID(), componentsUtils);
if (artifacsMetaCsarStatus.isLeft()) {
@@ -2895,7 +2900,9 @@ public class ResourceBusinessLogic extends ComponentBusinessLogic {
}
}
if (resStatus == null) {
- resStatus = Either.left(resource);
+ Either<Resource, StorageOperationStatus> toscaElement = toscaOperationFacade.getToscaElement(resource.getUniqueId());
+ resStatus = toscaElement.bimap(resourceResponse -> resourceResponse,
+ storageResponse -> componentsUtils.getResponseFormatByResource(componentsUtils.convertFromStorageResponse(storageResponse), resource));
}
} catch (Exception e) {
resStatus = Either.right(componentsUtils.getResponseFormat(ActionStatus.GENERAL_ERROR));
@@ -6209,11 +6216,23 @@ public class ResourceBusinessLogic extends ComponentBusinessLogic {
*
* return Either.left(true); }
*/
+ private boolean isResourceNameEquals(Resource currentResource, Resource updateInfoResource) {
+ String resourceNameUpdated = updateInfoResource.getName();
+ String resourceNameCurrent = currentResource.getName();
+ if (resourceNameCurrent.equals(resourceNameUpdated))
+ return true;
+ // In case of CVFC type we should support the case of old VF with CVFC instances that were created without the "Cvfc" suffix
+ return (currentResource.getResourceType().equals(ResourceTypeEnum.CVFC)
+ && resourceNameUpdated.equals(addCvfcSuffixToResourceName(resourceNameCurrent)));
+ }
+
+ private String addCvfcSuffixToResourceName(String resourceName) {
+ return resourceName+"Cvfc";
+ }
private Either<Boolean, ResponseFormat> validateResourceName(Resource currentResource, Resource updateInfoResource, boolean hasBeenCertified) {
String resourceNameUpdated = updateInfoResource.getName();
- String resourceNameCurrent = currentResource.getName();
- if (!resourceNameCurrent.equals(resourceNameUpdated)) {
+ if (!isResourceNameEquals(currentResource, updateInfoResource)) {
if (!hasBeenCertified) {
Either<Boolean, ResponseFormat> validateResourceNameResponse = validateComponentName(null, updateInfoResource, null);
if (validateResourceNameResponse.isRight()) {
@@ -6229,7 +6248,7 @@ public class ResourceBusinessLogic extends ComponentBusinessLogic {
currentResource.setNormalizedName(ValidationUtils.normaliseComponentName(resourceNameUpdated));
currentResource.setSystemName(ValidationUtils.convertToSystemName(resourceNameUpdated));
- } else {
+ } else if(currentResource.getResourceType() != ResourceTypeEnum.CVFC) {
log.info("Resource name: {}, cannot be updated once the resource has been certified once.", resourceNameUpdated);
ResponseFormat errorResponse = componentsUtils.getResponseFormat(ActionStatus.RESOURCE_NAME_CANNOT_BE_CHANGED);
return Either.right(errorResponse);
diff --git a/catalog-be/src/main/java/org/openecomp/sdc/be/tosca/CsarUtils.java b/catalog-be/src/main/java/org/openecomp/sdc/be/tosca/CsarUtils.java
index a0cc347e09..fda199052e 100644
--- a/catalog-be/src/main/java/org/openecomp/sdc/be/tosca/CsarUtils.java
+++ b/catalog-be/src/main/java/org/openecomp/sdc/be/tosca/CsarUtils.java
@@ -146,7 +146,8 @@ public class CsarUtils {
ImportUtils.Constants.USER_DEFINED_RESOURCE_NAMESPACE_PREFIX +
"([\\d\\w\\_\\-\\.\\s]+)" + DEL_PATTERN +
"([\\d\\w\\_\\-\\.\\s]+)" + DEL_PATTERN +
- "([\\d\\w\\_\\-\\.\\s]+)" + DEL_PATTERN;
+ "([\\d\\w\\_\\-\\.\\s]+)" + DEL_PATTERN +
+ "([\\d\\w\\_\\-\\.\\s]+)";
public static final String VF_NODE_TYPE_ARTIFACTS_PATH_PATTERN = ARTIFACTS + DEL_PATTERN+
// Artifact Group (i.e Deployment/Informational)
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 646a7ecc8b..68adbd5ae3 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
@@ -74,7 +74,9 @@ public class PropertyConvertor {
props.stream().filter(p -> p.getOwnerId() == null || p.getOwnerId().equals(component.getUniqueId())).forEach(property -> {
ToscaProperty prop = convertProperty(dataTypes, property, false);
- properties.put(property.getName(), prop);
+ if (prop != null) {
+ properties.put(property.getName(), prop);
+ }
});
if (!properties.isEmpty()) {
toscaNodeType.setProperties(properties);
@@ -98,13 +100,17 @@ public class PropertyConvertor {
}
log.trace("try to convert property {} from type {} with default value [{}]", property.getName(), property.getType(), property.getDefaultValue());
prop.setDefaultp(convertToToscaObject(property.getType(), property.getDefaultValue(), innerType, dataTypes));
+
+ if (prop.getDefaultp() == null) {
+ return null;
+ }
prop.setType(property.getType());
- prop.setDescription(property.getDescription());
- if (isCapabiltyProperty) {
- prop.setStatus(property.getStatus());
- prop.setRequired(property.isRequired());
- }
- return prop;
+ prop.setDescription(property.getDescription());
+ if (isCapabiltyProperty) {
+ prop.setStatus(property.getStatus());
+ prop.setRequired(property.isRequired());
+ }
+ return prop;
}
public Object convertToToscaObject(String propertyType, String value, String innerType, Map<String, DataTypeDefinition> dataTypes) {
diff --git a/catalog-be/src/main/webapp/WEB-INF/web.xml b/catalog-be/src/main/webapp/WEB-INF/web.xml
index 16c6fd6756..5ed38e6bc1 100644
--- a/catalog-be/src/main/webapp/WEB-INF/web.xml
+++ b/catalog-be/src/main/webapp/WEB-INF/web.xml
@@ -95,7 +95,7 @@
<init-param>
<param-name>swagger.api.basepath</param-name>
- <param-value>http://localhost:8080/sdc2/rest</param-value>
+ <param-value>/sdc2/rest</param-value>
</init-param>
<init-param>
@@ -129,7 +129,7 @@
<init-param>
<param-name>swagger.api.basepath</param-name>
<!-- Check if second param can be added -->
- <param-value>http://localhost:8080/sdc</param-value>
+ <param-value>/sdc</param-value>
</init-param>
<init-param>
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 0e27636901..40986bf59d 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
@@ -1655,17 +1655,15 @@ public class ResourceBusinessLogicTest {
deploymentArtifactToUpdate.setArtifactName(deploymentArtifactToUpdateFileName);
deploymentArtifactToUpdate.setArtifactType("SNMP_POLL");
deploymentArtifactToUpdate.setPayload(oldPayloadData);
- deploymentArtifactToUpdate
- .setArtifactChecksum(GeneralUtility.calculateMD5Base64EncodedByByteArray(oldPayloadData));
-
+ deploymentArtifactToUpdate.setArtifactChecksum(GeneralUtility.calculateMD5Base64EncodedByByteArray(oldPayloadData));
+
ArtifactDefinition deploymentArtifactToDelete = new ArtifactDefinition();
deploymentArtifactToDelete.setMandatory(false);
deploymentArtifactToDelete.setArtifactName(deploymentArtifactToDeleteFileName);
deploymentArtifactToDelete.setArtifactType("SNMP_TRAP");
deploymentArtifactToDelete.setPayload(oldPayloadData);
- deploymentArtifactToDelete
- .setArtifactChecksum(GeneralUtility.calculateMD5Base64EncodedByByteArray(oldPayloadData));
-
+ deploymentArtifactToDelete.setArtifactChecksum(GeneralUtility.calculateMD5Base64EncodedByByteArray(oldPayloadData));
+
ArtifactDefinition deploymentArtifactToIgnore = new ArtifactDefinition();
deploymentArtifacts.put(ValidationUtils.normalizeArtifactLabel(deploymentArtifactToUpdate.getArtifactName()),
diff --git a/catalog-be/src/test/java/org/openecomp/sdc/be/tosca/PropertyConvertorTest.java b/catalog-be/src/test/java/org/openecomp/sdc/be/tosca/PropertyConvertorTest.java
index e6f1ac82fb..a987e0243b 100644
--- a/catalog-be/src/test/java/org/openecomp/sdc/be/tosca/PropertyConvertorTest.java
+++ b/catalog-be/src/test/java/org/openecomp/sdc/be/tosca/PropertyConvertorTest.java
@@ -1,71 +1,102 @@
package org.openecomp.sdc.be.tosca;
-import java.util.Map;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertNull;
+import static org.junit.Assert.assertTrue;
-import javax.annotation.Generated;
+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.openecomp.sdc.be.model.Component;
import org.openecomp.sdc.be.model.DataTypeDefinition;
import org.openecomp.sdc.be.model.PropertyDefinition;
+import org.openecomp.sdc.be.model.Resource;
+import org.openecomp.sdc.be.model.tosca.ToscaPropertyType;
import org.openecomp.sdc.be.tosca.model.ToscaNodeType;
import org.openecomp.sdc.be.tosca.model.ToscaProperty;
import fj.data.Either;
public class PropertyConvertorTest {
+ private PropertyDefinition property;
+ Map<String, DataTypeDefinition> dataTypes;
- private PropertyConvertor createTestSubject() {
- return new PropertyConvertor();
- }
-
-
- @Test
- public void testGetInstance() throws Exception {
- PropertyConvertor result;
-
- // default test
- result = PropertyConvertor.getInstance();
- }
+ @Before
+ public void setUp(){
+ property = new PropertyDefinition();
+ property.setName("myProperty");
+ property.setType(ToscaPropertyType.INTEGER.getType());
+ dataTypes = new HashMap<String, DataTypeDefinition>();
+ dataTypes.put(property.getName(), new DataTypeDefinition());
+ }
-
- @Test
- public void testConvertProperties() throws Exception {
- PropertyConvertor testSubject;
- Component component = null;
- ToscaNodeType toscaNodeType = null;
- Map<String, DataTypeDefinition> dataTypes = null;
- Either<ToscaNodeType, ToscaError> result;
- // default test
- testSubject = createTestSubject();
- result = testSubject.convertProperties(component, toscaNodeType, dataTypes);
- }
+ @Test
+ public void convertPropertyWhenValueAndDefaultNull() {
+ assertNull(PropertyConvertor.getInstance().convertProperty(dataTypes, property, false));
+ }
-
- @Test
- public void testConvertProperty() throws Exception {
- PropertyConvertor testSubject;
- Map<String, DataTypeDefinition> dataTypes = null;
- PropertyDefinition property = null;
- boolean isCapabiltyProperty = false;
- ToscaProperty result;
+ @Test
+ public void convertPropertyWhenValueNullAndDefaultNotEmpty() {
+ final String def = "1";
+ property.setDefaultValue(def);
+ ToscaProperty result = PropertyConvertor.getInstance().convertProperty(dataTypes, property, false);
+ assertNotNull(result);
+ assertEquals(Integer.valueOf(def).intValue(), result.getDefaultp());
+ }
- // default test
- testSubject = createTestSubject();
- }
+ @Test
+ public void convertPropertiesWhenValueAndDefaultNullInOne() {
+ PropertyDefinition property1 = new PropertyDefinition();
+ property1.setName("otherProperty");
+ property1.setType(ToscaPropertyType.INTEGER.getType());
+ property1.setDefaultValue("2");
+ dataTypes.put(property1.getName(), new DataTypeDefinition());
+ Resource resource = new Resource();
+ List<PropertyDefinition> properties = new ArrayList<PropertyDefinition>();
+ properties.add(property);
+ properties.add(property1);
+ resource.setProperties(properties);
+ Either<ToscaNodeType, ToscaError> result = PropertyConvertor.getInstance().convertProperties(resource, new ToscaNodeType(), dataTypes);
+ assertTrue(result.isLeft());
+ assertEquals(1, result.left().value().getProperties().size());
+ }
-
- @Test
- public void testConvertToToscaObject() throws Exception {
- PropertyConvertor testSubject;
- String propertyType = "";
- String value = "";
- String innerType = "";
- Map<String, DataTypeDefinition> dataTypes = null;
- Object result;
+ @Test
+ public void convertPropertiesWhenValueAndDefaultExist() {
+ PropertyDefinition property1 = new PropertyDefinition();
+ property1.setName("otherProperty");
+ property1.setType(ToscaPropertyType.INTEGER.getType());
+ property1.setDefaultValue("2");
+ property.setDefaultValue("1");
+ dataTypes.put(property1.getName(), new DataTypeDefinition());
+ Resource resource = new Resource();
+ List<PropertyDefinition> properties = new ArrayList<PropertyDefinition>();
+ properties.add(property);
+ properties.add(property1);
+ resource.setProperties(properties);
+ Either<ToscaNodeType, ToscaError> result = PropertyConvertor.getInstance().convertProperties(resource, new ToscaNodeType(), dataTypes);
+ assertTrue(result.isLeft());
+ assertEquals(2, result.left().value().getProperties().size());
+ }
- // default test
- testSubject = createTestSubject();
- }
+ @Test
+ public void convertPropertiesWhenValueAndDefaultNullInAll() {
+ PropertyDefinition property1 = new PropertyDefinition();
+ property1.setName("otherProperty");
+ property1.setType(ToscaPropertyType.INTEGER.getType());
+ dataTypes.put(property1.getName(), new DataTypeDefinition());
+ Resource resource = new Resource();
+ List<PropertyDefinition> properties = new ArrayList<PropertyDefinition>();
+ properties.add(property);
+ properties.add(property1);
+ resource.setProperties(properties);
+ Either<ToscaNodeType, ToscaError> result = PropertyConvertor.getInstance().convertProperties(resource, new ToscaNodeType(), dataTypes);
+ assertTrue(result.isLeft());
+ assertNull(result.left().value().getProperties());
+ }
} \ No newline at end of file
diff --git a/catalog-model/src/main/java/org/openecomp/sdc/be/model/jsontitan/operations/BaseOperation.java b/catalog-model/src/main/java/org/openecomp/sdc/be/model/jsontitan/operations/BaseOperation.java
index 1726c397ad..79360f6e10 100644
--- a/catalog-model/src/main/java/org/openecomp/sdc/be/model/jsontitan/operations/BaseOperation.java
+++ b/catalog-model/src/main/java/org/openecomp/sdc/be/model/jsontitan/operations/BaseOperation.java
@@ -25,6 +25,7 @@ import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
+import java.util.Optional;
import java.util.UUID;
import java.util.stream.Collectors;
@@ -44,6 +45,7 @@ import org.openecomp.sdc.be.dao.jsongraph.types.JsonParseFlagEnum;
import org.openecomp.sdc.be.dao.jsongraph.types.VertexTypeEnum;
import org.openecomp.sdc.be.dao.jsongraph.utils.IdBuilderUtils;
import org.openecomp.sdc.be.dao.titan.TitanOperationStatus;
+import org.openecomp.sdc.be.datatypes.elements.ArtifactDataDefinition;
import org.openecomp.sdc.be.datatypes.elements.ComponentInstanceDataDefinition;
import org.openecomp.sdc.be.datatypes.elements.GroupDataDefinition;
import org.openecomp.sdc.be.datatypes.elements.GroupInstanceDataDefinition;
@@ -1338,32 +1340,49 @@ public abstract class BaseOperation {
// return StorageOperationStatus.OK;
// }
- protected GroupInstanceDataDefinition buildGroupInstanceDataDefinition(GroupDataDefinition group, ComponentInstanceDataDefinition componentInstance) {
-
- String componentInstanceName = componentInstance.getName();
- Long creationDate = System.currentTimeMillis();
- GroupInstanceDataDefinition groupInstance = new GroupInstanceDataDefinition();
- String groupUid = group.getUniqueId();
-
- groupInstance.setGroupUid(groupUid);
- groupInstance.setType(group.getType());
- groupInstance.setCustomizationUUID(generateCustomizationUUID());
- groupInstance.setCreationTime(creationDate);
- groupInstance.setModificationTime(creationDate);
- groupInstance.setName(buildGroupInstanceName(componentInstanceName, group.getName()));
- groupInstance.setGroupName(group.getName());
- groupInstance.setNormalizedName(ValidationUtils.normalizeComponentInstanceName(groupInstance.getName()));
- groupInstance.setUniqueId(UniqueIdBuilder.buildResourceInstanceUniuqeId(componentInstance.getUniqueId(), groupUid, groupInstance.getNormalizedName()));
- groupInstance.setArtifacts(group.getArtifacts());
- groupInstance.setArtifactsUuid(group.getArtifactsUuid());
- groupInstance.setProperties(group.getProperties());
- convertPropertiesToInstanceProperties(groupInstance.getProperties());
- groupInstance.setInvariantUUID(group.getInvariantUUID());
- groupInstance.setGroupUUID(group.getGroupUUID());
- groupInstance.setVersion(group.getVersion());
-
- return groupInstance;
- }
+ protected GroupInstanceDataDefinition buildGroupInstanceDataDefinition(GroupDataDefinition group, ComponentInstanceDataDefinition componentInstance, Map<String, ArtifactDataDefinition> instDeplArtifMap) {
+
+ String componentInstanceName = componentInstance.getName();
+ Long creationDate = System.currentTimeMillis();
+ GroupInstanceDataDefinition groupInstance = new GroupInstanceDataDefinition();
+ String groupUid = group.getUniqueId();
+
+ groupInstance.setGroupUid(groupUid);
+ groupInstance.setType(group.getType());
+ groupInstance.setCustomizationUUID(generateCustomizationUUID());
+ groupInstance.setCreationTime(creationDate);
+ groupInstance.setModificationTime(creationDate);
+ groupInstance.setName(buildGroupInstanceName(componentInstanceName, group.getName()));
+ groupInstance.setGroupName(group.getName());
+ groupInstance.setNormalizedName(ValidationUtils.normalizeComponentInstanceName(groupInstance.getName()));
+ groupInstance.setUniqueId(UniqueIdBuilder.buildResourceInstanceUniuqeId(componentInstance.getUniqueId(), groupUid, groupInstance.getNormalizedName()));
+ groupInstance.setArtifacts(group.getArtifacts());
+
+// List<String> fixedArtifactsUuid;
+// List<String> artifactsUuid = group.getArtifactsUuid();
+// if (instDeplArtifMap != null) {
+// fixedArtifactsUuid = new ArrayList<>();
+// artifactsUuid.forEach(u -> {
+// Optional<ArtifactDataDefinition> findFirst = instDeplArtifMap.values().stream().filter(a -> u.equals(a.getUniqueId())).findFirst();
+// if (findFirst.isPresent()) {
+// fixedArtifactsUuid.add(findFirst.get().getArtifactUUID());
+// } else {
+// fixedArtifactsUuid.add(u);
+// }
+// });
+// } else {
+// fixedArtifactsUuid = artifactsUuid;
+// }
+ groupInstance.setArtifactsUuid(group.getArtifactsUuid());
+ groupInstance.setProperties(group.getProperties());
+ convertPropertiesToInstanceProperties(groupInstance.getProperties());
+ groupInstance.setInvariantUUID(group.getInvariantUUID());
+ groupInstance.setGroupUUID(group.getGroupUUID());
+ groupInstance.setVersion(group.getVersion());
+
+ return groupInstance;
+ }
+
protected String buildGroupInstanceName(String instanceName, String groupName) {
return ValidationUtils.normalizeComponentInstanceName(instanceName) + ".." + groupName;
diff --git a/catalog-model/src/main/java/org/openecomp/sdc/be/model/jsontitan/operations/NodeTemplateOperation.java b/catalog-model/src/main/java/org/openecomp/sdc/be/model/jsontitan/operations/NodeTemplateOperation.java
index b642410548..7ff42ae42e 100644
--- a/catalog-model/src/main/java/org/openecomp/sdc/be/model/jsontitan/operations/NodeTemplateOperation.java
+++ b/catalog-model/src/main/java/org/openecomp/sdc/be/model/jsontitan/operations/NodeTemplateOperation.java
@@ -793,7 +793,7 @@ public class NodeTemplateOperation extends BaseOperation {
for (Map.Entry<String, List<ArtifactDefinition>> groupArtifacts : groupInstancesArtifacts.entrySet()) {
Optional<GroupDefinition> groupOptional = groups.stream().filter(g -> g.getUniqueId().equals(groupArtifacts.getKey())).findFirst();
if (groupOptional.isPresent()) {
- GroupInstanceDataDefinition groupInstance = buildGroupInstanceDataDefinition((GroupDataDefinition)groupOptional.get(), (ComponentInstanceDataDefinition)componentInstance);
+ GroupInstanceDataDefinition groupInstance = buildGroupInstanceDataDefinition((GroupDataDefinition) groupOptional.get(), (ComponentInstanceDataDefinition) componentInstance, null);
groupInstance.setGroupInstanceArtifacts(groupArtifacts.getValue().stream().map(a -> a.getUniqueId()).collect(Collectors.toList()));
groupInstance.setGroupInstanceArtifactsUuid(groupArtifacts.getValue().stream().map(a -> a.getArtifactUUID()).collect(Collectors.toList()));
groupInstanceToCreate.put(groupInstance.getName(), groupInstance);
diff --git a/catalog-model/src/main/java/org/openecomp/sdc/be/model/jsontitan/operations/ToscaElementLifecycleOperation.java b/catalog-model/src/main/java/org/openecomp/sdc/be/model/jsontitan/operations/ToscaElementLifecycleOperation.java
index 51d122524c..f34975b073 100644
--- a/catalog-model/src/main/java/org/openecomp/sdc/be/model/jsontitan/operations/ToscaElementLifecycleOperation.java
+++ b/catalog-model/src/main/java/org/openecomp/sdc/be/model/jsontitan/operations/ToscaElementLifecycleOperation.java
@@ -1120,7 +1120,7 @@ public class ToscaElementLifecycleOperation extends BaseOperation {
Map<String, GroupInstanceDataDefinition> groupInstanceToCreate = new HashMap<>();
for(GroupDataDefinition group:filteredGroups){
CommonUtility.addRecordToLog(logger, LogLevelEnum.DEBUG, "create new groupInstance {} ", group.getName());
- GroupInstanceDataDefinition groupInstance = buildGroupInstanceDataDefinition(group, vfInst);
+ GroupInstanceDataDefinition groupInstance = buildGroupInstanceDataDefinition(group, vfInst, instDeplArtifMap);
List<String> artifactsUid = new ArrayList<>();
List<String> artifactsId = new ArrayList<>();
for (ArtifactDataDefinition artifact : instDeplArtifMap.values()) {
diff --git a/catalog-model/src/main/java/org/openecomp/sdc/be/model/tosca/converters/DataTypePropertyConverter.java b/catalog-model/src/main/java/org/openecomp/sdc/be/model/tosca/converters/DataTypePropertyConverter.java
index 2d389f5fe5..f3b842e0cf 100644
--- a/catalog-model/src/main/java/org/openecomp/sdc/be/model/tosca/converters/DataTypePropertyConverter.java
+++ b/catalog-model/src/main/java/org/openecomp/sdc/be/model/tosca/converters/DataTypePropertyConverter.java
@@ -35,7 +35,7 @@ public class DataTypePropertyConverter {
*/
public String getDataTypePropertiesDefaultValuesRec(String propertyDataType, Map<String, DataTypeDefinition> dataTypes) {
JsonObject defaultValues = getDataTypePropsDefaultValuesRec(propertyDataType, dataTypes);
- return !defaultValues.isJsonNull() ? gson.toJson(defaultValues) : null;
+ return !JsonUtils.isJsonNullOrEmpty(defaultValues) ? gson.toJson(defaultValues) : null;
}
/**
diff --git a/catalog-model/src/test/java/org/openecomp/sdc/be/model/tosca/converters/DataTypePropertyConverterTest.java b/catalog-model/src/test/java/org/openecomp/sdc/be/model/tosca/converters/DataTypePropertyConverterTest.java
index ebb7566611..e15d784c7a 100644
--- a/catalog-model/src/test/java/org/openecomp/sdc/be/model/tosca/converters/DataTypePropertyConverterTest.java
+++ b/catalog-model/src/test/java/org/openecomp/sdc/be/model/tosca/converters/DataTypePropertyConverterTest.java
@@ -1,8 +1,5 @@
package org.openecomp.sdc.be.model.tosca.converters;
-import static org.junit.Assert.*;
-
-import com.google.gson.JsonElement;
import com.google.gson.JsonObject;
import org.junit.Before;
import org.junit.Test;
@@ -16,226 +13,175 @@ import java.util.HashMap;
import java.util.Map;
import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertTrue;
-import java.util.*;
-import org.junit.Assert;
+import static org.junit.Assert.assertNull;
public class DataTypePropertyConverterTest {
- private static final String EMPTY_JSON_STR = "{}";
- public static final String PROPERTY2_DEFAULT = "{\"prop1\":\"def1\",\"prop3\":\"def3\"}";
- private DataTypePropertyConverter testInstance = DataTypePropertyConverter.getInstance();
- private Map<String, DataTypeDefinition> dataTypes;
- private DataTypeDefinition noDefaultValue, dataType1, dataType2, dataType3;
- private PropertyDefinition prop1, prop2, prop3, noDefaultProp;
-
- @Before
- public void setUp() throws Exception {
- dataTypes = new HashMap<>();
-
- prop1 = new PropertyDefinition();
- prop1.setDefaultValue("def1");
- prop1.setName("prop1");
-
- prop2 = new PropertyDefinition();
- prop2.setType("dataType1");
- prop2.setName("prop2");
-
- prop3 = new PropertyDefinition();
- prop3.setDefaultValue("def3");
- prop3.setName("prop3");
-
- noDefaultProp = new PropertyDefinition();
- noDefaultProp.setName("noDefaultProp");
-
- noDefaultValue = new DataTypeDefinition();
- noDefaultValue.setProperties(Collections.singletonList(noDefaultProp));
-
- dataType1 = new DataTypeDefinition();
- dataType1.setProperties(Arrays.asList(prop1, prop3));
-
- dataType2 = new DataTypeDefinition();
- dataType2.setDerivedFrom(dataType1);
-
- dataType3 = new DataTypeDefinition();
- dataType3.setProperties(Collections.singletonList(prop2));
- dataType3.setDerivedFrom(noDefaultValue);
-
- dataTypes.put("noDefault", noDefaultValue);
- dataTypes.put("dataType1", dataType1);
- dataTypes.put("dataType2", dataType2);
- dataTypes.put("dataType3", dataType3);
- }
-
- @Test
- public void testGetPropertyDefaultValuesRec_dataTypeNotExist() throws Exception {
- String defaultValue = testInstance.getDataTypePropertiesDefaultValuesRec("someType", dataTypes);
- assertEquals(EMPTY_JSON_STR, defaultValue);
- }
-
- @Test
- public void testGetPropertyDefaultValuesRec_NoDefaultValue() throws Exception {
- String defaultValue = testInstance.getDataTypePropertiesDefaultValuesRec("noDefault", dataTypes);
- assertEquals(EMPTY_JSON_STR, defaultValue);
- }
-
- @Test
- public void testGetPropertyDefaultValuesRec() throws Exception {
- String defaultValue = testInstance.getDataTypePropertiesDefaultValuesRec("dataType1", dataTypes);
- assertEquals(PROPERTY2_DEFAULT, defaultValue);
- }
-
- @Test
- public void testGetPropertyDefaultValuesRec_defaultFromDerivedDataType_derivedDataTypeHasNoDefaults()
- throws Exception {
- dataType2.setDerivedFrom(noDefaultValue);
- String defaultValue = testInstance.getDataTypePropertiesDefaultValuesRec("dataType2", dataTypes);
- assertEquals(EMPTY_JSON_STR, defaultValue);
- }
-
- @Test
- public void testGetPropertyDefaultValuesRec_defaultFromDerivedDataType() throws Exception {
- String defaultValue = testInstance.getDataTypePropertiesDefaultValuesRec("dataType2", dataTypes);
- assertEquals(PROPERTY2_DEFAULT, defaultValue);
- }
-
- @Test
- public void testGetPropertyDefaultValuesRec_defaultFromDataTypesOfProperties_dataTypeOfPropertyHasNoDefault()
- throws Exception {
- dataType3.getProperties().get(0).setType(noDefaultValue.getName());
- String defaultValue = testInstance.getDataTypePropertiesDefaultValuesRec("dataType3", dataTypes);
- assertEquals(EMPTY_JSON_STR, defaultValue);
- }
-
- @Test
- public void testGetPropertyDefaultValuesRec_defaultFromDataTypesOfProperties() throws Exception {
- String defaultValue = testInstance.getDataTypePropertiesDefaultValuesRec("dataType3", dataTypes);
- assertEquals("{\"prop2\":" + PROPERTY2_DEFAULT + "}", defaultValue);// data
- // type
- // 3
- // has
- // property
- // prop2
- // which
- // has
- // a
- // data
- // type
- // with
- // property
- // prop1
- // which
- // has
- // a
- // default
- // value
- }
-
- @Test
- public void testMergeDefaultValues_allDefaultValuesAreOverridden() throws Exception {
- JsonObject value = new JsonObject();
- value.addProperty(noDefaultProp.getName(), "override1");
-
- JsonObject prop1Val = new JsonObject();
- prop1Val.addProperty(prop1.getName(), "prop1Override");
-
- JsonObject prop3Val = new JsonObject();
- prop3Val.addProperty(prop3.getName(), "prop3Override");
-
- JsonObject prop2Value = new JsonObject();
- prop2Value.add(prop3.getName(), prop3Val);
- prop2Value.add(prop1.getName(), prop1Val);
-
- value.add(prop2.getName(), prop2Value);
-
- String valBeforeMerge = value.toString();
-
- testInstance.mergeDataTypeDefaultValuesWithPropertyValue(value, "dataType3", dataTypes);
- assertEquals(valBeforeMerge, value.toString());
- }
-
- @Test
- public void testMergeDefaultValues() throws Exception {
- JsonObject value = new JsonObject();
- value.addProperty(noDefaultProp.getName(), "override1");
-
- JsonObject prop1Val = new JsonObject();
- prop1Val.addProperty(prop1.getName(), "prop1Override");
-
- value.add(prop2.getName(), prop1Val);
-
- testInstance.mergeDataTypeDefaultValuesWithPropertyValue(value, "dataType3", dataTypes);
-
- assertEquals("{\"noDefaultProp\":\"override1\",\"prop2\":{\"prop1\":\"prop1Override\",\"prop3\":\"def3\"}}",
- value.toString());// expect to merge prop 3 default as it was
- // not overridden
- }
-
- @Test
- public void testMergeDefaultValues_mergeAll() throws Exception {
- JsonObject value = new JsonObject();
- testInstance.mergeDataTypeDefaultValuesWithPropertyValue(value, "dataType3", dataTypes);
-
- assertEquals("{\"prop2\":" + PROPERTY2_DEFAULT + "}", value.toString());// expect
- // to
- // merge
- // prop
- // 3
- // default
- // as
- // it
- // was
- // not
- // overridden
- }
-
- @Test
- public void testMergeDefaultValues_doNotAddDefaultsForGetInputValues() throws Exception {
-
- JsonObject getInputValue = new JsonObject();
- getInputValue.addProperty("get_input", "in1");
-
- JsonObject value = new JsonObject();
- value.add(prop2.getName(), getInputValue);
-
- testInstance.mergeDataTypeDefaultValuesWithPropertyValue(value, "dataType3", dataTypes);
-
- assertEquals("{\"prop2\":{\"get_input\":\"in1\"}}", value.toString());
- }
-
- @Test
- public void testMergeDefaultValues_doNotAddDefaultsForGetInputInnerValues() throws Exception {
- JsonObject getInputValue = new JsonObject();
- getInputValue.addProperty("get_input", "in1");
+ private static final String EMPTY_JSON_STR = "{}";
+ public static final String PROPERTY2_DEFAULT = "{\"prop1\":\"def1\",\"prop3\":\"def3\"}";
+ private DataTypePropertyConverter testInstance = DataTypePropertyConverter.getInstance();
+ private Map<String, DataTypeDefinition> dataTypes;
+ private DataTypeDefinition noDefaultValue, dataType1, dataType2, dataType3;
+ private PropertyDefinition prop1, prop2, prop3, noDefaultProp;
+
+ @Before
+ public void setUp() throws Exception {
+ dataTypes = new HashMap<>();
+
+ prop1 = new PropertyDefinition();
+ prop1.setDefaultValue("def1");
+ prop1.setName("prop1");
+
+ prop2 = new PropertyDefinition();
+ prop2.setType("dataType1");
+ prop2.setName("prop2");
+
+ prop3 = new PropertyDefinition();
+ prop3.setDefaultValue("def3");
+ prop3.setName("prop3");
+
+ noDefaultProp = new PropertyDefinition();
+ noDefaultProp.setName("noDefaultProp");
+
+ noDefaultValue = new DataTypeDefinition();
+ noDefaultValue.setProperties(Collections.singletonList(noDefaultProp));
+
+ dataType1 = new DataTypeDefinition();
+ dataType1.setProperties(Arrays.asList(prop1, prop3));
+
+ dataType2 = new DataTypeDefinition();
+ dataType2.setDerivedFrom(dataType1);
+
+ dataType3 = new DataTypeDefinition();
+ dataType3.setProperties(Collections.singletonList(prop2));
+ dataType3.setDerivedFrom(noDefaultValue);
+
+ dataTypes.put("noDefault", noDefaultValue);
+ dataTypes.put("dataType1", dataType1);
+ dataTypes.put("dataType2", dataType2);
+ dataTypes.put("dataType3", dataType3);
+ }
+
+ @Test
+ public void testGetPropertyDefaultValuesRec_dataTypeNotExist() throws Exception {
+ String defaultValue = testInstance.getDataTypePropertiesDefaultValuesRec("someType", dataTypes);
+ assertNull(defaultValue);
+ }
+
+ @Test
+ public void testGetPropertyDefaultValuesRec_NoDefaultValue() throws Exception {
+ String defaultValue = testInstance.getDataTypePropertiesDefaultValuesRec("noDefault", dataTypes);
+ assertNull(defaultValue);
+ }
+
+ @Test
+ public void testGetPropertyDefaultValuesRec() throws Exception {
+ String defaultValue = testInstance.getDataTypePropertiesDefaultValuesRec("dataType1", dataTypes);
+ assertEquals(PROPERTY2_DEFAULT, defaultValue);
+ }
+
+ @Test
+ public void testGetPropertyDefaultValuesRec_defaultFromDerivedDataType_derivedDataTypeHasNoDefaults() throws Exception {
+ dataType2.setDerivedFrom(noDefaultValue);
+ String defaultValue = testInstance.getDataTypePropertiesDefaultValuesRec("dataType2", dataTypes);
+ assertNull(defaultValue);
+ }
+
+ @Test
+ public void testGetPropertyDefaultValuesRec_defaultFromDerivedDataType() throws Exception {
+ String defaultValue = testInstance.getDataTypePropertiesDefaultValuesRec("dataType2", dataTypes);
+ assertEquals(PROPERTY2_DEFAULT, defaultValue);
+ }
+
+ @Test
+ public void testGetPropertyDefaultValuesRec_defaultFromDataTypesOfProperties_dataTypeOfPropertyHasNoDefault() throws Exception {
+ dataType3.getProperties().get(0).setType(noDefaultValue.getName());
+ String defaultValue = testInstance.getDataTypePropertiesDefaultValuesRec("dataType3", dataTypes);
+ assertNull(defaultValue);
+ }
+
+ @Test
+ public void testGetPropertyDefaultValuesRec_defaultFromDataTypesOfProperties() throws Exception {
+ String defaultValue = testInstance.getDataTypePropertiesDefaultValuesRec("dataType3", dataTypes);
+ assertEquals("{\"prop2\":" + PROPERTY2_DEFAULT + "}", defaultValue);//data type 3 has property prop2 which has a data type with property prop1 which has a default value
+ }
+
+ @Test
+ public void testMergeDefaultValues_allDefaultValuesAreOverridden() throws Exception {
+ JsonObject value = new JsonObject();
+ value.addProperty(noDefaultProp.getName(), "override1");
+
+ JsonObject prop1Val = new JsonObject();
+ prop1Val.addProperty(prop1.getName(), "prop1Override");
+
+ JsonObject prop3Val = new JsonObject();
+ prop3Val.addProperty(prop3.getName(), "prop3Override");
+
+ JsonObject prop2Value = new JsonObject();
+ prop2Value.add(prop3.getName(), prop3Val);
+ prop2Value.add(prop1.getName(), prop1Val);
+
+ value.add(prop2.getName(), prop2Value);
+
+ String valBeforeMerge = value.toString();
+
+ testInstance.mergeDataTypeDefaultValuesWithPropertyValue(value, "dataType3", dataTypes);
+ assertEquals(valBeforeMerge, value.toString());
+ }
+
+ @Test
+ public void testMergeDefaultValues() throws Exception {
+ JsonObject value = new JsonObject();
+ value.addProperty(noDefaultProp.getName(), "override1");
+
+ JsonObject prop1Val = new JsonObject();
+ prop1Val.addProperty(prop1.getName(), "prop1Override");
+
+ value.add(prop2.getName(), prop1Val);
+
+ testInstance.mergeDataTypeDefaultValuesWithPropertyValue(value, "dataType3", dataTypes);
+
+ assertEquals("{\"noDefaultProp\":\"override1\",\"prop2\":{\"prop1\":\"prop1Override\",\"prop3\":\"def3\"}}",
+ value.toString());//expect to merge prop 3 default as it was not overridden
+ }
+
+ @Test
+ public void testMergeDefaultValues_mergeAll() throws Exception {
+ JsonObject value = new JsonObject();
+ testInstance.mergeDataTypeDefaultValuesWithPropertyValue(value, "dataType3", dataTypes);
- JsonObject prop1Val = new JsonObject();
- prop1Val.add(prop1.getName(), getInputValue);
+ assertEquals("{\"prop2\":" + PROPERTY2_DEFAULT + "}",
+ value.toString());//expect to merge prop 3 default as it was not overridden
+ }
- JsonObject value = new JsonObject();
- value.add(prop2.getName(), prop1Val);
+ @Test
+ public void testMergeDefaultValues_doNotAddDefaultsForGetInputValues() throws Exception {
- testInstance.mergeDataTypeDefaultValuesWithPropertyValue(value, "dataType3", dataTypes);
+ JsonObject getInputValue = new JsonObject();
+ getInputValue.addProperty("get_input", "in1");
- assertEquals("{\"prop2\":{\"prop1\":{\"get_input\":\"in1\"},\"prop3\":\"def3\"}}", value.toString());
+ JsonObject value = new JsonObject();
+ value.add(prop2.getName(), getInputValue);
- }
+ testInstance.mergeDataTypeDefaultValuesWithPropertyValue(value, "dataType3", dataTypes);
- private DataTypePropertyConverter createTestSubject() {
- return DataTypePropertyConverter.getInstance();
- }
+ assertEquals("{\"prop2\":{\"get_input\":\"in1\"}}", value.toString());
+ }
-
- @Test
- public void testGetInstance() throws Exception {
- DataTypePropertyConverter result;
+ @Test
+ public void testMergeDefaultValues_doNotAddDefaultsForGetInputInnerValues() throws Exception {
+ JsonObject getInputValue = new JsonObject();
+ getInputValue.addProperty("get_input", "in1");
- // default test
- result = DataTypePropertyConverter.getInstance();
- }
+ JsonObject prop1Val = new JsonObject();
+ prop1Val.add(prop1.getName(), getInputValue);
-
+ JsonObject value = new JsonObject();
+ value.add(prop2.getName(), prop1Val);
+ testInstance.mergeDataTypeDefaultValuesWithPropertyValue(value, "dataType3", dataTypes);
-
+ assertEquals("{\"prop2\":{\"prop1\":{\"get_input\":\"in1\"},\"prop3\":\"def3\"}}", value.toString());
+ }
}
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 367b806104..9022e7246e 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
@@ -54,5 +54,8 @@ public class JsonUtils {
public static boolean isEmptyJson(JsonElement json) {
return json.isJsonPrimitive() ? false : JsonUtils.isEmptyJson(json.getAsJsonObject());
}
-
+
+ public static boolean isJsonNullOrEmpty(JsonObject json) {
+ return json.isJsonNull() || isEmptyJson(json);
+ }
}