improved handling of indexed data
[ccsdk/sli/adaptors.git] / aai-service / provider / src / main / java / org / onap / ccsdk / sli / adaptors / aai / AAIServiceUtils.java
index 10aec46..3bd6ac4 100755 (executable)
@@ -5,6 +5,8 @@
  * Copyright (C) 2017 AT&T Intellectual Property. All rights
  *             reserved.
  * ================================================================================
+ * Modifications Copyright (C) 2018 IBM.
+ * ================================================================================
  * Licensed under the Apache License, Version 2.0 (the "License");
  * you may not use this file except in compliance with the License.
  * You may obtain a copy of the License at
  * limitations under the License.
  * ============LICENSE_END=========================================================
  */
-
+/**
+ * @author Rich Tabedzki
+ *
+ */
 package org.onap.ccsdk.sli.adaptors.aai;
 
 import java.lang.annotation.Annotation;
@@ -48,6 +53,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() {
@@ -151,7 +158,7 @@ public class AAIServiceUtils {
         String term1 = null;
         String op = null;
         String term2 = null;
-        HashMap<String, String> results = new HashMap<String, String>();
+        HashMap<String, String> results = new HashMap<>();
 
         for (int i = 0; i < keyTerms.length; i++) {
             if (term1 == null) {
@@ -191,7 +198,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 {
@@ -259,7 +272,7 @@ public class AAIServiceUtils {
     }
 
     protected static HashMap<String,String> pathToHashMap(String path) {
-        HashMap<String, String> nameValues = new  HashMap<String, String>();
+        HashMap<String, String> nameValues = new  HashMap<>();
 
         String[] split = path.split("/");