re base code
[sdc.git] / catalog-model / src / main / java / org / openecomp / sdc / be / model / operations / impl / DaoStatusConverter.java
1 /*-
2  * ============LICENSE_START=======================================================
3  * SDC
4  * ================================================================================
5  * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
6  * ================================================================================
7  * Licensed under the Apache License, Version 2.0 (the "License");
8  * you may not use this file except in compliance with the License.
9  * You may obtain a copy of the License at
10  * 
11  *      http://www.apache.org/licenses/LICENSE-2.0
12  * 
13  * Unless required by applicable law or agreed to in writing, software
14  * distributed under the License is distributed on an "AS IS" BASIS,
15  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16  * See the License for the specific language governing permissions and
17  * limitations under the License.
18  * ============LICENSE_END=========================================================
19  */
20
21 package org.openecomp.sdc.be.model.operations.impl;
22
23 import org.openecomp.sdc.be.dao.cassandra.CassandraOperationStatus;
24 import org.openecomp.sdc.be.dao.titan.TitanOperationStatus;
25 import org.openecomp.sdc.be.model.operations.api.StorageOperationStatus;
26
27 public class DaoStatusConverter {
28
29     public static StorageOperationStatus convertTitanStatusToStorageStatus(TitanOperationStatus titanStatus) {
30
31         if (titanStatus == null) {
32             return StorageOperationStatus.GENERAL_ERROR;
33         }
34
35         switch (titanStatus) {
36
37         case OK:
38             return StorageOperationStatus.OK;
39
40         case NOT_CONNECTED:
41             return StorageOperationStatus.CONNECTION_FAILURE;
42
43         case NOT_FOUND:
44             return StorageOperationStatus.NOT_FOUND;
45
46         case NOT_CREATED:
47             return StorageOperationStatus.SCHEMA_ERROR;
48
49         case INDEX_CANNOT_BE_CHANGED:
50             return StorageOperationStatus.SCHEMA_ERROR;
51
52         case MISSING_UNIQUE_ID:
53             return StorageOperationStatus.BAD_REQUEST;
54         case ALREADY_LOCKED:
55             return StorageOperationStatus.FAILED_TO_LOCK_ELEMENT;
56
57         case TITAN_SCHEMA_VIOLATION:
58             return StorageOperationStatus.SCHEMA_VIOLATION;
59
60         case INVALID_ID:
61             return StorageOperationStatus.INVALID_ID;
62         case MATCH_NOT_FOUND:
63             return StorageOperationStatus.MATCH_NOT_FOUND;
64
65         case ILLEGAL_ARGUMENT:
66             return StorageOperationStatus.BAD_REQUEST;
67         case ALREADY_EXIST:
68             return StorageOperationStatus.ENTITY_ALREADY_EXISTS;
69         case PROPERTY_NAME_ALREADY_EXISTS:
70             return StorageOperationStatus.PROPERTY_NAME_ALREADY_EXISTS;
71         case INVALID_PROPERTY:
72             return StorageOperationStatus.INVALID_PROPERTY;
73         default:
74             return StorageOperationStatus.GENERAL_ERROR;
75         }
76
77     }
78
79     public static StorageOperationStatus convertCassandraStatusToStorageStatus(CassandraOperationStatus status) {
80         if (status == null) {
81             return StorageOperationStatus.GENERAL_ERROR;
82         }
83         switch (status) {
84         case OK:
85             return StorageOperationStatus.OK;
86         case CLUSTER_NOT_CONNECTED:
87             return StorageOperationStatus.CONNECTION_FAILURE;
88         case KEYSPACE_NOT_CONNECTED:
89             return StorageOperationStatus.STORAGE_NOT_AVAILABLE;
90         case NOT_FOUND:
91             return StorageOperationStatus.NOT_FOUND;
92
93         default:
94             return StorageOperationStatus.GENERAL_ERROR;
95         }
96     }
97 }