1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19 package org.mycore.mods.access.facts.condition;
20
21 import java.util.Optional;
22
23 import org.jdom2.Element;
24 import org.mycore.access.facts.MCRFactsHolder;
25 import org.mycore.access.facts.condition.fact.MCRStringCondition;
26 import org.mycore.access.facts.fact.MCRObjectIDFact;
27 import org.mycore.access.facts.fact.MCRStringFact;
28 import org.mycore.datamodel.metadata.MCRObject;
29 import org.mycore.mods.MCRMODSEmbargoUtils;
30
31
32
33
34
35
36
37
38 public class MCRMODSEmbargoCondition extends MCRStringCondition {
39
40 private String idFact = "objid";
41
42 @Override
43 public void parse(Element xml) {
44 super.parse(xml);
45 this.idFact = Optional.ofNullable(xml.getAttributeValue("idfact")).orElse("objid");
46 }
47
48 @Override
49 public Optional<MCRStringFact> computeFact(MCRFactsHolder facts) {
50 Optional<MCRObjectIDFact> idc = facts.require(idFact);
51 if (idc.isPresent()) {
52 Optional<MCRObject> optMCRObject = idc.get().getObject();
53 if (optMCRObject.isPresent()) {
54 String embargo = MCRMODSEmbargoUtils.getEmbargo(optMCRObject.get());
55
56
57 if (embargo != null) {
58 MCRStringFact fact = new MCRStringFact(getFactName(), getTerm());
59 fact.setValue(embargo);
60 facts.add(fact);
61 return Optional.of(fact);
62 }
63 }
64 }
65 return Optional.empty();
66 }
67 }