Set corpus access public for stored query.
Change-Id: If58c392919e84aab26c7781fe42a5e6b05759968
diff --git a/full/Changes b/full/Changes
index 9315d2b..beb2de3 100644
--- a/full/Changes
+++ b/full/Changes
@@ -24,6 +24,9 @@
17/02/2021
- Removed escaping for KoralQuery in VC and query reference responses (margaretha)
- Added query and query language in virtual corpus table (margaretha)
+18/02/2021
+ - Set corpus access public for stored query (margaretha)
+
# version 0.62.4
24/01/2020
diff --git a/full/pom.xml b/full/pom.xml
index 407a212..826041a 100644
--- a/full/pom.xml
+++ b/full/pom.xml
@@ -69,62 +69,6 @@
</plugins>
</build>
</profile>
- <profile>
- <id>lite</id>
- <build>
- <plugins>
- <plugin>
- <artifactId>maven-shade-plugin</artifactId>
- <version>3.2.4</version>
- <executions>
- <execution>
- <id>lite</id>
- <phase>package</phase>
- <goals>
- <goal>shade</goal>
- </goals>
- <configuration>
- <finalName>
- Kustvakt-lite-${project.version}
- </finalName>
- <transformers>
- <transformer
- implementation="org.apache.maven.plugins.shade.resource.ManifestResourceTransformer">
- <mainClass>
- de.ids_mannheim.korap.server.KustvaktLiteServer
- </mainClass>
- </transformer>
- <transformer
- implementation="org.apache.maven.plugins.shade.resource.AppendingTransformer">
- <resource>META-INF/spring.handlers
- </resource>
- </transformer>
- <transformer
- implementation="org.apache.maven.plugins.shade.resource.AppendingTransformer">
- <resource>META-INF/spring.schemas
- </resource>
- </transformer>
- </transformers>
- <!-- Additional configuration. apparently there is a security exception -->
- <filters>
- <filter>
- <artifact>*:*</artifact>
- <excludes>
- <exclude>META-INF/*.SF</exclude>
- <exclude>META-INF/*.DSA
- </exclude>
- <exclude>META-INF/*.RSA
- </exclude>
- </excludes>
- </filter>
- </filters>
- </configuration>
- </execution>
- </executions>
- </plugin>
- </plugins>
- </build>
- </profile>
</profiles>
<build>
<!-- <resources> <resource> <directory>src/main/resources</directory> <filtering>true</filtering>
diff --git a/full/src/main/java/de/ids_mannheim/korap/config/NamedVCLoader.java b/full/src/main/java/de/ids_mannheim/korap/config/NamedVCLoader.java
index 1d5f2e5..115405e 100644
--- a/full/src/main/java/de/ids_mannheim/korap/config/NamedVCLoader.java
+++ b/full/src/main/java/de/ids_mannheim/korap/config/NamedVCLoader.java
@@ -60,7 +60,7 @@
String json = IOUtils.toString(is, "utf-8");
if (json != null) {
cacheVC(json, filename);
- vcService.storeVC(filename, ResourceType.SYSTEM,
+ vcService.storeQuery(filename, ResourceType.SYSTEM,
QueryType.VIRTUAL_CORPUS, json, null, null, null, true,
"system", null, null);
}
@@ -102,7 +102,7 @@
// ignore
if (DEBUG) jlog.debug(e);
}
- vcService.storeVC(filename, ResourceType.SYSTEM,
+ vcService.storeQuery(filename, ResourceType.SYSTEM,
QueryType.VIRTUAL_CORPUS, json, null, null, null, true,
"system", null, null);
}
diff --git a/full/src/main/java/de/ids_mannheim/korap/service/VirtualCorpusService.java b/full/src/main/java/de/ids_mannheim/korap/service/VirtualCorpusService.java
index 67d46d7..8d17105 100644
--- a/full/src/main/java/de/ids_mannheim/korap/service/VirtualCorpusService.java
+++ b/full/src/main/java/de/ids_mannheim/korap/service/VirtualCorpusService.java
@@ -62,7 +62,7 @@
public static boolean DEBUG = false;
- public static Pattern vcNamePattern = Pattern.compile("[-\\w.]+");
+ public static Pattern queryNamePattern = Pattern.compile("[-\\w.]+");
@Autowired
private VirtualCorpusDao vcDao;
@@ -243,17 +243,17 @@
// }
public Status handlePutRequest (String username, String vcCreator,
- String vcName, QueryJson vcJson) throws KustvaktException {
+ String vcName, QueryJson queryJson) throws KustvaktException {
verifyUsername(username, vcCreator);
VirtualCorpus vc = vcDao.retrieveVCByName(vcName, vcCreator);
- ParameterChecker.checkObjectValue(vcJson, "request entity");
+ ParameterChecker.checkObjectValue(queryJson, "request entity");
if (vc == null) {
- storeVC(vcJson, vcName, username);
+ storeQuery(queryJson, vcName, username);
return Status.CREATED;
}
else {
- editVC(vc, vcJson, vcName, username);
+ editVC(vc, queryJson, vcName, username);
return Status.NO_CONTENT;
}
}
@@ -322,38 +322,40 @@
}
}
- public void storeVC (QueryJson vc, String vcName, String createdBy)
+ public void storeQuery (QueryJson query, String queryName, String createdBy)
throws KustvaktException {
String koralQuery = null;
- if (vc.getQueryType().equals(QueryType.VIRTUAL_CORPUS)) {
- ParameterChecker.checkStringValue(vc.getCorpusQuery(),
+ if (query.getQueryType().equals(QueryType.VIRTUAL_CORPUS)) {
+ ParameterChecker.checkStringValue(query.getCorpusQuery(),
"corpusQuery");
- koralQuery = serializeCorpusQuery(vc.getCorpusQuery());
+ koralQuery = serializeCorpusQuery(query.getCorpusQuery());
}
- else if (vc.getQueryType().equals(QueryType.QUERY)) {
- ParameterChecker.checkStringValue(vc.getQuery(), "query");
- ParameterChecker.checkStringValue(vc.getQueryLanguage(),
+ else if (query.getQueryType().equals(QueryType.QUERY)) {
+ ParameterChecker.checkStringValue(query.getQuery(), "query");
+ ParameterChecker.checkStringValue(query.getQueryLanguage(),
"queryLanguage");
- koralQuery = serializeQuery(vc.getQuery(), vc.getQueryLanguage());
+ koralQuery =
+ serializeQuery(query.getQuery(), query.getQueryLanguage());
}
- storeVC(vcName, vc.getType(), vc.getQueryType(), koralQuery,
- vc.getDefinition(), vc.getDescription(), vc.getStatus(),
- vc.isCached(), createdBy, vc.getQuery(), vc.getQueryLanguage());
+ storeQuery(queryName, query.getType(), query.getQueryType(), koralQuery,
+ query.getDefinition(), query.getDescription(),
+ query.getStatus(), query.isCached(), createdBy,
+ query.getQuery(), query.getQueryLanguage());
}
- public void storeVC (String vcName, ResourceType type, QueryType queryType,
+ public void storeQuery (String queryName, ResourceType type, QueryType queryType,
String koralQuery, String definition, String description,
String status, boolean isCached, String username, String query,
String queryLanguage) throws KustvaktException {
- ParameterChecker.checkNameValue(vcName, "vcName");
+ ParameterChecker.checkNameValue(queryName, "name");
ParameterChecker.checkObjectValue(type, "type");
- if (!vcNamePattern.matcher(vcName).matches()) {
+ if (!queryNamePattern.matcher(queryName).matches()) {
throw new KustvaktException(StatusCodes.INVALID_ARGUMENT,
- "Virtual corpus name must only contain letters, numbers, "
- + "underscores, hypens and spaces",
- vcName);
+ queryType.displayName() + " name must only contain "
+ + "letters, numbers, underscores, hypens and spaces",
+ queryName);
}
if (type.equals(ResourceType.SYSTEM) && !username.equals("system")
@@ -362,13 +364,18 @@
"Unauthorized operation for user: " + username, username);
}
- CorpusAccess requiredAccess =
- determineRequiredAccess(isCached, vcName, koralQuery);
+ CorpusAccess requiredAccess = CorpusAccess.PUB;
+ if (queryType.equals(QueryType.VIRTUAL_CORPUS)) {
+ requiredAccess =
+ determineRequiredAccess(isCached, queryName, koralQuery);
+ }
- if (DEBUG) jlog.debug("Storing VC " + vcName + "in the database ");
- int vcId = 0;
+ if (DEBUG) jlog.debug("Storing virtul corpus or query: " + queryName
+ + "in the database ");
+
+ int queryId = 0;
try {
- vcId = vcDao.createVirtualCorpus(vcName, type, queryType,
+ queryId = vcDao.createVirtualCorpus(queryName, type, queryType,
requiredAccess, koralQuery, definition, description, status,
isCached, username, query, queryLanguage);
@@ -387,7 +394,7 @@
cause.getMessage());
}
if (type.equals(ResourceType.PUBLISHED)) {
- publishVC(vcId);
+ publishVC(queryId);
}
}
diff --git a/full/src/test/java/de/ids_mannheim/korap/service/VirtualCorpusServiceTest.java b/full/src/test/java/de/ids_mannheim/korap/service/VirtualCorpusServiceTest.java
index 31e51d8..7d1e2f6 100644
--- a/full/src/test/java/de/ids_mannheim/korap/service/VirtualCorpusServiceTest.java
+++ b/full/src/test/java/de/ids_mannheim/korap/service/VirtualCorpusServiceTest.java
@@ -48,7 +48,7 @@
vc.setCorpusQuery("corpusSigle=GOE");
vc.setType(ResourceType.PRIVATE);
vc.setQueryType(QueryType.VIRTUAL_CORPUS);
- vcService.storeVC(vc, "dory-vc", "dory");
+ vcService.storeQuery(vc, "dory-vc", "dory");
}
@Test
@@ -60,7 +60,7 @@
vc.setType(ResourceType.PUBLISHED);
vc.setQueryType(QueryType.VIRTUAL_CORPUS);
String username = "VirtualCorpusServiceTest";
- vcService.storeVC(vc, vcName, username );
+ vcService.storeQuery(vc, vcName, username );
List<VirtualCorpusAccessDto> accesses =
vcService.listVCAccessByUsername("admin");
diff --git a/full/src/test/java/de/ids_mannheim/korap/web/controller/QueryReferenceControllerTest.java b/full/src/test/java/de/ids_mannheim/korap/web/controller/QueryReferenceControllerTest.java
index a6ea7c7..de5b2da 100644
--- a/full/src/test/java/de/ids_mannheim/korap/web/controller/QueryReferenceControllerTest.java
+++ b/full/src/test/java/de/ids_mannheim/korap/web/controller/QueryReferenceControllerTest.java
@@ -17,6 +17,7 @@
import de.ids_mannheim.korap.config.SpringJerseyTest;
import de.ids_mannheim.korap.constant.ResourceType;
import de.ids_mannheim.korap.exceptions.KustvaktException;
+import de.ids_mannheim.korap.user.User.CorpusAccess;
import de.ids_mannheim.korap.utils.JsonUtils;
public class QueryReferenceControllerTest extends SpringJerseyTest {
@@ -39,12 +40,14 @@
assertEquals(Status.CREATED.getStatusCode(), response.getStatus());
JsonNode node = testRetrieveQueryByName(testUser, testUser, qName);
+// System.out.println(node);
assertEquals(qName, node.at("/name").asText());
assertEquals(ResourceType.PRIVATE.displayName(),
node.at("/type").asText());
assertEquals(testUser, node.at("/createdBy").asText());
assertEquals("der", node.at("/query").asText());
assertEquals("poliqarp", node.at("/queryLanguage").asText());
+ assertEquals(CorpusAccess.PUB.name(), node.at("/requiredAccess").asText());
}
@Test
diff --git a/full/src/test/java/de/ids_mannheim/korap/web/controller/VirtualCorpusControllerTest.java b/full/src/test/java/de/ids_mannheim/korap/web/controller/VirtualCorpusControllerTest.java
index d6c786c..666cac3 100644
--- a/full/src/test/java/de/ids_mannheim/korap/web/controller/VirtualCorpusControllerTest.java
+++ b/full/src/test/java/de/ids_mannheim/korap/web/controller/VirtualCorpusControllerTest.java
@@ -515,7 +515,7 @@
JsonNode node = JsonUtils.readTree(entity);
assertEquals(StatusCodes.INVALID_ARGUMENT,
node.at("/errors/0/0").asInt());
- assertEquals("vcName must contain at least 3 characters",
+ assertEquals("queryName must contain at least 3 characters",
node.at("/errors/0/1").asText());
}