Updated version.
Change-Id: Ib7dd7085b1df89c80958ef2eb0a76bf74ff42959
diff --git a/core/src/main/java/de/ids_mannheim/korap/resource/rewrite/CollectionRewrite.java b/core/src/main/java/de/ids_mannheim/korap/resource/rewrite/CollectionRewrite.java
index e2e6318..8937d42 100644
--- a/core/src/main/java/de/ids_mannheim/korap/resource/rewrite/CollectionRewrite.java
+++ b/core/src/main/java/de/ids_mannheim/korap/resource/rewrite/CollectionRewrite.java
@@ -14,6 +14,7 @@
import de.ids_mannheim.korap.config.KustvaktConfiguration;
import de.ids_mannheim.korap.exceptions.KustvaktException;
import de.ids_mannheim.korap.query.object.KoralMatchOperator;
+import de.ids_mannheim.korap.query.object.KoralOperation;
import de.ids_mannheim.korap.resource.rewrite.KoralNode.RewriteIdentifier;
import de.ids_mannheim.korap.user.User;
import de.ids_mannheim.korap.utils.JsonUtils;
@@ -36,7 +37,7 @@
private List<String> checkAvailability (JsonNode node, List<String> userAvailabilities) {
- if (node.has("operands")) {
+ if (node.has("operands") && node.at("/operation").asText().equals(KoralOperation.AND.toString())) {
ArrayList<JsonNode> operands = Lists
.newArrayList(node.at("/operands").elements());
for (int i = 0; i < operands.size(); i++) {
diff --git a/full/pom.xml b/full/pom.xml
index 1bfb4af..5d2a0cf 100644
--- a/full/pom.xml
+++ b/full/pom.xml
@@ -3,7 +3,7 @@
<modelVersion>4.0.0</modelVersion>
<groupId>de.ids_mannheim.korap</groupId>
<artifactId>Kustvakt-full</artifactId>
- <version>0.59.8</version>
+ <version>0.59.9</version>
<properties>
<java.version>1.7</java.version>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
diff --git a/full/src/main/resources/kustvakt.conf b/full/src/main/resources/kustvakt.conf
index 8d04c92..3c63dcd 100644
--- a/full/src/main/resources/kustvakt.conf
+++ b/full/src/main/resources/kustvakt.conf
@@ -15,8 +15,8 @@
kustvakt.management.registration=enable
kustvakt.regex.free = CC-BY.*
-kustvakt.regex.public = CC-BY.*|ACA.*
-kustvakt.regex.all = CC-BY.*|ACA.*|QAO.*
+kustvakt.regex.public = ACA.*
+kustvakt.regex.all = QAO.*
# server
server.port=8089
diff --git a/full/src/test/java/de/ids_mannheim/korap/web/service/full/MatchInfoServiceTest.java b/full/src/test/java/de/ids_mannheim/korap/web/service/full/MatchInfoServiceTest.java
index 3b575d4..a0c325f 100644
--- a/full/src/test/java/de/ids_mannheim/korap/web/service/full/MatchInfoServiceTest.java
+++ b/full/src/test/java/de/ids_mannheim/korap/web/service/full/MatchInfoServiceTest.java
@@ -5,7 +5,6 @@
import static org.junit.Assert.assertTrue;
import org.eclipse.jetty.http.HttpHeaders;
-import org.junit.BeforeClass;
import org.junit.Test;
import com.fasterxml.jackson.databind.JsonNode;
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 cbf1b3e..1145ad4 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
@@ -19,10 +19,10 @@
@Override
public void initMethod () throws KustvaktException {
-// helper().runBootInterfaces();
+ // helper().runBootInterfaces();
}
- private void checkAndFree (String json) throws KustvaktException{
+ private void checkAndFree (String json) throws KustvaktException {
JsonNode node = JsonUtils.readTree(json);
assertEquals("availability",
node.at("/collection/operands/0/key").asText());
@@ -35,7 +35,7 @@
}
- private void checkAndPublic (String json) throws KustvaktException{
+ private void checkAndPublic (String json) throws KustvaktException {
JsonNode node = JsonUtils.readTree(json);
assertNotNull(node);
assertEquals("operation:and",
@@ -57,8 +57,9 @@
assertEquals("availability(PUB)",
node.at("/collection/rewrites/0/scope").asText());
}
-
- private void checkAndPublicWithoutACA (String json) throws KustvaktException{
+
+ private void checkAndPublicWithoutACA (String json)
+ throws KustvaktException {
JsonNode node = JsonUtils.readTree(json);
assertNotNull(node);
assertEquals("operation:and",
@@ -71,63 +72,51 @@
node.at("/collection/operands/0/key").asText());
assertEquals("CC-BY.*",
node.at("/collection/operands/0/value").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());
-
+ assertEquals("ACA.*", node.at("/collection/operands/1/value").asText());
+
assertEquals("operation:insertion",
node.at("/collection/rewrites/0/operation").asText());
assertEquals("availability(PUB)",
node.at("/collection/rewrites/0/scope").asText());
}
-
- private void checkAndAll (String json) throws KustvaktException{
+
+ private void checkAndAll (String json) throws KustvaktException {
JsonNode node = JsonUtils.readTree(json);
assertNotNull(node);
assertEquals("availability(ALL)",
node.at("/collection/rewrites/0/scope").asText());
assertEquals("operation:insertion",
node.at("/collection/rewrites/0/operation").asText());
-
+
assertEquals("operation:and",
node.at("/collection/operation").asText());
-
+
node = node.at("/collection/operands/0");
- assertEquals("operation:or",
- node.at("/operation").asText());
-
- assertEquals("match:eq",
- node.at("/operands/0/match").asText());
- 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:or", node.at("/operation").asText());
+
+ assertEquals("match:eq", node.at("/operands/0/match").asText());
+ 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());
+
node = node.at("/operands/1");
- assertEquals("operation:or",
- node.at("/operation").asText());
- assertEquals("match:eq",
- node.at("/operands/0/match").asText());
- assertEquals("ACA.*",
- node.at("/operands/0/value").asText());
- assertEquals("match:eq",
- node.at("/operands/1/match").asText());
- assertEquals("QAO.*",
- node.at("/operands/1/value").asText());
-
+ assertEquals("operation:or", node.at("/operation").asText());
+ assertEquals("match:eq", node.at("/operands/0/match").asText());
+ assertEquals("ACA.*", node.at("/operands/0/value").asText());
+ assertEquals("match:eq", node.at("/operands/1/match").asText());
+ assertEquals("QAO.*", node.at("/operands/1/value").asText());
+
}
- private void checkAndAllWithoutACA (String json) throws KustvaktException{
+ private void checkAndAllWithoutACA (String json) throws KustvaktException {
JsonNode node = JsonUtils.readTree(json);
assertNotNull(node);
assertEquals("operation:and",
@@ -149,21 +138,20 @@
assertEquals("availability(ALL)",
node.at("/collection/rewrites/0/scope").asText());
}
-
-
+
+
private ClientResponse builtSimpleClientResponse (String collectionQuery) {
- return resource().path("search")
- .queryParam("q", "[orth=das]").queryParam("ql", "poliqarp")
- .queryParam("cq", collectionQuery).get(ClientResponse.class);
+ return resource().path("search").queryParam("q", "[orth=das]")
+ .queryParam("ql", "poliqarp").queryParam("cq", collectionQuery)
+ .get(ClientResponse.class);
}
private ClientResponse builtClientResponseWithIP (String collectionQuery,
String ip) {
- return resource().path("search")
- .queryParam("q", "[orth=das]").queryParam("ql", "poliqarp")
- .queryParam("cq", collectionQuery)
+ return resource().path("search").queryParam("q", "[orth=das]")
+ .queryParam("ql", "poliqarp").queryParam("cq", collectionQuery)
.header(Attributes.AUTHORIZATION,
BasicHttpAuth.encode("kustvakt", "kustvakt2015"))
.header(HttpHeaders.X_FORWARDED_FOR, ip)
@@ -172,9 +160,9 @@
@Test
- public void testAvailabilityFreeAuthorized () throws KustvaktException{
- ClientResponse response = builtSimpleClientResponse(
- "availability = CC-BY-SA");
+ public void testAvailabilityFreeAuthorized () throws KustvaktException {
+ ClientResponse response =
+ builtSimpleClientResponse("availability = CC-BY-SA");
assertEquals(ClientResponse.Status.OK.getStatusCode(),
response.getStatus());
@@ -184,9 +172,10 @@
@Test
- public void testAvailabilityRegexFreeAuthorized () throws KustvaktException{
- ClientResponse response = builtSimpleClientResponse(
- "availability = /.*BY.*/");
+ public void testAvailabilityRegexFreeAuthorized ()
+ throws KustvaktException {
+ ClientResponse response =
+ builtSimpleClientResponse("availability = /.*BY.*/");
assertEquals(ClientResponse.Status.OK.getStatusCode(),
response.getStatus());
@@ -195,9 +184,9 @@
@Test
- public void testAvailabilityFreeUnauthorized () throws KustvaktException{
- ClientResponse response = builtSimpleClientResponse(
- "availability = ACA-NC");
+ public void testAvailabilityFreeUnauthorized () throws KustvaktException {
+ ClientResponse response =
+ builtSimpleClientResponse("availability = ACA-NC");
assertEquals(ClientResponse.Status.OK.getStatusCode(),
response.getStatus());
@@ -206,9 +195,10 @@
@Test
- public void testAvailabilityRegexFreeUnauthorized () throws KustvaktException{
- ClientResponse response = builtSimpleClientResponse(
- "availability = /ACA.*/");
+ public void testAvailabilityRegexFreeUnauthorized ()
+ throws KustvaktException {
+ ClientResponse response =
+ builtSimpleClientResponse("availability = /ACA.*/");
assertEquals(ClientResponse.Status.OK.getStatusCode(),
response.getStatus());
@@ -216,13 +206,14 @@
}
@Test
- public void testAvailabilityRegexNoRewrite () throws KustvaktException{
+ public void testAvailabilityRegexNoRewrite () throws KustvaktException {
ClientResponse response = builtSimpleClientResponse(
"availability = /CC-BY.*/ & availability = /ACA.*/");
assertEquals(ClientResponse.Status.OK.getStatusCode(),
response.getStatus());
String json = response.getEntity(String.class);
+
JsonNode node = JsonUtils.readTree(json);
assertEquals("operation:and",
node.at("/collection/operation").asText());
@@ -237,46 +228,58 @@
assertEquals("match:eq",
node.at("/collection/operands/1/match").asText());
assertEquals("ACA.*", node.at("/collection/operands/1/value").asText());
-
+
}
@Test
- public void testAvailabilityRegexFreeUnauthorized3 () throws KustvaktException{
- ClientResponse response = builtSimpleClientResponse(
- "availability = /.*NC.*/");
+ public void testAvailabilityRegexFreeUnauthorized3 ()
+ throws KustvaktException {
+ ClientResponse response =
+ builtSimpleClientResponse("availability = /.*NC.*/");
assertEquals(ClientResponse.Status.OK.getStatusCode(),
response.getStatus());
-// System.out.println(response.getEntity(String.class));
+ // System.out.println(response.getEntity(String.class));
checkAndFree(response.getEntity(String.class));
}
@Test
- public void testNegationAvailabilityFreeUnauthorized () throws KustvaktException{
- ClientResponse response = builtSimpleClientResponse(
- "availability != /CC-BY.*/");
+ public void testNegationAvailabilityFreeUnauthorized ()
+ throws KustvaktException {
+ ClientResponse response =
+ builtSimpleClientResponse("availability != /CC-BY.*/");
assertEquals(ClientResponse.Status.OK.getStatusCode(),
response.getStatus());
checkAndFree(response.getEntity(String.class));
}
-
@Test
- public void testNegationAvailabilityFreeUnauthorized2 () throws KustvaktException{
- ClientResponse response = builtSimpleClientResponse(
- "availability != /.*BY.*/");
+ public void testNegationAvailabilityFreeUnauthorized2 ()
+ throws KustvaktException {
+ ClientResponse response =
+ builtSimpleClientResponse("availability != /.*BY.*/");
assertEquals(ClientResponse.Status.OK.getStatusCode(),
response.getStatus());
checkAndFree(response.getEntity(String.class));
}
+ @Test
+ public void testNegationAvailabilityWithOperationOrUnauthorized ()
+ throws KustvaktException {
+ ClientResponse response = builtSimpleClientResponse(
+ "availability = /CC-BY.*/ | availability != /CC-BY.*/");
+ assertEquals(ClientResponse.Status.OK.getStatusCode(),
+ response.getStatus());
+ checkAndFree(response.getEntity(String.class));
+ }
@Test
- public void testComplexNegationAvailabilityFreeUnauthorized () throws KustvaktException{
+ public void testComplexNegationAvailabilityFreeUnauthorized ()
+ throws KustvaktException {
ClientResponse response = builtSimpleClientResponse(
"textClass=politik & availability != /CC-BY.*/");
assertEquals(ClientResponse.Status.OK.getStatusCode(),
@@ -287,7 +290,8 @@
@Test
- public void testComplexAvailabilityFreeUnauthorized () throws KustvaktException{
+ public void testComplexAvailabilityFreeUnauthorized ()
+ throws KustvaktException {
ClientResponse response = builtSimpleClientResponse(
"textClass=politik & availability=ACA-NC");
assertEquals(ClientResponse.Status.OK.getStatusCode(),
@@ -298,7 +302,8 @@
@Test
- public void testComplexAvailabilityFreeUnauthorized3 () throws KustvaktException{
+ public void testComplexAvailabilityFreeUnauthorized3 ()
+ throws KustvaktException {
ClientResponse response = builtSimpleClientResponse(
"textClass=politik & availability=/.*NC.*/");
assertEquals(ClientResponse.Status.OK.getStatusCode(),
@@ -309,18 +314,18 @@
@Test
- public void testAvailabilityPublicAuthorized () throws KustvaktException{
- ClientResponse response = builtClientResponseWithIP(
- "availability=ACA-NC", "149.27.0.32");
+ public void testAvailabilityPublicAuthorized () throws KustvaktException {
+ ClientResponse response =
+ builtClientResponseWithIP("availability=ACA-NC", "149.27.0.32");
assertEquals(ClientResponse.Status.OK.getStatusCode(),
response.getStatus());
-
+
checkAndPublic(response.getEntity(String.class));
}
@Test
- public void testAvailabilityPublicUnauthorized () throws KustvaktException{
+ public void testAvailabilityPublicUnauthorized () throws KustvaktException {
ClientResponse response = builtClientResponseWithIP(
"availability=QAO-NC-LOC:ids", "149.27.0.32");
@@ -332,7 +337,8 @@
@Test
- public void testAvailabilityRegexPublicAuthorized () throws KustvaktException{
+ public void testAvailabilityRegexPublicAuthorized ()
+ throws KustvaktException {
ClientResponse response = builtClientResponseWithIP(
"availability= /ACA.*/", "149.27.0.32");
assertEquals(ClientResponse.Status.OK.getStatusCode(),
@@ -343,7 +349,8 @@
@Test
- public void testNegationAvailabilityPublicUnauthorized () throws KustvaktException{
+ public void testNegationAvailabilityPublicUnauthorized ()
+ throws KustvaktException {
ClientResponse response = builtClientResponseWithIP(
"availability != ACA-NC", "149.27.0.32");
assertEquals(ClientResponse.Status.OK.getStatusCode(),
@@ -354,7 +361,8 @@
@Test
- public void testNegationAvailabilityRegexPublicUnauthorized () throws KustvaktException{
+ public void testNegationAvailabilityRegexPublicUnauthorized ()
+ throws KustvaktException {
ClientResponse response = builtClientResponseWithIP(
"availability != /ACA.*/", "149.27.0.32");
assertEquals(ClientResponse.Status.OK.getStatusCode(),
@@ -365,7 +373,8 @@
@Test
- public void testComplexAvailabilityPublicUnauthorized () throws KustvaktException{
+ public void testComplexAvailabilityPublicUnauthorized ()
+ throws KustvaktException {
ClientResponse response = builtClientResponseWithIP(
"textClass=politik & availability=QAO-NC-LOC:ids",
"149.27.0.32");
@@ -378,7 +387,8 @@
@Test
- public void testNegationComplexAvailabilityPublicUnauthorized () throws KustvaktException{
+ public void testNegationComplexAvailabilityPublicUnauthorized ()
+ throws KustvaktException {
ClientResponse response = builtClientResponseWithIP(
"textClass=politik & availability!=QAO-NC-LOC:ids",
"149.27.0.32");
@@ -390,7 +400,7 @@
}
@Test
- public void testAvailabilityRegexAllAuthorized () throws KustvaktException{
+ public void testAvailabilityRegexAllAuthorized () throws KustvaktException {
ClientResponse response = builtClientResponseWithIP(
"availability= /ACA.*/", "10.27.0.32");
assertEquals(ClientResponse.Status.OK.getStatusCode(),
@@ -398,5 +408,5 @@
checkAndAllWithoutACA(response.getEntity(String.class));
}
-
+
}
diff --git a/full/src/test/java/de/ids_mannheim/korap/web/service/full/VirtualCorpusServiceTest.java b/full/src/test/java/de/ids_mannheim/korap/web/service/full/VirtualCorpusServiceTest.java
index 7996ac6..ab33aa1 100644
--- a/full/src/test/java/de/ids_mannheim/korap/web/service/full/VirtualCorpusServiceTest.java
+++ b/full/src/test/java/de/ids_mannheim/korap/web/service/full/VirtualCorpusServiceTest.java
@@ -3,6 +3,7 @@
import static org.junit.Assert.*;
import org.eclipse.jetty.http.HttpHeaders;
+import org.junit.Ignore;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.test.context.ContextConfiguration;
@@ -25,6 +26,7 @@
import de.ids_mannheim.korap.security.auth.BasicHttpAuth;
import de.ids_mannheim.korap.utils.JsonUtils;
+@Ignore
@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration("classpath:test-config.xml")
public class VirtualCorpusServiceTest extends JerseyTest {
diff --git a/full/src/test/resources/kustvakt-test.conf b/full/src/test/resources/kustvakt-test.conf
index 6659491..847788e 100644
--- a/full/src/test/resources/kustvakt-test.conf
+++ b/full/src/test/resources/kustvakt-test.conf
@@ -15,8 +15,8 @@
kustvakt.management.registration=enable
kustvakt.regex.free = CC-BY.*
-kustvakt.regex.public = CC-BY.*|ACA.*
-kustvakt.regex.all = CC-BY.*|ACA.*|QAO.*
+kustvakt.regex.public = ACA.*
+kustvakt.regex.all = QAO.*
# port&host added 06.02.17/FB
server.port=8089