2  * ============LICENSE_START=======================================================
 
   3  *  Copyright (C) 2018 Samsung Electronics Co., Ltd. All rights reserved.
 
   4  *  Modifications Copyright (C) 2019 Nordix Foundation.
 
   5  * ================================================================================
 
   6  * Licensed under the Apache License, Version 2.0 (the "License");
 
   7  * you may not use this file except in compliance with the License.
 
   8  * You may obtain a copy of the License at
 
  10  *      http://www.apache.org/licenses/LICENSE-2.0
 
  12  * Unless required by applicable law or agreed to in writing, software
 
  13  * distributed under the License is distributed on an "AS IS" BASIS,
 
  14  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 
  15  * See the License for the specific language governing permissions and
 
  16  * limitations under the License.
 
  18  * SPDX-License-Identifier: Apache-2.0
 
  19  * ============LICENSE_END=========================================================
 
  22 package org.onap.policy.appclcm.util;
 
  24 public enum StatusCodeEnum {
 
  25     ACCEPTED("ACCEPTED"), ERROR("ERROR"), REJECT("REJECT"), SUCCESS("SUCCESS"), FAILURE("FAILURE"),
 
  26     PARTIAL_SUCCESS("PARTIAL SUCCESS"), PARTIAL_FAILURE("PARTIAL FAILURE");
 
  30     StatusCodeEnum(final String name) {
 
  35     public String toString() {
 
  40      * Determine status enum from the code.
 
  42      * @param statusCode integer code indicating the status
 
  43      * @return enum representation of status code
 
  45     public static StatusCodeEnum fromStatusCode(final int statusCode) {
 
  46         if (statusCode == 100) {
 
  50         if (statusCode == 200) {
 
  54         if (isRejectStatusCode(statusCode)) {
 
  58         if (statusCode == 400) {
 
  62         if (isFailureStatusCode(statusCode)) {
 
  66         if (statusCode == 500) {
 
  67             return PARTIAL_SUCCESS;
 
  70         if (isPartialFailureStatusCode(statusCode)) {
 
  71             return PARTIAL_FAILURE;
 
  77     private static boolean isRejectStatusCode(final int statusCode) {
 
  78         return statusCode >= 300 && statusCode <= 313;
 
  81     private static boolean isFailureStatusCode(final int statusCode) {
 
  82         return statusCode == 450 || (statusCode >= 401 && statusCode <= 406);
 
  85     private static boolean isPartialFailureStatusCode(final int statusCode) {
 
  86         return statusCode >= 501 && statusCode <= 599;