2 * Copyright © 2016-2018 European Support Limited
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
16 package org.openecomp.sdc.be.dao.titan;
18 import com.thinkaurelius.titan.core.TitanVertex;
19 import fj.data.Either;
20 import java.util.List;
21 import org.apache.commons.lang3.tuple.ImmutablePair;
22 import org.apache.tinkerpop.gremlin.structure.Edge;
23 import org.apache.tinkerpop.gremlin.structure.Vertex;
24 import org.apache.tinkerpop.gremlin.structure.VertexProperty;
25 import org.openecomp.sdc.be.dao.graph.datatype.GraphEdge;
26 import org.openecomp.sdc.be.dao.graph.datatype.GraphNode;
27 import org.openecomp.sdc.be.dao.impl.HealingPipelineDao;
28 import org.openecomp.sdc.be.dao.jsongraph.heal.Heal;
29 import org.openecomp.sdc.be.dao.jsongraph.heal.HealConstants;
30 import org.openecomp.sdc.be.dao.jsongraph.heal.HealVersion;
31 import org.openecomp.sdc.be.dao.jsongraph.heal.HealVersionBuilder;
32 import org.openecomp.sdc.be.dao.neo4j.GraphEdgeLabels;
33 import org.openecomp.sdc.be.datatypes.enums.GraphPropertyEnum;
34 import org.openecomp.sdc.be.datatypes.enums.NodeTypeEnum;
35 import org.springframework.beans.factory.annotation.Autowired;
36 import org.springframework.stereotype.Component;
38 @Component("titan-generic-dao")
39 public class HealingTitanGenericDao extends TitanGenericDao {
42 private HealingPipelineDao healingPipelineDao;
44 public HealingTitanGenericDao(TitanGraphClient titanClient) {
49 public ImmutablePair<TitanVertex, Edge> getChildVertex(TitanVertex childVertex, GraphEdgeLabels edgeType) {
50 ImmutablePair<TitanVertex, Edge> childVertexEdgeImmutablePair = super.getChildVertex(childVertex, edgeType);
51 final TitanVertex graphVertex = childVertexEdgeImmutablePair.left;
52 healingPipelineDao.performGraphReadHealing(graphVertex, edgeType);
53 healingPipelineDao.setHealingVersion(graphVertex);
54 return childVertexEdgeImmutablePair;
58 public <T extends GraphNode> Either<List<ImmutablePair<T, GraphEdge>>, TitanOperationStatus> getChildrenNodes(String key, String uniqueId, GraphEdgeLabels edgeType, NodeTypeEnum nodeTypeEnum, Class<T> clazz, boolean withEdges) {
59 Either<List<ImmutablePair<T, GraphEdge>>, TitanOperationStatus> either = super.getChildrenNodes(key, uniqueId, edgeType, nodeTypeEnum, clazz, withEdges);
60 if (either.isRight()) {
63 List<ImmutablePair<T, GraphEdge>> list = either.left().value();
64 list.forEach(this::transformPair);
69 public <T extends GraphNode> Either<ImmutablePair<T, GraphEdge>, TitanOperationStatus> getChild(String key, String uniqueId, GraphEdgeLabels edgeType, NodeTypeEnum nodeTypeEnum, Class<T> clazz) {
70 Either<ImmutablePair<T, GraphEdge>, TitanOperationStatus> eitherChild = super.getChild(key, uniqueId, edgeType, nodeTypeEnum, clazz);
71 if (eitherChild.isRight()) {
74 ImmutablePair<T, GraphEdge> pair = eitherChild.left().value();
75 GraphNode graphNode = pair.left;
76 GraphEdge graphEdge = pair.right;
77 healingPipelineDao.performGraphReadHealing(graphNode, graphEdge);
78 healingPipelineDao.setHealingVersion(graphNode);
82 private <T extends GraphNode> void transformPair(ImmutablePair<T, GraphEdge> either) {
83 GraphEdge edgeType = either.right;
84 GraphNode childVertex = either.left;
85 Integer healingVersioInt = childVertex.getHealingVersion();
86 HealVersionBuilder.build(healingVersioInt);
87 healingPipelineDao.performGraphReadHealing(childVertex, edgeType);
88 healingPipelineDao.setHealingVersion(childVertex);
92 public Either<List<ImmutablePair<TitanVertex, Edge>>, TitanOperationStatus> getChildrenVertecies(String key, String uniqueId, GraphEdgeLabels edgeType) {
93 Either<List<ImmutablePair<TitanVertex, Edge>>, TitanOperationStatus> either = super.getChildrenVertecies(key, uniqueId, edgeType);
94 if (either.isRight()) {
97 List<ImmutablePair<TitanVertex, Edge>> list = either.left().value();
98 list.forEach(this::transformVertexPair);
102 private void transformVertexPair(ImmutablePair<TitanVertex, Edge> either) {
103 String edgeType = either.right.label();
104 TitanVertex childVertex = either.left;
105 VertexProperty<Integer> healingVersionProperty = childVertex.property(GraphPropertyEnum.HEALING_VERSION.getProperty());
106 Integer healingVersioInt = healingVersionProperty.orElse(HealConstants.DEFAULT_HEAL_VERSION);
107 HealVersionBuilder.build(healingVersioInt);
108 healingPipelineDao.performGraphReadHealing(childVertex, edgeType);
109 healingPipelineDao.setHealingVersion(childVertex);
113 public <T extends GraphNode> Either<T, TitanOperationStatus> updateNode(GraphNode node, Class<T> clazz) {
114 healingPipelineDao.setHealingVersion(node);
115 return super.updateNode(node, clazz);
119 public TitanOperationStatus updateVertex(GraphNode node, Vertex vertex) {
120 healingPipelineDao.setHealingVersion(node);
121 return super.updateVertex(node, vertex);
125 public void setHealingPipelineDao(HealingPipelineDao healingPipelineDao) {
126 this.healingPipelineDao = healingPipelineDao;