1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19 package org.mycore.access.mcrimpl;
20
21 import java.util.Optional;
22
23 import org.jdom2.Element;
24 import org.mycore.common.MCRSessionMgr;
25 import org.mycore.common.MCRUserInformation;
26 import org.mycore.parsers.bool.MCRCondition;
27
28
29
30
31
32
33
34 class MCRGroupClause implements MCRCondition<Object> {
35
36 private String groupname;
37
38 private boolean not;
39
40 MCRGroupClause(String group, boolean not) {
41 groupname = group;
42 this.not = not;
43 }
44
45 public boolean evaluate(Object o) {
46 MCRUserInformation userInformation = Optional.ofNullable(o)
47 .filter(obj -> obj instanceof MCRAccessData)
48 .map(MCRAccessData.class::cast)
49 .map(MCRAccessData::getUserInformation)
50 .orElseGet(MCRSessionMgr.getCurrentSession()::getUserInformation);
51 return userInformation.isUserInRole(groupname) ^ not;
52 }
53
54 @Override
55 public String toString() {
56 return "group" + (not ? " != " : " = ") + groupname + " ";
57 }
58
59 public Element toXML() {
60 Element cond = new Element("condition");
61 cond.setAttribute("field", "group");
62 cond.setAttribute("operator", (not ? "!=" : "="));
63 cond.setAttribute("value", groupname);
64 return cond;
65 }
66 }