1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19 package org.mycore.wfc.actionmapping;
20
21 import org.apache.logging.log4j.LogManager;
22 import org.jdom2.Element;
23 import org.mycore.datamodel.classifications2.MCRCategLinkReference;
24 import org.mycore.datamodel.classifications2.MCRCategLinkService;
25 import org.mycore.datamodel.classifications2.MCRCategLinkServiceFactory;
26 import org.mycore.datamodel.classifications2.MCRCategoryID;
27 import org.mycore.parsers.bool.MCRCondition;
28
29
30
31
32
33 public class MCRCategoryCondition implements MCRCondition<MCRWorkflowData> {
34
35 private MCRCategoryID mcrCategoryID;
36
37 private boolean not;
38
39 private String fieldName;
40
41 private static MCRCategLinkService LINK_SERVICE = MCRCategLinkServiceFactory.getInstance();
42
43 public MCRCategoryCondition(String fieldName, MCRCategoryID mcrCategoryID, boolean not) {
44 this.fieldName = fieldName;
45 this.mcrCategoryID = mcrCategoryID;
46 this.not = not;
47
48 }
49
50
51
52
53 @Override
54 public boolean evaluate(MCRWorkflowData workflowData) {
55 MCRCategLinkReference reference = workflowData.getCategoryReference();
56 if (reference == null) {
57 LogManager.getLogger(getClass())
58 .error("Cannot evaluate '{}', if MCRWorkflowData does not contain an object reference",
59 toString());
60 return false;
61 }
62 return LINK_SERVICE.isInCategory(reference, mcrCategoryID) ^ not;
63 }
64
65 @Override
66 public String toString() {
67 return fieldName + (not ? " != " : " = ") + mcrCategoryID.getID() + " ";
68 }
69
70
71
72
73 @Override
74 public Element toXML() {
75 Element cond = new Element("condition");
76 cond.setAttribute("field", fieldName);
77 cond.setAttribute("operator", (not ? "!=" : "="));
78 cond.setAttribute("value", mcrCategoryID.getID());
79 return cond;
80 }
81
82 }