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.janusgraph;
18 import fj.data.Either;
19 import java.util.List;
20 import org.apache.commons.lang3.tuple.ImmutablePair;
21 import org.apache.tinkerpop.gremlin.structure.Edge;
22 import org.apache.tinkerpop.gremlin.structure.Vertex;
23 import org.apache.tinkerpop.gremlin.structure.VertexProperty;
24 import org.janusgraph.core.JanusGraphVertex;
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.HealConstants;
29 import org.openecomp.sdc.be.dao.jsongraph.heal.HealVersionBuilder;
30 import org.openecomp.sdc.be.dao.neo4j.GraphEdgeLabels;
31 import org.openecomp.sdc.be.datatypes.enums.GraphPropertyEnum;
32 import org.openecomp.sdc.be.datatypes.enums.NodeTypeEnum;
33 import org.springframework.beans.factory.annotation.Autowired;
34 import org.springframework.stereotype.Component;
36 @Component("janusgraph-generic-dao")
37 public class HealingJanusGraphGenericDao extends JanusGraphGenericDao {
39 private HealingPipelineDao healingPipelineDao;
42 public HealingJanusGraphGenericDao(JanusGraphClient janusGraphClient) {
43 super(janusGraphClient);
47 public ImmutablePair<JanusGraphVertex, Edge> getChildVertex(JanusGraphVertex childVertex, GraphEdgeLabels edgeType) {
48 ImmutablePair<JanusGraphVertex, Edge> childVertexEdgeImmutablePair = super.getChildVertex(childVertex, edgeType);
49 final JanusGraphVertex graphVertex = childVertexEdgeImmutablePair.left;
50 healingPipelineDao.performGraphReadHealing(graphVertex, edgeType);
51 healingPipelineDao.setHealingVersion(graphVertex);
52 return childVertexEdgeImmutablePair;
56 public <T extends GraphNode> Either<List<ImmutablePair<T, GraphEdge>>, JanusGraphOperationStatus> getChildrenNodes(String key, String uniqueId,
57 GraphEdgeLabels edgeType,
58 NodeTypeEnum nodeTypeEnum,
61 Either<List<ImmutablePair<T, GraphEdge>>, JanusGraphOperationStatus> either = super
62 .getChildrenNodes(key, uniqueId, edgeType, nodeTypeEnum, clazz, withEdges);
63 if (either.isRight()) {
66 List<ImmutablePair<T, GraphEdge>> list = either.left().value();
67 list.forEach(this::transformPair);
72 public <T extends GraphNode> Either<ImmutablePair<T, GraphEdge>, JanusGraphOperationStatus> getChild(String key, String uniqueId,
73 GraphEdgeLabels edgeType,
74 NodeTypeEnum nodeTypeEnum, Class<T> clazz) {
75 Either<ImmutablePair<T, GraphEdge>, JanusGraphOperationStatus> eitherChild = super.getChild(key, uniqueId, edgeType, nodeTypeEnum, clazz);
76 if (eitherChild.isRight()) {
79 ImmutablePair<T, GraphEdge> pair = eitherChild.left().value();
80 GraphNode graphNode = pair.left;
81 GraphEdge graphEdge = pair.right;
82 healingPipelineDao.performGraphReadHealing(graphNode, graphEdge);
83 healingPipelineDao.setHealingVersion(graphNode);
87 private <T extends GraphNode> void transformPair(ImmutablePair<T, GraphEdge> either) {
88 GraphEdge edgeType = either.right;
89 GraphNode childVertex = either.left;
90 Integer healingVersioInt = childVertex.getHealingVersion();
91 HealVersionBuilder.build(healingVersioInt);
92 healingPipelineDao.performGraphReadHealing(childVertex, edgeType);
93 healingPipelineDao.setHealingVersion(childVertex);
97 public Either<List<ImmutablePair<JanusGraphVertex, Edge>>, JanusGraphOperationStatus> getChildrenVertecies(String key, String uniqueId,
98 GraphEdgeLabels edgeType) {
99 Either<List<ImmutablePair<JanusGraphVertex, Edge>>, JanusGraphOperationStatus> either = super.getChildrenVertecies(key, uniqueId, edgeType);
100 if (either.isRight()) {
103 List<ImmutablePair<JanusGraphVertex, Edge>> list = either.left().value();
104 list.forEach(this::transformVertexPair);
108 private void transformVertexPair(ImmutablePair<JanusGraphVertex, Edge> either) {
109 String edgeType = either.right.label();
110 JanusGraphVertex childVertex = either.left;
111 VertexProperty<Integer> healingVersionProperty = childVertex.property(GraphPropertyEnum.HEALING_VERSION.getProperty());
112 Integer healingVersioInt = healingVersionProperty.orElse(HealConstants.DEFAULT_HEAL_VERSION);
113 HealVersionBuilder.build(healingVersioInt);
114 healingPipelineDao.performGraphReadHealing(childVertex, edgeType);
115 healingPipelineDao.setHealingVersion(childVertex);
119 public <T extends GraphNode> Either<T, JanusGraphOperationStatus> updateNode(GraphNode node, Class<T> clazz) {
120 healingPipelineDao.setHealingVersion(node);
121 return super.updateNode(node, clazz);
125 public JanusGraphOperationStatus updateVertex(GraphNode node, Vertex vertex) {
126 healingPipelineDao.setHealingVersion(node);
127 return super.updateVertex(node, vertex);
131 public void setHealingPipelineDao(HealingPipelineDao healingPipelineDao) {
132 this.healingPipelineDao = healingPipelineDao;