summaryrefslogtreecommitdiffstats
path: root/catalog-model
diff options
context:
space:
mode:
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());
}