1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19 package org.mycore.mods.enrichment;
20
21 import java.util.ArrayList;
22 import java.util.List;
23 import java.util.concurrent.Callable;
24
25 import org.apache.logging.log4j.LogManager;
26 import org.apache.logging.log4j.Logger;
27 import org.jdom2.Element;
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45 class MCRDataSourceCall implements Callable<Boolean> {
46
47 private static final Logger LOGGER = LogManager.getLogger(MCRDataSourceCall.class);
48
49 private MCRDataSource ds;
50
51 private MCRIdentifierPool idPool;
52
53 private List<Element> results = new ArrayList<Element>();
54
55 private boolean gotResults = false;
56
57 MCRDataSourceCall(MCRDataSource ds, MCRIdentifierPool idPool) {
58 this.ds = ds;
59 this.idPool = idPool;
60 }
61
62
63
64
65
66
67
68 public Boolean call() {
69 if (!isFinished()) {
70 loop: for (MCRIdentifierResolver idResolver : ds.getResolvers()) {
71 for (MCRIdentifier id : idPool.getCurrentIdentifiersOfType(idResolver.getType())) {
72 if (isFinished()) {
73 break loop;
74 }
75
76 Element result = idResolver.resolve(id.getValue());
77 if (result != null) {
78 gotResults = true;
79 results.add(result);
80 idPool.addIdentifiersFrom(result);
81 }
82
83 LOGGER.info(ds + " with " + id + " returned " + (result != null ? "" : "no ") + "valid data");
84 }
85 }
86 }
87
88 return wasSuccessful();
89 }
90
91 boolean wasSuccessful() {
92 return gotResults;
93 }
94
95 private boolean isFinished() {
96 return ds.shouldStopOnFirstResult() ? wasSuccessful() : false;
97 }
98
99 List<Element> getResults() {
100 return results;
101 }
102
103 void clearResults() {
104 results.clear();
105 }
106 }