diff options
Diffstat (limited to 'catalog-dao/src/main/java/org/openecomp/sdc/be/dao/titan')
3 files changed, 52 insertions, 21 deletions
diff --git a/catalog-dao/src/main/java/org/openecomp/sdc/be/dao/titan/TitanGenericDao.java b/catalog-dao/src/main/java/org/openecomp/sdc/be/dao/titan/TitanGenericDao.java index 8bd190f932..1db807fa0e 100644 --- a/catalog-dao/src/main/java/org/openecomp/sdc/be/dao/titan/TitanGenericDao.java +++ b/catalog-dao/src/main/java/org/openecomp/sdc/be/dao/titan/TitanGenericDao.java @@ -20,15 +20,14 @@ package org.openecomp.sdc.be.dao.titan; -import java.util.ArrayList; -import java.util.HashMap; -import java.util.Iterator; -import java.util.List; -import java.util.Map; -import java.util.Map.Entry; -import java.util.stream.Collectors; -import java.util.stream.StreamSupport; - +import com.thinkaurelius.titan.core.PropertyKey; +import com.thinkaurelius.titan.core.TitanEdge; +import com.thinkaurelius.titan.core.TitanGraph; +import com.thinkaurelius.titan.core.TitanGraphQuery; +import com.thinkaurelius.titan.core.TitanVertex; +import com.thinkaurelius.titan.core.TitanVertexQuery; +import com.thinkaurelius.titan.graphdb.query.TitanPredicate; +import fj.data.Either; import org.apache.commons.lang3.tuple.ImmutablePair; import org.apache.commons.lang3.tuple.ImmutableTriple; import org.apache.tinkerpop.gremlin.structure.Direction; @@ -52,15 +51,14 @@ import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.stereotype.Component; -import com.thinkaurelius.titan.core.PropertyKey; -import com.thinkaurelius.titan.core.TitanEdge; -import com.thinkaurelius.titan.core.TitanGraph; -import com.thinkaurelius.titan.core.TitanGraphQuery; -import com.thinkaurelius.titan.core.TitanVertex; -import com.thinkaurelius.titan.core.TitanVertexQuery; -import com.thinkaurelius.titan.graphdb.query.TitanPredicate; - -import fj.data.Either; +import java.util.ArrayList; +import java.util.HashMap; +import java.util.Iterator; +import java.util.List; +import java.util.Map; +import java.util.Map.Entry; +import java.util.stream.Collectors; +import java.util.stream.StreamSupport; @Component("titan-generic-dao") public class TitanGenericDao { @@ -908,7 +906,7 @@ public class TitanGenericDao { return true; } - public <T extends GraphNode> Either<List<T>, TitanOperationStatus> getByCriteriaWithPradicat(NodeTypeEnum type, Map<String, Entry<TitanPredicate, Object>> props, Class<T> clazz) { + public <T extends GraphNode> Either<List<T>, TitanOperationStatus> getByCriteriaWithPredicate(NodeTypeEnum type, Map<String, Entry<TitanPredicate, Object>> props, Class<T> clazz) { Either<TitanGraph, TitanOperationStatus> graph = titanClient.getGraph(); if (graph.isLeft()) { try { @@ -1111,6 +1109,14 @@ public class TitanGenericDao { } + public Either<Boolean, TitanOperationStatus> isRelationExist(GraphNode from, GraphNode to, GraphEdgeLabels edgeLabel) { + return getEdgeByNodes(from, to, edgeLabel) + .left() + .map(edge -> true) + .right() + .bind(err -> err == TitanOperationStatus.NOT_FOUND ? Either.left(false): Either.right(err)); + } + public Either<GraphRelation, TitanOperationStatus> deleteRelation(GraphNode from, GraphNode to, GraphEdgeLabels label) { logger.debug("try to delete relation from [{}] to [{}]", from.getKeyValueId(), to.getKeyValueId()); return deleteEdge(label.getProperty(), from.getKeyValueId(), to.getKeyValueId(), from.getLabel(), to.getLabel()); diff --git a/catalog-dao/src/main/java/org/openecomp/sdc/be/dao/titan/TitanGraphClient.java b/catalog-dao/src/main/java/org/openecomp/sdc/be/dao/titan/TitanGraphClient.java index edcf70f093..7d151f1a3e 100644 --- a/catalog-dao/src/main/java/org/openecomp/sdc/be/dao/titan/TitanGraphClient.java +++ b/catalog-dao/src/main/java/org/openecomp/sdc/be/dao/titan/TitanGraphClient.java @@ -392,10 +392,8 @@ public class TitanGraphClient { private void logAlarm() { if (lastHealthState == true) { - BeEcompErrorManager.getInstance().processEcompError(EcompErrorName.BeHealthCheckRecovery, TITAN_HEALTH_CHECK_STR); BeEcompErrorManager.getInstance().logBeHealthCheckTitanRecovery(TITAN_HEALTH_CHECK_STR); } else { - BeEcompErrorManager.getInstance().processEcompError(EcompErrorName.BeHealthCheckError, TITAN_HEALTH_CHECK_STR); BeEcompErrorManager.getInstance().logBeHealthCheckTitanError(TITAN_HEALTH_CHECK_STR); } } diff --git a/catalog-dao/src/main/java/org/openecomp/sdc/be/dao/titan/TitanUtils.java b/catalog-dao/src/main/java/org/openecomp/sdc/be/dao/titan/TitanUtils.java new file mode 100644 index 0000000000..163ef807fb --- /dev/null +++ b/catalog-dao/src/main/java/org/openecomp/sdc/be/dao/titan/TitanUtils.java @@ -0,0 +1,27 @@ +package org.openecomp.sdc.be.dao.titan; + +import com.thinkaurelius.titan.graphdb.query.TitanPredicate; + +import java.util.Collection; +import java.util.HashMap; +import java.util.Map; +import java.util.Map.Entry; + +import static com.thinkaurelius.titan.core.attribute.Contain.NOT_IN; +import static java.util.Collections.emptyMap; +import static org.apache.commons.collections.CollectionUtils.isEmpty; + +public class TitanUtils { + + private TitanUtils() { + } + + public static <T> Map<String, Entry<TitanPredicate, Object>> buildNotInPredicate(String propKey, Collection<T> notInCollection) { + if (isEmpty(notInCollection)) { + return emptyMap(); + } + Map<String, Entry<TitanPredicate, Object>> predicateCriteria = new HashMap<>(); + predicateCriteria.put(propKey, new HashMap.SimpleEntry<>(NOT_IN, notInCollection)); + return predicateCriteria; + } +} |