summaryrefslogtreecommitdiffstats
path: root/aai-service
diff options
context:
space:
mode:
authorRich Tabedzki <richard.tabedzki@att.com>2020-03-11 11:52:01 -0400
committerDan Timoney <dtimoney@att.com>2020-03-19 18:27:33 +0000
commitcbe638c93aa8f4e2f2a686afbfa3e353c9e88d65 (patch)
tree9b8a6ee7095ceafb01b15fac0923ece6d4bedf35 /aai-service
parent75e70fdc849c5e6d44ae5ff10acb81863f9c5fb4 (diff)
Update processing of data of type List in AAIDeclarations
Changes made: * Updated processing of data of type List in AAIDeclarations Issue-ID: CCSDK-2170 Change-Id: I019eaba0315d1131ff3f5fe50d5d76f824f939b7 Signed-off-by: Rich Tabedzki <richard.tabedzki@att.com>
Diffstat (limited to 'aai-service')
-rwxr-xr-xaai-service/provider/src/main/java/org/onap/ccsdk/sli/adaptors/aai/AAIDeclarations.java55
1 files changed, 49 insertions, 6 deletions
diff --git a/aai-service/provider/src/main/java/org/onap/ccsdk/sli/adaptors/aai/AAIDeclarations.java b/aai-service/provider/src/main/java/org/onap/ccsdk/sli/adaptors/aai/AAIDeclarations.java
index 4066f462..a6f75d24 100755
--- a/aai-service/provider/src/main/java/org/onap/ccsdk/sli/adaptors/aai/AAIDeclarations.java
+++ b/aai-service/provider/src/main/java/org/onap/ccsdk/sli/adaptors/aai/AAIDeclarations.java
@@ -33,6 +33,8 @@ import java.lang.annotation.Annotation;
import java.lang.reflect.Field;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
+import java.lang.reflect.Modifier;
+import java.lang.NoSuchMethodException;
import java.net.MalformedURLException;
import java.net.URISyntaxException;
import java.net.URL;
@@ -138,12 +140,12 @@ public abstract class AAIDeclarations implements AAIClient {
public static final String QUERY_NODES_PATH = "org.onap.ccsdk.sli.adaptors.aai.query.nodes";
private static final String VERSION_PATTERN = "/v$/";
-
+
private static final String AAI_SERVICE_EXCEPTION = "AAI Service Exception";
protected abstract Logger getLogger();
public abstract AAIExecutorInterface getExecutor();
-
+
private static final String RELATIONSHIP_DATA= "Retrofitting relationship data: ";
@@ -1079,11 +1081,11 @@ public abstract class AAIDeclarations implements AAIClient {
String id = AAIServiceUtils.camelCaseToDashedString(value);
Field field = resourceClass.getDeclaredField(value);
Class<?> type = field.getType();
- Method setter = null;
+
try {
- setter = resourceClass.getMethod("set"+StringUtils.capitalize(value), type);
if(type.getName().startsWith("java.lang") || "boolean".equals(type.getName()) || "long".equals(type.getName()) || "int".equals(type.getName())) {
try {
+ Method setter = resourceClass.getMethod("set"+StringUtils.capitalize(value), type);
Object arglist[] = new Object[1];
arglist[0] = params.get(id);
@@ -1131,11 +1133,26 @@ public abstract class AAIDeclarations implements AAIClient {
newValues.add(tmpValue);
}
if(!newValues.isEmpty()) {
- Object o = setter.invoke(instance, newValues);
+ Method setter = findSetterFor(resourceClass, value);
+ if(setter != null) {
+ Object o = setter.invoke(instance, newValues);
+ } else {
+ try {
+ Method listGetter = resourceClass.getMethod("get"+StringUtils.capitalize(value));
+ Object o = listGetter.invoke(instance);
+ if(o != null && o instanceof java.util.List ) {
+ List innerList = List.class.cast(o);
+ innerList.addAll(newValues);
+ }
+ } catch(NoSuchMethodException nsme) {
+ getLogger().warn(AAI_SERVICE_EXCEPTION, nsme);
+ }
+ }
}
}
set.remove(id);
} else {
+ Method setter = resourceClass.getMethod("set"+StringUtils.capitalize(value), type);
setters.put(id, setter);
}
} catch(Exception exc) {
@@ -1148,6 +1165,17 @@ public abstract class AAIDeclarations implements AAIClient {
if(!type.getName().equals("java.lang.String")) {
getters.put(id, getter);
}
+ } catch(NoSuchMethodException exc) {
+ try {
+ if(type.getName().equals("java.lang.Boolean")) {
+ getter = resourceClass.getMethod("is"+StringUtils.capitalize(value));
+ getters.put(id, getter);
+ } else {
+ getLogger().warn(AAI_SERVICE_EXCEPTION, exc);
+ }
+ } catch(Exception iexc) {
+ getLogger().warn(AAI_SERVICE_EXCEPTION, iexc);
+ }
} catch(Exception exc) {
getLogger().warn(AAI_SERVICE_EXCEPTION, exc);
}
@@ -1472,6 +1500,21 @@ public abstract class AAIDeclarations implements AAIClient {
return QueryStatus.SUCCESS;
}
+ private Method findSetterFor(Class<? extends AAIDatum> resourceClass, String value) {
+ try {
+ String setterName = "set"+StringUtils.capitalize(value);
+ for (Method method : resourceClass.getDeclaredMethods()) {
+ int modifiers = method.getModifiers();
+ if (Modifier.isPublic(modifiers) && setterName.contentEquals(method.getName())) {
+ return method;
+ }
+ }
+ } catch(Exception exc) {
+ getLogger().warn("findSetterFor()", exc);
+ }
+ return null;
+ }
+
private QueryStatus newModelProcessRelationshipList(Object instance, Map<String, String> params, String prefix, SvcLogicContext ctx) throws Exception {
Class resourceClass = instance.getClass();
@@ -1636,7 +1679,7 @@ public abstract class AAIDeclarations implements AAIClient {
try {
obj = getMetadataMethod.invoke(instance);
} catch (InvocationTargetException x) {
- Throwable cause = x.getCause();
+ Throwable cause = x.getCause();
}
}
if(obj != null && obj instanceof Metadata){