aboutsummaryrefslogtreecommitdiffstats
path: root/client/client-editor
diff options
context:
space:
mode:
Diffstat (limited to 'client/client-editor')
-rw-r--r--client/client-editor/src/main/java/org/onap/policy/apex/client/editor/rest/handling/RestCommandHandler.java1
-rw-r--r--client/client-editor/src/main/java/org/onap/policy/apex/client/editor/rest/handling/bean/BeanBase.java35
2 files changed, 23 insertions, 13 deletions
diff --git a/client/client-editor/src/main/java/org/onap/policy/apex/client/editor/rest/handling/RestCommandHandler.java b/client/client-editor/src/main/java/org/onap/policy/apex/client/editor/rest/handling/RestCommandHandler.java
index c4fd6d6f4..5921c8960 100644
--- a/client/client-editor/src/main/java/org/onap/policy/apex/client/editor/rest/handling/RestCommandHandler.java
+++ b/client/client-editor/src/main/java/org/onap/policy/apex/client/editor/rest/handling/RestCommandHandler.java
@@ -23,7 +23,6 @@ package org.onap.policy.apex.client.editor.rest.handling;
import org.onap.policy.apex.model.modelapi.ApexApiResult;
import org.onap.policy.apex.model.modelapi.ApexApiResult.Result;
-// TODO: Auto-generated Javadoc
/**
* This interface defines the methods that a REST handler must implement to handle REST editor commands.
*
diff --git a/client/client-editor/src/main/java/org/onap/policy/apex/client/editor/rest/handling/bean/BeanBase.java b/client/client-editor/src/main/java/org/onap/policy/apex/client/editor/rest/handling/bean/BeanBase.java
index 20f8d6f07..6ac5c48e1 100644
--- a/client/client-editor/src/main/java/org/onap/policy/apex/client/editor/rest/handling/bean/BeanBase.java
+++ b/client/client-editor/src/main/java/org/onap/policy/apex/client/editor/rest/handling/bean/BeanBase.java
@@ -31,6 +31,9 @@ public abstract class BeanBase {
private static final String PROBLEM_RETRIEVING_FIELD_PREFIX = "Problem retrieving field called ('";
private static final String JSON_BEAN_SUFFIX = "') from JSON bean ";
+ // Magic numbers
+ private static final int GET_LENGTH = 3;
+
/**
* Gets a named field from the bean.
*
@@ -38,20 +41,14 @@ public abstract class BeanBase {
* @return the value for the field
*/
public String get(final String field) {
- // CHECKSTYLE:OFF: MagicNumber
// use getter preferably
for (final Method method : this.getClass().getMethods()) {
- if ((method.getName().startsWith("get")) && (method.getName().length() == (field.length() + 3))) {
- if (method.getName().toLowerCase().endsWith(field.toLowerCase())) {
- try {
- return (String) method.invoke(this);
- } catch (final Exception e) {
- throw new IllegalArgumentException(
- PROBLEM_RETRIEVING_FIELD_PREFIX + field + JSON_BEAN_SUFFIX + this, e);
- }
- }
+ if (method.getName().startsWith("get") && method.getName().length() == (field.length() + GET_LENGTH)
+ && method.getName().toLowerCase().endsWith(field.toLowerCase())) {
+ return invokeGetterMethod(field, method);
}
}
+
// Use field approach
if (field != null) {
try {
@@ -61,10 +58,24 @@ public abstract class BeanBase {
return (String) (f.get(this));
}
} catch (final Exception e) {
- throw new IllegalArgumentException(
- PROBLEM_RETRIEVING_FIELD_PREFIX + field + JSON_BEAN_SUFFIX + this, e);
+ throw new IllegalArgumentException(PROBLEM_RETRIEVING_FIELD_PREFIX + field + JSON_BEAN_SUFFIX + this,
+ e);
}
}
throw new IllegalArgumentException(PROBLEM_RETRIEVING_FIELD_PREFIX + field + JSON_BEAN_SUFFIX + this);
}
+
+ /**
+ * Invoke a getter method on a bean.
+ *
+ * @param field the field that the getter gets a value for
+ * @param method the method to invoke
+ */
+ private String invokeGetterMethod(final String field, final Method method) {
+ try {
+ return (String) method.invoke(this);
+ } catch (final Exception e) {
+ throw new IllegalArgumentException(PROBLEM_RETRIEVING_FIELD_PREFIX + field + JSON_BEAN_SUFFIX + this, e);
+ }
+ }
}