summaryrefslogtreecommitdiffstats
path: root/catalog-model/src/main/java
diff options
context:
space:
mode:
authorToshimichi Fukuda <t_fukuda@jp.fujitsu.com>2019-04-18 21:38:46 +0900
committerOfir Sonsino <ofir.sonsino@intl.att.com>2019-05-07 16:09:28 +0000
commit51411acd1d4b06fc9bbc40338a27dd061dba425f (patch)
tree51cbc4bb3372b7aa06e566eec6181b7a1838eee5 /catalog-model/src/main/java
parent55c536e65dcbd1981de61c6c8bea318585324d22 (diff)
Change to enable SDC list type input
Change-Id: Ic3a9c6e714a5afd22b58bf2cb066932b1ec2a5c0 Issue-ID: SDC-2046 Signed-off-by: Toshimichi Fukuda <t_fukuda@jp.fujitsu.com> Signed-off-by: Satoshi Fujii <fujii-satoshi@jp.fujitsu.com> Signed-off-by: Ayumu Ueha <ueha.ayumu@jp.fujitsu.com>
Diffstat (limited to 'catalog-model/src/main/java')
-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
8 files changed, 359 insertions, 128 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<>();