blob: d2d36100bcf34888a2b788431d78ed3cde50e246 [file] [log] [blame]
margarethaefc18a42018-03-01 16:01:42 +01001package de.ids_mannheim.korap.rewrite;
2
3import com.fasterxml.jackson.databind.JsonNode;
margaretha6b3ecdd2018-03-01 18:23:56 +01004
margarethaefc18a42018-03-01 16:01:42 +01005import de.ids_mannheim.korap.config.Attributes;
6import de.ids_mannheim.korap.config.KustvaktConfiguration;
margarethaefc18a42018-03-01 16:01:42 +01007import de.ids_mannheim.korap.user.User;
8
margaretha35e1ca22023-11-16 22:00:01 +01009/**
10 * EM: not used anymore. This rewrite was meant to remove doc from
11 * a collection by checking user access to the doc.
margaretha4fa4b062019-01-28 19:43:30 +010012 *
margarethaefc18a42018-03-01 16:01:42 +010013 * @author hanl
14 * @date 03/07/2015
15 */
16public class CollectionConstraint implements RewriteTask.IterableRewritePath {
17
margarethaefc18a42018-03-01 16:01:42 +010018 @Override
margaretha1bc9cca2018-12-11 15:09:44 +010019 public KoralNode rewriteQuery (KoralNode node, KustvaktConfiguration config,
margarethaefc18a42018-03-01 16:01:42 +010020 User user) {
21 if (node.get("@type").equals("koral:doc")) {
22 if (node.get("key").equals(Attributes.CORPUS_SIGLE)) {
23 String id = node.get("value");
24 // EM: MH checks if user has access to corpus
margaretha35e1ca22023-11-16 22:00:01 +010025 // KustvaktResource corpus = check(id, user);
26 // if (corpus == null)
27 node.removeNode(new KoralNode.RewriteIdentifier(
28 Attributes.CORPUS_SIGLE, id));
margarethaefc18a42018-03-01 16:01:42 +010029 }
30 }
margaretha1bc9cca2018-12-11 15:09:44 +010031 return node;
margarethaefc18a42018-03-01 16:01:42 +010032 }
33
margarethaefc18a42018-03-01 16:01:42 +010034 /**
35 * @param id
36 * @param user
37 * @return boolean if true access granted
38 */
margaretha35e1ca22023-11-16 22:00:01 +010039 // @Deprecated
40 // private KustvaktResource check (String id, User user) {
41 // // todo: can be used to circumvent access control if public filter not applied
42 // if (user == null)
43 // return null;
44 //
45 // KustvaktResource corpus;
46 // try {
47 // SecurityManager m = SecurityManager
48 // .findbyId(id, user, Corpus.class);
49 // corpus = m.getResource();
50 // }
51 // catch (RuntimeException | KustvaktException e) {
52 // return null;
53 // }
54 // return corpus;
55 // }
margarethaefc18a42018-03-01 16:01:42 +010056
57 @Override
58 public JsonNode rewriteResult (KoralNode node) {
59 return null;
60 }
61
margarethaefc18a42018-03-01 16:01:42 +010062 @Override
63 public String path () {
64 return "collection";
65 }
66}