Revision 47109
Added by Michele Artini over 6 years ago
modules/dnet-isti/trunk/src/main/java/eu/dnetlib/msro/workflows/nodes/GeneratePersonReportJobNode.java | ||
---|---|---|
3 | 3 |
import java.io.PrintWriter; |
4 | 4 |
import java.io.StringReader; |
5 | 5 |
import java.io.StringWriter; |
6 |
import java.nio.charset.StandardCharsets; |
|
6 | 7 |
import java.nio.file.Files; |
7 | 8 |
import java.nio.file.Paths; |
8 | 9 |
import java.text.SimpleDateFormat; |
... | ... | |
43 | 44 |
|
44 | 45 |
protected class SinglePersonReport { |
45 | 46 |
|
47 |
private final String id; |
|
46 | 48 |
private final String title; |
47 | 49 |
private final List<String> oldCreators = new ArrayList<>(); |
48 | 50 |
private final List<String> newCreators = new ArrayList<>(); |
49 | 51 |
|
50 |
public SinglePersonReport(final String title) { |
|
52 |
public SinglePersonReport(final String id, final String title) { |
|
53 |
this.id = id; |
|
51 | 54 |
this.title = title; |
52 | 55 |
} |
53 | 56 |
|
57 |
public String getId() { |
|
58 |
return id; |
|
59 |
} |
|
60 |
|
|
54 | 61 |
public String getTitle() { |
55 | 62 |
return title; |
56 | 63 |
} |
... | ... | |
80 | 87 |
} |
81 | 88 |
|
82 | 89 |
public boolean hasCorrections() { |
83 |
/* |
|
84 |
* final int size = newCreators.size(); |
|
85 |
* |
|
86 |
* if (oldCreators.size() != size) { return true; } |
|
87 |
* |
|
88 |
* final Set<String> set = new HashSet<>(); set.addAll(oldCreators); set.addAll(newCreators); |
|
89 |
* |
|
90 |
* return set.size() != size; |
|
91 |
*/ |
|
92 |
|
|
93 | 90 |
return (oldCreators.size() > 0) || (newCreators.size() > 0); |
94 | 91 |
} |
95 | 92 |
|
... | ... | |
97 | 94 |
public String toString() { |
98 | 95 |
final StringWriter sw = new StringWriter(); |
99 | 96 |
sw.write("** "); |
97 |
sw.write(id); |
|
98 |
sw.write(" - "); |
|
100 | 99 |
sw.write(title); |
101 | 100 |
sw.write(" **\n"); |
102 |
sw.write("ORIGINAL:\n"); |
|
103 |
for (int i = 0; i < oldCreators.size(); i++) { |
|
104 |
sw.write(String.format("%5d) %s\n", i + 1, oldCreators.get(i))); |
|
101 |
|
|
102 |
if (oldCreators.size() > 0) { |
|
103 |
sw.write("ORIGINAL:\n"); |
|
104 |
for (int i = 0; i < oldCreators.size(); i++) { |
|
105 |
final String s = oldCreators.get(i); |
|
106 |
sw.write(String.format("%5d) %s\n", i + 1, StringUtils.isNotBlank(s) ? s : "[empty]")); |
|
107 |
} |
|
105 | 108 |
} |
106 |
sw.write("CORRECTED:\n"); |
|
107 |
for (int i = 0; i < newCreators.size(); i++) { |
|
108 |
sw.write(String.format("%5d) %s\n", i + 1, newCreators.get(i))); |
|
109 |
if (newCreators.size() > 0) { |
|
110 |
sw.write("CORRECTED:\n"); |
|
111 |
for (int i = 0; i < newCreators.size(); i++) { |
|
112 |
final String s = newCreators.get(i); |
|
113 |
sw.write(String.format("%5d) %s\n", i + 1, StringUtils.isNotBlank(s) ? s : "[empty]")); |
|
114 |
} |
|
109 | 115 |
} |
110 | 116 |
return sw.toString(); |
111 | 117 |
} |
... | ... | |
114 | 120 |
|
115 | 121 |
@Override |
116 | 122 |
protected String execute(final Env env) throws Exception { |
123 |
|
|
117 | 124 |
@SuppressWarnings("unchecked") |
125 |
final ResultSet<String> rsIn = env.getAttribute(inputEprParam, ResultSet.class); |
|
118 | 126 |
|
119 |
final ResultSet<String> rsIn = env.getAttribute(inputEprParam, ResultSet.class); |
|
120 | 127 |
final SimpleDataTransformer f = dataTransformerFactory.createTransformer(ruleId); |
121 | 128 |
final SAXReader reader = new SAXReader(); |
122 | 129 |
|
123 | 130 |
final String fileName = "/tmp/report_" + (new SimpleDateFormat("yyyyMMdd_HHmmss_S")).format(new Date()) + ".txt"; |
124 | 131 |
|
125 |
try (PrintWriter pw = new PrintWriter(Files.newBufferedWriter(Paths.get(fileName)))) { |
|
132 |
try (PrintWriter pw = new PrintWriter(Files.newBufferedWriter(Paths.get(fileName), StandardCharsets.UTF_8))) {
|
|
126 | 133 |
StreamSupport.stream(resultSetClient.iter(rsIn, String.class).spliterator(), false).map( |
127 | 134 |
xml -> { |
128 | 135 |
try { |
129 | 136 |
final Document docOld = reader.read(new StringReader(xml)); |
130 | 137 |
final Document docNew = reader.read(new StringReader(f.apply(xml))); |
131 | 138 |
|
132 |
final SinglePersonReport report = new SinglePersonReport(docNew.valueOf("//*[local-name() = 'title']")); |
|
139 |
final String id = docNew.valueOf("//*[local-name() = 'recordIdentifier']"); |
|
140 |
final String title = docNew.valueOf("//*[local-name() = 'title']"); |
|
141 |
|
|
142 |
final SinglePersonReport report = new SinglePersonReport(id, title); |
|
133 | 143 |
for (final Object o : docOld.selectNodes("//*[local-name() = 'creator']")) { |
134 | 144 |
final String p1 = ((Node) o).valueOf("./*[local-name() = 'surname']").trim(); |
135 | 145 |
final String p2 = ((Node) o).valueOf("./*[local-name() = 'name']").trim(); |
Also available in: Unified diff
wf to generate a report of corrected authors