aboutsummaryrefslogtreecommitdiffstats
path: root/catalog-model/src/main/java/org/openecomp/sdc/be/model/operations/impl
diff options
context:
space:
mode:
authorandre.schmid <andre.schmid@est.tech>2022-10-04 20:29:28 +0100
committerMichael Morris <michael.morris@est.tech>2022-10-17 14:42:22 +0000
commitaa72781388f3e6408bb43f1b024d88ec1c9d2c10 (patch)
tree15002a934486557f1d62eec49e57af1e2e59b443 /catalog-model/src/main/java/org/openecomp/sdc/be/model/operations/impl
parentb75fe3c7ce231c86cd4c6d052da453d02809c8f9 (diff)
Add data type properties workspace
Implements the properties workspace for a data type, with the list and filter feature. Change-Id: I2ec337a0481bddd5fe32e45644abdc88e197fa49 Issue-ID: SDC-4214 Signed-off-by: André Schmid <andre.schmid@est.tech>
Diffstat (limited to 'catalog-model/src/main/java/org/openecomp/sdc/be/model/operations/impl')
-rw-r--r--catalog-model/src/main/java/org/openecomp/sdc/be/model/operations/impl/DataTypeOperation.java32
-rw-r--r--catalog-model/src/main/java/org/openecomp/sdc/be/model/operations/impl/PropertyOperation.java12
2 files changed, 36 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 f75e3cfb17..4194ab70db 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
@@ -21,11 +21,13 @@ package org.openecomp.sdc.be.model.operations.impl;
import fj.data.Either;
import java.util.ArrayList;
import java.util.Collections;
+import java.util.Comparator;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Optional;
import org.apache.commons.collections.CollectionUtils;
+import org.apache.commons.collections4.MapUtils;
import org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.GraphTraversalSource;
import org.apache.tinkerpop.gremlin.structure.Vertex;
import org.janusgraph.core.JanusGraph;
@@ -38,6 +40,8 @@ import org.openecomp.sdc.be.dao.neo4j.GraphEdgeLabels;
import org.openecomp.sdc.be.dao.neo4j.GraphPropertiesDictionary;
import org.openecomp.sdc.be.datatypes.elements.DataTypeDataDefinition;
import org.openecomp.sdc.be.datatypes.enums.NodeTypeEnum;
+import org.openecomp.sdc.be.exception.supplier.DataTypeOperationExceptionSupplier;
+import org.openecomp.sdc.be.model.PropertyDefinition;
import org.openecomp.sdc.be.model.jsonjanusgraph.operations.exception.OperationException;
import org.openecomp.sdc.be.model.operations.api.StorageOperationStatus;
import org.openecomp.sdc.be.resources.data.DataTypeData;
@@ -53,6 +57,7 @@ public class DataTypeOperation extends AbstractOperation {
private static final Logger LOGGER = LoggerFactory.getLogger(DataTypeOperation.class);
private ModelOperation modelOperation;
+ private PropertyOperation propertyOperation;
@Autowired
public DataTypeOperation(final HealingJanusGraphGenericDao janusGraphGenericDao) {
@@ -65,6 +70,11 @@ public class DataTypeOperation extends AbstractOperation {
this.modelOperation = modelOperation;
}
+ @Autowired
+ public void setPropertyOperation(PropertyOperation propertyOperation) {
+ this.propertyOperation = propertyOperation;
+ }
+
public List<DataTypeData> getAllDataTypeNodes() {
final List<DataTypeData> dataTypesFound = new ArrayList<>();
final Either<List<DataTypeData>, JanusGraphOperationStatus> getAllDataTypesWithNullModel =
@@ -172,4 +182,26 @@ public class DataTypeOperation extends AbstractOperation {
}
return Optional.of(dataTypeEither.left().value().getDataTypeDataDefinition());
}
+
+ public List<PropertyDefinition> findAllProperties(final String uniqueId) {
+ final Either<Map<String, PropertyDefinition>, JanusGraphOperationStatus> propertiesEither =
+ propertyOperation.findPropertiesOfNode(NodeTypeEnum.DataType, uniqueId);
+ if (propertiesEither.isRight()) {
+ final JanusGraphOperationStatus status = propertiesEither.right().value();
+ if (status == JanusGraphOperationStatus.NOT_FOUND) {
+ return List.of();
+ }
+ LOGGER.error("Could not retrieve data type '{}' properties. JanusGraphOperationStatus: '{}'", uniqueId, status);
+
+ throw DataTypeOperationExceptionSupplier.unexpectedErrorWhileFetchingProperties(uniqueId).get();
+ }
+ final Map<String, PropertyDefinition> propertyMap = propertiesEither.left().value();
+ if (MapUtils.isEmpty(propertyMap)) {
+ return List.of();
+ }
+ final List<PropertyDefinition> propertyDefinitions = new ArrayList<>(propertyMap.values());
+ propertyDefinitions.sort(Comparator.comparing(PropertyDefinition::getName));
+ return propertyDefinitions;
+ }
+
}
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 6b580527c4..9e5c2e49bc 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
@@ -330,13 +330,9 @@ public class PropertyOperation extends AbstractOperation implements IPropertyOpe
List<PropertyConstraint> constraints = propertyDefinition.getConstraints();
propertyDefinition.setUniqueId(UniqueIdBuilder.buildPropertyUniqueId(uniqueId, propertyName));
PropertyData propertyData = new PropertyData(propertyDefinition, convertConstraintsToString(constraints));
- if (log.isDebugEnabled()) {
- log.debug(BEFORE_ADDING_PROPERTY_TO_GRAPH, propertyData);
- }
+ log.debug(BEFORE_ADDING_PROPERTY_TO_GRAPH, propertyData);
Either<PropertyData, JanusGraphOperationStatus> createNodeResult = janusGraphGenericDao.createNode(propertyData, PropertyData.class);
- if (log.isDebugEnabled()) {
- log.debug(AFTER_ADDING_PROPERTY_TO_GRAPH, propertyData);
- }
+ log.debug(AFTER_ADDING_PROPERTY_TO_GRAPH, propertyData);
if (createNodeResult.isRight()) {
JanusGraphOperationStatus operationStatus = createNodeResult.right().value();
log.error("Failed to add property {} to graph. status is {}", propertyName, operationStatus);
@@ -346,8 +342,8 @@ public class PropertyOperation extends AbstractOperation implements IPropertyOpe
props.put(GraphPropertiesDictionary.NAME.getProperty(), propertyName);
UniqueIdData uniqueIdData = new UniqueIdData(nodeType, uniqueId);
log.debug("Before associating {} to property {}", uniqueIdData, propertyName);
- Either<GraphRelation, JanusGraphOperationStatus> createRelResult = janusGraphGenericDao
- .createRelation(uniqueIdData, propertyData, GraphEdgeLabels.PROPERTY, props);
+ Either<GraphRelation, JanusGraphOperationStatus> createRelResult =
+ janusGraphGenericDao.createRelation(uniqueIdData, propertyData, GraphEdgeLabels.PROPERTY, props);
if (createRelResult.isRight()) {
JanusGraphOperationStatus operationStatus = createNodeResult.right().value();
log.error(FAILED_TO_ASSOCIATE_RESOURCE_TO_PROPERTY_IN_GRAPH_STATUS_IS, uniqueId, propertyName, operationStatus);