json pointer rewrite restriction parameter
diff --git a/src/main/java/de/ids_mannheim/korap/config/KustvaktConfiguration.java b/src/main/java/de/ids_mannheim/korap/config/KustvaktConfiguration.java
index 4fe6a27..33b2398 100644
--- a/src/main/java/de/ids_mannheim/korap/config/KustvaktConfiguration.java
+++ b/src/main/java/de/ids_mannheim/korap/config/KustvaktConfiguration.java
@@ -180,7 +180,7 @@
if (f.exists()) {
log4j.load(new FileInputStream(f));
PropertyConfigurator.configure(log4j);
- jlog.warn(
+ jlog.info(
"using local logging properties file ({}) to configure logging system",
"./log4j.properties");
return;
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 af6470d..03b77ec 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
@@ -58,6 +58,6 @@
@Override
public String at() {
- return "collection";
+ return "/collection";
}
}
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 dc74cab..5b31fa4 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
@@ -121,8 +121,8 @@
}
}else if (root.path("@type").asText().equals("koral:token")) {
// todo: koral:token nodes cannot be flagged for deletion --> creates the possibility for empty koral:token nodes
- // processIterableNode(KoralNode.wrapNode(root), user,
- // this.token_node_processors, post);
+ processNode(name,KoralNode.wrapNode(root), user,
+ this.token_node_processors, post);
return process(name, root.path("wrap"), user, post);
}else {
return processNode(name, KoralNode.wrapNode(root), user,
@@ -139,8 +139,7 @@
return false;
}
- public JsonNode preProcess(JsonNode root, User user) {
- boolean post = false;
+ private JsonNode process(JsonNode root, User user, boolean post) {
Iterator<Map.Entry<String, JsonNode>> it = root.fields();
while (it.hasNext()) {
Map.Entry<String, JsonNode> next = it.next();
@@ -150,19 +149,16 @@
return root;
}
+ public JsonNode preProcess(JsonNode root, User user) {
+ return process(root, user, false);
+ }
+
public String preProcess(String json, User user) {
return JsonUtils.toJSON(preProcess(JsonUtils.readTree(json), user));
}
public JsonNode postProcess(JsonNode root, User user) {
- boolean post = true;
- Iterator<Map.Entry<String, JsonNode>> it = root.fields();
- while (it.hasNext()) {
- Map.Entry<String, JsonNode> next = it.next();
- process(next.getKey(), next.getValue(), user, post);
- }
- processFixedNode(root, user, this.query_processors, post);
- return root;
+ return process(root, user, true);
}
public String postProcess(String json, User user) {
@@ -177,8 +173,7 @@
*/
// todo: integrate notifications into system!
private boolean processNode(String rootNode, KoralNode node, User user,
- Collection<? extends RewriteTask.IterableRewriteAt> tasks,
- boolean post) {
+ Collection<? extends RewriteTask> tasks, boolean post) {
for (RewriteTask task : tasks) {
jlog.debug("running processor on node: " + node);
jlog.debug("on processor: " + task.getClass().toString());
@@ -206,13 +201,14 @@
private void processFixedNode(JsonNode node, User user,
Collection<RewriteTask.RewriteNodeAt> tasks, boolean post) {
for (RewriteTask.RewriteNodeAt task : tasks) {
- if (!node.at(task.at()).isMissingNode()) {
- if (!post)
- task.preProcess(KoralNode.wrapNode(node.at(task.at())),
- this.config, user);
- else
- task.postProcess(KoralNode.wrapNode(node.at(task.at())));
- }
+ JsonNode next = node;
+ if ((task.at() != null && !node.at(task.at()).isMissingNode()))
+ next = node.at(task.at());
+
+ if (!post)
+ task.preProcess(KoralNode.wrapNode(next), this.config, user);
+ else
+ task.postProcess(KoralNode.wrapNode(next));
}
}
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 7a7189c..11e29b8 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
@@ -21,14 +21,26 @@
User user);
}
+ /**
+ *
+ */
interface RewriteAfter extends RewriteTask {
JsonNode postProcess(KoralNode node);
}
+ /**
+ * nodes subject to rewrites at fixed json pointer location.
+ * Json-pointer based rewrites are processed after iterable rewrites
+ * Deletion via KoralNode not allowed.
+ */
interface RewriteNodeAt extends RewriteBefore, RewriteAfter {
String at();
}
+ /**
+ * terminal object nodes that are subject to rewrites through node iteration
+ * (both object and array node iteration supported)
+ */
interface IterableRewriteAt extends RewriteBefore, RewriteAfter {
String path();
}