summaryrefslogtreecommitdiffstats
path: root/catalog-model/src
diff options
context:
space:
mode:
Diffstat (limited to 'catalog-model/src')
-rw-r--r--catalog-model/src/main/java/org/openecomp/sdc/be/model/Component.java13
-rw-r--r--catalog-model/src/main/java/org/openecomp/sdc/be/model/ComponentInstListInput.java66
-rw-r--r--catalog-model/src/main/java/org/openecomp/sdc/be/model/ComponentParametersView.java232
-rw-r--r--catalog-model/src/main/java/org/openecomp/sdc/be/model/DataTypeDefinition.java2
-rw-r--r--catalog-model/src/main/java/org/openecomp/sdc/be/model/jsontitan/datamodel/TopologyTemplate.java18
-rw-r--r--catalog-model/src/main/java/org/openecomp/sdc/be/model/jsontitan/operations/TopologyTemplateOperation.java48
-rw-r--r--catalog-model/src/main/java/org/openecomp/sdc/be/model/jsontitan/operations/ToscaOperationFacade.java82
-rw-r--r--catalog-model/src/main/java/org/openecomp/sdc/be/model/jsontitan/utils/ModelConverter.java26
-rw-r--r--catalog-model/src/test/java/org/openecomp/sdc/be/model/ComponentParametersViewTest.java24
-rw-r--r--catalog-model/src/test/java/org/openecomp/sdc/be/model/jsontitan/datamodel/TopologyTemplateTest.java20
-rw-r--r--catalog-model/src/test/java/org/openecomp/sdc/be/model/jsontitan/operations/TopologyTemplateOperationTest.java24
-rw-r--r--catalog-model/src/test/java/org/openecomp/sdc/be/model/jsontitan/operations/ToscaOperationFacadeTest.java104
12 files changed, 525 insertions, 134 deletions
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 65ad149a89..b65997cb35 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
@@ -51,6 +51,8 @@ import org.openecomp.sdc.be.model.category.SubCategoryDefinition;
import org.openecomp.sdc.be.model.jsontitan.datamodel.ToscaElementTypeEnum;
import org.openecomp.sdc.common.api.ArtifactTypeEnum;
+import static java.util.stream.Collectors.toMap;
+
public abstract class Component implements PropertiesOwner {
private ComponentMetadataDefinition componentMetadataDefinition;
@@ -78,8 +80,17 @@ public abstract class Component implements PropertiesOwner {
private Map<String, List<UploadNodeFilterInfo>> serviceFilters;
protected List<PropertyDefinition> properties;
private Map<String, InterfaceDefinition> interfaces;
+ private List<DataTypeDefinition> dataTypes;
+
+ public List<DataTypeDefinition> getDataTypes() {
+ return dataTypes;
+ }
+
+ public void setDataTypes(List<DataTypeDefinition> dataTypes) {
+ this.dataTypes = dataTypes;
+ }
- public Map<String, InterfaceDefinition> getInterfaces() {
+ public Map<String, InterfaceDefinition> getInterfaces() {
return interfaces;
}
diff --git a/catalog-model/src/main/java/org/openecomp/sdc/be/model/ComponentInstListInput.java b/catalog-model/src/main/java/org/openecomp/sdc/be/model/ComponentInstListInput.java
new file mode 100644
index 0000000000..ee4bef2236
--- /dev/null
+++ b/catalog-model/src/main/java/org/openecomp/sdc/be/model/ComponentInstListInput.java
@@ -0,0 +1,66 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * SDC
+ * ================================================================================
+ * Copyright (C) 2019 Fujitsu Limited. All rights reserved.
+ * ================================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * ============LICENSE_END=========================================================
+ */
+
+package org.openecomp.sdc.be.model;
+
+/**
+ * Represents a pair of a list of properties to be declared and a "list input" to be created.
+ * This class is used for passing parameters on creating a list input.
+ */
+public class ComponentInstListInput {
+ private ComponentInstInputsMap componentInstInputsMap;
+ private InputDefinition listInput;
+
+ /**
+ * Gets componentInstInputsMap which includes properties to be declared.
+ *
+ * @return componentInstInputsMap
+ */
+ public ComponentInstInputsMap getComponentInstInputsMap() {
+ return componentInstInputsMap;
+ }
+
+ /**
+ * Sets componentInstInputsMap.
+ *
+ * @param componentInstInputsMap
+ */
+ public void setComponentInstInputsMap(ComponentInstInputsMap componentInstInputsMap) {
+ this.componentInstInputsMap = componentInstInputsMap;
+ }
+
+ /**
+ * Gets the input to be created.
+ *
+ * @return the list input
+ */
+ public InputDefinition getListInput() {
+ return listInput;
+ }
+
+ /**
+ * Sets the input to be created.
+ *
+ * @param listInput
+ */
+ public void setListInput(InputDefinition listInput) {
+ this.listInput = listInput;
+ }
+}
diff --git a/catalog-model/src/main/java/org/openecomp/sdc/be/model/ComponentParametersView.java b/catalog-model/src/main/java/org/openecomp/sdc/be/model/ComponentParametersView.java
index 05d9a572a3..3edb8ded6c 100644
--- a/catalog-model/src/main/java/org/openecomp/sdc/be/model/ComponentParametersView.java
+++ b/catalog-model/src/main/java/org/openecomp/sdc/be/model/ComponentParametersView.java
@@ -51,6 +51,7 @@ public class ComponentParametersView {
private boolean ignorePolicies = false;
private boolean ignoreNodeFilterRequirements = false;
private boolean ignoreNodeFilter = false;
+ private boolean ignoreDataType = false;
public ComponentParametersView() {
}
@@ -154,6 +155,9 @@ public class ComponentParametersView {
this.setIgnoreComponentInstances(false);
this.setIgnoreComponentInstancesInterfaces(false);
break;
+ case DATA_TYPES:
+ this.setIgnoreDataType(false);
+ break;
default:
break;
}
@@ -167,120 +171,114 @@ public class ComponentParametersView {
public Component filter(Component component, ComponentTypeEnum componentType) {
- if (ignoreUsers) {
- component.setCreatorUserId(null);
- component.setCreatorFullName(null);
- component.setLastUpdaterUserId(null);
- component.setLastUpdaterFullName(null);
- }
-
- if (ignoreGroups) {
- component.setGroups(null);
- }
-
- if (ignoreComponentInstances) {
- component.setComponentInstances(null);
- component.setComponentInstancesRelations(null);
- }
-
- if (ignoreComponentInstancesProperties) {
- component.setComponentInstancesProperties(null);
- }
-
- if (ignoreProperties && componentType == ComponentTypeEnum.RESOURCE) {
- ((Resource) component).setProperties(null);
- }
-
- if (ignoreCapabilities) {
- component.setCapabilities(null);
- }
-
- if (ignoreRequirements) {
- component.setRequirements(null);
- }
-
- if (ignoreCategories) {
- component.setCategories(null);
- }
-
- if (ignoreAllVersions) {
- component.setAllVersions(null);
- }
- if (ignoreAdditionalInformation && componentType == ComponentTypeEnum.RESOURCE) {
- ((Resource) component).setAdditionalInformation(null);
- }
-
- if (ignoreArtifacts) {
- component.setArtifacts(null);
- component.setSpecificComponetTypeArtifacts(null);
- component.setDeploymentArtifacts(null);
- component.setToscaArtifacts(null);
- }
- if (ignoreNodeFilterRequirements){
- component.setNodeFilterComponents(null);
- }
- if (ignoreInterfaces && ignoreInterfaceInstances &&
- componentType == ComponentTypeEnum.RESOURCE) {
- component.setInterfaces(null);
- }
- if (ignoreDerivedFrom && componentType == ComponentTypeEnum.RESOURCE) {
- ((Resource) component).setDerivedFrom(null);
- }
- if (ignoreAttributesFrom && componentType == ComponentTypeEnum.RESOURCE) {
- ((Resource) component).setAttributes(null);
- }
- if (ignoreComponentInstancesAttributesFrom) {
- component.setComponentInstancesAttributes(null);
- }
- if (ignoreInputs) {
- component.setInputs(null);
- }
- if (ignoreComponentInstancesInputs) {
- component.setComponentInstancesInputs(null);
- }
- if (ignoreServicePath && componentType == ComponentTypeEnum.SERVICE) {
- ((Service) component).setForwardingPaths(null);
- }
- if (ignoreNodeFilter){
- component.setNodeFilterComponents(null);
- }
- return component;
-
- }
-
- public boolean isIgnoreNodeFilterRequirements() {
- return ignoreNodeFilterRequirements;
- }
-
- public void setIgnoreNodeFilterRequirements(boolean ignoreNodeFilter) {
- this.ignoreNodeFilterRequirements = ignoreNodeFilter;
- }
-
- public void disableAll() {
- ignoreUsers = true;
- ignoreGroups = true;
- ignorePolicies = true;
- ignoreComponentInstances = true;
- ignoreComponentInstancesProperties = true;
- ignoreProperties = true;
- ignoreCapabilities = true;
- ignoreRequirements = true;
- ignoreCategories = true;
- ignoreAllVersions = true;
- ignoreAdditionalInformation = true;
- ignoreArtifacts = true;
- ignoreInterfaces = true;
- ignoreInterfaceInstances = true;
- ignoreDerivedFrom = true;
- ignoreAttributesFrom = true;
- ignoreInputs = true;
- ignoreComponentInstancesAttributesFrom = true;
- ignoreComponentInstancesInputs = true;
- ignoreCapabiltyProperties = true;
- ignoreServicePath = true;
- ignoreNodeFilterRequirements = true;
+ if (ignoreUsers) {
+ component.setCreatorUserId(null);
+ component.setCreatorFullName(null);
+ component.setLastUpdaterUserId(null);
+ component.setLastUpdaterFullName(null);
+ }
+ if (ignoreGroups) {
+ component.setGroups(null);
+ }
+ if (ignoreComponentInstances) {
+ component.setComponentInstances(null);
+ component.setComponentInstancesRelations(null);
+ }
+ if (ignoreComponentInstancesProperties) {
+ component.setComponentInstancesProperties(null);
+ }
+ if (ignoreProperties && componentType == ComponentTypeEnum.RESOURCE) {
+ ((Resource) component).setProperties(null);
+ }
+ if (ignoreCapabilities) {
+ component.setCapabilities(null);
+ }
+ if (ignoreRequirements) {
+ component.setRequirements(null);
+ }
+ if (ignoreCategories) {
+ component.setCategories(null);
+ }
+ if (ignoreAllVersions) {
+ component.setAllVersions(null);
+ }
+ if (ignoreAdditionalInformation && componentType == ComponentTypeEnum.RESOURCE) {
+ ((Resource) component).setAdditionalInformation(null);
+ }
+ if (ignoreArtifacts) {
+ component.setArtifacts(null);
+ component.setSpecificComponetTypeArtifacts(null);
+ component.setDeploymentArtifacts(null);
+ component.setToscaArtifacts(null);
+ }
+ if (ignoreNodeFilterRequirements){
+ component.setNodeFilterComponents(null);
+ }
+ if (ignoreInterfaces && ignoreInterfaceInstances &&
+ componentType == ComponentTypeEnum.RESOURCE) {
+ component.setInterfaces(null);
+ }
+ if (ignoreDerivedFrom && componentType == ComponentTypeEnum.RESOURCE) {
+ ((Resource) component).setDerivedFrom(null);
+ }
+ if (ignoreAttributesFrom && componentType == ComponentTypeEnum.RESOURCE) {
+ ((Resource) component).setAttributes(null);
+ }
+ if (ignoreComponentInstancesAttributesFrom) {
+ component.setComponentInstancesAttributes(null);
+ }
+ if (ignoreInputs) {
+ component.setInputs(null);
+ }
+ if (ignoreComponentInstancesInputs) {
+ component.setComponentInstancesInputs(null);
+ }
+ if (ignoreServicePath && componentType == ComponentTypeEnum.SERVICE) {
+ ((Service) component).setForwardingPaths(null);
+ }
+ if (ignoreNodeFilter){
+ component.setNodeFilterComponents(null);
+ }
+ if (ignoreDataType) {
+ component.setDataTypes(null);
+ }
+ return component;
+ }
+
+ public boolean isIgnoreNodeFilterRequirements() {
+ return ignoreNodeFilterRequirements;
+ }
+
+ public void setIgnoreNodeFilterRequirements(boolean ignoreNodeFilter) {
+ this.ignoreNodeFilterRequirements = ignoreNodeFilter;
+ }
+
+ public void disableAll() {
+ ignoreUsers = true;
+ ignoreGroups = true;
+ ignorePolicies = true;
+ ignoreComponentInstances = true;
+ ignoreComponentInstancesProperties = true;
+ ignoreProperties = true;
+ ignoreCapabilities = true;
+ ignoreRequirements = true;
+ ignoreCategories = true;
+ ignoreAllVersions = true;
+ ignoreAdditionalInformation = true;
+ ignoreArtifacts = true;
+ ignoreInterfaces = true;
+ ignoreInterfaceInstances = true;
+ ignoreDerivedFrom = true;
+ ignoreAttributesFrom = true;
+ ignoreInputs = true;
+ ignoreComponentInstancesAttributesFrom = true;
+ ignoreComponentInstancesInputs = true;
+ ignoreCapabiltyProperties = true;
+ ignoreServicePath = true;
+ ignoreNodeFilterRequirements = true;
ignoreNodeFilter = true;
- }
+ ignoreDataType = true;
+ }
public boolean isIgnoreGroups() {
return ignoreGroups;
@@ -462,6 +460,14 @@ public class ComponentParametersView {
this.ignoreNodeFilter = ignoreNodeFilter;
}
+ public boolean isIgnoreDataType() {
+ return ignoreDataType;
+ }
+
+ public void setIgnoreDataType(boolean ignoreDataType) {
+ this.ignoreDataType = ignoreDataType;
+ }
+
public JsonParseFlagEnum detectParseFlag() {
JsonParseFlagEnum parseFlag;
if (isIgnoreComponentInstances()) {
diff --git a/catalog-model/src/main/java/org/openecomp/sdc/be/model/DataTypeDefinition.java b/catalog-model/src/main/java/org/openecomp/sdc/be/model/DataTypeDefinition.java
index 44c6b7b82e..4dc952d59b 100644
--- a/catalog-model/src/main/java/org/openecomp/sdc/be/model/DataTypeDefinition.java
+++ b/catalog-model/src/main/java/org/openecomp/sdc/be/model/DataTypeDefinition.java
@@ -21,8 +21,10 @@
package org.openecomp.sdc.be.model;
import org.openecomp.sdc.be.datatypes.elements.DataTypeDataDefinition;
+import org.openecomp.sdc.be.datatypes.elements.PropertyDataDefinition;
import java.util.List;
+import java.util.stream.Collectors;
public class DataTypeDefinition extends DataTypeDataDefinition {
diff --git a/catalog-model/src/main/java/org/openecomp/sdc/be/model/jsontitan/datamodel/TopologyTemplate.java b/catalog-model/src/main/java/org/openecomp/sdc/be/model/jsontitan/datamodel/TopologyTemplate.java
index 14b7a2f786..8c0253a148 100644
--- a/catalog-model/src/main/java/org/openecomp/sdc/be/model/jsontitan/datamodel/TopologyTemplate.java
+++ b/catalog-model/src/main/java/org/openecomp/sdc/be/model/jsontitan/datamodel/TopologyTemplate.java
@@ -25,6 +25,7 @@ import org.openecomp.sdc.be.datatypes.elements.*;
import org.openecomp.sdc.be.datatypes.elements.MapCapabilityProperty;
import org.openecomp.sdc.be.datatypes.elements.MapListCapabilityDataDefinition;
import org.openecomp.sdc.be.datatypes.tosca.ToscaDataDefinition;
+import org.openecomp.sdc.be.model.DataTypeDefinition;
import org.openecomp.sdc.be.model.MapInterfaceInstanceDataDefinition;
import org.openecomp.sdc.be.model.jsontitan.enums.JsonConstantKeysEnum;
@@ -57,6 +58,7 @@ public class TopologyTemplate extends ToscaElement{
private Map<String, InterfaceDataDefinition> interfaces;
private Map<String, MapInterfaceInstanceDataDefinition> instInterfaces;
private Map<String, MapInterfaceDataDefinition> componentInstInterfaces;
+ private Map<String, DataTypeDataDefinition> dataTypes;
private Map<String, CINodeFilterDataDefinition> nodeFilterComponents;
//Component Instances External References (instanceId -> ExternalRefsMap)
@@ -239,6 +241,22 @@ public class TopologyTemplate extends ToscaElement{
this.nodeFilterComponents = nodeFilters;
}
+ /**
+ * Gets data types.
+ * @return Current data types.
+ */
+ public Map<String, DataTypeDataDefinition> getDataTypes() {
+ return dataTypes;
+ }
+
+ /**
+ * Sets data types.
+ * @param dataTypes New data types.
+ */
+ public void setDataTypes(Map<String, DataTypeDataDefinition> dataTypes) {
+ this.dataTypes = dataTypes;
+ }
+
/**
* Adds component instance to composition of topology template
* Note that component instance will be overrided in case if the topology template already contains a component instance with the same name
diff --git a/catalog-model/src/main/java/org/openecomp/sdc/be/model/jsontitan/operations/TopologyTemplateOperation.java b/catalog-model/src/main/java/org/openecomp/sdc/be/model/jsontitan/operations/TopologyTemplateOperation.java
index 417577320c..b0bfc153f4 100644
--- a/catalog-model/src/main/java/org/openecomp/sdc/be/model/jsontitan/operations/TopologyTemplateOperation.java
+++ b/catalog-model/src/main/java/org/openecomp/sdc/be/model/jsontitan/operations/TopologyTemplateOperation.java
@@ -22,19 +22,8 @@ package org.openecomp.sdc.be.model.jsontitan.operations;
import com.google.gson.reflect.TypeToken;
import fj.data.Either;
-import java.lang.reflect.Type;
-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.Optional;
-import java.util.Set;
-import java.util.stream.Collectors;
import org.apache.commons.collections.MapUtils;
+import org.apache.commons.lang.builder.ReflectionToStringBuilder;
import org.apache.tinkerpop.gremlin.structure.Direction;
import org.apache.tinkerpop.gremlin.structure.Edge;
import org.openecomp.sdc.be.dao.jsongraph.GraphVertex;
@@ -47,6 +36,7 @@ import org.openecomp.sdc.be.datatypes.elements.ArtifactDataDefinition;
import org.openecomp.sdc.be.datatypes.elements.CINodeFilterDataDefinition;
import org.openecomp.sdc.be.datatypes.elements.ComponentInstanceDataDefinition;
import org.openecomp.sdc.be.datatypes.elements.CompositionDataDefinition;
+import org.openecomp.sdc.be.datatypes.elements.DataTypeDataDefinition;
import org.openecomp.sdc.be.datatypes.elements.ForwardingPathDataDefinition;
import org.openecomp.sdc.be.datatypes.elements.GroupDataDefinition;
import org.openecomp.sdc.be.datatypes.elements.InterfaceDataDefinition;
@@ -72,7 +62,6 @@ import org.openecomp.sdc.be.model.ComponentInstanceProperty;
import org.openecomp.sdc.be.model.ComponentParametersView;
import org.openecomp.sdc.be.model.DistributionStatusEnum;
import org.openecomp.sdc.be.model.GroupDefinition;
-
import org.openecomp.sdc.be.model.PolicyDefinition;
import org.openecomp.sdc.be.model.User;
import org.openecomp.sdc.be.model.category.CategoryDefinition;
@@ -92,6 +81,19 @@ import org.openecomp.sdc.common.log.wrappers.Logger;
import org.openecomp.sdc.common.util.ValidationUtils;
import org.springframework.beans.factory.annotation.Autowired;
+import java.lang.reflect.Type;
+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.Optional;
+import java.util.Set;
+import java.util.stream.Collectors;
+
@org.springframework.stereotype.Component("topology-template-operation")
public class TopologyTemplateOperation extends ToscaElementOperation {
@@ -777,9 +779,29 @@ public class TopologyTemplateOperation extends ToscaElementOperation {
return Either.right(DaoStatusConverter.convertTitanStatusToStorageStatus(storageStatus));
}
}
+
+ if (!componentParametersView.isIgnoreDataType()) {
+ TitanOperationStatus storageStatus = setDataTypesFromGraph(componentV, toscaElement);
+ if (storageStatus != TitanOperationStatus.OK) {
+ return Either.right(DaoStatusConverter.convertTitanStatusToStorageStatus(storageStatus));
+ }
+ }
+
return Either.left(toscaElement);
}
+ private TitanOperationStatus setDataTypesFromGraph(GraphVertex componentV, TopologyTemplate toscaElement) {
+ Either<Map<String, DataTypeDataDefinition>, TitanOperationStatus> result = getDataFromGraph(componentV, EdgeLabelEnum.DATA_TYPES);
+ if (result.isLeft()) {
+ toscaElement.setDataTypes(result.left().value());
+ } else {
+ if (result.right().value() != TitanOperationStatus.NOT_FOUND) {
+ return result.right().value();
+ }
+ }
+ return TitanOperationStatus.OK;
+ }
+
private TitanOperationStatus setPoliciesFromGraph(GraphVertex componentV, TopologyTemplate toscaElement) {
Either<Map<String, PolicyDataDefinition>, TitanOperationStatus> result = getDataFromGraph(componentV, EdgeLabelEnum.POLICIES);
if (result.isLeft()) {
diff --git a/catalog-model/src/main/java/org/openecomp/sdc/be/model/jsontitan/operations/ToscaOperationFacade.java b/catalog-model/src/main/java/org/openecomp/sdc/be/model/jsontitan/operations/ToscaOperationFacade.java
index 10dd919fc7..8456486bef 100644
--- a/catalog-model/src/main/java/org/openecomp/sdc/be/model/jsontitan/operations/ToscaOperationFacade.java
+++ b/catalog-model/src/main/java/org/openecomp/sdc/be/model/jsontitan/operations/ToscaOperationFacade.java
@@ -20,6 +20,7 @@
package org.openecomp.sdc.be.model.jsontitan.operations;
+import com.datastax.driver.core.DataType;
import fj.data.Either;
import org.apache.commons.collections.CollectionUtils;
import org.apache.commons.collections.MapUtils;
@@ -46,6 +47,7 @@ import org.openecomp.sdc.be.model.operations.api.StorageOperationStatus;
import org.openecomp.sdc.be.model.operations.impl.DaoStatusConverter;
import org.openecomp.sdc.be.model.operations.impl.UniqueIdBuilder;
import org.openecomp.sdc.be.resources.data.ComponentMetadataData;
+import org.openecomp.sdc.be.resources.data.DataTypeData;
import org.openecomp.sdc.common.jsongraph.util.CommonUtility;
import org.openecomp.sdc.common.jsongraph.util.CommonUtility.LogLevelEnum;
import org.openecomp.sdc.common.log.wrappers.Logger;
@@ -171,6 +173,7 @@ public class ToscaOperationFacade {
VertexTypeEnum label = componentV.getLabel();
ToscaElementOperation toscaOperation = getToscaElementOperation(componentV);
+ log.debug("getToscaElementByOperation: toscaOperation={}", toscaOperation.getClass());
Either<ToscaElement, StorageOperationStatus> toscaElement;
String componentId = componentV.getUniqueId();
if (toscaOperation != null) {
@@ -971,7 +974,74 @@ public class ToscaOperationFacade {
}
- public Either<List<InputDefinition>, StorageOperationStatus> getComponentInputs(String componentId) {
+ /**
+ * Add data types into a Component.
+ *
+ * @param dataTypes datatypes to be added. the key should be each name of data type.
+ * @param componentId unique ID of Component.
+ * @return list of data types.
+ */
+ public Either<List<DataTypeDefinition>, StorageOperationStatus> addDataTypesToComponent(Map<String, DataTypeDefinition> dataTypes, String componentId) {
+
+ log.trace("#addDataTypesToComponent - enter, componentId={}", componentId);
+
+ /* get component vertex */
+ Either<GraphVertex, TitanOperationStatus> getVertexEither = titanDao.getVertexById(componentId, JsonParseFlagEnum.NoParse);
+ if (getVertexEither.isRight()) {
+ /* not found / error */
+ log.debug(COULDNT_FETCH_COMPONENT_WITH_AND_UNIQUE_ID_ERROR, componentId, getVertexEither.right().value());
+ return Either.right(DaoStatusConverter.convertTitanStatusToStorageStatus(getVertexEither.right().value()));
+ }
+ GraphVertex vertex = getVertexEither.left().value();
+ log.trace("#addDataTypesToComponent - get vertex ok");
+
+ // convert DataTypeDefinition to DataTypeDataDefinition
+ Map<String, DataTypeDataDefinition> dataTypeDataMap = dataTypes.entrySet().stream()
+ .collect(Collectors.toMap(Map.Entry::getKey, e -> convertDataTypeToDataTypeData(e.getValue())));
+
+ // add datatype(s) to the Component.
+ // if child vertex does not exist, it will be created.
+ StorageOperationStatus status = topologyTemplateOperation.addToscaDataToToscaElement(vertex,
+ EdgeLabelEnum.DATA_TYPES, VertexTypeEnum.DATA_TYPES, dataTypeDataMap, JsonPresentationFields.NAME);
+
+ if (StorageOperationStatus.OK == status) {
+ log.debug(COMPONENT_CREATED_SUCCESSFULLY);
+ List<DataTypeDefinition> inputsResList = null;
+ if (!dataTypes.isEmpty()) {
+ inputsResList = new ArrayList<>(dataTypes.values());
+ }
+ return Either.left(inputsResList);
+ }
+
+ log.trace("#addDataTypesToComponent - leave");
+ return Either.right(status);
+ }
+
+ private DataTypeDataDefinition convertDataTypeToDataTypeData(DataTypeDefinition dataType) {
+ DataTypeDataDefinition dataTypeData = new DataTypeDataDefinition(dataType);
+ if (CollectionUtils.isNotEmpty(dataType.getProperties())) {
+ List<PropertyDataDefinition> propertyDataList = dataType.getProperties().stream()
+ .map(PropertyDataDefinition::new).collect(Collectors.toList());
+ dataTypeData.setPropertiesData(propertyDataList);
+ }
+
+ // if "derivedFrom" data_type exists, copy the name to "derivedFromName"
+ if (dataType.getDerivedFrom() != null && StringUtils.isNotEmpty(dataType.getDerivedFrom().getName())) {
+ // if names are different, log it
+ if (!StringUtils.equals(dataTypeData.getDerivedFromName(), dataType.getDerivedFrom().getName())) {
+ log.debug("#convertDataTypeToDataTypeData - derivedFromName(={}) overwritten by derivedFrom.name(={})",
+ dataType.getDerivedFromName(), dataType.getDerivedFrom().getName());
+ }
+ dataTypeData.setDerivedFromName(dataType.getDerivedFrom().getName());
+ }
+
+ // supply "name" field to toscaPresentationValue in each datatype object for DAO operations
+ dataTypeData.setToscaPresentationValue(JsonPresentationFields.NAME, dataType.getName());
+ return dataTypeData;
+ }
+
+
+ public Either<List<InputDefinition>, StorageOperationStatus> getComponentInputs(String componentId) {
Either<GraphVertex, TitanOperationStatus> getVertexEither = titanDao.getVertexById(componentId, JsonParseFlagEnum.NoParse);
if (getVertexEither.isRight()) {
@@ -2068,6 +2138,16 @@ public class ToscaOperationFacade {
return getToscaElementOperation(resource).deleteToscaDataElement(resource.getUniqueId(), EdgeLabelEnum.INPUTS, VertexTypeEnum.INPUTS, inputName, JsonPresentationFields.NAME);
}
+ /**
+ * Deletes a data type from a component.
+ * @param component the container which has the data type
+ * @param dataTypeName the data type name to be deleted
+ * @return Operation result.
+ */
+ public StorageOperationStatus deleteDataTypeOfComponent(Component component, String dataTypeName) {
+ return getToscaElementOperation(component).deleteToscaDataElement(component.getUniqueId(), EdgeLabelEnum.DATA_TYPES, VertexTypeEnum.DATA_TYPES, dataTypeName, JsonPresentationFields.NAME);
+ }
+
public Either<PropertyDefinition, StorageOperationStatus> updatePropertyOfComponent(Component component,
PropertyDefinition newPropertyDefinition) {
diff --git a/catalog-model/src/main/java/org/openecomp/sdc/be/model/jsontitan/utils/ModelConverter.java b/catalog-model/src/main/java/org/openecomp/sdc/be/model/jsontitan/utils/ModelConverter.java
index 808fdbd4f6..cfd00a5313 100644
--- a/catalog-model/src/main/java/org/openecomp/sdc/be/model/jsontitan/utils/ModelConverter.java
+++ b/catalog-model/src/main/java/org/openecomp/sdc/be/model/jsontitan/utils/ModelConverter.java
@@ -23,9 +23,11 @@ package org.openecomp.sdc.be.model.jsontitan.utils;
import com.google.common.collect.Lists;
import com.google.common.collect.Maps;
import org.apache.commons.collections.CollectionUtils;
+import org.apache.commons.collections.ListUtils;
import org.apache.commons.collections.MapUtils;
import org.apache.commons.lang.BooleanUtils;
import org.apache.commons.lang3.StringUtils;
+import org.apache.commons.lang3.builder.ReflectionToStringBuilder;
import org.openecomp.sdc.be.dao.jsongraph.GraphVertex;
import org.openecomp.sdc.be.dao.jsongraph.types.VertexTypeEnum;
import org.openecomp.sdc.be.datatypes.elements.*;
@@ -152,6 +154,8 @@ public class ModelConverter {
convertServiceInterfaces(topologyTemplate, service);
+ convertDataTypes(topologyTemplate, service);
+
convertNodeFiltersComponents(topologyTemplate, service);
setCapabilitiesToComponent(topologyTemplate, service);
setRequirementsToComponent(topologyTemplate, service);
@@ -205,6 +209,7 @@ public class ModelConverter {
convertProperties(topologyTemplate, resource);
setCapabilitiesToComponent(topologyTemplate, resource);
setRequirementsToComponent(topologyTemplate, resource);
+ convertDataTypes(topologyTemplate, resource);
}
convertArtifacts(toscaElement, resource);
convertAdditionalInformation(toscaElement, resource);
@@ -1106,6 +1111,26 @@ public class ModelConverter {
}
}
+ private static void convertDataTypes(TopologyTemplate topologyTemplate, Component component) {
+ Map<String, DataTypeDataDefinition> dataTypeDataMap = topologyTemplate.getDataTypes();
+ if (MapUtils.isNotEmpty(dataTypeDataMap)) {
+ List<DataTypeDefinition> dataTypeMap = dataTypeDataMap.values().stream().map(e -> {
+ DataTypeDefinition dataType = new DataTypeDefinition(e);
+
+ if(CollectionUtils.isNotEmpty(e.getPropertiesData())) {
+ log.debug("#convertDataTypes - propertiesData is not null. {}",
+ ReflectionToStringBuilder.toString(e.getPropertiesData()));
+ dataType.setProperties(e.getPropertiesData().stream()
+ .map(PropertyDefinition::new).collect(Collectors.toList()));
+ } else {
+ log.debug("#convertDataTypes - propertiesData is null. ignore.");
+ }
+ return dataType;
+ }).collect(Collectors.toList());
+ component.setDataTypes(dataTypeMap);
+ }
+ }
+
private static void convertCommonToscaData(Component component, ToscaElement toscaElement) {
toscaElement.setUUID(component.getUUID());
@@ -1168,6 +1193,7 @@ public class ModelConverter {
+
private static void setComponentInstancesToComponent(TopologyTemplate topologyTemplate, Component component) {
List<ComponentInstance> componentInstances = new ArrayList<>();
diff --git a/catalog-model/src/test/java/org/openecomp/sdc/be/model/ComponentParametersViewTest.java b/catalog-model/src/test/java/org/openecomp/sdc/be/model/ComponentParametersViewTest.java
index d84b821950..7f8ea5184c 100644
--- a/catalog-model/src/test/java/org/openecomp/sdc/be/model/ComponentParametersViewTest.java
+++ b/catalog-model/src/test/java/org/openecomp/sdc/be/model/ComponentParametersViewTest.java
@@ -7,6 +7,8 @@ import org.openecomp.sdc.be.datatypes.enums.ComponentTypeEnum;
import java.util.LinkedList;
+import static org.junit.Assert.assertSame;
+
public class ComponentParametersViewTest {
private ComponentParametersView createTestSubject() {
@@ -449,6 +451,26 @@ public class ComponentParametersViewTest {
@Test
+ public void testIsIgnoreNodeFilterWithTrue() throws Exception {
+ ComponentParametersView testSubject;
+
+ testSubject = createTestSubject();
+ testSubject.setIgnoreNodeFilter(true);
+ assertSame(testSubject.isIgnoreNodeFilter(), true);
+ }
+
+
+ @Test
+ public void testIsIgnoreNodeFilterWithFalse() throws Exception {
+ ComponentParametersView testSubject;
+
+ testSubject = createTestSubject();
+ testSubject.setIgnoreNodeFilter(false);
+ assertSame(testSubject.isIgnoreNodeFilter(), false);
+ }
+
+
+ @Test
public void testDetectParseFlag() throws Exception {
ComponentParametersView testSubject;
JsonParseFlagEnum result;
@@ -457,4 +479,4 @@ public class ComponentParametersViewTest {
testSubject = createTestSubject();
result = testSubject.detectParseFlag();
}
-} \ No newline at end of file
+}
diff --git a/catalog-model/src/test/java/org/openecomp/sdc/be/model/jsontitan/datamodel/TopologyTemplateTest.java b/catalog-model/src/test/java/org/openecomp/sdc/be/model/jsontitan/datamodel/TopologyTemplateTest.java
index 72ca0c0cab..c13ddd3970 100644
--- a/catalog-model/src/test/java/org/openecomp/sdc/be/model/jsontitan/datamodel/TopologyTemplateTest.java
+++ b/catalog-model/src/test/java/org/openecomp/sdc/be/model/jsontitan/datamodel/TopologyTemplateTest.java
@@ -5,6 +5,7 @@ import java.util.Map;
import org.junit.Test;
import org.openecomp.sdc.be.datatypes.elements.*;
import org.openecomp.sdc.be.datatypes.tosca.ToscaDataDefinition;
+import org.openecomp.sdc.be.model.DataTypeDefinition;
public class TopologyTemplateTest {
@@ -366,10 +367,29 @@ public class TopologyTemplateTest {
}
+ @Test
+ public void testGetDataTypes() throws Exception {
+ TopologyTemplate testSubject;
+ Map<String, DataTypeDataDefinition> result;
+ // default test
+ testSubject = createTestSubject();
+ result = testSubject.getDataTypes();
+ }
@Test
+ public void testSetDataTypes() throws Exception {
+ TopologyTemplate testSubject;
+ Map<String, DataTypeDataDefinition> dataTypes = null;
+
+ // default test
+ testSubject = createTestSubject();
+ testSubject.setDataTypes(dataTypes);
+ }
+
+
+ @Test
public void testGetComponentInstances() throws Exception {
TopologyTemplate testSubject;
Map<String, ComponentInstanceDataDefinition> result;
diff --git a/catalog-model/src/test/java/org/openecomp/sdc/be/model/jsontitan/operations/TopologyTemplateOperationTest.java b/catalog-model/src/test/java/org/openecomp/sdc/be/model/jsontitan/operations/TopologyTemplateOperationTest.java
index 8bb252ea12..4ace70b34f 100644
--- a/catalog-model/src/test/java/org/openecomp/sdc/be/model/jsontitan/operations/TopologyTemplateOperationTest.java
+++ b/catalog-model/src/test/java/org/openecomp/sdc/be/model/jsontitan/operations/TopologyTemplateOperationTest.java
@@ -26,11 +26,10 @@ import org.openecomp.sdc.be.model.PolicyDefinition;
import org.openecomp.sdc.be.model.User;
import org.openecomp.sdc.be.model.operations.api.StorageOperationStatus;
import org.openecomp.sdc.be.model.operations.impl.UniqueIdBuilder;
+import org.openecomp.sdc.be.model.ComponentParametersView;
+import org.openecomp.sdc.be.model.jsontitan.datamodel.ToscaElement;
-import java.util.Collections;
-import java.util.HashMap;
-import java.util.Iterator;
-import java.util.Map;
+import java.util.*;
import static org.assertj.core.api.Assertions.assertThat;
import static org.junit.Assert.assertEquals;
@@ -107,6 +106,23 @@ public class TopologyTemplateOperationTest {
}
@Test
+ public void testSetDataTypesFromGraph() {
+ GraphVertex containerVertex = new GraphVertex();
+ ComponentParametersView filter = new ComponentParametersView(true);
+ filter.setIgnoreComponentInstancesInterfaces(true);
+ filter.setIgnoreDataType(false);
+ String componentName = "componentName";
+ String componentId = UniqueIdBuilder.buildResourceUniqueId();
+ containerVertex.setVertex(Mockito.mock(TitanVertex.class));
+ containerVertex.setJsonMetadataField(JsonPresentationFields.NAME, componentName);
+ containerVertex.setUniqueId(componentId);
+ containerVertex.setLabel(VertexTypeEnum.TOPOLOGY_TEMPLATE);
+ when(titanDao.getChildVertex(any(GraphVertex.class), any(EdgeLabelEnum.class), any(JsonParseFlagEnum.class))).thenReturn(Either.right(TitanOperationStatus.GENERAL_ERROR));
+ Either<ToscaElement, StorageOperationStatus> storageOperationStatus = topologyTemplateOperation.getToscaElement(containerVertex, filter);
+ assertThat(storageOperationStatus).isEqualTo(Either.right(StorageOperationStatus.GENERAL_ERROR));
+ }
+
+ @Test
public void testUpdateDistributionStatus() {
Either<GraphVertex, StorageOperationStatus> result;
String uniqueId = "uniqueId";
diff --git a/catalog-model/src/test/java/org/openecomp/sdc/be/model/jsontitan/operations/ToscaOperationFacadeTest.java b/catalog-model/src/test/java/org/openecomp/sdc/be/model/jsontitan/operations/ToscaOperationFacadeTest.java
index 63856e6515..0eb0b3c6d2 100644
--- a/catalog-model/src/test/java/org/openecomp/sdc/be/model/jsontitan/operations/ToscaOperationFacadeTest.java
+++ b/catalog-model/src/test/java/org/openecomp/sdc/be/model/jsontitan/operations/ToscaOperationFacadeTest.java
@@ -61,6 +61,9 @@ import org.openecomp.sdc.be.model.jsontitan.datamodel.ToscaElement;
import org.openecomp.sdc.be.model.jsontitan.datamodel.ToscaElementTypeEnum;
import org.openecomp.sdc.be.model.jsontitan.utils.ModelConverter;
import org.openecomp.sdc.be.model.operations.api.StorageOperationStatus;
+import org.openecomp.sdc.be.model.DataTypeDefinition;
+import org.openecomp.sdc.be.model.PropertyDefinition;
+import org.openecomp.sdc.be.datatypes.elements.DataTypeDataDefinition;
import static org.assertj.core.api.Assertions.assertThat;
@@ -73,6 +76,8 @@ import java.util.Set;
import java.util.HashSet;
import java.util.stream.Collectors;
import java.util.stream.IntStream;
+import java.util.Collections;
+import java.util.Arrays;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertSame;
@@ -81,11 +86,11 @@ import static org.mockito.Mockito.when;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.ArgumentMatchers.anyMap;
import static org.mockito.ArgumentMatchers.anyInt;
+import static org.mockito.ArgumentMatchers.anyString;
import static org.mockito.ArgumentMatchers.eq;
@RunWith(MockitoJUnitRunner.class)
public class ToscaOperationFacadeTest {
-
@InjectMocks
private ToscaOperationFacade testInstance;
@@ -482,6 +487,103 @@ public class ToscaOperationFacadeTest {
return toscaElement;
}
+ @Test
+ public void addDataTypesToComponentSuccessTest(){
+ Either<List<DataTypeDefinition>, StorageOperationStatus> result = addDataTypesToComponentWithStatus(StorageOperationStatus.OK);
+ assertTrue(result.isLeft());
+ }
+
+ @Test
+ public void addDataTypesToComponentFailureTest_BadRequest(){
+ Either<List<DataTypeDefinition>, StorageOperationStatus> result = addDataTypesToComponentWithStatus(StorageOperationStatus.BAD_REQUEST);
+ assertTrue(result.isRight() && result.right().value() == StorageOperationStatus.BAD_REQUEST);
+ }
+
+ private Either<List<DataTypeDefinition>, StorageOperationStatus> addDataTypesToComponentWithStatus(StorageOperationStatus status) {
+ Map<String, DataTypeDefinition> dataTypes = new HashMap<>();
+ String componentId = "componentid";
+ String Id = "id";
+
+ PropertyDefinition noDefaultProp = new PropertyDefinition();
+ noDefaultProp.setName("noDefaultProp");
+ PropertyDefinition prop1 = new PropertyDefinition();
+ prop1.setDefaultValue("def1");
+ prop1.setName("prop1");
+ PropertyDefinition prop2 = new PropertyDefinition();
+ prop2.setType("dataType1");
+ prop2.setName("prop2");
+ PropertyDefinition prop3 = new PropertyDefinition();
+ prop3.setDefaultValue("def3");
+ prop3.setName("prop3");
+
+ DataTypeDefinition noDefaultValue = new DataTypeDefinition();
+ noDefaultValue.setProperties(Collections.singletonList(noDefaultProp));
+ noDefaultValue.setDerivedFromName("name0");
+
+ DataTypeDefinition dataType1 = new DataTypeDefinition();
+ dataType1.setProperties(Arrays.asList(prop1, prop3));
+ dataType1.setName("name1");
+ dataType1.setDerivedFromName("derivedfromname1");
+
+ DataTypeDefinition dataType2 = new DataTypeDefinition();
+ dataType2.setDerivedFrom(dataType1);
+ dataType2.setName("name2");
+ dataType2.setDerivedFromName("derivedfromname2");
+
+ DataTypeDefinition dataType3 = new DataTypeDefinition();
+ dataType3.setProperties(Collections.singletonList(prop2));
+ dataType3.setDerivedFrom(noDefaultValue);
+ dataType3.setName("name3");
+ dataType3.setDerivedFromName("derivedfromname3");
+
+ dataTypes.put("noDefault", noDefaultValue);
+ dataTypes.put("dataType1", dataType1);
+ dataTypes.put("dataType2", dataType2);
+ dataTypes.put("dataType3", dataType3);
+
+ GraphVertex vertex;
+ if(status == StorageOperationStatus.OK){
+ vertex = getTopologyTemplateVertex();
+ } else {
+ vertex = getNodeTypeVertex();
+ }
+ Either<GraphVertex, TitanOperationStatus> getVertexEither = Either.left(vertex);
+ when(titanDaoMock.getVertexById(componentId, JsonParseFlagEnum.NoParse)).thenReturn(getVertexEither);
+ when(topologyTemplateOperationMock.addToscaDataToToscaElement(eq(vertex),
+ eq(EdgeLabelEnum.DATA_TYPES), eq(VertexTypeEnum.DATA_TYPES), anyMap(), eq(JsonPresentationFields.NAME))).thenReturn(status);
+ return testInstance.addDataTypesToComponent(dataTypes, componentId);
+ }
+
+ @Test
+ public void testDataTypesToComponentFailureTest_NotFound() {
+ Either<List<DataTypeDefinition>, StorageOperationStatus> result;
+ String componentId = "componentId";
+ GraphVertex vertex = getNodeTypeVertex();
+ Map<String, DataTypeDefinition> dataTypes = new HashMap<>();
+ when(titanDaoMock.getVertexById(componentId, JsonParseFlagEnum.NoParse)).thenReturn(Either.right(TitanOperationStatus.NOT_FOUND));
+ result = testInstance.addDataTypesToComponent(dataTypes, componentId);
+ assertTrue(result.isRight() && result.right().value() == StorageOperationStatus.NOT_FOUND);
+ }
+
+ @Test
+ public void testDeleteDataTypeOfComponent() {
+ StorageOperationStatus result;
+ Component component = new Resource();
+ String id = "id";
+ component.setUniqueId(id);
+ String datatype = null;
+
+ DataTypeDefinition dataType1 = new DataTypeDefinition();
+ dataType1.setName("name1");
+ Map<String, DataTypeDataDefinition> dataTypeDataMap = new HashMap<>();
+ dataTypeDataMap.put("datatype1", dataType1);
+ List<DataTypeDefinition> dataTypeMap = dataTypeDataMap.values().stream().map(e -> { DataTypeDefinition dataType = new DataTypeDefinition(e);return dataType; }).collect(Collectors.toList());
+ component.setDataTypes(dataTypeMap);
+ GraphVertex graphVertex = getTopologyTemplateVertex();
+ result = testInstance.deleteDataTypeOfComponent(component, "datatype1");
+ assertEquals(datatype, result);
+ }
+
private Either<PolicyDefinition, StorageOperationStatus> associatePolicyToComponentWithStatus(StorageOperationStatus status) {
PolicyDefinition policy = new PolicyDefinition();
String componentId = "componentId";