aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-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
-rw-r--r--catalog-be/src/test/java/org/openecomp/sdc/be/components/impl/InputsBusinessLogicTest.java8
-rw-r--r--catalog-be/src/test/java/org/openecomp/sdc/be/components/impl/ResourceBusinessLogicTest.java2
-rw-r--r--catalog-be/src/test/java/org/openecomp/sdc/be/components/validation/PropertyValidatorTest.java18
-rw-r--r--catalog-model/src/main/java/org/openecomp/sdc/be/model/DataTypeDefinition.java2
-rw-r--r--catalog-model/src/main/java/org/openecomp/sdc/be/model/operations/api/IPropertyOperation.java8
-rw-r--r--catalog-model/src/main/java/org/openecomp/sdc/be/model/operations/impl/AttributeOperation.java2
-rw-r--r--catalog-model/src/main/java/org/openecomp/sdc/be/model/operations/impl/PropertyOperation.java148
-rw-r--r--catalog-model/src/main/java/org/openecomp/sdc/be/model/operations/impl/UniqueIdBuilder.java4
-rw-r--r--catalog-model/src/test/java/org/openecomp/sdc/be/model/operations/impl/PropertyOperationTest.java124
15 files changed, 207 insertions, 219 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());
}
diff --git a/catalog-be/src/test/java/org/openecomp/sdc/be/components/impl/InputsBusinessLogicTest.java b/catalog-be/src/test/java/org/openecomp/sdc/be/components/impl/InputsBusinessLogicTest.java
index 548ef1ace9..308d272a79 100644
--- a/catalog-be/src/test/java/org/openecomp/sdc/be/components/impl/InputsBusinessLogicTest.java
+++ b/catalog-be/src/test/java/org/openecomp/sdc/be/components/impl/InputsBusinessLogicTest.java
@@ -469,7 +469,7 @@ public class InputsBusinessLogicTest {
// for BaseOperation.getAllDataTypes:
when(applicationDataTypeCache.getAll()).thenReturn(Either.left(new HashMap<>())); // don't use Collections.emptyMap
// for BaseOperation.validatePropertyDefaultValue:
- when(propertyOperation.isPropertyTypeValid(any())).thenReturn(true);
+ when(propertyOperation.isPropertyTypeValid(any(), any())).thenReturn(true);
when(propertyOperation.isPropertyInnerTypeValid(any(),any())).thenReturn(new ImmutablePair<>(listInput.getSchemaType(), true));
when(propertyOperation.isPropertyDefaultValueValid(any(), any())).thenReturn(true);
// for createListInputsInGraph:
@@ -565,12 +565,12 @@ public class InputsBusinessLogicTest {
when(propertyDeclarationOrchestrator.getPropOwnerId(componentInstInputsMap)).thenReturn(COMPONENT_INSTANCE_ID);
when(applicationDataTypeCache.getAll()).thenReturn(Either.left(new HashMap<>())); // don't use Collections.emptyMap
// for BaseOperation.validatePropertyDefaultValue:
- when(propertyOperation.isPropertyTypeValid(any())).thenReturn(false);
+ when(propertyOperation.isPropertyTypeValid(any(), any())).thenReturn(false);
Either<List<InputDefinition>, ResponseFormat> result =
testInstance.createListInput(USER_ID, COMPONENT_ID, ComponentTypeEnum.SERVICE, createListInputParams, true, false);
assertThat(result.isRight()).isTrue();
- verify(propertyOperation, times(1)).isPropertyTypeValid(any());
+ verify(propertyOperation, times(1)).isPropertyTypeValid(any(), any());
}
@Test
@@ -585,7 +585,7 @@ public class InputsBusinessLogicTest {
when(propertyDeclarationOrchestrator.getPropOwnerId(componentInstInputsMap)).thenReturn(COMPONENT_INSTANCE_ID);
when(applicationDataTypeCache.getAll()).thenReturn(Either.left(new HashMap<>())); // don't use Collections.emptyMap
// for BaseOperation.validatePropertyDefaultValue:
- when(propertyOperation.isPropertyTypeValid(any())).thenReturn(true);
+ when(propertyOperation.isPropertyTypeValid(any(), any())).thenReturn(true);
when(propertyOperation.isPropertyInnerTypeValid(any(),any())).thenReturn(new ImmutablePair<>(listInput.getSchemaType(), true));
when(propertyOperation.isPropertyDefaultValueValid(any(), any())).thenReturn(true);
when(toscaOperationFacadeMock.addInputsToComponent(anyMap(), eq(COMPONENT_ID))).thenReturn(Either.right(StorageOperationStatus.NOT_FOUND));
diff --git a/catalog-be/src/test/java/org/openecomp/sdc/be/components/impl/ResourceBusinessLogicTest.java b/catalog-be/src/test/java/org/openecomp/sdc/be/components/impl/ResourceBusinessLogicTest.java
index 09f4ac72de..17078bcb75 100644
--- a/catalog-be/src/test/java/org/openecomp/sdc/be/components/impl/ResourceBusinessLogicTest.java
+++ b/catalog-be/src/test/java/org/openecomp/sdc/be/components/impl/ResourceBusinessLogicTest.java
@@ -1720,7 +1720,7 @@ public class ResourceBusinessLogicTest {
List<PropertyDefinition> properties = new ArrayList<>();
properties.add(property);
basic.setProperties(properties);
- when(propertyOperation.isPropertyTypeValid(property)).thenReturn(true);
+ when(propertyOperation.isPropertyTypeValid(property, null)).thenReturn(true);
when(propertyOperation.isPropertyDefaultValueValid(property, emptyDataTypes)).thenReturn(true);
Boolean validatePropertiesDefaultValues = bl.validatePropertiesDefaultValues(basic);
assertTrue(validatePropertiesDefaultValues);
diff --git a/catalog-be/src/test/java/org/openecomp/sdc/be/components/validation/PropertyValidatorTest.java b/catalog-be/src/test/java/org/openecomp/sdc/be/components/validation/PropertyValidatorTest.java
index 9a9e9578b6..f85ec2953a 100644
--- a/catalog-be/src/test/java/org/openecomp/sdc/be/components/validation/PropertyValidatorTest.java
+++ b/catalog-be/src/test/java/org/openecomp/sdc/be/components/validation/PropertyValidatorTest.java
@@ -59,8 +59,7 @@ public class PropertyValidatorTest {
Mockito.when(propertyOperation.validateAndUpdatePropertyValue(
Mockito.any(), Mockito.any(), Mockito.any(), Mockito.any())).thenReturn(Either.left(""));
- PropertyValidator propertyValidator = new PropertyValidator(propertyOperation, componentsUtils,
- applicationDataTypeCache, exceptionUtils);
+ PropertyValidator propertyValidator = new PropertyValidator(propertyOperation, componentsUtils, exceptionUtils);
List<PropertyDefinition> props = new ArrayList<>();
List<PropertyDefinition> dbProps = new ArrayList<>();
PropertyDefinition prop = new PropertyDefinition();
@@ -73,19 +72,4 @@ public class PropertyValidatorTest {
Mockito.verify(propertyOperation).validateAndUpdatePropertyValue(TYPE, VALUE, null, Collections.emptyMap());
}
-
- @Test
- public void shouldIterateOverPropertiesOnInvalidType() {
- PropertyValidator propertyValidator = new PropertyValidator(propertyOperation, componentsUtils,
- applicationDataTypeCache, exceptionUtils);
- List<PropertyDefinition> props = new ArrayList<>();
- PropertyDefinition prop = new PropertyDefinition();
- prop.setName(TEST);
- prop.setValue(VALUE);
- prop.setType(TYPE);
- props.add(prop);
- Either<Boolean, ResponseFormat> booleanResponseFormatEither = propertyValidator.iterateOverProperties(props);
-
- assertTrue(booleanResponseFormatEither.isRight());
- }
} \ No newline at end of file
diff --git a/catalog-model/src/main/java/org/openecomp/sdc/be/model/DataTypeDefinition.java b/catalog-model/src/main/java/org/openecomp/sdc/be/model/DataTypeDefinition.java
index b61aa5a4c2..01f6cd1b40 100644
--- a/catalog-model/src/main/java/org/openecomp/sdc/be/model/DataTypeDefinition.java
+++ b/catalog-model/src/main/java/org/openecomp/sdc/be/model/DataTypeDefinition.java
@@ -36,6 +36,7 @@ public class DataTypeDefinition extends DataTypeDataDefinition {
private DataTypeDefinition derivedFrom;
private List<PropertyConstraint> constraints;
private List<PropertyDefinition> properties;
+ private String model;
public DataTypeDefinition(final DataTypeDataDefinition dataTypeDataDefinition) {
super(dataTypeDataDefinition);
@@ -49,6 +50,7 @@ public class DataTypeDefinition extends DataTypeDataDefinition {
this.setUniqueId(dataTypeDefinition.getUniqueId());
this.setConstraints(dataTypeDefinition.getConstraints());
this.setDescription(dataTypeDefinition.getDescription());
+ this.setModel(dataTypeDefinition.getModel());
}
public List<PropertyConstraint> safeGetConstraints() {
diff --git a/catalog-model/src/main/java/org/openecomp/sdc/be/model/operations/api/IPropertyOperation.java b/catalog-model/src/main/java/org/openecomp/sdc/be/model/operations/api/IPropertyOperation.java
index 163ee43655..c0cc097c49 100644
--- a/catalog-model/src/main/java/org/openecomp/sdc/be/model/operations/api/IPropertyOperation.java
+++ b/catalog-model/src/main/java/org/openecomp/sdc/be/model/operations/api/IPropertyOperation.java
@@ -50,7 +50,7 @@ public interface IPropertyOperation {
public boolean isPropertyDefaultValueValid(IComplexDefaultValue propertyDefinition, Map<String, DataTypeDefinition> dataTypes);
- public boolean isPropertyTypeValid(IComplexDefaultValue propertyDefinition);
+ public boolean isPropertyTypeValid(IComplexDefaultValue propertyDefinition, String model);
public ImmutablePair<String, Boolean> isPropertyInnerTypeValid(IComplexDefaultValue propertyDefinition,
Map<String, DataTypeDefinition> dataTypes);
@@ -65,11 +65,9 @@ public interface IPropertyOperation {
* @param name
* @return
*/
- public Either<DataTypeDefinition, StorageOperationStatus> getDataTypeByName(String name);
+ public Either<DataTypeDefinition, StorageOperationStatus> getDataTypeByName(String name, String validForModel);
- public Either<DataTypeDefinition, StorageOperationStatus> getDataTypeByName(String name, boolean inTransaction);
-
- public Either<DataTypeDefinition, StorageOperationStatus> getDataTypeByNameWithoutDerived(String name);
+ public Either<DataTypeDefinition, StorageOperationStatus> getDataTypeByName(String name, String validForModel, boolean inTransaction);
public StorageOperationStatus validateAndUpdateProperty(IComplexDefaultValue propertyDefinition, Map<String, DataTypeDefinition> dataTypes);
diff --git a/catalog-model/src/main/java/org/openecomp/sdc/be/model/operations/impl/AttributeOperation.java b/catalog-model/src/main/java/org/openecomp/sdc/be/model/operations/impl/AttributeOperation.java
index 74dc4207a1..685dc85675 100644
--- a/catalog-model/src/main/java/org/openecomp/sdc/be/model/operations/impl/AttributeOperation.java
+++ b/catalog-model/src/main/java/org/openecomp/sdc/be/model/operations/impl/AttributeOperation.java
@@ -78,7 +78,7 @@ public class AttributeOperation extends AbstractOperation {
}
private Either<Boolean, JanusGraphOperationStatus> isDefinedInDataTypes(final String propertyType) {
- final String dataTypeUid = UniqueIdBuilder.buildDataTypeUid(propertyType);
+ final String dataTypeUid = UniqueIdBuilder.buildDataTypeUid(null, propertyType);
final Either<DataTypeDefinition, JanusGraphOperationStatus> dataTypeByUid = getDataTypeByUid(dataTypeUid);
if (dataTypeByUid.isRight()) {
final JanusGraphOperationStatus status = dataTypeByUid.right().value();
diff --git a/catalog-model/src/main/java/org/openecomp/sdc/be/model/operations/impl/PropertyOperation.java b/catalog-model/src/main/java/org/openecomp/sdc/be/model/operations/impl/PropertyOperation.java
index 06323644b7..1f4fca0685 100644
--- a/catalog-model/src/main/java/org/openecomp/sdc/be/model/operations/impl/PropertyOperation.java
+++ b/catalog-model/src/main/java/org/openecomp/sdc/be/model/operations/impl/PropertyOperation.java
@@ -19,20 +19,8 @@
*/
package org.openecomp.sdc.be.model.operations.impl;
-import com.fasterxml.jackson.core.ObjectCodec;
-import com.fasterxml.jackson.databind.DeserializationContext;
-import com.fasterxml.jackson.databind.JsonNode;
-import com.google.common.collect.Maps;
-import com.google.gson.JsonArray;
-import com.google.gson.JsonDeserializationContext;
-import com.google.gson.JsonDeserializer;
-import com.google.gson.JsonElement;
-import com.google.gson.JsonObject;
-import com.google.gson.JsonParseException;
-import com.google.gson.JsonParser;
-import com.google.gson.JsonSerializationContext;
-import com.google.gson.JsonSerializer;
-import fj.data.Either;
+import static org.openecomp.sdc.common.log.enums.EcompLoggerErrorCode.BUSINESS_PROCESS_ERROR;
+
import java.io.IOException;
import java.lang.reflect.Type;
import java.util.ArrayList;
@@ -101,10 +89,25 @@ import org.openecomp.sdc.be.resources.data.UniqueIdData;
import org.openecomp.sdc.common.log.wrappers.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
+import com.fasterxml.jackson.core.ObjectCodec;
+import com.fasterxml.jackson.databind.DeserializationContext;
+import com.fasterxml.jackson.databind.JsonNode;
+import com.google.common.collect.Maps;
+import com.google.gson.JsonArray;
+import com.google.gson.JsonDeserializationContext;
+import com.google.gson.JsonDeserializer;
+import com.google.gson.JsonElement;
+import com.google.gson.JsonObject;
+import com.google.gson.JsonParseException;
+import com.google.gson.JsonParser;
+import com.google.gson.JsonSerializationContext;
+import com.google.gson.JsonSerializer;
+import fj.data.Either;
@Component("property-operation")
public class PropertyOperation extends AbstractOperation implements IPropertyOperation {
+ private static final String AFTER_RETRIEVING_DERIVED_FROM_NODE_OF_STATUS_IS = "After retrieving DERIVED_FROM node of {}. status is {}";
private static final String FAILED_TO_FETCH_PROPERTIES_OF_DATA_TYPE = "Failed to fetch properties of data type {}";
private static final String DATA_TYPE_CANNOT_BE_FOUND_IN_GRAPH_STATUS_IS = "Data type {} cannot be found in graph. status is {}";
private static final String GOING_TO_EXECUTE_COMMIT_ON_GRAPH = "Going to execute commit on graph.";
@@ -809,12 +812,12 @@ public class PropertyOperation extends AbstractOperation implements IPropertyOpe
}
}
- public boolean isPropertyTypeValid(IComplexDefaultValue property) {
+ public boolean isPropertyTypeValid(final IComplexDefaultValue property, final String model) {
if (property == null) {
return false;
}
if (ToscaPropertyType.isValidType(property.getType()) == null) {
- Either<Boolean, JanusGraphOperationStatus> definedInDataTypes = isDefinedInDataTypes(property.getType());
+ Either<Boolean, JanusGraphOperationStatus> definedInDataTypes = isDefinedInDataTypes(property.getType(), model);
if (definedInDataTypes.isRight()) {
return false;
} else {
@@ -1115,7 +1118,7 @@ public class PropertyOperation extends AbstractOperation implements IPropertyOpe
*/
private Either<DataTypeData, JanusGraphOperationStatus> addDataTypeToGraph(DataTypeDefinition dataTypeDefinition) {
log.debug("Got data type {}", dataTypeDefinition);
- String dtUniqueId = UniqueIdBuilder.buildDataTypeUid(dataTypeDefinition.getName());
+ String dtUniqueId = UniqueIdBuilder.buildDataTypeUid(dataTypeDefinition.getModel(), dataTypeDefinition.getName());
DataTypeData dataTypeData = buildDataTypeData(dataTypeDefinition, dtUniqueId);
log.debug("Before adding data type to graph. dataTypeData = {}", dataTypeData);
Either<DataTypeData, JanusGraphOperationStatus> createDataTypeResult = janusGraphGenericDao.createNode(dataTypeData, DataTypeData.class);
@@ -1128,17 +1131,28 @@ public class PropertyOperation extends AbstractOperation implements IPropertyOpe
}
DataTypeData resultCTD = createDataTypeResult.left().value();
List<PropertyDefinition> properties = dataTypeDefinition.getProperties();
- Either<Map<String, PropertyData>, JanusGraphOperationStatus> addPropertiesToDataType = addPropertiesToDataType(resultCTD.getUniqueId(),
+ Either<Map<String, PropertyData>, JanusGraphOperationStatus> addPropertiesToDataType = addPropertiesToDataType(resultCTD.getUniqueId(), dataTypeDefinition.getModel(),
properties);
if (addPropertiesToDataType.isRight()) {
log.debug("Failed add properties {} to data type {}", properties, dataTypeDefinition.getName());
return Either.right(addPropertiesToDataType.right().value());
}
+
+ final Either<GraphRelation, JanusGraphOperationStatus> modelRelationship = addDataTypeToModel(dataTypeDefinition);
+ if (modelRelationship.isRight()) {
+ return Either.right(modelRelationship.right().value());
+ }
+
String derivedFrom = dataTypeDefinition.getDerivedFromName();
if (derivedFrom != null) {
+ final Either<DataTypeDefinition, JanusGraphOperationStatus> derivedFromDataType = getDataTypeByNameValidForModel(derivedFrom, dataTypeDefinition.getModel());
+ if (derivedFromDataType.isRight()) {
+ return Either.right(derivedFromDataType.right().value());
+ }
+
log.debug("Before creating relation between data type {} to its parent {}", dtUniqueId, derivedFrom);
UniqueIdData from = new UniqueIdData(NodeTypeEnum.DataType, dtUniqueId);
- String deriveFromUid = UniqueIdBuilder.buildDataTypeUid(derivedFrom);
+ final String deriveFromUid = derivedFromDataType.left().value().getUniqueId();
UniqueIdData to = new UniqueIdData(NodeTypeEnum.DataType, deriveFromUid);
Either<GraphRelation, JanusGraphOperationStatus> createRelation = janusGraphGenericDao
.createRelation(from, to, GraphEdgeLabels.DERIVED_FROM, null);
@@ -1149,6 +1163,17 @@ public class PropertyOperation extends AbstractOperation implements IPropertyOpe
}
return Either.left(createDataTypeResult.left().value());
}
+
+ private Either<GraphRelation, JanusGraphOperationStatus> addDataTypeToModel(final DataTypeDefinition dataTypeDefinition) {
+ final String model = dataTypeDefinition.getModel();
+ if (model == null) {
+ return Either.left(null);
+ }
+ final GraphNode from = new UniqueIdData(NodeTypeEnum.Model, UniqueIdBuilder.buildModelUid(model));
+ final GraphNode to = new UniqueIdData(NodeTypeEnum.DataType, dataTypeDefinition.getUniqueId());
+ log.info("Connecting model {} to type {}", from, to);
+ return janusGraphGenericDao.createRelation(from , to, GraphEdgeLabels.MODEL_ELEMENT, Collections.emptyMap());
+ }
private DataTypeData buildDataTypeData(DataTypeDefinition dataTypeDefinition, String ctUniqueId) {
DataTypeData dataTypeData = new DataTypeData(dataTypeDefinition);
@@ -1171,14 +1196,14 @@ public class PropertyOperation extends AbstractOperation implements IPropertyOpe
* @param properties
* @return
*/
- private Either<Map<String, PropertyData>, JanusGraphOperationStatus> addPropertiesToDataType(String uniqueId,
- List<PropertyDefinition> properties) {
+ private Either<Map<String, PropertyData>, JanusGraphOperationStatus> addPropertiesToDataType(final String uniqueId, final String modelName,
+ final List<PropertyDefinition> properties) {
Map<String, PropertyData> propertiesData = new HashMap<>();
if (properties != null && !properties.isEmpty()) {
for (PropertyDefinition propertyDefinition : properties) {
String propertyName = propertyDefinition.getName();
String propertyType = propertyDefinition.getType();
- Either<Boolean, JanusGraphOperationStatus> validPropertyType = isValidPropertyType(propertyType);
+ Either<Boolean, JanusGraphOperationStatus> validPropertyType = isValidPropertyType(propertyType, modelName);
if (validPropertyType.isRight()) {
log.debug("Data type {} contains invalid property type {}", uniqueId, propertyType);
return Either.right(validPropertyType.right().value());
@@ -1217,6 +1242,45 @@ public class PropertyOperation extends AbstractOperation implements IPropertyOpe
}
return Either.left(propertiesData);
}
+
+ public Either<DataTypeDefinition, JanusGraphOperationStatus> getDataTypeByNameValidForModel(final String name, final String modelName) {
+ final Either<DataTypeData, JanusGraphOperationStatus> dataTypesRes = janusGraphGenericDao
+ .getNode(GraphPropertiesDictionary.NAME.getProperty(), name, DataTypeData.class, modelName);
+ if (dataTypesRes.isRight()) {
+ final JanusGraphOperationStatus status = dataTypesRes.right().value();
+ log.debug(DATA_TYPE_CANNOT_BE_FOUND_IN_GRAPH_STATUS_IS, name, status);
+ return Either.right(status);
+ }
+ final DataTypeData dataType = dataTypesRes.left().value();
+ final DataTypeDefinition dataTypeDefinition = new DataTypeDefinition(dataType.getDataTypeDataDefinition());
+ final JanusGraphOperationStatus propertiesStatus = fillProperties(dataTypeDefinition.getUniqueId(), dataTypeDefinition);
+ if (propertiesStatus != JanusGraphOperationStatus.OK) {
+ log.error(BUSINESS_PROCESS_ERROR, FAILED_TO_FETCH_PROPERTIES_OF_DATA_TYPE, dataTypeDefinition.getUniqueId());
+ return Either.right(propertiesStatus);
+ }
+ final Either<ImmutablePair<DataTypeData, GraphEdge>, JanusGraphOperationStatus> parentNode = janusGraphGenericDao
+ .getChild(UniqueIdBuilder.getKeyByNodeType(NodeTypeEnum.DataType), dataTypeDefinition.getUniqueId(), GraphEdgeLabels.DERIVED_FROM, NodeTypeEnum.DataType,
+ DataTypeData.class);
+ log.debug(AFTER_RETRIEVING_DERIVED_FROM_NODE_OF_STATUS_IS, dataTypeDefinition.getUniqueId(), parentNode);
+ if (parentNode.isRight()) {
+ final JanusGraphOperationStatus janusGraphOperationStatus = parentNode.right().value();
+ if (janusGraphOperationStatus != JanusGraphOperationStatus.NOT_FOUND) {
+ log.error(BUSINESS_PROCESS_ERROR, "Failed to find the parent data type of data type {}. status is {}", dataTypeDefinition.getUniqueId(), janusGraphOperationStatus);
+ return Either.right(janusGraphOperationStatus);
+ }
+ } else {
+ // derived from node was found
+ final ImmutablePair<DataTypeData, GraphEdge> immutablePair = parentNode.left().value();
+ final DataTypeData parentDataType = immutablePair.getKey();
+ final Either<DataTypeDefinition, JanusGraphOperationStatus> dataTypeByUid = getDataTypeByUid(parentDataType.getUniqueId());
+ if (dataTypeByUid.isRight()) {
+ return Either.right(dataTypeByUid.right().value());
+ }
+ DataTypeDefinition parentDataTypeDefinition = dataTypeByUid.left().value();
+ dataTypeDefinition.setDerivedFrom(parentDataTypeDefinition);
+ }
+ return Either.left(dataTypeDefinition);
+ }
/**
* Build Data type object from graph by unique id
@@ -1243,7 +1307,7 @@ public class PropertyOperation extends AbstractOperation implements IPropertyOpe
Either<ImmutablePair<DataTypeData, GraphEdge>, JanusGraphOperationStatus> parentNode = janusGraphGenericDao
.getChild(UniqueIdBuilder.getKeyByNodeType(NodeTypeEnum.DataType), uniqueId, GraphEdgeLabels.DERIVED_FROM, NodeTypeEnum.DataType,
DataTypeData.class);
- log.debug("After retrieving DERIVED_FROM node of {}. status is {}", uniqueId, parentNode);
+ log.debug(AFTER_RETRIEVING_DERIVED_FROM_NODE_OF_STATUS_IS, uniqueId, parentNode);
if (parentNode.isRight()) {
JanusGraphOperationStatus janusGraphOperationStatus = parentNode.right().value();
if (janusGraphOperationStatus != JanusGraphOperationStatus.NOT_FOUND) {
@@ -1330,11 +1394,10 @@ public class PropertyOperation extends AbstractOperation implements IPropertyOpe
}
@Override
- public Either<DataTypeDefinition, StorageOperationStatus> getDataTypeByName(String name, boolean inTransaction) {
+ public Either<DataTypeDefinition, StorageOperationStatus> getDataTypeByName(final String name, final String validForModel, final boolean inTransaction) {
Either<DataTypeDefinition, StorageOperationStatus> result = null;
try {
- String dtUid = UniqueIdBuilder.buildDataTypeUid(name);
- Either<DataTypeDefinition, JanusGraphOperationStatus> ctResult = this.getDataTypeByUid(dtUid);
+ Either<DataTypeDefinition, JanusGraphOperationStatus> ctResult = this.getDataTypeByNameValidForModel(name, validForModel);
if (ctResult.isRight()) {
JanusGraphOperationStatus status = ctResult.right().value();
if (status != JanusGraphOperationStatus.NOT_FOUND) {
@@ -1359,24 +1422,18 @@ public class PropertyOperation extends AbstractOperation implements IPropertyOpe
}
@Override
- public Either<DataTypeDefinition, StorageOperationStatus> getDataTypeByName(String name) {
- return getDataTypeByName(name, true);
- }
-
- @Override
- public Either<DataTypeDefinition, StorageOperationStatus> getDataTypeByNameWithoutDerived(String name) {
- return getDataTypeByNameWithoutDerived(name, true);
+ public Either<DataTypeDefinition, StorageOperationStatus> getDataTypeByName(final String name, final String validForModel) {
+ return getDataTypeByName(name, validForModel, true);
}
-
- private Either<DataTypeDefinition, StorageOperationStatus> getDataTypeByNameWithoutDerived(String name, boolean inTransaction) {
+
+ public Either<DataTypeDefinition, StorageOperationStatus> getDataTypeByUidWithoutDerived(String uid, boolean inTransaction) {
Either<DataTypeDefinition, StorageOperationStatus> result = null;
try {
- String uid = UniqueIdBuilder.buildDataTypeUid(name);
Either<DataTypeDefinition, JanusGraphOperationStatus> ctResult = this.getDataTypeByUidWithoutDerivedDataTypes(uid);
if (ctResult.isRight()) {
JanusGraphOperationStatus status = ctResult.right().value();
if (status != JanusGraphOperationStatus.NOT_FOUND) {
- log.error("Failed to retrieve information on capability type {} status is {}", name, status);
+ log.error(BUSINESS_PROCESS_ERROR, "Failed to retrieve information on data type {} status is {}", uid, status);
}
result = Either.right(DaoStatusConverter.convertJanusGraphStatusToStorageStatus(ctResult.right().value()));
return result;
@@ -1425,23 +1482,22 @@ public class PropertyOperation extends AbstractOperation implements IPropertyOpe
return new DataTypeDefinition(dataTypeData.getDataTypeDataDefinition());
}
- private Either<Boolean, JanusGraphOperationStatus> isValidPropertyType(String propertyType) {
+ private Either<Boolean, JanusGraphOperationStatus> isValidPropertyType(String propertyType, final String modelName) {
if (propertyType == null || propertyType.isEmpty()) {
return Either.left(false);
}
ToscaPropertyType toscaPropertyType = ToscaPropertyType.isValidType(propertyType);
if (toscaPropertyType == null) {
- return isDefinedInDataTypes(propertyType);
+ return isDefinedInDataTypes(propertyType, modelName);
} else {
return Either.left(true);
}
}
- public Either<Boolean, JanusGraphOperationStatus> isDefinedInDataTypes(String propertyType) {
- String dataTypeUid = UniqueIdBuilder.buildDataTypeUid(propertyType);
- Either<DataTypeDefinition, JanusGraphOperationStatus> dataTypeByUid = getDataTypeByUid(dataTypeUid);
- if (dataTypeByUid.isRight()) {
- JanusGraphOperationStatus status = dataTypeByUid.right().value();
+ public Either<Boolean, JanusGraphOperationStatus> isDefinedInDataTypes(final String propertyType, final String modelName) {
+ Either<DataTypeDefinition, JanusGraphOperationStatus> dataType = getDataTypeByNameValidForModel(propertyType, modelName);
+ if (dataType.isRight()) {
+ JanusGraphOperationStatus status = dataType.right().value();
if (status == JanusGraphOperationStatus.NOT_FOUND) {
return Either.left(false);
}
@@ -1531,7 +1587,7 @@ public class PropertyOperation extends AbstractOperation implements IPropertyOpe
Either<ImmutablePair<DataTypeData, GraphEdge>, JanusGraphOperationStatus> parentNode = janusGraphGenericDao
.getChild(UniqueIdBuilder.getKeyByNodeType(NodeTypeEnum.DataType), uniqueId, GraphEdgeLabels.DERIVED_FROM, NodeTypeEnum.DataType,
DataTypeData.class);
- log.debug("After retrieving DERIVED_FROM node of {}. status is {}", uniqueId, parentNode);
+ log.debug(AFTER_RETRIEVING_DERIVED_FROM_NODE_OF_STATUS_IS, uniqueId, parentNode);
if (parentNode.isRight()) {
JanusGraphOperationStatus janusGraphOperationStatus = parentNode.right().value();
if (janusGraphOperationStatus != JanusGraphOperationStatus.NOT_FOUND) {
@@ -1752,7 +1808,7 @@ public class PropertyOperation extends AbstractOperation implements IPropertyOpe
}
}
Either<Map<String, PropertyData>, JanusGraphOperationStatus> addPropertiesToDataType = addPropertiesToDataType(
- oldDataTypeDefinition.getUniqueId(), propertiesToAdd);
+ oldDataTypeDefinition.getUniqueId(), oldDataTypeDefinition.getModel(), propertiesToAdd);
if (addPropertiesToDataType.isRight()) {
log.debug("Failed to update data type {} to Graph. Status is {}", oldDataTypeDefinition,
addPropertiesToDataType.right().value().name());
diff --git a/catalog-model/src/main/java/org/openecomp/sdc/be/model/operations/impl/UniqueIdBuilder.java b/catalog-model/src/main/java/org/openecomp/sdc/be/model/operations/impl/UniqueIdBuilder.java
index 77b28c7561..6e3d968556 100644
--- a/catalog-model/src/main/java/org/openecomp/sdc/be/model/operations/impl/UniqueIdBuilder.java
+++ b/catalog-model/src/main/java/org/openecomp/sdc/be/model/operations/impl/UniqueIdBuilder.java
@@ -176,8 +176,8 @@ public class UniqueIdBuilder {
return resourceUniqueId + DOT + "additionalinformation";
}
- static String buildDataTypeUid(String name) {
- return name + DOT + "datatype";
+ public static String buildDataTypeUid(final String modelName, final String name) {
+ return StringUtils.isEmpty(modelName) ? name + DOT + "datatype" : modelName + DOT + name + DOT + "datatype";
}
public static String buildInvariantUUID() {
diff --git a/catalog-model/src/test/java/org/openecomp/sdc/be/model/operations/impl/PropertyOperationTest.java b/catalog-model/src/test/java/org/openecomp/sdc/be/model/operations/impl/PropertyOperationTest.java
index 254208e06c..6812b44b41 100644
--- a/catalog-model/src/test/java/org/openecomp/sdc/be/model/operations/impl/PropertyOperationTest.java
+++ b/catalog-model/src/test/java/org/openecomp/sdc/be/model/operations/impl/PropertyOperationTest.java
@@ -26,11 +26,15 @@ import org.apache.commons.lang3.tuple.ImmutablePair;
import org.junit.Assert;
import org.junit.Before;
import org.junit.Test;
-import org.openecomp.sdc.be.dao.impl.HealingPipelineDao;
+import org.mockito.Mockito;
+import org.openecomp.sdc.be.dao.graph.datatype.GraphEdge;
+import org.openecomp.sdc.be.dao.graph.datatype.GraphRelation;
import org.openecomp.sdc.be.dao.janusgraph.HealingJanusGraphGenericDao;
import org.openecomp.sdc.be.dao.janusgraph.JanusGraphClient;
import org.openecomp.sdc.be.dao.janusgraph.JanusGraphGenericDao;
import org.openecomp.sdc.be.dao.janusgraph.JanusGraphOperationStatus;
+import org.openecomp.sdc.be.dao.neo4j.GraphEdgeLabels;
+import org.openecomp.sdc.be.dao.neo4j.GraphPropertiesDictionary;
import org.openecomp.sdc.be.datatypes.elements.PropertyDataDefinition;
import org.openecomp.sdc.be.datatypes.elements.PropertyRule;
import org.openecomp.sdc.be.datatypes.enums.NodeTypeEnum;
@@ -44,7 +48,6 @@ import org.openecomp.sdc.be.model.tosca.constraints.LessOrEqualConstraint;
import org.openecomp.sdc.be.resources.data.DataTypeData;
import org.openecomp.sdc.be.resources.data.PropertyData;
import org.openecomp.sdc.be.resources.data.PropertyValueData;
-
import java.util.*;
import static org.junit.Assert.*;
@@ -774,7 +777,7 @@ public class PropertyOperationTest extends ModelTestBase {
// test 1
testSubject = createTestSubject();
property = null;
- result = testSubject.isPropertyTypeValid(property);
+ result = testSubject.isPropertyTypeValid(property, null);
Assert.assertEquals(false, result);
}
@@ -852,52 +855,71 @@ public class PropertyOperationTest extends ModelTestBase {
@Test
- public void testAddDataType() throws Exception {
- PropertyOperation testSubject;
+ public void testAddAndGetDataType() throws Exception {
+ final String dataTypeName = "myDataType";
DataTypeDefinition dataTypeDefinition = new DataTypeDefinition();
+ dataTypeDefinition.setName("myDataType");
Either<DataTypeDefinition, StorageOperationStatus> result;
-
- // default test
- testSubject = createTestSubject();
- result = testSubject.addDataType(dataTypeDefinition);
+
+ Mockito.doReturn(Either.left(new DataTypeData(dataTypeDefinition))).when(janusGraphGenericDao)
+ .createNode(Mockito.any(), Mockito.eq(DataTypeData.class));
+
+ Mockito.doReturn(Either.left(new DataTypeData(dataTypeDefinition))).when(janusGraphGenericDao)
+ .getNode(GraphPropertiesDictionary.NAME.getProperty(), dataTypeName, DataTypeData.class, null);
+
+ Mockito.doReturn(Either.left(Collections.EMPTY_LIST)).when(janusGraphGenericDao)
+ .getChildrenNodes(Mockito.anyString(), Mockito.anyString(), Mockito.eq(GraphEdgeLabels.PROPERTY), Mockito.eq(NodeTypeEnum.Property), Mockito.eq(PropertyData.class));
+
+ result = propertyOperation.addDataType(dataTypeDefinition);
+ assertTrue(result.isLeft());
+
+ Mockito.doReturn(Either.right(JanusGraphOperationStatus.NOT_FOUND)).when(janusGraphGenericDao)
+ .getChild(Mockito.anyString(), Mockito.anyString(), Mockito.eq(GraphEdgeLabels.DERIVED_FROM), Mockito.eq(NodeTypeEnum.DataType), Mockito.eq(DataTypeData.class));
+
+ result = propertyOperation.getDataTypeByName(dataTypeName, null, false);
+ assertTrue(result.isLeft());
+
+ result = propertyOperation.getDataTypeByName(dataTypeName, null);
+ assertTrue(result.isLeft());
+
+ Mockito.doReturn(Either.left(new DataTypeData(dataTypeDefinition))).when(janusGraphGenericDao)
+ .getNode(GraphPropertiesDictionary.UNIQUE_ID.getProperty(), dataTypeName + ".datatype", DataTypeData.class);
+
+ Either<DataTypeDefinition, JanusGraphOperationStatus> resultGetByUid = propertyOperation.getDataTypeByUid("myDataType.datatype");
+ assertTrue(resultGetByUid.isLeft());
+
+ Either<Boolean, JanusGraphOperationStatus> resultIsDefinedDataType = propertyOperation.isDefinedInDataTypes(dataTypeName, null);
+ assertTrue(resultIsDefinedDataType.isLeft());
}
-
- @Test
- public void testGetDataTypeByName() throws Exception {
- PropertyOperation testSubject;
- String name = "";
- boolean inTransaction = false;
- Either<DataTypeDefinition, StorageOperationStatus> result;
-
- // default test
- testSubject = createTestSubject();
- result = testSubject.getDataTypeByName(name, inTransaction);
- }
-
-
- @Test
- public void testGetDataTypeByName_1() throws Exception {
- PropertyOperation testSubject;
- String name = "";
- Either<DataTypeDefinition, StorageOperationStatus> result;
-
- // default test
- testSubject = createTestSubject();
- result = testSubject.getDataTypeByName(name);
- }
-
-
- @Test
- public void testGetDataTypeByNameWithoutDerived() throws Exception {
- PropertyOperation testSubject;
- String name = "";
- Either<DataTypeDefinition, StorageOperationStatus> result;
-
- // default test
- testSubject = createTestSubject();
- result = testSubject.getDataTypeByNameWithoutDerived(name);
- }
+ @Test
+ public void testAddDataTypeToModel() throws Exception {
+ DataTypeDefinition dataTypeDefinition = new DataTypeDefinition();
+ dataTypeDefinition.setName("testName");
+ dataTypeDefinition.setModel("testModel");
+ Either<DataTypeDefinition, StorageOperationStatus> result;
+
+ Mockito.doReturn(Either.left(new DataTypeData(dataTypeDefinition))).when(janusGraphGenericDao)
+ .createNode(Mockito.any(), Mockito.eq(DataTypeData.class));
+
+ Mockito.doReturn(Either.left(new GraphRelation())).when(janusGraphGenericDao)
+ .createRelation(Mockito.any(), Mockito.any(), Mockito.eq(GraphEdgeLabels.MODEL_ELEMENT), Mockito.any());
+
+ result = propertyOperation.addDataType(dataTypeDefinition);
+ assertTrue(result.isLeft());
+
+ Mockito.doReturn(Either.left(new DataTypeData(dataTypeDefinition))).when(janusGraphGenericDao)
+ .getNode(GraphPropertiesDictionary.UNIQUE_ID.getProperty(), "testModel.testName.datatype", DataTypeData.class);
+
+ Mockito.doReturn(Either.left(Collections.EMPTY_LIST)).when(janusGraphGenericDao)
+ .getChildrenNodes(Mockito.anyString(), Mockito.anyString(), Mockito.eq(GraphEdgeLabels.PROPERTY), Mockito.eq(NodeTypeEnum.Property), Mockito.eq(PropertyData.class));
+
+ Mockito.doReturn(Either.right(JanusGraphOperationStatus.NOT_FOUND)).when(janusGraphGenericDao)
+ .getChild(Mockito.anyString(), Mockito.anyString(), Mockito.eq(GraphEdgeLabels.DERIVED_FROM), Mockito.eq(NodeTypeEnum.DataType), Mockito.eq(DataTypeData.class));
+
+ Either<DataTypeDefinition, JanusGraphOperationStatus> resultGetByUid = propertyOperation.getDataTypeByUid("testModel.testName.datatype");
+ assertTrue(resultGetByUid.isLeft());
+ }
@Test
@@ -913,18 +935,6 @@ public class PropertyOperationTest extends ModelTestBase {
@Test
- public void testIsDefinedInDataTypes() throws Exception {
- PropertyOperation testSubject;
- String propertyType = "";
- Either<Boolean, JanusGraphOperationStatus> result;
-
- // default test
- testSubject = createTestSubject();
- result = testSubject.isDefinedInDataTypes(propertyType);
- }
-
-
- @Test
public void testGetAllDataTypes() throws Exception {
PropertyOperation testSubject;
Either<Map<String, DataTypeDefinition>, JanusGraphOperationStatus> result;