2 * ============LICENSE_START=======================================================
3 * Copyright (C) 2018 Samsung Electronics Co., Ltd. All rights reserved.
4 * ================================================================================
5 * Licensed under the Apache License, Version 2.0 (the "License");
6 * you may not use this file except in compliance with the License.
7 * You may obtain a copy of the License at
9 * http://www.apache.org/licenses/LICENSE-2.0
11 * Unless required by applicable law or agreed to in writing, software
12 * distributed under the License is distributed on an "AS IS" BASIS,
13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 * See the License for the specific language governing permissions and
15 * limitations under the License.
17 * SPDX-License-Identifier: Apache-2.0
18 * ============LICENSE_END=========================================================
21 package org.onap.policy.appclcm.util;
23 import java.util.HashMap;
26 public enum StatusCodeEnum {
27 ACCEPTED("ACCEPTED"), ERROR("ERROR"), REJECT("REJECT"), SUCCESS("SUCCESS"), FAILURE("FAILURE"),
28 PARTIAL_SUCCESS("PARTIAL SUCCESS"), PARTIAL_FAILURE("PARTIAL FAILURE");
32 StatusCodeEnum(final String name) {
36 public String toString() {
41 * Determine status enum from the code.
43 * @param statusCode integer code indicating the status
44 * @return enum representation of status code
46 public static StatusCodeEnum fromStatusCode(final int statusCode) {
47 if (statusCode == 100) {
51 if (statusCode == 200) {
55 if (isRejectStatusCode(statusCode)) {
59 if (statusCode == 400) {
63 if (isFailureStatusCode(statusCode)) {
67 if (statusCode == 500) {
68 return PARTIAL_SUCCESS;
71 if (isPartialFailureStatusCode(statusCode)) {
72 return PARTIAL_FAILURE;
78 private static boolean isRejectStatusCode(final int statusCode) {
79 return statusCode >= 300 && statusCode <= 313;
82 private static boolean isFailureStatusCode(final int statusCode) {
83 return statusCode == 450 || (statusCode >= 401 && statusCode <= 406);
86 private static boolean isPartialFailureStatusCode(final int statusCode) {
87 return statusCode >= 501 && statusCode <= 599;