aboutsummaryrefslogtreecommitdiffstats
path: root/catalog-be/src/main/java
diff options
context:
space:
mode:
authoraribeiro <anderson.ribeiro@est.tech>2020-11-17 10:52:41 +0000
committeraribeiro <anderson.ribeiro@est.tech>2020-11-17 10:52:41 +0000
commit2f74a4ac81f228bdb0bf0f509e9c0ef296d28d82 (patch)
tree78a1a00ae007885085304aa835d0e6e4868bc8b3 /catalog-be/src/main/java
parentba9b67ace03cd9bf1e5f275c060824ce89599b88 (diff)
Fix import VFC with attributes
Fix import VFC with default attribute value Fix Update, create and delete attribute action Make attribute definition tosca compliant Issue-ID: SDC-3381 Signed-off-by: aribeiro <anderson.ribeiro@est.tech> Change-Id: Ibbd36b105b8c86d1e750f3b6d55752d63fe6530e
Diffstat (limited to 'catalog-be/src/main/java')
-rw-r--r--catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/AttributeBusinessLogic.java93
-rw-r--r--catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/BaseBusinessLogic.java29
-rw-r--r--catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/ComponentBusinessLogic.java1
-rw-r--r--catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/ImportUtils.java48
-rw-r--r--catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/ResourceBusinessLogic.java3
-rw-r--r--catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/ResourceImportManager.java60
-rw-r--r--catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/ServiceImportBusinessLogic.java51
-rw-r--r--catalog-be/src/main/java/org/openecomp/sdc/be/servlets/AttributeServlet.java86
-rw-r--r--catalog-be/src/main/java/org/openecomp/sdc/be/tosca/ToscaExportHandler.java27
-rw-r--r--catalog-be/src/main/java/org/openecomp/sdc/be/tosca/model/ToscaNodeType.java3
10 files changed, 213 insertions, 188 deletions
diff --git a/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/AttributeBusinessLogic.java b/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/AttributeBusinessLogic.java
index ef82eba0a4..cef4d8f6df 100644
--- a/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/AttributeBusinessLogic.java
+++ b/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/AttributeBusinessLogic.java
@@ -21,11 +21,17 @@
package org.openecomp.sdc.be.components.impl;
import fj.data.Either;
+import java.util.List;
+import java.util.Map;
+import java.util.Objects;
+import java.util.Optional;
+import org.apache.commons.lang3.tuple.ImmutablePair;
import org.openecomp.sdc.be.config.BeEcompErrorManager;
import org.openecomp.sdc.be.dao.api.ActionStatus;
import org.openecomp.sdc.be.datatypes.elements.AttributeDataDefinition;
+import org.openecomp.sdc.be.datatypes.elements.PropertyDataDefinition;
+import org.openecomp.sdc.be.datatypes.elements.SchemaDefinition;
import org.openecomp.sdc.be.datatypes.enums.NodeTypeEnum;
-import org.openecomp.sdc.be.model.AttributeDefinition;
import org.openecomp.sdc.be.model.DataTypeDefinition;
import org.openecomp.sdc.be.model.Resource;
import org.openecomp.sdc.be.model.jsonjanusgraph.operations.ArtifactsOperations;
@@ -37,16 +43,13 @@ import org.openecomp.sdc.be.model.operations.api.IGroupTypeOperation;
import org.openecomp.sdc.be.model.operations.api.StorageOperationStatus;
import org.openecomp.sdc.be.model.operations.impl.InterfaceLifecycleOperation;
import org.openecomp.sdc.be.model.operations.utils.ComponentValidationUtils;
+import org.openecomp.sdc.be.model.tosca.ToscaPropertyType;
+import org.openecomp.sdc.be.model.tosca.converters.PropertyValueConverter;
import org.openecomp.sdc.common.log.wrappers.Logger;
import org.openecomp.sdc.exception.ResponseFormat;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
-import java.util.List;
-import java.util.Map;
-import java.util.Objects;
-import java.util.Optional;
-
/**
* This class holds the business logic relevant for attributes manipulation.
*
@@ -113,15 +116,15 @@ public class AttributeBusinessLogic extends BaseBusinessLogic {
}
Map<String, DataTypeDefinition> eitherAllDataTypes = getAllDataTypes(applicationDataTypeCache);
// validate property default values
- Either<Boolean, ResponseFormat> defaultValuesValidation = validatePropertyDefaultValue((AttributeDefinition)newAttributeDef, eitherAllDataTypes);
+ Either<Boolean, ResponseFormat> defaultValuesValidation = validateAttributeDefaultValue(newAttributeDef, eitherAllDataTypes);
if (defaultValuesValidation.isRight()) {
return Either.right(defaultValuesValidation.right().value());
}
- handleDefaultValue((AttributeDefinition)newAttributeDef, eitherAllDataTypes);
+ handleAttributeDefaultValue(newAttributeDef, eitherAllDataTypes);
// add the new attribute to resource on graph
- // need to get StorageOpaerationStatus and convert to ActionStatus from
+ // need to get StorageOperationStatus and convert to ActionStatus from
// componentsUtils
Either<AttributeDataDefinition, StorageOperationStatus> either = toscaOperationFacade.addAttributeOfResource(resource, newAttributeDef);
if (either.isRight()) {
@@ -135,13 +138,73 @@ public class AttributeBusinessLogic extends BaseBusinessLogic {
commitOrRollback(result);
graphLockOperation.unlockComponent(resourceId, NodeTypeEnum.Resource);
}
+ }
+
+ private Either<Boolean, ResponseFormat> validateAttributeDefaultValue(final AttributeDataDefinition attributeDefinition,
+ final Map<String, DataTypeDefinition> dataTypes) {
+
+ if (!attributeOperation.isAttributeTypeValid(attributeDefinition)) {
+ log.info("Invalid type for attribute '{}' type '{}'", attributeDefinition.getName(), attributeDefinition.getType());
+ final ResponseFormat responseFormat = componentsUtils.getResponseFormat(ActionStatus.INVALID_PROPERTY_TYPE, attributeDefinition
+ .getType(), attributeDefinition.getName());
+ return Either.right(responseFormat);
+ }
+ String type = attributeDefinition.getType();
+ String innerType = null;
+ if (type.equals(ToscaPropertyType.LIST.getType()) || type.equals(ToscaPropertyType.MAP.getType())) {
+ final ImmutablePair<String, Boolean> propertyInnerTypeValid = attributeOperation.isAttributeInnerTypeValid(
+ attributeDefinition, dataTypes);
+ innerType = propertyInnerTypeValid.getLeft();
+ if (!propertyInnerTypeValid.getRight()) {
+ log.info("Invalid inner type for attribute '{}' type '{}', dataTypeCount '{}'",
+ attributeDefinition.getName(), attributeDefinition.getType(), dataTypes.size());
+ final ResponseFormat responseFormat = componentsUtils
+ .getResponseFormat(ActionStatus.INVALID_PROPERTY_INNER_TYPE, innerType, attributeDefinition.getName());
+ return Either.right(responseFormat);
+ }
+ }
+ if (!attributeOperation.isAttributeDefaultValueValid(attributeDefinition, dataTypes)) {
+ log.info("Invalid default value for attribute '{}' type '{}'", attributeDefinition.getName(),
+ attributeDefinition.getType());
+ ResponseFormat responseFormat;
+ if (type.equals(ToscaPropertyType.LIST.getType()) || type.equals(ToscaPropertyType.MAP.getType())) {
+ responseFormat = componentsUtils.getResponseFormat(ActionStatus.INVALID_COMPLEX_DEFAULT_VALUE,
+ attributeDefinition.getName(), type, innerType,
+ (String) attributeDefinition.get_default());
+ } else {
+ responseFormat = componentsUtils.getResponseFormat(ActionStatus.INVALID_DEFAULT_VALUE,
+ attributeDefinition.getName(), type, (String) attributeDefinition.get_default());
+ }
+ return Either.right(responseFormat);
+
+ }
+ return Either.left(true);
+ }
+
+ private void handleAttributeDefaultValue(final AttributeDataDefinition newAttributeDefinition,
+ final Map<String, DataTypeDefinition> dataTypes) {
+ final ToscaPropertyType type = ToscaPropertyType.isValidType(newAttributeDefinition.getType());
+ final PropertyValueConverter converter = type.getConverter();
+ // get inner type
+ String innerType = null;
+ final SchemaDefinition schema = newAttributeDefinition.getSchema();
+ if (schema != null) {
+ final PropertyDataDefinition prop = schema.getProperty();
+ if (schema.getProperty() != null) {
+ innerType = prop.getType();
+ }
+ }
+ if (newAttributeDefinition.get_default() != null) {
+ newAttributeDefinition.set_default(converter
+ .convert((String) newAttributeDefinition.get_default(), innerType, dataTypes));
+ }
}
private boolean isAttributeExist(List<AttributeDataDefinition> attributes, String resourceUid, String propertyName) {
boolean isExist = false;
if (attributes != null) {
- isExist = attributes.stream().anyMatch(p -> Objects.equals(p.getName(), propertyName) && Objects.equals(p.getParentUniqueId(), resourceUid));
+ isExist = attributes.stream().anyMatch(p -> Objects.equals(p.getName(), propertyName) && Objects.equals(p.getOwnerId(), resourceUid));
}
return isExist;
@@ -169,8 +232,10 @@ public class AttributeBusinessLogic extends BaseBusinessLogic {
return Either.right(componentsUtils.getResponseFormat(ActionStatus.ATTRIBUTE_NOT_FOUND, ""));
} else {
// verify attribute exist in resource
- Optional<AttributeDataDefinition> optionalAtt = attributes.stream().filter(att -> att.getUniqueId().equals(attributeId) && resourceId.equals(att.getParentUniqueId())).findAny();
- return optionalAtt.<Either<AttributeDataDefinition, ResponseFormat>>map(Either::left).orElseGet(() -> Either.right(componentsUtils.getResponseFormat(ActionStatus.ATTRIBUTE_NOT_FOUND, "")));
+ Optional<AttributeDataDefinition> optionalAtt = attributes.stream().filter(att ->
+ att.getUniqueId().equals(attributeId)).findAny();
+ return optionalAtt.<Either<AttributeDataDefinition, ResponseFormat>>map(Either::left).orElseGet(() ->
+ Either.right(componentsUtils.getResponseFormat(ActionStatus.ATTRIBUTE_NOT_FOUND, "")));
}
}
@@ -213,13 +278,13 @@ public class AttributeBusinessLogic extends BaseBusinessLogic {
Map<String, DataTypeDefinition> eitherAllDataTypes = getAllDataTypes(applicationDataTypeCache);
// validate attribute default values
- Either<Boolean, ResponseFormat> defaultValuesValidation = validatePropertyDefaultValue((AttributeDefinition)newAttDef, eitherAllDataTypes);
+ Either<Boolean, ResponseFormat> defaultValuesValidation = validateAttributeDefaultValue(newAttDef, eitherAllDataTypes);
if (defaultValuesValidation.isRight()) {
return Either.right(defaultValuesValidation.right().value());
}
// add the new property to resource on graph
- StorageOperationStatus validateAndUpdateAttribute = propertyOperation.validateAndUpdateProperty((AttributeDefinition)newAttDef, eitherAllDataTypes);
+ StorageOperationStatus validateAndUpdateAttribute = attributeOperation.validateAndUpdateAttribute(newAttDef, eitherAllDataTypes);
if (validateAndUpdateAttribute != StorageOperationStatus.OK) {
log.debug("Problem while updating attribute with id {}. Reason - {}", attributeId, validateAndUpdateAttribute);
result = Either.right(componentsUtils.getResponseFormatByResource(componentsUtils.convertFromStorageResponse(validateAndUpdateAttribute), resource.getName()));
diff --git a/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/BaseBusinessLogic.java b/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/BaseBusinessLogic.java
index 2616801c42..d1df40c091 100644
--- a/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/BaseBusinessLogic.java
+++ b/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/BaseBusinessLogic.java
@@ -79,6 +79,7 @@ import org.openecomp.sdc.be.model.operations.api.IGroupInstanceOperation;
import org.openecomp.sdc.be.model.operations.api.IGroupOperation;
import org.openecomp.sdc.be.model.operations.api.IGroupTypeOperation;
import org.openecomp.sdc.be.model.operations.api.StorageOperationStatus;
+import org.openecomp.sdc.be.model.operations.impl.AttributeOperation;
import org.openecomp.sdc.be.model.operations.impl.DaoStatusConverter;
import org.openecomp.sdc.be.model.operations.impl.InterfaceLifecycleOperation;
import org.openecomp.sdc.be.model.operations.impl.PolicyTypeOperation;
@@ -116,6 +117,7 @@ public abstract class BaseBusinessLogic {
protected JanusGraphDao janusGraphDao;
protected JanusGraphGenericDao janusGraphGenericDao;
protected PropertyOperation propertyOperation;
+ protected AttributeOperation attributeOperation;
protected ApplicationDataTypeCache applicationDataTypeCache;
protected ToscaOperationFacade toscaOperationFacade;
protected ApplicationDataTypeCache dataTypeCache;
@@ -195,6 +197,11 @@ public abstract class BaseBusinessLogic {
this.propertyOperation = propertyOperation;
}
+ @Autowired
+ public void setAttributeOperation(AttributeOperation attributeOperation) {
+ this.attributeOperation = attributeOperation;
+ }
+
User validateUserNotEmpty(User user, String ecompErrorContext) {
return userValidations.validateUserNotEmpty(user, ecompErrorContext);
}
@@ -478,28 +485,6 @@ public abstract class BaseBusinessLogic {
return Either.left(true);
}
-
- void handleDefaultValue(IComplexDefaultValue newAttributeDef, Map<String, DataTypeDefinition> dataTypes) {
- // convert property
- ToscaPropertyType type = ToscaPropertyType.isValidType(newAttributeDef.getType());
- PropertyValueConverter converter = type.getConverter();
- // get inner type
- String innerType = null;
-
- SchemaDefinition schema = newAttributeDef.getSchema();
- if (schema != null) {
- PropertyDataDefinition prop = schema.getProperty();
- if (schema.getProperty() != null) {
- innerType = prop.getType();
- }
- }
- String convertedValue;
- if (newAttributeDef.getDefaultValue() != null) {
- convertedValue = converter.convert(newAttributeDef.getDefaultValue(), innerType, dataTypes);
- newAttributeDef.setDefaultValue(convertedValue);
- }
- }
-
void validateComponentTypeEnum(ComponentTypeEnum componentTypeEnum, String errorContext, Wrapper<ResponseFormat> errorWrapper) {
if (componentTypeEnum == null) {
BeEcompErrorManager.getInstance().logInvalidInputError(errorContext, "invalid component type", ErrorSeverity.INFO);
diff --git a/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/ComponentBusinessLogic.java b/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/ComponentBusinessLogic.java
index 34236eb644..72aeb2b8f9 100644
--- a/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/ComponentBusinessLogic.java
+++ b/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/ComponentBusinessLogic.java
@@ -59,7 +59,6 @@ import org.openecomp.sdc.be.datatypes.tosca.ToscaDataDefinition;
import org.openecomp.sdc.be.facade.operations.CatalogOperation;
import org.openecomp.sdc.be.impl.ComponentsUtils;
import org.openecomp.sdc.be.model.ArtifactDefinition;
-import org.openecomp.sdc.be.model.AttributeDefinition;
import org.openecomp.sdc.be.model.CapReqDef;
import org.openecomp.sdc.be.model.Component;
import org.openecomp.sdc.be.model.ComponentInstance;
diff --git a/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/ImportUtils.java b/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/ImportUtils.java
index f04eca1744..4127faa820 100644
--- a/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/ImportUtils.java
+++ b/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/ImportUtils.java
@@ -20,21 +20,33 @@
package org.openecomp.sdc.be.components.impl;
+import static org.apache.commons.collections.CollectionUtils.isEmpty;
+import static org.openecomp.sdc.be.components.impl.ResourceImportManager.PROPERTY_NAME_PATTERN_IGNORE_LENGTH;
+import static org.openecomp.sdc.be.datatypes.elements.Annotation.setAnnotationsName;
+
import com.google.gson.Gson;
import com.google.gson.GsonBuilder;
import com.google.gson.JsonParseException;
import com.google.gson.reflect.TypeToken;
import fj.data.Either;
+import java.lang.reflect.Type;
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.Iterator;
+import java.util.LinkedHashMap;
+import java.util.List;
+import java.util.Map;
+import java.util.Map.Entry;
+import java.util.function.Consumer;
+import java.util.function.Function;
import org.apache.commons.collections.CollectionUtils;
-import org.apache.commons.collections.MapUtils;
import org.apache.commons.lang3.StringEscapeUtils;
-import org.apache.tinkerpop.gremlin.structure.T;
import org.openecomp.sdc.be.components.impl.exceptions.ByActionStatusComponentException;
import org.openecomp.sdc.be.config.BeEcompErrorManager;
import org.openecomp.sdc.be.dao.api.ActionStatus;
-import org.openecomp.sdc.be.dao.janusgraph.JanusGraphOperationStatus;
import org.openecomp.sdc.be.datatypes.elements.Annotation;
-import org.openecomp.sdc.be.datatypes.elements.AttributeDataDefinition;
import org.openecomp.sdc.be.datatypes.elements.PropertyDataDefinition;
import org.openecomp.sdc.be.datatypes.elements.SchemaDefinition;
import org.openecomp.sdc.be.datatypes.enums.JsonPresentationFields;
@@ -42,7 +54,6 @@ import org.openecomp.sdc.be.datatypes.tosca.ToscaDataDefinition;
import org.openecomp.sdc.be.impl.ComponentsUtils;
import org.openecomp.sdc.be.model.AnnotationTypeDefinition;
import org.openecomp.sdc.be.model.AttributeDefinition;
-import org.openecomp.sdc.be.model.DataTypeDefinition;
import org.openecomp.sdc.be.model.HeatParameterDefinition;
import org.openecomp.sdc.be.model.InputDefinition;
import org.openecomp.sdc.be.model.LifecycleStateEnum;
@@ -70,25 +81,6 @@ import org.yaml.snakeyaml.nodes.Tag;
import org.yaml.snakeyaml.representer.Representer;
import org.yaml.snakeyaml.resolver.Resolver;
-import java.lang.reflect.Type;
-import java.util.ArrayList;
-import java.util.Collection;
-import java.util.Collections;
-import java.util.HashMap;
-import java.util.Iterator;
-import java.util.LinkedHashMap;
-import java.util.List;
-import java.util.Map;
-import java.util.Map.Entry;
-import java.util.function.Consumer;
-import java.util.function.Function;
-
-import static org.apache.commons.collections.CollectionUtils.isEmpty;
-import static org.openecomp.sdc.be.components.impl.ResourceImportManager.PROPERTY_NAME_PATTERN_IGNORE_LENGTH;
-import static org.openecomp.sdc.be.datatypes.elements.Annotation.setAnnotationsName;
-import static org.openecomp.sdc.be.model.jsonjanusgraph.operations.ToscaElementOperation.createDataType;
-import static org.openecomp.sdc.be.model.jsonjanusgraph.operations.ToscaElementOperation.createDataTypeDefinitionWithName;
-
@Component
public final class ImportUtils {
@@ -616,14 +608,6 @@ public final class ImportUtils {
}
- public static Either<Map<String, AttributeDataDefinition>, ResultStatusEnum> getAttributes(
- Map<String, Object> toscaJson) {
- Function<String, AttributeDataDefinition> elementGenByName = ImportUtils::createAttribute;
- Function<Map<String, Object>, AttributeDataDefinition> func = ImportUtils::createModuleAttribute;
-
- return getElements(toscaJson, TypeUtils.ToscaTagNamesEnum.ATTRIBUTES, elementGenByName, func);
- }
-
public static <T> Either<Map<String, T>, ResultStatusEnum> getElements(Map<String, Object> toscaJson,
TypeUtils.ToscaTagNamesEnum elementTagName,
Function<String, T> elementGenByName,
diff --git a/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/ResourceBusinessLogic.java b/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/ResourceBusinessLogic.java
index 50b2941f1b..7788066e52 100644
--- a/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/ResourceBusinessLogic.java
+++ b/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/ResourceBusinessLogic.java
@@ -2660,7 +2660,8 @@ public class ResourceBusinessLogic extends ComponentBusinessLogic {
resource.getComponentInstances()
.stream()
.filter(i -> !i.isCreatedFromCsar())
- .forEach(i->processUiComponentInstance(oldResource, i, instCapabilities, instRequirements, instDeploymentArtifacts, instArtifacts, instProperties, instInputs, instAttributes));
+ .forEach(i -> processUiComponentInstance(oldResource, i, instCapabilities, instRequirements,
+ instDeploymentArtifacts, instArtifacts, instProperties, instInputs, instAttributes));
associateComponentInstancePropertiesToComponent(yamlName, resource, instProperties);
associateComponentInstanceInputsToComponent(yamlName, resource, instInputs);
diff --git a/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/ResourceImportManager.java b/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/ResourceImportManager.java
index 4e6628c8dd..7ff916df32 100644
--- a/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/ResourceImportManager.java
+++ b/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/ResourceImportManager.java
@@ -28,10 +28,22 @@ import static org.openecomp.sdc.be.model.jsonjanusgraph.operations.ToscaElementO
import static org.openecomp.sdc.be.utils.TypeUtils.setField;
import fj.data.Either;
+import java.util.ArrayList;
+import java.util.Arrays;
import java.util.Collections;
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.Iterator;
import java.util.LinkedHashMap;
+import java.util.List;
+import java.util.Map;
+import java.util.Map.Entry;
+import java.util.Set;
+import java.util.function.Function;
+import java.util.regex.Pattern;
+import java.util.stream.Collectors;
+import javax.servlet.ServletContext;
import org.apache.commons.codec.binary.Base64;
-import org.apache.commons.collections4.CollectionUtils;
import org.apache.commons.collections4.MapUtils;
import org.apache.commons.lang3.StringUtils;
import org.apache.commons.lang3.tuple.ImmutablePair;
@@ -62,9 +74,7 @@ import org.openecomp.sdc.be.datatypes.enums.ResourceTypeEnum;
import org.openecomp.sdc.be.impl.ComponentsUtils;
import org.openecomp.sdc.be.impl.WebAppContextWrapper;
import org.openecomp.sdc.be.model.ArtifactDefinition;
-import org.openecomp.sdc.be.model.AttributeDefinition;
import org.openecomp.sdc.be.model.CapabilityDefinition;
-import org.openecomp.sdc.be.model.ComponentInstanceAttribute;
import org.openecomp.sdc.be.model.ComponentInstanceProperty;
import org.openecomp.sdc.be.model.DataTypeDefinition;
import org.openecomp.sdc.be.model.InterfaceDefinition;
@@ -96,20 +106,6 @@ import org.springframework.stereotype.Component;
import org.springframework.web.context.WebApplicationContext;
import org.yaml.snakeyaml.Yaml;
-import javax.servlet.ServletContext;
-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.Set;
-import java.util.function.Function;
-import java.util.regex.Pattern;
-import java.util.stream.Collectors;
-
@Component("resourceImportManager")
public class ResourceImportManager {
@@ -359,7 +355,6 @@ public class ResourceImportManager {
if (StringUtils.isEmpty(resource.getToscaResourceName())) {
setToscaResourceName(toscaJson, resource);
}
- setAttributes(toscaJson, resource);
setCapabilities(toscaJson, resource, parentResource);
setProperties(toscaJson, resource);
setRequirements(toscaJson, resource, parentResource);
@@ -680,28 +675,6 @@ public class ResourceImportManager {
}
}
- private ResultStatusEnum setAttributes(Map<String, Object> toscaJson, Resource resource) {
- ResultStatusEnum result = ResultStatusEnum.OK;
- Either<Map<String, AttributeDataDefinition>, ResultStatusEnum> attributes = ImportUtils
- .getAttributes(toscaJson);
- if (attributes.isLeft()) {
- List<AttributeDataDefinition> attributeList = new ArrayList<>();
- Map<String, AttributeDataDefinition> value = attributes.left().value();
- if (value != null) {
- for (Entry<String, AttributeDataDefinition> entry : value.entrySet()) {
- String name = entry.getKey();
- AttributeDataDefinition attributeDef = entry.getValue();
- attributeDef.setName(name);
- attributeList.add(attributeDef);
- }
- }
- resource.setAttributes(attributeList);
- } else {
- result = attributes.right().value();
- }
- return result;
- }
-
private Resource setDerivedFrom(Map<String, Object> toscaJson, Resource resource) {
Either<String, ResultStatusEnum> toscaDerivedFromElement = ImportUtils
.findFirstToscaStringElement(toscaJson, TypeUtils.ToscaTagNamesEnum.DERIVED_FROM);
@@ -1024,16 +997,17 @@ public class ResourceImportManager {
final Map<String, Object> attributeMap = (Map<String, Object>) value;
- final AttributeDefinition attributeDefinition = new AttributeDefinition();
+ final AttributeDataDefinition attributeDefinition = new AttributeDataDefinition();
attributeDefinition.setName(key);
setField(attributeMap, ToscaTagNamesEnum.DESCRIPTION, attributeDefinition::setDescription);
setField(attributeMap, ToscaTagNamesEnum.TYPE, attributeDefinition::setType);
+ setField(attributeMap, ToscaTagNamesEnum.DEFAULT_VALUE, attributeDefinition::set_default);
setField(attributeMap, ToscaTagNamesEnum.STATUS, attributeDefinition::setStatus);
- setField(attributeMap, ToscaTagNamesEnum.ENTRY_SCHEMA, attributeDefinition::setEntry_schema);
+ setField(attributeMap, ToscaTagNamesEnum.ENTRY_SCHEMA, attributeDefinition::setSchema);
attributeDataDefinitionList.add(attributeDefinition);
} else {
- final AttributeDefinition attributeDefinition = new AttributeDefinition();
+ final AttributeDataDefinition attributeDefinition = new AttributeDataDefinition();
attributeDefinition.setName(key);
attributeDataDefinitionList.add(attributeDefinition);
}
diff --git a/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/ServiceImportBusinessLogic.java b/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/ServiceImportBusinessLogic.java
index b47c3928e8..3b19ea9d86 100644
--- a/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/ServiceImportBusinessLogic.java
+++ b/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/ServiceImportBusinessLogic.java
@@ -24,7 +24,6 @@ import static org.openecomp.sdc.be.components.impl.ImportUtils.getPropertyJsonSt
import static org.openecomp.sdc.be.tosca.CsarUtils.VF_NODE_TYPE_ARTIFACTS_PATH_PATTERN;
import fj.data.Either;
-
import java.util.ArrayList;
import java.util.Collection;
import java.util.EnumMap;
@@ -36,13 +35,10 @@ import java.util.Map;
import java.util.Optional;
import java.util.Set;
import java.util.regex.Pattern;
-
import lombok.Getter;
import lombok.Setter;
-import org.apache.commons.codec.binary.Base64;
import org.apache.commons.collections.CollectionUtils;
import org.apache.commons.collections.MapUtils;
-import org.apache.commons.collections4.ListUtils;
import org.apache.commons.lang3.tuple.ImmutablePair;
import org.openecomp.sdc.be.components.csar.CsarArtifactsAndGroupsBusinessLogic;
import org.openecomp.sdc.be.components.csar.CsarBusinessLogic;
@@ -71,20 +67,13 @@ import org.openecomp.sdc.be.config.BeEcompErrorManager;
import org.openecomp.sdc.be.config.ConfigurationManager;
import org.openecomp.sdc.be.dao.api.ActionStatus;
import org.openecomp.sdc.be.dao.janusgraph.JanusGraphOperationStatus;
-import org.openecomp.sdc.be.dao.jsongraph.types.JsonParseFlagEnum;
import org.openecomp.sdc.be.datamodel.utils.ArtifactUtils;
import org.openecomp.sdc.be.datamodel.utils.UiComponentDataConverter;
-import org.openecomp.sdc.be.datatypes.elements.ArtifactDataDefinition;
import org.openecomp.sdc.be.datatypes.elements.AttributeDataDefinition;
-import org.openecomp.sdc.be.datatypes.elements.CapabilityDataDefinition;
import org.openecomp.sdc.be.datatypes.elements.GetInputValueDataDefinition;
import org.openecomp.sdc.be.datatypes.elements.ListCapabilityDataDefinition;
import org.openecomp.sdc.be.datatypes.elements.ListRequirementDataDefinition;
-import org.openecomp.sdc.be.datatypes.elements.PropertyDataDefinition;
-import org.openecomp.sdc.be.datatypes.elements.RequirementDataDefinition;
-import org.openecomp.sdc.be.datatypes.enums.ComponentFieldsEnum;
import org.openecomp.sdc.be.datatypes.enums.ComponentTypeEnum;
-import org.openecomp.sdc.be.datatypes.enums.CreatedFrom;
import org.openecomp.sdc.be.datatypes.enums.NodeTypeEnum;
import org.openecomp.sdc.be.datatypes.enums.ResourceTypeEnum;
import org.openecomp.sdc.be.impl.ComponentsUtils;
@@ -92,7 +81,6 @@ import org.openecomp.sdc.be.info.NodeTypeInfoToUpdateArtifacts;
import org.openecomp.sdc.be.model.ArtifactDefinition;
import org.openecomp.sdc.be.model.CapabilityDefinition;
import org.openecomp.sdc.be.model.CapabilityRequirementRelationship;
-import org.openecomp.sdc.be.model.CapabilityTypeDefinition;
import org.openecomp.sdc.be.model.Component;
import org.openecomp.sdc.be.model.ComponentInstance;
import org.openecomp.sdc.be.model.ComponentInstanceInput;
@@ -102,7 +90,6 @@ import org.openecomp.sdc.be.model.DataTypeDefinition;
import org.openecomp.sdc.be.model.DistributionStatusEnum;
import org.openecomp.sdc.be.model.GroupDefinition;
import org.openecomp.sdc.be.model.InputDefinition;
-import org.openecomp.sdc.be.model.InterfaceDefinition;
import org.openecomp.sdc.be.model.LifeCycleTransitionEnum;
import org.openecomp.sdc.be.model.LifecycleStateEnum;
import org.openecomp.sdc.be.model.NodeTypeInfo;
@@ -115,16 +102,12 @@ import org.openecomp.sdc.be.model.RequirementCapabilityRelDef;
import org.openecomp.sdc.be.model.RequirementDefinition;
import org.openecomp.sdc.be.model.Resource;
import org.openecomp.sdc.be.model.Service;
-import org.openecomp.sdc.be.model.UploadCapInfo;
import org.openecomp.sdc.be.model.UploadComponentInstanceInfo;
-import org.openecomp.sdc.be.model.UploadInfo;
import org.openecomp.sdc.be.model.UploadNodeFilterInfo;
import org.openecomp.sdc.be.model.UploadPropInfo;
import org.openecomp.sdc.be.model.UploadReqInfo;
import org.openecomp.sdc.be.model.UploadResourceInfo;
import org.openecomp.sdc.be.model.User;
-import org.openecomp.sdc.be.model.category.CategoryDefinition;
-import org.openecomp.sdc.be.model.category.SubCategoryDefinition;
import org.openecomp.sdc.be.model.jsonjanusgraph.datamodel.ToscaElement;
import org.openecomp.sdc.be.model.jsonjanusgraph.operations.ArtifactsOperations;
import org.openecomp.sdc.be.model.jsonjanusgraph.operations.InterfaceOperation;
@@ -132,21 +115,15 @@ import org.openecomp.sdc.be.model.jsonjanusgraph.operations.NodeFilterOperation;
import org.openecomp.sdc.be.model.jsonjanusgraph.operations.ToscaOperationFacade;
import org.openecomp.sdc.be.model.jsonjanusgraph.utils.ModelConverter;
import org.openecomp.sdc.be.model.operations.StorageException;
-import org.openecomp.sdc.be.model.operations.api.ICapabilityTypeOperation;
import org.openecomp.sdc.be.model.operations.api.IElementOperation;
import org.openecomp.sdc.be.model.operations.api.IGroupInstanceOperation;
import org.openecomp.sdc.be.model.operations.api.IGroupOperation;
import org.openecomp.sdc.be.model.operations.api.IGroupTypeOperation;
-import org.openecomp.sdc.be.model.operations.api.IInterfaceLifecycleOperation;
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.InterfaceLifecycleOperation;
-import org.openecomp.sdc.be.model.operations.impl.UniqueIdBuilder;
-import org.openecomp.sdc.be.model.operations.utils.ComponentValidationUtils;
import org.openecomp.sdc.be.resources.data.auditing.AuditingActionEnum;
-import org.openecomp.sdc.be.resources.data.auditing.model.ResourceVersionInfo;
import org.openecomp.sdc.be.tosca.CsarUtils;
-import org.openecomp.sdc.be.utils.CommonBeUtils;
import org.openecomp.sdc.be.utils.TypeUtils;
import org.openecomp.sdc.common.api.ArtifactGroupTypeEnum;
import org.openecomp.sdc.common.api.ArtifactTypeEnum;
@@ -154,11 +131,9 @@ import org.openecomp.sdc.common.api.Constants;
import org.openecomp.sdc.common.datastructure.Wrapper;
import org.openecomp.sdc.common.kpi.api.ASDCKpiApi;
import org.openecomp.sdc.common.log.wrappers.Logger;
-import org.openecomp.sdc.common.util.GeneralUtility;
import org.openecomp.sdc.common.util.ValidationUtils;
import org.openecomp.sdc.exception.ResponseFormat;
import org.springframework.beans.factory.annotation.Autowired;
-import org.yaml.snakeyaml.DumperOptions;
import org.yaml.snakeyaml.Yaml;
@Getter
@@ -1297,7 +1272,18 @@ public class ServiceImportBusinessLogic{
return eitherGetResource.left().value();
}
- protected void processComponentInstance(String yamlName, Resource resource, List<ComponentInstance> componentInstancesList, Either<Map<String, DataTypeDefinition>, JanusGraphOperationStatus> allDataTypes, Map<String, List<ComponentInstanceProperty>> instProperties, Map<ComponentInstance, Map<String, List<CapabilityDefinition>>> instCapabilties, Map<ComponentInstance, Map<String, List<RequirementDefinition>>> instRequirements, Map<String, Map<String, ArtifactDefinition>> instDeploymentArtifacts, Map<String, Map<String, ArtifactDefinition>> instArtifacts, Map<String, List<AttributeDataDefinition>> instAttributes, Map<String, Resource> originCompMap, Map<String, List<ComponentInstanceInput>> instInputs, UploadComponentInstanceInfo uploadComponentInstanceInfo) {
+ protected void processComponentInstance(String yamlName, Resource resource,
+ List<ComponentInstance> componentInstancesList,
+ Either<Map<String, DataTypeDefinition>, JanusGraphOperationStatus> allDataTypes,
+ Map<String, List<ComponentInstanceProperty>> instProperties,
+ Map<ComponentInstance, Map<String, List<CapabilityDefinition>>> instCapabilties,
+ Map<ComponentInstance, Map<String, List<RequirementDefinition>>> instRequirements,
+ Map<String, Map<String, ArtifactDefinition>> instDeploymentArtifacts,
+ Map<String, Map<String, ArtifactDefinition>> instArtifacts,
+ Map<String, List<AttributeDataDefinition>> instAttributes,
+ Map<String, Resource> originCompMap,
+ Map<String, List<ComponentInstanceInput>> instInputs,
+ UploadComponentInstanceInfo uploadComponentInstanceInfo) {
Optional<ComponentInstance> currentCompInstanceOpt = componentInstancesList.stream()
.filter(i -> i.getName().equals(uploadComponentInstanceInfo.getName()))
.findFirst();
@@ -1736,7 +1722,18 @@ public class ServiceImportBusinessLogic{
return eitherGetResource.left().value();
}
- protected void processComponentInstance(String yamlName, Service service, List<ComponentInstance> componentInstancesList, Either<Map<String, DataTypeDefinition>, JanusGraphOperationStatus> allDataTypes, Map<String, List<ComponentInstanceProperty>> instProperties, Map<ComponentInstance, Map<String, List<CapabilityDefinition>>> instCapabilties, Map<ComponentInstance, Map<String, List<RequirementDefinition>>> instRequirements, Map<String, Map<String, ArtifactDefinition>> instDeploymentArtifacts, Map<String, Map<String, ArtifactDefinition>> instArtifacts, Map<String, List<AttributeDataDefinition>> instAttributes, Map<String, Resource> originCompMap, Map<String, List<ComponentInstanceInput>> instInputs, UploadComponentInstanceInfo uploadComponentInstanceInfo) {
+ protected void processComponentInstance(String yamlName, Service service,
+ List<ComponentInstance> componentInstancesList,
+ Either<Map<String, DataTypeDefinition>, JanusGraphOperationStatus> allDataTypes,
+ Map<String, List<ComponentInstanceProperty>> instProperties,
+ Map<ComponentInstance, Map<String, List<CapabilityDefinition>>> instCapabilties,
+ Map<ComponentInstance, Map<String, List<RequirementDefinition>>> instRequirements,
+ Map<String, Map<String, ArtifactDefinition>> instDeploymentArtifacts,
+ Map<String, Map<String, ArtifactDefinition>> instArtifacts,
+ Map<String, List<AttributeDataDefinition>> instAttributes,
+ Map<String, Resource> originCompMap,
+ Map<String, List<ComponentInstanceInput>> instInputs,
+ UploadComponentInstanceInfo uploadComponentInstanceInfo) {
log.debug("enter ServiceImportBusinessLogic processComponentInstance");
Optional<ComponentInstance> currentCompInstanceOpt = componentInstancesList.stream()
.filter(i -> i.getName().equals(uploadComponentInstanceInfo.getName()))
diff --git a/catalog-be/src/main/java/org/openecomp/sdc/be/servlets/AttributeServlet.java b/catalog-be/src/main/java/org/openecomp/sdc/be/servlets/AttributeServlet.java
index 9f54f1fae8..b4b2c15dcb 100644
--- a/catalog-be/src/main/java/org/openecomp/sdc/be/servlets/AttributeServlet.java
+++ b/catalog-be/src/main/java/org/openecomp/sdc/be/servlets/AttributeServlet.java
@@ -20,6 +20,7 @@
package org.openecomp.sdc.be.servlets;
+import com.fasterxml.jackson.databind.ObjectMapper;
import com.google.gson.Gson;
import com.google.gson.GsonBuilder;
import com.jcabi.aspects.Loggable;
@@ -32,6 +33,21 @@ import io.swagger.v3.oas.annotations.media.Schema;
import io.swagger.v3.oas.annotations.responses.ApiResponse;
import io.swagger.v3.oas.annotations.servers.Server;
import io.swagger.v3.oas.annotations.tags.Tag;
+import java.io.IOException;
+import javax.inject.Inject;
+import javax.servlet.ServletContext;
+import javax.servlet.http.HttpServletRequest;
+import javax.ws.rs.Consumes;
+import javax.ws.rs.DELETE;
+import javax.ws.rs.HeaderParam;
+import javax.ws.rs.POST;
+import javax.ws.rs.PUT;
+import javax.ws.rs.Path;
+import javax.ws.rs.PathParam;
+import javax.ws.rs.Produces;
+import javax.ws.rs.core.Context;
+import javax.ws.rs.core.MediaType;
+import javax.ws.rs.core.Response;
import org.openecomp.sdc.be.components.impl.AttributeBusinessLogic;
import org.openecomp.sdc.be.components.impl.ComponentInstanceBusinessLogic;
import org.openecomp.sdc.be.components.impl.ResourceImportManager;
@@ -42,31 +58,15 @@ import org.openecomp.sdc.be.dao.api.ActionStatus;
import org.openecomp.sdc.be.datatypes.elements.AttributeDataDefinition;
import org.openecomp.sdc.be.impl.ComponentsUtils;
import org.openecomp.sdc.be.impl.ServletUtils;
-import org.openecomp.sdc.be.model.AttributeDefinition;
import org.openecomp.sdc.be.model.User;
import org.openecomp.sdc.be.user.UserBusinessLogic;
import org.openecomp.sdc.common.api.Constants;
import org.openecomp.sdc.common.datastructure.Wrapper;
+import org.openecomp.sdc.common.log.enums.EcompLoggerErrorCode;
import org.openecomp.sdc.common.log.wrappers.Logger;
import org.openecomp.sdc.exception.ResponseFormat;
import org.springframework.stereotype.Controller;
-import javax.inject.Inject;
-import javax.servlet.ServletContext;
-import javax.servlet.http.HttpServletRequest;
-import javax.ws.rs.Consumes;
-import javax.ws.rs.DELETE;
-import javax.ws.rs.HeaderParam;
-import javax.ws.rs.POST;
-import javax.ws.rs.PUT;
-import javax.ws.rs.Path;
-import javax.ws.rs.PathParam;
-import javax.ws.rs.Produces;
-import javax.ws.rs.core.Context;
-import javax.ws.rs.core.MediaType;
-import javax.ws.rs.core.Response;
-import java.io.IOException;
-
/**
* Web Servlet for actions on Attributes
*
@@ -122,18 +122,17 @@ public class AttributeServlet extends AbstractValidationsServlet {
log.debug("Start handle request of {} modifier id is {} data is {}", url, userId, data);
try {
- Wrapper<ResponseFormat> errorWrapper = new Wrapper<>();
- Wrapper<AttributeDataDefinition> attributesWrapper = new Wrapper<>();
- // convert json to AttributeDefinition
+ final Wrapper<ResponseFormat> errorWrapper = new Wrapper<>();
+ AttributeDataDefinition attributeDataDefinition = convertJsonToObject(data, errorWrapper);
- buildAttributeFromString(data, attributesWrapper, errorWrapper);
if (errorWrapper.isEmpty()) {
AttributeBusinessLogic businessLogic = getClassFromWebAppContext(context, () -> AttributeBusinessLogic.class);
- Either<AttributeDataDefinition, ResponseFormat> createAttribute = businessLogic.createAttribute(resourceId, attributesWrapper.getInnerElement(), userId);
+ Either<AttributeDataDefinition, ResponseFormat> createAttribute = businessLogic
+ .createAttribute(resourceId, attributeDataDefinition, userId);
if (createAttribute.isRight()) {
errorWrapper.setInnerElement(createAttribute.right().value());
} else {
- attributesWrapper.setInnerElement(createAttribute.left().value());
+ attributeDataDefinition = createAttribute.left().value();
}
}
@@ -142,10 +141,9 @@ public class AttributeServlet extends AbstractValidationsServlet {
log.info("Failed to create Attribute. Reason - ", errorWrapper.getInnerElement());
response = buildErrorResponse(errorWrapper.getInnerElement());
} else {
- AttributeDataDefinition createdAttDef = attributesWrapper.getInnerElement();
- log.debug("Attribute {} created successfully with id {}", createdAttDef.getName(), createdAttDef.getUniqueId());
+ log.debug("Attribute {} created successfully with id {}", attributeDataDefinition.getName(), attributeDataDefinition.getUniqueId());
ResponseFormat responseFormat = getComponentsUtils().getResponseFormat(ActionStatus.CREATED);
- response = buildOkResponse(responseFormat, RepresentationUtils.toRepresentation(createdAttDef));
+ response = buildOkResponse(responseFormat, RepresentationUtils.toRepresentation(attributeDataDefinition));
}
return response;
@@ -197,21 +195,16 @@ public class AttributeServlet extends AbstractValidationsServlet {
log.debug("modifier id is {}", userId);
try {
- // convert json to PropertyDefinition
- Wrapper<ResponseFormat> errorWrapper = new Wrapper<>();
- Wrapper<AttributeDataDefinition> attributesWrapper = new Wrapper<>();
- // convert json to AttributeDefinition
-
- buildAttributeFromString(data, attributesWrapper, errorWrapper);
-
+ final Wrapper<ResponseFormat> errorWrapper = new Wrapper<>();
+ AttributeDataDefinition attributeDataDefinition = convertJsonToObject(data, errorWrapper);
if (errorWrapper.isEmpty()) {
AttributeBusinessLogic businessLogic = getClassFromWebAppContext(context, () -> AttributeBusinessLogic.class);
- Either<AttributeDataDefinition, ResponseFormat> eitherUpdateAttribute = businessLogic.updateAttribute(resourceId, attributeId, attributesWrapper.getInnerElement(), userId);
- // update property
+ Either<AttributeDataDefinition, ResponseFormat> eitherUpdateAttribute = businessLogic
+ .updateAttribute(resourceId, attributeId, attributeDataDefinition, userId);
if (eitherUpdateAttribute.isRight()) {
errorWrapper.setInnerElement(eitherUpdateAttribute.right().value());
} else {
- attributesWrapper.setInnerElement(eitherUpdateAttribute.left().value());
+ attributeDataDefinition = eitherUpdateAttribute.left().value();
}
}
@@ -220,10 +213,9 @@ public class AttributeServlet extends AbstractValidationsServlet {
log.info("Failed to update Attribute. Reason - ", errorWrapper.getInnerElement());
response = buildErrorResponse(errorWrapper.getInnerElement());
} else {
- AttributeDataDefinition updatedAttribute = attributesWrapper.getInnerElement();
- log.debug("Attribute id {} updated successfully ", updatedAttribute.getUniqueId());
+ log.debug("Attribute id {} updated successfully ", attributeDataDefinition.getUniqueId());
ResponseFormat responseFormat = getComponentsUtils().getResponseFormat(ActionStatus.OK);
- response = buildOkResponse(responseFormat, RepresentationUtils.toRepresentation(updatedAttribute));
+ response = buildOkResponse(responseFormat, RepresentationUtils.toRepresentation(attributeDataDefinition));
}
return response;
@@ -295,7 +287,7 @@ public class AttributeServlet extends AbstractValidationsServlet {
Wrapper<ResponseFormat> errorWrapper) {
try {
Gson gson = new GsonBuilder().setPrettyPrinting().create();
- final AttributeDataDefinition attribute = gson.fromJson(data, AttributeDefinition.class);
+ final AttributeDataDefinition attribute = gson.fromJson(data, AttributeDataDefinition.class);
if (attribute == null) {
log.info(ATTRIBUTE_CONTENT_IS_INVALID, data);
ResponseFormat responseFormat = getComponentsUtils().getResponseFormat(ActionStatus.INVALID_CONTENT);
@@ -311,4 +303,18 @@ public class AttributeServlet extends AbstractValidationsServlet {
log.info(ATTRIBUTE_CONTENT_IS_INVALID, data);
}
}
+
+ private AttributeDataDefinition convertJsonToObject(final String data,
+ final Wrapper<ResponseFormat> errorWrapper) {
+
+ final ObjectMapper mapper = new ObjectMapper();
+ try {
+ return mapper.readValue(data, AttributeDataDefinition.class);
+ } catch (final IOException e) {
+ log.error(EcompLoggerErrorCode.BUSINESS_PROCESS_ERROR, ATTRIBUTE_CONTENT_IS_INVALID, data);
+ ResponseFormat responseFormat = getComponentsUtils().getResponseFormat(ActionStatus.INVALID_CONTENT);
+ errorWrapper.setInnerElement(responseFormat);
+ return null;
+ }
+ }
}
diff --git a/catalog-be/src/main/java/org/openecomp/sdc/be/tosca/ToscaExportHandler.java b/catalog-be/src/main/java/org/openecomp/sdc/be/tosca/ToscaExportHandler.java
index 08c3d18157..9eebbc50cb 100644
--- a/catalog-be/src/main/java/org/openecomp/sdc/be/tosca/ToscaExportHandler.java
+++ b/catalog-be/src/main/java/org/openecomp/sdc/be/tosca/ToscaExportHandler.java
@@ -25,6 +25,10 @@ import static org.apache.commons.collections.CollectionUtils.isNotEmpty;
import static org.apache.commons.collections.MapUtils.isNotEmpty;
import static org.openecomp.sdc.be.components.utils.PropertiesUtils.resolvePropertyValueFromInput;
import static org.openecomp.sdc.be.tosca.InterfacesOperationsConverter.addInterfaceTypeElement;
+
+import com.fasterxml.jackson.databind.ObjectMapper;
+import com.fasterxml.jackson.databind.SerializationFeature;
+import fj.data.Either;
import java.beans.IntrospectionException;
import java.util.ArrayList;
import java.util.Collection;
@@ -46,6 +50,7 @@ import org.apache.commons.lang.StringUtils;
import org.apache.commons.lang3.tuple.ImmutablePair;
import org.apache.commons.lang3.tuple.ImmutableTriple;
import org.apache.commons.lang3.tuple.Triple;
+import org.onap.sdc.tosca.datatypes.model.AttributeDefinition;
import org.onap.sdc.tosca.services.YamlUtil;
import org.openecomp.sdc.be.components.impl.exceptions.SdcResourceNotFoundException;
import org.openecomp.sdc.be.config.ConfigurationManager;
@@ -58,7 +63,6 @@ import org.openecomp.sdc.be.datatypes.elements.ListDataDefinition;
import org.openecomp.sdc.be.datatypes.elements.PropertyDataDefinition;
import org.openecomp.sdc.be.datatypes.elements.RequirementNodeFilterCapabilityDataDefinition;
import org.openecomp.sdc.be.datatypes.elements.RequirementNodeFilterPropertyDataDefinition;
-import org.openecomp.sdc.be.datatypes.elements.RequirementSubstitutionFilterCapabilityDataDefinition;
import org.openecomp.sdc.be.datatypes.elements.RequirementSubstitutionFilterPropertyDataDefinition;
import org.openecomp.sdc.be.datatypes.elements.SubstitutionFilterDataDefinition;
import org.openecomp.sdc.be.datatypes.elements.ToscaArtifactDataDefinition;
@@ -123,9 +127,6 @@ import org.yaml.snakeyaml.nodes.NodeTuple;
import org.yaml.snakeyaml.nodes.Tag;
import org.yaml.snakeyaml.representer.Represent;
import org.yaml.snakeyaml.representer.Representer;
-import com.fasterxml.jackson.databind.ObjectMapper;
-import com.fasterxml.jackson.databind.SerializationFeature;
-import fj.data.Either;
@org.springframework.stereotype.Component("tosca-export-handler")
public class ToscaExportHandler {
@@ -1079,14 +1080,28 @@ public class ToscaExportHandler {
if (component instanceof Resource) {
final List<AttributeDataDefinition> attributes = ((Resource) component).getAttributes();
if (CollectionUtils.isNotEmpty(attributes)) {
- final Map<String, AttributeDataDefinition> attributeDataDefinitionMap
- = attributes.stream().collect(Collectors.toMap(AttributeDataDefinition::getName, a -> a));
+ final Map<String, Object> attributeDataDefinitionMap = new HashMap<>();
+ attributes.forEach(attributeDataDefinition ->
+ buildAttributeData(attributeDataDefinition, attributeDataDefinitionMap));
+
toscaNodeType.setAttributes(attributeDataDefinitionMap);
}
}
return toscaNodeType;
}
+ private void buildAttributeData(final AttributeDataDefinition originalAttributeDataDefinition,
+ final Map<String, Object> attributeDataDefinitionMap) {
+
+ attributeDataDefinitionMap.put(originalAttributeDataDefinition.getName(),
+ new ObjectMapper().convertValue(new AttributeDefinition(
+ originalAttributeDataDefinition.getType(),
+ originalAttributeDataDefinition.getDescription(),
+ originalAttributeDataDefinition.get_default(),
+ originalAttributeDataDefinition.getStatus(),
+ originalAttributeDataDefinition.getEntry_schema()), Object.class));
+ }
+
private Either<Map<String, Object>, ToscaError> createProxyInterfaceTypes(Component container) {
Map<String, Object> proxyInterfaceTypes = new HashMap<>();
diff --git a/catalog-be/src/main/java/org/openecomp/sdc/be/tosca/model/ToscaNodeType.java b/catalog-be/src/main/java/org/openecomp/sdc/be/tosca/model/ToscaNodeType.java
index b5e5866fe4..856c430f65 100644
--- a/catalog-be/src/main/java/org/openecomp/sdc/be/tosca/model/ToscaNodeType.java
+++ b/catalog-be/src/main/java/org/openecomp/sdc/be/tosca/model/ToscaNodeType.java
@@ -25,7 +25,6 @@ import java.util.Map;
import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.Setter;
-import org.openecomp.sdc.be.datatypes.elements.AttributeDataDefinition;
@Getter
@Setter
@@ -41,6 +40,6 @@ public class ToscaNodeType {
private Map<String, ToscaCapability> capabilities;
private List<Map<String, ToscaRequirement>> requirements;
- private Map<String, AttributeDataDefinition> attributes;
+ private Map<String, Object> attributes;
}