Catalog alignment
[sdc.git] / catalog-dao / src / main / java / org / openecomp / sdc / be / dao / jsongraph / HealingJanusGraphDao.java
1 /*
2  * Copyright © 2016-2018 European Support Limited
3  *
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
7  *
8  *      http://www.apache.org/licenses/LICENSE-2.0
9  *
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.
15  */
16
17 package org.openecomp.sdc.be.dao.jsongraph;
18
19 import fj.data.Either;
20 import java.util.List;
21 import java.util.Optional;
22 import java.util.stream.Collectors;
23 import org.openecomp.sdc.be.dao.impl.HealingPipelineDao;
24 import org.openecomp.sdc.be.dao.janusgraph.JanusGraphClient;
25 import org.openecomp.sdc.be.dao.jsongraph.types.EdgeLabelEnum;
26 import org.openecomp.sdc.be.dao.jsongraph.types.JsonParseFlagEnum;
27 import org.openecomp.sdc.be.dao.janusgraph.JanusGraphOperationStatus;
28 import org.springframework.beans.factory.annotation.Autowired;
29 import org.springframework.stereotype.Component;
30
31 @Component("janusgraph-dao")
32 public class HealingJanusGraphDao extends JanusGraphDao {
33
34     private HealingPipelineDao healingPipelineDao;
35
36
37     @Autowired
38     public HealingJanusGraphDao(HealingPipelineDao healingPipelineDao, JanusGraphClient janusGraphClient) {
39         super(janusGraphClient);
40         this.healingPipelineDao = healingPipelineDao;
41     }
42
43     @Override
44     public Either<List<GraphVertex>, JanusGraphOperationStatus> getChildrenVertices(GraphVertex parentVertex,
45                                                                                      EdgeLabelEnum edgeLabel, JsonParseFlagEnum parseFlag) {
46         Either<List<GraphVertex>, JanusGraphOperationStatus> childrenVertecies =
47                 super.getChildrenVertices(parentVertex, edgeLabel, parseFlag);
48         return Either.iif(childrenVertecies.isRight(), () -> childrenVertecies.right().value(),
49                 () -> childrenVertecies.left().value().stream()
50                               .map(graphVertex -> transformVertex(graphVertex, edgeLabel))
51                               .collect(Collectors.toList()));
52     }
53
54     private GraphVertex transformVertex(GraphVertex graphVertex, EdgeLabelEnum edgeLabelEnum) {
55         Optional<GraphVertex> optional = healingPipelineDao.performGraphReadHealing(graphVertex, edgeLabelEnum);
56         return optional.orElse(graphVertex);
57     }
58
59
60     public void setHealingPipelineDao(HealingPipelineDao healingPipelineDao) {
61         this.healingPipelineDao = healingPipelineDao;
62     }
63
64 }