re base code
[sdc.git] / catalog-be / src / main / java / org / openecomp / sdc / be / components / impl / DataTypesService.java
1 package org.openecomp.sdc.be.components.impl;
2
3 import fj.data.Either;
4 import org.openecomp.sdc.be.config.BeEcompErrorManager;
5 import org.openecomp.sdc.be.dao.api.ActionStatus;
6 import org.openecomp.sdc.be.dao.titan.TitanOperationStatus;
7 import org.openecomp.sdc.be.impl.ComponentsUtils;
8 import org.openecomp.sdc.be.model.DataTypeDefinition;
9 import org.openecomp.sdc.be.model.cache.ApplicationDataTypeCache;
10 import org.openecomp.sdc.exception.ResponseFormat;
11 import org.springframework.stereotype.Component;
12
13 import java.util.Map;
14
15 @Component
16 public class DataTypesService {
17
18     private final ComponentsUtils componentsUtils;
19
20     public DataTypesService(ComponentsUtils componentsUtils) {
21         this.componentsUtils = componentsUtils;
22     }
23
24     public Either<Map<String, DataTypeDefinition>, ResponseFormat> getAllDataTypes(ApplicationDataTypeCache applicationDataTypeCache) {
25         Either<Map<String, DataTypeDefinition>, TitanOperationStatus> allDataTypes = applicationDataTypeCache.getAll();
26         if (allDataTypes.isRight()) {
27             TitanOperationStatus operationStatus = allDataTypes.right().value();
28             if (operationStatus == TitanOperationStatus.NOT_FOUND) {
29                 BeEcompErrorManager.getInstance().logInternalDataError("FetchDataTypes", "Data types are not loaded", BeEcompErrorManager.ErrorSeverity.ERROR);
30                 return Either.right(componentsUtils.getResponseFormat(ActionStatus.DATA_TYPE_CANNOT_BE_EMPTY));
31             } else {
32                 BeEcompErrorManager.getInstance().logInternalFlowError("FetchDataTypes", "Failed to fetch data types", BeEcompErrorManager.ErrorSeverity.ERROR);
33                 return Either.right(componentsUtils.getResponseFormat(ActionStatus.GENERAL_ERROR));
34             }
35         }
36         return Either.left(allDataTypes.left().value());
37     }
38
39 }