1 |
2907e2c8
|
Andreas Müller
|
/**
|
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 |
|
|
package eu.etaxonomy.cdm.io.dwca.out;
|
10 |
|
|
|
11 |
2ae594e7
|
Andreas Müller
|
import java.util.ArrayList;
|
12 |
d5fe8657
|
Andreas Müller
|
import java.util.HashSet;
|
13 |
2ae594e7
|
Andreas Müller
|
import java.util.List;
|
14 |
|
|
import java.util.Set;
|
15 |
d5fe8657
|
Andreas Müller
|
import java.util.UUID;
|
16 |
2ae594e7
|
Andreas Müller
|
|
17 |
2907e2c8
|
Andreas Müller
|
import org.apache.log4j.Logger;
|
18 |
|
|
|
19 |
|
|
import eu.etaxonomy.cdm.io.common.CdmExportBase;
|
20 |
|
|
import eu.etaxonomy.cdm.io.common.ICdmExport;
|
21 |
|
|
import eu.etaxonomy.cdm.model.common.CdmBase;
|
22 |
d5fe8657
|
Andreas Müller
|
import eu.etaxonomy.cdm.model.description.DescriptionElementBase;
|
23 |
2907e2c8
|
Andreas Müller
|
import eu.etaxonomy.cdm.model.location.NamedArea;
|
24 |
|
|
import eu.etaxonomy.cdm.model.location.WaterbodyOrCountry;
|
25 |
2ae594e7
|
Andreas Müller
|
import eu.etaxonomy.cdm.model.taxon.Classification;
|
26 |
|
|
import eu.etaxonomy.cdm.model.taxon.Taxon;
|
27 |
7624f446
|
Andreas Müller
|
import eu.etaxonomy.cdm.model.taxon.TaxonBase;
|
28 |
2ae594e7
|
Andreas Müller
|
import eu.etaxonomy.cdm.model.taxon.TaxonNode;
|
29 |
2907e2c8
|
Andreas Müller
|
|
30 |
e08884ef
|
Andreas Müller
|
/**
|
31 |
|
|
* @author a.mueller
|
32 |
|
|
* @date 18.04.2011
|
33 |
|
|
*
|
34 |
|
|
*/
|
35 |
2907e2c8
|
Andreas Müller
|
public abstract class DwcaExportBase extends CdmExportBase<DwcaTaxExportConfigurator, DwcaTaxExportState> implements ICdmExport<DwcaTaxExportConfigurator, DwcaTaxExportState>{
|
36 |
|
|
private static final Logger logger = Logger.getLogger(DwcaExportBase.class);
|
37 |
|
|
|
38 |
d5fe8657
|
Andreas Müller
|
protected Set<Integer> existingRecordIds = new HashSet<Integer>();
|
39 |
|
|
protected Set<UUID> existingRecordUuids = new HashSet<UUID>();
|
40 |
|
|
|
41 |
|
|
|
42 |
2ae594e7
|
Andreas Müller
|
/**
|
43 |
|
|
* Returns the list of taxon nodes that are part in one of the given classifications
|
44 |
|
|
* and do have a taxon attached (empty taxon nodes should not but do exist in CDM databases).
|
45 |
|
|
* Preliminary implementation. Better implement API method for this.
|
46 |
|
|
* @return
|
47 |
|
|
*/
|
48 |
|
|
protected List<TaxonNode> getAllNodes(Set<Classification> classificationList) {
|
49 |
|
|
List<TaxonNode> allNodes = getClassificationService().getAllNodes();
|
50 |
|
|
List<TaxonNode> result = new ArrayList<TaxonNode>();
|
51 |
|
|
for (TaxonNode node : allNodes){
|
52 |
|
|
if (node.getClassification() == null ){
|
53 |
|
|
continue;
|
54 |
|
|
}else if (classificationList != null && classificationList.contains(node.getClassification())){
|
55 |
|
|
continue;
|
56 |
|
|
}
|
57 |
|
|
Taxon taxon = CdmBase.deproxy(node.getTaxon(), Taxon.class);
|
58 |
|
|
if (taxon == null){
|
59 |
|
|
String message = "There is a taxon node without taxon: " + node.getId();
|
60 |
|
|
logger.warn(message);
|
61 |
|
|
continue;
|
62 |
|
|
}
|
63 |
|
|
result.add(node);
|
64 |
|
|
}
|
65 |
|
|
return result;
|
66 |
|
|
}
|
67 |
|
|
|
68 |
|
|
|
69 |
2907e2c8
|
Andreas Müller
|
/**
|
70 |
|
|
* Creates the locationId, locality, countryCode triple
|
71 |
|
|
* @param record
|
72 |
|
|
* @param area
|
73 |
|
|
*/
|
74 |
7624f446
|
Andreas Müller
|
protected void handleArea(IDwcaAreaRecord record, NamedArea area, TaxonBase<?> taxon, boolean required) {
|
75 |
2907e2c8
|
Andreas Müller
|
if (area != null){
|
76 |
|
|
record.setLocationId(area.getId());
|
77 |
|
|
record.setLocality(area.getLabel());
|
78 |
|
|
if (area.isInstanceOf(WaterbodyOrCountry.class)){
|
79 |
|
|
WaterbodyOrCountry country = CdmBase.deproxy(area, WaterbodyOrCountry.class);
|
80 |
|
|
record.setCountryCode(country.getIso3166_A2());
|
81 |
|
|
}
|
82 |
7624f446
|
Andreas Müller
|
}else{
|
83 |
|
|
if (required){
|
84 |
|
|
String message = "Description requires area but area does not exist for taxon " + getTaxonLogString(taxon);
|
85 |
|
|
logger.warn(message);
|
86 |
|
|
}
|
87 |
2907e2c8
|
Andreas Müller
|
}
|
88 |
|
|
}
|
89 |
7624f446
|
Andreas Müller
|
|
90 |
|
|
|
91 |
|
|
protected String getTaxonLogString(TaxonBase<?> taxon) {
|
92 |
|
|
return taxon.getTitleCache() + "(" + taxon.getId() + ")";
|
93 |
|
|
}
|
94 |
d5fe8657
|
Andreas Müller
|
|
95 |
|
|
|
96 |
|
|
/**
|
97 |
|
|
* @param el
|
98 |
|
|
* @return
|
99 |
|
|
*/
|
100 |
|
|
protected boolean recordExists(CdmBase el) {
|
101 |
|
|
return existingRecordIds.contains(el.getId());
|
102 |
|
|
}
|
103 |
|
|
|
104 |
|
|
|
105 |
|
|
/**
|
106 |
|
|
* @param sec
|
107 |
|
|
*/
|
108 |
|
|
protected void addExistingRecord(CdmBase cdmBase) {
|
109 |
|
|
existingRecordIds.add(cdmBase.getId());
|
110 |
|
|
}
|
111 |
|
|
|
112 |
|
|
/**
|
113 |
|
|
* @param el
|
114 |
|
|
* @return
|
115 |
|
|
*/
|
116 |
|
|
protected boolean recordExistsUuid(CdmBase el) {
|
117 |
|
|
return existingRecordUuids.contains(el.getUuid());
|
118 |
|
|
}
|
119 |
|
|
|
120 |
|
|
/**
|
121 |
|
|
* @param sec
|
122 |
|
|
*/
|
123 |
|
|
protected void addExistingRecordUuid(CdmBase cdmBase) {
|
124 |
|
|
existingRecordUuids.add(cdmBase.getUuid());
|
125 |
|
|
}
|
126 |
2907e2c8
|
Andreas Müller
|
}
|