Fixed rewrite redundancy in collection rewrite.

Change-Id: Id3c4744449064e21f02d682fe62bc07dc6201a6f
diff --git a/full/src/main/java/de/ids_mannheim/korap/authentication/KustvaktAuthenticationManager.java b/full/src/main/java/de/ids_mannheim/korap/authentication/KustvaktAuthenticationManager.java
index 7ee3506..60c3126 100644
--- a/full/src/main/java/de/ids_mannheim/korap/authentication/KustvaktAuthenticationManager.java
+++ b/full/src/main/java/de/ids_mannheim/korap/authentication/KustvaktAuthenticationManager.java
@@ -231,13 +231,11 @@
 					corpusAccess = CorpusAccess.PUB;
 				}
 				
-				if (DEBUG_LOG == true) {
-					System.out.printf("Debug: X-Forwarded-For : '%s' (%d values) -> %s\n", 
-							Arrays.toString(vals), vals.length, vals[0]);
-					System.out.printf("Debug: X-Forwarded-For : location = %s corpusAccess = %s\n",
-							location == Location.INTERN ? "INTERN" : "EXTERN", corpusAccess == CorpusAccess.ALL ? "ALL"
-									: corpusAccess == CorpusAccess.PUB ? "PUB" : "FREE");
-				}
+			    jlog.debug(String.format("X-Forwarded-For : '%s' (%d values) -> %s\n", 
+						Arrays.toString(vals), vals.length, vals[0]));
+			    jlog.debug(String.format("X-Forwarded-For : location = %s corpusAccess = %s\n",
+						location == Location.INTERN ? "INTERN" : "EXTERN", corpusAccess == CorpusAccess.ALL ? "ALL"
+								: corpusAccess == CorpusAccess.PUB ? "PUB" : "FREE"));
 
 			} catch (UnknownHostException e) {
 				// TODO Auto-generated catch block
diff --git a/full/src/main/resources/log4j.properties b/full/src/main/resources/log4j.properties
index 308c9ca..7f9c1ca 100644
--- a/full/src/main/resources/log4j.properties
+++ b/full/src/main/resources/log4j.properties
@@ -6,7 +6,7 @@
 
 #log4j.logger.de.ids_mannheim.korap.service.VirtualCorpusService = error, debugLog
 #log4j.logger.de.ids_mannheim.korap.web.controller.AuthenticationController = debug, debugLog, stdout
-
+log4j.logger.de.ids_mannheim.korap.resource.rewrite.CollectionRewrite= stdout, debugLog
 
 # Direct log messages to stdout
 log4j.appender.stdout=org.apache.log4j.ConsoleAppender
@@ -36,4 +36,4 @@
 
 
 log4j.logger.de.ids_mannheim.korap.security.ac = ERROR, policyLog
-log4j.logger.de.ids_mannheim.korap.security.auth = ERROR, authLog
\ No newline at end of file
+log4j.logger.de.ids_mannheim.korap.authentication = debug, authLog
\ No newline at end of file
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 7328064..cf19694 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
@@ -64,21 +64,17 @@
                 node.at("/collection/rewrites/0/scope").asText());
     }
 
-    private void checkAndPublicWithoutACA (String json)
+    private void checkAndPublicWithACA (String json)
             throws KustvaktException {
         JsonNode node = JsonUtils.readTree(json);
         assertNotNull(node);
         assertEquals("operation:and",
                 node.at("/collection/operation").asText());
-        assertEquals("match:eq",
-                node.at("/collection/operands/0/match").asText());
-        assertEquals("type:regex",
-                node.at("/collection/operands/0/type").asText());
-        assertEquals("availability",
-                node.at("/collection/operands/0/key").asText());
-        assertEquals("CC-BY.*",
-                node.at("/collection/operands/0/value").asText());
-
+        assertEquals("operation:insertion",
+                node.at("/collection/rewrites/0/operation").asText());
+        assertEquals("availability(PUB)",
+                node.at("/collection/rewrites/0/scope").asText());
+        
         assertEquals("match:eq",
                 node.at("/collection/operands/1/match").asText());
         assertEquals("type:regex",
@@ -86,11 +82,26 @@
         assertEquals("availability",
                 node.at("/collection/operands/1/key").asText());
         assertEquals("ACA.*", node.at("/collection/operands/1/value").asText());
+        
+        node = node.at("/collection/operands/0");
+        assertEquals("match:eq",
+                node.at("/operands/0/match").asText());
+        assertEquals("type:regex",
+                node.at("/operands/0/type").asText());
+        assertEquals("availability",
+                node.at("/operands/0/key").asText());
+        assertEquals("CC-BY.*",
+                node.at("/operands/0/value").asText());
 
-        assertEquals("operation:insertion",
-                node.at("/collection/rewrites/0/operation").asText());
-        assertEquals("availability(PUB)",
-                node.at("/collection/rewrites/0/scope").asText());
+        assertEquals("match:eq",
+                node.at("/operands/1/match").asText());
+        assertEquals("type:regex",
+                node.at("/operands/1/type").asText());
+        assertEquals("availability",
+                node.at("/operands/1/key").asText());
+        assertEquals("ACA.*", node.at("/operands/1/value").asText());
+
+        
     }
 
     private void checkAndAll (String json) throws KustvaktException {
@@ -122,27 +133,39 @@
 
     }
 
-    private void checkAndAllWithoutACA (String json) throws KustvaktException {
+    private void checkAndAllWithACA (String json) throws KustvaktException {
         JsonNode node = JsonUtils.readTree(json);
         assertNotNull(node);
         assertEquals("operation:and",
                 node.at("/collection/operation").asText());
-        assertEquals("match:eq",
-                node.at("/collection/operands/0/operands/0/match").asText());
-        assertEquals("type:regex",
-                node.at("/collection/operands/0/operands/0/type").asText());
-        assertEquals("availability",
-                node.at("/collection/operands/0/operands/0/key").asText());
-        assertEquals("CC-BY.*",
-                node.at("/collection/operands/0/operands/0/value").asText());
-        assertEquals("match:eq",
-                node.at("/collection/operands/0/operands/1/match").asText());
-        assertEquals("QAO.*",
-                node.at("/collection/operands/0/operands/1/value").asText());
         assertEquals("operation:insertion",
                 node.at("/collection/rewrites/0/operation").asText());
         assertEquals("availability(ALL)",
                 node.at("/collection/rewrites/0/scope").asText());
+        
+        assertEquals("match:eq",
+                node.at("/collection/operands/1/match").asText());
+        assertEquals("type:regex",
+                node.at("/collection/operands/1/type").asText());
+        assertEquals("availability",
+                node.at("/collection/operands/1/key").asText());
+        assertEquals("ACA.*", node.at("/collection/operands/1/value").asText());
+        
+        node = node.at("/collection/operands/0");
+        
+        assertEquals("match:eq",
+                node.at("/operands/0/match").asText());
+        assertEquals("type:regex",
+                node.at("/operands/0/type").asText());
+        assertEquals("availability",
+                node.at("/operands/0/key").asText());
+        assertEquals("CC-BY.*",
+                node.at("/operands/0/value").asText());
+        assertEquals("match:eq",
+                node.at("/operands/1/operands/1/match").asText());
+        assertEquals("QAO.*",
+                node.at("/operands/1/operands/1/value").asText());
+        
     }
 
 
@@ -350,7 +373,7 @@
         assertEquals(ClientResponse.Status.OK.getStatusCode(),
                 response.getStatus());
 
-        checkAndPublicWithoutACA(response.getEntity(String.class));
+        checkAndPublicWithACA(response.getEntity(String.class));
     }
 
 
@@ -412,7 +435,7 @@
         assertEquals(ClientResponse.Status.OK.getStatusCode(),
                 response.getStatus());
 
-        checkAndAllWithoutACA(response.getEntity(String.class));
+        checkAndAllWithACA(response.getEntity(String.class));
     }
 
 }