aboutsummaryrefslogtreecommitdiffstats
path: root/catalog-model/src/main/java/org/openecomp/sdc/be/model/operations/impl/AbstractOperation.java
diff options
context:
space:
mode:
Diffstat (limited to 'catalog-model/src/main/java/org/openecomp/sdc/be/model/operations/impl/AbstractOperation.java')
-rw-r--r--catalog-model/src/main/java/org/openecomp/sdc/be/model/operations/impl/AbstractOperation.java499
1 files changed, 235 insertions, 264 deletions
diff --git a/catalog-model/src/main/java/org/openecomp/sdc/be/model/operations/impl/AbstractOperation.java b/catalog-model/src/main/java/org/openecomp/sdc/be/model/operations/impl/AbstractOperation.java
index f0e4056663..b42581aee4 100644
--- a/catalog-model/src/main/java/org/openecomp/sdc/be/model/operations/impl/AbstractOperation.java
+++ b/catalog-model/src/main/java/org/openecomp/sdc/be/model/operations/impl/AbstractOperation.java
@@ -20,13 +20,12 @@
package org.openecomp.sdc.be.model.operations.impl;
-import java.lang.reflect.Type;
-import java.util.List;
-import java.util.Map;
-import java.util.function.Function;
-import java.util.function.Supplier;
-import java.util.stream.Collectors;
-
+import com.google.gson.Gson;
+import com.google.gson.GsonBuilder;
+import com.google.gson.JsonElement;
+import com.google.gson.reflect.TypeToken;
+import com.thinkaurelius.titan.core.TitanVertex;
+import fj.data.Either;
import org.apache.commons.lang3.tuple.ImmutablePair;
import org.openecomp.sdc.be.config.BeEcompErrorManager;
import org.openecomp.sdc.be.config.BeEcompErrorManager.ErrorSeverity;
@@ -51,331 +50,303 @@ import org.openecomp.sdc.be.model.tosca.validators.DataTypeValidatorConverter;
import org.openecomp.sdc.be.model.tosca.validators.PropertyTypeValidator;
import org.openecomp.sdc.be.resources.data.ResourceMetadataData;
import org.openecomp.sdc.be.resources.data.UniqueIdData;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-
-import com.google.gson.Gson;
-import com.google.gson.GsonBuilder;
-import com.google.gson.JsonElement;
-import com.google.gson.reflect.TypeToken;
-import com.thinkaurelius.titan.core.TitanVertex;
+import org.openecomp.sdc.common.log.wrappers.Logger;
+import org.springframework.beans.factory.annotation.Autowired;
-import fj.data.Either;
+import java.lang.reflect.Type;
+import java.util.List;
+import java.util.Map;
+import java.util.function.Supplier;
+import java.util.stream.Collectors;
public abstract class AbstractOperation {
- private static Logger log = LoggerFactory.getLogger(AbstractOperation.class.getName());
- @javax.annotation.Resource
- protected TitanGenericDao titanGenericDao;
- public static final String EMPTY_VALUE = null;
- protected Gson gson = new Gson();
+ private static final Logger log = Logger.getLogger(AbstractOperation.class.getName());
+
+ @Autowired
+ protected TitanGenericDao titanGenericDao;
+
+ public static final String EMPTY_VALUE = null;
+
+ protected Gson gson = new Gson();
+
+ @Autowired
+ protected ApplicationDataTypeCache applicationDataTypeCache;
+
+ protected DataTypeValidatorConverter dataTypeValidatorConverter = DataTypeValidatorConverter.getInstance();
+
+ protected <SomeData extends GraphNode, SomeDefenition> Either<SomeData, TitanOperationStatus> addDefinitionToNodeType(SomeDefenition someDefinition, NodeTypeEnum nodeType, String nodeUniqueId, final GraphEdgeLabels edgeType,
+ Supplier<SomeData> dataBuilder, Supplier<String> defNameGenerator) {
+ String defName = defNameGenerator.get();
+ log.debug("Got {} {}", defName, someDefinition);
+
+ SomeData someData = dataBuilder.get();
+
+ log.debug("Before adding {} to graph. data = {}", defName, someData);
+
+ @SuppressWarnings("unchecked")
+ Either<SomeData, TitanOperationStatus> eitherSomeData = titanGenericDao.createNode(someData, (Class<SomeData>) someData.getClass());
+
+ log.debug("After adding {} to graph. status is = {}", defName, eitherSomeData);
+
+ if (eitherSomeData.isRight()) {
+ TitanOperationStatus operationStatus = eitherSomeData.right().value();
+ log.error("Failed to add {} to graph. status is {}", defName, operationStatus);
+ return Either.right(operationStatus);
+ }
+ UniqueIdData uniqueIdData = new UniqueIdData(nodeType, nodeUniqueId);
+ log.debug("Before associating {} to {}.", uniqueIdData, defName);
- @javax.annotation.Resource
- protected ApplicationDataTypeCache applicationDataTypeCache;
-
- protected DataTypeValidatorConverter dataTypeValidatorConverter = DataTypeValidatorConverter.getInstance();
-
- protected <SomeData extends GraphNode, SomeDefenition> Either<SomeData, TitanOperationStatus> addDefinitionToNodeType(SomeDefenition someDefinition, NodeTypeEnum nodeType, String nodeUniqueId, final GraphEdgeLabels edgeType,
- Supplier<SomeData> dataBuilder, Supplier<String> defNameGenerator) {
- String defName = defNameGenerator.get();
- log.debug("Got {} {}", defName, someDefinition);
-
- SomeData someData = dataBuilder.get();
-
- log.debug("Before adding {} to graph. data = {}", defName, someData);
-
- @SuppressWarnings("unchecked")
- Either<SomeData, TitanOperationStatus> eitherSomeData = titanGenericDao.createNode(someData, (Class<SomeData>) someData.getClass());
-
- log.debug("After adding {} to graph. status is = {}", defName, eitherSomeData);
-
- if (eitherSomeData.isRight()) {
- TitanOperationStatus operationStatus = eitherSomeData.right().value();
- log.error("Failed to add {} to graph. status is {}", defName, operationStatus);
- return Either.right(operationStatus);
- }
- UniqueIdData uniqueIdData = new UniqueIdData(nodeType, nodeUniqueId);
- log.debug("Before associating {} to {}.", uniqueIdData, defName);
-
- Either<GraphRelation, TitanOperationStatus> eitherRelations = titanGenericDao.createRelation(uniqueIdData, eitherSomeData.left().value(), edgeType, null);
- if (eitherRelations.isRight()) {
- TitanOperationStatus operationStatus = eitherRelations.right().value();
- BeEcompErrorManager.getInstance().logInternalFlowError("AddDefinitionToNodeType", "Failed to associate" + nodeType.getName() + " " + nodeUniqueId + "to " + defName + "in graph. status is " + operationStatus, ErrorSeverity.ERROR);
- return Either.right(operationStatus);
- }
- return Either.left(eitherSomeData.left().value());
- }
-
- protected <SomeData extends GraphNode, SomeDefenition> TitanOperationStatus addDefinitionToNodeType(TitanVertex vertex, SomeDefenition someDefinition, NodeTypeEnum nodeType, String nodeUniqueId, final GraphEdgeLabels edgeType,
- Supplier<SomeData> dataBuilder, Supplier<String> defNameGenerator) {
- String defName = defNameGenerator.get();
- log.debug("Got {} {}", defName, someDefinition);
-
- SomeData someData = dataBuilder.get();
-
- log.debug("Before adding {} to graph. data = {}", defName, someData);
-
- @SuppressWarnings("unchecked")
- Either<TitanVertex, TitanOperationStatus> eitherSomeData = titanGenericDao.createNode(someData);
-
- log.debug("After adding {} to graph. status is = {}", defName, eitherSomeData);
-
- if (eitherSomeData.isRight()) {
- TitanOperationStatus operationStatus = eitherSomeData.right().value();
- log.error("Failed to add {} to graph. status is {}", defName, operationStatus);
- return operationStatus;
- }
+ Either<GraphRelation, TitanOperationStatus> eitherRelations = titanGenericDao.createRelation(uniqueIdData, eitherSomeData.left().value(), edgeType, null);
+ if (eitherRelations.isRight()) {
+ TitanOperationStatus operationStatus = eitherRelations.right().value();
+ BeEcompErrorManager.getInstance().logInternalFlowError("AddDefinitionToNodeType", "Failed to associate" + nodeType.getName() + " " + nodeUniqueId + "to " + defName + "in graph. status is " + operationStatus, ErrorSeverity.ERROR);
+ return Either.right(operationStatus);
+ }
+ return Either.left(eitherSomeData.left().value());
+ }
- TitanOperationStatus relations = titanGenericDao.createEdge(vertex, eitherSomeData.left().value(), edgeType, null);
- if (!relations.equals(TitanOperationStatus.OK)) {
- TitanOperationStatus operationStatus = relations;
- BeEcompErrorManager.getInstance().logInternalFlowError("AddDefinitionToNodeType", "Failed to associate" + nodeType.getName() + " " + nodeUniqueId + "to " + defName + "in graph. status is " + operationStatus, ErrorSeverity.ERROR);
- return operationStatus;
- }
- return relations;
- }
+ protected <SomeData extends GraphNode, SomeDefenition> TitanOperationStatus addDefinitionToNodeType(TitanVertex vertex, SomeDefenition someDefinition, NodeTypeEnum nodeType, String nodeUniqueId, final GraphEdgeLabels edgeType,
+ Supplier<SomeData> dataBuilder, Supplier<String> defNameGenerator) {
+ String defName = defNameGenerator.get();
+ log.debug("Got {} {}", defName, someDefinition);
- interface NodeElementFetcher<ElementDefinition> {
- TitanOperationStatus findAllNodeElements(String nodeId, List<ElementDefinition> listTofill);
- }
+ SomeData someData = dataBuilder.get();
- public <ElementDefinition> TitanOperationStatus findAllResourceElementsDefinitionRecursively(String resourceId, List<ElementDefinition> elements, NodeElementFetcher<ElementDefinition> singleNodeFetcher) {
+ log.debug("Before adding {} to graph. data = {}", defName, someData);
- if (log.isTraceEnabled())
- log.trace("Going to fetch elements under resource {}", resourceId);
- TitanOperationStatus resourceAttributesStatus = singleNodeFetcher.findAllNodeElements(resourceId, elements);
+ @SuppressWarnings("unchecked")
+ Either<TitanVertex, TitanOperationStatus> eitherSomeData = titanGenericDao.createNode(someData);
- if (resourceAttributesStatus != TitanOperationStatus.OK) {
- return resourceAttributesStatus;
- }
+ log.debug("After adding {} to graph. status is = {}", defName, eitherSomeData);
- Either<ImmutablePair<ResourceMetadataData, GraphEdge>, TitanOperationStatus> parentNodes = titanGenericDao.getChild(UniqueIdBuilder.getKeyByNodeType(NodeTypeEnum.Resource), resourceId, GraphEdgeLabels.DERIVED_FROM, NodeTypeEnum.Resource,
- ResourceMetadataData.class);
+ if (eitherSomeData.isRight()) {
+ TitanOperationStatus operationStatus = eitherSomeData.right().value();
+ log.error("Failed to add {} to graph. status is {}", defName, operationStatus);
+ return operationStatus;
+ }
- if (parentNodes.isRight()) {
- TitanOperationStatus parentNodesStatus = parentNodes.right().value();
- if (parentNodesStatus != TitanOperationStatus.NOT_FOUND) {
- BeEcompErrorManager.getInstance().logInternalFlowError("findAllResourceElementsDefinitionRecursively", "Failed to find parent elements of resource " + resourceId + ". status is " + parentNodesStatus, ErrorSeverity.ERROR);
- return parentNodesStatus;
- }
- }
+ TitanOperationStatus relations = titanGenericDao.createEdge(vertex, eitherSomeData.left().value(), edgeType, null);
+ if (!relations.equals(TitanOperationStatus.OK)) {
+ BeEcompErrorManager.getInstance().logInternalFlowError("AddDefinitionToNodeType", "Failed to associate" + nodeType.getName() + " " + nodeUniqueId + "to " + defName + "in graph. status is " + relations, ErrorSeverity.ERROR);
+ return relations;
+ }
+ return relations;
+ }
- if (parentNodes.isLeft()) {
- ImmutablePair<ResourceMetadataData, GraphEdge> parnetNodePair = parentNodes.left().value();
- String parentUniqueId = parnetNodePair.getKey().getMetadataDataDefinition().getUniqueId();
- TitanOperationStatus addParentIntStatus = findAllResourceElementsDefinitionRecursively(parentUniqueId, elements, singleNodeFetcher);
-
- if (addParentIntStatus != TitanOperationStatus.OK) {
- BeEcompErrorManager.getInstance().logInternalFlowError("findAllResourceElementsDefinitionRecursively", "Failed to find all resource elements of resource " + parentUniqueId, ErrorSeverity.ERROR);
+ interface NodeElementFetcher<ElementDefinition> {
+ TitanOperationStatus findAllNodeElements(String nodeId, List<ElementDefinition> listTofill);
+ }
- return addParentIntStatus;
- }
- }
- return TitanOperationStatus.OK;
- }
+ public <ElementDefinition> TitanOperationStatus findAllResourceElementsDefinitionRecursively(String resourceId, List<ElementDefinition> elements, NodeElementFetcher<ElementDefinition> singleNodeFetcher) {
- protected <T, TStatus> void handleTransactionCommitRollback(boolean inTransaction, Either<T, TStatus> result) {
- if (!inTransaction) {
- if (result == null || result.isRight()) {
- log.error("Going to execute rollback on graph.");
- titanGenericDao.rollback();
- } else {
- log.debug("Going to execute commit on graph.");
- titanGenericDao.commit();
- }
- }
- }
+ if (log.isTraceEnabled())
+ log.trace("Going to fetch elements under resource {}", resourceId);
+ TitanOperationStatus resourceAttributesStatus = singleNodeFetcher.findAllNodeElements(resourceId, elements);
- public <ElementTypeDefinition> Either<ElementTypeDefinition, StorageOperationStatus> getElementType(Function<String, Either<ElementTypeDefinition, TitanOperationStatus>> elementGetter, String uniqueId, boolean inTransaction) {
- Either<ElementTypeDefinition, StorageOperationStatus> result = null;
- try {
-
- Either<ElementTypeDefinition, TitanOperationStatus> ctResult = elementGetter.apply(uniqueId);
+ if (resourceAttributesStatus != TitanOperationStatus.OK) {
+ return resourceAttributesStatus;
+ }
- if (ctResult.isRight()) {
- TitanOperationStatus status = ctResult.right().value();
- if (status != TitanOperationStatus.NOT_FOUND) {
- log.error("Failed to retrieve information on element uniqueId: {}. status is {}", uniqueId, status);
- }
- result = Either.right(DaoStatusConverter.convertTitanStatusToStorageStatus(ctResult.right().value()));
- return result;
- }
+ Either<ImmutablePair<ResourceMetadataData, GraphEdge>, TitanOperationStatus> parentNodes = titanGenericDao.getChild(UniqueIdBuilder.getKeyByNodeType(NodeTypeEnum.Resource), resourceId, GraphEdgeLabels.DERIVED_FROM, NodeTypeEnum.Resource,
+ ResourceMetadataData.class);
- result = Either.left(ctResult.left().value());
+ if (parentNodes.isRight()) {
+ TitanOperationStatus parentNodesStatus = parentNodes.right().value();
+ if (parentNodesStatus != TitanOperationStatus.NOT_FOUND) {
+ BeEcompErrorManager.getInstance().logInternalFlowError("findAllResourceElementsDefinitionRecursively", "Failed to find parent elements of resource " + resourceId + ". status is " + parentNodesStatus, ErrorSeverity.ERROR);
+ return parentNodesStatus;
+ }
+ }
- return result;
- } finally {
- handleTransactionCommitRollback(inTransaction, result);
+ if (parentNodes.isLeft()) {
+ ImmutablePair<ResourceMetadataData, GraphEdge> parnetNodePair = parentNodes.left().value();
+ String parentUniqueId = parnetNodePair.getKey().getMetadataDataDefinition().getUniqueId();
+ TitanOperationStatus addParentIntStatus = findAllResourceElementsDefinitionRecursively(parentUniqueId, elements, singleNodeFetcher);
- }
+ if (addParentIntStatus != TitanOperationStatus.OK) {
+ BeEcompErrorManager.getInstance().logInternalFlowError("findAllResourceElementsDefinitionRecursively", "Failed to find all resource elements of resource " + parentUniqueId, ErrorSeverity.ERROR);
- }
+ return addParentIntStatus;
+ }
+ }
+ return TitanOperationStatus.OK;
+ }
- /**
- * @param propertyDefinition
- * @return
- */
+ protected <T, TStatus> void handleTransactionCommitRollback(boolean inTransaction, Either<T, TStatus> result) {
+ if (!inTransaction) {
+ if (result == null || result.isRight()) {
+ log.error("Going to execute rollback on graph.");
+ titanGenericDao.rollback();
+ } else {
+ log.debug("Going to execute commit on graph.");
+ titanGenericDao.commit();
+ }
+ }
+ }
- protected StorageOperationStatus validateAndUpdateProperty(IComplexDefaultValue propertyDefinition, Map<String, DataTypeDefinition> dataTypes) {
- log.trace("Going to validate property type and value. {}", propertyDefinition);
+ /**
+ * @param propertyDefinition
+ * @return
+ */
- String propertyType = propertyDefinition.getType();
- String value = propertyDefinition.getDefaultValue();
+ protected StorageOperationStatus validateAndUpdateProperty(IComplexDefaultValue propertyDefinition, Map<String, DataTypeDefinition> dataTypes) {
- ToscaPropertyType type = getType(propertyType);
+ log.trace("Going to validate property type and value. {}", propertyDefinition);
- if (type == null) {
+ String propertyType = propertyDefinition.getType();
+ String value = propertyDefinition.getDefaultValue();
- DataTypeDefinition dataTypeDefinition = dataTypes.get(propertyType);
- if (dataTypeDefinition == null) {
- log.debug("The type {} of property cannot be found.", propertyType);
- return StorageOperationStatus.INVALID_TYPE;
- }
+ ToscaPropertyType type = getType(propertyType);
- StorageOperationStatus status = validateAndUpdateComplexValue(propertyDefinition, propertyType, value, dataTypeDefinition, dataTypes);
+ if (type == null) {
- return status;
+ DataTypeDefinition dataTypeDefinition = dataTypes.get(propertyType);
+ if (dataTypeDefinition == null) {
+ log.debug("The type {} of property cannot be found.", propertyType);
+ return StorageOperationStatus.INVALID_TYPE;
+ }
- }
- String innerType = null;
+ return validateAndUpdateComplexValue(propertyDefinition, propertyType, value, dataTypeDefinition, dataTypes);
- Either<String, TitanOperationStatus> checkInnerType = getInnerType(type, () -> propertyDefinition.getSchema());
- if (checkInnerType.isRight()) {
- return StorageOperationStatus.INVALID_TYPE;
- }
- innerType = checkInnerType.left().value();
+ }
+ String innerType = null;
- log.trace("After validating property type {}", propertyType);
+ Either<String, TitanOperationStatus> checkInnerType = getInnerType(type, propertyDefinition::getSchema);
+ if (checkInnerType.isRight()) {
+ return StorageOperationStatus.INVALID_TYPE;
+ }
+ innerType = checkInnerType.left().value();
- boolean isValidProperty = isValidValue(type, value, innerType, dataTypes);
- if (false == isValidProperty) {
- log.info("The value {} of property from type {} is invalid", value, type);
- return StorageOperationStatus.INVALID_VALUE;
- }
+ log.trace("After validating property type {}", propertyType);
- PropertyValueConverter converter = type.getConverter();
+ boolean isValidProperty = isValidValue(type, value, innerType, dataTypes);
+ if (!isValidProperty) {
+ log.info("The value {} of property from type {} is invalid", value, type);
+ return StorageOperationStatus.INVALID_VALUE;
+ }
- if (isEmptyValue(value)) {
- 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(value)) {
- String convertedValue = converter.convert(value, innerType, dataTypes);
- propertyDefinition.setDefaultValue(convertedValue);
- }
- return StorageOperationStatus.OK;
- }
+ PropertyValueConverter converter = type.getConverter();
- protected ToscaPropertyType getType(String propertyType) {
+ if (isEmptyValue(value)) {
+ log.debug("Default value was not sent for property {}. Set default value to {}", propertyDefinition.getName(), EMPTY_VALUE);
+ propertyDefinition.setDefaultValue(EMPTY_VALUE);
+ } else if (!isEmptyValue(value)) {
+ String convertedValue = converter.convert(value, innerType, dataTypes);
+ propertyDefinition.setDefaultValue(convertedValue);
+ }
+ return StorageOperationStatus.OK;
+ }
- ToscaPropertyType type = ToscaPropertyType.isValidType(propertyType);
+ protected ToscaPropertyType getType(String propertyType) {
- return type;
+ return ToscaPropertyType.isValidType(propertyType);
- }
+ }
- protected boolean isValidValue(ToscaPropertyType type, String value, String innerType, Map<String, DataTypeDefinition> dataTypes) {
- if (isEmptyValue(value)) {
- return true;
- }
+ protected boolean isValidValue(ToscaPropertyType type, String value, String innerType, Map<String, DataTypeDefinition> dataTypes) {
+ if (isEmptyValue(value)) {
+ return true;
+ }
- PropertyTypeValidator validator = type.getValidator();
+ PropertyTypeValidator validator = type.getValidator();
- return validator.isValid(value, innerType, dataTypes);
- }
+ return validator.isValid(value, innerType, dataTypes);
+ }
- public boolean isEmptyValue(String value) {
- return value == null;
- }
+ public boolean isEmptyValue(String value) {
+ return value == null;
+ }
- public boolean isNullParam(String value) {
- return value == null;
- }
+ public boolean isNullParam(String value) {
+ return value == null;
+ }
- protected StorageOperationStatus validateAndUpdateComplexValue(IComplexDefaultValue propertyDefinition, String propertyType,
+ protected StorageOperationStatus validateAndUpdateComplexValue(IComplexDefaultValue propertyDefinition, String propertyType,
- String value, DataTypeDefinition dataTypeDefinition, Map<String, DataTypeDefinition> dataTypes) {
+ String value, DataTypeDefinition dataTypeDefinition, Map<String, DataTypeDefinition> dataTypes) {
- ImmutablePair<JsonElement, Boolean> validateResult = dataTypeValidatorConverter.validateAndUpdate(value, dataTypeDefinition, dataTypes);
+ ImmutablePair<JsonElement, Boolean> validateResult = dataTypeValidatorConverter.validateAndUpdate(value, dataTypeDefinition, dataTypes);
- if (validateResult.right.booleanValue() == false) {
- log.debug("The value {} of property from type {} is invalid", propertyType, propertyType);
- return StorageOperationStatus.INVALID_VALUE;
- }
+ if (!validateResult.right.booleanValue()) {
+ log.debug("The value {} of property from type {} is invalid", propertyType, propertyType);
+ return StorageOperationStatus.INVALID_VALUE;
+ }
- JsonElement jsonElement = validateResult.left;
+ JsonElement jsonElement = validateResult.left;
- log.trace("Going to update value in property definition {} {}" , propertyDefinition.getName() , (jsonElement != null ? jsonElement.toString() : null));
+ log.trace("Going to update value in property definition {} {}" , propertyDefinition.getName() , (jsonElement != null ? jsonElement.toString() : null));
- updateValue(propertyDefinition, jsonElement);
+ updateValue(propertyDefinition, jsonElement);
- return StorageOperationStatus.OK;
- }
+ return StorageOperationStatus.OK;
+ }
- protected void updateValue(IComplexDefaultValue propertyDefinition, JsonElement jsonElement) {
+ protected void updateValue(IComplexDefaultValue propertyDefinition, JsonElement jsonElement) {
- propertyDefinition.setDefaultValue(getValueFromJsonElement(jsonElement));
+ propertyDefinition.setDefaultValue(getValueFromJsonElement(jsonElement));
- }
+ }
- protected String getValueFromJsonElement(JsonElement jsonElement) {
- String value = null;
+ protected String getValueFromJsonElement(JsonElement jsonElement) {
+ String value = null;
- if (jsonElement == null || jsonElement.isJsonNull()) {
- value = EMPTY_VALUE;
- } else {
- value = jsonElement.toString();
- }
+ if (jsonElement == null || jsonElement.isJsonNull()) {
+ value = EMPTY_VALUE;
+ } else {
+ value = jsonElement.toString();
+ }
- return value;
- }
+ return value;
+ }
- protected Either<String, TitanOperationStatus> getInnerType(ToscaPropertyType type, Supplier<SchemaDefinition> schemeGen) {
- String innerType = null;
- if (type == ToscaPropertyType.LIST || type == ToscaPropertyType.MAP) {
+ protected Either<String, TitanOperationStatus> getInnerType(ToscaPropertyType type, Supplier<SchemaDefinition> schemeGen) {
+ String innerType = null;
+ if (type == ToscaPropertyType.LIST || type == ToscaPropertyType.MAP) {
- SchemaDefinition def = schemeGen.get();// propDataDef.getSchema();
- if (def == null) {
- log.debug("Schema doesn't exists for property of type {}", type);
- return Either.right(TitanOperationStatus.ILLEGAL_ARGUMENT);
- }
- PropertyDataDefinition propDef = def.getProperty();
- if (propDef == null) {
- log.debug("Property in Schema Definition inside property of type {} doesn't exist", type);
- return Either.right(TitanOperationStatus.ILLEGAL_ARGUMENT);
- }
- innerType = propDef.getType();
- }
- return Either.left(innerType);
- }
+ SchemaDefinition def = schemeGen.get();
+ if (def == null) {
+ log.debug("Schema doesn't exists for property of type {}", type);
+ return Either.right(TitanOperationStatus.ILLEGAL_ARGUMENT);
+ }
+ PropertyDataDefinition propDef = def.getProperty();
+ if (propDef == null) {
+ log.debug("Property in Schema Definition inside property of type {} doesn't exist", type);
+ return Either.right(TitanOperationStatus.ILLEGAL_ARGUMENT);
+ }
+ innerType = propDef.getType();
+ }
+ return Either.left(innerType);
+ }
- /**
- * Convert Constarint object to json in order to add it to the Graph
- *
- * @param constraints
- * @return
- */
- public List<String> convertConstraintsToString(List<PropertyConstraint> constraints) {
+ /**
+ * Convert Constarint object to json in order to add it to the Graph
+ *
+ * @param constraints
+ * @return
+ */
+ public List<String> convertConstraintsToString(List<PropertyConstraint> constraints) {
- if (constraints == null || constraints.isEmpty()) {
- return null;
- }
+ if (constraints == null || constraints.isEmpty()) {
+ return null;
+ }
- return constraints.stream().map(gson::toJson).collect(Collectors.toList());
- }
+ return constraints.stream().map(gson::toJson).collect(Collectors.toList());
+ }
- public List<PropertyConstraint> convertConstraints(List<String> constraints) {
+ public List<PropertyConstraint> convertConstraints(List<String> constraints) {
- if (constraints == null || constraints.isEmpty()) {
- return null;
- }
+ if (constraints == null || constraints.isEmpty()) {
+ return null;
+ }
- Type constraintType = new TypeToken<PropertyConstraint>() {
- }.getType();
+ Type constraintType = new TypeToken<PropertyConstraint>() {
+ }.getType();
- Gson gson = new GsonBuilder().registerTypeAdapter(constraintType, new PropertyConstraintDeserialiser()).create();
+ Gson gson = new GsonBuilder().registerTypeAdapter(constraintType, new PropertyConstraintDeserialiser()).create();
- return constraints.stream().map(c -> gson.fromJson(c, PropertyConstraint.class)).collect(Collectors.toList());
- }
+ return constraints.stream().map(c -> gson.fromJson(c, PropertyConstraint.class)).collect(Collectors.toList());
+ }
}