summaryrefslogtreecommitdiffstats
path: root/catalog-model/src/main/java/org
diff options
context:
space:
mode:
authorJvD_Ericsson <jeff.van.dam@est.tech>2023-02-21 14:07:50 +0000
committerMichael Morris <michael.morris@est.tech>2023-02-22 14:16:42 +0000
commit9b8d90c9cdc012ca444d35465dc2e77662e4becf (patch)
treeef9f5f6d99a5bcc5eb40d965829d9a5c0128ea76 /catalog-model/src/main/java/org
parent8aa94a97ebfff1205e85470d78202f598632dbd6 (diff)
Support delete non-normative data types
Issue-ID: SDC-4411 Signed-off-by: JvD_Ericsson <jeff.van.dam@est.tech> Change-Id: I246e50d848a17178369bfb643989d5447a887017
Diffstat (limited to 'catalog-model/src/main/java/org')
-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/ModelOperation.java28
2 files changed, 42 insertions, 8 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 f79f1501e7..b8ddff9907 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
@@ -16,6 +16,7 @@
* SPDX-License-Identifier: Apache-2.0
* ============LICENSE_END=========================================================
*/
+
package org.openecomp.sdc.be.model.operations.impl;
import fj.data.Either;
@@ -190,6 +191,18 @@ public class DataTypeOperation extends AbstractOperation {
});
}
+ public void deleteDataTypesByDataTypeId(final String dataTypeId) {
+ final JanusGraph janusGraph = janusGraphGenericDao.getJanusGraph();
+ final GraphTraversalSource traversal = janusGraph.traversal();
+ final List<Vertex> dataTypeList = traversal.V()
+ .has(GraphPropertiesDictionary.UNIQUE_ID.getProperty(), dataTypeId)
+ .toList();
+ dataTypeList.forEach(dataTypeVertex -> {
+ traversal.V(dataTypeVertex).out(GraphEdgeLabels.PROPERTY.getProperty()).drop().iterate();
+ dataTypeVertex.remove();
+ });
+ }
+
public Optional<DataTypeDataDefinition> getDataTypeByUid(final String uniqueId) {
final Either<DataTypeData, JanusGraphOperationStatus> dataTypeEither = janusGraphGenericDao
.getNode(UniqueIdBuilder.getKeyByNodeType(NodeTypeEnum.DataType), uniqueId, DataTypeData.class);
@@ -288,7 +301,8 @@ public class DataTypeOperation extends AbstractOperation {
getDataTypeByUid(dataTypeId).orElseThrow(DataTypeOperationExceptionSupplier.dataTypeNotFound(dataTypeId));
final Either<PropertyDefinition, JanusGraphOperationStatus> resultEither =
- propertyOperation.updatePropertyAssociatedToNode(NodeTypeEnum.DataType, dataTypeId, PropertyDefinitionDtoMapper.mapTo(propertyDefinitionDto));
+ 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);
@@ -310,6 +324,11 @@ public class DataTypeOperation extends AbstractOperation {
dataTypeDataDefinition.getName(), isAdd);
}
+ public void removeDataTypeFromAdditionalType(final DataTypeDataDefinition dataTypeDataDefinition) {
+ modelOperation.removeDataTypeFromAdditionalType(ElementTypeEnum.DATA_TYPE, dataTypeDataDefinition.getModel(),
+ dataTypeDataDefinition.getName());
+ }
+
public PropertyDefinitionDto deleteProperty(final DataTypeDataDefinition dataTypeDataDefinition, final String propertyId) {
final List<PropertyDefinition> propertiesData = findAllProperties(dataTypeDataDefinition.getUniqueId());
final String dataTypeDataDefinitionName = dataTypeDataDefinition.getName();
@@ -336,5 +355,4 @@ public class DataTypeOperation extends AbstractOperation {
propertiesData.remove(propertyDefinition);
return PropertyDefinitionDtoMapper.mapFrom(propertyDataDefinition);
}
-
}
diff --git a/catalog-model/src/main/java/org/openecomp/sdc/be/model/operations/impl/ModelOperation.java b/catalog-model/src/main/java/org/openecomp/sdc/be/model/operations/impl/ModelOperation.java
index 19289411c3..b57c57a9cc 100644
--- a/catalog-model/src/main/java/org/openecomp/sdc/be/model/operations/impl/ModelOperation.java
+++ b/catalog-model/src/main/java/org/openecomp/sdc/be/model/operations/impl/ModelOperation.java
@@ -16,6 +16,7 @@
* SPDX-License-Identifier: Apache-2.0
* ============LICENSE_END=========================================================
*/
+
package org.openecomp.sdc.be.model.operations.impl;
import static org.openecomp.sdc.be.utils.TypeUtils.ToscaTagNamesEnum.DATA_TYPES;
@@ -74,9 +75,8 @@ import org.yaml.snakeyaml.Yaml;
@Component("model-operation")
public class ModelOperation {
- private static final Logger log = Logger.getLogger(ModelOperation.class);
static final Path ADDITIONAL_TYPE_DEFINITIONS_PATH = Path.of(ADDITIONAL_TYPE_DEFINITIONS);
-
+ private static final Logger log = Logger.getLogger(ModelOperation.class);
private final JanusGraphGenericDao janusGraphGenericDao;
private final JanusGraphDao janusGraphDao;
private final ToscaModelImportCassandraDao toscaModelImportCassandraDao;
@@ -411,10 +411,9 @@ public class ModelOperation {
final Map<String, Object> existingProperties =
(Map<String, Object>) ((Map<String, Object>) existingTypeContent.get(newTypeToUpdate.getKey())).get(PROPERTIES.getElementName());
- final List<Entry<String, Object>> propertiesMissingFromNewDef = MapUtils.isEmpty(existingProperties) ? Collections.emptyList()
- : existingProperties.entrySet().stream()
- .filter(existingPropEntry -> !propertiesInNewDef.keySet().contains(existingPropEntry.getKey()))
- .collect(Collectors.toList());
+ final List<Entry<String, Object>> propertiesMissingFromNewDef = MapUtils.isEmpty(existingProperties) ? Collections.emptyList() :
+ existingProperties.entrySet().stream()
+ .filter(existingPropEntry -> !propertiesInNewDef.keySet().contains(existingPropEntry.getKey())).collect(Collectors.toList());
if (CollectionUtils.isNotEmpty(propertiesMissingFromNewDef)) {
typesToUpate.put(newTypeToUpdate.getKey(), newTypeToUpdate.getValue());
@@ -458,6 +457,23 @@ public class ModelOperation {
toscaModelImportCassandraDao.saveAll(modelName, rebuiltModelImportList);
}
+ public void removeDataTypeFromAdditionalType(final ElementTypeEnum elementTypeEnum, final String modelName, final String name) {
+ final List<ToscaImportByModel> modelImportList = toscaModelImportCassandraDao.findAllByModel(modelName);
+ final Optional<ToscaImportByModel> additionalTypeDefinitionsImportOptional = modelImportList.stream()
+ .filter(t -> ADDITIONAL_TYPE_DEFINITIONS_PATH.equals(Path.of(t.getFullPath()))).findAny();
+ if (additionalTypeDefinitionsImportOptional.isEmpty()) {
+ return;
+ }
+ final ToscaImportByModel additionalTypeDefinitionsImport = additionalTypeDefinitionsImportOptional.get();
+ removeExistingTypesFromDefaultImports(elementTypeEnum, Collections.singletonMap(name, null),
+ Collections.singletonList(additionalTypeDefinitionsImport));
+ final List<ToscaImportByModel> rebuiltModelImportList = modelImportList.stream()
+ .filter(toscaImportByModel -> !ADDITIONAL_TYPE_DEFINITIONS_PATH.equals(Path.of(toscaImportByModel.getFullPath())))
+ .collect(Collectors.toList());
+ rebuiltModelImportList.add(additionalTypeDefinitionsImport);
+ toscaModelImportCassandraDao.saveAll(modelName, rebuiltModelImportList);
+ }
+
private String buildPropertyAdditionalTypeDefinitionContent(final ElementTypeEnum elementTypeEnum, final String name,
final PropertyDefinitionDto property, final Map<String, Object> originalContent,
boolean isAdd) {