Revision f104a204
Added by Andreas Müller almost 2 years ago
cdmlib-commons/src/main/java/eu/etaxonomy/cdm/common/monitor/DefaultProgressMonitor.java | ||
---|---|---|
91 | 91 |
// this.workDone = this.workDone + work; |
92 | 92 |
} |
93 | 93 |
|
94 |
|
|
95 | 94 |
@Override |
96 | 95 |
public void internalWorked(double work) { |
97 | 96 |
computeWorked(work); |
... | ... | |
147 | 146 |
return result; |
148 | 147 |
} |
149 | 148 |
|
150 |
|
|
151 |
/** |
|
152 |
* {@inheritDoc} |
|
153 |
*/ |
|
154 | 149 |
@Override |
155 | 150 |
public void waitForFeedback() { |
156 | 151 |
if(feedbackLock == null) { |
... | ... | |
170 | 165 |
} |
171 | 166 |
} |
172 | 167 |
|
173 |
/** |
|
174 |
* {@inheritDoc} |
|
175 |
*/ |
|
176 | 168 |
@Override |
177 | 169 |
public void setFeedback(Serializable feedback) { |
178 | 170 |
synchronized (feedbackLock) { |
... | ... | |
182 | 174 |
} |
183 | 175 |
} |
184 | 176 |
|
185 |
|
|
186 |
/** |
|
187 |
* {@inheritDoc} |
|
188 |
*/ |
|
189 | 177 |
@Override |
190 | 178 |
public Serializable getFeedback() { |
191 | 179 |
return feedback; |
192 | 180 |
} |
193 | 181 |
|
194 |
/** |
|
195 |
* {@inheritDoc} |
|
196 |
*/ |
|
197 | 182 |
@Override |
198 | 183 |
public boolean getIsWaitingForFeedback() { |
199 | 184 |
return isWaitingForFeedback; |
200 | 185 |
} |
201 | 186 |
|
202 |
|
|
203 |
/** |
|
204 |
* {@inheritDoc} |
|
205 |
*/ |
|
206 | 187 |
@Override |
207 | 188 |
public void waitForFeedback(long feedbackWaitTimeout) { |
208 | 189 |
if(feedbackWaitTimeout <= 0 ) { |
... | ... | |
212 | 193 |
waitForFeedback(); |
213 | 194 |
} |
214 | 195 |
|
215 |
|
|
216 |
/** |
|
217 |
* {@inheritDoc} |
|
218 |
*/ |
|
219 | 196 |
@Override |
220 | 197 |
public boolean hasFeedbackWaitTimedOut() { |
221 | 198 |
long now = System.currentTimeMillis(); |
222 | 199 |
return isWaitingForFeedback && (now - feedbackWaitStartTime > feedbackWaitTimeout); |
223 | 200 |
} |
224 | 201 |
|
225 |
|
|
226 |
|
|
227 |
/** |
|
228 |
* {@inheritDoc} |
|
229 |
*/ |
|
230 | 202 |
@Override |
231 | 203 |
public String getOwner() { |
232 | 204 |
return owner; |
233 | 205 |
} |
234 | 206 |
|
235 |
|
|
236 |
/** |
|
237 |
* {@inheritDoc} |
|
238 |
*/ |
|
239 | 207 |
@Override |
240 | 208 |
public void setOwner(String owner) { |
241 | 209 |
this.owner = owner; |
242 | 210 |
} |
243 | 211 |
|
244 |
|
|
245 |
/** |
|
246 |
* {@inheritDoc} |
|
247 |
*/ |
|
248 | 212 |
@Override |
249 | 213 |
public void interrupt() { |
250 | 214 |
// do nothing |
251 | 215 |
} |
252 |
|
|
253 |
|
|
254 |
|
|
255 |
} |
|
216 |
} |
cdmlib-commons/src/main/java/eu/etaxonomy/cdm/common/monitor/NullProgressMonitor.java | ||
---|---|---|
1 | 1 |
/** |
2 |
* |
|
3 |
*/ |
|
2 |
* Copyright (C) 2015 EDIT |
|
3 |
* European Distributed Institute of Taxonomy |
|
4 |
* http://www.e-taxonomy.eu |
|
5 |
* |
|
6 |
* The contents of this file are subject to the Mozilla Public License Version 1.1 |
|
7 |
* See LICENSE.TXT at the top of this package for the full license terms. |
|
8 |
*/ |
|
4 | 9 |
package eu.etaxonomy.cdm.common.monitor; |
5 | 10 |
|
6 | 11 |
import java.io.Serializable; |
7 | 12 |
|
8 |
|
|
9 | 13 |
/** |
10 | 14 |
* Empty default implementation |
11 | 15 |
* |
... | ... | |
66 | 70 |
// do nothing |
67 | 71 |
} |
68 | 72 |
|
69 |
/** |
|
70 |
* {@inheritDoc} |
|
71 |
*/ |
|
72 | 73 |
@Override |
73 | 74 |
public void waitForFeedback() { |
74 | 75 |
// do nothing |
75 | 76 |
} |
76 | 77 |
|
77 |
/** |
|
78 |
* {@inheritDoc} |
|
79 |
*/ |
|
80 | 78 |
@Override |
81 | 79 |
public void setFeedback(Serializable feedback) { |
82 | 80 |
// do nothing |
83 | 81 |
} |
84 | 82 |
|
85 |
/** |
|
86 |
* {@inheritDoc} |
|
87 |
*/ |
|
88 | 83 |
@Override |
89 | 84 |
public Serializable getFeedback() { |
90 | 85 |
return null; |
91 | 86 |
} |
92 | 87 |
|
93 |
/** |
|
94 |
* {@inheritDoc} |
|
95 |
*/ |
|
96 | 88 |
@Override |
97 | 89 |
public boolean getIsWaitingForFeedback() { |
98 | 90 |
return false; |
99 | 91 |
} |
100 | 92 |
|
101 |
/** |
|
102 |
* {@inheritDoc} |
|
103 |
*/ |
|
104 | 93 |
@Override |
105 | 94 |
public void waitForFeedback(long feedbackWaitTimeout) { |
106 |
// do nothing |
|
107 |
|
|
95 |
// do nothing |
|
108 | 96 |
} |
109 | 97 |
|
110 |
/** |
|
111 |
* {@inheritDoc} |
|
112 |
*/ |
|
113 | 98 |
@Override |
114 | 99 |
public boolean hasFeedbackWaitTimedOut() { |
115 | 100 |
return false; |
116 | 101 |
} |
117 | 102 |
|
118 |
/** |
|
119 |
* {@inheritDoc} |
|
120 |
*/ |
|
121 | 103 |
@Override |
122 | 104 |
public String getOwner() { |
123 | 105 |
return null; |
124 | 106 |
} |
125 | 107 |
|
126 |
/** |
|
127 |
* {@inheritDoc} |
|
128 |
*/ |
|
129 | 108 |
@Override |
130 | 109 |
public void setOwner(String owner) { |
131 | 110 |
// do nothing |
132 |
|
|
133 | 111 |
} |
134 | 112 |
|
135 |
/** |
|
136 |
* {@inheritDoc} |
|
137 |
*/ |
|
138 | 113 |
@Override |
139 | 114 |
public void interrupt() { |
140 | 115 |
// do nothing |
141 |
|
|
142 | 116 |
} |
143 |
|
|
144 |
} |
|
117 |
} |
cdmlib-io/src/main/java/eu/etaxonomy/cdm/io/common/EmptyImportState.java | ||
---|---|---|
11 | 11 |
/** |
12 | 12 |
* @author a.mueller |
13 | 13 |
* @since 14.03.2017 |
14 |
* |
|
15 | 14 |
*/ |
16 | 15 |
public class EmptyImportState<CONFIG extends ImportConfiguratorBase, IO extends CdmImportBase> |
17 | 16 |
extends ImportStateBase<CONFIG, IO> { |
18 | 17 |
|
19 |
/** |
|
20 |
* @param config |
|
21 |
*/ |
|
22 | 18 |
protected EmptyImportState(CONFIG config) { |
23 | 19 |
super(config); |
24 | 20 |
} |
25 | 21 |
|
26 |
/** |
|
27 |
* {@inheritDoc} |
|
28 |
*/ |
|
29 | 22 |
@Override |
30 | 23 |
public CONFIG getConfig() { |
31 | 24 |
return super.getConfig(); |
32 | 25 |
} |
33 |
|
|
34 |
|
|
35 |
|
|
36 |
} |
|
26 |
} |
cdmlib-io/src/main/java/eu/etaxonomy/cdm/io/common/SimpleImportConfiguratorBase.java | ||
---|---|---|
14 | 14 |
/** |
15 | 15 |
* @author a.mueller |
16 | 16 |
* @since 14.03.2017 |
17 |
* |
|
18 | 17 |
*/ |
19 | 18 |
public abstract class SimpleImportConfiguratorBase<SOURCE extends Object> |
20 | 19 |
extends ImportConfiguratorBase<EmptyImportState<SimpleImportConfiguratorBase,?>, SOURCE>{ |
21 | 20 |
private static final long serialVersionUID = 5310312930219876822L; |
22 | 21 |
|
23 |
/** |
|
24 |
* @param transformer |
|
25 |
*/ |
|
26 | 22 |
protected SimpleImportConfiguratorBase(SOURCE source, ICdmDataSource destination, IInputTransformer transformer) { |
27 | 23 |
super(transformer); |
28 | 24 |
setSource(source); |
29 | 25 |
setDestination(destination); |
30 | 26 |
} |
31 | 27 |
|
32 |
|
|
33 |
/** |
|
34 |
* {@inheritDoc} |
|
35 |
*/ |
|
36 | 28 |
@Override |
37 | 29 |
public EmptyImportState getNewState() { |
38 | 30 |
return new EmptyImportState(this); |
39 | 31 |
} |
40 |
|
|
41 |
} |
|
32 |
} |
cdmlib-io/src/main/java/eu/etaxonomy/cdm/io/csv/in/CsvImportBase.java | ||
---|---|---|
109 | 109 |
} catch (IOException e) { |
110 | 110 |
throw new RuntimeException(e); |
111 | 111 |
} |
112 |
|
|
113 | 112 |
} |
114 | 113 |
|
115 | 114 |
private TransactionStatus startNewTransaction(STATE state, TransactionStatus tx) { |
... | ... | |
214 | 213 |
return sourceRef; |
215 | 214 |
} |
216 | 215 |
|
217 |
/** |
|
218 |
* {@inheritDoc} |
|
219 |
*/ |
|
220 | 216 |
@Override |
221 | 217 |
protected boolean doCheck(STATE state) { |
222 | 218 |
return true; |
223 | 219 |
} |
224 | 220 |
|
225 |
/** |
|
226 |
* {@inheritDoc} |
|
227 |
*/ |
|
228 | 221 |
@Override |
229 | 222 |
protected boolean isIgnore(STATE state) { |
230 | 223 |
return false; |
231 | 224 |
} |
232 |
} |
|
225 |
} |
cdmlib-io/src/main/java/eu/etaxonomy/cdm/io/csv/redlist/demo/CsvDemoExport.java | ||
---|---|---|
6 | 6 |
* The contents of this file are subject to the Mozilla Public License Version 1.1 |
7 | 7 |
* See LICENSE.TXT at the top of this package for the full license terms. |
8 | 8 |
*/ |
9 |
|
|
10 | 9 |
package eu.etaxonomy.cdm.io.csv.redlist.demo; |
11 | 10 |
|
12 | 11 |
import java.io.ByteArrayOutputStream; |
... | ... | |
21 | 20 |
import java.util.UUID; |
22 | 21 |
|
23 | 22 |
import org.apache.commons.lang.StringUtils; |
24 |
import org.apache.logging.log4j.LogManager;import org.apache.logging.log4j.Logger; |
|
23 |
import org.apache.logging.log4j.LogManager; |
|
24 |
import org.apache.logging.log4j.Logger; |
|
25 | 25 |
import org.springframework.stereotype.Component; |
26 | 26 |
import org.springframework.transaction.TransactionStatus; |
27 | 27 |
|
... | ... | |
49 | 49 |
import eu.etaxonomy.cdm.model.taxon.TaxonRelationship; |
50 | 50 |
import eu.etaxonomy.cdm.model.taxon.TaxonRelationshipType; |
51 | 51 |
|
52 |
|
|
53 | 52 |
/** |
54 | 53 |
* @author a.oppermann |
55 | 54 |
* @since 18.10.2012 |
56 | 55 |
*/ |
57 |
|
|
58 | 56 |
@Component |
59 | 57 |
public class CsvDemoExport extends CsvDemoBase { |
60 | 58 |
|
... | ... | |
110 | 108 |
} |
111 | 109 |
break; |
112 | 110 |
case EXPORT_DATA: |
113 |
exportStream = new ByteArrayOutputStream();;
|
|
111 |
exportStream = new ByteArrayOutputStream(); |
|
114 | 112 |
writer = new PrintWriter(exportStream); |
115 | 113 |
break; |
116 | 114 |
default : |
... | ... | |
137 | 135 |
this.clearExistingRecordIds(); |
138 | 136 |
} |
139 | 137 |
|
140 |
// commitTransaction(txStatus); |
|
141 | 138 |
return; |
142 | 139 |
} |
143 | 140 |
|
144 |
|
|
145 |
/** |
|
146 |
* @param state |
|
147 |
* @param config |
|
148 |
* @param txStatus |
|
149 |
* @param classificationSet |
|
150 |
* @param recordList |
|
151 |
*/ |
|
152 | 141 |
private void performJsonXMLPagination(CsvDemoExportState state, CsvDemoExportConfigurator config, |
153 | 142 |
TransactionStatus txStatus, Set<Classification> classificationSet, List<CsvDemoRecord> recordList) { |
154 |
// TODO Auto-generated method stub |
|
143 |
|
|
155 | 144 |
Classification classification = null; |
156 | 145 |
for(Classification c : classificationSet){ |
157 | 146 |
classification = c; |
... | ... | |
176 | 165 |
commitTransaction(txStatus); |
177 | 166 |
} |
178 | 167 |
|
179 |
|
|
180 |
/** |
|
181 |
* @param state |
|
182 |
* @param config |
|
183 |
* @param txStatus |
|
184 |
* @param classificationSet |
|
185 |
* @param progressMonitor |
|
186 |
* @param writer |
|
187 |
* @return |
|
188 |
*/ |
|
189 | 168 |
private void performCSVExport(CsvDemoExportState state, CsvDemoExportConfigurator config, |
190 | 169 |
TransactionStatus txStatus, Set<Classification> classificationSet, IProgressMonitor progressMonitor, |
191 | 170 |
PrintWriter writer) { |
... | ... | |
264 | 243 |
} |
265 | 244 |
} |
266 | 245 |
|
267 |
|
|
268 | 246 |
//TODO: Exception handling |
269 | 247 |
/** |
270 | 248 |
* |
271 | 249 |
* @param config |
272 |
* @return |
|
273 | 250 |
*/ |
274 | 251 |
protected Set<Classification> assembleClassificationSet(CsvDemoExportConfigurator config){ |
275 | 252 |
if(config != null){ |
... | ... | |
284 | 261 |
|
285 | 262 |
//TODO: Exception handling |
286 | 263 |
/** |
287 |
* |
|
288 | 264 |
* @param state |
289 |
* @return |
|
290 | 265 |
*/ |
291 | 266 |
private CsvDemoRecord assembleRecord(CsvDemoExportState state) { |
292 | 267 |
if(state!=null){ |
... | ... | |
299 | 274 |
return null; |
300 | 275 |
} |
301 | 276 |
|
302 |
|
|
303 | 277 |
/** |
304 | 278 |
* handles the information record for the actual {@link Taxon} including {@link Classification classification}, Taxon Name, Taxon ID, |
305 | 279 |
* Taxon Status, Synonyms, {@link Feature features} data |
280 |
* |
|
306 | 281 |
* @param record the concrete information record |
307 |
* @param taxonBase {@link Taxon} |
|
308 |
* @param name |
|
309 |
* @param acceptedTaxon |
|
310 |
* @param parent |
|
311 |
* @param basionym |
|
312 |
* @param isPartial |
|
313 |
* @param isProParte |
|
314 |
* @param config |
|
315 |
* @param node |
|
316 |
* @param node |
|
317 |
* @param type |
|
318 | 282 |
*/ |
319 | 283 |
private void handleTaxonBase(CsvDemoRecord record, TaxonBase<?> taxonBase, |
320 | 284 |
INonViralName name, Classification classification, |
... | ... | |
397 | 361 |
if(config.isRedlistFeatures()){ |
398 | 362 |
if(features!= null) { |
399 | 363 |
|
400 |
List<List<String>> featureCells = new ArrayList<List<String>>(features.size());
|
|
364 |
List<List<String>> featureCells = new ArrayList<>(features.size()); |
|
401 | 365 |
for(int i = 0; i < features.size(); i++) { |
402 |
featureCells.add(new ArrayList<String>());
|
|
366 |
featureCells.add(new ArrayList<>()); |
|
403 | 367 |
} |
404 | 368 |
handleRelatedRedlistStatus(record, taxon, false, featureCells, features); |
405 | 369 |
handleRelatedRedlistStatus(record, taxon, true, featureCells, features); |
406 |
|
|
407 | 370 |
} |
408 | 371 |
} |
409 | 372 |
|
... | ... | |
428 | 391 |
} |
429 | 392 |
} |
430 | 393 |
|
431 |
/** |
|
432 |
* @param record |
|
433 |
* @param name |
|
434 |
* @param type |
|
435 |
* @param isPartial |
|
436 |
* @param isProParte |
|
437 |
*/ |
|
438 | 394 |
private void handleTaxonomicStatus( |
439 | 395 |
CsvDemoRecord record, |
440 | 396 |
INonViralName name, |
... | ... | |
471 | 427 |
} |
472 | 428 |
|
473 | 429 |
/** |
474 |
* |
|
475 | 430 |
* This method concatenates several synonyms in a list. |
476 |
* |
|
477 |
* @param record |
|
478 |
* @param taxon |
|
479 | 431 |
*/ |
480 | 432 |
private void handleSynonyms(CsvDemoRecord record, Taxon taxon) { |
481 | 433 |
|
... | ... | |
492 | 444 |
record.setSynonyms(synonymLabels); |
493 | 445 |
} |
494 | 446 |
|
495 |
/** |
|
496 |
* |
|
497 |
* @param record |
|
498 |
* @param taxon |
|
499 |
*/ |
|
500 | 447 |
private void handleDiscriptionData(CsvDemoRecord record, Taxon taxon) { |
501 | 448 |
|
502 | 449 |
Set<TaxonDescription> descriptions = taxon.getDescriptions(); |
... | ... | |
513 | 460 |
} |
514 | 461 |
record.setCountryCode(distributions); |
515 | 462 |
} |
516 |
/** |
|
517 |
* |
|
518 |
* @param record |
|
519 |
* @param taxon |
|
520 |
* @param featureCells |
|
521 |
* @param features |
|
522 |
*/ |
|
463 |
|
|
523 | 464 |
private void handleRedlistStatus(CsvDemoRecord record, Taxon taxon, List<List<String>> featureCells, List<Feature> features){ |
524 | 465 |
Set<TaxonDescription> descriptions = taxon.getDescriptions(); |
525 | 466 |
|
... | ... | |
557 | 498 |
record.setFeatures(featureCells); |
558 | 499 |
} |
559 | 500 |
|
560 |
/** |
|
561 |
* |
|
562 |
* @param record |
|
563 |
* @param taxon |
|
564 |
* @param relationFrom |
|
565 |
* @param featureCells |
|
566 |
* @param features |
|
567 |
*/ |
|
568 | 501 |
private void handleRelatedRedlistStatus(CsvDemoRecord record, Taxon taxon, boolean relationFrom, List<List<String>> featureCells, List<Feature> features) { |
569 | 502 |
|
570 | 503 |
if (relationFrom) { |
571 | 504 |
handleRedlistStatus(record, taxon, featureCells, features); |
572 | 505 |
} |
573 | 506 |
|
574 |
|
|
575 | 507 |
Set<TaxonRelationship> taxRels; |
576 | 508 |
if(relationFrom){ |
577 | 509 |
taxRels = taxon.getRelationsFromThisTaxon(); |
... | ... | |
591 | 523 |
} |
592 | 524 |
} |
593 | 525 |
|
594 |
|
|
595 |
|
|
596 |
/** |
|
597 |
* |
|
598 |
* @param taxonNodes |
|
599 |
*/ |
|
600 | 526 |
private void sortTaxonNodes(List<TaxonNode> taxonNodes) { |
601 | 527 |
Collections.sort(taxonNodes, new Comparator<TaxonNode>() { |
602 | 528 |
|
... | ... | |
626 | 552 |
return ! state.getConfig().isDoTaxa(); |
627 | 553 |
} |
628 | 554 |
|
629 |
|
|
630 |
/** |
|
631 |
* {@inheritDoc} |
|
632 |
*/ |
|
633 | 555 |
@Override |
634 | 556 |
public byte[] getByteArray() { |
635 | 557 |
if (this.exportStream != null){ |
... | ... | |
637 | 559 |
} |
638 | 560 |
return null; |
639 | 561 |
} |
640 |
|
|
641 |
} |
|
562 |
} |
cdmlib-io/src/main/java/eu/etaxonomy/cdm/io/distribution/excelupdate/ExcelDistributionUpdate.java | ||
---|---|---|
15 | 15 |
import java.util.Set; |
16 | 16 |
import java.util.UUID; |
17 | 17 |
|
18 |
import org.apache.logging.log4j.LogManager;import org.apache.logging.log4j.Logger; |
|
18 |
import org.apache.logging.log4j.LogManager; |
|
19 |
import org.apache.logging.log4j.Logger; |
|
19 | 20 |
import org.springframework.stereotype.Component; |
20 | 21 |
|
21 | 22 |
import eu.etaxonomy.cdm.common.CdmUtils; |
... | ... | |
44 | 45 |
* |
45 | 46 |
* @author a.mueller |
46 | 47 |
* @since 04.04.2017 |
47 |
* |
|
48 | 48 |
*/ |
49 | 49 |
@Component |
50 | 50 |
public class ExcelDistributionUpdate |
... | ... | |
55 | 55 |
|
56 | 56 |
private static final String AREA_MAP = "AreaMap"; |
57 | 57 |
|
58 |
/** |
|
59 |
* {@inheritDoc} |
|
60 |
*/ |
|
61 | 58 |
@Override |
62 | 59 |
protected void analyzeRecord(Map<String, String> record, ExcelDistributionUpdateState state) { |
63 | 60 |
// nothing to do |
64 | 61 |
} |
65 | 62 |
|
66 |
/** |
|
67 |
* {@inheritDoc} |
|
68 |
*/ |
|
69 | 63 |
@Override |
70 | 64 |
protected void firstPass(ExcelDistributionUpdateState state) { |
71 | 65 |
Map<String, String> record = state.getOriginalRecord(); |
... | ... | |
93 | 87 |
} |
94 | 88 |
} |
95 | 89 |
|
96 |
/** |
|
97 |
* @param state |
|
98 |
* @param taxon |
|
99 |
* @param record |
|
100 |
* @param line |
|
101 |
*/ |
|
102 | 90 |
private void handleAreasForTaxon(ExcelDistributionUpdateState state, Taxon taxon, Map<String, String> record, |
103 | 91 |
String line) { |
104 | 92 |
ImportResult result = state.getResult(); |
... | ... | |
156 | 144 |
} |
157 | 145 |
} |
158 | 146 |
|
159 |
/** |
|
160 |
* @param taxon |
|
161 |
* @return |
|
162 |
*/ |
|
163 | 147 |
private String getTaxonLabel(Taxon taxon) { |
164 | 148 |
return taxon.getName() == null ? taxon.getTitleCache() : taxon.getName().getTitleCache(); |
165 | 149 |
} |
... | ... | |
195 | 179 |
return result; |
196 | 180 |
} |
197 | 181 |
|
198 |
/** |
|
199 |
* @param statusStr |
|
200 |
* @return |
|
201 |
*/ |
|
202 | 182 |
private PresenceAbsenceTerm getStatusByStatusStr(ExcelDistributionUpdateState state, String statusStr, String line) { |
203 | 183 |
// FIXME replace hardcoded; |
204 | 184 |
if ("A".equals(statusStr)) { |
... | ... | |
218 | 198 |
return null; |
219 | 199 |
} |
220 | 200 |
|
221 |
/** |
|
222 |
* @param state |
|
223 |
* @param key |
|
224 |
* @param line |
|
225 |
* @return |
|
226 |
*/ |
|
227 | 201 |
private NamedArea getAreaByIdInVoc(ExcelDistributionUpdateState state, String id, String line) { |
228 | 202 |
//TODO remember in state |
229 | 203 |
Map<String, NamedArea> areaMap = (Map<String, NamedArea>)state.getStatusItem(AREA_MAP); |
... | ... | |
235 | 209 |
return area; |
236 | 210 |
} |
237 | 211 |
|
238 |
/** |
|
239 |
* @param state |
|
240 |
* @return |
|
241 |
*/ |
|
242 | 212 |
private Map<String, NamedArea> createAreaMap(ExcelDistributionUpdateState state) { |
243 | 213 |
Map<String, NamedArea> result = new HashMap<>(); |
244 | 214 |
TermVocabulary<?> voc = getVocabularyService().find(state.getConfig().getAreaVocabularyUuid()); |
... | ... | |
252 | 222 |
return result; |
253 | 223 |
} |
254 | 224 |
|
255 |
/** |
|
256 |
* @param keys |
|
257 |
* @return |
|
258 |
*/ |
|
259 | 225 |
private Set<String> removeNonAreaKeys(Set<String> keys) { |
260 | 226 |
Iterator<String> it = keys.iterator(); |
261 | 227 |
while (it.hasNext()){ |
... | ... | |
278 | 244 |
return false; |
279 | 245 |
} |
280 | 246 |
|
281 |
/** |
|
282 |
* @param state |
|
283 |
* @param taxon |
|
284 |
* @param line |
|
285 |
* @return |
|
286 |
*/ |
|
287 | 247 |
private Map<NamedArea, Set<Distribution>> getExistingDistributions( |
288 | 248 |
ExcelDistributionUpdateState state, Taxon taxon, |
289 | 249 |
String line) { |
... | ... | |
306 | 266 |
return result; |
307 | 267 |
} |
308 | 268 |
|
309 |
/** |
|
310 |
* {@inheritDoc} |
|
311 |
*/ |
|
312 | 269 |
@Override |
313 | 270 |
protected void secondPass(ExcelDistributionUpdateState state) { |
314 | 271 |
// nothing to do |
315 | 272 |
} |
316 | 273 |
|
317 |
/** |
|
318 |
* {@inheritDoc} |
|
319 |
*/ |
|
320 | 274 |
@Override |
321 | 275 |
protected boolean isIgnore(ExcelDistributionUpdateState state) { |
322 | 276 |
return false; |
323 | 277 |
} |
278 |
|
|
324 | 279 |
@Override |
325 | 280 |
protected boolean requiresNomenclaturalCode() { |
326 | 281 |
return false; |
327 | 282 |
} |
328 |
|
|
329 |
} |
|
283 |
} |
cdmlib-io/src/main/java/eu/etaxonomy/cdm/io/dwca/out/DwcaMetaDataExport.java | ||
---|---|---|
1 |
/** |
|
2 |
* Copyright (C) 2007 EDIT |
|
3 |
* European Distributed Institute of Taxonomy |
|
4 |
* http://www.e-taxonomy.eu |
|
5 |
* |
|
6 |
* The contents of this file are subject to the Mozilla Public License Version 1.1 |
|
7 |
* See LICENSE.TXT at the top of this package for the full license terms. |
|
8 |
*/ |
|
9 |
|
|
10 |
package eu.etaxonomy.cdm.io.dwca.out; |
|
11 |
|
|
12 |
import java.io.FileNotFoundException; |
|
13 |
import java.io.IOException; |
|
14 |
import eu.etaxonomy.cdm.common.URI; |
|
15 |
import java.util.List; |
|
16 |
|
|
17 |
import javax.xml.stream.XMLStreamException; |
|
18 |
import javax.xml.stream.XMLStreamWriter; |
|
19 |
|
|
20 |
import org.apache.commons.lang.StringUtils; |
|
21 |
import org.apache.logging.log4j.LogManager;import org.apache.logging.log4j.Logger; |
|
22 |
import org.springframework.stereotype.Component; |
|
23 |
|
|
24 |
import eu.etaxonomy.cdm.io.dwca.out.DwcaMetaDataRecord.FieldEntry; |
|
25 |
|
|
26 |
/** |
|
27 |
* @author a.mueller |
|
28 |
* @since 20.04.2011 |
|
29 |
*/ |
|
30 |
@Component |
|
31 |
public class DwcaMetaDataExport extends DwcaExportBase { |
|
32 |
|
|
33 |
private static final long serialVersionUID = -4033439569151252697L; |
|
34 |
|
|
35 |
private static final Logger logger = LogManager.getLogger(DwcaMetaDataExport.class); |
|
36 |
|
|
37 |
protected static final String fileName = "meta.xml"; |
|
38 |
|
|
39 |
/** |
|
40 |
* Constructor |
|
41 |
*/ |
|
42 |
public DwcaMetaDataExport() { |
|
43 |
super(); |
|
44 |
this.ioName = this.getClass().getSimpleName(); |
|
45 |
} |
|
46 |
|
|
47 |
/** |
|
48 |
* {@inheritDoc} |
|
49 |
*/ |
|
50 |
@Override |
|
51 |
protected void doInvoke(DwcaTaxExportState state){ |
|
52 |
DwcaTaxExportConfigurator config = state.getConfig(); |
|
53 |
|
|
54 |
DwcaMetaDataRecord metaDataRecord = new DwcaMetaDataRecord(! IS_CORE, fileName, null); |
|
55 |
metaDataRecord.setMetaData(true); |
|
56 |
state.addMetaRecord(metaDataRecord); |
|
57 |
|
|
58 |
XMLStreamWriter writer = null; |
|
59 |
try { |
|
60 |
writer = createXmlStreamWriter(state, DwcaTaxExportFile.METADATA); |
|
61 |
|
|
62 |
String rootNamespace = "http://rs.tdwg.org/dwc/text/"; |
|
63 |
String rootName = "archive"; |
|
64 |
|
|
65 |
List<DwcaMetaDataRecord> metaRecords = state.getMetaRecords(); |
|
66 |
|
|
67 |
// create header |
|
68 |
writer.writeStartDocument(); |
|
69 |
writer.setDefaultNamespace(rootNamespace); |
|
70 |
|
|
71 |
// create root element |
|
72 |
writer.writeStartElement(rootName); |
|
73 |
writer.writeNamespace(null, rootNamespace); |
|
74 |
|
|
75 |
writer.writeNamespace("xsi", "http://www.w3.org/2001/XMLSchema-instance"); |
|
76 |
writer.writeAttribute("http://www.w3.org/2001/XMLSchema-instance", "schemaLocation", "http://rs.tdwg.org/dwc/text/ http://rs.tdwg.org/dwc/text/tdwg_dwc_text.xsd"); |
|
77 |
|
|
78 |
for (DwcaMetaDataRecord metaRecord : metaRecords){ |
|
79 |
if (! metaRecord.isMetaData()){ |
|
80 |
writeMetaDataRecord(writer, config, metaRecord); |
|
81 |
} |
|
82 |
} |
|
83 |
writer.writeEndElement(); |
|
84 |
writer.writeEndDocument(); |
|
85 |
writer.flush(); |
|
86 |
writer.close(); |
|
87 |
} catch (FileNotFoundException e) { |
|
88 |
String message = "Metadata file could not be found"; |
|
89 |
state.getResult().addException(e, message); |
|
90 |
} catch (XMLStreamException e) { |
|
91 |
if (e.getNestedException() != null){ |
|
92 |
String message = "Nested XMLStreamException while handling metadata"; |
|
93 |
state.getResult().addException((Exception)e.getNestedException(), message); |
|
94 |
}else{ |
|
95 |
String message = "XMLStreamException while handling metadata"; |
|
96 |
state.getResult().addException(e, message); |
|
97 |
} |
|
98 |
} catch (IOException e) { |
|
99 |
String message = "IOException while handling metadata"; |
|
100 |
state.getResult().addException(e, message); |
|
101 |
} finally{ |
|
102 |
closeWriter(writer, state); |
|
103 |
} |
|
104 |
|
|
105 |
return; |
|
106 |
} |
|
107 |
|
|
108 |
private void writeMetaDataRecord(XMLStreamWriter writer, |
|
109 |
DwcaTaxExportConfigurator config, DwcaMetaDataRecord metaRecord) throws XMLStreamException { |
|
110 |
if (! metaRecord.hasEntries()){ |
|
111 |
return; |
|
112 |
} |
|
113 |
String encoding = config.getEncoding(); |
|
114 |
String linesTerminatedBy = config.getLinesTerminatedBy(); |
|
115 |
String fieldsEnclosedBy = config.getFieldsEnclosedBy(); |
|
116 |
String ignoreHeaderLines = config.isHasHeaderLines()? "1":"0"; |
|
117 |
String fieldsTerminatedBy= config.getFieldsTerminatedBy(); |
|
118 |
|
|
119 |
// create core element |
|
120 |
String elementName = metaRecord.isCore()? "core": "extension"; |
|
121 |
String rowType = metaRecord.getRowType(); |
|
122 |
writeElementStart(writer, elementName, encoding, linesTerminatedBy, fieldsEnclosedBy, |
|
123 |
fieldsTerminatedBy, ignoreHeaderLines, rowType); |
|
124 |
String filename = metaRecord.getFileLocation(); |
|
125 |
writeFiles(writer, filename ); |
|
126 |
writeId(writer, metaRecord.isCore()); |
|
127 |
|
|
128 |
List<FieldEntry> entryList = metaRecord.getEntries(); |
|
129 |
for (FieldEntry fieldEntry : entryList){ |
|
130 |
if (fieldEntry.index != 0){ |
|
131 |
writeFieldLine(writer, fieldEntry.index, fieldEntry.term, fieldEntry.defaultValue); |
|
132 |
} |
|
133 |
} |
|
134 |
|
|
135 |
writer.writeEndElement(); |
|
136 |
} |
|
137 |
|
|
138 |
private void writeFieldLine(XMLStreamWriter writer, int index, URI term, String defaultValue) throws XMLStreamException { |
|
139 |
writer.writeStartElement("field"); |
|
140 |
if (StringUtils.isNotBlank(defaultValue)){ |
|
141 |
writer.writeAttribute("default", defaultValue); |
|
142 |
}else{ |
|
143 |
writer.writeAttribute("index", String.valueOf(index)); |
|
144 |
} |
|
145 |
writer.writeAttribute("term", term.toString()); |
|
146 |
writer.writeEndElement(); |
|
147 |
|
|
148 |
} |
|
149 |
|
|
150 |
private void writeId(XMLStreamWriter writer, boolean isCore) throws XMLStreamException { |
|
151 |
String strId = isCore? "id" : "coreid"; |
|
152 |
writer.writeStartElement(strId); |
|
153 |
writer.writeAttribute("index", "0"); |
|
154 |
writer.writeEndElement(); |
|
155 |
} |
|
156 |
|
|
157 |
|
|
158 |
private void writeFiles(XMLStreamWriter writer, String filename) throws XMLStreamException { |
|
159 |
writer.writeStartElement("files"); |
|
160 |
writer.writeStartElement("location"); |
|
161 |
writer.writeCharacters(filename); |
|
162 |
writer.writeEndElement(); |
|
163 |
writer.writeEndElement(); |
|
164 |
|
|
165 |
} |
|
166 |
|
|
167 |
/** |
|
168 |
* @param writer |
|
169 |
* @param encoding |
|
170 |
* @param linesTerminatedBy |
|
171 |
* @param fieldsEnclosedBy |
|
172 |
* @param ignoreHeaderLines |
|
173 |
* @param rowType |
|
174 |
* @param elementName |
|
175 |
* @throws XMLStreamException |
|
176 |
*/ |
|
177 |
private void writeElementStart(XMLStreamWriter writer, String elementName, String encoding, |
|
178 |
String linesTerminatedBy, String fieldsEnclosedBy, String fieldsTerminatedBy, |
|
179 |
String ignoreHeaderLines, String rowType) |
|
180 |
throws XMLStreamException { |
|
181 |
writer.writeStartElement(elementName); |
|
182 |
writer.writeAttribute( "encoding", encoding ); |
|
183 |
writer.writeAttribute( "linesTerminatedBy", linesTerminatedBy ); |
|
184 |
writer.writeAttribute( "fieldsEnclosedBy", fieldsEnclosedBy ); |
|
185 |
writer.writeAttribute("fieldsTerminatedBy", fieldsTerminatedBy); |
|
186 |
writer.writeAttribute("ignoreHeaderLines", ignoreHeaderLines); |
|
187 |
writer.writeAttribute("rowType", rowType); |
|
188 |
} |
|
189 |
|
|
190 |
|
|
191 |
|
|
192 |
@Override |
|
193 |
protected boolean doCheck(DwcaTaxExportState state) { |
|
194 |
boolean result = true; |
|
195 |
logger.warn("No check implemented for " + this.ioName); |
|
196 |
return result; |
|
197 |
} |
|
198 |
|
|
199 |
@Override |
|
200 |
protected boolean isIgnore(DwcaTaxExportState state) { |
|
201 |
return ! state.getConfig().isDoMetaData(); |
|
202 |
} |
|
203 |
|
|
204 |
|
|
205 |
} |
|
1 |
/** |
|
2 |
* Copyright (C) 2007 EDIT |
|
3 |
* European Distributed Institute of Taxonomy |
|
4 |
* http://www.e-taxonomy.eu |
|
5 |
* |
|
6 |
* The contents of this file are subject to the Mozilla Public License Version 1.1 |
|
7 |
* See LICENSE.TXT at the top of this package for the full license terms. |
|
8 |
*/ |
|
9 |
|
|
10 |
package eu.etaxonomy.cdm.io.dwca.out; |
|
11 |
|
|
12 |
import java.io.FileNotFoundException; |
|
13 |
import java.io.IOException; |
|
14 |
import java.util.List; |
|
15 |
|
|
16 |
import javax.xml.stream.XMLStreamException; |
|
17 |
import javax.xml.stream.XMLStreamWriter; |
|
18 |
|
|
19 |
import org.apache.commons.lang.StringUtils; |
|
20 |
import org.apache.logging.log4j.LogManager; |
|
21 |
import org.apache.logging.log4j.Logger; |
|
22 |
import org.springframework.stereotype.Component; |
|
23 |
|
|
24 |
import eu.etaxonomy.cdm.common.URI; |
|
25 |
import eu.etaxonomy.cdm.io.dwca.out.DwcaMetaDataRecord.FieldEntry; |
|
26 |
|
|
27 |
/** |
|
28 |
* @author a.mueller |
|
29 |
* @since 20.04.2011 |
|
30 |
*/ |
|
31 |
@Component |
|
32 |
public class DwcaMetaDataExport extends DwcaExportBase { |
|
33 |
|
|
34 |
private static final long serialVersionUID = -4033439569151252697L; |
|
35 |
|
|
36 |
private static final Logger logger = LogManager.getLogger(DwcaMetaDataExport.class); |
|
37 |
|
|
38 |
protected static final String fileName = "meta.xml"; |
|
39 |
|
|
40 |
/** |
|
41 |
* Constructor |
|
42 |
*/ |
|
43 |
public DwcaMetaDataExport() { |
|
44 |
super(); |
|
45 |
this.ioName = this.getClass().getSimpleName(); |
|
46 |
} |
|
47 |
|
|
48 |
@Override |
|
49 |
protected void doInvoke(DwcaTaxExportState state){ |
|
50 |
DwcaTaxExportConfigurator config = state.getConfig(); |
|
51 |
|
|
52 |
DwcaMetaDataRecord metaDataRecord = new DwcaMetaDataRecord(! IS_CORE, fileName, null); |
|
53 |
metaDataRecord.setMetaData(true); |
|
54 |
state.addMetaRecord(metaDataRecord); |
|
55 |
|
|
56 |
XMLStreamWriter writer = null; |
|
57 |
try { |
|
58 |
writer = createXmlStreamWriter(state, DwcaTaxExportFile.METADATA); |
|
59 |
|
|
60 |
String rootNamespace = "http://rs.tdwg.org/dwc/text/"; |
|
61 |
String rootName = "archive"; |
|
62 |
|
|
63 |
List<DwcaMetaDataRecord> metaRecords = state.getMetaRecords(); |
|
64 |
|
|
65 |
// create header |
|
66 |
writer.writeStartDocument(); |
|
67 |
writer.setDefaultNamespace(rootNamespace); |
|
68 |
|
|
69 |
// create root element |
|
70 |
writer.writeStartElement(rootName); |
|
71 |
writer.writeNamespace(null, rootNamespace); |
|
72 |
|
|
73 |
writer.writeNamespace("xsi", "http://www.w3.org/2001/XMLSchema-instance"); |
|
74 |
writer.writeAttribute("http://www.w3.org/2001/XMLSchema-instance", "schemaLocation", "http://rs.tdwg.org/dwc/text/ http://rs.tdwg.org/dwc/text/tdwg_dwc_text.xsd"); |
|
75 |
|
|
76 |
for (DwcaMetaDataRecord metaRecord : metaRecords){ |
|
77 |
if (! metaRecord.isMetaData()){ |
|
78 |
writeMetaDataRecord(writer, config, metaRecord); |
|
79 |
} |
|
80 |
} |
|
81 |
writer.writeEndElement(); |
|
82 |
writer.writeEndDocument(); |
|
83 |
writer.flush(); |
|
84 |
writer.close(); |
|
85 |
} catch (FileNotFoundException e) { |
|
86 |
String message = "Metadata file could not be found"; |
|
87 |
state.getResult().addException(e, message); |
|
88 |
} catch (XMLStreamException e) { |
|
89 |
if (e.getNestedException() != null){ |
|
90 |
String message = "Nested XMLStreamException while handling metadata"; |
|
91 |
state.getResult().addException((Exception)e.getNestedException(), message); |
|
92 |
}else{ |
|
93 |
String message = "XMLStreamException while handling metadata"; |
|
94 |
state.getResult().addException(e, message); |
|
95 |
} |
|
96 |
} catch (IOException e) { |
|
97 |
String message = "IOException while handling metadata"; |
|
98 |
state.getResult().addException(e, message); |
|
99 |
} finally{ |
|
100 |
closeWriter(writer, state); |
|
101 |
} |
|
102 |
|
|
103 |
return; |
|
104 |
} |
|
105 |
|
|
106 |
private void writeMetaDataRecord(XMLStreamWriter writer, |
|
107 |
DwcaTaxExportConfigurator config, DwcaMetaDataRecord metaRecord) throws XMLStreamException { |
|
108 |
if (! metaRecord.hasEntries()){ |
|
109 |
return; |
|
110 |
} |
|
111 |
String encoding = config.getEncoding(); |
|
112 |
String linesTerminatedBy = config.getLinesTerminatedBy(); |
|
113 |
String fieldsEnclosedBy = config.getFieldsEnclosedBy(); |
|
114 |
String ignoreHeaderLines = config.isHasHeaderLines()? "1":"0"; |
|
115 |
String fieldsTerminatedBy= config.getFieldsTerminatedBy(); |
|
116 |
|
|
117 |
// create core element |
|
118 |
String elementName = metaRecord.isCore()? "core": "extension"; |
|
119 |
String rowType = metaRecord.getRowType(); |
|
120 |
writeElementStart(writer, elementName, encoding, linesTerminatedBy, fieldsEnclosedBy, |
|
121 |
fieldsTerminatedBy, ignoreHeaderLines, rowType); |
|
122 |
String filename = metaRecord.getFileLocation(); |
|
123 |
writeFiles(writer, filename ); |
|
124 |
writeId(writer, metaRecord.isCore()); |
|
125 |
|
|
126 |
List<FieldEntry> entryList = metaRecord.getEntries(); |
|
127 |
for (FieldEntry fieldEntry : entryList){ |
|
128 |
if (fieldEntry.index != 0){ |
|
129 |
writeFieldLine(writer, fieldEntry.index, fieldEntry.term, fieldEntry.defaultValue); |
|
130 |
} |
|
131 |
} |
|
132 |
|
|
133 |
writer.writeEndElement(); |
|
134 |
} |
|
135 |
|
|
136 |
private void writeFieldLine(XMLStreamWriter writer, int index, URI term, String defaultValue) throws XMLStreamException { |
|
137 |
writer.writeStartElement("field"); |
|
138 |
if (StringUtils.isNotBlank(defaultValue)){ |
|
139 |
writer.writeAttribute("default", defaultValue); |
|
140 |
}else{ |
|
141 |
writer.writeAttribute("index", String.valueOf(index)); |
|
142 |
} |
|
143 |
writer.writeAttribute("term", term.toString()); |
|
144 |
writer.writeEndElement(); |
|
145 |
|
|
146 |
} |
|
147 |
|
|
148 |
private void writeId(XMLStreamWriter writer, boolean isCore) throws XMLStreamException { |
|
149 |
String strId = isCore? "id" : "coreid"; |
|
150 |
writer.writeStartElement(strId); |
|
151 |
writer.writeAttribute("index", "0"); |
|
152 |
writer.writeEndElement(); |
|
153 |
} |
|
154 |
|
|
155 |
|
|
156 |
private void writeFiles(XMLStreamWriter writer, String filename) throws XMLStreamException { |
|
157 |
writer.writeStartElement("files"); |
|
158 |
writer.writeStartElement("location"); |
|
159 |
writer.writeCharacters(filename); |
|
160 |
writer.writeEndElement(); |
|
161 |
writer.writeEndElement(); |
|
162 |
|
|
163 |
} |
|
164 |
|
|
165 |
/** |
|
166 |
* @param writer |
|
167 |
* @param encoding |
|
168 |
* @param linesTerminatedBy |
|
169 |
* @param fieldsEnclosedBy |
|
170 |
* @param ignoreHeaderLines |
|
171 |
* @param rowType |
|
172 |
* @param elementName |
|
173 |
* @throws XMLStreamException |
|
174 |
*/ |
|
175 |
private void writeElementStart(XMLStreamWriter writer, String elementName, String encoding, |
|
176 |
String linesTerminatedBy, String fieldsEnclosedBy, String fieldsTerminatedBy, |
|
177 |
String ignoreHeaderLines, String rowType) |
|
178 |
throws XMLStreamException { |
|
179 |
writer.writeStartElement(elementName); |
|
180 |
writer.writeAttribute( "encoding", encoding ); |
|
181 |
writer.writeAttribute( "linesTerminatedBy", linesTerminatedBy ); |
|
182 |
writer.writeAttribute( "fieldsEnclosedBy", fieldsEnclosedBy ); |
|
183 |
writer.writeAttribute("fieldsTerminatedBy", fieldsTerminatedBy); |
|
184 |
writer.writeAttribute("ignoreHeaderLines", ignoreHeaderLines); |
|
185 |
writer.writeAttribute("rowType", rowType); |
|
186 |
} |
|
187 |
|
|
188 |
|
|
189 |
|
|
190 |
@Override |
|
191 |
protected boolean doCheck(DwcaTaxExportState state) { |
|
192 |
boolean result = true; |
|
193 |
logger.warn("No check implemented for " + this.ioName); |
|
194 |
return result; |
|
195 |
} |
|
196 |
|
|
197 |
@Override |
|
198 |
protected boolean isIgnore(DwcaTaxExportState state) { |
|
199 |
return ! state.getConfig().isDoMetaData(); |
|
200 |
} |
|
201 |
|
|
202 |
|
|
203 |
} |
cdmlib-io/src/main/java/eu/etaxonomy/cdm/io/dwca/out/DwcaResultWriter.java | ||
---|---|---|
11 | 11 |
import java.io.IOException; |
12 | 12 |
import java.io.PrintWriter; |
13 | 13 |
|
14 |
import org.apache.logging.log4j.LogManager;import org.apache.logging.log4j.Logger; |
|
14 |
import org.apache.logging.log4j.LogManager; |
|
15 |
import org.apache.logging.log4j.Logger; |
|
15 | 16 |
import org.springframework.stereotype.Component; |
16 | 17 |
|
17 | 18 |
/** |
... | ... | |
19 | 20 |
* |
20 | 21 |
* @author a.mueller |
21 | 22 |
* @since 25.06.2017 |
22 |
* |
|
23 | 23 |
*/ |
24 | 24 |
@Component |
25 | 25 |
public class DwcaResultWriter extends DwcaExportBase { |
... | ... | |
28 | 28 |
@SuppressWarnings("unused") |
29 | 29 |
private static final Logger logger = LogManager.getLogger(DwcaDescriptionExport.class); |
30 | 30 |
|
31 |
|
|
32 |
/** |
|
33 |
* {@inheritDoc} |
|
34 |
*/ |
|
35 | 31 |
@Override |
36 | 32 |
protected void doInvoke(DwcaTaxExportState state) { |
37 | 33 |
addReport(state); |
... | ... | |
56 | 52 |
} |
57 | 53 |
} |
58 | 54 |
|
59 |
/** |
|
60 |
* @param state |
|
61 |
*/ |
|
62 | 55 |
protected void closeZip(DwcaTaxExportState state) { |
63 | 56 |
if (state.isZip()){ |
64 | 57 |
try { |
... | ... | |
69 | 62 |
} |
70 | 63 |
} |
71 | 64 |
|
72 |
/** |
|
73 |
* {@inheritDoc} |
|
74 |
*/ |
|
75 | 65 |
@Override |
76 | 66 |
protected boolean doCheck(DwcaTaxExportState state) { |
77 | 67 |
return false; |
78 | 68 |
} |
79 | 69 |
|
80 |
|
|
81 |
/** |
|
82 |
* {@inheritDoc} |
|
83 |
*/ |
|
84 | 70 |
@Override |
85 | 71 |
protected boolean isIgnore(DwcaTaxExportState state) { |
86 | 72 |
return false; |
87 | 73 |
} |
88 |
|
|
89 |
} |
|
74 |
} |
cdmlib-io/src/main/java/eu/etaxonomy/cdm/io/dwca/out/DwcaTaxExport.java | ||
---|---|---|
1 |
/** |
|
2 |
* Copyright (C) 2007 EDIT |
|
3 |
* European Distributed Institute of Taxonomy |
|
4 |
* http://www.e-taxonomy.eu |
|
5 |
* |
|
6 |
* The contents of this file are subject to the Mozilla Public License Version 1.1 |
|
7 |
* See LICENSE.TXT at the top of this package for the full license terms. |
|
8 |
*/ |
|
9 |
|
|
10 |
package eu.etaxonomy.cdm.io.dwca.out; |
|
11 |
|
|
12 |
import java.io.FileNotFoundException; |
|
13 |
import java.io.IOException; |
|
14 |
import java.io.UnsupportedEncodingException; |
|
15 |
import java.util.Arrays; |
|
16 |
import java.util.List; |
|
17 |
|
|
18 |
import org.apache.logging.log4j.LogManager;import org.apache.logging.log4j.Logger; |
|
19 |
import org.springframework.beans.factory.annotation.Autowired; |
|
20 |
import org.springframework.stereotype.Component; |
|
21 |
|
|
22 |
import eu.etaxonomy.cdm.api.service.ITaxonNodeService; |
|
23 |
import eu.etaxonomy.cdm.common.monitor.IProgressMonitor; |
|
24 |
import eu.etaxonomy.cdm.filter.TaxonNodeFilter; |
|
25 |
import eu.etaxonomy.cdm.io.common.TaxonNodeOutStreamPartitioner; |
|
26 |
import eu.etaxonomy.cdm.io.common.XmlExportState; |
|
27 |
import eu.etaxonomy.cdm.model.taxon.TaxonNode; |
|
28 |
|
|
29 |
/** |
|
30 |
* @author a.mueller |
|
31 |
* @since 18.04.2011 |
|
32 |
*/ |
|
33 |
@Component |
|
34 |
public class DwcaTaxExport extends DwcaExportBase { |
|
35 |
private static final long serialVersionUID = -3770976064909193441L; |
|
36 |
|
|
37 |
private static final Logger logger = LogManager.getLogger(DwcaTaxExport.class); |
|
38 |
|
|
39 |
|
|
40 |
@Autowired |
|
41 |
private ITaxonNodeService taxonNodeService; |
|
42 |
|
|
43 |
public DwcaTaxExport() { |
|
44 |
super(); |
|
45 |
this.ioName = this.getClass().getSimpleName(); |
|
46 |
file = DwcaTaxExportFile.TAXON; |
|
47 |
} |
|
48 |
|
|
49 |
|
|
50 |
/** |
|
51 |
* {@inheritDoc} |
|
52 |
*/ |
|
53 |
@Override |
|
54 |
public long countSteps(DwcaTaxExportState state) { |
|
55 |
TaxonNodeFilter filter = state.getConfig().getTaxonNodeFilter(); |
|
56 |
return taxonNodeService.count(filter); |
|
57 |
} |
|
58 |
|
|
59 |
/** |
|
60 |
* Retrieves data from a CDM DB and serializes the CDM to XML. |
|
61 |
* Starts with root taxa and traverses the classification to retrieve children taxa, synonyms and relationships. |
|
62 |
* Taxa that are not part of the classification are not found. |
|
63 |
* <BR> |
|
64 |
* {@inheritDoc} |
|
65 |
*/ |
|
66 |
@Override |
|
67 |
protected void doInvoke(DwcaTaxExportState state){ |
|
68 |
|
|
69 |
IProgressMonitor monitor = state.getConfig().getProgressMonitor(); |
|
70 |
|
|
71 |
List<DwcaDataExportBase> exports = Arrays.asList(new DwcaDataExportBase[]{ |
|
72 |
new DwcaTaxonExport(state), |
|
73 |
new DwcaReferenceExport(state), |
|
74 |
new DwcaResourceRelationExport(state), |
|
75 |
new DwcaTypesExport(state), |
|
76 |
new DwcaVernacularExport(state), |
|
77 |
new DwcaDescriptionExport(state), |
|
78 |
new DwcaDistributionExport(state), |
|
79 |
new DwcaImageExport(state) |
|
80 |
}); |
|
81 |
|
|
82 |
|
|
83 |
@SuppressWarnings("unchecked") |
|
84 |
TaxonNodeOutStreamPartitioner<XmlExportState> partitioner |
|
85 |
= TaxonNodeOutStreamPartitioner.NewInstance( |
|
86 |
this, state, state.getConfig().getTaxonNodeFilter(), |
|
87 |
100, monitor, null); |
|
88 |
try { |
|
89 |
|
|
90 |
monitor.subTask("Start partitioning"); |
|
91 |
|
|
92 |
TaxonNode node = partitioner.next(); |
|
93 |
while (node != null){ |
|
94 |
for (DwcaDataExportBase export : exports){ |
|
95 |
handleTaxonNode(export, state, node); |
|
96 |
} |
|
97 |
node = partitioner.next(); |
|
98 |
} |
|
99 |
} catch (Exception e) { |
|
100 |
String message = "Unexpected exception: " + e.getMessage(); |
|
101 |
state.getResult().addException(e, message, "DwcaTaxExport.doInvoke()"); |
|
102 |
} |
|
103 |
finally{ |
|
104 |
if(partitioner != null){ |
|
105 |
partitioner.close(); |
|
106 |
} |
|
107 |
for (DwcaDataExportBase export : exports){ |
|
108 |
closeWriter(export, state); |
|
109 |
} |
|
110 |
} |
|
111 |
|
|
112 |
return; |
|
113 |
|
|
114 |
} |
|
115 |
|
|
116 |
/** |
|
117 |
* @param taxonExport |
|
118 |
* @param state |
|
119 |
*/ |
|
120 |
private void closeWriter(DwcaDataExportBase export, DwcaTaxExportState state) { |
|
121 |
if (!export.isIgnore(state)){ |
|
122 |
export.closeWriter(state); |
|
123 |
} |
|
124 |
} |
|
125 |
|
|
126 |
private void handleTaxonNode(DwcaDataExportBase export, DwcaTaxExportState state, TaxonNode node) throws FileNotFoundException, UnsupportedEncodingException, IOException { |
|
127 |
if (!export.isIgnore(state)){ |
|
128 |
export.handleTaxonNode(state, node); |
|
129 |
} |
|
130 |
} |
|
131 |
|
|
132 |
|
|
133 |
@Override |
|
134 |
protected boolean doCheck(DwcaTaxExportState state) { |
|
135 |
boolean result = true; |
|
136 |
logger.warn("No check implemented for " + this.ioName); |
|
137 |
return result; |
|
138 |
} |
|
139 |
|
|
140 |
|
|
141 |
@Override |
|
142 |
public boolean isIgnore(DwcaTaxExportState state) { |
|
143 |
return ! state.getConfig().isDoTaxa(); |
|
144 |
} |
|
145 |
|
|
146 |
} |
|
1 |
/** |
|
2 |
* Copyright (C) 2007 EDIT |
|
3 |
* European Distributed Institute of Taxonomy |
|
4 |
* http://www.e-taxonomy.eu |
|
5 |
* |
|
6 |
* The contents of this file are subject to the Mozilla Public License Version 1.1 |
|
7 |
* See LICENSE.TXT at the top of this package for the full license terms. |
|
8 |
*/ |
|
9 |
|
|
10 |
package eu.etaxonomy.cdm.io.dwca.out; |
|
11 |
|
|
12 |
import java.io.FileNotFoundException; |
|
13 |
import java.io.IOException; |
|
14 |
import java.io.UnsupportedEncodingException; |
|
15 |
import java.util.Arrays; |
|
16 |
import java.util.List; |
|
17 |
|
|
18 |
import org.apache.logging.log4j.LogManager; |
|
19 |
import org.apache.logging.log4j.Logger; |
|
20 |
import org.springframework.beans.factory.annotation.Autowired; |
|
21 |
import org.springframework.stereotype.Component; |
|
22 |
|
|
23 |
import eu.etaxonomy.cdm.api.service.ITaxonNodeService; |
|
24 |
import eu.etaxonomy.cdm.common.monitor.IProgressMonitor; |
|
25 |
import eu.etaxonomy.cdm.filter.TaxonNodeFilter; |
|
26 |
import eu.etaxonomy.cdm.io.common.TaxonNodeOutStreamPartitioner; |
|
27 |
import eu.etaxonomy.cdm.io.common.XmlExportState; |
|
28 |
import eu.etaxonomy.cdm.model.taxon.TaxonNode; |
|
29 |
|
|
30 |
/** |
|
31 |
* @author a.mueller |
|
32 |
* @since 18.04.2011 |
|
33 |
*/ |
|
34 |
@Component |
|
35 |
public class DwcaTaxExport extends DwcaExportBase { |
|
36 |
private static final long serialVersionUID = -3770976064909193441L; |
|
37 |
|
|
38 |
private static final Logger logger = LogManager.getLogger(DwcaTaxExport.class); |
|
39 |
|
|
40 |
|
|
41 |
@Autowired |
|
42 |
private ITaxonNodeService taxonNodeService; |
|
43 |
|
|
44 |
public DwcaTaxExport() { |
|
45 |
super(); |
|
46 |
this.ioName = this.getClass().getSimpleName(); |
|
47 |
file = DwcaTaxExportFile.TAXON; |
|
48 |
} |
|
49 |
|
|
50 |
@Override |
|
51 |
public long countSteps(DwcaTaxExportState state) { |
|
52 |
TaxonNodeFilter filter = state.getConfig().getTaxonNodeFilter(); |
|
53 |
return taxonNodeService.count(filter); |
|
54 |
} |
|
55 |
|
|
56 |
/** |
|
57 |
* Retrieves data from a CDM DB and serializes the CDM to XML. |
|
58 |
* Starts with root taxa and traverses the classification to retrieve children taxa, synonyms and relationships. |
|
59 |
* Taxa that are not part of the classification are not found. |
|
60 |
* <BR> |
|
61 |
* {@inheritDoc} |
|
62 |
*/ |
|
63 |
@Override |
|
64 |
protected void doInvoke(DwcaTaxExportState state){ |
|
65 |
|
|
66 |
IProgressMonitor monitor = state.getConfig().getProgressMonitor(); |
|
67 |
|
|
68 |
List<DwcaDataExportBase> exports = Arrays.asList(new DwcaDataExportBase[]{ |
|
69 |
new DwcaTaxonExport(state), |
|
70 |
new DwcaReferenceExport(state), |
|
71 |
new DwcaResourceRelationExport(state), |
|
72 |
new DwcaTypesExport(state), |
|
73 |
new DwcaVernacularExport(state), |
|
74 |
new DwcaDescriptionExport(state), |
|
75 |
new DwcaDistributionExport(state), |
|
76 |
new DwcaImageExport(state) |
|
77 |
}); |
|
78 |
|
|
79 |
|
|
80 |
@SuppressWarnings("unchecked") |
|
81 |
TaxonNodeOutStreamPartitioner<XmlExportState> partitioner |
|
82 |
= TaxonNodeOutStreamPartitioner.NewInstance( |
|
83 |
this, state, state.getConfig().getTaxonNodeFilter(), |
|
84 |
100, monitor, null); |
|
85 |
try { |
|
86 |
|
|
87 |
monitor.subTask("Start partitioning"); |
|
88 |
|
|
89 |
TaxonNode node = partitioner.next(); |
|
90 |
while (node != null){ |
|
91 |
for (DwcaDataExportBase export : exports){ |
|
92 |
handleTaxonNode(export, state, node); |
|
93 |
} |
|
94 |
node = partitioner.next(); |
|
95 |
} |
|
96 |
} catch (Exception e) { |
|
97 |
String message = "Unexpected exception: " + e.getMessage(); |
|
98 |
state.getResult().addException(e, message, "DwcaTaxExport.doInvoke()"); |
|
99 |
} |
|
100 |
finally{ |
|
101 |
if(partitioner != null){ |
|
102 |
partitioner.close(); |
|
103 |
} |
|
104 |
for (DwcaDataExportBase export : exports){ |
|
105 |
closeWriter(export, state); |
|
106 |
} |
|
107 |
} |
|
108 |
|
|
109 |
return; |
|
110 |
|
|
111 |
} |
|
112 |
|
|
113 |
/** |
|
114 |
* @param taxonExport |
|
115 |
* @param state |
|
116 |
*/ |
|
117 |
private void closeWriter(DwcaDataExportBase export, DwcaTaxExportState state) { |
|
118 |
if (!export.isIgnore(state)){ |
|
119 |
export.closeWriter(state); |
|
120 |
} |
|
121 |
} |
|
122 |
|
|
123 |
private void handleTaxonNode(DwcaDataExportBase export, DwcaTaxExportState state, TaxonNode node) throws FileNotFoundException, UnsupportedEncodingException, IOException { |
|
124 |
if (!export.isIgnore(state)){ |
|
125 |
export.handleTaxonNode(state, node); |
|
126 |
} |
|
127 |
} |
|
128 |
|
|
129 |
|
|
130 |
@Override |
|
131 |
protected boolean doCheck(DwcaTaxExportState state) { |
|
132 |
boolean result = true; |
|
133 |
logger.warn("No check implemented for " + this.ioName); |
|
134 |
return result; |
|
135 |
} |
|
136 |
|
|
137 |
|
|
138 |
@Override |
|
139 |
public boolean isIgnore(DwcaTaxExportState state) { |
|
140 |
return ! state.getConfig().isDoTaxa(); |
|
141 |
} |
|
142 |
|
|
143 |
} |
Also available in: Unified diff
cleanup