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.
17 package org.openecomp.sdc.be.dao.jsongraph;
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;
31 @Component("janusgraph-dao")
32 public class HealingJanusGraphDao extends JanusGraphDao {
34 private HealingPipelineDao healingPipelineDao;
38 public HealingJanusGraphDao(HealingPipelineDao healingPipelineDao, JanusGraphClient janusGraphClient) {
39 super(janusGraphClient);
40 this.healingPipelineDao = healingPipelineDao;
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()));
54 private GraphVertex transformVertex(GraphVertex graphVertex, EdgeLabelEnum edgeLabelEnum) {
55 Optional<GraphVertex> optional = healingPipelineDao.performGraphReadHealing(graphVertex, edgeLabelEnum);
56 return optional.orElse(graphVertex);
60 public void setHealingPipelineDao(HealingPipelineDao healingPipelineDao) {
61 this.healingPipelineDao = healingPipelineDao;