aboutsummaryrefslogtreecommitdiffstats
path: root/catalog-model/src/main/java/org
diff options
context:
space:
mode:
authorvasraz <vasyl.razinkov@est.tech>2022-10-03 13:34:10 +0100
committerMichael Morris <michael.morris@est.tech>2022-10-05 08:17:59 +0000
commit404bfc9c50e95df1e75dbf8325fae41bfd96871a (patch)
tree3a957dd7d8e541235d8f88bd2a131b308a4f24de /catalog-model/src/main/java/org
parent0899720f168c09d037e577109d7cab665fe1fb91 (diff)
Implement API for fetching single data type
Signed-off-by: Vasyl Razinkov <vasyl.razinkov@est.tech> Change-Id: Icebf660d67d503250e4f6d4d7fd5a2e169cdc951 Issue-ID: SDC-4184
Diffstat (limited to 'catalog-model/src/main/java/org')
-rw-r--r--catalog-model/src/main/java/org/openecomp/sdc/be/model/operations/impl/CapabilityTypeOperation.java31
-rw-r--r--catalog-model/src/main/java/org/openecomp/sdc/be/model/operations/impl/DataTypeOperation.java42
2 files changed, 48 insertions, 25 deletions
diff --git a/catalog-model/src/main/java/org/openecomp/sdc/be/model/operations/impl/CapabilityTypeOperation.java b/catalog-model/src/main/java/org/openecomp/sdc/be/model/operations/impl/CapabilityTypeOperation.java
index f4073baa3d..ff4dc0aabd 100644
--- a/catalog-model/src/main/java/org/openecomp/sdc/be/model/operations/impl/CapabilityTypeOperation.java
+++ b/catalog-model/src/main/java/org/openecomp/sdc/be/model/operations/impl/CapabilityTypeOperation.java
@@ -114,10 +114,12 @@ public class CapabilityTypeOperation extends AbstractOperation implements ICapab
public Either<CapabilityTypeDefinition, StorageOperationStatus> validateUpdateProperties(CapabilityTypeDefinition capabilityTypeDefinition) {
JanusGraphOperationStatus error = null;
if (MapUtils.isNotEmpty(capabilityTypeDefinition.getProperties()) && capabilityTypeDefinition.getDerivedFrom() != null) {
- final Either<CapabilityTypeData, JanusGraphOperationStatus> derivedFromNode = janusGraphGenericDao.getNode(GraphPropertiesDictionary.TYPE.getProperty(),
+ final Either<CapabilityTypeData, JanusGraphOperationStatus> derivedFromNode = janusGraphGenericDao.getNode(
+ GraphPropertiesDictionary.TYPE.getProperty(),
capabilityTypeDefinition.getDerivedFrom(), CapabilityTypeData.class, capabilityTypeDefinition.getModel());
if (derivedFromNode.isRight()) {
- log.error(BUSINESS_PROCESS_ERROR, "Failed to find the derived from type for {}. status is {}", capabilityTypeDefinition.getType(), derivedFromNode.right().value());
+ log.error(BUSINESS_PROCESS_ERROR, "Failed to find the derived from type for {}. status is {}", capabilityTypeDefinition.getType(),
+ derivedFromNode.right().value());
return Either.right(DaoStatusConverter.convertJanusGraphStatusToStorageStatus(derivedFromNode.right().value()));
}
Either<Map<String, PropertyDefinition>, JanusGraphOperationStatus> allPropertiesRes = getAllCapabilityTypePropertiesFromAllDerivedFrom(
@@ -178,15 +180,15 @@ public class CapabilityTypeOperation extends AbstractOperation implements ICapab
log.error("Failed add properties {} to capability {}", propertiesMap, capabilityTypeDefinition.getType());
return Either.right(DaoStatusConverter.convertJanusGraphStatusToStorageStatus(addPropertiesToCapablityType.right().value()));
}
-
+
final Either<GraphRelation, StorageOperationStatus> modelRelationship = addCapabilityTypeToModel(capabilityTypeDefinition);
if (modelRelationship.isRight()) {
return Either.right(modelRelationship.right().value());
- }
-
+ }
+
return addDerivedFromRelation(capabilityTypeDefinition, ctUniqueId).left().map(updatedDerivedFrom -> createCTResult.left().value());
}
-
+
private Either<GraphRelation, StorageOperationStatus> addCapabilityTypeToModel(final CapabilityTypeDefinition capabilityTypeDefinition) {
final String model = capabilityTypeDefinition.getModel();
if (model == null) {
@@ -195,7 +197,8 @@ public class CapabilityTypeOperation extends AbstractOperation implements ICapab
final GraphNode from = new UniqueIdData(NodeTypeEnum.Model, UniqueIdBuilder.buildModelUid(model));
final GraphNode to = new UniqueIdData(NodeTypeEnum.CapabilityType, capabilityTypeDefinition.getUniqueId());
log.info("Connecting model {} to type {}", from, to);
- return janusGraphGenericDao.createRelation(from , to, GraphEdgeLabels.MODEL_ELEMENT, Collections.emptyMap()).right().map(DaoStatusConverter::convertJanusGraphStatusToStorageStatus);
+ return janusGraphGenericDao.createRelation(from, to, GraphEdgeLabels.MODEL_ELEMENT, Collections.emptyMap()).right()
+ .map(DaoStatusConverter::convertJanusGraphStatusToStorageStatus);
}
private CapabilityTypeData buildCapabilityTypeData(CapabilityTypeDefinition capabilityTypeDefinition, String ctUniqueId) {
@@ -237,7 +240,7 @@ public class CapabilityTypeOperation extends AbstractOperation implements ICapab
// Optimization: In case of Capability Type its unique ID is the same as type
return getCapabilityTypeByUid(capabilityType);
}
-
+
public Either<CapabilityTypeDefinition, JanusGraphOperationStatus> getCapabilityTypeByType(final String capabilityType, final String model) {
final Either<CapabilityTypeData, JanusGraphOperationStatus> capabilityTypesRes = janusGraphGenericDao
.getNode(GraphPropertiesDictionary.TYPE.getProperty(), capabilityType, CapabilityTypeData.class, model);
@@ -256,7 +259,6 @@ public class CapabilityTypeOperation extends AbstractOperation implements ICapab
* @return
*/
public Either<CapabilityTypeDefinition, JanusGraphOperationStatus> getCapabilityTypeByUid(String uniqueId) {
- Either<CapabilityTypeDefinition, JanusGraphOperationStatus> result = null;
Either<CapabilityTypeData, JanusGraphOperationStatus> capabilityTypesRes = janusGraphGenericDao
.getNode(UniqueIdBuilder.getKeyByNodeType(NodeTypeEnum.CapabilityType), uniqueId, CapabilityTypeData.class);
if (capabilityTypesRes.isRight()) {
@@ -266,7 +268,7 @@ public class CapabilityTypeOperation extends AbstractOperation implements ICapab
}
return getCapabilityTypeDefinition(capabilityTypesRes.left().value());
}
-
+
private Either<CapabilityTypeDefinition, JanusGraphOperationStatus> getCapabilityTypeDefinition(final CapabilityTypeData ctData) {
CapabilityTypeDefinition capabilityTypeDefinition = new CapabilityTypeDefinition(ctData.getCapabilityTypeDataDefinition());
Either<Map<String, PropertyDefinition>, JanusGraphOperationStatus> propertiesStatus = OperationUtils
@@ -285,7 +287,8 @@ public class CapabilityTypeOperation extends AbstractOperation implements ICapab
if (parentNode.isRight()) {
JanusGraphOperationStatus janusGraphOperationStatus = parentNode.right().value();
if (janusGraphOperationStatus != JanusGraphOperationStatus.NOT_FOUND) {
- log.error(BUSINESS_PROCESS_ERROR, "Failed to find the parent capability of capability type {}. status is {}", ctData.getUniqueId(), janusGraphOperationStatus);
+ log.error(BUSINESS_PROCESS_ERROR, "Failed to find the parent capability of capability type {}. status is {}", ctData.getUniqueId(),
+ janusGraphOperationStatus);
return Either.right(janusGraphOperationStatus);
}
} else {
@@ -294,14 +297,14 @@ public class CapabilityTypeOperation extends AbstractOperation implements ICapab
CapabilityTypeData parentCT = immutablePair.getKey();
capabilityTypeDefinition.setDerivedFrom(parentCT.getCapabilityTypeDataDefinition().getType());
}
-
+
final Either<ImmutablePair<ModelData, GraphEdge>, JanusGraphOperationStatus> model = janusGraphGenericDao.getParentNode(
- UniqueIdBuilder.getKeyByNodeType(NodeTypeEnum.CapabilityType), ctData.getUniqueId(), GraphEdgeLabels.MODEL_ELEMENT,
+ UniqueIdBuilder.getKeyByNodeType(NodeTypeEnum.CapabilityType), ctData.getUniqueId(), GraphEdgeLabels.MODEL_ELEMENT,
NodeTypeEnum.Model, ModelData.class);
if (model.isLeft()) {
capabilityTypeDefinition.setModel(model.left().value().getLeft().getName());
}
-
+
return Either.left(capabilityTypeDefinition);
}
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 a0963c9030..f75e3cfb17 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
@@ -24,17 +24,22 @@ import java.util.Collections;
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.tinkerpop.gremlin.process.traversal.dsl.graph.GraphTraversalSource;
import org.apache.tinkerpop.gremlin.structure.Vertex;
import org.janusgraph.core.JanusGraph;
import org.openecomp.sdc.be.config.BeEcompErrorManager;
import org.openecomp.sdc.be.config.BeEcompErrorManager.ErrorSeverity;
+import org.openecomp.sdc.be.dao.api.ActionStatus;
import org.openecomp.sdc.be.dao.janusgraph.HealingJanusGraphGenericDao;
import org.openecomp.sdc.be.dao.janusgraph.JanusGraphOperationStatus;
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.model.jsonjanusgraph.operations.exception.OperationException;
+import org.openecomp.sdc.be.model.operations.api.StorageOperationStatus;
import org.openecomp.sdc.be.resources.data.DataTypeData;
import org.openecomp.sdc.common.log.enums.EcompLoggerErrorCode;
import org.slf4j.Logger;
@@ -71,38 +76,38 @@ public class DataTypeOperation extends AbstractOperation {
}
final List<DataTypeData> allDataTypeNodesWithModel = getAllDataTypesWithModel();
- if(CollectionUtils.isNotEmpty(allDataTypeNodesWithModel)) {
+ if (CollectionUtils.isNotEmpty(allDataTypeNodesWithModel)) {
dataTypesFound.addAll(allDataTypeNodesWithModel);
}
return dataTypesFound;
}
-
+
public Map<String, List<String>> getAllDataTypeUidsToModels() {
final Map<String, List<String>> dataTypesFound = new HashMap<>();
final Either<List<DataTypeData>, JanusGraphOperationStatus> getAllDataTypesWithNullModel =
janusGraphGenericDao.getByCriteria(NodeTypeEnum.DataType, null, DataTypeData.class);
final var dataTypesValidated = validateDataType(getAllDataTypesWithNullModel, null);
-
- for (DataTypeData dataType: dataTypesValidated) {
- if (!dataTypesFound.containsKey(dataType.getUniqueId())){
+
+ for (DataTypeData dataType : dataTypesValidated) {
+ if (!dataTypesFound.containsKey(dataType.getUniqueId())) {
dataTypesFound.put(dataType.getUniqueId(), new ArrayList<>());
}
dataTypesFound.get(dataType.getUniqueId()).add(null);
}
-
+
modelOperation.findAllModels()
.forEach(model -> {
- for (DataTypeData dataType: getAllDataTypesWithModel(model.getName())) {
- if (!dataTypesFound.containsKey(dataType.getUniqueId())){
+ for (DataTypeData dataType : getAllDataTypesWithModel(model.getName())) {
+ if (!dataTypesFound.containsKey(dataType.getUniqueId())) {
dataTypesFound.put(dataType.getUniqueId(), new ArrayList<>());
}
dataTypesFound.get(dataType.getUniqueId()).add(model.getName());
}
- });
+ });
return dataTypesFound;
}
-
+
private List<DataTypeData> getAllDataTypesWithModel(final String modelName) {
final Either<List<DataTypeData>, JanusGraphOperationStatus> getAllDataTypesByModel = janusGraphGenericDao
.getByCriteriaForModel(NodeTypeEnum.DataType, null, modelName, DataTypeData.class);
@@ -129,7 +134,7 @@ public class DataTypeOperation extends AbstractOperation {
if (getDataTypes.isRight()) {
final var status = getDataTypes.right().value();
if (LOGGER.isErrorEnabled()) {
- final var errorMsg= String.format("Failed to fetch data types from database with model %s. Status is %s", modelName, status);
+ final var errorMsg = String.format("Failed to fetch data types from database with model %s. Status is %s", modelName, status);
LOGGER.error(String.valueOf(EcompLoggerErrorCode.UNKNOWN_ERROR), DataTypeOperation.class.getName(), errorMsg);
BeEcompErrorManager.getInstance().logInternalConnectionError(DataTypeOperation.class.getName(), errorMsg, ErrorSeverity.ERROR);
}
@@ -152,4 +157,19 @@ public class DataTypeOperation extends AbstractOperation {
});
}
+ public Optional<DataTypeDataDefinition> getDataTypeByUid(final String uniqueId) {
+ final Either<DataTypeData, JanusGraphOperationStatus> dataTypeEither = janusGraphGenericDao
+ .getNode(UniqueIdBuilder.getKeyByNodeType(NodeTypeEnum.DataType), uniqueId, DataTypeData.class);
+ if (dataTypeEither.isRight()) {
+ if (JanusGraphOperationStatus.NOT_FOUND.equals(dataTypeEither.right().value())) {
+ return Optional.empty();
+ }
+ final StorageOperationStatus storageOperationStatus
+ = DaoStatusConverter.convertJanusGraphStatusToStorageStatus(dataTypeEither.right().value());
+ LOGGER.warn("Failed to fetch data type '{}' from JanusGraph. Status is: {}", uniqueId, storageOperationStatus);
+ throw new OperationException(ActionStatus.GENERAL_ERROR,
+ String.format("Failed to fetch data type '%s' from JanusGraph. Status is: %s", uniqueId, storageOperationStatus));
+ }
+ return Optional.of(dataTypeEither.left().value().getDataTypeDataDefinition());
+ }
}