| margaretha | 398f472 | 2019-01-09 19:07:20 +0100 | [diff] [blame] | 1 | package de.ids_mannheim.korap.rewrite; |
| Michael Hanl | 1e18cb4 | 2015-08-06 20:57:35 +0200 | [diff] [blame] | 2 | |
| margaretha | 56e8e55 | 2017-12-05 16:31:21 +0100 | [diff] [blame] | 3 | import java.lang.reflect.Constructor; |
| 4 | import java.lang.reflect.InvocationTargetException; |
| 5 | import java.util.Collection; |
| 6 | import java.util.HashSet; |
| 7 | import java.util.Iterator; |
| margaretha | 563aabe | 2018-09-13 20:39:45 +0200 | [diff] [blame] | 8 | import java.util.LinkedHashSet; |
| margaretha | 4fa4b06 | 2019-01-28 19:43:30 +0100 | [diff] [blame] | 9 | import java.util.List; |
| margaretha | 56e8e55 | 2017-12-05 16:31:21 +0100 | [diff] [blame] | 10 | import java.util.Map; |
| 11 | import java.util.Set; |
| 12 | |
| margaretha | 49cb688 | 2018-07-04 04:19:54 +0200 | [diff] [blame] | 13 | import org.apache.logging.log4j.LogManager; |
| 14 | import org.apache.logging.log4j.Logger; |
| margaretha | 56e8e55 | 2017-12-05 16:31:21 +0100 | [diff] [blame] | 15 | import org.springframework.beans.factory.annotation.Autowired; |
| 16 | |
| Michael Hanl | 1e18cb4 | 2015-08-06 20:57:35 +0200 | [diff] [blame] | 17 | import com.fasterxml.jackson.databind.JsonNode; |
| margaretha | 56e8e55 | 2017-12-05 16:31:21 +0100 | [diff] [blame] | 18 | |
| Michael Hanl | 59bff81 | 2015-10-27 23:10:32 +0100 | [diff] [blame] | 19 | import de.ids_mannheim.korap.config.KustvaktConfiguration; |
| Michael Hanl | 3a1dfe1 | 2016-02-17 11:26:07 +0100 | [diff] [blame] | 20 | import de.ids_mannheim.korap.exceptions.KustvaktException; |
| Michael Hanl | 1e18cb4 | 2015-08-06 20:57:35 +0200 | [diff] [blame] | 21 | import de.ids_mannheim.korap.user.User; |
| 22 | import de.ids_mannheim.korap.utils.JsonUtils; |
| Michael Hanl | 1e18cb4 | 2015-08-06 20:57:35 +0200 | [diff] [blame] | 23 | |
| 24 | /** |
| 25 | * @author hanl |
| 26 | * @date 30/06/2015 |
| 27 | */ |
| Michael Hanl | f078532 | 2015-11-13 16:14:45 +0100 | [diff] [blame] | 28 | // todo: do post processing! |
| Michael Hanl | f21773f | 2015-10-16 23:02:31 +0200 | [diff] [blame] | 29 | //todo: load rewritenode and rewritequery automatically from classpath by default, but namespaced from package |
| margaretha | 35e1ca2 | 2023-11-16 22:00:01 +0100 | [diff] [blame] | 30 | public class RewriteHandler { |
| margaretha | ade7d4a | 2017-07-20 19:53:35 +0200 | [diff] [blame] | 31 | //implements BeanInjectable { |
| Michael Hanl | 1e18cb4 | 2015-08-06 20:57:35 +0200 | [diff] [blame] | 32 | |
| margaretha | 49cb688 | 2018-07-04 04:19:54 +0200 | [diff] [blame] | 33 | private static Logger jlog = LogManager.getLogger(RewriteHandler.class); |
| Michael Hanl | e56bb89 | 2016-05-25 17:34:41 +0200 | [diff] [blame] | 34 | private Collection<RewriteTask.IterableRewritePath> node_processors; |
| Michael Hanl | f078532 | 2015-11-13 16:14:45 +0100 | [diff] [blame] | 35 | private Collection<RewriteTask.RewriteKoralToken> token_node_processors; |
| Michael Hanl | bcb48c7 | 2015-11-17 22:11:05 +0100 | [diff] [blame] | 36 | private Collection<RewriteTask> query_processors; |
| Michael Hanl | 022543e | 2015-11-17 21:25:25 +0100 | [diff] [blame] | 37 | |
| Michael Hanl | 2760cc4 | 2015-11-16 19:30:01 +0100 | [diff] [blame] | 38 | private Set<Class> failed_task_registration; |
| margaretha | ade7d4a | 2017-07-20 19:53:35 +0200 | [diff] [blame] | 39 | @Autowired |
| Michael Hanl | 59bff81 | 2015-10-27 23:10:32 +0100 | [diff] [blame] | 40 | private KustvaktConfiguration config; |
| Michael Hanl | 1e18cb4 | 2015-08-06 20:57:35 +0200 | [diff] [blame] | 41 | |
| margaretha | 4fa4b06 | 2019-01-28 19:43:30 +0100 | [diff] [blame] | 42 | public RewriteHandler (List<RewriteTask> rewriteTasks) { |
| 43 | this(); |
| margaretha | 35e1ca2 | 2023-11-16 22:00:01 +0100 | [diff] [blame] | 44 | for (RewriteTask t : rewriteTasks) { |
| margaretha | 4fa4b06 | 2019-01-28 19:43:30 +0100 | [diff] [blame] | 45 | addProcessor(t); |
| 46 | } |
| 47 | } |
| margaretha | 35e1ca2 | 2023-11-16 22:00:01 +0100 | [diff] [blame] | 48 | |
| margaretha | 4fa4b06 | 2019-01-28 19:43:30 +0100 | [diff] [blame] | 49 | // EM: for testing |
| Michael Hanl | 8abaf9e | 2016-05-23 16:46:35 +0200 | [diff] [blame] | 50 | public RewriteHandler (KustvaktConfiguration config) { |
| Michael Hanl | daf8660 | 2016-05-12 14:31:52 +0200 | [diff] [blame] | 51 | this(); |
| margaretha | 35e1ca2 | 2023-11-16 22:00:01 +0100 | [diff] [blame] | 52 | this.config = config; |
| Michael Hanl | daf8660 | 2016-05-12 14:31:52 +0200 | [diff] [blame] | 53 | } |
| 54 | |
| Michael Hanl | 8abaf9e | 2016-05-23 16:46:35 +0200 | [diff] [blame] | 55 | public RewriteHandler () { |
| Michael Hanl | 1e18cb4 | 2015-08-06 20:57:35 +0200 | [diff] [blame] | 56 | this.node_processors = new HashSet<>(); |
| Michael Hanl | f078532 | 2015-11-13 16:14:45 +0100 | [diff] [blame] | 57 | this.token_node_processors = new HashSet<>(); |
| margaretha | 563aabe | 2018-09-13 20:39:45 +0200 | [diff] [blame] | 58 | this.query_processors = new LinkedHashSet<>(); |
| Michael Hanl | 2760cc4 | 2015-11-16 19:30:01 +0100 | [diff] [blame] | 59 | this.failed_task_registration = new HashSet<>(); |
| Michael Hanl | daf8660 | 2016-05-12 14:31:52 +0200 | [diff] [blame] | 60 | } |
| 61 | |
| Michael Hanl | 8abaf9e | 2016-05-23 16:46:35 +0200 | [diff] [blame] | 62 | public Set getFailedProcessors () { |
| Michael Hanl | daf8660 | 2016-05-12 14:31:52 +0200 | [diff] [blame] | 63 | return this.failed_task_registration; |
| Michael Hanl | 1e18cb4 | 2015-08-06 20:57:35 +0200 | [diff] [blame] | 64 | } |
| 65 | |
| Michael Hanl | 8abaf9e | 2016-05-23 16:46:35 +0200 | [diff] [blame] | 66 | public boolean addProcessor (RewriteTask rewriter) { |
| Michael Hanl | f078532 | 2015-11-13 16:14:45 +0100 | [diff] [blame] | 67 | if (rewriter instanceof RewriteTask.RewriteKoralToken) |
| 68 | return this.token_node_processors |
| 69 | .add((RewriteTask.RewriteKoralToken) rewriter); |
| Michael Hanl | e56bb89 | 2016-05-25 17:34:41 +0200 | [diff] [blame] | 70 | else if (rewriter instanceof RewriteTask.IterableRewritePath) |
| Michael Hanl | 022543e | 2015-11-17 21:25:25 +0100 | [diff] [blame] | 71 | return this.node_processors |
| Michael Hanl | e56bb89 | 2016-05-25 17:34:41 +0200 | [diff] [blame] | 72 | .add((RewriteTask.IterableRewritePath) rewriter); |
| Michael Hanl | 33829ec | 2016-05-28 17:03:38 +0200 | [diff] [blame] | 73 | else if (rewriter instanceof RewriteTask.RewriteQuery |
| 74 | | rewriter instanceof RewriteTask.RewriteResult) |
| Michael Hanl | bcb48c7 | 2015-11-17 22:11:05 +0100 | [diff] [blame] | 75 | return this.query_processors.add(rewriter); |
| Michael Hanl | 2760cc4 | 2015-11-16 19:30:01 +0100 | [diff] [blame] | 76 | |
| 77 | this.failed_task_registration.add(rewriter.getClass()); |
| Michael Hanl | f078532 | 2015-11-13 16:14:45 +0100 | [diff] [blame] | 78 | return false; |
| Michael Hanl | 1e18cb4 | 2015-08-06 20:57:35 +0200 | [diff] [blame] | 79 | } |
| 80 | |
| Michael Hanl | f078532 | 2015-11-13 16:14:45 +0100 | [diff] [blame] | 81 | @Override |
| Michael Hanl | 8abaf9e | 2016-05-23 16:46:35 +0200 | [diff] [blame] | 82 | public String toString () { |
| Michael Hanl | f078532 | 2015-11-13 16:14:45 +0100 | [diff] [blame] | 83 | StringBuilder b = new StringBuilder(); |
| 84 | b.append("--------------------------"); |
| 85 | b.append("pre/post: " + this.node_processors.toString()).append("\n") |
| 86 | .append("\n") |
| 87 | .append("query: " + this.query_processors.toString()) |
| 88 | .append("\n") |
| 89 | .append("koraltoken: " + this.token_node_processors.toString()); |
| 90 | b.append("---------------------------"); |
| 91 | return b.toString(); |
| Michael Hanl | 59bff81 | 2015-10-27 23:10:32 +0100 | [diff] [blame] | 92 | } |
| 93 | |
| 94 | /** |
| Michael Hanl | 8abaf9e | 2016-05-23 16:46:35 +0200 | [diff] [blame] | 95 | * expects extended RewriteNode/Query class with empty default |
| 96 | * constructor |
| 97 | * |
| Michael Hanl | 59bff81 | 2015-10-27 23:10:32 +0100 | [diff] [blame] | 98 | * @param rewriter |
| Michael Hanl | 8abaf9e | 2016-05-23 16:46:35 +0200 | [diff] [blame] | 99 | * @return boolean if rewriter class was successfully added to |
| 100 | * rewrite handler! |
| Michael Hanl | 59bff81 | 2015-10-27 23:10:32 +0100 | [diff] [blame] | 101 | */ |
| margaretha | 4fa4b06 | 2019-01-28 19:43:30 +0100 | [diff] [blame] | 102 | @Deprecated |
| Michael Hanl | 8abaf9e | 2016-05-23 16:46:35 +0200 | [diff] [blame] | 103 | public boolean add (Class<? extends RewriteTask> rewriter) { |
| Michael Hanl | 59bff81 | 2015-10-27 23:10:32 +0100 | [diff] [blame] | 104 | RewriteTask task; |
| 105 | try { |
| 106 | Constructor c = rewriter.getConstructor(); |
| 107 | task = (RewriteTask) c.newInstance(); |
| Michael Hanl | 8abaf9e | 2016-05-23 16:46:35 +0200 | [diff] [blame] | 108 | } |
| 109 | catch (NoSuchMethodException | InvocationTargetException |
| Michael Hanl | 59bff81 | 2015-10-27 23:10:32 +0100 | [diff] [blame] | 110 | | IllegalAccessException | InstantiationException e) { |
| Michael Hanl | 2760cc4 | 2015-11-16 19:30:01 +0100 | [diff] [blame] | 111 | this.failed_task_registration.add(rewriter); |
| Michael Hanl | 59bff81 | 2015-10-27 23:10:32 +0100 | [diff] [blame] | 112 | return false; |
| 113 | } |
| Michael Hanl | f078532 | 2015-11-13 16:14:45 +0100 | [diff] [blame] | 114 | return addProcessor(task); |
| Michael Hanl | 1e18cb4 | 2015-08-06 20:57:35 +0200 | [diff] [blame] | 115 | } |
| 116 | |
| Michael Hanl | f8fcc7a | 2016-06-03 17:41:07 +0200 | [diff] [blame] | 117 | public String processQuery (JsonNode root, User user) |
| 118 | throws KustvaktException { |
| Michael Hanl | 86d598e | 2016-05-26 15:13:00 +0200 | [diff] [blame] | 119 | RewriteProcess process = new RewriteProcess(root, user); |
| 120 | JsonNode pre = process.start(false); |
| Michael Hanl | cedf721 | 2016-05-28 10:43:09 +0200 | [diff] [blame] | 121 | return JsonUtils.toJSON(pre); |
| Michael Hanl | 4b42baa | 2015-11-17 21:46:04 +0100 | [diff] [blame] | 122 | } |
| 123 | |
| Michael Hanl | f8fcc7a | 2016-06-03 17:41:07 +0200 | [diff] [blame] | 124 | public String processQuery (String json, User user) |
| 125 | throws KustvaktException { |
| Michael Hanl | 33829ec | 2016-05-28 17:03:38 +0200 | [diff] [blame] | 126 | return processQuery(JsonUtils.readTree(json), user); |
| Michael Hanl | f078532 | 2015-11-13 16:14:45 +0100 | [diff] [blame] | 127 | } |
| 128 | |
| Michael Hanl | f8fcc7a | 2016-06-03 17:41:07 +0200 | [diff] [blame] | 129 | public String processResult (String json, User user) |
| 130 | throws KustvaktException { |
| Michael Hanl | 33829ec | 2016-05-28 17:03:38 +0200 | [diff] [blame] | 131 | return processResult(JsonUtils.readTree(json), user); |
| 132 | } |
| 133 | |
| Michael Hanl | f8fcc7a | 2016-06-03 17:41:07 +0200 | [diff] [blame] | 134 | public String processResult (JsonNode node, User user) |
| 135 | throws KustvaktException { |
| Michael Hanl | 33829ec | 2016-05-28 17:03:38 +0200 | [diff] [blame] | 136 | RewriteProcess process = new RewriteProcess(node, user); |
| 137 | JsonNode pre = process.start(true); |
| 138 | return JsonUtils.toJSON(pre); |
| 139 | } |
| 140 | |
| Michael Hanl | 86d598e | 2016-05-26 15:13:00 +0200 | [diff] [blame] | 141 | public void clear () { |
| 142 | this.node_processors.clear(); |
| 143 | this.query_processors.clear(); |
| 144 | this.token_node_processors.clear(); |
| Michael Hanl | 022543e | 2015-11-17 21:25:25 +0100 | [diff] [blame] | 145 | } |
| 146 | |
| margaretha | 35e1ca2 | 2023-11-16 22:00:01 +0100 | [diff] [blame] | 147 | // public <T extends ContextHolder> void insertBeans (T beans) { |
| 148 | // this.beans = beans; |
| 149 | // this.config = beans.getConfiguration(); |
| 150 | // } |
| Michael Hanl | 86d598e | 2016-05-26 15:13:00 +0200 | [diff] [blame] | 151 | |
| 152 | public class RewriteProcess { |
| 153 | |
| margaretha | a85965d | 2018-12-19 15:58:21 +0100 | [diff] [blame] | 154 | private static final boolean DEBUG = false; |
| Michael Hanl | 86d598e | 2016-05-26 15:13:00 +0200 | [diff] [blame] | 155 | private JsonNode root; |
| 156 | private User user; |
| 157 | |
| Michael Hanl | 33829ec | 2016-05-28 17:03:38 +0200 | [diff] [blame] | 158 | private RewriteProcess (JsonNode root, User user) { |
| Michael Hanl | 86d598e | 2016-05-26 15:13:00 +0200 | [diff] [blame] | 159 | this.root = root; |
| 160 | this.user = user; |
| 161 | } |
| 162 | |
| Michael Hanl | 33829ec | 2016-05-28 17:03:38 +0200 | [diff] [blame] | 163 | private KoralNode processNode (String key, JsonNode value, |
| Michael Hanl | f8fcc7a | 2016-06-03 17:41:07 +0200 | [diff] [blame] | 164 | boolean result) throws KustvaktException { |
| Michael Hanl | 86d598e | 2016-05-26 15:13:00 +0200 | [diff] [blame] | 165 | KoralNode kroot = KoralNode.wrapNode(value); |
| 166 | if (value.isObject()) { |
| 167 | if (value.has("operands")) { |
| 168 | JsonNode ops = value.at("/operands"); |
| 169 | Iterator<JsonNode> it = ops.elements(); |
| 170 | while (it.hasNext()) { |
| 171 | JsonNode next = it.next(); |
| Michael Hanl | 33829ec | 2016-05-28 17:03:38 +0200 | [diff] [blame] | 172 | KoralNode kn = processNode(key, next, result); |
| Michael Hanl | 86d598e | 2016-05-26 15:13:00 +0200 | [diff] [blame] | 173 | if (kn.isRemove()) |
| 174 | it.remove(); |
| 175 | } |
| 176 | } |
| 177 | else if (value.path("@type").asText().equals("koral:token")) { |
| 178 | // todo: koral:token nodes cannot be flagged for deletion --> creates the possibility for empty koral:token nodes |
| 179 | rewrite(key, kroot, |
| Michael Hanl | 33829ec | 2016-05-28 17:03:38 +0200 | [diff] [blame] | 180 | RewriteHandler.this.token_node_processors, result); |
| 181 | return processNode(key, value.path("wrap"), result); |
| Michael Hanl | 86d598e | 2016-05-26 15:13:00 +0200 | [diff] [blame] | 182 | } |
| 183 | else { |
| 184 | return rewrite(key, kroot, |
| Michael Hanl | 33829ec | 2016-05-28 17:03:38 +0200 | [diff] [blame] | 185 | RewriteHandler.this.node_processors, result); |
| Michael Hanl | 86d598e | 2016-05-26 15:13:00 +0200 | [diff] [blame] | 186 | } |
| 187 | } |
| 188 | else if (value.isArray()) { |
| 189 | Iterator<JsonNode> it = value.elements(); |
| 190 | while (it.hasNext()) { |
| 191 | JsonNode next = it.next(); |
| Michael Hanl | 33829ec | 2016-05-28 17:03:38 +0200 | [diff] [blame] | 192 | KoralNode kn = processNode(key, next, result); |
| Michael Hanl | 86d598e | 2016-05-26 15:13:00 +0200 | [diff] [blame] | 193 | if (kn.isRemove()) |
| 194 | it.remove(); |
| 195 | } |
| 196 | } |
| 197 | return kroot; |
| 198 | } |
| 199 | |
| Michael Hanl | f8fcc7a | 2016-06-03 17:41:07 +0200 | [diff] [blame] | 200 | private JsonNode start (boolean result) throws KustvaktException { |
| margaretha | 35e1ca2 | 2023-11-16 22:00:01 +0100 | [diff] [blame] | 201 | if (DEBUG) { |
| 202 | jlog.debug("Running rewrite process on query " + root); |
| margaretha | a85965d | 2018-12-19 15:58:21 +0100 | [diff] [blame] | 203 | } |
| Michael Hanl | 86d598e | 2016-05-26 15:13:00 +0200 | [diff] [blame] | 204 | if (root != null) { |
| 205 | Iterator<Map.Entry<String, JsonNode>> it = root.fields(); |
| 206 | while (it.hasNext()) { |
| 207 | Map.Entry<String, JsonNode> next = it.next(); |
| Michael Hanl | 33829ec | 2016-05-28 17:03:38 +0200 | [diff] [blame] | 208 | processNode(next.getKey(), next.getValue(), result); |
| Michael Hanl | 86d598e | 2016-05-26 15:13:00 +0200 | [diff] [blame] | 209 | } |
| Michael Hanl | 33829ec | 2016-05-28 17:03:38 +0200 | [diff] [blame] | 210 | processFixedNode(root, RewriteHandler.this.query_processors, |
| 211 | result); |
| Michael Hanl | 86d598e | 2016-05-26 15:13:00 +0200 | [diff] [blame] | 212 | } |
| 213 | return root; |
| 214 | } |
| 215 | |
| 216 | /** |
| 217 | * @param node |
| 218 | * @param tasks |
| Michael Hanl | 33829ec | 2016-05-28 17:03:38 +0200 | [diff] [blame] | 219 | * @return boolean true if node is to be removed from parent! |
| 220 | * Only |
| Michael Hanl | 86d598e | 2016-05-26 15:13:00 +0200 | [diff] [blame] | 221 | * applies if parent is an array node |
| 222 | */ |
| 223 | private KoralNode rewrite (String rootNode, KoralNode node, |
| Michael Hanl | f8fcc7a | 2016-06-03 17:41:07 +0200 | [diff] [blame] | 224 | Collection<? extends RewriteTask> tasks, boolean result) |
| 225 | throws KustvaktException { |
| Michael Hanl | 86d598e | 2016-05-26 15:13:00 +0200 | [diff] [blame] | 226 | if (RewriteHandler.this.config == null) |
| margaretha | 35e1ca2 | 2023-11-16 22:00:01 +0100 | [diff] [blame] | 227 | throw new RuntimeException( |
| 228 | "KustvaktConfiguration must be set!"); |
| Michael Hanl | 86d598e | 2016-05-26 15:13:00 +0200 | [diff] [blame] | 229 | |
| 230 | for (RewriteTask task : tasks) { |
| margaretha | a85965d | 2018-12-19 15:58:21 +0100 | [diff] [blame] | 231 | if (DEBUG) { |
| 232 | jlog.debug("running processor on node: " + node); |
| 233 | jlog.debug("on processor: " + task.getClass().toString()); |
| 234 | } |
| Michael Hanl | 86d598e | 2016-05-26 15:13:00 +0200 | [diff] [blame] | 235 | |
| margaretha | 35e1ca2 | 2023-11-16 22:00:01 +0100 | [diff] [blame] | 236 | // if (RewriteHandler.this.beans != null |
| 237 | // && task instanceof BeanInjectable) |
| 238 | // ((BeanInjectable) task) |
| 239 | // .insertBeans(RewriteHandler.this.beans); |
| Michael Hanl | 86d598e | 2016-05-26 15:13:00 +0200 | [diff] [blame] | 240 | |
| 241 | if (task instanceof RewriteTask.IterableRewritePath) { |
| 242 | RewriteTask.IterableRewritePath rw = (RewriteTask.IterableRewritePath) task; |
| 243 | if (rw.path() != null && !rw.path().equals(rootNode)) { |
| margaretha | 35e1ca2 | 2023-11-16 22:00:01 +0100 | [diff] [blame] | 244 | if (DEBUG) { |
| margaretha | a85965d | 2018-12-19 15:58:21 +0100 | [diff] [blame] | 245 | jlog.debug("skipping node: " + node); |
| 246 | } |
| Michael Hanl | 86d598e | 2016-05-26 15:13:00 +0200 | [diff] [blame] | 247 | continue; |
| 248 | } |
| 249 | } |
| Michael Hanl | f8fcc7a | 2016-06-03 17:41:07 +0200 | [diff] [blame] | 250 | if (!result && task instanceof RewriteTask.RewriteQuery) { |
| 251 | ((RewriteTask.RewriteQuery) task).rewriteQuery(node, |
| 252 | RewriteHandler.this.config, this.user); |
| Michael Hanl | 86d598e | 2016-05-26 15:13:00 +0200 | [diff] [blame] | 253 | } |
| Michael Hanl | f8fcc7a | 2016-06-03 17:41:07 +0200 | [diff] [blame] | 254 | else if (task instanceof RewriteTask.RewriteResult) { |
| 255 | ((RewriteTask.RewriteResult) task).rewriteResult(node); |
| Michael Hanl | 86d598e | 2016-05-26 15:13:00 +0200 | [diff] [blame] | 256 | } |
| Michael Hanl | f8fcc7a | 2016-06-03 17:41:07 +0200 | [diff] [blame] | 257 | |
| Michael Hanl | 86d598e | 2016-05-26 15:13:00 +0200 | [diff] [blame] | 258 | if (node.isRemove()) { |
| Michael Hanl | 33829ec | 2016-05-28 17:03:38 +0200 | [diff] [blame] | 259 | node.buildRewrites(this.root.at("/" + rootNode)); |
| Michael Hanl | 86d598e | 2016-05-26 15:13:00 +0200 | [diff] [blame] | 260 | break; |
| Michael Hanl | 33829ec | 2016-05-28 17:03:38 +0200 | [diff] [blame] | 261 | } |
| 262 | else |
| Michael Hanl | 86d598e | 2016-05-26 15:13:00 +0200 | [diff] [blame] | 263 | node.buildRewrites(); |
| 264 | } |
| 265 | return node; |
| 266 | } |
| 267 | |
| 268 | // fixme: merge with processNode! |
| 269 | private void processFixedNode (JsonNode node, |
| Michael Hanl | f8fcc7a | 2016-06-03 17:41:07 +0200 | [diff] [blame] | 270 | Collection<RewriteTask> tasks, boolean post) |
| 271 | throws KustvaktException { |
| Michael Hanl | 86d598e | 2016-05-26 15:13:00 +0200 | [diff] [blame] | 272 | for (RewriteTask task : tasks) { |
| 273 | KoralNode next = KoralNode.wrapNode(node); |
| 274 | if (task instanceof RewriteTask.RewriteNodeAt) { |
| 275 | RewriteTask.RewriteNodeAt rwa = (RewriteTask.RewriteNodeAt) task; |
| margaretha | 35e1ca2 | 2023-11-16 22:00:01 +0100 | [diff] [blame] | 276 | if ((rwa.at() != null |
| 277 | && !node.at(rwa.at()).isMissingNode())) |
| Michael Hanl | 86d598e | 2016-05-26 15:13:00 +0200 | [diff] [blame] | 278 | next = next.at(rwa.at()); |
| 279 | } |
| 280 | |
| Michael Hanl | f8fcc7a | 2016-06-03 17:41:07 +0200 | [diff] [blame] | 281 | if (!post & task instanceof RewriteTask.RewriteQuery) |
| margaretha | 1bc9cca | 2018-12-11 15:09:44 +0100 | [diff] [blame] | 282 | next = ((RewriteTask.RewriteQuery) task).rewriteQuery(next, |
| Michael Hanl | f8fcc7a | 2016-06-03 17:41:07 +0200 | [diff] [blame] | 283 | RewriteHandler.this.config, user); |
| 284 | else if (task instanceof RewriteTask.RewriteResult) |
| 285 | ((RewriteTask.RewriteResult) task).rewriteResult(next); |
| 286 | next.buildRewrites(); |
| 287 | |
| Michael Hanl | 86d598e | 2016-05-26 15:13:00 +0200 | [diff] [blame] | 288 | } |
| 289 | } |
| 290 | |
| Michael Hanl | 86d598e | 2016-05-26 15:13:00 +0200 | [diff] [blame] | 291 | } |
| margaretha | 3495447 | 2018-10-24 20:05:17 +0200 | [diff] [blame] | 292 | |
| Michael Hanl | 1e18cb4 | 2015-08-06 20:57:35 +0200 | [diff] [blame] | 293 | } |