diff options
Diffstat (limited to 'catalog-dao')
5 files changed, 60 insertions, 15 deletions
diff --git a/catalog-dao/src/main/java/org/openecomp/sdc/be/dao/api/ActionStatus.java b/catalog-dao/src/main/java/org/openecomp/sdc/be/dao/api/ActionStatus.java index 66399a49f7..4465997c4a 100644 --- a/catalog-dao/src/main/java/org/openecomp/sdc/be/dao/api/ActionStatus.java +++ b/catalog-dao/src/main/java/org/openecomp/sdc/be/dao/api/ActionStatus.java @@ -54,6 +54,7 @@ public enum ActionStatus { // Model related MODEL_ALREADY_EXISTS, INVALID_MODEL, MODEL_IMPORTS_IS_EMPTY, COULD_NOT_READ_MODEL_IMPORTS, MODEL_NOT_FOUND, MODEL_NAME_CANNOT_BE_EMPTY, COMPONENT_WITH_MODEL_ALREADY_EXIST, COMPONENT_WITH_VENDOR_RELEASE_ALREADY_EXISTS, COMPONENT_WITH_VENDOR_RELEASE_ALREADY_EXISTS_IN_MODEL, + UNKNOWN_MODEL_TYPE, // Service API URL INVALID_SERVICE_API_URL, // Property related diff --git a/catalog-dao/src/main/java/org/openecomp/sdc/be/dao/janusgraph/JanusGraphDao.java b/catalog-dao/src/main/java/org/openecomp/sdc/be/dao/janusgraph/JanusGraphDao.java index 5d0c4cffb6..449a4968e8 100644 --- a/catalog-dao/src/main/java/org/openecomp/sdc/be/dao/janusgraph/JanusGraphDao.java +++ b/catalog-dao/src/main/java/org/openecomp/sdc/be/dao/janusgraph/JanusGraphDao.java @@ -58,6 +58,7 @@ import org.openecomp.sdc.be.dao.jsongraph.utils.JsonParserUtils; import org.openecomp.sdc.be.dao.neo4j.GraphEdgeLabels; import org.openecomp.sdc.be.datatypes.enums.ComponentTypeEnum; import org.openecomp.sdc.be.datatypes.enums.GraphPropertyEnum; +import org.openecomp.sdc.be.datatypes.enums.ModelTypeEnum; import org.openecomp.sdc.be.datatypes.tosca.ToscaDataDefinition; import org.openecomp.sdc.common.jsongraph.util.CommonUtility; import org.openecomp.sdc.common.jsongraph.util.CommonUtility.LogLevelEnum; @@ -442,12 +443,29 @@ public class JanusGraphDao { return Either.right(graph.right().value()); } } + + public Either<List<GraphVertex>, JanusGraphOperationStatus> getByCriteria(final VertexTypeEnum type, final Map<GraphPropertyEnum, Object> props, + final Map<GraphPropertyEnum, Object> hasNotProps, + final JsonParseFlagEnum parseFlag, + final String model) { + return getByCriteria(type, props, hasNotProps, null, parseFlag, model, false); + } - public Either<List<GraphVertex>, JanusGraphOperationStatus> getByCriteria(VertexTypeEnum type, Map<GraphPropertyEnum, Object> props, - Map<GraphPropertyEnum, Object> hasNotProps, - JsonParseFlagEnum parseFlag, - String model) { - return getByCriteria(type, props, hasNotProps, null, parseFlag, model); + public Either<List<GraphVertex>, JanusGraphOperationStatus> getByCriteria(final VertexTypeEnum type, final Map<GraphPropertyEnum, Object> props, + final Map<GraphPropertyEnum, Object> hasNotProps, + final JsonParseFlagEnum parseFlag, + final String model, + final boolean includeNormativeExtensionModels) { + return getByCriteria(type, props, hasNotProps, null, parseFlag, model, includeNormativeExtensionModels); + } + + public Either<List<GraphVertex>, JanusGraphOperationStatus> getByCriteria(final VertexTypeEnum type, + final Map<GraphPropertyEnum, Object> hasProps, + final Map<GraphPropertyEnum, Object> hasNotProps, + final Map<String, Entry<JanusGraphPredicate, Object>> predicates, + final JsonParseFlagEnum parseFlag, + final String model) { + return getByCriteria(type, hasProps, hasNotProps, predicates, parseFlag, model, false); } public Either<List<GraphVertex>, JanusGraphOperationStatus> getByCriteria(final VertexTypeEnum type, @@ -455,7 +473,8 @@ public class JanusGraphDao { final Map<GraphPropertyEnum, Object> hasNotProps, final Map<String, Entry<JanusGraphPredicate, Object>> predicates, final JsonParseFlagEnum parseFlag, - final String model) { + final String model, + final boolean includeNormativeExtensionModels) { Either<JanusGraph, JanusGraphOperationStatus> graph = janusGraphClient.getGraph(); if (graph.isLeft()) { try { @@ -492,7 +511,7 @@ public class JanusGraphDao { } List<GraphVertex> result = new ArrayList<>(); - final Predicate<? super JanusGraphVertex> filterPredicate = StringUtils.isEmpty(model) ? this::vertexNotConnectedToAnyModel : vertex -> vertexValidForModel(vertex, model); + final Predicate<? super JanusGraphVertex> filterPredicate = StringUtils.isEmpty(model) ? this::vertexNotConnectedToAnyModel : vertex -> vertexValidForModel(vertex, model, includeNormativeExtensionModels); final List<JanusGraphVertex> verticesForModel = StreamSupport.stream(vertices.spliterator(), false).filter(filterPredicate).collect(Collectors.toList()); if (verticesForModel == null || verticesForModel.size() == 0) { return Either.right(JanusGraphOperationStatus.NOT_FOUND); @@ -585,22 +604,35 @@ public class JanusGraphDao { } } - private boolean vertexValidForModel(final JanusGraphVertex vertex, final String model) { + private boolean vertexValidForModel(final JanusGraphVertex vertex, final String model, final boolean includeNormativeExtensions) { final String vertexLabel = (String)vertex.property(GraphPropertyEnum.LABEL.getProperty()).value(); final VertexTypeEnum vertexType = VertexTypeEnum.getByName(vertexLabel); final GraphEdgeLabels edgeLabel = vertexType.equals(VertexTypeEnum.TOPOLOGY_TEMPLATE) ? GraphEdgeLabels.MODEL : GraphEdgeLabels.MODEL_ELEMENT; final Either<List<ImmutablePair<JanusGraphVertex, Edge>>, JanusGraphOperationStatus> modelVertices = getParentVerticies(vertex, edgeLabel); - return modelVertices.isLeft() && modelVertices.left().value().stream().anyMatch(vertexPair -> modelVertexMatchesModel(vertexPair.getLeft(), model)); + return modelVertices.isLeft() && modelVertices.left().value().stream().anyMatch(vertexPair -> modelVertexMatchesModel(vertexPair.getLeft(), model, includeNormativeExtensions)); } - private boolean modelVertexMatchesModel(final JanusGraphVertex modelVertex, final String model) { + private boolean modelVertexMatchesModel(final JanusGraphVertex modelVertex, final String model, final boolean includeNormativeExtensions) { if (model.equals((String)modelVertex.property("name").value())) { return true; } final Either<List<ImmutablePair<JanusGraphVertex, Edge>>, JanusGraphOperationStatus> derivedModels = getParentVerticies(modelVertex, GraphEdgeLabels.DERIVED_FROM); - return derivedModels.isLeft() && derivedModels.left().value().stream().anyMatch(derivedModel ->modelVertexMatchesModel(derivedModel.left, model)); + if (derivedModels.isLeft() && derivedModels.left().value().stream().anyMatch(derivedModel ->modelVertexMatchesModel(derivedModel.left, model, includeNormativeExtensions))) { + return true; + } + + if (includeNormativeExtensions && isANormativeExtension(modelVertex)) { + final Either<List<Vertex>,JanusGraphOperationStatus> derivedFromModels = + getChildrenVertices(modelVertex, EdgeLabelEnum.DERIVED_FROM, JsonParseFlagEnum.ParseAll); + return derivedFromModels.isLeft() && derivedFromModels.left().value().stream().anyMatch(derivedFromModel -> model.equals((String)derivedFromModel.property("name").value())); + } + return false; + } + + private boolean isANormativeExtension(final JanusGraphVertex modelVertex) { + return ModelTypeEnum.NORMATIVE_EXTENSION.getValue().equals((String)modelVertex.property(GraphPropertyEnum.MODEL_TYPE.getProperty()).value()); } private Either<List<ImmutablePair<JanusGraphVertex, Edge>>, JanusGraphOperationStatus> getParentVerticies( diff --git a/catalog-dao/src/main/java/org/openecomp/sdc/be/dao/neo4j/GraphPropertiesDictionary.java b/catalog-dao/src/main/java/org/openecomp/sdc/be/dao/neo4j/GraphPropertiesDictionary.java index cbfee5e799..03016f793f 100644 --- a/catalog-dao/src/main/java/org/openecomp/sdc/be/dao/neo4j/GraphPropertiesDictionary.java +++ b/catalog-dao/src/main/java/org/openecomp/sdc/be/dao/neo4j/GraphPropertiesDictionary.java @@ -50,7 +50,8 @@ public enum GraphPropertiesDictionary { CONTACT_ID ("contactId", String.class, false, false), VENDOR_NAME ("vendorName", String.class, false, false), VENDOR_RELEASE ("vendorRelease", String.class, false, false), - MODEL ("model", String.class, false, false), + MODEL ("model", String.class, false, false), + MODEL_TYPE ("modelType", String.class, false, false), CONFORMANCE_LEVEL ("conformanceLevel", String.class, false, false), ICON ("icon", String.class, false, false), TAGS ("tags", String.class, false, false), diff --git a/catalog-dao/src/main/java/org/openecomp/sdc/be/resources/data/ModelData.java b/catalog-dao/src/main/java/org/openecomp/sdc/be/resources/data/ModelData.java index 026b1d7998..5f7b15e043 100644 --- a/catalog-dao/src/main/java/org/openecomp/sdc/be/resources/data/ModelData.java +++ b/catalog-dao/src/main/java/org/openecomp/sdc/be/resources/data/ModelData.java @@ -23,6 +23,7 @@ import java.util.Map; import lombok.Getter; import org.openecomp.sdc.be.dao.graph.datatype.GraphNode; import org.openecomp.sdc.be.dao.neo4j.GraphPropertiesDictionary; +import org.openecomp.sdc.be.datatypes.enums.ModelTypeEnum; import org.openecomp.sdc.be.datatypes.enums.NodeTypeEnum; @Getter @@ -30,17 +31,20 @@ public class ModelData extends GraphNode { private final String name; private final String uniqueId; + private final String modelType; - public ModelData(final String name, final String uniqueId) { + public ModelData(final String name, final String uniqueId, final ModelTypeEnum modelType) { super(NodeTypeEnum.Model); this.name = name; this.uniqueId = uniqueId; + this.modelType = modelType.getValue(); } public ModelData(final Map<String, Object> properties) { super(NodeTypeEnum.Model); name = (String) properties.get(GraphPropertiesDictionary.NAME.getProperty()); uniqueId = (String) properties.get(GraphPropertiesDictionary.UNIQUE_ID.getProperty()); + modelType = (String) properties.get(GraphPropertiesDictionary.MODEL_TYPE.getProperty()); } @Override @@ -48,6 +52,7 @@ public class ModelData extends GraphNode { final Map<String, Object> map = new HashMap<>(); addIfExists(map, GraphPropertiesDictionary.NAME, name); addIfExists(map, GraphPropertiesDictionary.UNIQUE_ID, uniqueId); + addIfExists(map, GraphPropertiesDictionary.MODEL_TYPE, modelType); return map; } diff --git a/catalog-dao/src/test/java/org/openecomp/sdc/be/resources/data/ModelDataTest.java b/catalog-dao/src/test/java/org/openecomp/sdc/be/resources/data/ModelDataTest.java index 1fb34dd5e6..f011e36509 100644 --- a/catalog-dao/src/test/java/org/openecomp/sdc/be/resources/data/ModelDataTest.java +++ b/catalog-dao/src/test/java/org/openecomp/sdc/be/resources/data/ModelDataTest.java @@ -27,17 +27,19 @@ import org.junit.jupiter.api.BeforeAll; import org.junit.jupiter.api.Test; import org.junit.jupiter.api.TestInstance; import org.junit.jupiter.api.TestInstance.Lifecycle; +import org.openecomp.sdc.be.datatypes.enums.ModelTypeEnum; @TestInstance(Lifecycle.PER_CLASS) class ModelDataTest { private final String modelName = "ETSI-SDC-MODEL-TEST"; private final String modelId = UUID.randomUUID().toString(); + private final ModelTypeEnum modelType = ModelTypeEnum.NORMATIVE; ModelData modelData; @BeforeAll void initTestData() { - modelData = new ModelData(modelName, modelId); + modelData = new ModelData(modelName, modelId, modelType); } @Test @@ -45,17 +47,20 @@ class ModelDataTest { assertThat(modelData).isNotNull(); assertThat(modelData.getUniqueId()).isEqualTo(modelId); assertThat(modelData.getName()).isEqualTo(modelName); + assertThat(modelData.getModelType()).isEqualTo(modelType.getValue()); } @Test void modelDataFromPropertiesMapTest() { - final Map<String, Object> properties = new HashMap(); + final Map<String, Object> properties = new HashMap<>(); properties.put("name", modelData.getName()); properties.put("uid", modelData.getUniqueId()); + properties.put("modelType", modelData.getModelType()); final ModelData modelDataFromPropertiesMap = new ModelData(properties); assertThat(modelDataFromPropertiesMap).isNotNull(); assertThat(modelDataFromPropertiesMap.getUniqueId()).isEqualTo(modelId); assertThat(modelDataFromPropertiesMap.getName()).isEqualTo(modelName); + assertThat(modelDataFromPropertiesMap.getModelType()).isEqualTo(modelType.getValue()); } @Test @@ -65,6 +70,7 @@ class ModelDataTest { assertThat(result).isNotEmpty(); assertThat(result.values()).contains(modelId); assertThat(result.values()).contains(modelName); + assertThat(result.values()).contains(modelType.getValue()); } } |