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 org.janusgraph.core.JanusGraphVertex;
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.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 {
40 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, GraphEdgeLabels edgeType, NodeTypeEnum nodeTypeEnum, Class<T> clazz, boolean withEdges) {
57 Either<List<ImmutablePair<T, GraphEdge>>, JanusGraphOperationStatus> either = super.getChildrenNodes(key, uniqueId, edgeType, nodeTypeEnum, clazz, withEdges);
58 if (either.isRight()) {
61 List<ImmutablePair<T, GraphEdge>> list = either.left().value();
62 list.forEach(this::transformPair);
67 public <T extends GraphNode> Either<ImmutablePair<T, GraphEdge>, JanusGraphOperationStatus> getChild(String key, String uniqueId, GraphEdgeLabels edgeType, NodeTypeEnum nodeTypeEnum, Class<T> clazz) {
68 Either<ImmutablePair<T, GraphEdge>, JanusGraphOperationStatus> eitherChild = super.getChild(key, uniqueId, edgeType, nodeTypeEnum, clazz);
69 if (eitherChild.isRight()) {
72 ImmutablePair<T, GraphEdge> pair = eitherChild.left().value();
73 GraphNode graphNode = pair.left;
74 GraphEdge graphEdge = pair.right;
75 healingPipelineDao.performGraphReadHealing(graphNode, graphEdge);
76 healingPipelineDao.setHealingVersion(graphNode);
80 private <T extends GraphNode> void transformPair(ImmutablePair<T, GraphEdge> either) {
81 GraphEdge edgeType = either.right;
82 GraphNode childVertex = either.left;
83 Integer healingVersioInt = childVertex.getHealingVersion();
84 HealVersionBuilder.build(healingVersioInt);
85 healingPipelineDao.performGraphReadHealing(childVertex, edgeType);
86 healingPipelineDao.setHealingVersion(childVertex);
90 public Either<List<ImmutablePair<JanusGraphVertex, Edge>>, JanusGraphOperationStatus> getChildrenVertecies(String key, String uniqueId, GraphEdgeLabels edgeType) {
91 Either<List<ImmutablePair<JanusGraphVertex, Edge>>, JanusGraphOperationStatus> either = super.getChildrenVertecies(key, uniqueId, edgeType);
92 if (either.isRight()) {
95 List<ImmutablePair<JanusGraphVertex, Edge>> list = either.left().value();
96 list.forEach(this::transformVertexPair);
100 private void transformVertexPair(ImmutablePair<JanusGraphVertex, Edge> either) {
101 String edgeType = either.right.label();
102 JanusGraphVertex childVertex = either.left;
103 VertexProperty<Integer> healingVersionProperty = childVertex.property(GraphPropertyEnum.HEALING_VERSION.getProperty());
104 Integer healingVersioInt = healingVersionProperty.orElse(HealConstants.DEFAULT_HEAL_VERSION);
105 HealVersionBuilder.build(healingVersioInt);
106 healingPipelineDao.performGraphReadHealing(childVertex, edgeType);
107 healingPipelineDao.setHealingVersion(childVertex);
111 public <T extends GraphNode> Either<T, JanusGraphOperationStatus> updateNode(GraphNode node, Class<T> clazz) {
112 healingPipelineDao.setHealingVersion(node);
113 return super.updateNode(node, clazz);
117 public JanusGraphOperationStatus updateVertex(GraphNode node, Vertex vertex) {
118 healingPipelineDao.setHealingVersion(node);
119 return super.updateVertex(node, vertex);
123 public void setHealingPipelineDao(HealingPipelineDao healingPipelineDao) {
124 this.healingPipelineDao = healingPipelineDao;