tests
diff --git a/dependency-reduced-pom.xml b/dependency-reduced-pom.xml
index e485c69..47cef40 100644
--- a/dependency-reduced-pom.xml
+++ b/dependency-reduced-pom.xml
@@ -4,7 +4,7 @@
<groupId>de.ids_mannheim.korap</groupId>
<artifactId>Kustvakt-core</artifactId>
<name>Kustvakt core</name>
- <version>0.4</version>
+ <version>0.5</version>
<description>Kustvakt core, basic rest api for testing purposes and default
interfaces</description>
<build>
@@ -23,7 +23,7 @@
<testResources>
<testResource>
<filtering>true</filtering>
- <directory>src/main/resources</directory>
+ <directory>src/test/resources</directory>
<includes>
<include>**/*.prop</include>
<include>**/*.xml</include>
@@ -31,10 +31,31 @@
<include>**/*.properties</include>
</includes>
</testResource>
+ <testResource>
+ <filtering>true</filtering>
+ <directory>src/main/resources</directory>
+ <includes>
+ <include>**/*.prop</include>
+ <include>**/*.xml</include>
+ <include>**/*.conf</include>
+ <include>**/*.properties</include>
+ <include>**/*.sql</include>
+ </includes>
+ </testResource>
</testResources>
<plugins>
<plugin>
+ <artifactId>maven-compiler-plugin</artifactId>
+ <version>3.3</version>
+ <configuration>
+ <compilerVersion>1.7</compilerVersion>
+ <source>1.7</source>
+ <target>1.7</target>
+ </configuration>
+ </plugin>
+ <plugin>
<artifactId>maven-jar-plugin</artifactId>
+ <version>2.1</version>
<executions>
<execution>
<phase>package</phase>
@@ -52,7 +73,7 @@
<exclude>**/*APITest.java</exclude>
</excludes>
<includes>
- <include>**/TestSuite.java</include>
+ <include>**/*.java</include>
</includes>
</configuration>
</plugin>
@@ -198,7 +219,7 @@
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
- <version>0.11.8</version>
+ <version>1.16.6</version>
<scope>provided</scope>
</dependency>
<dependency>
diff --git a/pom.xml b/pom.xml
index c28e0ef..54386dd 100644
--- a/pom.xml
+++ b/pom.xml
@@ -183,7 +183,7 @@
</transformer>
</transformers>
<!-- Additional configuration. -->
- <!-- apparently there is a securityexception -->
+ <!-- apparently there is a securityException -->
<filters>
<filter>
<artifact>*:*</artifact>
diff --git a/src/main/java/de/ids_mannheim/korap/exceptions/EmptyResultException.java b/src/main/java/de/ids_mannheim/korap/exceptions/EmptyResultException.java
index 07acf8d..a854bc5 100644
--- a/src/main/java/de/ids_mannheim/korap/exceptions/EmptyResultException.java
+++ b/src/main/java/de/ids_mannheim/korap/exceptions/EmptyResultException.java
@@ -4,6 +4,7 @@
* @author hanl
* @date 25/03/2014
*/
+@Deprecated // even useful anymore?
public class EmptyResultException extends KustvaktException {
public EmptyResultException(String message, String entity) {
diff --git a/src/main/java/de/ids_mannheim/korap/handlers/EntityDao.java b/src/main/java/de/ids_mannheim/korap/handlers/EntityDao.java
index b81dc3d..77d4150 100644
--- a/src/main/java/de/ids_mannheim/korap/handlers/EntityDao.java
+++ b/src/main/java/de/ids_mannheim/korap/handlers/EntityDao.java
@@ -43,8 +43,8 @@
}
@Override
- public UserSettings getUserSettings(Integer userid) throws
- KustvaktException {
+ public UserSettings getUserSettings(Integer userid)
+ throws KustvaktException {
MapSqlParameterSource np = new MapSqlParameterSource();
np.addValue("us", userid);
final String sql =
@@ -100,8 +100,8 @@
* @throws KustvaktException
*/
- private void createSettings(UserSettings settings) throws
- KustvaktException {
+ private void createSettings(UserSettings settings)
+ throws KustvaktException {
final String sql =
"INSERT INTO user_settings (user_id, fileNameForExport,leftContextItemForExport,"
+
@@ -186,7 +186,7 @@
+
"email=:email, address=:address, country=:country, privateUsage=:privateUsage "
+
- "WHERE userID=:userID;";
+ "WHERE user_id=:userID;";
try {
return this.jdbcTemplate
.update(up, new BeanPropertySqlParameterSource(details));
@@ -199,8 +199,8 @@
}
}
- private void createUserDetails(UserDetails details) throws
- KustvaktException {
+ private void createUserDetails(UserDetails details)
+ throws KustvaktException {
final String up =
"INSERT INTO user_details (user_id, firstName, lastName, gender, phone, institution, "
+
@@ -223,8 +223,7 @@
// usersettings are fetched plus basic account info, no details, since i rarely use them anyway!
@Override
- public User getAccount(String username)
- throws KustvaktException {
+ public User getAccount(String username) throws KustvaktException {
Map<String, String> namedParameters = Collections
.singletonMap("username", username);
final String sql = "select a.* from korap_users as a where a.username=:username;";
@@ -259,6 +258,9 @@
if (param != null) {
np.addValue("frag", param.getUriFragment());
np.addValue("exp", new Date(param.getUriExpiration()));
+ }else {
+ np.addValue("frag", null);
+ np.addValue("exp", null);
}
np.addValue("id", k.getId());
diff --git a/src/main/java/de/ids_mannheim/korap/handlers/RowMapperFactory.java b/src/main/java/de/ids_mannheim/korap/handlers/RowMapperFactory.java
index c5cc374..9ace5a5 100644
--- a/src/main/java/de/ids_mannheim/korap/handlers/RowMapperFactory.java
+++ b/src/main/java/de/ids_mannheim/korap/handlers/RowMapperFactory.java
@@ -13,6 +13,7 @@
import java.sql.ResultSet;
import java.sql.SQLException;
+import java.sql.Timestamp;
import java.util.Map;
/**
@@ -63,8 +64,9 @@
rs.getTimestamp(Attributes.ACCOUNT_CREATION).getTime());
user.setAccountLink(rs.getString(Attributes.ACCOUNTLINK));
+ Timestamp exp = rs.getTimestamp(Attributes.URI_EXPIRATION);
URIParam param = new URIParam(rs.getString(Attributes.URI_FRAGMENT),
- rs.getDate(Attributes.URI_EXPIRATION).getTime());
+ exp == null ? -1 : exp.getTime());
user.addField(param);
return user;
}
diff --git a/src/main/java/de/ids_mannheim/korap/resource/rewrite/CollectionCleanupFilter.java b/src/main/java/de/ids_mannheim/korap/resource/rewrite/CollectionCleanupFilter.java
index b55f18f..c243f73 100644
--- a/src/main/java/de/ids_mannheim/korap/resource/rewrite/CollectionCleanupFilter.java
+++ b/src/main/java/de/ids_mannheim/korap/resource/rewrite/CollectionCleanupFilter.java
@@ -2,6 +2,8 @@
import com.fasterxml.jackson.databind.JsonNode;
import com.fasterxml.jackson.databind.node.ObjectNode;
+import de.ids_mannheim.korap.config.KustvaktConfiguration;
+import de.ids_mannheim.korap.user.User;
import de.ids_mannheim.korap.utils.JsonUtils;
import java.util.Iterator;
@@ -10,6 +12,7 @@
* @author hanl
* @date 28/07/2015
*/
+//todo: 21.10.15
public class CollectionCleanupFilter extends RewriteTask.RewriteQuery {
// track path to operand
@@ -17,12 +20,13 @@
private StringBuilder builder;
public CollectionCleanupFilter() {
- this.builder = new StringBuilder();
+ super();
}
@Override
- public JsonNode rewrite(KoralNode node) {
- if (node.rawNode().has("collection")) {
+ public JsonNode rewrite(KoralNode node, KustvaktConfiguration config,
+ User user) {
+ if (node.has("collection")) {
JsonNode coll = node.rawNode().path("collection");
process(coll);
}
diff --git a/src/main/java/de/ids_mannheim/korap/resource/rewrite/CollectionConstraint.java b/src/main/java/de/ids_mannheim/korap/resource/rewrite/CollectionConstraint.java
index 1ceb1e3..4b753cb 100644
--- a/src/main/java/de/ids_mannheim/korap/resource/rewrite/CollectionConstraint.java
+++ b/src/main/java/de/ids_mannheim/korap/resource/rewrite/CollectionConstraint.java
@@ -1,10 +1,12 @@
package de.ids_mannheim.korap.resource.rewrite;
import com.fasterxml.jackson.databind.JsonNode;
+import de.ids_mannheim.korap.config.KustvaktConfiguration;
import de.ids_mannheim.korap.exceptions.KustvaktException;
import de.ids_mannheim.korap.resources.Corpus;
import de.ids_mannheim.korap.resources.KustvaktResource;
import de.ids_mannheim.korap.security.ac.SecurityManager;
+import de.ids_mannheim.korap.user.User;
/**
* @author hanl
@@ -13,16 +15,13 @@
// todo: test
public class CollectionConstraint extends RewriteTask.RewriteNode {
- public CollectionConstraint() {
- super();
- }
-
@Override
- public JsonNode rewrite(KoralNode koralnode) {
+ public JsonNode rewrite(KoralNode koralnode, KustvaktConfiguration config,
+ User user) {
JsonNode node = koralnode.rawNode();
if (node.at("/@type").asText().equals("koral:doc")) {
- if (node.at("/key").asText().equals("corpusID") && !check(
- koralnode)) {
+ if (node.at("/key").asText().equals("corpusID") && !check(koralnode,
+ user)) {
koralnode.removeNode();
// todo: add message that node was removed!
}
@@ -30,15 +29,15 @@
return node;
}
- private boolean check(KoralNode node) {
- if (!node.hasUser())
+ private boolean check(KoralNode node, User user) {
+ if (user == null)
return true;
String id = node.rawNode().at("/value").asText();
KustvaktResource corpus;
try {
SecurityManager m = SecurityManager
- .findbyId(id, node.getUser(), Corpus.class);
+ .findbyId(id, user, Corpus.class);
corpus = m.getResource();
}catch (KustvaktException e) {
return false;
diff --git a/src/main/java/de/ids_mannheim/korap/resource/rewrite/FoundryInject.java b/src/main/java/de/ids_mannheim/korap/resource/rewrite/FoundryInject.java
index b166181..d44606e 100644
--- a/src/main/java/de/ids_mannheim/korap/resource/rewrite/FoundryInject.java
+++ b/src/main/java/de/ids_mannheim/korap/resource/rewrite/FoundryInject.java
@@ -3,7 +3,7 @@
import com.fasterxml.jackson.databind.JsonNode;
import de.ids_mannheim.korap.config.KustvaktConfiguration;
import de.ids_mannheim.korap.resource.LayerMapper;
-
+import de.ids_mannheim.korap.user.User;
/**
* @author hanl
@@ -11,18 +11,16 @@
*/
public class FoundryInject extends RewriteTask.RewriteNode {
- private KustvaktConfiguration config;
-
- public FoundryInject(KustvaktConfiguration config) {
+ public FoundryInject() {
super();
- this.config = config;
}
@Override
- public JsonNode rewrite(KoralNode node) {
+ public JsonNode rewrite(KoralNode node, KustvaktConfiguration config,
+ User user) {
LayerMapper mapper;
- if (node.hasUser())
- mapper = new LayerMapper(config, node.getUser().getSettings());
+ if (user != null)
+ mapper = new LayerMapper(config, user.getSettings());
else
mapper = new LayerMapper(config);
diff --git a/src/main/java/de/ids_mannheim/korap/resource/rewrite/IdWriter.java b/src/main/java/de/ids_mannheim/korap/resource/rewrite/IdWriter.java
index 86999a5..5e4bece 100644
--- a/src/main/java/de/ids_mannheim/korap/resource/rewrite/IdWriter.java
+++ b/src/main/java/de/ids_mannheim/korap/resource/rewrite/IdWriter.java
@@ -1,8 +1,49 @@
package de.ids_mannheim.korap.resource.rewrite;
+import com.fasterxml.jackson.databind.JsonNode;
+import com.fasterxml.jackson.databind.node.ObjectNode;
+import de.ids_mannheim.korap.config.KustvaktConfiguration;
+import de.ids_mannheim.korap.user.User;
+
/**
* @author hanl
* @date 25/09/2015
*/
-public class IdWriter {
+// todo: 20.10.15
+public class IdWriter extends RewriteTask.RewriteNode {
+
+ private int counter;
+
+ public IdWriter() {
+ super();
+ this.counter = 0;
+
+ }
+
+ @Override
+ public JsonNode rewrite(KoralNode node, KustvaktConfiguration config,
+ User user) {
+ JsonNode result = node.rawNode();
+ if (result.path("@type").asText().equals("koral:token"))
+ addId(result);
+ return result;
+ }
+
+ private JsonNode addId(JsonNode node) {
+ if (node.isObject()) {
+ ObjectNode o = (ObjectNode) node;
+ String s = extractToken(node);
+ if (s != null && !s.isEmpty())
+ o.put("idn", s + "_" + counter++);
+ }
+ return node;
+ }
+
+ // fixme: koral token --> how does grouping behave?!
+ private String extractToken(JsonNode token) {
+ JsonNode wrap = token.path("wrap");
+ if (!wrap.isMissingNode())
+ return wrap.path("key").asText();
+ return null;
+ }
}
diff --git a/src/main/java/de/ids_mannheim/korap/resource/rewrite/KoralNode.java b/src/main/java/de/ids_mannheim/korap/resource/rewrite/KoralNode.java
index 64365e1..f4580ad 100644
--- a/src/main/java/de/ids_mannheim/korap/resource/rewrite/KoralNode.java
+++ b/src/main/java/de/ids_mannheim/korap/resource/rewrite/KoralNode.java
@@ -3,7 +3,6 @@
import com.fasterxml.jackson.databind.JsonNode;
import com.fasterxml.jackson.databind.node.ArrayNode;
import com.fasterxml.jackson.databind.node.ObjectNode;
-import de.ids_mannheim.korap.user.User;
import de.ids_mannheim.korap.utils.JsonUtils;
import java.util.LinkedHashMap;
@@ -19,40 +18,21 @@
private JsonNode node;
private KoralRewriteBuilder builder;
private boolean toRemove;
- private final User user;
private KoralNode(JsonNode node) {
- this(node, null);
- }
-
- public KoralNode(JsonNode node, User user) {
this.node = node;
this.builder = new KoralRewriteBuilder();
this.toRemove = false;
- this.user = user;
}
- public boolean hasUser() {
- return this.user != null;
- }
-
- public User getUser() {
- return this.user;
- }
-
- public static KoralNode getNode(JsonNode node) {
+ public static KoralNode wrapNode(JsonNode node) {
return new KoralNode(node) {
};
}
- public static KoralNode getNode(JsonNode node, User user) {
- return new KoralNode(node, user) {
- };
- }
-
public void set(String name, Object value) {
- if (this.node.isObject()) {
+ if (this.node.isObject() && this.node.path(name).isMissingNode()) {
ObjectNode node = (ObjectNode) this.node;
if (value instanceof String)
node.put(name, (String) value);
@@ -91,6 +71,16 @@
}
}
+ public boolean has(Object ident) {
+ if (ident instanceof String)
+ return this.node.has((String) ident);
+ if (ident instanceof Integer)
+ return this.node.has((int) ident);
+ return false;
+ }
+
+
+
public JsonNode rawNode() {
return this.node;
}
@@ -103,6 +93,7 @@
return this.toRemove;
}
+ //todo: 21.10.15 -- redo with better return policies!
private static class KoralRewriteBuilder {
private Map<String, String> map;
diff --git a/src/main/java/de/ids_mannheim/korap/resource/rewrite/MetaConstraint.java b/src/main/java/de/ids_mannheim/korap/resource/rewrite/MetaConstraint.java
index af7d998..bf6f2e1 100644
--- a/src/main/java/de/ids_mannheim/korap/resource/rewrite/MetaConstraint.java
+++ b/src/main/java/de/ids_mannheim/korap/resource/rewrite/MetaConstraint.java
@@ -1,6 +1,8 @@
package de.ids_mannheim.korap.resource.rewrite;
import com.fasterxml.jackson.databind.JsonNode;
+import de.ids_mannheim.korap.config.KustvaktConfiguration;
+import de.ids_mannheim.korap.user.User;
/**
* @author hanl
@@ -13,7 +15,8 @@
}
@Override
- public JsonNode rewrite(KoralNode node) {
+ public JsonNode rewrite(KoralNode node, KustvaktConfiguration config,
+ User user) {
if (node.rawNode().has("meta")) {
JsonNode meta = node.rawNode().path("meta");
//todo: check meta parameter
diff --git a/src/main/java/de/ids_mannheim/korap/resource/rewrite/PublicCollection.java b/src/main/java/de/ids_mannheim/korap/resource/rewrite/PublicCollection.java
index 88ce41e..d8a35dc 100644
--- a/src/main/java/de/ids_mannheim/korap/resource/rewrite/PublicCollection.java
+++ b/src/main/java/de/ids_mannheim/korap/resource/rewrite/PublicCollection.java
@@ -1,9 +1,11 @@
package de.ids_mannheim.korap.resource.rewrite;
import com.fasterxml.jackson.databind.JsonNode;
+import de.ids_mannheim.korap.config.KustvaktConfiguration;
import de.ids_mannheim.korap.exceptions.KustvaktException;
import de.ids_mannheim.korap.resources.Corpus;
import de.ids_mannheim.korap.security.ac.ResourceFinder;
+import de.ids_mannheim.korap.user.User;
import de.ids_mannheim.korap.utils.CollectionQueryBuilder3;
import java.util.Set;
@@ -14,27 +16,34 @@
*/
public class PublicCollection extends RewriteTask.RewriteQuery {
+ public PublicCollection() {
+ super();
+ }
+
// todo: where to inject the array node into? --> super group with and relation plus subgroup with ids and or operation
@Override
- public JsonNode rewrite(KoralNode node) {
+ public JsonNode rewrite(KoralNode node, KustvaktConfiguration config,
+ User user) {
JsonNode subnode = node.rawNode();
if (!subnode.at("/collection").findValuesAsText("key")
.contains("corpusID")) {
//todo: inject public collection node
- if (node.hasUser()) {
+ if (user != null) {
try {
ResourceFinder finder = ResourceFinder
- .init(node.getUser(), Corpus.class);
+ .init(user, Corpus.class);
Set<String> ids = finder.getIds();
createNode(ids);
}catch (KustvaktException e) {
e.printStackTrace();
+ //todo: 20.10.15 - 21.10.15
}
}
}
return subnode;
}
+ //todo: 20.10.15
private JsonNode createNode(Set<String> ids) {
JsonNode node = CollectionQueryBuilder3.Utils.buildDocGroup();
return node;
diff --git a/src/main/java/de/ids_mannheim/korap/resource/rewrite/RewriteHandler.java b/src/main/java/de/ids_mannheim/korap/resource/rewrite/RewriteHandler.java
index d9eb391..8af6eae 100644
--- a/src/main/java/de/ids_mannheim/korap/resource/rewrite/RewriteHandler.java
+++ b/src/main/java/de/ids_mannheim/korap/resource/rewrite/RewriteHandler.java
@@ -2,11 +2,14 @@
import com.fasterxml.jackson.databind.JsonNode;
import de.ids_mannheim.korap.config.KustvaktClassLoader;
+import de.ids_mannheim.korap.config.KustvaktConfiguration;
import de.ids_mannheim.korap.user.User;
import de.ids_mannheim.korap.utils.JsonUtils;
import de.ids_mannheim.korap.utils.KustvaktLogger;
import org.slf4j.Logger;
+import java.lang.reflect.Constructor;
+import java.lang.reflect.InvocationTargetException;
import java.util.Collection;
import java.util.HashSet;
import java.util.Iterator;
@@ -21,19 +24,50 @@
private static Logger jlog = KustvaktLogger.initiate(RewriteHandler.class);
private Collection<RewriteTask.RewriteNode> node_processors;
private Collection<RewriteTask.RewriteQuery> query_processors;
+ private KustvaktConfiguration config;
- public RewriteHandler() {
+ // fixme: make default constructor with configuration!
+ public RewriteHandler(KustvaktConfiguration config) {
+ this.config = config;
this.node_processors = new HashSet<>();
this.query_processors = new HashSet<>();
KustvaktClassLoader.loadSubTypes(RewriteTask.RewriteNode.class);
}
- public void add(RewriteTask.RewriteNode node) {
- this.node_processors.add(node);
+ public void add(RewriteTask.RewriteNode rewriter) {
+ this.node_processors.add(rewriter);
}
- public void add(RewriteTask.RewriteQuery node) {
- this.query_processors.add(node);
+ public void add(RewriteTask.RewriteQuery rewriter) {
+ this.query_processors.add(rewriter);
+ }
+
+ /**
+ * expects extended RewriteNode/Query class with default config constructor
+ *
+ * @param rewriter
+ */
+ //todo: 21.10.15
+ public boolean add(Class<? extends RewriteTask> rewriter) {
+ RewriteTask task;
+ try {
+ Constructor c = rewriter.getConstructor();
+ task = (RewriteTask) c.newInstance();
+ }catch (NoSuchMethodException | InvocationTargetException
+ | IllegalAccessException | InstantiationException e) {
+ return false;
+ }
+
+ if (task instanceof RewriteTask.RewriteNode) {
+ this.node_processors.add((RewriteTask.RewriteNode) task);
+ return true;
+ }
+
+ if (task instanceof RewriteTask.RewriteQuery) {
+ this.query_processors.add((RewriteTask.RewriteQuery) task);
+ return true;
+ }
+ return false;
}
public void clear() {
@@ -72,15 +106,16 @@
return JsonUtils.toJSON(apply(JsonUtils.readTree(json), user));
}
- private static boolean processNode(JsonNode node, User user,
+ // todo: integrate notifications into system!
+ private boolean processNode(JsonNode node, User user,
Collection<? extends RewriteTask> tasks) {
- KoralNode knode = KoralNode.getNode(node, user);
+ KoralNode knode = KoralNode.wrapNode(node);
for (RewriteTask task : tasks) {
if (jlog.isDebugEnabled()) {
jlog.debug("running node in processor " + node);
jlog.debug("on processor " + task.getClass().toString());
}
- task.rewrite(knode);
+ task.rewrite(knode, this.config, user);
if (knode.toRemove())
break;
}
diff --git a/src/main/java/de/ids_mannheim/korap/resource/rewrite/RewriteTask.java b/src/main/java/de/ids_mannheim/korap/resource/rewrite/RewriteTask.java
index 4b44c42..07bebc4 100644
--- a/src/main/java/de/ids_mannheim/korap/resource/rewrite/RewriteTask.java
+++ b/src/main/java/de/ids_mannheim/korap/resource/rewrite/RewriteTask.java
@@ -1,6 +1,8 @@
package de.ids_mannheim.korap.resource.rewrite;
import com.fasterxml.jackson.databind.JsonNode;
+import de.ids_mannheim.korap.config.KustvaktConfiguration;
+import de.ids_mannheim.korap.user.User;
import lombok.Getter;
/**
@@ -13,8 +15,14 @@
private RewriteTask() {
}
- public abstract JsonNode rewrite(KoralNode node);
-
+ /**
+ * @param node Json node in KoralNode wrapper
+ * @param config {@link KustvaktConfiguration} singleton instance to use default configuration parameters
+ * @param user injected by rewrite handler if available. Might cause {@link NullPointerException} if not checked properly
+ * @return
+ */
+ public abstract JsonNode rewrite(KoralNode node,
+ KustvaktConfiguration config, User user);
/**
* query rewrites get injected the entire query from root containing all child nodes
@@ -31,12 +39,10 @@
}
}
-
-
/**
* node rewrites get injected typically object nodes that are subject to altering.
* Be aware that node rewrites are processed before query rewrites. Thus query rewrite may override previous node rewrites
- *
+ * <p/>
* {@link de.ids_mannheim.korap.resource.rewrite.RewriteTask.RewriteNode} rewrite support the deletion of the respective node by simply setting the node invalid in KoralNode
*
* @author hanl
diff --git a/src/main/java/de/ids_mannheim/korap/resource/rewrite/TreeConstraint.java b/src/main/java/de/ids_mannheim/korap/resource/rewrite/TreeConstraint.java
index 0bde30f..245e787 100644
--- a/src/main/java/de/ids_mannheim/korap/resource/rewrite/TreeConstraint.java
+++ b/src/main/java/de/ids_mannheim/korap/resource/rewrite/TreeConstraint.java
@@ -1,6 +1,8 @@
package de.ids_mannheim.korap.resource.rewrite;
import com.fasterxml.jackson.databind.JsonNode;
+import de.ids_mannheim.korap.config.KustvaktConfiguration;
+import de.ids_mannheim.korap.user.User;
/**
* #ELEM(W ANA=N)
@@ -44,12 +46,13 @@
private String pointer;
- public TreeConstraint(String constraint_pointer) {
- this.pointer = constraint_pointer;
+ public TreeConstraint() {
+ super();
}
@Override
- public JsonNode rewrite(KoralNode node) {
+ public JsonNode rewrite(KoralNode node, KustvaktConfiguration config,
+ User user) {
System.out.println("FIND PATH " + node.rawNode().findParent(pointer));
return node.rawNode();
diff --git a/src/main/java/de/ids_mannheim/korap/web/service/light/LightService.java b/src/main/java/de/ids_mannheim/korap/web/service/light/LightService.java
index b7463d9..621e87d 100644
--- a/src/main/java/de/ids_mannheim/korap/web/service/light/LightService.java
+++ b/src/main/java/de/ids_mannheim/korap/web/service/light/LightService.java
@@ -47,9 +47,9 @@
this.searchKrill = new SearchKrill(config.getIndexDir());
UriBuilder builder = UriBuilder.fromUri("http://10.0.10.13").port(9997);
this.graphDBhandler = new ClientsHandler(builder.build());
- this.processor = new RewriteHandler();
- this.processor.add(new FoundryInject(this.config));
- this.processor.add(new PublicCollection());
+ this.processor = new RewriteHandler(config);
+ this.processor.add(FoundryInject.class);
+ this.processor.add(PublicCollection.class);
}
/**
diff --git a/src/main/resources/log4j.properties b/src/main/resources/log4j.properties
index ff5d34c..602c496 100644
--- a/src/main/resources/log4j.properties
+++ b/src/main/resources/log4j.properties
@@ -1,7 +1,7 @@
# Root logger option
#log4j.threshold=ALL
-log4j.rootLogger=DEBUG, stdout, debugLog
+log4j.rootLogger=INFO, stdout, debugLog
log4j.logger.log=ERROR, errorLog
# Direct log messages to stdout
diff --git a/src/test/java/CollectionRewriteTest.java b/src/test/java/CollectionRewriteTest.java
index 19cea60..c1c88b1 100644
--- a/src/test/java/CollectionRewriteTest.java
+++ b/src/test/java/CollectionRewriteTest.java
@@ -12,6 +12,7 @@
* @author hanl
* @date 03/09/2015
*/
+// todo: 20.10.15
public class CollectionRewriteTest {
private static String simple_add_query = "[pos=ADJA]";
@@ -24,10 +25,10 @@
config = BeanConfiguration.getBeans().getConfiguration();
}
-// @Test
+ // @Test
public void testCollectionNodeRemoveCorpusIdNoErrors() {
- RewriteHandler handler = new RewriteHandler();
- handler.add(new CollectionConstraint());
+ RewriteHandler handler = new RewriteHandler(config);
+ handler.add(CollectionConstraint.class);
QuerySerializer s = new QuerySerializer();
s.setQuery(simple_add_query, "poliqarp");
s.setCollection("textClass=politik & corpusID=WPD");
@@ -39,8 +40,8 @@
//@Test
public void testCollectionNodeRemoveAllCorpusIdNoErrors() {
- RewriteHandler handler = new RewriteHandler();
- handler.add(new CollectionConstraint());
+ RewriteHandler handler = new RewriteHandler(config);
+ handler.add(CollectionConstraint.class);
QuerySerializer s = new QuerySerializer();
s.setQuery(simple_add_query, "poliqarp");
s.setCollection("corpusID=BRZ13 & corpusID=WPD");
@@ -53,8 +54,8 @@
//@Test
public void testCollectionNodeRemoveGroupedCorpusIdNoErrors() {
- RewriteHandler handler = new RewriteHandler();
- handler.add(new CollectionConstraint());
+ RewriteHandler handler = new RewriteHandler(config);
+ handler.add(CollectionConstraint.class);
QuerySerializer s = new QuerySerializer();
s.setQuery(simple_add_query, "poliqarp");
s.setCollection(
@@ -72,9 +73,9 @@
//fixme: will probably fail when one doc groups are being refactored
//@Test
public void testCollectionCleanEmptyDocGroupNoErrors() {
- RewriteHandler handler = new RewriteHandler();
- handler.add(new CollectionConstraint());
- handler.add(new CollectionCleanupFilter());
+ RewriteHandler handler = new RewriteHandler(config);
+ handler.add(CollectionConstraint.class);
+ handler.add(CollectionCleanupFilter.class);
QuerySerializer s = new QuerySerializer();
s.setQuery(simple_add_query, "poliqarp");
s.setCollection(
@@ -92,9 +93,9 @@
//@Test
public void testCollectionCleanMoveOneDocFromGroupUpNoErrors() {
- RewriteHandler handler = new RewriteHandler();
- handler.add(new CollectionConstraint());
- handler.add(new CollectionCleanupFilter());
+ RewriteHandler handler = new RewriteHandler(config);
+ handler.add(CollectionConstraint.class);
+ handler.add(CollectionCleanupFilter.class);
QuerySerializer s = new QuerySerializer();
s.setQuery(simple_add_query, "poliqarp");
s.setCollection("(corpusID=BRZ13 & textClass=Wissenschaft)");
@@ -106,9 +107,9 @@
//@Test
public void testCollectionCleanEmptyGroupAndMoveOneFromGroupUpNoErrors() {
- RewriteHandler handler = new RewriteHandler();
- handler.add(new CollectionConstraint());
- handler.add(new CollectionCleanupFilter());
+ RewriteHandler handler = new RewriteHandler(config);
+ handler.add(CollectionConstraint.class);
+ handler.add(CollectionCleanupFilter.class);
QuerySerializer s = new QuerySerializer();
s.setQuery(simple_add_query, "poliqarp");
s.setCollection(
@@ -122,9 +123,9 @@
//@Test
public void testCollectionRemoveAndMoveOneFromGroupUpNoErrors() {
- RewriteHandler handler = new RewriteHandler();
- handler.add(new CollectionConstraint());
- handler.add(new CollectionCleanupFilter());
+ RewriteHandler handler = new RewriteHandler(config);
+ handler.add(CollectionConstraint.class);
+ handler.add(CollectionCleanupFilter.class);
QuerySerializer s = new QuerySerializer();
s.setQuery(simple_add_query, "poliqarp");
s.setCollection(
diff --git a/src/test/java/FoundryRewriteTest.java b/src/test/java/FoundryRewriteTest.java
index 5a91a09..ff19ec2 100644
--- a/src/test/java/FoundryRewriteTest.java
+++ b/src/test/java/FoundryRewriteTest.java
@@ -32,8 +32,8 @@
@Test
public void testSimpleFoundryAddThrowsNoError() {
- RewriteHandler processor = new RewriteHandler();
- processor.add(new FoundryInject(config));
+ RewriteHandler processor = new RewriteHandler(config);
+ processor.add(FoundryInject.class);
QuerySerializer s = new QuerySerializer();
s.setQuery(simple_add_query, "poliqarp");
String result = processor.apply(s.toJSON(), null);
@@ -57,9 +57,9 @@
@Test
public void testFoundryInjectPosNoErrors() {
QuerySerializer s = new QuerySerializer();
- RewriteHandler handler = new RewriteHandler();
+ RewriteHandler handler = new RewriteHandler(config);
s.setQuery("[pos=ADJA]", "poliqarp");
- handler.add(new FoundryInject(config));
+ assert handler.add(FoundryInject.class);
String result = handler.apply(s.toJSON(), null);
JsonNode node = JsonUtils.readTree(result);
@@ -73,9 +73,9 @@
@Test
public void testFoundryInjectJoinedQueryNoErrors() {
QuerySerializer s = new QuerySerializer();
- RewriteHandler handler = new RewriteHandler();
+ RewriteHandler handler = new RewriteHandler(config);
s.setQuery("[orth=laufe/i & base!=Lauf]", "poliqarp");
- handler.add(new FoundryInject(config));
+ assert handler.add(FoundryInject.class);
String result = handler.apply(s.toJSON(), null);
JsonNode node = JsonUtils.readTree(result);
@@ -90,9 +90,9 @@
@Test
public void testFoundryInjectGroupedQueryNoErrors() {
QuerySerializer s = new QuerySerializer();
- RewriteHandler handler = new RewriteHandler();
+ RewriteHandler handler = new RewriteHandler(config);
s.setQuery("[(base=laufen | base=gehen) & tt/pos=VVFIN]", "poliqarp");
- handler.add(new FoundryInject(config));
+ assert handler.add(FoundryInject.class);
String result = handler.apply(s.toJSON(), null);
JsonNode node = JsonUtils.readTree(result);
diff --git a/src/test/java/de/ids_mannheim/korap/config/TestHelper.java b/src/test/java/de/ids_mannheim/korap/config/TestHelper.java
index 3040814..fb7eaa7 100644
--- a/src/test/java/de/ids_mannheim/korap/config/TestHelper.java
+++ b/src/test/java/de/ids_mannheim/korap/config/TestHelper.java
@@ -19,8 +19,9 @@
private static final String[] credentials = new String[] { "test1",
"testPass#2015" };
- public static void setup() {
- if (BeanConfiguration.hasContext()) {
+ public static boolean setup() {
+ boolean r = BeanConfiguration.hasContext();
+ if (r) {
EntityHandlerIface dao = BeanConfiguration.getBeans()
.getUserDBHandler();
@@ -32,8 +33,10 @@
dao.createAccount(user);
}catch (KustvaktException e) {
e.printStackTrace();
+ return false;
}
}
+ return r;
}
public static final String[] getCredentials() {