summaryrefslogtreecommitdiffstats
path: root/catalog-be/src/main
diff options
context:
space:
mode:
Diffstat (limited to 'catalog-be/src/main')
-rw-r--r--catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/BaseBusinessLogic.java2
-rw-r--r--catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/ComponentBusinessLogic.java2
-rw-r--r--catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/DataTypeImportManager.java23
-rw-r--r--catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/ResourceBusinessLogic.java2
-rw-r--r--catalog-be/src/main/java/org/openecomp/sdc/be/components/validation/PropertyValidator.java71
-rw-r--r--catalog-be/src/main/java/org/openecomp/sdc/be/servlets/TypesUploadServlet.java10
6 files changed, 24 insertions, 86 deletions
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 fbfeaa5320..792e6963c0 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
@@ -451,7 +451,7 @@ public abstract class BaseBusinessLogic {
Either<Boolean, ResponseFormat> validatePropertyDefaultValue(IComplexDefaultValue property, Map<String, DataTypeDefinition> dataTypes) {
String type;
String innerType = null;
- if (!propertyOperation.isPropertyTypeValid(property)) {
+ if (!propertyOperation.isPropertyTypeValid(property, null)) {
log.info("Invalid type for property '{}' type '{}'", property.getName(), property.getType());
ResponseFormat responseFormat = componentsUtils
.getResponseFormat(ActionStatus.INVALID_PROPERTY_TYPE, property.getType(), property.getName());
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 afb84a9ea8..d0d40e9db0 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
@@ -821,7 +821,7 @@ public abstract class ComponentBusinessLogic extends BaseBusinessLogic {
if (ToscaPropertyType.isScalarType(propertyType)) {
return false;
}
- Either<DataTypeDefinition, StorageOperationStatus> getDataTypeByNameRes = propertyOperation.getDataTypeByName(propertyType);
+ Either<DataTypeDefinition, StorageOperationStatus> getDataTypeByNameRes = propertyOperation.getDataTypeByName(propertyType, null);
if (getDataTypeByNameRes.isRight()) {
return false;
}
diff --git a/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/DataTypeImportManager.java b/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/DataTypeImportManager.java
index 4c7f072f71..6343eb9b3d 100644
--- a/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/DataTypeImportManager.java
+++ b/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/DataTypeImportManager.java
@@ -27,6 +27,7 @@ import java.util.Map;
import java.util.Set;
import java.util.stream.Collectors;
import javax.annotation.Resource;
+import org.apache.commons.lang3.StringUtils;
import org.apache.commons.lang3.tuple.ImmutablePair;
import org.openecomp.sdc.be.components.impl.CommonImportManager.ElementTypeEnum;
import org.openecomp.sdc.be.dao.api.ActionStatus;
@@ -34,8 +35,10 @@ import org.openecomp.sdc.be.datatypes.elements.PropertyDataDefinition;
import org.openecomp.sdc.be.impl.ComponentsUtils;
import org.openecomp.sdc.be.model.DataTypeDefinition;
import org.openecomp.sdc.be.model.PropertyDefinition;
+import org.openecomp.sdc.be.model.RelationshipTypeDefinition;
import org.openecomp.sdc.be.model.operations.api.StorageOperationStatus;
import org.openecomp.sdc.be.model.operations.impl.PropertyOperation;
+import org.openecomp.sdc.be.model.operations.impl.UniqueIdBuilder;
import org.openecomp.sdc.be.model.tosca.ToscaPropertyType;
import org.openecomp.sdc.be.utils.TypeUtils;
import org.openecomp.sdc.common.log.wrappers.Logger;
@@ -53,20 +56,24 @@ public class DataTypeImportManager {
@Resource
private CommonImportManager commonImportManager;
- public Either<List<ImmutablePair<DataTypeDefinition, Boolean>>, ResponseFormat> createDataTypes(String dataTypeYml) {
+ public Either<List<ImmutablePair<DataTypeDefinition, Boolean>>, ResponseFormat> createDataTypes(final String dataTypeYml, final String modelName) {
return commonImportManager
- .createElementTypes(dataTypeYml, this::createDataTypesFromYml, this::createDataTypesByDao, ElementTypeEnum.DATA_TYPE);
+ .createElementTypes(dataTypeYml, dataTypesFromYml -> createDataTypesFromYml(dataTypeYml, modelName), this::createDataTypesByDao, ElementTypeEnum.DATA_TYPE);
}
-
- private Either<List<DataTypeDefinition>, ActionStatus> createDataTypesFromYml(String dataTypesYml) {
- return commonImportManager.createElementTypesFromYml(dataTypesYml, this::createDataType);
+
+ private Either<List<DataTypeDefinition>, ActionStatus> createDataTypesFromYml(final String dataTypesYml, final String modelName) {
+ final Either<List<DataTypeDefinition>, ActionStatus> dataTypes = commonImportManager.createElementTypesFromYml(dataTypesYml, this::createDataType);
+ if (dataTypes.isLeft() && StringUtils.isNotEmpty(modelName)){
+ dataTypes.left().value().forEach(dataType -> dataType.setModel(modelName));
+ }
+ return dataTypes;
}
private Either<List<ImmutablePair<DataTypeDefinition, Boolean>>, ResponseFormat> createDataTypesByDao(
List<DataTypeDefinition> dataTypesToCreate) {
return commonImportManager.createElementTypesByDao(dataTypesToCreate, this::validateDataType,
- dataType -> new ImmutablePair<>(ElementTypeEnum.DATA_TYPE, dataType.getName()),
- dataTypeName -> propertyOperation.getDataTypeByNameWithoutDerived(dataTypeName), dataType -> propertyOperation.addDataType(dataType),
+ dataType -> new ImmutablePair<>(ElementTypeEnum.DATA_TYPE, UniqueIdBuilder.buildDataTypeUid(dataType.getModel(), dataType.getName())),
+ dataTypeUid -> propertyOperation.getDataTypeByUidWithoutDerived(dataTypeUid, true), dataType -> propertyOperation.addDataType(dataType),
(newDataType, oldDataType) -> propertyOperation.updateDataType(newDataType, oldDataType));
}
@@ -119,7 +126,7 @@ public class DataTypeImportManager {
}
String derivedDataType = dataType.getDerivedFromName();
if (derivedDataType != null) {
- Either<DataTypeDefinition, StorageOperationStatus> derivedDataTypeByName = propertyOperation.getDataTypeByName(derivedDataType, true);
+ Either<DataTypeDefinition, StorageOperationStatus> derivedDataTypeByName = propertyOperation.getDataTypeByName(derivedDataType, dataType.getModel());
if (derivedDataTypeByName.isRight()) {
StorageOperationStatus status = derivedDataTypeByName.right().value();
if (status == StorageOperationStatus.NOT_FOUND) {
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 d692b4fc81..99ceb2158e 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
@@ -4736,7 +4736,7 @@ public class ResourceBusinessLogic extends ComponentBusinessLogic {
String type = null;
String innerType = null;
for (PropertyDefinition property : properties) {
- if (!propertyOperation.isPropertyTypeValid(property)) {
+ if (!propertyOperation.isPropertyTypeValid(property, null)) {
log.info("Invalid type for property {}", property);
throw new ByActionStatusComponentException(ActionStatus.INVALID_PROPERTY_TYPE, property.getType(), property.getName());
}
diff --git a/catalog-be/src/main/java/org/openecomp/sdc/be/components/validation/PropertyValidator.java b/catalog-be/src/main/java/org/openecomp/sdc/be/components/validation/PropertyValidator.java
index bdb6799cb6..33cba4f4a4 100644
--- a/catalog-be/src/main/java/org/openecomp/sdc/be/components/validation/PropertyValidator.java
+++ b/catalog-be/src/main/java/org/openecomp/sdc/be/components/validation/PropertyValidator.java
@@ -19,26 +19,16 @@
*/
package org.openecomp.sdc.be.components.validation;
-import fj.data.Either;
import java.util.List;
import java.util.Map;
import java.util.Optional;
-import org.apache.commons.lang3.tuple.ImmutablePair;
-import org.openecomp.sdc.be.components.impl.ResourceBusinessLogic;
import org.openecomp.sdc.be.components.impl.utils.ExceptionUtils;
-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.impl.ComponentsUtils;
import org.openecomp.sdc.be.model.DataTypeDefinition;
import org.openecomp.sdc.be.model.PropertyDefinition;
-import org.openecomp.sdc.be.model.cache.ApplicationDataTypeCache;
-import org.openecomp.sdc.be.model.operations.impl.DaoStatusConverter;
import org.openecomp.sdc.be.model.operations.impl.PropertyOperation;
-import org.openecomp.sdc.be.model.tosca.ToscaPropertyType;
import org.openecomp.sdc.exception.ResponseFormat;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Component;
@Component
@@ -46,16 +36,13 @@ public class PropertyValidator {
private final PropertyOperation propertyOperation;
private final ComponentsUtils componentsUtils;
- private final ApplicationDataTypeCache applicationDataTypeCache;
private final ExceptionUtils exceptionUtils;
- private static final Logger log = LoggerFactory.getLogger(ResourceBusinessLogic.class);
- public PropertyValidator(PropertyOperation propertyOperation, ComponentsUtils componentsUtils, ApplicationDataTypeCache applicationDataTypeCache,
+ public PropertyValidator(PropertyOperation propertyOperation, ComponentsUtils componentsUtils,
ExceptionUtils exceptionUtils) {
this.exceptionUtils = exceptionUtils;
this.propertyOperation = propertyOperation;
this.componentsUtils = componentsUtils;
- this.applicationDataTypeCache = applicationDataTypeCache;
}
public void thinPropertiesValidator(List<PropertyDefinition> properties, List<PropertyDefinition> dbAnnotationTypeDefinitionProperties,
@@ -87,60 +74,4 @@ public class PropertyValidator {
exceptionUtils.rollBackAndThrow(responseFormat);
return null;
}
-
- public Either<Boolean, ResponseFormat> iterateOverProperties(List<PropertyDefinition> properties) {
- Either<Boolean, ResponseFormat> eitherResult = Either.left(true);
- String type = null;
- String innerType = null;
- for (PropertyDefinition property : properties) {
- if (!propertyOperation.isPropertyTypeValid(property)) {
- log.info("Invalid type for property {}", property);
- ResponseFormat responseFormat = componentsUtils
- .getResponseFormat(ActionStatus.INVALID_PROPERTY_TYPE, property.getType(), property.getName());
- eitherResult = Either.right(responseFormat);
- break;
- }
- Either<Map<String, DataTypeDefinition>, JanusGraphOperationStatus> allDataTypes = applicationDataTypeCache.getAll();
- if (allDataTypes.isRight()) {
- JanusGraphOperationStatus status = allDataTypes.right().value();
- BeEcompErrorManager.getInstance().logInternalFlowError("AddPropertyToGroup", "Failed to validate property. Status is " + status,
- BeEcompErrorManager.ErrorSeverity.ERROR);
- return Either.right(componentsUtils.getResponseFormat(
- componentsUtils.convertFromStorageResponse(DaoStatusConverter.convertJanusGraphStatusToStorageStatus(status))));
- }
- type = property.getType();
- if (type.equals(ToscaPropertyType.LIST.getType()) || type.equals(ToscaPropertyType.MAP.getType())) {
- ResponseFormat responseFormat = validateMapOrListPropertyType(property, allDataTypes.left().value());
- if (responseFormat != null) {
- break;
- }
- }
- if (!propertyOperation.isPropertyDefaultValueValid(property, allDataTypes.left().value())) {
- log.info("Invalid default value for property {}", property);
- ResponseFormat responseFormat;
- if (type.equals(ToscaPropertyType.LIST.getType()) || type.equals(ToscaPropertyType.MAP.getType())) {
- responseFormat = componentsUtils
- .getResponseFormat(ActionStatus.INVALID_COMPLEX_DEFAULT_VALUE, property.getName(), type, innerType,
- property.getDefaultValue());
- } else {
- responseFormat = componentsUtils
- .getResponseFormat(ActionStatus.INVALID_DEFAULT_VALUE, property.getName(), type, property.getDefaultValue());
- }
- eitherResult = Either.right(responseFormat);
- break;
- }
- }
- return eitherResult;
- }
-
- private ResponseFormat validateMapOrListPropertyType(PropertyDefinition property, Map<String, DataTypeDefinition> allDataTypes) {
- ResponseFormat responseFormat = null;
- ImmutablePair<String, Boolean> propertyInnerTypeValid = propertyOperation.isPropertyInnerTypeValid(property, allDataTypes);
- String propertyInnerType = propertyInnerTypeValid.getLeft();
- if (!propertyInnerTypeValid.getRight().booleanValue()) {
- log.info("Invalid inner type for property {}", property);
- responseFormat = componentsUtils.getResponseFormat(ActionStatus.INVALID_PROPERTY_INNER_TYPE, propertyInnerType, property.getName());
- }
- return responseFormat;
- }
}
diff --git a/catalog-be/src/main/java/org/openecomp/sdc/be/servlets/TypesUploadServlet.java b/catalog-be/src/main/java/org/openecomp/sdc/be/servlets/TypesUploadServlet.java
index 1ca18334c4..fed26cccde 100644
--- a/catalog-be/src/main/java/org/openecomp/sdc/be/servlets/TypesUploadServlet.java
+++ b/catalog-be/src/main/java/org/openecomp/sdc/be/servlets/TypesUploadServlet.java
@@ -193,9 +193,9 @@ public class TypesUploadServlet extends AbstractValidationsServlet {
@ApiResponse(responseCode = "409", description = "Data types already exist")})
@PermissionAllowed(AafPermission.PermNames.INTERNAL_ALL_VALUE)
public Response uploadDataTypes(@Parameter(description = "FileInputStream") @FormDataParam("dataTypesZip") File file,
- @Context final HttpServletRequest request, @HeaderParam("USER_ID") String creator) {
- ConsumerTwoParam<Wrapper<Response>, String> createElementsMethod = this::createDataTypes;
- return uploadElementTypeServletLogic(createElementsMethod, file, request, creator, NodeTypeEnum.DataType.getName());
+ @Context final HttpServletRequest request, @HeaderParam("USER_ID") String creator,
+ @Parameter(description = "model") @FormDataParam("model") String modelName) {
+ return uploadElementTypeServletLogic(this::createDataTypes, file, request, creator, NodeTypeEnum.DataType.getName(), modelName);
}
@POST
@@ -338,9 +338,9 @@ public class TypesUploadServlet extends AbstractValidationsServlet {
}
// data types
- private void createDataTypes(Wrapper<Response> responseWrapper, String dataTypesYml) {
+ private void createDataTypes(Wrapper<Response> responseWrapper, String dataTypesYml, final String modelName) {
final Supplier<Either<List<ImmutablePair<DataTypeDefinition, Boolean>>, ResponseFormat>> generateElementTypeFromYml = () -> dataTypeImportManager
- .createDataTypes(dataTypesYml);
+ .createDataTypes(dataTypesYml, modelName);
buildStatusForElementTypeCreate(responseWrapper, generateElementTypeFromYml, ActionStatus.DATA_TYPE_ALREADY_EXIST,
NodeTypeEnum.DataType.name());
}