Upgrade SDC from Titan to Janus Graph
[sdc.git] / catalog-be / src / main / java / org / openecomp / sdc / be / components / impl / RelationshipTypeBusinessLogic.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.components.impl;
18
19 import java.util.Map;
20
21 import fj.data.Either;
22 import org.openecomp.sdc.be.config.BeEcompErrorManager;
23 import org.openecomp.sdc.be.dao.api.ActionStatus;
24 import org.openecomp.sdc.be.dao.janusgraph.JanusGraphOperationStatus;
25 import org.openecomp.sdc.be.impl.ComponentsUtils;
26 import org.openecomp.sdc.be.model.RelationshipTypeDefinition;
27 import org.openecomp.sdc.be.model.operations.impl.RelationshipTypeOperation;
28 import org.openecomp.sdc.exception.ResponseFormat;
29 import org.springframework.beans.factory.annotation.Autowired;
30 import org.springframework.stereotype.Component;
31
32 @Component("relationshipTypeBusinessLogic")
33 public class RelationshipTypeBusinessLogic {
34
35     @Autowired
36     private RelationshipTypeOperation relationshipTypeOperation;
37
38     @Autowired
39     protected ComponentsUtils componentsUtils;
40
41     public Either<Map<String, RelationshipTypeDefinition>, ResponseFormat> getAllRelationshipTypes() {
42         Either<Map<String, RelationshipTypeDefinition>, JanusGraphOperationStatus> allRelationshipTypes =
43                 relationshipTypeOperation.getAllRelationshipTypes();
44         if (allRelationshipTypes.isRight()) {
45             JanusGraphOperationStatus operationStatus = allRelationshipTypes.right().value();
46             if (JanusGraphOperationStatus.NOT_FOUND == operationStatus) {
47                 BeEcompErrorManager.getInstance().logInternalDataError("FetchRelationshipTypes", "Relationship types "
48                                 + "are "
49                                 + "not loaded",
50                         BeEcompErrorManager.ErrorSeverity.ERROR);
51                 return Either.right(componentsUtils.getResponseFormat(ActionStatus.DATA_TYPE_CANNOT_BE_EMPTY));
52             } else {
53                 BeEcompErrorManager.getInstance().logInternalFlowError("FetchRelationshipTypes", "Failed to fetch "
54                                 + "relationship types",
55                         BeEcompErrorManager.ErrorSeverity.ERROR);
56                 return Either.right(componentsUtils.getResponseFormat(ActionStatus.GENERAL_ERROR));
57             }
58         }
59         return Either.left(allRelationshipTypes.left().value());
60     }
61
62 }