aboutsummaryrefslogtreecommitdiffstats
path: root/catalog-model
diff options
context:
space:
mode:
authorfranciscovila <javier.paradela.vila@est.tech>2023-02-07 17:00:03 +0000
committerMichael Morris <michael.morris@est.tech>2023-02-09 19:17:04 +0000
commitabbc25ad32db4f4c898bdaaea0b66c0a1d5fd8da (patch)
treea760d6e5495b797a8ee28acc42a83439e9b1a68f /catalog-model
parentbe850f6e83cbaa5c16f79c2c8732583f42e55429 (diff)
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 <javier.paradela.vila@est.tech> Change-Id: I37749fd3d2992f3134a09c07bb43c0208ce12a23
Diffstat (limited to 'catalog-model')
-rw-r--r--catalog-model/src/main/java/org/openecomp/sdc/be/model/operations/impl/DataTypeOperation.java22
-rw-r--r--catalog-model/src/main/java/org/openecomp/sdc/be/model/operations/impl/PropertyOperation.java18
2 files changed, 40 insertions, 0 deletions
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<PropertyDefinition, JanusGraphOperationStatus> 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<PropertyDefinition, JanusGraphOperationStatus> updatePropertyAssociatedToNode(NodeTypeEnum nodeType, String uniqueId,
+ PropertyDefinition newProperty) {
+ Either<Map<String, PropertyDefinition>, JanusGraphOperationStatus> oldPropertiesRes = findPropertiesOfNode(nodeType, uniqueId);
+
+ if (oldPropertiesRes.isRight()) {
+ return Either.right(oldPropertiesRes.right().value());
+ } else {
+ Map<String, PropertyDefinition> 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<Map<String, PropertyDefinition>, JanusGraphOperationStatus> findPropertiesOfNode(NodeTypeEnum nodeType, String uniqueId) {
Map<String, PropertyDefinition> resourceProps = new HashMap<>();
Either<List<ImmutablePair<PropertyData, GraphEdge>>, 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());
}