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