migrate model-impl from drools-applications
[policy/models.git] / models-interactions / model-impl / appclcm / src / main / java / org / onap / policy / appclcm / LcmResponseCode.java
1 /*-
2  * ============LICENSE_START=======================================================
3  * appclcm
4  * ================================================================================
5  * Copyright (C) 2017-2019 AT&T Intellectual Property. All rights reserved.
6  * Modifications Copyright (C) 2019 Nordix Foundation.
7  * Modifications Copyright (C) 2018 Samsung Electronics Co., Ltd.
8  * ================================================================================
9  * Licensed under the Apache License, Version 2.0 (the "License");
10  * you may not use this file except in compliance with the License.
11  * You may obtain a copy of the License at
12  *
13  *      http://www.apache.org/licenses/LICENSE-2.0
14  *
15  * Unless required by applicable law or agreed to in writing, software
16  * distributed under the License is distributed on an "AS IS" BASIS,
17  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
18  * See the License for the specific language governing permissions and
19  * limitations under the License.
20  * ============LICENSE_END=========================================================
21  */
22
23 package org.onap.policy.appclcm;
24
25 import java.io.Serializable;
26 import org.onap.policy.appclcm.util.StatusCodeEnum;
27
28 public class LcmResponseCode implements Serializable {
29
30     /* These fields define the key to the response code value. */
31     public static final String ACCEPTED = "ACCEPTED";
32     public static final String ERROR = "ERROR";
33     public static final String REJECT = "REJECT";
34     public static final String SUCCESS = "SUCCESS";
35     public static final String FAILURE = "FAILURE";
36     public static final String PARTIAL_SUCCESS = "PARTIAL SUCCESS";
37     public static final String PARTIAL_FAILURE = "PARTIAL FAILURE";
38     private static final long serialVersionUID = 8189456447227022582L;
39
40     private final Integer code;
41
42     protected LcmResponseCode(final int code) {
43         this.code = code;
44     }
45
46     public int getCode() {
47         return this.code;
48     }
49
50     @Override
51     public String toString() {
52         return Integer.toString(this.code);
53     }
54
55     /**
56      * Translates the code to a string value that represents the meaning of the code.
57      *
58      * @param code the numeric value that is returned by APPC based on success, failure, etc. of the action requested
59      * @return the string value equivalent of the APPC response code
60      */
61     public static String toResponseValue(int code) {
62         StatusCodeEnum statusCodeEnum = StatusCodeEnum.fromStatusCode(code);
63         return (statusCodeEnum != null) ? statusCodeEnum.toString() : null;
64     }
65 }