X-Git-Url: https://gerrit.onap.org/r/gitweb?a=blobdiff_plain;f=catalog-dao%2Fsrc%2Fmain%2Fjava%2Forg%2Fopenecomp%2Fsdc%2Fbe%2Fdao%2Fjanusgraph%2FJanusGraphDao.java;h=ed6999271501345702300e5f9b867e70ac156c8b;hb=cee79dd87db512691b7f3fde339635a1ca8632e7;hp=449a4968e8c9301fbe8fff1f87ff4a6198c90d6f;hpb=4b7564241a1d9bf322764a905c3e80215a026b15;p=sdc.git 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 449a4968e8..ed69992715 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 @@ -24,6 +24,8 @@ import static org.apache.commons.collections.CollectionUtils.isEmpty; import fj.data.Either; import java.io.IOException; import java.util.ArrayList; +import java.util.Collections; +import java.util.EnumMap; import java.util.HashMap; import java.util.Iterator; import java.util.List; @@ -49,6 +51,7 @@ import org.janusgraph.core.JanusGraphVertex; import org.janusgraph.core.JanusGraphVertexQuery; import org.janusgraph.core.PropertyKey; import org.janusgraph.graphdb.query.JanusGraphPredicate; +import org.openecomp.sdc.be.dao.api.exception.JanusGraphException; import org.openecomp.sdc.be.dao.jsongraph.GraphVertex; import org.openecomp.sdc.be.dao.jsongraph.types.EdgeLabelEnum; import org.openecomp.sdc.be.dao.jsongraph.types.EdgePropertyEnum; @@ -604,6 +607,39 @@ public class JanusGraphDao { } } + + /** + * Finds the vertices that have the given invariant id and any additional property provided. + * + * @param invariantUuid the invariant uuid + * @param additionalPropertiesToMatch any additional property to match along with the {@link GraphPropertyEnum#INVARIANT_UUID} + * @return the list of vertex that has the given invariant uuid + * @throws JanusGraphException if the find operation was returned an error status + */ + public List findAllVertexByInvariantUuid(final String invariantUuid, + final Map additionalPropertiesToMatch) { + final Map propertiesToMatch = new EnumMap<>(GraphPropertyEnum.class); + if (MapUtils.isNotEmpty(additionalPropertiesToMatch)) { + propertiesToMatch.putAll(additionalPropertiesToMatch); + } + propertiesToMatch.put(GraphPropertyEnum.INVARIANT_UUID, invariantUuid); + final Either, JanusGraphOperationStatus> vertexEither = + getByCriteria(null, propertiesToMatch, JsonParseFlagEnum.ParseMetadata); + if (vertexEither.isRight()) { + final JanusGraphOperationStatus status = vertexEither.right().value(); + if (status == JanusGraphOperationStatus.NOT_FOUND) { + return Collections.emptyList(); + } + final String errorMsg = String.format("Couldn't fetch vertex with invariantUUId '%s'. Status was '%s'", invariantUuid, status); + throw new JanusGraphException(status, errorMsg); + } + final List vertices = vertexEither.left().value(); + if (vertices == null || vertices.isEmpty()) { + return Collections.emptyList(); + } + return vertices; + } + 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);