Reformat catalog-model
[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 package org.openecomp.sdc.be.model.operations.impl;
21
22 import org.openecomp.sdc.be.dao.cassandra.CassandraOperationStatus;
23 import org.openecomp.sdc.be.dao.janusgraph.JanusGraphOperationStatus;
24 import org.openecomp.sdc.be.model.operations.api.StorageOperationStatus;
25
26 public class DaoStatusConverter {
27
28     public static StorageOperationStatus convertJanusGraphStatusToStorageStatus(JanusGraphOperationStatus janusGraphStatus) {
29         if (janusGraphStatus == null) {
30             return StorageOperationStatus.GENERAL_ERROR;
31         }
32         switch (janusGraphStatus) {
33             case OK:
34                 return StorageOperationStatus.OK;
35             case NOT_CONNECTED:
36                 return StorageOperationStatus.CONNECTION_FAILURE;
37             case NOT_FOUND:
38                 return StorageOperationStatus.NOT_FOUND;
39             case NOT_CREATED:
40                 return StorageOperationStatus.SCHEMA_ERROR;
41             case INDEX_CANNOT_BE_CHANGED:
42                 return StorageOperationStatus.SCHEMA_ERROR;
43             case MISSING_UNIQUE_ID:
44                 return StorageOperationStatus.BAD_REQUEST;
45             case ALREADY_LOCKED:
46                 return StorageOperationStatus.FAILED_TO_LOCK_ELEMENT;
47             case JANUSGRAPH_SCHEMA_VIOLATION:
48                 return StorageOperationStatus.SCHEMA_VIOLATION;
49             case INVALID_ID:
50                 return StorageOperationStatus.INVALID_ID;
51             case MATCH_NOT_FOUND:
52                 return StorageOperationStatus.MATCH_NOT_FOUND;
53             case ILLEGAL_ARGUMENT:
54                 return StorageOperationStatus.BAD_REQUEST;
55             case ALREADY_EXIST:
56                 return StorageOperationStatus.ENTITY_ALREADY_EXISTS;
57             case PROPERTY_NAME_ALREADY_EXISTS:
58                 return StorageOperationStatus.PROPERTY_NAME_ALREADY_EXISTS;
59             case INVALID_PROPERTY:
60                 return StorageOperationStatus.INVALID_PROPERTY;
61             default:
62                 return StorageOperationStatus.GENERAL_ERROR;
63         }
64     }
65
66     public static StorageOperationStatus convertCassandraStatusToStorageStatus(CassandraOperationStatus status) {
67         if (status == null) {
68             return StorageOperationStatus.GENERAL_ERROR;
69         }
70         switch (status) {
71             case OK:
72                 return StorageOperationStatus.OK;
73             case CLUSTER_NOT_CONNECTED:
74                 return StorageOperationStatus.CONNECTION_FAILURE;
75             case KEYSPACE_NOT_CONNECTED:
76                 return StorageOperationStatus.STORAGE_NOT_AVAILABLE;
77             case NOT_FOUND:
78                 return StorageOperationStatus.NOT_FOUND;
79             default:
80                 return StorageOperationStatus.GENERAL_ERROR;
81         }
82     }
83 }