diff options
author | MichaelMorris <michael.morris@est.tech> | 2021-08-20 15:40:35 +0100 |
---|---|---|
committer | Andr� Schmid <andre.schmid@est.tech> | 2021-08-27 10:33:32 +0000 |
commit | a5e32b3d20bc078482cb08645c38ffb685c0f145 (patch) | |
tree | 133fe88578f3a3c3db3ec73315b65f45caba625a /catalog-dao/src/main/java | |
parent | 4701612ba26c4b8c7c7e9fbfa38f582a4b74669f (diff) |
Support querying of model by type
Signed-off-by: MichaelMorris <michael.morris@est.tech>
Issue-ID: SDC-3678
Change-Id: I5fd19eefe475113df501901628b2ee8669004399
Diffstat (limited to 'catalog-dao/src/main/java')
4 files changed, 52 insertions, 13 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; } |