Upgrade SDC from Titan to Janus Graph
[sdc.git] / catalog-dao / src / main / java / org / openecomp / sdc / be / dao / impl / heal / HealNodeGraphDao.java
1 package org.openecomp.sdc.be.dao.impl.heal;
2
3 import org.openecomp.sdc.be.dao.graph.datatype.GraphEdge;
4 import org.openecomp.sdc.be.dao.graph.datatype.GraphNode;
5 import org.openecomp.sdc.be.dao.impl.HealingPipelineDao;
6 import org.openecomp.sdc.be.dao.jsongraph.heal.Heal;
7 import org.openecomp.sdc.be.dao.jsongraph.heal.HealVersion;
8 import org.openecomp.sdc.be.dao.jsongraph.heal.HealVersionBuilder;
9
10 public class HealNodeGraphDao implements HealGraphDao<GraphNode, GraphEdge> {
11
12     private HealingPipelineDao healingPipelineDao;
13
14
15     public HealNodeGraphDao(HealingPipelineDao healingPipelineDao) {
16         this.healingPipelineDao = healingPipelineDao;
17     }
18
19     @Override
20     public GraphNode performGraphReadHealing(GraphNode childVertex, GraphEdge graphEdge) {
21         Integer healingVersionInt =  childVertex.getHealingVersion();
22         HealVersion<Integer> healingVersion = HealVersionBuilder.build(healingVersionInt);
23         healingPipelineDao.getHealersForVertex(graphEdge.getEdgeType().getProperty(), healingVersion).forEach(heal -> healJanusGraphVertex(childVertex, heal));
24         childVertex.setHealingVersion(healingPipelineDao.getCurrentHealVersion().getVersion());
25         return childVertex;
26     }
27
28     private GraphNode healJanusGraphVertex(GraphNode childVertex, Heal<GraphNode> heal) {
29         heal.healData(childVertex);
30         final HealVersion<Integer> healVersion = heal.fromVersion();
31         HealVersion<Integer> newerVersion = HealVersionBuilder.build(healVersion.getVersion() + 1);
32         childVertex.setHealingVersion(newerVersion.getVersion());
33         return childVertex;
34     }
35 }