minor updates to clean up code 76/97976/1
authorAgarwal, Ruchira (ra1926) <ra1926@att.com>
Tue, 5 Nov 2019 18:16:50 +0000 (18:16 +0000)
committerAgarwal, Ruchira (ra1926) <ra1926@att.com>
Tue, 5 Nov 2019 18:16:50 +0000 (18:16 +0000)
clean up code to sync with internal

Issue-ID: CCSDK-1873
Signed-off-by: Agarwal, Ruchira (ra1926) <ra1926@att.com>
Change-Id: Idcc7186d5aaa783c527de3986e7a1ecd9bfcf651

15 files changed:
aai-service/provider/pom.xml
aai-service/provider/src/main/java/org/onap/ccsdk/sli/adaptors/aai/AAIClient.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/GenericRequest.java
aai-service/provider/src/test/java/org/onap/ccsdk/sli/adaptors/aai/EchoRequestTest.java
ansible-adapter/ansible-adapter-bundle/pom.xml
ansible-adapter/ansible-adapter-features/ccsdk-ansible-adapter/pom.xml
base/http/provider/pom.xml
base/http/provider/src/main/java/org/onap/ccsdk/sli/adaptors/base/http/BasicAuthFilter.java
base/http/provider/src/test/java/org/onap/ccsdk/sli/adaptors/base/http/BasicAuthFilterTest.java
mdsal-resource/features/ccsdk-mdsal-resource/pom.xml
mdsal-resource/provider/src/main/java/org/onap/ccsdk/sli/adaptors/resource/mdsal/RestService.java
netbox-client/features/ccsdk-netbox-client/pom.xml
netbox-client/provider/pom.xml
sql-resource/provider/src/main/java/org/onap/ccsdk/sli/adaptors/resource/sql/SqlResource.java

index 9650087..f63bc42 100755 (executable)
             <groupId>org.springframework</groupId>
             <artifactId>spring-core</artifactId>
             <scope>test</scope>
-        </dependency>
-         <dependency>
-            <groupId>org.apache.httpcomponents</groupId>
-            <artifactId>httpcore</artifactId>
         </dependency>
         <dependency>
             <groupId>org.apache.httpcomponents</groupId>
             <plugin>
                 <groupId>org.jvnet.jaxb2.maven2</groupId>
                 <artifactId>maven-jaxb2-plugin</artifactId>
-                <version>0.13.1</version>
+               <version>0.14.0</version>
                 <executions>
                     <execution>
                         <id>gen-xjc</id>
                         <plugin>
                             <groupId>org.jvnet.jaxb2_commons</groupId>
                             <artifactId>jaxb2-basics-annotate</artifactId>
-                            <version>0.6.4</version>
+                            <version>0.6.5</version>
                         </plugin>
                     </plugins>
                 </configuration>
index 4b4c439..28b4955 100755 (executable)
@@ -37,6 +37,9 @@ import org.onap.ccsdk.sli.core.sli.SvcLogicJavaPlugin;
 import org.onap.ccsdk.sli.core.sli.SvcLogicResource;
 import org.onap.ccsdk.sli.adaptors.aai.data.notify.NotifyEvent;
 
+import com.fasterxml.jackson.core.JsonParseException;
+import com.fasterxml.jackson.databind.JsonMappingException;
+
 public interface AAIClient extends SvcLogicResource, SvcLogicJavaPlugin {
 
     public SearchResults requestServiceInstanceURL(String svcInstanceId) throws AAIServiceException;
@@ -76,7 +79,7 @@ public interface AAIClient extends SvcLogicResource, SvcLogicJavaPlugin {
 
     public void logKeyError(String keys);
 
-    public QueryStatus processResponseData(String rv, String resource, AAIRequest request, String prefix,  SvcLogicContext ctx, Map<String, String> nameValues, String modifier) throws IOException, AAIServiceException ;
+    public QueryStatus processResponseData(String rv, String resource, AAIRequest request, String prefix,  SvcLogicContext ctx, Map<String, String> nameValues, String modifier) throws JsonParseException, JsonMappingException, IOException, AAIServiceException ;
     public String getPathTemplateForResource(String resoourceName, String join, SvcLogicContext ctx) throws MalformedURLException;
     public boolean isDeprecatedFormat(String resource, Map<String, String> nameValues);
 
index c57b3a4..8b8aaaa 100755 (executable)
@@ -1636,6 +1636,7 @@ public abstract class AAIDeclarations implements AAIClient {
                 try {
                     obj = getMetadataMethod.invoke(instance);
                 } catch (InvocationTargetException x) {
+                   Throwable cause = x.getCause();
                 }
             }
             if(obj != null && obj instanceof Metadata){
index 7c6234e..7f15c03 100755 (executable)
@@ -189,9 +189,13 @@ public class GenericRequest extends AAIRequest {
 
                             queryParams.put(splitKey[1], encodeQuery(value));
                         } else {
-                            String token = String.format("%s/{%s}", splitKey[0], splitKey[1]);
-                            String encoded_vnf = encodeQuery(value);
-                            request_url = request_url.replace(token, String.format("%s/%s", splitKey[0], encoded_vnf));
+                               String encoded_vnf = encodeQuery(value);
+                               if(!resourceName.equals(splitKey[0]) && resourceName.contains(splitKey[0])) {
+                                       queryParams.put(splitKey[1], encoded_vnf);
+                               } else {
+                                       String token = String.format("%s/{%s}", splitKey[0], splitKey[1]);
+                                       request_url = request_url.replace(token, String.format("%s/%s", splitKey[0], encoded_vnf));
+                               }
                         }
                     }
 
index 6954130..3e0a72f 100755 (executable)
@@ -34,6 +34,8 @@ import org.junit.FixMethodOrder;
 import org.junit.Test;
 import org.junit.runners.MethodSorters;
 import org.onap.ccsdk.sli.adaptors.aai.data.AAIDatum;
+import org.onap.ccsdk.sli.core.sli.SvcLogicContext;
+import org.onap.ccsdk.sli.core.sli.SvcLogicResource.QueryStatus;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
@@ -111,4 +113,24 @@ public class EchoRequestTest {
         }
 
     }
+    
+//     @Test
+       public void EchoTest() {
+               LOG.info("----------------------- Test: " + new Object(){}.getClass().getEnclosingMethod().getName() + " -----------------------");
+               try
+               {
+                       SvcLogicContext ctx = new SvcLogicContext();
+                       
+                       QueryStatus resp = null;
+
+//                 (String resource, boolean localOnly, String select, String key, String prefix, String orderBy, SvcLogicContext ctx)
+                       resp = aaiService.query("echo", false, null, "",        "aaidata", null, ctx);
+                       assert(resp == QueryStatus.SUCCESS);
+               }
+               catch (Throwable e)
+               {
+                       LOG.error("Caught exception", e);
+//                     fail("Caught exception");
+               }
+       }
 }
index c73018b..614fe6d 100644 (file)
                <dependency>
                        <groupId>org.onap.ccsdk.sli.core</groupId>
                        <artifactId>sli-common</artifactId>
+                        <scope>provided</scope>
                </dependency>
 
                <dependency>
                        <groupId>org.onap.ccsdk.sli.core</groupId>
                        <artifactId>sli-provider</artifactId>
+                        <scope>provided</scope>
                </dependency>
 
                <dependency>
index bf0b5b5..523d450 100644 (file)
@@ -28,6 +28,7 @@
             <version>${ccsdk.sli.core.version}</version>
             <type>xml</type>
             <classifier>features</classifier>
+           <scope>provided</scope>
         </dependency>
 
         <dependency>
index aabeca2..642238c 100644 (file)
@@ -28,7 +28,6 @@
                <dependency>
                        <groupId>org.glassfish.jersey.core</groupId>
                        <artifactId>jersey-client</artifactId>
-                       <version>${jersey.version}</version>
                        <scope>test</scope>
                </dependency>
                <dependency>
index 48d996e..5d3d463 100644 (file)
@@ -6,13 +6,9 @@ import javax.ws.rs.client.ClientRequestContext;
 import javax.ws.rs.client.ClientRequestFilter;
 import javax.ws.rs.core.MultivaluedMap;
 
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-
 public class BasicAuthFilter implements ClientRequestFilter {
     private final String basicAuthValue;
 
-
     public BasicAuthFilter(String basicAuthValue) {
         this.basicAuthValue = basicAuthValue;
     }
@@ -21,4 +17,6 @@ public class BasicAuthFilter implements ClientRequestFilter {
         MultivaluedMap<String, Object> headers = requestContext.getHeaders();
         headers.add("Authorization", basicAuthValue);
     }
+
+
 }
index b9565ba..d9d552d 100644 (file)
@@ -8,7 +8,7 @@ public class BasicAuthFilterTest {
     
     @Test
     public void notNullParameters() throws Exception {
-        BasicAuthFilter myFilter = new BasicAuthFilter("helloworld");
+        BasicAuthFilter myFilter = new BasicAuthFilter("hello");
         assertNotNull(myFilter);
     }
     
index 41b0ef3..ab512ed 100644 (file)
@@ -29,6 +29,7 @@
             <version>${ccsdk.sli.core.version}</version>
             <type>xml</type>
             <classifier>features</classifier>
+            <scope>provided</scope>
         </dependency>
 
         <dependency>
index 2991e6b..30859a4 100644 (file)
@@ -34,6 +34,7 @@ import java.net.URL;
 import javax.net.ssl.HostnameVerifier;
 import javax.net.ssl.HttpsURLConnection;
 import javax.net.ssl.SSLSession;
+import javax.xml.XMLConstants;
 import javax.xml.parsers.DocumentBuilder;
 import javax.xml.parsers.DocumentBuilderFactory;
 
@@ -180,9 +181,11 @@ public class RestService {
             LOG.info("Response body :\n"+respString);
 
             DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
+            dbf.setFeature(XMLConstants.FEATURE_SECURE_PROCESSING, true);  
+            dbf.setFeature("http://xml.org/sax/features/external-general-entities", false); 
+            dbf.setFeature("http://xml.org/sax/features/external-parameter-entities", false);
             DocumentBuilder db = dbf.newDocumentBuilder();
 
-
             response = db.parse(new ByteArrayInputStream(respString.getBytes()));
 
         } catch (Exception e) {
index e006b19..13dc8bf 100644 (file)
 
 
     <dependencies>
-        <dependency>
-            <groupId>org.opendaylight.controller</groupId>
-            <artifactId>odl-mdsal-broker</artifactId>
-            <type>xml</type>
-            <classifier>features</classifier>
-        </dependency>
 
         <dependency>
             <groupId>org.onap.ccsdk.sli.core</groupId>
@@ -51,6 +45,7 @@
             <version>${ccsdk.sli.core.version}</version>
             <type>xml</type>
             <classifier>features</classifier>
+           <scope>provided</scope>
         </dependency>
 
         <dependency>
@@ -59,6 +54,7 @@
             <version>${ccsdk.sli.core.version}</version>
             <type>xml</type>
             <classifier>features</classifier>
+           <scope>provided</scope>
         </dependency>
 
         <dependency>
index 475eeb5..b8fa494 100644 (file)
         <dependency>
             <groupId>org.onap.ccsdk.sli.core</groupId>
             <artifactId>sli-common</artifactId>
-            <scope>compile</scope>
+            <scope>provided</scope>
         </dependency>
         <dependency>
             <groupId>org.onap.ccsdk.sli.core</groupId>
             <artifactId>sliPluginUtils-provider</artifactId>
-            <version>${project.version}</version>
-            <scope>compile</scope>
+           <version>${ccsdk.sli.core.version}</version>
+            <scope>provided</scope>
         </dependency>
         <dependency>
             <groupId>org.osgi</groupId>
         <dependency>
             <groupId>com.github.tomakehurst</groupId>
             <artifactId>wiremock</artifactId>
-            <version>2.23.2</version>
+           <version>2.23.2</version>
             <scope>test</scope>
         </dependency>
         <dependency>
index 767fdac..69965d1 100755 (executable)
@@ -100,7 +100,7 @@ public class SqlResource implements SvcLogicResource, SvcLogicJavaPlugin {
             return (QueryStatus.FAILURE);
         }
 
-        String theStmt = resolveCtxVars(key, ctx);
+        String theStmt = resolveCtxVars(key, ctx, resource);
 
         try {
             CachedRowSet results = dblibSvc.getData(theStmt, null, null);
@@ -131,8 +131,9 @@ public class SqlResource implements SvcLogicResource, SvcLogicJavaPlugin {
         if (dblibSvc == null) {
             return (QueryStatus.FAILURE);
         }
+       
+        String sqlQuery = resolveCtxVars(key, ctx, resource);
 
-        String sqlQuery = resolveCtxVars(key, ctx);
 
         try {
 
@@ -230,7 +231,7 @@ public class SqlResource implements SvcLogicResource, SvcLogicJavaPlugin {
             return (QueryStatus.FAILURE);
         }
 
-        String sqlStmt = resolveCtxVars(key, ctx);
+        String sqlStmt = resolveCtxVars(key, ctx, "");
 
         LOG.debug("key = [" + key + "]; sqlStmt = [" + sqlStmt + "]");
         try {
@@ -247,7 +248,7 @@ public class SqlResource implements SvcLogicResource, SvcLogicJavaPlugin {
 
     }
 
-    private String resolveCtxVars(String key, SvcLogicContext ctx) {
+    private String resolveCtxVars(String key, SvcLogicContext ctx, String resource) {
         if (key == null) {
             return (null);
         }
@@ -257,16 +258,20 @@ public class SqlResource implements SvcLogicResource, SvcLogicJavaPlugin {
             LOG.debug("Stripped outer single quotes - key is now [" + key + "]");
         }
 
-        String[] keyTerms = key.split("\\s+");
+       //"SQL-TRUE" allows for the key to be used as is.
+       if (!resource.equals("SQL-TRUE")) {
+               String[] keyTerms = key.split("\\s+");
 
-        StringBuffer sqlBuffer = new StringBuffer();
+               StringBuffer sqlBuffer = new StringBuffer();
 
-        for (int i = 0; i < keyTerms.length; i++) {
-            sqlBuffer.append(resolveTerm(keyTerms[i], ctx));
-            sqlBuffer.append(" ");
-        }
+               for (int i = 0; i < keyTerms.length; i++) {
+                       sqlBuffer.append(resolveTerm(keyTerms[i], ctx));
+                       sqlBuffer.append(" ");
+               }
+               key = sqlBuffer.toString();
+       }
 
-        return (sqlBuffer.toString());
+        return (key);
     }
 
     private String resolveTerm(String term, SvcLogicContext ctx) {
@@ -441,7 +446,7 @@ public class SqlResource implements SvcLogicResource, SvcLogicJavaPlugin {
             return (strValue);
         } else {
             ResultSet results = null;
-            try (Connection conn =  dblibSvc.getConnection();
+            try (Connection conn = dblibSvc.getConnection();
                PreparedStatement stmt = conn.prepareStatement("SELECT CAST(AES_DECRYPT(?, ?) AS CHAR(50)) FROM DUAL")) {
 
                 stmt.setBytes(1, colValue);