aboutsummaryrefslogtreecommitdiffstats
path: root/plugins/plugins-executor
diff options
context:
space:
mode:
authorliamfallon <liam.fallon@ericsson.com>2018-09-22 21:07:43 +0100
committerliamfallon <liam.fallon@ericsson.com>2018-09-22 21:15:22 +0100
commit6973ec9109fd2651e2284663b6c8039bd830a677 (patch)
treef1f02ef9e5400805e6c2179dc539ad15c3ce5334 /plugins/plugins-executor
parenta02548ec2e98a8a13cd76ecc83379b13cd26030b (diff)
Fix sonar problems in Apex
Fixed some easy to resolve Sonar issues. Issue-ID: POLICY-1034 Change-Id: Ia8e4606bd4307daca499b4a74c96135211e572fd Signed-off-by: liamfallon <liam.fallon@ericsson.com>
Diffstat (limited to 'plugins/plugins-executor')
-rw-r--r--plugins/plugins-executor/plugins-executor-jython/src/main/java/org/onap/policy/apex/plugins/executor/jython/JythonTaskExecutor.java47
-rw-r--r--plugins/plugins-executor/plugins-executor-jython/src/main/java/org/onap/policy/apex/plugins/executor/jython/JythonTaskSelectExecutor.java50
2 files changed, 61 insertions, 36 deletions
diff --git a/plugins/plugins-executor/plugins-executor-jython/src/main/java/org/onap/policy/apex/plugins/executor/jython/JythonTaskExecutor.java b/plugins/plugins-executor/plugins-executor-jython/src/main/java/org/onap/policy/apex/plugins/executor/jython/JythonTaskExecutor.java
index 39ca0dc43..bddb63b42 100644
--- a/plugins/plugins-executor/plugins-executor-jython/src/main/java/org/onap/policy/apex/plugins/executor/jython/JythonTaskExecutor.java
+++ b/plugins/plugins-executor/plugins-executor-jython/src/main/java/org/onap/policy/apex/plugins/executor/jython/JythonTaskExecutor.java
@@ -100,23 +100,7 @@ public class JythonTaskExecutor extends TaskExecutor {
// Set up the Jython engine
interpreter.set("executor", getExecutionContext());
interpreter.exec(compiled);
- try {
- final Object ret = interpreter.get("returnValue", java.lang.Boolean.class);
- if (ret == null) {
- LOGGER.error("execute: task logic failed to set a return value for task \""
- + getSubject().getKey().getId() + "\"");
- throw new StateMachineException("execute: task logic failed to set a return value for task \""
- + getSubject().getKey().getId() + "\"");
- }
- returnValue = (Boolean) ret;
- } catch (NullPointerException | ClassCastException e) {
- LOGGER.error("execute: task selection logic failed to set a correct return value for state \""
- + getSubject().getKey().getId() + "\"", e);
- throw new StateMachineException(
- "execute: task selection logic failed to set a return value for state \""
- + getSubject().getKey().getId() + "\"",
- e);
- }
+ returnValue = handleInterpreterResult();
}
/* */
} catch (final Exception e) {
@@ -137,6 +121,35 @@ public class JythonTaskExecutor extends TaskExecutor {
}
/**
+ * Handle the result returned by the interpreter.
+ *
+ * @return true if the result was successful
+ * @throws StateMachineException on interpreter failures
+ */
+ private boolean handleInterpreterResult() throws StateMachineException {
+ boolean returnValue = false;
+
+ try {
+ final Object ret = interpreter.get("returnValue", java.lang.Boolean.class);
+ if (ret == null) {
+ LOGGER.error("execute: task logic failed to set a return value for task \""
+ + getSubject().getKey().getId() + "\"");
+ throw new StateMachineException("execute: task logic failed to set a return value for task \""
+ + getSubject().getKey().getId() + "\"");
+ }
+ returnValue = (Boolean) ret;
+ } catch (NullPointerException | ClassCastException e) {
+ LOGGER.error("execute: task selection logic failed to set a correct return value for state \""
+ + getSubject().getKey().getId() + "\"", e);
+ throw new StateMachineException(
+ "execute: task selection logic failed to set a return value for state \""
+ + getSubject().getKey().getId() + "\"",
+ e);
+ }
+ return returnValue;
+ }
+
+ /**
* Cleans up the task after processing.
*
* @throws StateMachineException thrown when a state machine execution error occurs
diff --git a/plugins/plugins-executor/plugins-executor-jython/src/main/java/org/onap/policy/apex/plugins/executor/jython/JythonTaskSelectExecutor.java b/plugins/plugins-executor/plugins-executor-jython/src/main/java/org/onap/policy/apex/plugins/executor/jython/JythonTaskSelectExecutor.java
index 3ff061fa4..9a2433122 100644
--- a/plugins/plugins-executor/plugins-executor-jython/src/main/java/org/onap/policy/apex/plugins/executor/jython/JythonTaskSelectExecutor.java
+++ b/plugins/plugins-executor/plugins-executor-jython/src/main/java/org/onap/policy/apex/plugins/executor/jython/JythonTaskSelectExecutor.java
@@ -103,25 +103,7 @@ public class JythonTaskSelectExecutor extends TaskSelectExecutor {
// Set up the Jython engine
interpreter.set("executor", getExecutionContext());
interpreter.exec(compiled);
-
- try {
- final Object ret = interpreter.get("returnValue", java.lang.Boolean.class);
- if (ret == null) {
- LOGGER.error(TSL_FAILED_PREFIX
- + getSubject().getKey().getId() + "\"");
- throw new StateMachineException(
- TSL_FAILED_PREFIX
- + getSubject().getKey().getId() + "\"");
- }
- returnValue = (Boolean) ret;
- } catch (NullPointerException | ClassCastException e) {
- LOGGER.error("execute: task selection logic failed to set a correct return value for state \""
- + getSubject().getKey().getId() + "\"", e);
- throw new StateMachineException(
- TSL_FAILED_PREFIX
- + getSubject().getKey().getId() + "\"",
- e);
- }
+ returnValue = handleInterpreterResult();
}
/* */
} catch (final Exception e) {
@@ -143,6 +125,36 @@ public class JythonTaskSelectExecutor extends TaskSelectExecutor {
}
/**
+ * Handle the result returned by the interpreter.
+ *
+ * @return true if the result was successful
+ * @throws StateMachineException on interpreter errors
+ */
+ private boolean handleInterpreterResult() throws StateMachineException {
+ boolean returnValue = false;
+
+ try {
+ final Object ret = interpreter.get("returnValue", java.lang.Boolean.class);
+ if (ret == null) {
+ LOGGER.error(TSL_FAILED_PREFIX
+ + getSubject().getKey().getId() + "\"");
+ throw new StateMachineException(
+ TSL_FAILED_PREFIX
+ + getSubject().getKey().getId() + "\"");
+ }
+ returnValue = (Boolean) ret;
+ } catch (NullPointerException | ClassCastException e) {
+ LOGGER.error("execute: task selection logic failed to set a correct return value for state \""
+ + getSubject().getKey().getId() + "\"", e);
+ throw new StateMachineException(
+ TSL_FAILED_PREFIX
+ + getSubject().getKey().getId() + "\"",
+ e);
+ }
+ return returnValue;
+ }
+
+ /**
* Cleans up the task after processing.
*
* @throws StateMachineException thrown when a state machine execution error occurs