Enabled definition of multiple license regex in kustvakt.conf.

Change-Id: I1ca43049de8b9a8994bd7451c8c65e94841b40f7
diff --git a/full/src/main/java/de/ids_mannheim/korap/rewrite/CollectionRewrite.java b/full/src/main/java/de/ids_mannheim/korap/rewrite/CollectionRewrite.java
index 57f92db..44388dd 100644
--- a/full/src/main/java/de/ids_mannheim/korap/rewrite/CollectionRewrite.java
+++ b/full/src/main/java/de/ids_mannheim/korap/rewrite/CollectionRewrite.java
@@ -164,15 +164,38 @@
 
     private String buildAvailability (List<String> userAvailabilities) {
         StringBuilder sb = new StringBuilder();
-        for (int i = 0; i < userAvailabilities.size() - 1; i++) {
-            sb.append("availability=/");
-            sb.append(userAvailabilities.get(i));
-            sb.append("/ | ");
+        for (int i = 0; i < userAvailabilities.size(); i++) {
+            parseAvailability(sb, userAvailabilities.get(i), "|");
         }
-        sb.append("availability=/");
-        sb.append(userAvailabilities.get(userAvailabilities.size() - 1));
-        sb.append("/");
-        return sb.toString();
+        String availabilities = sb.toString(); 
+        return availabilities.substring(0, availabilities.length()-3);
     }
+    
+    private void parseAvailability (StringBuilder sb, String availability, String operator) {
+        String uaArr[] = null;
+        if (availability.contains("|")){
+            uaArr = availability.split("\\|");
+            for (int j=0; j < uaArr.length; j++){
+                parseAvailability(sb, uaArr[j].trim(), "|");
+            }
+        }
+        // EM: not supported
+//        else if (availability.contains("&")){
+//            uaArr = availability.split("&");
+//            for (int j=0; j < uaArr.length -1; j++){
+//                parseAvailability(sb, uaArr[j], "&");
+//            }
+//            parseAvailability(sb, uaArr[uaArr.length-1], "|");
+//        } 
+        else{
+            sb.append("availability=/");
+            sb.append(availability);
+            sb.append("/ ");
+            sb.append(operator);
+            sb.append(" ");
+        }
+
+    }
+    
 }
 
diff --git a/full/src/main/resources/kustvakt.conf b/full/src/main/resources/kustvakt.conf
index 338c726..8e8a59c 100644
--- a/full/src/main/resources/kustvakt.conf
+++ b/full/src/main/resources/kustvakt.conf
@@ -19,7 +19,7 @@
 
 ## availability regex
 availability.regex.free = CC-BY.*
-availability.regex.public = ACA.*
+availability.regex.public = ACA.* | QAO.NC
 availability.regex.all = QAO.*
 
 kustvakt.management.registration=enable
diff --git a/full/src/test/java/de/ids_mannheim/korap/web/service/full/SearchServiceTest.java b/full/src/test/java/de/ids_mannheim/korap/web/service/full/SearchServiceTest.java
index de7e93d..376bcfb 100644
--- a/full/src/test/java/de/ids_mannheim/korap/web/service/full/SearchServiceTest.java
+++ b/full/src/test/java/de/ids_mannheim/korap/web/service/full/SearchServiceTest.java
@@ -155,7 +155,8 @@
         assertEquals("koral:docGroup", node.at("/collection/@type").asText());
         assertEquals("CC-BY.*",
                 node.at("/collection/operands/0/value").asText());
-        assertEquals("ACA.*", node.at("/collection/operands/1/value").asText());
+        assertEquals("ACA.*", node.at("/collection/operands/1/operands/0/value").asText());
+        assertEquals("QAO-NC", node.at("/collection/operands/1/operands/1/value").asText());
         assertEquals("operation:or", node.at("/collection/operation").asText());
         assertEquals("availability(PUB)",
                 node.at("/collection/rewrites/0/scope").asText());
diff --git a/full/src/test/java/de/ids_mannheim/korap/web/service/full/SearchWithAvailabilityTest.java b/full/src/test/java/de/ids_mannheim/korap/web/service/full/SearchWithAvailabilityTest.java
index 5bc1ac4..dad8f99 100644
--- a/full/src/test/java/de/ids_mannheim/korap/web/service/full/SearchWithAvailabilityTest.java
+++ b/full/src/test/java/de/ids_mannheim/korap/web/service/full/SearchWithAvailabilityTest.java
@@ -55,9 +55,13 @@
         assertEquals("CC-BY.*",
                 node.at("/collection/operands/0/operands/0/value").asText());
         assertEquals("match:eq",
-                node.at("/collection/operands/0/operands/1/match").asText());
+                node.at("/collection/operands/0/operands/1/operands/0/match").asText());
         assertEquals("ACA.*",
-                node.at("/collection/operands/0/operands/1/value").asText());
+                node.at("/collection/operands/0/operands/1/operands/0/value").asText());
+        assertEquals("match:eq",
+                node.at("/collection/operands/0/operands/1/operands/1/match").asText());
+        assertEquals("QAO-NC",
+                node.at("/collection/operands/0/operands/1/operands/1/value").asText());
         assertEquals("operation:insertion",
                 node.at("/collection/rewrites/0/operation").asText());
         assertEquals("availability(PUB)",
@@ -94,12 +98,12 @@
                 node.at("/operands/0/value").asText());
 
         assertEquals("match:eq",
-                node.at("/operands/1/match").asText());
+                node.at("/operands/1/operands/0/match").asText());
         assertEquals("type:regex",
-                node.at("/operands/1/type").asText());
+                node.at("/operands/1/operands/0/type").asText());
         assertEquals("availability",
-                node.at("/operands/1/key").asText());
-        assertEquals("ACA.*", node.at("/operands/1/value").asText());
+                node.at("/operands/1/operands/0/key").asText());
+        assertEquals("ACA.*", node.at("/operands/1/operands/0/value").asText());
 
         
     }
@@ -162,9 +166,13 @@
         assertEquals("CC-BY.*",
                 node.at("/operands/0/value").asText());
         assertEquals("match:eq",
-                node.at("/operands/1/operands/1/match").asText());
+                node.at("/operands/1/operands/1/operands/0/match").asText());
+        assertEquals("QAO-NC",
+                node.at("/operands/1/operands/1/operands/0/value").asText());
+        assertEquals("match:eq",
+                node.at("/operands/1/operands/1/operands/1/match").asText());
         assertEquals("QAO.*",
-                node.at("/operands/1/operands/1/value").asText());
+                node.at("/operands/1/operands/1/operands/1/value").asText());
         
     }
 
diff --git a/full/src/test/resources/kustvakt-test.conf b/full/src/test/resources/kustvakt-test.conf
index 04e00b8..b16b08e 100644
--- a/full/src/test/resources/kustvakt-test.conf
+++ b/full/src/test/resources/kustvakt-test.conf
@@ -24,7 +24,7 @@
 
 ## availability regex
 availability.regex.free = CC-BY.*
-availability.regex.public = ACA.*
+availability.regex.public = ACA.* | QAO-NC
 availability.regex.all = QAO.*
 
 kustvakt.management.registration=enable