aboutsummaryrefslogtreecommitdiffstats
path: root/controlloop/common
diff options
context:
space:
mode:
authorJorge Hernandez <jorge.hernandez-herrero@att.com>2018-11-30 15:15:09 +0000
committerGerrit Code Review <gerrit@onap.org>2018-11-30 15:15:09 +0000
commitabc87799ac49357391dee7012c6003e05bb49326 (patch)
tree8594464ce5b4e54ed9fb5b66b841fee65bba5384 /controlloop/common
parentd697d828df129afa52555e9381d69c45d526c7d6 (diff)
parent74e0706bab06db09ce25998d3d3a52ec8b0237d3 (diff)
Merge "Reduce resp values meth complexity"
Diffstat (limited to 'controlloop/common')
-rw-r--r--controlloop/common/model-impl/appclcm/src/main/java/org/onap/policy/appclcm/LcmResponseCode.java36
-rw-r--r--controlloop/common/model-impl/appclcm/src/main/java/org/onap/policy/appclcm/util/StatusCodeEnum.java89
-rw-r--r--controlloop/common/model-impl/sdnr/src/main/java/org/onap/policy/sdnr/PciResponseCode.java40
-rw-r--r--controlloop/common/model-impl/sdnr/src/main/java/org/onap/policy/sdnr/util/StatusCodeEnum.java90
4 files changed, 206 insertions, 49 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
diff --git a/controlloop/common/model-impl/sdnr/src/main/java/org/onap/policy/sdnr/PciResponseCode.java b/controlloop/common/model-impl/sdnr/src/main/java/org/onap/policy/sdnr/PciResponseCode.java
index eba57366d..430adcb92 100644
--- a/controlloop/common/model-impl/sdnr/src/main/java/org/onap/policy/sdnr/PciResponseCode.java
+++ b/controlloop/common/model-impl/sdnr/src/main/java/org/onap/policy/sdnr/PciResponseCode.java
@@ -3,13 +3,14 @@
* sdnr
* ================================================================================
* Copyright (C) 2018 Wipro Limited 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.sdnr;
-public class PciResponseCode {
+import java.io.Serializable;
+import org.onap.policy.sdnr.util.StatusCodeEnum;
+
+public class PciResponseCode implements Serializable {
/* These fields define the key to the response code value. */
public static final String ACCEPTED = "ACCEPTED";
@@ -30,8 +34,9 @@ public class PciResponseCode {
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 = -5371924429933449763L;
- private Integer code;
+ private final Integer code;
protected PciResponseCode(final int code) {
this.code = code;
@@ -47,30 +52,13 @@ public class PciResponseCode {
}
/**
- * Translates the code to a string value that represents the meaning of the
- * code.
- *
- * @param code
- * the numeric value that is returned by SDNR based on success,
- * failure, etc. of the action requested
+ * Translates the code to a string value that represents the meaning of the code.
+ *
+ * @param code the numeric value that is returned by SDNR based on success, failure, etc. of the action requested
* @return the string value equivalent of the SDNR response code
*/
public static String toResponseValue(int code) {
- if (code == 100) {
- return ACCEPTED;
- } else if (code == 200) {
- return SUCCESS;
- } else if (code >= 300 && code <= 313) {
- return REJECT;
- } else if (code == 400) {
- return ERROR;
- } 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/sdnr/src/main/java/org/onap/policy/sdnr/util/StatusCodeEnum.java b/controlloop/common/model-impl/sdnr/src/main/java/org/onap/policy/sdnr/util/StatusCodeEnum.java
new file mode 100644
index 000000000..8830545da
--- /dev/null
+++ b/controlloop/common/model-impl/sdnr/src/main/java/org/onap/policy/sdnr/util/StatusCodeEnum.java
@@ -0,0 +1,90 @@
+/*-
+ * ============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.sdnr.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 SUCCESS;
+ }
+
+ if (isRejectStatusCode(statusCode)) {
+ return REJECT;
+ }
+
+ if (statusCode == 400) {
+ return ERROR;
+ }
+
+ 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;
+ }
+
+}