From abbc25ad32db4f4c898bdaaea0b66c0a1d5fd8da Mon Sep 17 00:00:00 2001 From: franciscovila Date: Tue, 7 Feb 2023 17:00:03 +0000 Subject: Edit properties of non-normative data types Develop all necessary changes in the UI to allow editing of non-normative data types Issue-ID: SDC-4373 Signed-off-by: franciscovila Change-Id: I37749fd3d2992f3134a09c07bb43c0208ce12a23 --- .../model/operations/impl/DataTypeOperation.java | 22 ++++++++++++++++++++++ .../model/operations/impl/PropertyOperation.java | 18 ++++++++++++++++++ 2 files changed, 40 insertions(+) (limited to 'catalog-model') diff --git a/catalog-model/src/main/java/org/openecomp/sdc/be/model/operations/impl/DataTypeOperation.java b/catalog-model/src/main/java/org/openecomp/sdc/be/model/operations/impl/DataTypeOperation.java index bbc70f6c3f..391add9a94 100644 --- a/catalog-model/src/main/java/org/openecomp/sdc/be/model/operations/impl/DataTypeOperation.java +++ b/catalog-model/src/main/java/org/openecomp/sdc/be/model/operations/impl/DataTypeOperation.java @@ -281,6 +281,28 @@ public class DataTypeOperation extends AbstractOperation { return PropertyDefinitionDtoMapper.mapFrom(propertyDataDefinition); } + public PropertyDefinitionDto updateProperty(final String dataTypeId, final PropertyDefinitionDto propertyDefinitionDto) { + final String propertyName = propertyDefinitionDto.getName(); + LOGGER.debug("Updating property '{}' to data type '{}'.", propertyName, dataTypeId); + + getDataTypeByUid(dataTypeId).orElseThrow(DataTypeOperationExceptionSupplier.dataTypeNotFound(dataTypeId)); + + final Either resultEither = + propertyOperation.updatePropertyAssociatedToNode(NodeTypeEnum.DataType, dataTypeId, PropertyDefinitionDtoMapper.mapTo(propertyDefinitionDto)); + if (resultEither.isRight()) { + final JanusGraphOperationStatus status = resultEither.right().value(); + LOGGER.debug("Could not update property '{}' on data type '{}'. JanusGraph status is '{}'", propertyName, dataTypeId, status); + if (status == JanusGraphOperationStatus.JANUSGRAPH_SCHEMA_VIOLATION) { + throw DataTypeOperationExceptionSupplier.dataTypePropertyAlreadyExists(dataTypeId, propertyName).get(); + } + LOGGER.error("Could not update property '{}' on data type '{}'. JanusGraph status is '{}'", propertyName, dataTypeId, status); + throw DataTypeOperationExceptionSupplier.unexpectedErrorWhileCreatingProperty(dataTypeId, propertyName).get(); + } + LOGGER.debug("Property '{}' was updated in data type '{}'.", propertyName, dataTypeId); + final PropertyDefinition propertyData = resultEither.left().value(); + return PropertyDefinitionDtoMapper.mapFrom(propertyData); + } + public void addPropertyToAdditionalTypeDataType(DataTypeDataDefinition dataTypeDataDefinition, PropertyDefinitionDto property) { modelOperation.addPropertyToAdditionalType(ElementTypeEnum.DATA_TYPE, property, dataTypeDataDefinition.getModel(), dataTypeDataDefinition.getName()); } 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 0b8d2c8cb1..516474331b 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 @@ -382,6 +382,23 @@ public class PropertyOperation extends AbstractOperation implements IPropertyOpe return Either.left(createNodeResult.left().value()); } + public Either updatePropertyAssociatedToNode(NodeTypeEnum nodeType, String uniqueId, + PropertyDefinition newProperty) { + Either, JanusGraphOperationStatus> oldPropertiesRes = findPropertiesOfNode(nodeType, uniqueId); + + if (oldPropertiesRes.isRight()) { + return Either.right(oldPropertiesRes.right().value()); + } else { + Map oldProperties = oldPropertiesRes.left().value(); + PropertyDefinition oldPropDef = oldProperties.get(newProperty.getName()); + JanusGraphOperationStatus status = updateOldProperty(newProperty, oldPropDef); + if (status != JanusGraphOperationStatus.OK) { + return Either.right(status); + } + } + return Either.left(newProperty); + } + public Either, JanusGraphOperationStatus> findPropertiesOfNode(NodeTypeEnum nodeType, String uniqueId) { Map resourceProps = new HashMap<>(); Either>, JanusGraphOperationStatus> childrenNodes = janusGraphGenericDao @@ -501,6 +518,7 @@ public class PropertyOperation extends AbstractOperation implements IPropertyOpe oldPropDef.setDefaultValue(newPropDef.getDefaultValue()); oldPropDef.setDescription(newPropDef.getDescription()); oldPropDef.setRequired(newPropDef.isRequired()); + oldPropDef.setConstraints(newPropDef.getConstraints()); // Type is updated to fix possible null type issue in janusGraph DB oldPropDef.setType(newPropDef.getType()); } -- cgit 1.2.3-korg