diff options
author | Krishnakumar Jinka <kris.jinka@samsung.com> | 2018-11-25 13:56:36 +0900 |
---|---|---|
committer | krisjinka <kris.jinka@samsung.com> | 2018-11-30 07:54:55 +0900 |
commit | 74e0706bab06db09ce25998d3d3a52ec8b0237d3 (patch) | |
tree | ccb8014774070b951f8da3aea990b936d12e94cd /controlloop/common/model-impl/appclcm/src | |
parent | 6a55a271c6ca735ceaf4ab306633cb30715561bd (diff) |
Reduce resp values meth complexity
The response values determining method has more complexity
reduce it using enums. Fix build fail due to incorrect
response value. Modify LCM response code to enum. Fix
enum package. Modify status code enum. Add modification
copyright notice. Fix review comments. Add serialization key
Issue-ID: POLICY-1251
Change-Id: I49909b6dd2810dd864784afab0a328b855131501
Signed-off-by: kris.jinka <kris.jinka@samsung.com>
Signed-off-by: krisjinka <kris.jinka@samsung.com>
Diffstat (limited to 'controlloop/common/model-impl/appclcm/src')
2 files changed, 102 insertions, 23 deletions
diff --git a/controlloop/common/model-impl/appclcm/src/main/java/org/onap/policy/appclcm/LcmResponseCode.java b/controlloop/common/model-impl/appclcm/src/main/java/org/onap/policy/appclcm/LcmResponseCode.java index cca69b132..d3c3464ed 100644 --- a/controlloop/common/model-impl/appclcm/src/main/java/org/onap/policy/appclcm/LcmResponseCode.java +++ b/controlloop/common/model-impl/appclcm/src/main/java/org/onap/policy/appclcm/LcmResponseCode.java @@ -3,13 +3,14 @@ * appclcm * ================================================================================ * Copyright (C) 2017-2018 AT&T Intellectual Property. All rights reserved. + * Modifications Copyright (C) 2018 Samsung Electronics Co., Ltd. Intellectual Property. All rights reserved. * ================================================================================ * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at - * + * * http://www.apache.org/licenses/LICENSE-2.0 - * + * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. @@ -20,7 +21,10 @@ package org.onap.policy.appclcm; -public class LcmResponseCode { +import java.io.Serializable; +import org.onap.policy.appclcm.util.StatusCodeEnum; + +public class LcmResponseCode implements Serializable { /* These fields define the key to the response code value. */ public static final String ACCEPTED = "ACCEPTED"; @@ -30,8 +34,9 @@ public class LcmResponseCode { public static final String FAILURE = "FAILURE"; public static final String PARTIAL_SUCCESS = "PARTIAL SUCCESS"; public static final String PARTIAL_FAILURE = "PARTIAL FAILURE"; + private static final long serialVersionUID = 8189456447227022582L; - private Integer code; + private final Integer code; protected LcmResponseCode(final int code) { this.code = code; @@ -48,27 +53,12 @@ public class LcmResponseCode { /** * Translates the code to a string value that represents the meaning of the code. - * - * @param code the numeric value that is returned by APPC based on success, failure, etc. of the - * action requested + * + * @param code the numeric value that is returned by APPC based on success, failure, etc. of the action requested * @return the string value equivalent of the APPC response code */ public static String toResponseValue(int code) { - if (code == 100) { - return ACCEPTED; - } else if (code == 200) { - return ERROR; - } else if (code >= 300 && code <= 313) { - return REJECT; - } else if (code == 400) { - return SUCCESS; - } else if (code == 450 || (code >= 401 && code <= 406)) { - return FAILURE; - } else if (code == 500) { - return PARTIAL_SUCCESS; - } else if (code >= 501 && code <= 599) { - return PARTIAL_FAILURE; - } - return null; + StatusCodeEnum statusCodeEnum = StatusCodeEnum.fromStatusCode(code); + return (statusCodeEnum != null) ? statusCodeEnum.toString() : null; } } diff --git a/controlloop/common/model-impl/appclcm/src/main/java/org/onap/policy/appclcm/util/StatusCodeEnum.java b/controlloop/common/model-impl/appclcm/src/main/java/org/onap/policy/appclcm/util/StatusCodeEnum.java new file mode 100644 index 000000000..d954789e8 --- /dev/null +++ b/controlloop/common/model-impl/appclcm/src/main/java/org/onap/policy/appclcm/util/StatusCodeEnum.java @@ -0,0 +1,89 @@ +/*- + * ============LICENSE_START======================================================= + * Copyright (C) 2018 Samsung Electronics Co., Ltd. All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + * SPDX-License-Identifier: Apache-2.0 + * ============LICENSE_END========================================================= + */ + +package org.onap.policy.appclcm.util; + +import java.util.HashMap; +import java.util.Map; + +public enum StatusCodeEnum { + ACCEPTED("ACCEPTED"), ERROR("ERROR"), REJECT("REJECT"), SUCCESS("SUCCESS"), FAILURE("FAILURE"), + PARTIAL_SUCCESS("PARTIAL SUCCESS"), PARTIAL_FAILURE("PARTIAL FAILURE"); + + private String name; + + StatusCodeEnum(final String name) { + this.name = name; + } + + public String toString() { + return this.name; + } + + /** + * Determine status enum from the code. + * + * @param statusCode integer code indicating the status + * @return enum representation of status code + */ + public static StatusCodeEnum fromStatusCode(final int statusCode) { + if (statusCode == 100) { + return ACCEPTED; + } + + if (statusCode == 200) { + return ERROR; + } + + if (isRejectStatusCode(statusCode)) { + return REJECT; + } + + if (statusCode == 400) { + return SUCCESS; + } + + if (isFailureStatusCode(statusCode)) { + return FAILURE; + } + + if (statusCode == 500) { + return PARTIAL_SUCCESS; + } + + if (isPartialFailureStatusCode(statusCode)) { + return PARTIAL_FAILURE; + } + + return null; + } + + private static boolean isRejectStatusCode(final int statusCode) { + return statusCode >= 300 && statusCode <= 313; + } + + private static boolean isFailureStatusCode(final int statusCode) { + return statusCode == 450 || (statusCode >= 401 && statusCode <= 406); + } + + private static boolean isPartialFailureStatusCode(final int statusCode) { + return statusCode >= 501 && statusCode <= 599; + } +}
\ No newline at end of file |