From 47bcc63a9daff1f310125fed006f27c93656fa83 Mon Sep 17 00:00:00 2001 From: aribeiro Date: Thu, 15 Jul 2021 09:18:37 +0100 Subject: Retrieve data types based on component model Issue-ID: SDC-3660 Signed-off-by: aribeiro Change-Id: I09c533eb39277532b29e581e4dd57e9df952e8e6 --- .../files/default/error-configuration.yaml | 9 ++++ .../components/impl/AnnotationBusinessLogic.java | 11 ++--- .../be/components/impl/AttributeBusinessLogic.java | 13 +++--- .../sdc/be/components/impl/BaseBusinessLogic.java | 41 ++++------------- .../impl/ComponentInstanceBusinessLogic.java | 34 ++------------ .../sdc/be/components/impl/DataTypesService.java | 2 +- .../sdc/be/components/impl/GroupBusinessLogic.java | 25 +++-------- .../be/components/impl/InputsBusinessLogic.java | 15 +++---- .../be/components/impl/PropertyBusinessLogic.java | 6 +-- .../be/components/impl/ResourceBusinessLogic.java | 37 +++++---------- .../be/components/impl/ResourceImportManager.java | 8 ++-- .../be/components/impl/ServiceBusinessLogic.java | 14 +++--- .../impl/ServiceImportBusinessLogic.java | 52 ++++++++-------------- .../PropertyDataValueMergeBusinessLogic.java | 9 ++-- .../components/validation/AnnotationValidator.java | 23 +++++----- .../PropertyValueConstraintValidationUtil.java | 7 +-- .../org/openecomp/sdc/be/impl/ComponentsUtils.java | 19 ++++++++ .../sdc/be/servlets/ComponentPropertyServlet.java | 5 ++- .../sdc/be/servlets/TypesFetchServlet.java | 6 ++- .../sdc/be/tosca/GroupExportParserImpl.java | 10 ++--- .../sdc/be/tosca/PolicyExportParserImpl.java | 10 ++--- .../openecomp/sdc/be/tosca/ToscaExportHandler.java | 12 ++--- 22 files changed, 153 insertions(+), 215 deletions(-) (limited to 'catalog-be/src/main') diff --git a/catalog-be/src/main/docker/backend/chef-repo/cookbooks/sdc-catalog-be/files/default/error-configuration.yaml b/catalog-be/src/main/docker/backend/chef-repo/cookbooks/sdc-catalog-be/files/default/error-configuration.yaml index df13e80fe8..cbbd5eeef6 100644 --- a/catalog-be/src/main/docker/backend/chef-repo/cookbooks/sdc-catalog-be/files/default/error-configuration.yaml +++ b/catalog-be/src/main/docker/backend/chef-repo/cookbooks/sdc-catalog-be/files/default/error-configuration.yaml @@ -2536,3 +2536,12 @@ errors: message: "Error: Component '%1' with Vendor Release '%2' already exists.", messageId: "SVC4152" } + + #-----------SVC4153--------------------------- + # %1 - "Model name" + DATA_TYPES_NOT_LOADED: { + code: 500, + message: "Error: Could not fetch data types from data base with model %1", + messageId: "SVC4153" + } + diff --git a/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/AnnotationBusinessLogic.java b/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/AnnotationBusinessLogic.java index f8d487169a..953f5e3804 100644 --- a/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/AnnotationBusinessLogic.java +++ b/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/AnnotationBusinessLogic.java @@ -54,7 +54,7 @@ public class AnnotationBusinessLogic { if (isNotEmpty(inputAnnotationList)) { for (Annotation annotation : inputAnnotationList) { AnnotationTypeDefinition dbAnnotationTypeDefinition = annotationTypeOperations.getLatestType(annotation.getType()); - validateMergeAndSetAnnoProps(annotation, dbAnnotationTypeDefinition); + validateMergeAndSetAnnoProps(annotation, dbAnnotationTypeDefinition, input.getModel()); } } input.setAnnotations(inputAnnotationList); @@ -66,15 +66,16 @@ public class AnnotationBusinessLogic { return annotationTypeOperations; } - private void validateMergeAndSetAnnoProps(Annotation annotation, AnnotationTypeDefinition dbAnnotationTypeDefinition) { - annotationValidator.validateAnnotationsProperties(annotation, dbAnnotationTypeDefinition); + private void validateMergeAndSetAnnoProps(final Annotation annotation, final AnnotationTypeDefinition dbAnnotationTypeDefinition, + final String model) { + annotationValidator.validateAnnotationsProperties(annotation, dbAnnotationTypeDefinition, model); List mergedPropertiesList = mergePropsOfAnnoDataTypeWithParsedAnnoProps(annotation.getProperties(), dbAnnotationTypeDefinition.getProperties()); annotation.setProperties(mergedPropertiesList); } - private List mergePropsOfAnnoDataTypeWithParsedAnnoProps(List annoProperties, - List typePropertiesList) { + private List mergePropsOfAnnoDataTypeWithParsedAnnoProps(final List annoProperties, + final List typePropertiesList) { Set mergedPropertiesSet = new HashSet<>(typePropertiesList); Map typePropsMap = MapUtil.toMap(typePropertiesList, PropertyDefinition::getName); for (PropertyDataDefinition propertyDataDefinitionObject : annoProperties) { 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 687a5d56ef..2380d48deb 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 @@ -104,13 +104,14 @@ public class AttributeBusinessLogic extends BaseBusinessLogic { if (isAttributeExist(resource.getAttributes(), resourceId, newAttributeDef.getName())) { return Either.right(componentsUtils.getResponseFormat(ActionStatus.ATTRIBUTE_ALREADY_EXIST, newAttributeDef.getName())); } - Map eitherAllDataTypes = getAllDataTypes(applicationDataTypeCache); + // fetch DataTypes by Model Name + Map allDataTypes = componentsUtils.getAllDataTypes(applicationDataTypeCache, resource.getModel()); // validate property default values - Either defaultValuesValidation = validateAttributeDefaultValue(newAttributeDef, eitherAllDataTypes); + Either defaultValuesValidation = validateAttributeDefaultValue(newAttributeDef, allDataTypes); if (defaultValuesValidation.isRight()) { return Either.right(defaultValuesValidation.right().value()); } - handleAttributeDefaultValue(newAttributeDef, eitherAllDataTypes); + handleAttributeDefaultValue(newAttributeDef, allDataTypes); // add the new attribute to resource on graph // need to get StorageOperationStatus and convert to ActionStatus from @@ -252,14 +253,14 @@ public class AttributeBusinessLogic extends BaseBusinessLogic { if (eitherAttribute.isRight()) { return Either.right(eitherAttribute.right().value()); } - Map eitherAllDataTypes = getAllDataTypes(applicationDataTypeCache); + Map allDataTypes = componentsUtils.getAllDataTypes(applicationDataTypeCache, resource.getModel()); // validate attribute default values - Either defaultValuesValidation = validateAttributeDefaultValue(newAttDef, eitherAllDataTypes); + Either defaultValuesValidation = validateAttributeDefaultValue(newAttDef, allDataTypes); if (defaultValuesValidation.isRight()) { return Either.right(defaultValuesValidation.right().value()); } // add the new property to resource on graph - StorageOperationStatus validateAndUpdateAttribute = attributeOperation.validateAndUpdateAttribute(newAttDef, eitherAllDataTypes); + StorageOperationStatus validateAndUpdateAttribute = attributeOperation.validateAndUpdateAttribute(newAttDef, allDataTypes); if (validateAndUpdateAttribute != StorageOperationStatus.OK) { log.debug("Problem while updating attribute with id {}. Reason - {}", attributeId, validateAndUpdateAttribute); result = Either.right(componentsUtils 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 792e6963c0..3cb76806c8 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 @@ -118,7 +118,6 @@ public abstract class BaseBusinessLogic { protected AttributeOperation attributeOperation; protected ApplicationDataTypeCache applicationDataTypeCache; protected ToscaOperationFacade toscaOperationFacade; - protected ApplicationDataTypeCache dataTypeCache; protected IGroupOperation groupOperation; protected IGroupInstanceOperation groupInstanceOperation; protected InterfaceLifecycleOperation interfaceLifecycleTypeOperation; @@ -190,11 +189,6 @@ public abstract class BaseBusinessLogic { this.policyTypeOperation = policyTypeOperation; } - @Autowired - public void setDataTypeCache(ApplicationDataTypeCache dataTypeCache) { - this.dataTypeCache = dataTypeCache; - } - @Autowired public void setPropertyOperation(PropertyOperation propertyOperation) { this.propertyOperation = propertyOperation; @@ -341,21 +335,12 @@ public abstract class BaseBusinessLogic { } String updateInputPropertyObjectValue(T property) { - Either, JanusGraphOperationStatus> allDataTypesEither = dataTypeCache.getAll(); - if (allDataTypesEither.isRight()) { - JanusGraphOperationStatus status = allDataTypesEither.right().value(); - BeEcompErrorManager.getInstance() - .logInternalFlowError("UpdatePropertyValueOnComponentInstance", "Failed to update property value on instance. Status is " + status, - ErrorSeverity.ERROR); - throw new ByActionStatusComponentException( - componentsUtils.convertFromStorageResponse(DaoStatusConverter.convertJanusGraphStatusToStorageStatus(status))); - } - Map allDataTypes = allDataTypesEither.left().value(); String propertyType = property.getType(); String innerType = getInnerType(property); // Specific Update Logic Either isValid = propertyOperation - .validateAndUpdatePropertyValue(propertyType, property.getValue(), true, innerType, allDataTypes); + .validateAndUpdatePropertyValue(propertyType, property.getValue(), true, innerType, + componentsUtils.getAllDataTypes(applicationDataTypeCache, property.getModel())); String newValue = property.getValue(); if (isValid.isRight()) { Boolean res = isValid.right().value(); @@ -433,21 +418,6 @@ public abstract class BaseBusinessLogic { return null; } - protected Map getAllDataTypes(ApplicationDataTypeCache applicationDataTypeCache) { - Either, JanusGraphOperationStatus> allDataTypes = applicationDataTypeCache.getAll(); - if (allDataTypes.isRight()) { - JanusGraphOperationStatus operationStatus = allDataTypes.right().value(); - if (operationStatus == JanusGraphOperationStatus.NOT_FOUND) { - BeEcompErrorManager.getInstance().logInternalDataError("FetchDataTypes", "Data types are not loaded", ErrorSeverity.ERROR); - throw new ByActionStatusComponentException(ActionStatus.DATA_TYPE_CANNOT_BE_EMPTY); - } else { - BeEcompErrorManager.getInstance().logInternalFlowError("FetchDataTypes", "Failed to fetch data types", ErrorSeverity.ERROR); - throw new ByActionStatusComponentException(ActionStatus.GENERAL_ERROR); - } - } - return allDataTypes.left().value(); - } - Either validatePropertyDefaultValue(IComplexDefaultValue property, Map dataTypes) { String type; String innerType = null; @@ -706,7 +676,8 @@ public abstract class BaseBusinessLogic { if (inputPathArr.length > 1) { inputPathArr = ArrayUtils.remove(inputPathArr, 0); } - Map dataTypeDefinitionMap = applicationDataTypeCache.getAll().left().value(); + final Map dataTypeDefinitionMap = + componentsUtils.getAllDataTypes(applicationDataTypeCache, inputDefinition.getModel()); String propertyType = inputDefinition.getParentPropertyType(); for (String anInputPathArr : inputPathArr) { if (ToscaType.isPrimitiveType(propertyType)) { @@ -774,4 +745,8 @@ public abstract class BaseBusinessLogic { } return result.left().value(); } + + public String getComponentModelByComponentId(final String componentId) throws BusinessLogicException { + return getComponent(componentId).getModel(); + } } diff --git a/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/ComponentInstanceBusinessLogic.java b/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/ComponentInstanceBusinessLogic.java index bce343efaf..e2c3df172d 100644 --- a/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/ComponentInstanceBusinessLogic.java +++ b/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/ComponentInstanceBusinessLogic.java @@ -2227,16 +2227,7 @@ public class ComponentInstanceBusinessLogic extends BaseBusinessLogic { } private Either validatePropertyObjectValue(T property, String newValue, boolean isInput) { - Either, JanusGraphOperationStatus> allDataTypesEither = dataTypeCache.getAll(); - if (allDataTypesEither.isRight()) { - JanusGraphOperationStatus status = allDataTypesEither.right().value(); - BeEcompErrorManager.getInstance() - .logInternalFlowError(UPDATE_PROPERTY_CONTEXT, "Failed to update property value on instance. Status is " + status, - ErrorSeverity.ERROR); - return Either.right(componentsUtils - .getResponseFormat(componentsUtils.convertFromStorageResponse(DaoStatusConverter.convertJanusGraphStatusToStorageStatus(status)))); - } - Map allDataTypes = allDataTypesEither.left().value(); + final Map allDataTypes = componentsUtils.getAllDataTypes(applicationDataTypeCache, property.getModel()); String propertyType = property.getType(); String innerType = getInnerType(property); @@ -2275,16 +2266,7 @@ public class ComponentInstanceBusinessLogic extends BaseBusinessLogic { } private Either updatePropertyObjectValue(T property, boolean isInput) { - Either, JanusGraphOperationStatus> allDataTypesEither = dataTypeCache.getAll(); - if (allDataTypesEither.isRight()) { - JanusGraphOperationStatus status = allDataTypesEither.right().value(); - BeEcompErrorManager.getInstance() - .logInternalFlowError(UPDATE_PROPERTY_CONTEXT, "Failed to update property value on instance. Status is " + status, - ErrorSeverity.ERROR); - return Either.right(componentsUtils - .getResponseFormat(componentsUtils.convertFromStorageResponse(DaoStatusConverter.convertJanusGraphStatusToStorageStatus(status)))); - } - Map allDataTypes = allDataTypesEither.left().value(); + final Map allDataTypes = componentsUtils.getAllDataTypes(applicationDataTypeCache, property.getModel()); String innerType = null; String propertyType = property.getType(); ToscaPropertyType type = ToscaPropertyType.isValidType(propertyType); @@ -2341,15 +2323,6 @@ public class ComponentInstanceBusinessLogic extends BaseBusinessLogic { } private Either updateAttributeObjectValue(final T attribute) { - final Either, JanusGraphOperationStatus> allDataTypesEither = dataTypeCache.getAll(); - if (allDataTypesEither.isRight()) { - JanusGraphOperationStatus status = allDataTypesEither.right().value(); - BeEcompErrorManager.getInstance() - .logInternalFlowError(UPDATE_PROPERTY_CONTEXT, "Failed to update attribute value on instance. Status is " + status, - ErrorSeverity.ERROR); - return Either.right(componentsUtils - .getResponseFormat(componentsUtils.convertFromStorageResponse(DaoStatusConverter.convertJanusGraphStatusToStorageStatus(status)))); - } String innerType = null; final String attributeType = attribute.getType(); final ToscaPropertyType type = ToscaPropertyType.isValidType(attributeType); @@ -2374,7 +2347,8 @@ public class ComponentInstanceBusinessLogic extends BaseBusinessLogic { // Specific Update Logic String newValue = attribute.getValue(); - final var isValid = attributeOperation.validateAndUpdateAttributeValue(attribute, innerType, allDataTypesEither.left().value()); + final var isValid = attributeOperation.validateAndUpdateAttributeValue(attribute, innerType, + componentsUtils.getAllDataTypes(applicationDataTypeCache, attribute.getModel())); if (isValid.isRight()) { final Boolean res = isValid.right().value(); if (!Boolean.TRUE.equals(res)) { diff --git a/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/DataTypesService.java b/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/DataTypesService.java index be61e7b112..db53800d7b 100644 --- a/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/DataTypesService.java +++ b/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/DataTypesService.java @@ -40,7 +40,7 @@ public class DataTypesService { } public Either, ResponseFormat> getAllDataTypes(ApplicationDataTypeCache applicationDataTypeCache) { - Either, JanusGraphOperationStatus> allDataTypes = applicationDataTypeCache.getAll(); + Either, JanusGraphOperationStatus> allDataTypes = applicationDataTypeCache.getAll(null); if (allDataTypes.isRight()) { JanusGraphOperationStatus operationStatus = allDataTypes.right().value(); if (operationStatus == JanusGraphOperationStatus.NOT_FOUND) { diff --git a/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/GroupBusinessLogic.java b/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/GroupBusinessLogic.java index 0d85675c45..ae9ab04a87 100644 --- a/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/GroupBusinessLogic.java +++ b/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/GroupBusinessLogic.java @@ -1068,19 +1068,13 @@ public class GroupBusinessLogic extends BaseBusinessLogic { boolean fromCsar) { Map groups = new HashMap<>(); Either, ResponseFormat> result = null; - Either, StorageOperationStatus> createGroupsResult = null; - Either, JanusGraphOperationStatus> allDataTypes = dataTypeCache.getAll(); - if (allDataTypes.isRight()) { - JanusGraphOperationStatus status = allDataTypes.right().value(); - BeEcompErrorManager.getInstance() - .logInternalFlowError("AddPropertyToGroup", "Failed to add property to group. Status is " + status, ErrorSeverity.ERROR); - return Either.right(componentsUtils - .getResponseFormat(componentsUtils.convertFromStorageResponse(DaoStatusConverter.convertJanusGraphStatusToStorageStatus(status)))); - } + Either, StorageOperationStatus> createGroupsResult; + // handle groups and convert to tosca data if (groupDefinitions != null && !groupDefinitions.isEmpty()) { for (GroupDefinition groupDefinition : groupDefinitions) { - Either handleGroupRes = handleGroup(component, groupDefinition, allDataTypes.left().value()); + Either handleGroupRes = handleGroup(component, groupDefinition, + componentsUtils.getAllDataTypes(applicationDataTypeCache, component.getModel())); if (handleGroupRes.isRight()) { result = Either.right(handleGroupRes.right().value()); break; @@ -1150,18 +1144,11 @@ public class GroupBusinessLogic extends BaseBusinessLogic { Either, ResponseFormat> result = null; Either, StorageOperationStatus> createGroupsResult = null; List groups = new ArrayList<>(); - Either, JanusGraphOperationStatus> allDataTypes = dataTypeCache.getAll(); - if (allDataTypes.isRight()) { - JanusGraphOperationStatus status = allDataTypes.right().value(); - BeEcompErrorManager.getInstance() - .logInternalFlowError("AddPropertyToGroup", "Failed to add property to group. Status is " + status, ErrorSeverity.ERROR); - return Either.right(componentsUtils - .getResponseFormat(componentsUtils.convertFromStorageResponse(DaoStatusConverter.convertJanusGraphStatusToStorageStatus(status)))); - } // handle groups and convert to tosca data if (groupDefinitions != null && !groupDefinitions.isEmpty()) { for (GroupDefinition groupDefinition : groupDefinitions) { - Either handleGroupRes = handleGroup(component, groupDefinition, allDataTypes.left().value()); + Either handleGroupRes = handleGroup(component, groupDefinition, + componentsUtils.getAllDataTypes(applicationDataTypeCache, component.getModel())); if (handleGroupRes.isRight()) { result = Either.right(handleGroupRes.right().value()); break; diff --git a/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/InputsBusinessLogic.java b/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/InputsBusinessLogic.java index 0d9681a8dc..28faf73c21 100644 --- a/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/InputsBusinessLogic.java +++ b/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/InputsBusinessLogic.java @@ -289,14 +289,14 @@ public class InputsBusinessLogic extends BaseBusinessLogic { } } //Validate value and Constraint of input - Either constraintValidatorResponse = validateInputValueConstraint(inputs); + Either constraintValidatorResponse = validateInputValueConstraint(inputs, component.getModel()); if (constraintValidatorResponse.isRight()) { log.error("Failed validation value and constraint of property: {}", constraintValidatorResponse.right().value()); return Either.right(constraintValidatorResponse.right().value()); } validateCanWorkOnComponent(component, userId); Map dataTypes; - dataTypes = getAllDataTypes(applicationDataTypeCache); + dataTypes = componentsUtils.getAllDataTypes(applicationDataTypeCache, component.getModel()); List componentsOldInputs = Optional.ofNullable(component.getInputs()).orElse(Collections.emptyList()); for (InputDefinition newInput : inputs) { InputDefinition currInput = getInputFromInputsListById(componentsOldInputs, newInput); @@ -335,7 +335,7 @@ public class InputsBusinessLogic extends BaseBusinessLogic { return result; } - private Either validateInputValueConstraint(List inputs) { + private Either validateInputValueConstraint(List inputs, final String model) { PropertyValueConstraintValidationUtil propertyValueConstraintValidationUtil = PropertyValueConstraintValidationUtil.getInstance(); List inputDefinitions = new ArrayList<>(); for (InputDefinition inputDefinition : inputs) { @@ -350,7 +350,7 @@ public class InputsBusinessLogic extends BaseBusinessLogic { } inputDefinitions.add(inputDef); } - return propertyValueConstraintValidationUtil.validatePropertyConstraints(inputDefinitions, applicationDataTypeCache); + return propertyValueConstraintValidationUtil.validatePropertyConstraints(inputDefinitions, applicationDataTypeCache, model); } public Either, ResponseFormat> getInputsForComponentInput(String userId, String componentId, String inputId) { @@ -571,7 +571,7 @@ public class InputsBusinessLogic extends BaseBusinessLogic { List resourceProperties = component.getInputs(); - Map dataTypes = getAllDataTypes(applicationDataTypeCache); + final Map dataTypes = componentsUtils.getAllDataTypes(applicationDataTypeCache, component.getModel()); for (Map.Entry inputDefinition : inputs.entrySet()) { String inputName = inputDefinition.getKey(); @@ -609,8 +609,7 @@ public class InputsBusinessLogic extends BaseBusinessLogic { log.trace("#createListInputsInGraph: enter"); - Map dataTypes = getAllDataTypes( - applicationDataTypeCache); + Map dataTypes = componentsUtils.getAllDataTypes(applicationDataTypeCache, component.getModel()); dataTypes.putAll(privateDataTypes); for (Map.Entry inputDefinition : inputs.entrySet()) { @@ -829,7 +828,7 @@ public class InputsBusinessLogic extends BaseBusinessLogic { result = Either.right(componentsUtils.getResponseFormat(ActionStatus.INPUT_ALREADY_EXIST, inputName)); return result; } - Map allDataTypes = getAllDataTypes(applicationDataTypeCache); + Map allDataTypes = componentsUtils.getAllDataTypes(applicationDataTypeCache, component.getModel()); // validate input default values Either defaultValuesValidation = validatePropertyDefaultValue(newInputDefinition, allDataTypes); if (defaultValuesValidation.isRight()) { diff --git a/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/PropertyBusinessLogic.java b/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/PropertyBusinessLogic.java index d7564ed50e..bbdae470e1 100644 --- a/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/PropertyBusinessLogic.java +++ b/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/PropertyBusinessLogic.java @@ -78,10 +78,6 @@ public class PropertyBusinessLogic extends BaseBusinessLogic { artifactToscaOperation); } - public Map getAllDataTypes() { - return getAllDataTypes(applicationDataTypeCache); - } - /** * Create new property on component in graph * @@ -123,7 +119,7 @@ public class PropertyBusinessLogic extends BaseBusinessLogic { result = Either.right(componentsUtils.getResponseFormat(ActionStatus.PROPERTY_ALREADY_EXIST, propertyName)); return result; } else { - Map allDataTypes = getAllDataTypes(applicationDataTypeCache); + Map allDataTypes = componentsUtils.getAllDataTypes(applicationDataTypeCache, component.getModel()); // validate property default values Either defaultValuesValidation = validatePropertyDefaultValue(newPropertyDefinition, allDataTypes); if (defaultValuesValidation.isRight()) { 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 2435b5e937..c401948495 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 @@ -83,7 +83,6 @@ import org.openecomp.sdc.be.config.BeEcompErrorManager; import org.openecomp.sdc.be.config.BeEcompErrorManager.ErrorSeverity; 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.JanusGraphDao; import org.openecomp.sdc.be.datamodel.api.HighestFilterEnum; import org.openecomp.sdc.be.datamodel.utils.ArtifactUtils; @@ -152,7 +151,6 @@ 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; @@ -2301,21 +2299,10 @@ public class ResourceBusinessLogic extends ComponentBusinessLogic { Map> instAttributes = new HashMap<>(); List relations = new ArrayList<>(); Map> instInputs = new HashMap<>(); - log.debug("#createResourceInstancesRelations - Before get all datatypes. "); - Either, JanusGraphOperationStatus> allDataTypes = dataTypeCache.getAll(); - if (allDataTypes.isRight()) { - JanusGraphOperationStatus status = allDataTypes.right().value(); - BeEcompErrorManager.getInstance() - .logInternalFlowError("UpdatePropertyValueOnComponentInstance", "Failed to update property value on instance. Status is " + status, - ErrorSeverity.ERROR); - loggerSupportability.log(LoggerSupportabilityActions.CREATE_RELATIONS, resource.getComponentMetadataForSupportLog(), StatusCode.ERROR, - "ERROR while update property value on instance. Status is: " + status); - throw new ByActionStatusComponentException( - componentsUtils.convertFromStorageResponse(DaoStatusConverter.convertJanusGraphStatusToStorageStatus(status)), yamlName); - } Resource finalResource = resource; uploadResInstancesMap.values().forEach( - i -> processComponentInstance(yamlName, finalResource, componentInstancesList, allDataTypes, instProperties, instCapabilities, + i -> processComponentInstance(yamlName, finalResource, componentInstancesList, + componentsUtils.getAllDataTypes(applicationDataTypeCache, resource.getModel()), instProperties, instCapabilities, instRequirements, instDeploymentArtifacts, instArtifacts, instAttributes, existingNodeTypesByResourceNames, instInputs, i)); resource.getComponentInstances().stream().filter(i -> !i.isCreatedFromCsar()).forEach( i -> processUiComponentInstance(oldResource, i, instCapabilities, instRequirements, instDeploymentArtifacts, instArtifacts, @@ -2536,7 +2523,7 @@ public class ResourceBusinessLogic extends ComponentBusinessLogic { } private void processComponentInstance(String yamlName, Resource resource, List componentInstancesList, - Either, JanusGraphOperationStatus> allDataTypes, + Map allDataTypes, Map> instProperties, Map>> instCapabilties, Map>> instRequirements, @@ -2574,12 +2561,12 @@ public class ResourceBusinessLogic extends ComponentBusinessLogic { } if (originResource.getResourceType() != ResourceTypeEnum.CVFC) { ResponseFormat addPropertiesValueToRiRes = addPropertyValuesToRi(uploadComponentInstanceInfo, resource, originResource, - currentCompInstance, instProperties, allDataTypes.left().value()); + currentCompInstance, instProperties, allDataTypes); if (addPropertiesValueToRiRes.getStatus() != 200) { throw new ByResponseFormatComponentException(addPropertiesValueToRiRes); } } else { - addInputsValuesToRi(uploadComponentInstanceInfo, resource, originResource, currentCompInstance, instInputs, allDataTypes.left().value()); + addInputsValuesToRi(uploadComponentInstanceInfo, resource, originResource, currentCompInstance, instInputs, allDataTypes); } } @@ -2602,7 +2589,7 @@ public class ResourceBusinessLogic extends ComponentBusinessLogic { return originResource; } - private void processComponentInstanceCapabilities(Either, JanusGraphOperationStatus> allDataTypes, + private void processComponentInstanceCapabilities(Map allDataTypes, Map>> instCapabilties, UploadComponentInstanceInfo uploadComponentInstanceInfo, ComponentInstance currentCompInstance, Resource originResource) { @@ -2612,18 +2599,18 @@ public class ResourceBusinessLogic extends ComponentBusinessLogic { Map> newPropertiesMap = new HashMap<>(); originResource.getCapabilities().forEach((k, v) -> addCapabilities(originCapabilities, k, v)); uploadComponentInstanceInfo.getCapabilities().values().forEach(l -> addCapabilitiesProperties(newPropertiesMap, l)); - updateCapabilityPropertiesValues(allDataTypes, originCapabilities, newPropertiesMap); + updateCapabilityPropertiesValues(originCapabilities, newPropertiesMap, allDataTypes); } else { originCapabilities = originResource.getCapabilities(); } instCapabilties.put(currentCompInstance, originCapabilities); } - private void updateCapabilityPropertiesValues(Either, JanusGraphOperationStatus> allDataTypes, - Map> originCapabilities, - Map> newPropertiesMap) { + private void updateCapabilityPropertiesValues(Map> originCapabilities, + Map> newPropertiesMap, + Map allDataTypes) { originCapabilities.values().stream().flatMap(Collection::stream).filter(c -> newPropertiesMap.containsKey(c.getName())) - .forEach(c -> updatePropertyValues(c.getProperties(), newPropertiesMap.get(c.getName()), allDataTypes.left().value())); + .forEach(c -> updatePropertyValues(c.getProperties(), newPropertiesMap.get(c.getName()), allDataTypes)); } private void addCapabilitiesProperties(Map> newPropertiesMap, List capabilities) { @@ -4931,7 +4918,7 @@ public class ResourceBusinessLogic extends ComponentBusinessLogic { log.info("Invalid type for property {}", property); throw new ByActionStatusComponentException(ActionStatus.INVALID_PROPERTY_TYPE, property.getType(), property.getName()); } - Map allDataTypes = getAllDataTypes(applicationDataTypeCache); + Map allDataTypes = componentsUtils.getAllDataTypes(applicationDataTypeCache, property.getModel()); type = property.getType(); if (type.equals(ToscaPropertyType.LIST.getType()) || type.equals(ToscaPropertyType.MAP.getType())) { ResponseFormat responseFormat = validateMapOrListPropertyType(property, innerType, allDataTypes); 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 6efdab4a96..9f1669c135 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 @@ -320,7 +320,7 @@ public class ResourceImportManager { if (toscaElements.isLeft()) { final Map toscaAttributes = (Map) foundElements.get(0); if (MapUtils.isNotEmpty(toscaAttributes)) { - resource.setDataTypes(extractDataTypeFromJson(resourceBusinessLogic, toscaAttributes)); + resource.setDataTypes(extractDataTypeFromJson(resourceBusinessLogic, toscaAttributes, resource.getModel())); } } // Derived From @@ -914,10 +914,12 @@ public class ResourceImportManager { } private List extractDataTypeFromJson(final ResourceBusinessLogic resourceBusinessLogic, - final Map foundElements) { + final Map foundElements, + final String model) { final List dataTypeDefinitionList = new ArrayList<>(); if (MapUtils.isNotEmpty(foundElements)) { - final Either, JanusGraphOperationStatus> dataTypeCacheAll = resourceBusinessLogic.dataTypeCache.getAll(); + final Either, JanusGraphOperationStatus> dataTypeCacheAll = + resourceBusinessLogic.applicationDataTypeCache.getAll(model); if (dataTypeCacheAll.isLeft()) { for (final Entry attributeNameValue : foundElements.entrySet()) { final Object value = attributeNameValue.getValue(); diff --git a/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/ServiceBusinessLogic.java b/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/ServiceBusinessLogic.java index 21d27f3fa0..50cf5d8c65 100644 --- a/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/ServiceBusinessLogic.java +++ b/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/ServiceBusinessLogic.java @@ -382,11 +382,11 @@ public class ServiceBusinessLogic extends ComponentBusinessLogic { if (STATIC.equals(sourceValue)) { // Validate constraint on input value Either constraintValidationResult = validateOperationInputConstraint(operationInputDefinition, consumptionValue, - type); + type, containerService.getModel()); if (constraintValidationResult.isRight()) { return Either.right(constraintValidationResult.right().value()); } - return handleConsumptionStaticValue(consumptionValue, type, operation, operationInputDefinition); + return handleConsumptionStaticValue(consumptionValue, type, operation, operationInputDefinition, containerService.getModel()); } if (Objects.isNull(sourceValue)) { List propertyDefinitions; @@ -523,13 +523,13 @@ public class ServiceBusinessLogic extends ComponentBusinessLogic { } public Either handleConsumptionStaticValue(String value, String type, Operation operation, - OperationInputDefinition operationInputDefinition) { + OperationInputDefinition operationInputDefinition, String model) { boolean isInputTypeSimilarToOperation = isAssignedValueFromValidType(type, value); if (!isInputTypeSimilarToOperation) { return Either.right(componentsUtils.getResponseFormat(ActionStatus.INVALID_CONSUMPTION_TYPE, type)); } //Validate Constraint and Value - Either constraintValidationResponse = validateOperationInputConstraint(operationInputDefinition, value, type); + Either constraintValidationResponse = validateOperationInputConstraint(operationInputDefinition, value, type, model); if (constraintValidationResponse.isRight()) { return Either.right(constraintValidationResponse.right().value()); } @@ -538,7 +538,7 @@ public class ServiceBusinessLogic extends ComponentBusinessLogic { } private Either validateOperationInputConstraint(OperationInputDefinition operationInputDefinition, String value, - String type) { + String type, String model) { ComponentInstanceProperty propertyDefinition = new ComponentInstanceProperty(); propertyDefinition.setType(operationInputDefinition.getParentPropertyType()); InputDefinition inputDefinition = new InputDefinition(); @@ -548,8 +548,8 @@ public class ServiceBusinessLogic extends ComponentBusinessLogic { if (Objects.nonNull(operationInputDefinition.getParentPropertyType())) { inputDefinition.setProperties(Collections.singletonList(propertyDefinition)); } - return PropertyValueConstraintValidationUtil.getInstance() - .validatePropertyConstraints(Collections.singletonList(inputDefinition), applicationDataTypeCache); + return PropertyValueConstraintValidationUtil.getInstance().validatePropertyConstraints(Collections.singletonList(inputDefinition), + applicationDataTypeCache, model); } private void addStaticValueToInputOperation(String value, Operation operation, OperationInputDefinition operationInputDefinition) { 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 c0c68d6c47..1a5a996a46 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 @@ -66,7 +66,6 @@ import org.openecomp.sdc.be.components.validation.component.ComponentValidator; 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.datamodel.utils.ArtifactUtils; import org.openecomp.sdc.be.datamodel.utils.UiComponentDataConverter; import org.openecomp.sdc.be.datatypes.elements.GetInputValueDataDefinition; @@ -108,6 +107,7 @@ 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.cache.ApplicationDataTypeCache; 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; @@ -120,7 +120,6 @@ 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.DaoStatusConverter; import org.openecomp.sdc.be.model.operations.impl.InterfaceLifecycleOperation; import org.openecomp.sdc.be.resources.data.auditing.AuditingActionEnum; import org.openecomp.sdc.be.tosca.CsarUtils; @@ -965,20 +964,14 @@ public class ServiceImportBusinessLogic { Map originCompMap = new HashMap<>(); List relations = new ArrayList<>(); Map> instInputs = new HashMap<>(); + log.debug("enter ServiceImportBusinessLogic createResourceInstancesRelations#createResourceInstancesRelations - Before get all datatypes. "); - if (serviceBusinessLogic.dataTypeCache != null) { - Either, JanusGraphOperationStatus> allDataTypes = serviceBusinessLogic.dataTypeCache.getAll(); - if (allDataTypes.isRight()) { - JanusGraphOperationStatus status = allDataTypes.right().value(); - BeEcompErrorManager.getInstance().logInternalFlowError("UpdatePropertyValueOnComponentInstance", - "Failed to update property value on instance. Status is " + status, BeEcompErrorManager.ErrorSeverity.ERROR); - throw new ComponentException(componentsUtils - .getResponseFormat(componentsUtils.convertFromStorageResponse(DaoStatusConverter.convertJanusGraphStatusToStorageStatus(status)), - yamlName)); - } + final ApplicationDataTypeCache applicationDataTypeCache = serviceBusinessLogic.applicationDataTypeCache; + if (applicationDataTypeCache != null) { Resource finalResource = resource; uploadResInstancesMap.values().forEach( - i -> processComponentInstance(yamlName, finalResource, componentInstancesList, allDataTypes, instProperties, instCapabilities, + i -> processComponentInstance(yamlName, finalResource, componentInstancesList, + componentsUtils.getAllDataTypes(applicationDataTypeCache, finalResource.getModel()), instProperties, instCapabilities, instRequirements, instDeploymentArtifacts, instArtifacts, instAttributes, originCompMap, instInputs, i)); } serviceImportParseLogic.associateComponentInstancePropertiesToComponent(yamlName, resource, instProperties); @@ -1333,20 +1326,13 @@ public class ServiceImportBusinessLogic { List relations = new ArrayList<>(); Map> instInputs = new HashMap<>(); log.debug("enter ServiceImportBusinessLogic createServiceInstancesRelations#createResourceInstancesRelations - Before get all datatypes. "); - if (serviceBusinessLogic.dataTypeCache != null) { - Either, JanusGraphOperationStatus> allDataTypes = serviceBusinessLogic.dataTypeCache.getAll(); - if (allDataTypes.isRight()) { - JanusGraphOperationStatus status = allDataTypes.right().value(); - BeEcompErrorManager.getInstance().logInternalFlowError("UpdatePropertyValueOnComponentInstance", - "Failed to update property value on instance. Status is " + status, BeEcompErrorManager.ErrorSeverity.ERROR); - throw new ComponentException(componentsUtils - .getResponseFormat(componentsUtils.convertFromStorageResponse(DaoStatusConverter.convertJanusGraphStatusToStorageStatus(status)), - yamlName)); - } + final ApplicationDataTypeCache applicationDataTypeCache = serviceBusinessLogic.applicationDataTypeCache; + if (applicationDataTypeCache != null) { Service finalResource = service; uploadResInstancesMap.values().forEach( - i -> processComponentInstance(yamlName, finalResource, componentInstancesList, allDataTypes, instProperties, instCapabilities, - instRequirements, instDeploymentArtifacts, instArtifacts, instAttributes, originCompMap, instInputs, i)); + i -> processComponentInstance(yamlName, finalResource, componentInstancesList, + componentsUtils.getAllDataTypes(applicationDataTypeCache, finalResource.getModel()), instProperties, + instCapabilities, instRequirements, instDeploymentArtifacts, instArtifacts, instAttributes, originCompMap, instInputs, i)); } serviceImportParseLogic.associateComponentInstancePropertiesToComponent(yamlName, service, instProperties); serviceImportParseLogic.associateComponentInstanceInputsToComponent(yamlName, service, instInputs); @@ -1376,7 +1362,7 @@ public class ServiceImportBusinessLogic { } protected void processComponentInstance(String yamlName, Component component, List componentInstancesList, - Either, JanusGraphOperationStatus> allDataTypes, + Map allDataTypes, Map> instProperties, Map>> instCapabilties, Map>> instRequirements, @@ -1416,12 +1402,12 @@ public class ServiceImportBusinessLogic { } if (originResource.getResourceType() != ResourceTypeEnum.VF) { ResponseFormat addPropertiesValueToRiRes = addPropertyValuesToRi(uploadComponentInstanceInfo, component, originResource, - currentCompInstance, instProperties, allDataTypes.left().value()); + currentCompInstance, instProperties, allDataTypes); if (addPropertiesValueToRiRes.getStatus() != 200) { throw new ComponentException(addPropertiesValueToRiRes); } } else { - addInputsValuesToRi(uploadComponentInstanceInfo, component, originResource, currentCompInstance, instInputs, allDataTypes.left().value()); + addInputsValuesToRi(uploadComponentInstanceInfo, component, originResource, currentCompInstance, instInputs, allDataTypes); } } @@ -1557,7 +1543,7 @@ public class ServiceImportBusinessLogic { return componentsUtils.getResponseFormat(ActionStatus.OK); } - protected void processComponentInstanceCapabilities(Either, JanusGraphOperationStatus> allDataTypes, + protected void processComponentInstanceCapabilities(Map allDataTypes, Map>> instCapabilties, UploadComponentInstanceInfo uploadComponentInstanceInfo, ComponentInstance currentCompInstance, Resource originResource) { @@ -1569,18 +1555,18 @@ public class ServiceImportBusinessLogic { originResource.getCapabilities().forEach((k, v) -> serviceImportParseLogic.addCapabilities(originCapabilities, k, v)); uploadComponentInstanceInfo.getCapabilities().values() .forEach(l -> serviceImportParseLogic.addCapabilitiesProperties(newPropertiesMap, l)); - updateCapabilityPropertiesValues(allDataTypes, originCapabilities, newPropertiesMap); + updateCapabilityPropertiesValues(allDataTypes, originCapabilities, newPropertiesMap, originResource.getModel()); } else { originCapabilities = originResource.getCapabilities(); } instCapabilties.put(currentCompInstance, originCapabilities); } - protected void updateCapabilityPropertiesValues(Either, JanusGraphOperationStatus> allDataTypes, + protected void updateCapabilityPropertiesValues(Map allDataTypes, Map> originCapabilities, - Map> newPropertiesMap) { + Map> newPropertiesMap, String model) { originCapabilities.values().stream().flatMap(Collection::stream).filter(c -> newPropertiesMap.containsKey(c.getName())) - .forEach(c -> updatePropertyValues(c.getProperties(), newPropertiesMap.get(c.getName()), allDataTypes.left().value())); + .forEach(c -> updatePropertyValues(c.getProperties(), newPropertiesMap.get(c.getName()), allDataTypes)); } protected void updatePropertyValues(List properties, Map newProperties, diff --git a/catalog-be/src/main/java/org/openecomp/sdc/be/components/merge/property/PropertyDataValueMergeBusinessLogic.java b/catalog-be/src/main/java/org/openecomp/sdc/be/components/merge/property/PropertyDataValueMergeBusinessLogic.java index 9888129071..272798f869 100644 --- a/catalog-be/src/main/java/org/openecomp/sdc/be/components/merge/property/PropertyDataValueMergeBusinessLogic.java +++ b/catalog-be/src/main/java/org/openecomp/sdc/be/components/merge/property/PropertyDataValueMergeBusinessLogic.java @@ -43,15 +43,15 @@ public class PropertyDataValueMergeBusinessLogic { private static final Logger LOGGER = Logger.getLogger(PropertyDataValueMergeBusinessLogic.class); private final PropertyValueMerger propertyValueMerger; - private final ApplicationDataTypeCache dataTypeCache; + private final ApplicationDataTypeCache applicationDataTypeCache; private final PropertyConvertor propertyConvertor; private final Gson gson = new Gson(); @Autowired - public PropertyDataValueMergeBusinessLogic(PropertyValueMerger propertyValueMerger, ApplicationDataTypeCache dataTypeCache, + public PropertyDataValueMergeBusinessLogic(PropertyValueMerger propertyValueMerger, ApplicationDataTypeCache applicationDataTypeCache, PropertyConvertor propertyConvertor) { this.propertyValueMerger = propertyValueMerger; - this.dataTypeCache = dataTypeCache; + this.applicationDataTypeCache = applicationDataTypeCache; this.propertyConvertor = propertyConvertor; } @@ -60,7 +60,7 @@ public class PropertyDataValueMergeBusinessLogic { * @param newProp the new property to merge value into */ public void mergePropertyValue(PropertyDataDefinition oldProp, PropertyDataDefinition newProp, List getInputNamesToMerge) { - Either, JanusGraphOperationStatus> dataTypesEither = dataTypeCache.getAll(); + Either, JanusGraphOperationStatus> dataTypesEither = applicationDataTypeCache.getAll(oldProp.getModel()); if (dataTypesEither.isRight()) { LOGGER.debug("failed to fetch data types, skip merging of previous property values. status: {}", dataTypesEither.right().value()); } else { @@ -116,4 +116,5 @@ public class PropertyDataValueMergeBusinessLogic { String getInputEntry = "\"%s\":\"%s\""; return value != null && value.contains(String.format(getInputEntry, ToscaFunctions.GET_INPUT.getFunctionName(), inputName)); } + } diff --git a/catalog-be/src/main/java/org/openecomp/sdc/be/components/validation/AnnotationValidator.java b/catalog-be/src/main/java/org/openecomp/sdc/be/components/validation/AnnotationValidator.java index b4f6bbe7db..a443e5f90b 100644 --- a/catalog-be/src/main/java/org/openecomp/sdc/be/components/validation/AnnotationValidator.java +++ b/catalog-be/src/main/java/org/openecomp/sdc/be/components/validation/AnnotationValidator.java @@ -21,52 +21,49 @@ package org.openecomp.sdc.be.components.validation; import java.util.ArrayList; import java.util.List; -import java.util.Map; -import org.openecomp.sdc.be.components.impl.ResourceImportManager; import org.openecomp.sdc.be.components.impl.utils.ExceptionUtils; import org.openecomp.sdc.be.datatypes.elements.Annotation; import org.openecomp.sdc.be.datatypes.elements.PropertyDataDefinition; import org.openecomp.sdc.be.impl.ComponentsUtils; import org.openecomp.sdc.be.model.AnnotationTypeDefinition; -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.common.log.wrappers.Logger; import org.springframework.stereotype.Component; @Component public class AnnotationValidator { - private static final Logger log = Logger.getLogger(ResourceImportManager.class); private final PropertyValidator propertyValidator; private final ExceptionUtils exceptionUtils; - private final ApplicationDataTypeCache dataTypeCache; + private final ApplicationDataTypeCache applicationDataTypeCache; private final ComponentsUtils componentsUtils; - public AnnotationValidator(PropertyValidator propertyValidator, ExceptionUtils exceptionUtils, ApplicationDataTypeCache dataTypeCache, + public AnnotationValidator(PropertyValidator propertyValidator, ExceptionUtils exceptionUtils, ApplicationDataTypeCache applicationDataTypeCache, ComponentsUtils componentsUtils) { this.propertyValidator = propertyValidator; this.exceptionUtils = exceptionUtils; - this.dataTypeCache = dataTypeCache; + this.applicationDataTypeCache = applicationDataTypeCache; this.componentsUtils = componentsUtils; } - public List validateAnnotationsProperties(Annotation annotation, AnnotationTypeDefinition dbAnnotationTypeDefinition) { + public List validateAnnotationsProperties(final Annotation annotation, final AnnotationTypeDefinition dbAnnotationTypeDefinition, + final String model) { List validAnnotations = new ArrayList<>(); - if (annotation != null && propertiesValidator(annotation.getProperties(), dbAnnotationTypeDefinition.getProperties())) { + if (annotation != null && propertiesValidator(annotation.getProperties(), dbAnnotationTypeDefinition.getProperties(), model)) { validAnnotations.add(annotation); } return validAnnotations; } - private boolean propertiesValidator(List properties, List dbAnnotationTypeDefinitionProperties) { + private boolean propertiesValidator(final List properties, + final List dbAnnotationTypeDefinitionProperties, final String model) { List propertyDefinitionsList = new ArrayList<>(); if (properties == null || dbAnnotationTypeDefinitionProperties == null) { return false; } properties.stream().forEach(property -> propertyDefinitionsList.add(new PropertyDefinition(property))); - Map allDataTypes = dataTypeCache.getAll().left().on(error -> exceptionUtils.rollBackAndThrow(error)); - propertyValidator.thinPropertiesValidator(propertyDefinitionsList, dbAnnotationTypeDefinitionProperties, allDataTypes); + propertyValidator.thinPropertiesValidator(propertyDefinitionsList, dbAnnotationTypeDefinitionProperties, + applicationDataTypeCache.getAll(model).left().on(error -> exceptionUtils.rollBackAndThrow(error))); return true; } } diff --git a/catalog-be/src/main/java/org/openecomp/sdc/be/datamodel/utils/PropertyValueConstraintValidationUtil.java b/catalog-be/src/main/java/org/openecomp/sdc/be/datamodel/utils/PropertyValueConstraintValidationUtil.java index 9569247047..e7c6ef386d 100644 --- a/catalog-be/src/main/java/org/openecomp/sdc/be/datamodel/utils/PropertyValueConstraintValidationUtil.java +++ b/catalog-be/src/main/java/org/openecomp/sdc/be/datamodel/utils/PropertyValueConstraintValidationUtil.java @@ -62,10 +62,11 @@ public class PropertyValueConstraintValidationUtil { return new PropertyValueConstraintValidationUtil(); } - public Either validatePropertyConstraints(Collection propertyDefinitionList, - ApplicationDataTypeCache applicationDataTypeCache) { + public Either validatePropertyConstraints(final Collection propertyDefinitionList, + final ApplicationDataTypeCache applicationDataTypeCache, + final String model) { ResponseFormatManager responseFormatManager = getResponseFormatManager(); - dataTypeDefinitionCache = applicationDataTypeCache.getAll().left().value(); + dataTypeDefinitionCache = applicationDataTypeCache.getAll(model).left().value(); CollectionUtils.emptyIfNull(propertyDefinitionList).stream().filter(this::isValuePresent) .forEach(this::evaluatePropertyTypeForConstraintValidation); if (CollectionUtils.isNotEmpty(errorMessages)) { diff --git a/catalog-be/src/main/java/org/openecomp/sdc/be/impl/ComponentsUtils.java b/catalog-be/src/main/java/org/openecomp/sdc/be/impl/ComponentsUtils.java index 607497ca26..3b55e67c75 100644 --- a/catalog-be/src/main/java/org/openecomp/sdc/be/impl/ComponentsUtils.java +++ b/catalog-be/src/main/java/org/openecomp/sdc/be/impl/ComponentsUtils.java @@ -75,9 +75,11 @@ import org.openecomp.sdc.be.components.impl.exceptions.ByActionStatusComponentEx import org.openecomp.sdc.be.components.impl.exceptions.ByResponseFormatComponentException; import org.openecomp.sdc.be.components.impl.exceptions.ComponentException; import org.openecomp.sdc.be.config.BeEcompErrorManager; +import org.openecomp.sdc.be.config.BeEcompErrorManager.ErrorSeverity; import org.openecomp.sdc.be.dao.api.ActionStatus; import org.openecomp.sdc.be.dao.cassandra.CassandraOperationStatus; import org.openecomp.sdc.be.dao.graph.datatype.AdditionalInformationEnum; +import org.openecomp.sdc.be.dao.janusgraph.JanusGraphOperationStatus; import org.openecomp.sdc.be.datamodel.utils.ConstraintConvertor; import org.openecomp.sdc.be.datatypes.elements.AdditionalInfoParameterInfo; import org.openecomp.sdc.be.datatypes.elements.RequirementNodeFilterPropertyDataDefinition; @@ -97,6 +99,7 @@ import org.openecomp.sdc.be.model.PropertyConstraint; import org.openecomp.sdc.be.model.RequirementDefinition; import org.openecomp.sdc.be.model.Resource; import org.openecomp.sdc.be.model.User; +import org.openecomp.sdc.be.model.cache.ApplicationDataTypeCache; import org.openecomp.sdc.be.model.operations.StorageException; import org.openecomp.sdc.be.model.operations.api.StorageOperationStatus; import org.openecomp.sdc.be.model.operations.impl.PropertyOperation.PropertyConstraintDeserialiser; @@ -1542,4 +1545,20 @@ public class ComponentsUtils { return uiConstraintsMaps.stream().map(dataMap -> new com.fasterxml.jackson.databind.ObjectMapper().convertValue(dataMap, UIConstraint.class)) .collect(Collectors.toList()); } + + public Map getAllDataTypes(final ApplicationDataTypeCache applicationDataTypeCache, final String model) { + final Either, JanusGraphOperationStatus> allDataTypes = applicationDataTypeCache.getAll(model); + if (allDataTypes.isRight()) { + final var operationStatus = allDataTypes.right().value(); + if (operationStatus == JanusGraphOperationStatus.NOT_FOUND) { + BeEcompErrorManager.getInstance().logInternalDataError("FetchDataTypes", "Data types are not loaded", ErrorSeverity.ERROR); + throw new ByActionStatusComponentException(ActionStatus.DATA_TYPES_NOT_LOADED, model); + } else { + BeEcompErrorManager.getInstance().logInternalFlowError("FetchDataTypes", "Failed to fetch data types", ErrorSeverity.ERROR); + throw new ByActionStatusComponentException(ActionStatus.GENERAL_ERROR); + } + } + return allDataTypes.left().value(); + } + } diff --git a/catalog-be/src/main/java/org/openecomp/sdc/be/servlets/ComponentPropertyServlet.java b/catalog-be/src/main/java/org/openecomp/sdc/be/servlets/ComponentPropertyServlet.java index 6d82e2b239..fec5dd8b7b 100644 --- a/catalog-be/src/main/java/org/openecomp/sdc/be/servlets/ComponentPropertyServlet.java +++ b/catalog-be/src/main/java/org/openecomp/sdc/be/servlets/ComponentPropertyServlet.java @@ -315,9 +315,10 @@ public class ComponentPropertyServlet extends BeGenericServlet { ResponseFormat responseFormat = getComponentsUtils().getResponseFormat(ActionStatus.INVALID_CONTENT); return buildErrorResponse(responseFormat); } - //Validate value and Constraint of property + //Validate value and Constraint of property and Fetch all data types from cache Either constraintValidatorResponse = PropertyValueConstraintValidationUtil.getInstance() - .validatePropertyConstraints(properties.values(), applicationDataTypeCache); + .validatePropertyConstraints(properties.values(), applicationDataTypeCache, + propertyBusinessLogic.getComponentModelByComponentId(componentId)); if (constraintValidatorResponse.isRight()) { log.error("Failed validation value and constraint of property: {}", constraintValidatorResponse.right().value()); return buildErrorResponse(constraintValidatorResponse.right().value()); diff --git a/catalog-be/src/main/java/org/openecomp/sdc/be/servlets/TypesFetchServlet.java b/catalog-be/src/main/java/org/openecomp/sdc/be/servlets/TypesFetchServlet.java index ac195f9315..9d3817431f 100644 --- a/catalog-be/src/main/java/org/openecomp/sdc/be/servlets/TypesFetchServlet.java +++ b/catalog-be/src/main/java/org/openecomp/sdc/be/servlets/TypesFetchServlet.java @@ -120,7 +120,8 @@ public class TypesFetchServlet extends AbstractValidationsServlet { @ApiResponse(responseCode = "400", description = "Invalid content / Missing content"), @ApiResponse(responseCode = "404", description = "Data types not found")}) @PermissionAllowed(AafPermission.PermNames.INTERNAL_ALL_VALUE) - public Response getAllDataTypesServlet(@Context final HttpServletRequest request, @HeaderParam(value = Constants.USER_ID_HEADER) String userId) { + public Response getAllDataTypesServlet(@Context final HttpServletRequest request, @HeaderParam(value = Constants.USER_ID_HEADER) String userId, + @Parameter(description = "model") @QueryParam("model") String modelName) { Wrapper responseWrapper = new Wrapper<>(); Wrapper userWrapper = new Wrapper<>(); init(); @@ -128,7 +129,8 @@ public class TypesFetchServlet extends AbstractValidationsServlet { if (responseWrapper.isEmpty()) { String url = request.getMethod() + " " + request.getRequestURI(); log.debug("Start handle request of {} - modifier id is {}", url, userId); - Map dataTypes = propertyBusinessLogic.getAllDataTypes(); + final Map dataTypes = resourceBusinessLogic.getComponentsUtils() + .getAllDataTypes(resourceBusinessLogic.getApplicationDataTypeCache(), modelName); String dataTypeJson = gson.toJson(dataTypes); Response okResponse = buildOkResponse(getComponentsUtils().getResponseFormat(ActionStatus.OK), dataTypeJson); responseWrapper.setInnerElement(okResponse); diff --git a/catalog-be/src/main/java/org/openecomp/sdc/be/tosca/GroupExportParserImpl.java b/catalog-be/src/main/java/org/openecomp/sdc/be/tosca/GroupExportParserImpl.java index 0b0ecd21d1..30420876b7 100644 --- a/catalog-be/src/main/java/org/openecomp/sdc/be/tosca/GroupExportParserImpl.java +++ b/catalog-be/src/main/java/org/openecomp/sdc/be/tosca/GroupExportParserImpl.java @@ -66,17 +66,17 @@ public class GroupExportParserImpl implements GroupExportParser { private static final Logger log = Logger.getLogger(GroupExportParserImpl.class); private final PropertyConvertor propertyConvertor; private Map dataTypes; - private ApplicationDataTypeCache dataTypeCache; + private ApplicationDataTypeCache applicationDataTypeCache; @Autowired - public GroupExportParserImpl(ApplicationDataTypeCache dataTypeCache, PropertyConvertor propertyConvertor) { - this.dataTypeCache = dataTypeCache; + public GroupExportParserImpl(ApplicationDataTypeCache applicationDataTypeCache, PropertyConvertor propertyConvertor) { + this.applicationDataTypeCache = applicationDataTypeCache; this.propertyConvertor = propertyConvertor; this.dataTypes = getDataTypes(); } private Map getDataTypes() { - Either, JanusGraphOperationStatus> dataTypesEither = dataTypeCache.getAll(); + Either, JanusGraphOperationStatus> dataTypesEither = applicationDataTypeCache.getAll(null); if (dataTypesEither.isRight()) { log.error("Failed to retrieve all data types {}", dataTypesEither.right().value()); throw new SdcResourceNotFoundException(); @@ -86,7 +86,7 @@ public class GroupExportParserImpl implements GroupExportParser { @EventListener public void onDataTypesCacheChangedEvent(ApplicationDataTypeCache.DataTypesCacheChangedEvent dataTypesCacheChangedEvent) { - dataTypes = dataTypesCacheChangedEvent.getNewData(); + dataTypes = dataTypesCacheChangedEvent.getNewData().get(null); log.debug("Data types cache updated."); } diff --git a/catalog-be/src/main/java/org/openecomp/sdc/be/tosca/PolicyExportParserImpl.java b/catalog-be/src/main/java/org/openecomp/sdc/be/tosca/PolicyExportParserImpl.java index d544d34b66..7fe8e941a5 100644 --- a/catalog-be/src/main/java/org/openecomp/sdc/be/tosca/PolicyExportParserImpl.java +++ b/catalog-be/src/main/java/org/openecomp/sdc/be/tosca/PolicyExportParserImpl.java @@ -52,19 +52,19 @@ import org.springframework.context.event.EventListener; public class PolicyExportParserImpl implements PolicyExportParser { private static final Logger log = Logger.getLogger(PolicyExportParserImpl.class); - private ApplicationDataTypeCache dataTypeCache; + private ApplicationDataTypeCache applicationDataTypeCache; private Map dataTypes; private PropertyConvertor propertyConvertor; @Autowired - public PolicyExportParserImpl(ApplicationDataTypeCache dataTypeCache, PropertyConvertor propertyConvertor) { - this.dataTypeCache = dataTypeCache; + public PolicyExportParserImpl(ApplicationDataTypeCache applicationDataTypeCache, PropertyConvertor propertyConvertor) { + this.applicationDataTypeCache = applicationDataTypeCache; this.propertyConvertor = propertyConvertor; this.dataTypes = getDataTypes(); } private Map getDataTypes() { - Either, JanusGraphOperationStatus> dataTypesEither = dataTypeCache.getAll(); + Either, JanusGraphOperationStatus> dataTypesEither = applicationDataTypeCache.getAll(null); if (dataTypesEither.isRight()) { log.error("Failed to retrieve all data types {}", dataTypesEither.right().value()); throw new SdcResourceNotFoundException(); @@ -74,7 +74,7 @@ public class PolicyExportParserImpl implements PolicyExportParser { @EventListener public void onDataTypesCacheChangedEvent(ApplicationDataTypeCache.DataTypesCacheChangedEvent dataTypesCacheChangedEvent) { - dataTypes = dataTypesCacheChangedEvent.getNewData(); + dataTypes = dataTypesCacheChangedEvent.getNewData().get(null); log.debug("Data types cache updated."); } 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 3fe3bd5c42..ef5192c048 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 @@ -157,7 +157,7 @@ public class ToscaExportHandler { .of("Service Function", "Service Role", "Naming Policy", "Service Type"); private static final YamlUtil yamlUtil = new YamlUtil(); private static final String COULD_NOT_PARSE_COMPONENT_ATTRIBUTES_COMPONENT_UNIQUE_ID = "Could not parse component '{}' attributes. Component unique id '{}'."; - private ApplicationDataTypeCache dataTypeCache; + private ApplicationDataTypeCache applicationDataTypeCache; private ToscaOperationFacade toscaOperationFacade; private CapabilityRequirementConverter capabilityRequirementConverter; private PolicyExportParser policyExportParser; @@ -170,7 +170,7 @@ public class ToscaExportHandler { private InterfacesOperationsConverter interfacesOperationsConverter; @Autowired - public ToscaExportHandler(final ApplicationDataTypeCache dataTypeCache, + public ToscaExportHandler(final ApplicationDataTypeCache applicationDataTypeCache, final ToscaOperationFacade toscaOperationFacade, final CapabilityRequirementConverter capabilityRequirementConverter, final PolicyExportParser policyExportParser, @@ -181,7 +181,7 @@ public class ToscaExportHandler { final OutputConverter outputConverter, final InterfaceLifecycleOperation interfaceLifecycleOperation, final InterfacesOperationsConverter interfacesOperationsConverter) { - this.dataTypeCache = dataTypeCache; + this.applicationDataTypeCache = applicationDataTypeCache; this.toscaOperationFacade = toscaOperationFacade; this.capabilityRequirementConverter = capabilityRequirementConverter; this.policyExportParser = policyExportParser; @@ -323,7 +323,7 @@ public class ToscaExportHandler { if (MapUtils.isNotEmpty(proxyInterfaceTypes)) { toscaNode.setInterface_types(proxyInterfaceTypes); } - Either, JanusGraphOperationStatus> dataTypesEither = dataTypeCache.getAll(); + Either, JanusGraphOperationStatus> dataTypesEither = applicationDataTypeCache.getAll(component.getModel()); if (dataTypesEither.isRight()) { log.debug("Failed to retrieve all data types {}", dataTypesEither.right().value()); return Either.right(ToscaError.GENERAL_ERROR); @@ -701,7 +701,7 @@ public class ToscaExportHandler { List allGlobalInterfaceTypes = lifecycleTypeEither.left().value().values().stream().map(InterfaceDataDefinition::getType) .collect(Collectors.toList()); toscaNode.setInterface_types(addInterfaceTypeElement(component, allGlobalInterfaceTypes)); - Either, JanusGraphOperationStatus> dataTypesEither = dataTypeCache.getAll(); + Either, JanusGraphOperationStatus> dataTypesEither = applicationDataTypeCache.getAll(component.getModel()); if (dataTypesEither.isRight()) { log.debug("Failed to fetch all data types :", dataTypesEither.right().value()); return Either.right(ToscaError.GENERAL_ERROR); @@ -1182,7 +1182,7 @@ public class ToscaExportHandler { String derivedFrom = ((Resource) origComponent).getToscaResourceName(); toscaNodeType.setDerived_from(derivedFrom); - Either, JanusGraphOperationStatus> dataTypesEither = dataTypeCache.getAll(); + Either, JanusGraphOperationStatus> dataTypesEither = applicationDataTypeCache.getAll(origComponent.getModel()); if (dataTypesEither.isRight()) { log.debug("Failed to retrieve all data types {}", dataTypesEither.right().value()); } -- cgit 1.2.3-korg