Implement support for inner variables 33/67133/3
authorRich Tabedzki <richard.tabedzki@att.com>
Mon, 17 Sep 2018 21:34:17 +0000 (17:34 -0400)
committerRich Tabedzki <richard.tabedzki@att.com>
Tue, 18 Sep 2018 01:06:57 +0000 (21:06 -0400)
Changes made:
* added code that allows replacement of aai version variable in variable substitution

Change-Id: Ib2226c3ed0b308abcdcfe70797960bd32e4eaf50
Issue-ID: CCSDK-580
Signed-off-by: Rich Tabedzki <richard.tabedzki@att.com>
aai-service/provider/src/main/java/org/onap/ccsdk/sli/adaptors/aai/AAIClientRESTExecutor.java
aai-service/provider/src/main/java/org/onap/ccsdk/sli/adaptors/aai/AAIDeclarations.java
aai-service/provider/src/main/java/org/onap/ccsdk/sli/adaptors/aai/AAIRequest.java
aai-service/provider/src/main/java/org/onap/ccsdk/sli/adaptors/aai/AAIServiceUtils.java
aai-service/provider/src/main/java/org/onap/ccsdk/sli/adaptors/aai/HttpMethod.java [new file with mode: 0755]
aai-service/provider/src/main/resources/aaiclient.properties
aai-service/provider/src/test/resources/aaiclient.properties

index 0050afb..d362d0e 100755 (executable)
@@ -48,7 +48,6 @@ import javax.net.ssl.KeyManagerFactory;
 import javax.net.ssl.SSLContext;
 import javax.net.ssl.SSLSession;
 import javax.net.ssl.SSLSocketFactory;
-import javax.ws.rs.HttpMethod;
 
 import org.apache.commons.codec.binary.Base64;
 import org.onap.ccsdk.sli.adaptors.aai.AAIService.TransactionIdTracker;
@@ -63,8 +62,6 @@ import org.slf4j.LoggerFactory;
 
 import com.fasterxml.jackson.databind.DeserializationFeature;
 import com.fasterxml.jackson.databind.ObjectMapper;
-import com.sun.jersey.api.client.config.DefaultClientConfig;
-import com.sun.jersey.client.urlconnection.HTTPSProperties;
 import org.apache.http.impl.EnglishReasonPhraseCatalog;
 
 /**
@@ -132,7 +129,6 @@ public class AAIClientRESTExecutor implements AAIExecutorInterface {
 
         if(keystorePath != null && keystorePassword != null && (new File(keystorePath)).exists())
         {
-            DefaultClientConfig config = new DefaultClientConfig();
             //both jersey and HttpURLConnection can use this
             SSLContext ctx = null;
             try {
@@ -159,12 +155,6 @@ public class AAIClientRESTExecutor implements AAIExecutorInterface {
                 }
 
                 ctx.init(kmf.getKeyManagers(), null, null);
-                config.getProperties().put(HTTPSProperties.PROPERTY_HTTPS_PROPERTIES, new HTTPSProperties( new HostnameVerifier() {
-                        @Override
-                        public boolean verify( String s, SSLSession sslSession ) {
-                            return ignoreCertificateHostError;
-                        }
-                }, ctx));
 
                 CTX = ctx;
                 LOG.debug("SSLContext created");
@@ -261,6 +251,7 @@ public class AAIClientRESTExecutor implements AAIExecutorInterface {
                responseMessage = con.getResponseMessage();
             } catch(Exception exc) {
                responseMessage = EnglishReasonPhraseCatalog.INSTANCE.getReason(responseCode,null);
+            } finally {
                if(responseMessage == null)
                        responseMessage = NOT_PROVIDED;
             }
@@ -402,6 +393,7 @@ public class AAIClientRESTExecutor implements AAIExecutorInterface {
                responseMessage = con.getResponseMessage();
             } catch(Exception exc) {
                responseMessage = EnglishReasonPhraseCatalog.INSTANCE.getReason(responseCode,null);
+            } finally {
                if(responseMessage == null)
                        responseMessage = NOT_PROVIDED;
             }
@@ -483,6 +475,7 @@ public class AAIClientRESTExecutor implements AAIExecutorInterface {
                responseMessage = conn.getResponseMessage();
             } catch(Exception exc) {
                responseMessage = EnglishReasonPhraseCatalog.INSTANCE.getReason(responseCode,null);
+            } finally {
                if(responseMessage == null)
                        responseMessage = NOT_PROVIDED;
             }
@@ -564,6 +557,7 @@ public class AAIClientRESTExecutor implements AAIExecutorInterface {
                responseMessage = con.getResponseMessage();
             } catch(Exception exc) {
                responseMessage = EnglishReasonPhraseCatalog.INSTANCE.getReason(responseCode,null);
+            } finally {
                if(responseMessage == null)
                        responseMessage = NOT_PROVIDED;
             }
@@ -638,6 +632,7 @@ public class AAIClientRESTExecutor implements AAIExecutorInterface {
                responseMessage = con.getResponseMessage();
             } catch(Exception exc) {
                responseMessage = EnglishReasonPhraseCatalog.INSTANCE.getReason(responseCode,null);
+            } finally {
                if(responseMessage == null)
                        responseMessage = NOT_PROVIDED;
             }
index 9943589..aa16ef3 100755 (executable)
@@ -102,6 +102,8 @@ public abstract class AAIDeclarations implements AAIClient {
 
     public static final String TARGET_URI         = "org.onap.ccsdk.sli.adaptors.aai.uri";
 
+    public static final String AAI_VERSION          = "org.onap.ccsdk.sli.adaptors.aai.version";
+
     // Availability zones query
     public static final String QUERY_PATH         = "org.onap.ccsdk.sli.adaptors.aai.path.query";
 
@@ -137,6 +139,8 @@ public abstract class AAIDeclarations implements AAIClient {
     // node query (1602)
     public static final String QUERY_NODES_PATH          = "org.onap.ccsdk.sli.adaptors.aai.query.nodes";
 
+    private static final String VERSION_PATTERN = "/v$/";
+
 
     protected abstract Logger getLogger();
     public abstract AAIExecutorInterface getExecutor();
@@ -1264,7 +1268,7 @@ public abstract class AAIDeclarations implements AAIClient {
                     getLogger().debug("About to process related link of {}", relatedLink);
                     if(relatedLink != null) {
                         if(relatedLink.contains("v$"))
-                            relatedLink = relatedLink.replace("v$", "v14");
+                            relatedLink = relatedLink.replace(VERSION_PATTERN, "/v14/");
                         relationship.setRelatedLink(relatedLink);
                     } else {
                         Map<String, String> relParams = new HashMap<>();
@@ -1553,7 +1557,7 @@ public abstract class AAIDeclarations implements AAIClient {
 
                 if (relatedLink != null) {
                     if(relatedLink.contains("v$"))
-                        relatedLink = relatedLink.replace("v$", "v14");
+                        relatedLink = relatedLink.replace(VERSION_PATTERN,  AAIRequest.getSupportedAAIVersion());
                     relationship.setRelatedLink(relatedLink);
                 } else {
                     Map<String, String> relParams = new HashMap<>();
@@ -1753,7 +1757,7 @@ public abstract class AAIDeclarations implements AAIClient {
 
     private QueryStatus processDeleteRelationshipList(String resource, String key, SvcLogicContext ctx, HashMap<String, String> nameValues) {
         try {
-            AAIRequest request = AAIRequest.createRequest(resource, nameValues);
+            AAIRequest request = AAIRequest.createRequest(resource.split(":")[0], nameValues);
             if(request == null) {
                 return QueryStatus.FAILURE;
             }
index 7ac9423..b621564 100755 (executable)
@@ -32,6 +32,7 @@ import java.net.URISyntaxException;
 import java.net.URL;
 import java.net.URLDecoder;
 import java.net.URLEncoder;
+import java.nio.charset.StandardCharsets;
 import java.util.ArrayList;
 import java.util.Arrays;
 import java.util.BitSet;
@@ -173,7 +174,7 @@ public abstract class AAIRequest {
             }
 
             InputStream in = url.openStream();
-            Reader reader = new InputStreamReader(in, "UTF-8");
+            Reader reader = new InputStreamReader(in, StandardCharsets.UTF_8);
 
             Properties properties = new Properties();
             properties.load(reader);
@@ -468,4 +469,8 @@ public abstract class AAIRequest {
     public String getTargetUri() {
         return targetUri;
     }
+    public static final String getSupportedAAIVersion() {
+        return configProperties.getProperty(AAIDeclarations.AAI_VERSION, "/v14/");
+    }
 }
index 10aec46..6af9f9c 100755 (executable)
@@ -48,6 +48,8 @@ import org.slf4j.LoggerFactory;
 
 public class AAIServiceUtils {
 
+    private static final String VERSION_PATTERN = "/v$/";
+
     private static final Logger LOG = LoggerFactory.getLogger(AAIService.class);
 
     private AAIServiceUtils() {
@@ -191,7 +193,13 @@ public class AAIServiceUtils {
         if (term.startsWith("$") && (ctx != null)) {
             // Resolve any index variables.
 
-            return ("'" + resolveCtxVariable(term.substring(1), ctx) + "'");
+            term = ("'" + resolveCtxVariable(term.substring(1), ctx) + "'");
+            if (term.contains(VERSION_PATTERN) && (ctx != null)) {
+                return term.replace(VERSION_PATTERN, AAIRequest.getSupportedAAIVersion());
+            }
+            return term;
+        } else if (term.contains(VERSION_PATTERN) && (ctx != null)) {
+            return term.replace(VERSION_PATTERN, AAIRequest.getSupportedAAIVersion());
         } else if (term.startsWith("'") || term.startsWith("\"")) {
             return (term);
         } else {
diff --git a/aai-service/provider/src/main/java/org/onap/ccsdk/sli/adaptors/aai/HttpMethod.java b/aai-service/provider/src/main/java/org/onap/ccsdk/sli/adaptors/aai/HttpMethod.java
new file mode 100755 (executable)
index 0000000..28d79cf
--- /dev/null
@@ -0,0 +1,10 @@
+package org.onap.ccsdk.sli.adaptors.aai;
+
+public interface HttpMethod {
+    public static final String GET = "GET";
+    public static final String HEAD = "HEAD";
+    public static final String PATCH = "PATCH";
+    public static final String POST = "POST";
+    public static final String PUT = "PUT";
+    public static final String DELETE = "DELETE";
+}
index 3d803c1..d23078d 100755 (executable)
@@ -41,6 +41,9 @@ org.onap.ccsdk.sli.adaptors.aai.uri=https://aai.api.simpledemo.onap.org:8443
 connection.timeout=60000
 read.timeout=60000
 
+# aai version
+org.onap.ccsdk.sli.adaptors.aai.version=/v14/
+
 # query
 org.onap.ccsdk.sli.adaptors.aai.path.query=/aai/v14/search/sdn-zone-query
 org.onap.ccsdk.sli.adaptors.aai.query.nodes=/aai/v14/search/nodes-query?search-node-type={node-type}&filter={entity-identifier}:EQUALS:{entity-name}
index 3d803c1..d23078d 100755 (executable)
@@ -41,6 +41,9 @@ org.onap.ccsdk.sli.adaptors.aai.uri=https://aai.api.simpledemo.onap.org:8443
 connection.timeout=60000
 read.timeout=60000
 
+# aai version
+org.onap.ccsdk.sli.adaptors.aai.version=/v14/
+
 # query
 org.onap.ccsdk.sli.adaptors.aai.path.query=/aai/v14/search/sdn-zone-query
 org.onap.ccsdk.sli.adaptors.aai.query.nodes=/aai/v14/search/nodes-query?search-node-type={node-type}&filter={entity-identifier}:EQUALS:{entity-name}