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