Merge "VOL-543:  Provision for specifying urls where subscriber id is not at the end"
diff --git a/README.md b/README.md
index 4383fa2..b83c394 100644
--- a/README.md
+++ b/README.md
@@ -47,3 +47,51 @@
 each instance of ONOS in a cluster might have a different set of objects in its
 cache. The thought behind this is that each instance in a cluster will be a
 master for a different set of devices and thus needs different information.
+
+
+### Configuration Paramters
+```
+"org.opencord.sadis" : {
+      "sadis" : {
+        "integration" : {
+          "url": "http://localhost/src/test/resources/%s",
+          "cache" : {
+            "maxsize" : 50,
+            "ttl" : "PT1m"
+          }
+        },
+        "entries" : [ {
+          "id" : "uni-1",
+          "cTag" : 2,
+          "sTag" : 2,
+          "nasPortId" : "PON 1",
+          "circuitId" : "VOLT-1",
+        }, {
+          "id" : "211702604597",
+          "hardwareIdentifier" : "00:1e:67:d2:ef:66",
+          "ipAddress" : "144.60.34.89",
+          "nasId" : "66"
+        }]
+      }
+    }
+```
+* __url__ - A url using which the subscriber and device data can be fetched. It is mandatory to have a `%s` in the url which will be substituted with the id for that subscriber/device to retrieve the data.
+* __maxsize__ - Maximum number of entries that the cache may contain
+* __ttl__ - Number of seconds after last access at which the cache entry expires
+
+Entries can be for Subscribers and OLT Devices; they are differentiated by the id.
+If the url is specified the data for the subscribers/devices are picked from there else the local data is used.
+
+##### For a subscriber
+* __id__ - Unique identifier for the subscriber. This should match the name of the logical port name for this subscriber as can be seen from the ONOS `ports` command
+* __cTag__ - C-Tag to be used for this subscriber
+* __sTag__ - S-Tag to be used for this subscriber
+* __nasPortId__ - NAS Port Id to be used for this subscriber; for example in RADIUS messages
+* __circuitId__ - Circuit Id to be used for this subscriber; for example in DHCP messages
+
+##### For an OLT Device
+* __id__ - Unique identifier for an OLT device. This should match the serial number of the device as can be seen from the ONOS `devices` command
+* __hardwareIdentifier__ - MAC address for this device
+* __ipAddress__ - IP address of this device
+* __nasId__ - NAS Id to be used for this device; for example in RADIUS messages
+
diff --git a/app/src/main/java/org/opencord/sadis/impl/SadisConfig.java b/app/src/main/java/org/opencord/sadis/impl/SadisConfig.java
index 42a11af..eb48fe0 100644
--- a/app/src/main/java/org/opencord/sadis/impl/SadisConfig.java
+++ b/app/src/main/java/org/opencord/sadis/impl/SadisConfig.java
@@ -81,6 +81,7 @@
     private static final String SADIS_URL = "url";
     private static final String SADIS_ENTRIES = "entries";
     private static final String DEFAULT_CACHE_TTL = "PT0S";
+    private static final String SUBSCRIBER_ID_SUB_PATTERN = "%s";
 
     /**
      * Returns SADIS integration URL.
@@ -99,7 +100,11 @@
         if (url.isMissingNode()) {
             return null;
         }
-
+        StringBuffer buf = new StringBuffer(SUBSCRIBER_ID_SUB_PATTERN);
+        if (!url.asText().contains(buf)) {
+            log.error("Error in url, missing {}", SUBSCRIBER_ID_SUB_PATTERN);
+            return null;
+        }
         return new URL(url.asText());
     }
 
diff --git a/app/src/main/java/org/opencord/sadis/impl/SubscriberAndDeviceInformationAdapter.java b/app/src/main/java/org/opencord/sadis/impl/SubscriberAndDeviceInformationAdapter.java
index 5085ae8..5026e66 100644
--- a/app/src/main/java/org/opencord/sadis/impl/SubscriberAndDeviceInformationAdapter.java
+++ b/app/src/main/java/org/opencord/sadis/impl/SubscriberAndDeviceInformationAdapter.java
@@ -192,14 +192,9 @@
             }
         } else {
             // Augment URL with query parameters
-            StringBuilder buf = new StringBuilder(this.url);
-            if (buf.charAt(buf.length() - 1) != '/') {
-                buf.append('/');
-            }
+            String urlWithSubId = this.url.replaceAll("%s", id);
 
-            buf.append(id);
-
-            try (InputStream io = new URL(buf.toString()).openStream()) {
+            try (InputStream io = new URL(urlWithSubId).openStream()) {
                 info = mapper.readValue(io, SubscriberAndDeviceInformation.class);
                 local.put(id, info);
                 return info;
diff --git a/app/src/test/resources/RemoteConfig.json b/app/src/test/resources/RemoteConfig.json
index b708fbc..e2c798f 100644
--- a/app/src/test/resources/RemoteConfig.json
+++ b/app/src/test/resources/RemoteConfig.json
@@ -1,6 +1,6 @@
 {
   "integration": {
-    "url": "file:src/test/resources",
+    "url": "file:src/test/resources/%s",
     "cache": {
       "maxsize": 50,
       "ttl": "PT1m"