summaryrefslogtreecommitdiffstats
path: root/catalog-model/src/main/java/org/openecomp/sdc/be/model/operations/impl/HeatParametersOperation.java
diff options
context:
space:
mode:
Diffstat (limited to 'catalog-model/src/main/java/org/openecomp/sdc/be/model/operations/impl/HeatParametersOperation.java')
-rw-r--r--catalog-model/src/main/java/org/openecomp/sdc/be/model/operations/impl/HeatParametersOperation.java742
1 files changed, 369 insertions, 373 deletions
diff --git a/catalog-model/src/main/java/org/openecomp/sdc/be/model/operations/impl/HeatParametersOperation.java b/catalog-model/src/main/java/org/openecomp/sdc/be/model/operations/impl/HeatParametersOperation.java
index 7b7ead5a19..6d050afb2c 100644
--- a/catalog-model/src/main/java/org/openecomp/sdc/be/model/operations/impl/HeatParametersOperation.java
+++ b/catalog-model/src/main/java/org/openecomp/sdc/be/model/operations/impl/HeatParametersOperation.java
@@ -20,11 +20,7 @@
package org.openecomp.sdc.be.model.operations.impl;
-import java.util.ArrayList;
-import java.util.HashMap;
-import java.util.List;
-import java.util.Map;
-
+import fj.data.Either;
import org.apache.commons.lang3.tuple.ImmutablePair;
import org.apache.tinkerpop.gremlin.structure.Edge;
import org.openecomp.sdc.be.dao.graph.datatype.GraphEdge;
@@ -43,432 +39,432 @@ import org.openecomp.sdc.be.model.tosca.validators.PropertyTypeValidator;
import org.openecomp.sdc.be.resources.data.HeatParameterData;
import org.openecomp.sdc.be.resources.data.HeatParameterValueData;
import org.openecomp.sdc.be.resources.data.UniqueIdData;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
+import org.openecomp.sdc.common.log.wrappers.Logger;
import org.springframework.stereotype.Component;
-import fj.data.Either;
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
@Component("heat-parameter-operation")
public class HeatParametersOperation implements IHeatParametersOperation {
- public static final String EMPTY_VALUE = null;
+ public static final String EMPTY_VALUE = null;
+
+ private static final Logger log = Logger.getLogger(HeatParametersOperation.class.getName());
+
+ @javax.annotation.Resource
+ private TitanGenericDao titanGenericDao;
+
+ public TitanGenericDao getTitanGenericDao() {
+ return titanGenericDao;
+ }
+
+ public void setTitanGenericDao(TitanGenericDao titanGenericDao) {
+ this.titanGenericDao = titanGenericDao;
+ }
+
+ public StorageOperationStatus getHeatParametersOfNode(NodeTypeEnum nodeType, String uniqueId, List<HeatParameterDefinition> properties) {
+
+ Either<List<ImmutablePair<HeatParameterData, GraphEdge>>, TitanOperationStatus> childrenNodes = titanGenericDao.getChildrenNodes(UniqueIdBuilder.getKeyByNodeType(nodeType), uniqueId, GraphEdgeLabels.HEAT_PARAMETER, NodeTypeEnum.HeatParameter,
+ HeatParameterData.class);
+
+ if (childrenNodes.isRight()) {
+ TitanOperationStatus status = childrenNodes.right().value();
+ if (status == TitanOperationStatus.NOT_FOUND) {
+ status = TitanOperationStatus.OK;
+ }
+ return DaoStatusConverter.convertTitanStatusToStorageStatus(status);
+ }
+
+ List<ImmutablePair<HeatParameterData, GraphEdge>> values = childrenNodes.left().value();
+ if (values != null) {
+
+ for (ImmutablePair<HeatParameterData, GraphEdge> immutablePair : values) {
+ GraphEdge edge = immutablePair.getValue();
+ String propertyName = (String) edge.getProperties().get(GraphPropertiesDictionary.NAME.getProperty());
+ if (log.isDebugEnabled())
+ log.debug("Property {} is associated to node {}", propertyName, uniqueId);
+ HeatParameterData propertyData = immutablePair.getKey();
+ HeatParameterDefinition propertyDefinition = convertParameterDataToParameterDefinition(propertyData, propertyName, uniqueId);
- private static Logger log = LoggerFactory.getLogger(HeatParametersOperation.class.getName());
+ properties.add(propertyDefinition);
- @javax.annotation.Resource
- private TitanGenericDao titanGenericDao;
+ if (log.isTraceEnabled()) {
+ log.trace("getHeatParametersOfNode - property {} associated to node {}", propertyDefinition, uniqueId);
+ }
+ }
- public TitanGenericDao getTitanGenericDao() {
- return titanGenericDao;
- }
+ }
- public void setTitanGenericDao(TitanGenericDao titanGenericDao) {
- this.titanGenericDao = titanGenericDao;
- }
+ return StorageOperationStatus.OK;
+ }
- public StorageOperationStatus getHeatParametersOfNode(NodeTypeEnum nodeType, String uniqueId, List<HeatParameterDefinition> properties) {
+ public StorageOperationStatus getParametersValueNodes(NodeTypeEnum parentNodeType, String parentUniqueId, List<HeatParameterValueData> heatValues) {
- Either<List<ImmutablePair<HeatParameterData, GraphEdge>>, TitanOperationStatus> childrenNodes = titanGenericDao.getChildrenNodes(UniqueIdBuilder.getKeyByNodeType(nodeType), uniqueId, GraphEdgeLabels.HEAT_PARAMETER, NodeTypeEnum.HeatParameter,
- HeatParameterData.class);
+ Either<List<ImmutablePair<HeatParameterValueData, GraphEdge>>, TitanOperationStatus> childrenNodes = titanGenericDao.getChildrenNodes(UniqueIdBuilder.getKeyByNodeType(parentNodeType), parentUniqueId, GraphEdgeLabels.PARAMETER_VALUE,
+ NodeTypeEnum.HeatParameterValue, HeatParameterValueData.class);
- if (childrenNodes.isRight()) {
- TitanOperationStatus status = childrenNodes.right().value();
- if (status == TitanOperationStatus.NOT_FOUND) {
- status = TitanOperationStatus.OK;
- }
- return DaoStatusConverter.convertTitanStatusToStorageStatus(status);
- }
+ if (childrenNodes.isRight()) {
+ TitanOperationStatus status = childrenNodes.right().value();
+ if (status == TitanOperationStatus.NOT_FOUND) {
+ status = TitanOperationStatus.OK;
+ }
+ return DaoStatusConverter.convertTitanStatusToStorageStatus(status);
+ }
- List<ImmutablePair<HeatParameterData, GraphEdge>> values = childrenNodes.left().value();
- if (values != null) {
+ List<ImmutablePair<HeatParameterValueData, GraphEdge>> values = childrenNodes.left().value();
+ if (values != null) {
- for (ImmutablePair<HeatParameterData, GraphEdge> immutablePair : values) {
- GraphEdge edge = immutablePair.getValue();
- String propertyName = (String) edge.getProperties().get(GraphPropertiesDictionary.NAME.getProperty());
- if (log.isDebugEnabled())
- log.debug("Property {} is associated to node {}", propertyName, uniqueId);
- HeatParameterData propertyData = immutablePair.getKey();
- HeatParameterDefinition propertyDefinition = convertParameterDataToParameterDefinition(propertyData, propertyName, uniqueId);
+ for (ImmutablePair<HeatParameterValueData, GraphEdge> immutablePair : values) {
+ GraphEdge edge = immutablePair.getValue();
+ String propertyName = (String) edge.getProperties().get(GraphPropertiesDictionary.NAME.getProperty());
+ log.trace("Heat value {} is associated to node {}", propertyName,parentUniqueId);
+ HeatParameterValueData propertyData = immutablePair.getKey();
- properties.add(propertyDefinition);
+ heatValues.add(propertyData);
+ }
- if (log.isTraceEnabled()) {
- log.trace("getHeatParametersOfNode - property {} associated to node {}", propertyDefinition, uniqueId);
- }
- }
+ }
- }
+ return StorageOperationStatus.OK;
+ }
- return StorageOperationStatus.OK;
- }
+ @Override
+ public Either<List<HeatParameterDefinition>, StorageOperationStatus> deleteAllHeatParametersAssociatedToNode(NodeTypeEnum nodeType, String uniqueId) {
- public StorageOperationStatus getParametersValueNodes(NodeTypeEnum parentNodeType, String parentUniqueId, List<HeatParameterValueData> heatValues) {
+ List<HeatParameterDefinition> heatParams = new ArrayList<>();
+ StorageOperationStatus propertiesOfNodeRes = getHeatParametersOfNode(nodeType, uniqueId, heatParams);
- Either<List<ImmutablePair<HeatParameterValueData, GraphEdge>>, TitanOperationStatus> childrenNodes = titanGenericDao.getChildrenNodes(UniqueIdBuilder.getKeyByNodeType(parentNodeType), parentUniqueId, GraphEdgeLabels.PARAMETER_VALUE,
- NodeTypeEnum.HeatParameterValue, HeatParameterValueData.class);
+ if (!propertiesOfNodeRes.equals(StorageOperationStatus.OK) && !propertiesOfNodeRes.equals(StorageOperationStatus.NOT_FOUND)) {
+ return Either.right(propertiesOfNodeRes);
+ }
- if (childrenNodes.isRight()) {
- TitanOperationStatus status = childrenNodes.right().value();
- if (status == TitanOperationStatus.NOT_FOUND) {
- status = TitanOperationStatus.OK;
- }
- return DaoStatusConverter.convertTitanStatusToStorageStatus(status);
- }
+ for (HeatParameterDefinition propertyDefinition : heatParams) {
- List<ImmutablePair<HeatParameterValueData, GraphEdge>> values = childrenNodes.left().value();
- if (values != null) {
+ String propertyUid = propertyDefinition.getUniqueId();
+ Either<HeatParameterData, TitanOperationStatus> deletePropertyRes = deleteHeatParameterFromGraph(propertyUid);
+ if (deletePropertyRes.isRight()) {
+ log.error("Failed to delete heat parameter with id {}", propertyUid);
+ TitanOperationStatus status = deletePropertyRes.right().value();
+ if (status == TitanOperationStatus.NOT_FOUND) {
+ status = TitanOperationStatus.INVALID_ID;
+ }
+ return Either.right(DaoStatusConverter.convertTitanStatusToStorageStatus(status));
+ }
- for (ImmutablePair<HeatParameterValueData, GraphEdge> immutablePair : values) {
- GraphEdge edge = immutablePair.getValue();
- String propertyName = (String) edge.getProperties().get(GraphPropertiesDictionary.NAME.getProperty());
- log.trace("Heat value {} is associated to node {}", propertyName,parentUniqueId);
- HeatParameterValueData propertyData = immutablePair.getKey();
+ }
- heatValues.add(propertyData);
- }
+ log.debug("The heat parameters deleted from node {} are {}", uniqueId, heatParams);
+ return Either.left(heatParams);
+ }
- }
+ @Override
+ public StorageOperationStatus deleteAllHeatValuesAssociatedToNode(NodeTypeEnum parentNodeType, String parentUniqueId) {
- return StorageOperationStatus.OK;
- }
+ List<HeatParameterValueData> heatValues = new ArrayList<>();
+ StorageOperationStatus propertiesOfNodeRes = getParametersValueNodes(parentNodeType, parentUniqueId, heatValues);
- @Override
- public Either<List<HeatParameterDefinition>, StorageOperationStatus> deleteAllHeatParametersAssociatedToNode(NodeTypeEnum nodeType, String uniqueId) {
+ if (!propertiesOfNodeRes.equals(StorageOperationStatus.OK) && !propertiesOfNodeRes.equals(StorageOperationStatus.NOT_FOUND)) {
+ return propertiesOfNodeRes;
+ }
- List<HeatParameterDefinition> heatParams = new ArrayList<HeatParameterDefinition>();
- StorageOperationStatus propertiesOfNodeRes = getHeatParametersOfNode(nodeType, uniqueId, heatParams);
+ for (HeatParameterValueData propertyDefinition : heatValues) {
- if (!propertiesOfNodeRes.equals(StorageOperationStatus.OK) && !propertiesOfNodeRes.equals(StorageOperationStatus.NOT_FOUND)) {
- return Either.right(propertiesOfNodeRes);
- }
+ String propertyUid = (String) propertyDefinition.getUniqueId();
+ Either<HeatParameterValueData, TitanOperationStatus> deletePropertyRes = deleteHeatParameterValueFromGraph(propertyUid);
+ if (deletePropertyRes.isRight()) {
+ log.error("Failed to delete heat parameter value with id {}", propertyUid);
+ TitanOperationStatus status = deletePropertyRes.right().value();
+ if (status == TitanOperationStatus.NOT_FOUND) {
+ status = TitanOperationStatus.INVALID_ID;
+ }
+ return DaoStatusConverter.convertTitanStatusToStorageStatus(status);
+ }
- for (HeatParameterDefinition propertyDefinition : heatParams) {
+ }
- String propertyUid = propertyDefinition.getUniqueId();
- Either<HeatParameterData, TitanOperationStatus> deletePropertyRes = deleteHeatParameterFromGraph(propertyUid);
- if (deletePropertyRes.isRight()) {
- log.error("Failed to delete heat parameter with id {}", propertyUid);
- TitanOperationStatus status = deletePropertyRes.right().value();
- if (status == TitanOperationStatus.NOT_FOUND) {
- status = TitanOperationStatus.INVALID_ID;
- }
- return Either.right(DaoStatusConverter.convertTitanStatusToStorageStatus(status));
- }
+ log.debug("The heat values deleted from node {} are {}" , parentUniqueId, heatValues);
+ return StorageOperationStatus.OK;
+ }
- }
+ private Either<HeatParameterData, TitanOperationStatus> deleteHeatParameterFromGraph(String propertyId) {
+ log.debug("Before deleting heat parameter from graph {}" , propertyId);
+ return titanGenericDao.deleteNode(UniqueIdBuilder.getKeyByNodeType(NodeTypeEnum.HeatParameter), propertyId, HeatParameterData.class);
+ }
- log.debug("The heat parameters deleted from node {} are {}", uniqueId, heatParams);
- return Either.left(heatParams);
- }
+ private Either<HeatParameterValueData, TitanOperationStatus> deleteHeatParameterValueFromGraph(String propertyId) {
+ log.debug("Before deleting heat parameter from graph {}" , propertyId);
+ return titanGenericDao.deleteNode(UniqueIdBuilder.getKeyByNodeType(NodeTypeEnum.HeatParameterValue), propertyId, HeatParameterValueData.class);
+ }
- @Override
- public StorageOperationStatus deleteAllHeatValuesAssociatedToNode(NodeTypeEnum parentNodeType, String parentUniqueId) {
+ @Override
+ public StorageOperationStatus addPropertiesToGraph(List<HeatParameterDefinition> properties, String parentId, NodeTypeEnum nodeType) {
- List<HeatParameterValueData> heatValues = new ArrayList<HeatParameterValueData>();
- StorageOperationStatus propertiesOfNodeRes = getParametersValueNodes(parentNodeType, parentUniqueId, heatValues);
+ if (properties != null) {
+ for (HeatParameterDefinition propertyDefinition : properties) {
- if (!propertiesOfNodeRes.equals(StorageOperationStatus.OK) && !propertiesOfNodeRes.equals(StorageOperationStatus.NOT_FOUND)) {
- return propertiesOfNodeRes;
- }
+ String propertyName = propertyDefinition.getName();
- for (HeatParameterValueData propertyDefinition : heatValues) {
+ Either<HeatParameterData, TitanOperationStatus> addPropertyToGraph = addPropertyToGraph(propertyName, propertyDefinition, parentId, nodeType);
- String propertyUid = (String) propertyDefinition.getUniqueId();
- Either<HeatParameterValueData, TitanOperationStatus> deletePropertyRes = deleteHeatParameterValueFromGraph(propertyUid);
- if (deletePropertyRes.isRight()) {
- log.error("Failed to delete heat parameter value with id {}", propertyUid);
- TitanOperationStatus status = deletePropertyRes.right().value();
- if (status == TitanOperationStatus.NOT_FOUND) {
- status = TitanOperationStatus.INVALID_ID;
- }
- return DaoStatusConverter.convertTitanStatusToStorageStatus(status);
- }
+ if (addPropertyToGraph.isRight()) {
+ return DaoStatusConverter.convertTitanStatusToStorageStatus(addPropertyToGraph.right().value());
+ }
+ }
+ }
- }
+ return StorageOperationStatus.OK;
- log.debug("The heat values deleted from node {} are {}" , parentUniqueId, heatValues);
- return StorageOperationStatus.OK;
- }
+ }
- private Either<HeatParameterData, TitanOperationStatus> deleteHeatParameterFromGraph(String propertyId) {
- log.debug("Before deleting heat parameter from graph {}" , propertyId);
- return titanGenericDao.deleteNode(UniqueIdBuilder.getKeyByNodeType(NodeTypeEnum.HeatParameter), propertyId, HeatParameterData.class);
- }
+ @Override
+ public StorageOperationStatus updateHeatParameters(List<HeatParameterDefinition> properties) {
- private Either<HeatParameterValueData, TitanOperationStatus> deleteHeatParameterValueFromGraph(String propertyId) {
- log.debug("Before deleting heat parameter from graph {}" , propertyId);
- return titanGenericDao.deleteNode(UniqueIdBuilder.getKeyByNodeType(NodeTypeEnum.HeatParameterValue), propertyId, HeatParameterValueData.class);
- }
+ if (properties == null) {
+ return StorageOperationStatus.OK;
+ }
+ for (HeatParameterDefinition property : properties) {
- @Override
- public StorageOperationStatus addPropertiesToGraph(List<HeatParameterDefinition> properties, String parentId, NodeTypeEnum nodeType) {
+ HeatParameterData heatParameterData = new HeatParameterData(property);
+ Either<HeatParameterData, TitanOperationStatus> updateNode = titanGenericDao.updateNode(heatParameterData, HeatParameterData.class);
+ if (updateNode.isRight()) {
+ log.debug("failed to update heat parameter in graph. id = {}", property.getUniqueId());
+ return DaoStatusConverter.convertTitanStatusToStorageStatus(updateNode.right().value());
+ }
+ }
- if (properties != null) {
- for (HeatParameterDefinition propertyDefinition : properties) {
+ return StorageOperationStatus.OK;
+ }
- String propertyName = propertyDefinition.getName();
-
- Either<HeatParameterData, TitanOperationStatus> addPropertyToGraph = addPropertyToGraph(propertyName, propertyDefinition, parentId, nodeType);
-
- if (addPropertyToGraph.isRight()) {
- return DaoStatusConverter.convertTitanStatusToStorageStatus(addPropertyToGraph.right().value());
- }
- }
- }
-
- return StorageOperationStatus.OK;
-
- }
-
- @Override
- public StorageOperationStatus updateHeatParameters(List<HeatParameterDefinition> properties) {
+ public Either<HeatParameterData, TitanOperationStatus> addPropertyToGraph(String propertyName, HeatParameterDefinition propertyDefinition, String parentId, NodeTypeEnum nodeType) {
- if (properties == null) {
- return StorageOperationStatus.OK;
- }
- for (HeatParameterDefinition property : properties) {
+ UniqueIdData parentNode = new UniqueIdData(nodeType, parentId);
- HeatParameterData heatParameterData = new HeatParameterData(property);
- Either<HeatParameterData, TitanOperationStatus> updateNode = titanGenericDao.updateNode(heatParameterData, HeatParameterData.class);
- if (updateNode.isRight()) {
- log.debug("failed to update heat parameter in graph. id = {}", property.getUniqueId());
- return DaoStatusConverter.convertTitanStatusToStorageStatus(updateNode.right().value());
- }
- }
+ propertyDefinition.setUniqueId(UniqueIdBuilder.buildHeatParameterUniqueId(parentId, propertyName));
+ HeatParameterData propertyData = new HeatParameterData(propertyDefinition);
- return StorageOperationStatus.OK;
- }
+ log.debug("Before adding property to graph {}" , propertyData);
+ Either<HeatParameterData, TitanOperationStatus> createNodeResult = titanGenericDao.createNode(propertyData, HeatParameterData.class);
+ log.debug("After adding property to graph {}" , propertyData);
+ if (createNodeResult.isRight()) {
+ TitanOperationStatus operationStatus = createNodeResult.right().value();
+ log.error("Failed to add property {} to graph. status is {}", propertyName, operationStatus);
+ return Either.right(operationStatus);
+ }
- public Either<HeatParameterData, TitanOperationStatus> addPropertyToGraph(String propertyName, HeatParameterDefinition propertyDefinition, String parentId, NodeTypeEnum nodeType) {
+ Map<String, Object> props = new HashMap<>();
+ props.put(GraphPropertiesDictionary.NAME.getProperty(), propertyName);
+ Either<GraphRelation, TitanOperationStatus> createRelResult = titanGenericDao.createRelation(parentNode, propertyData, GraphEdgeLabels.HEAT_PARAMETER, props);
+ if (createRelResult.isRight()) {
+ TitanOperationStatus operationStatus = createRelResult.right().value();
+ log.error("Failed to associate {} {} to heat parameter {} in graph. status is {}", nodeType.getName(), parentId, propertyName, operationStatus);
+ return Either.right(operationStatus);
+ }
- UniqueIdData parentNode = new UniqueIdData(nodeType, parentId);
+ return Either.left(createNodeResult.left().value());
- propertyDefinition.setUniqueId(UniqueIdBuilder.buildHeatParameterUniqueId(parentId, propertyName));
- HeatParameterData propertyData = new HeatParameterData(propertyDefinition);
+ }
- log.debug("Before adding property to graph {}" , propertyData);
- Either<HeatParameterData, TitanOperationStatus> createNodeResult = titanGenericDao.createNode(propertyData, HeatParameterData.class);
- log.debug("After adding property to graph {}" , propertyData);
- if (createNodeResult.isRight()) {
- TitanOperationStatus operationStatus = createNodeResult.right().value();
- log.error("Failed to add property {} to graph. status is {}", propertyName, operationStatus);
- return Either.right(operationStatus);
- }
+ public StorageOperationStatus validateAndUpdateProperty(HeatParameterDefinition propertyDefinition) {
- Map<String, Object> props = new HashMap<String, Object>();
- props.put(GraphPropertiesDictionary.NAME.getProperty(), propertyName);
- Either<GraphRelation, TitanOperationStatus> createRelResult = titanGenericDao.createRelation(parentNode, propertyData, GraphEdgeLabels.HEAT_PARAMETER, props);
- if (createRelResult.isRight()) {
- TitanOperationStatus operationStatus = createRelResult.right().value();
- log.error("Failed to associate {} {} to heat parameter {} in graph. status is {}", nodeType.getName(), parentId, propertyName, operationStatus);
- return Either.right(operationStatus);
- }
+ log.trace("Going to validate property type and value. {}" , propertyDefinition);
- return Either.left(createNodeResult.left().value());
+ String propertyType = propertyDefinition.getType();
+ HeatParameterType type = getType(propertyType);
- }
+ if (type == null) {
+ log.info("The type {} of heat parameter is invalid", type);
- public StorageOperationStatus validateAndUpdateProperty(HeatParameterDefinition propertyDefinition) {
+ return StorageOperationStatus.INVALID_TYPE;
+ }
+ propertyDefinition.setType(type.getType());
- log.trace("Going to validate property type and value. {}" , propertyDefinition);
+ log.trace("After validating property type {}", propertyType);
- String propertyType = propertyDefinition.getType();
- HeatParameterType type = getType(propertyType);
-
- if (type == null) {
- log.info("The type {} of heat parameter is invalid", type);
-
- return StorageOperationStatus.INVALID_TYPE;
- }
- propertyDefinition.setType(type.getType());
-
- log.trace("After validating property type {}", propertyType);
-
- // validate default value
- String defaultValue = propertyDefinition.getDefaultValue();
- boolean isValidProperty = isValidValue(type, defaultValue);
- if (false == isValidProperty) {
- log.info("The value {} of property from type {} is invalid", defaultValue, type);
- return StorageOperationStatus.INVALID_VALUE;
- }
-
- PropertyValueConverter converter = type.getConverter();
-
- if (isEmptyValue(defaultValue)) {
- log.debug("Default value was not sent for property {}. Set default value to {}", propertyDefinition.getName() , EMPTY_VALUE);
-
- propertyDefinition.setDefaultValue(EMPTY_VALUE);
- } else if (false == isEmptyValue(defaultValue)) {
- String convertedValue = converter.convert(defaultValue, null, null);
- propertyDefinition.setDefaultValue(convertedValue);
- }
-
- // validate current value
- String value = propertyDefinition.getCurrentValue();
- isValidProperty = isValidValue(type, value);
- if (false == isValidProperty) {
- log.info("The value {} of property from type {} is invalid", value, type);
- return StorageOperationStatus.INVALID_VALUE;
- }
-
- if (isEmptyValue(value)) {
- log.debug("Value was not sent for property {}. Set value to {}", propertyDefinition.getName(), EMPTY_VALUE);
-
- propertyDefinition.setCurrentValue(EMPTY_VALUE);
- } else if (!value.equals("")) {
- String convertedValue = converter.convert(value, null, null);
- propertyDefinition.setCurrentValue(convertedValue);
- }
-
- return StorageOperationStatus.OK;
- }
-
- public HeatParameterDefinition convertParameterDataToParameterDefinition(HeatParameterData propertyDataResult, String propertyName, String resourceId) {
- log.debug("convert to HeatParamereDefinition {}", propertyDataResult);
-
- HeatParameterDefinition propertyDefResult = new HeatParameterDefinition(propertyDataResult.getHeatDataDefinition());
-
- propertyDefResult.setName(propertyName);
-
- return propertyDefResult;
- }
-
- private HeatParameterType getType(String propertyType) {
-
- HeatParameterType type = HeatParameterType.isValidType(propertyType);
-
- return type;
-
- }
-
- protected boolean isValidValue(HeatParameterType type, String value) {
- if (isEmptyValue(value)) {
- return true;
- }
-
- PropertyTypeValidator validator = type.getValidator();
-
- boolean isValid = validator.isValid(value, null, null);
- if (true == isValid) {
- return true;
- } else {
- return false;
- }
-
- }
-
- public boolean isEmptyValue(String value) {
- if (value == null) {
- return true;
- }
- return false;
- }
-
- public boolean isNullParam(String value) {
- if (value == null) {
- return true;
- }
- return false;
- }
-
- @Override
- public Either<HeatParameterValueData, StorageOperationStatus> updateHeatParameterValue(HeatParameterDefinition heatParam, String artifactId, String resourceInstanceId, String artifactLabel) {
- String heatEnvId = UniqueIdBuilder.buildHeatParameterValueUniqueId(resourceInstanceId, artifactLabel, heatParam.getName());
- Either<HeatParameterValueData, TitanOperationStatus> getNode = titanGenericDao.getNode(GraphPropertiesDictionary.UNIQUE_ID.getProperty(), heatEnvId, HeatParameterValueData.class);
- if (getNode.isRight() || getNode.left().value() == null) {
- if (heatParam.getCurrentValue() == null || (heatParam.getDefaultValue() != null && heatParam.getCurrentValue().equals(heatParam.getDefaultValue()))) {
- log.debug("Updated heat parameter value equals default value. No need to create heat parameter value for heat parameter {}", heatParam.getUniqueId());
- return Either.left(null);
- }
- return createHeatParameterValue(heatParam, artifactId, resourceInstanceId, artifactLabel);
- } else {
- heatParam.setUniqueId(heatEnvId);
- return updateHeatParameterValue(heatParam);
- }
- }
-
- public Either<HeatParameterValueData, StorageOperationStatus> updateHeatParameterValue(HeatParameterDefinition heatParam) {
- HeatParameterValueData heatParameterValue = new HeatParameterValueData();
- heatParameterValue.setUniqueId(heatParam.getUniqueId());
- if (heatParam.getCurrentValue() == null || (heatParam.getDefaultValue() != null && heatParam.getCurrentValue().equals(heatParam.getDefaultValue()))) {
- Either<GraphRelation, TitanOperationStatus> deleteParameterValueIncomingRelation = titanGenericDao.deleteIncomingRelationByCriteria(heatParameterValue, GraphEdgeLabels.PARAMETER_VALUE, null);
- if (deleteParameterValueIncomingRelation.isRight()) {
- log.debug("Failed to delete heat parameter value incoming relation on graph. id = {}", heatParameterValue.getUniqueId());
- return Either.right(DaoStatusConverter.convertTitanStatusToStorageStatus(deleteParameterValueIncomingRelation.right().value()));
- }
- Either<Edge, TitanOperationStatus> getOutgoingRelation = titanGenericDao.getOutgoingEdgeByCriteria(GraphPropertiesDictionary.UNIQUE_ID.getProperty(), (String) heatParameterValue.getUniqueId(), GraphEdgeLabels.PARAMETER_IMPL, null);
- if (getOutgoingRelation.isRight()) {
- log.debug("Failed to get heat parameter value outgoing relation from graph. id = {}", heatParameterValue.getUniqueId());
- return Either.right(DaoStatusConverter.convertTitanStatusToStorageStatus(getOutgoingRelation.right().value()));
- }
- Edge edge = getOutgoingRelation.left().value();
- if (edge == null) {
- log.debug("Failed to get heat parameter value outgoing relation from graph. id = {}", heatParameterValue.getUniqueId());
- return Either.right(StorageOperationStatus.GENERAL_ERROR);
- }
- edge.remove();
-
- Either<HeatParameterValueData, TitanOperationStatus> deleteNode = titanGenericDao.deleteNode(heatParameterValue, HeatParameterValueData.class);
- if (deleteNode.isRight()) {
- log.debug("Failed to delete heat parameter value on graph. id = {}", heatParameterValue.getUniqueId());
- return Either.right(DaoStatusConverter.convertTitanStatusToStorageStatus(deleteNode.right().value()));
- }
- return Either.left(deleteNode.left().value());
- }
- heatParameterValue.setValue(heatParam.getCurrentValue());
- Either<HeatParameterValueData, TitanOperationStatus> updateNode = titanGenericDao.updateNode(heatParameterValue, HeatParameterValueData.class);
- if (updateNode.isRight()) {
- log.debug("Failed to update heat parameter value in graph. id = {}", heatParameterValue.getUniqueId());
- return Either.right(DaoStatusConverter.convertTitanStatusToStorageStatus(updateNode.right().value()));
- }
- return Either.left(updateNode.left().value());
- }
-
- public Either<HeatParameterValueData, StorageOperationStatus> createHeatParameterValue(HeatParameterDefinition heatParam, String artifactId, String resourceInstanceId, String artifactLabel) {
-
- Either<HeatParameterValueData, TitanOperationStatus> addHeatValueToGraph = addHeatValueToGraph(heatParam, artifactLabel, artifactId, resourceInstanceId);
- if (addHeatValueToGraph.isRight()) {
- log.debug("Failed to create heat parameters value on graph for artifact {}", artifactId);
- return Either.right(DaoStatusConverter.convertTitanStatusToStorageStatus(addHeatValueToGraph.right().value()));
- }
- return Either.left(addHeatValueToGraph.left().value());
- }
-
- public Either<HeatParameterValueData, TitanOperationStatus> addHeatValueToGraph(HeatParameterDefinition heatParameter, String artifactLabel, String artifactId, String resourceInstanceId) {
-
- UniqueIdData heatEnvNode = new UniqueIdData(NodeTypeEnum.ArtifactRef, artifactId);
- HeatParameterValueData heatValueData = new HeatParameterValueData();
- heatValueData.setUniqueId(UniqueIdBuilder.buildHeatParameterValueUniqueId(resourceInstanceId, artifactLabel, heatParameter.getName()));
- heatValueData.setValue(heatParameter.getCurrentValue());
-
- log.debug("Before adding property to graph {}", heatValueData);
- Either<HeatParameterValueData, TitanOperationStatus> createNodeResult = titanGenericDao.createNode(heatValueData, HeatParameterValueData.class);
- log.debug("After adding property to graph {}", heatValueData);
- if (createNodeResult.isRight()) {
- TitanOperationStatus operationStatus = createNodeResult.right().value();
- log.error("Failed to add heat value {} to graph. status is {}", heatValueData.getUniqueId(), operationStatus);
- return Either.right(operationStatus);
- }
-
- Map<String, Object> props = new HashMap<String, Object>();
- props.put(GraphPropertiesDictionary.NAME.getProperty(), heatParameter.getName());
- Either<GraphRelation, TitanOperationStatus> createRelResult = titanGenericDao.createRelation(heatEnvNode, heatValueData, GraphEdgeLabels.PARAMETER_VALUE, props);
- if (createRelResult.isRight()) {
- TitanOperationStatus operationStatus = createRelResult.right().value();
- log.error("Failed to associate heat value {} to heat env artifact {} in graph. status is {}", heatValueData.getUniqueId(), artifactId, operationStatus);
- return Either.right(operationStatus);
- }
- UniqueIdData heatParameterNode = new UniqueIdData(NodeTypeEnum.HeatParameter, heatParameter.getUniqueId());
- Either<GraphRelation, TitanOperationStatus> createRel2Result = titanGenericDao.createRelation(heatValueData, heatParameterNode, GraphEdgeLabels.PARAMETER_IMPL, null);
- if (createRel2Result.isRight()) {
- TitanOperationStatus operationStatus = createRel2Result.right().value();
- log.error("Failed to associate heat value {} to heat parameter {} in graph. status is {}", heatValueData.getUniqueId(), heatParameter.getName(), operationStatus);
- return Either.right(operationStatus);
- }
-
- return Either.left(createNodeResult.left().value());
-
- }
+ // validate default value
+ String defaultValue = propertyDefinition.getDefaultValue();
+ boolean isValidProperty = isValidValue(type, defaultValue);
+ if (!isValidProperty) {
+ log.info("The value {} of property from type {} is invalid", defaultValue, type);
+ return StorageOperationStatus.INVALID_VALUE;
+ }
+
+ PropertyValueConverter converter = type.getConverter();
+
+ if (isEmptyValue(defaultValue)) {
+ log.debug("Default value was not sent for property {}. Set default value to {}", propertyDefinition.getName() , EMPTY_VALUE);
+
+ propertyDefinition.setDefaultValue(EMPTY_VALUE);
+ } else if (!isEmptyValue(defaultValue)) {
+ String convertedValue = converter.convert(defaultValue, null, null);
+ propertyDefinition.setDefaultValue(convertedValue);
+ }
+
+ // validate current value
+ String value = propertyDefinition.getCurrentValue();
+ isValidProperty = isValidValue(type, value);
+ if (!isValidProperty) {
+ log.info("The value {} of property from type {} is invalid", value, type);
+ return StorageOperationStatus.INVALID_VALUE;
+ }
+
+ if (isEmptyValue(value)) {
+ log.debug("Value was not sent for property {}. Set value to {}", propertyDefinition.getName(), EMPTY_VALUE);
+
+ propertyDefinition.setCurrentValue(EMPTY_VALUE);
+ } else if (!value.equals("")) {
+ String convertedValue = converter.convert(value, null, null);
+ propertyDefinition.setCurrentValue(convertedValue);
+ }
+
+ return StorageOperationStatus.OK;
+ }
+
+ public HeatParameterDefinition convertParameterDataToParameterDefinition(HeatParameterData propertyDataResult, String propertyName, String resourceId) {
+ log.debug("convert to HeatParamereDefinition {}", propertyDataResult);
+
+ HeatParameterDefinition propertyDefResult = new HeatParameterDefinition(propertyDataResult.getHeatDataDefinition());
+
+ propertyDefResult.setName(propertyName);
+
+ return propertyDefResult;
+ }
+
+ private HeatParameterType getType(String propertyType) {
+
+ return HeatParameterType.isValidType(propertyType);
+
+ }
+
+ protected boolean isValidValue(HeatParameterType type, String value) {
+ if (isEmptyValue(value)) {
+ return true;
+ }
+
+ PropertyTypeValidator validator = type.getValidator();
+
+ boolean isValid = validator.isValid(value, null, null);
+ if (isValid) {
+ return true;
+ } else {
+ return false;
+ }
+
+ }
+
+ public boolean isEmptyValue(String value) {
+ if (value == null) {
+ return true;
+ }
+ return false;
+ }
+
+ public boolean isNullParam(String value) {
+ if (value == null) {
+ return true;
+ }
+ return false;
+ }
+
+ @Override
+ public Either<HeatParameterValueData, StorageOperationStatus> updateHeatParameterValue(HeatParameterDefinition heatParam, String artifactId, String resourceInstanceId, String artifactLabel) {
+ String heatEnvId = UniqueIdBuilder.buildHeatParameterValueUniqueId(resourceInstanceId, artifactLabel, heatParam.getName());
+ Either<HeatParameterValueData, TitanOperationStatus> getNode = titanGenericDao.getNode(GraphPropertiesDictionary.UNIQUE_ID.getProperty(), heatEnvId, HeatParameterValueData.class);
+ if (getNode.isRight() || getNode.left().value() == null) {
+ if (heatParam.getCurrentValue() == null || (heatParam.getDefaultValue() != null && heatParam.getCurrentValue().equals(heatParam.getDefaultValue()))) {
+ log.debug("Updated heat parameter value equals default value. No need to create heat parameter value for heat parameter {}", heatParam.getUniqueId());
+ return Either.left(null);
+ }
+ return createHeatParameterValue(heatParam, artifactId, resourceInstanceId, artifactLabel);
+ } else {
+ heatParam.setUniqueId(heatEnvId);
+ return updateHeatParameterValue(heatParam);
+ }
+ }
+
+ public Either<HeatParameterValueData, StorageOperationStatus> updateHeatParameterValue(HeatParameterDefinition heatParam) {
+ HeatParameterValueData heatParameterValue = new HeatParameterValueData();
+ heatParameterValue.setUniqueId(heatParam.getUniqueId());
+ if (heatParam.getCurrentValue() == null || (heatParam.getDefaultValue() != null && heatParam.getCurrentValue().equals(heatParam.getDefaultValue()))) {
+ Either<GraphRelation, TitanOperationStatus> deleteParameterValueIncomingRelation = titanGenericDao.deleteIncomingRelationByCriteria(heatParameterValue, GraphEdgeLabels.PARAMETER_VALUE, null);
+ if (deleteParameterValueIncomingRelation.isRight()) {
+ log.debug("Failed to delete heat parameter value incoming relation on graph. id = {}", heatParameterValue.getUniqueId());
+ return Either.right(DaoStatusConverter.convertTitanStatusToStorageStatus(deleteParameterValueIncomingRelation.right().value()));
+ }
+ Either<Edge, TitanOperationStatus> getOutgoingRelation = titanGenericDao.getOutgoingEdgeByCriteria(GraphPropertiesDictionary.UNIQUE_ID.getProperty(), (String) heatParameterValue.getUniqueId(), GraphEdgeLabels.PARAMETER_IMPL, null);
+ if (getOutgoingRelation.isRight()) {
+ log.debug("Failed to get heat parameter value outgoing relation from graph. id = {}", heatParameterValue.getUniqueId());
+ return Either.right(DaoStatusConverter.convertTitanStatusToStorageStatus(getOutgoingRelation.right().value()));
+ }
+ Edge edge = getOutgoingRelation.left().value();
+ if (edge == null) {
+ log.debug("Failed to get heat parameter value outgoing relation from graph. id = {}", heatParameterValue.getUniqueId());
+ return Either.right(StorageOperationStatus.GENERAL_ERROR);
+ }
+ edge.remove();
+
+ Either<HeatParameterValueData, TitanOperationStatus> deleteNode = titanGenericDao.deleteNode(heatParameterValue, HeatParameterValueData.class);
+ if (deleteNode.isRight()) {
+ log.debug("Failed to delete heat parameter value on graph. id = {}", heatParameterValue.getUniqueId());
+ return Either.right(DaoStatusConverter.convertTitanStatusToStorageStatus(deleteNode.right().value()));
+ }
+ return Either.left(deleteNode.left().value());
+ }
+ heatParameterValue.setValue(heatParam.getCurrentValue());
+ Either<HeatParameterValueData, TitanOperationStatus> updateNode = titanGenericDao.updateNode(heatParameterValue, HeatParameterValueData.class);
+ if (updateNode.isRight()) {
+ log.debug("Failed to update heat parameter value in graph. id = {}", heatParameterValue.getUniqueId());
+ return Either.right(DaoStatusConverter.convertTitanStatusToStorageStatus(updateNode.right().value()));
+ }
+ return Either.left(updateNode.left().value());
+ }
+
+ public Either<HeatParameterValueData, StorageOperationStatus> createHeatParameterValue(HeatParameterDefinition heatParam, String artifactId, String resourceInstanceId, String artifactLabel) {
+
+ Either<HeatParameterValueData, TitanOperationStatus> addHeatValueToGraph = addHeatValueToGraph(heatParam, artifactLabel, artifactId, resourceInstanceId);
+ if (addHeatValueToGraph.isRight()) {
+ log.debug("Failed to create heat parameters value on graph for artifact {}", artifactId);
+ return Either.right(DaoStatusConverter.convertTitanStatusToStorageStatus(addHeatValueToGraph.right().value()));
+ }
+ return Either.left(addHeatValueToGraph.left().value());
+ }
+
+ public Either<HeatParameterValueData, TitanOperationStatus> addHeatValueToGraph(HeatParameterDefinition heatParameter, String artifactLabel, String artifactId, String resourceInstanceId) {
+
+ UniqueIdData heatEnvNode = new UniqueIdData(NodeTypeEnum.ArtifactRef, artifactId);
+ HeatParameterValueData heatValueData = new HeatParameterValueData();
+ heatValueData.setUniqueId(UniqueIdBuilder.buildHeatParameterValueUniqueId(resourceInstanceId, artifactLabel, heatParameter.getName()));
+ heatValueData.setValue(heatParameter.getCurrentValue());
+
+ log.debug("Before adding property to graph {}", heatValueData);
+ Either<HeatParameterValueData, TitanOperationStatus> createNodeResult = titanGenericDao.createNode(heatValueData, HeatParameterValueData.class);
+ log.debug("After adding property to graph {}", heatValueData);
+ if (createNodeResult.isRight()) {
+ TitanOperationStatus operationStatus = createNodeResult.right().value();
+ log.error("Failed to add heat value {} to graph. status is {}", heatValueData.getUniqueId(), operationStatus);
+ return Either.right(operationStatus);
+ }
+
+ Map<String, Object> props = new HashMap<>();
+ props.put(GraphPropertiesDictionary.NAME.getProperty(), heatParameter.getName());
+ Either<GraphRelation, TitanOperationStatus> createRelResult = titanGenericDao.createRelation(heatEnvNode, heatValueData, GraphEdgeLabels.PARAMETER_VALUE, props);
+ if (createRelResult.isRight()) {
+ TitanOperationStatus operationStatus = createRelResult.right().value();
+ log.error("Failed to associate heat value {} to heat env artifact {} in graph. status is {}", heatValueData.getUniqueId(), artifactId, operationStatus);
+ return Either.right(operationStatus);
+ }
+ UniqueIdData heatParameterNode = new UniqueIdData(NodeTypeEnum.HeatParameter, heatParameter.getUniqueId());
+ Either<GraphRelation, TitanOperationStatus> createRel2Result = titanGenericDao.createRelation(heatValueData, heatParameterNode, GraphEdgeLabels.PARAMETER_IMPL, null);
+ if (createRel2Result.isRight()) {
+ TitanOperationStatus operationStatus = createRel2Result.right().value();
+ log.error("Failed to associate heat value {} to heat parameter {} in graph. status is {}", heatValueData.getUniqueId(), heatParameter.getName(), operationStatus);
+ return Either.right(operationStatus);
+ }
+
+ return Either.left(createNodeResult.left().value());
+
+ }
}