Fixing trustStore issues in AAI Client
[ccsdk/sli/adaptors.git] / aai-service / provider / src / main / java / org / onap / ccsdk / sli / adaptors / aai / AAIServiceUtils.java
index 0566aac..5c42151 100755 (executable)
 package org.onap.ccsdk.sli.adaptors.aai;
 
 import java.lang.annotation.Annotation;
+import java.lang.reflect.Method;
 import java.net.MalformedURLException;
 import java.net.URI;
 import java.net.URISyntaxException;
 import java.util.Arrays;
 import java.util.HashMap;
+import java.util.Map;
 import java.util.HashSet;
 import java.util.Iterator;
 import java.util.LinkedList;
@@ -36,9 +38,9 @@ import java.util.Set;
 import javax.xml.bind.annotation.XmlType;
 
 import org.apache.commons.lang.StringUtils;
-import org.openecomp.aai.inventory.v11.Relationship;
-import org.openecomp.aai.inventory.v11.RelationshipData;
-import org.openecomp.aai.inventory.v11.RelationshipList;
+import org.openecomp.aai.inventory.v13.Relationship;
+import org.openecomp.aai.inventory.v13.RelationshipData;
+import org.openecomp.aai.inventory.v13.RelationshipList;
 import org.onap.ccsdk.sli.core.sli.SvcLogicContext;
 import org.onap.ccsdk.sli.adaptors.aai.data.AAIDatum;
 import org.slf4j.Logger;
@@ -48,14 +50,14 @@ public class AAIServiceUtils {
 
     private static final Logger LOG = LoggerFactory.getLogger(AAIService.class);
 
+    private AAIServiceUtils() {
+    }
+
     public static String getPrimaryIdFromClass(Class<? extends AAIDatum> resourceClass){
         // 1. find class
         getLogger().debug(resourceClass.getName());
-        AAIDatum instance = null;
 
         try {
-            instance = resourceClass.newInstance();
-
             Annotation[] annotations = resourceClass.getAnnotations();
             for(Annotation annotation : annotations) {
                 Class<? extends Annotation> anotationType = annotation.annotationType();
@@ -72,19 +74,15 @@ public class AAIServiceUtils {
                 }
             }
         } catch(Exception exc) {
-
+            getLogger().warn("getPrimaryIdFromClass failed", exc);
         }
         return null;
     }
 
     public static String getSecondaryIdFromClass(Class<? extends AAIDatum> resourceClass){
-        // 1. find class
         getLogger().debug(resourceClass.getName());
-        AAIDatum instance = null;
 
         try {
-            instance = resourceClass.newInstance();
-
             Annotation[] annotations = resourceClass.getAnnotations();
             for(Annotation annotation : annotations) {
                 Class<? extends Annotation> anotationType = annotation.annotationType();
@@ -111,6 +109,16 @@ public class AAIServiceUtils {
         return null;
     }
 
+    public static Method getRelationshipListGetterMethodFromClassDefinition(Class resourceClass) {
+        Method getRelationshipListMethod = null;
+
+        try {
+             getRelationshipListMethod = resourceClass.getMethod("getRelationshipList");
+        } catch(Exception exc) {
+            getLogger().debug("Retrofiting relationship data: " + exc.getMessage());
+        }
+        return getRelationshipListMethod;
+    }
 
     private static Logger getLogger() {
         return LOG;
@@ -264,33 +272,28 @@ public class AAIServiceUtils {
                 if(AAIRequest.getResourceNames().contains(tag)){
                     LOG.info(tag);
                     // get the class from tag
-                    Class<? extends AAIDatum> clazz = null;
-                    try {
-                        clazz = AAIRequest.getClassFromResource(tag);
-                        String fieldName = AAIServiceUtils.getPrimaryIdFromClass(clazz);
-
-                        String value = it.next();
-                        if(!StringUtils.isEmpty(value)){
-                            nameValues.put(String.format("%s.%s", tag, fieldName), value);
-                            switch(tag) {
-                            case "cloud-region":
-                            case "entitlement":
-                            case "license":
-                            case "route-target":
-                            case "service-capability":
-                            case "ctag-pool":
-                                String secondaryFieldName = AAIServiceUtils.getSecondaryIdFromClass(clazz);
-                                if(secondaryFieldName != null) {
-                                    value = it.next();
-                                    nameValues.put(String.format("%s.%s", tag, secondaryFieldName), value);
-                                }
-                                break;
-                            default:
-                                break;
+                    Class<? extends AAIDatum> clazz = AAIRequest.getClassFromResource(tag);
+                    String fieldName = AAIServiceUtils.getPrimaryIdFromClass(clazz);
+
+                    String value = it.next();
+                    if(!StringUtils.isEmpty(value)){
+                        nameValues.put(String.format("%s.%s", tag, fieldName), value);
+                        switch(tag) {
+                        case "cloud-region":
+                        case "entitlement":
+                        case "license":
+                        case "route-target":
+                        case "service-capability":
+                        case "ctag-pool":
+                            String secondaryFieldName = AAIServiceUtils.getSecondaryIdFromClass(clazz);
+                            if(secondaryFieldName != null) {
+                                value = it.next();
+                                nameValues.put(String.format("%s.%s", tag, secondaryFieldName), value);
                             }
+                            break;
+                        default:
+                            break;
                         }
-                    } catch (ClassNotFoundException exc) {
-                        LOG.info("Caught exception", exc);
                     }
                 }
             }
@@ -308,9 +311,10 @@ public class AAIServiceUtils {
         return request.getRequestPath();
     }
 
-    public static boolean isValidFormat(String resource, HashMap<String, String> nameValues) {
+    public static boolean isValidFormat(String resource, Map<String, String> nameValues) {
 
         switch(resource){
+    case "custom-query":
         case "formatted-query":
         case "generic-query":
         case "named-query":
@@ -329,10 +333,10 @@ public class AAIServiceUtils {
         Set<String> keys = nameValues.keySet();
         for(String key : keys) {
             if(!key.contains(".")) {
-                if("depth".equals(key) || "related-to".equals(key) || "related_to".equals(key) || "related-link".equals(key) || "related_link".equals(key) || "selflink".equals(key))
+                if("depth".equals(key) || "related-to".equals(key) || "related_to".equals(key) || "related-link".equals(key) || "related_link".equals(key) || "selflink".equals(key) || "resource_path".equals(key))
                     continue;
                 else {
-                    getLogger().warn(String.format("key %s is incompatible with resource type '%s'", key, resource));
+                    getLogger().warn(String.format("key '%s' is incompatible with resource type '%s'", key, resource));
                 }
             }
         }