Revision 00dfef96
Added by Andreas Müller over 6 years ago
cdmlib-io/src/main/java/eu/etaxonomy/cdm/io/dwca/out/DwcaExportBase.java | ||
---|---|---|
29 | 29 |
|
30 | 30 |
import org.apache.commons.lang.StringUtils; |
31 | 31 |
import org.apache.log4j.Logger; |
32 |
import org.springframework.beans.factory.annotation.Autowired; |
|
32 | 33 |
|
34 |
import eu.etaxonomy.cdm.api.service.IClassificationService; |
|
35 |
import eu.etaxonomy.cdm.api.service.ITaxonNodeService; |
|
33 | 36 |
import eu.etaxonomy.cdm.common.CdmUtils; |
34 | 37 |
import eu.etaxonomy.cdm.io.common.CdmExportBase; |
35 | 38 |
import eu.etaxonomy.cdm.io.common.ICdmExport; |
... | ... | |
61 | 64 |
|
62 | 65 |
protected static final boolean IS_CORE = true; |
63 | 66 |
|
67 |
@Autowired |
|
68 |
private IClassificationService classificationService; |
|
69 |
|
|
70 |
@Autowired |
|
71 |
private ITaxonNodeService taxonNodeService; |
|
72 |
|
|
64 | 73 |
|
65 | 74 |
@Override |
66 | 75 |
public int countSteps(DwcaTaxExportState state) { |
... | ... | |
104 | 113 |
|
105 | 114 |
private void makeAllNodes(DwcaTaxExportState state, Set<UUID> subtreeSet) { |
106 | 115 |
|
107 |
boolean doSynonyms = false; |
|
108 |
boolean recursive = true; |
|
109 |
Set<UUID> uuidSet = new HashSet<>(); |
|
116 |
try { |
|
117 |
boolean doSynonyms = false; |
|
118 |
boolean recursive = true; |
|
119 |
Set<UUID> uuidSet = new HashSet<>(); |
|
120 |
|
|
121 |
for (UUID subtreeUuid : subtreeSet){ |
|
122 |
UUID tnUuuid = taxonNodeUuid(subtreeUuid); |
|
123 |
uuidSet.add(tnUuuid); |
|
124 |
List<TaxonNodeDto> records = getTaxonNodeService().pageChildNodesDTOs(tnUuuid, |
|
125 |
recursive, doSynonyms, null, null, null).getRecords(); |
|
126 |
for (TaxonNodeDto dto : records){ |
|
127 |
uuidSet.add(dto.getUuid()); |
|
128 |
} |
|
129 |
} |
|
130 |
List<TaxonNode> allNodes = getTaxonNodeService().find(uuidSet); |
|
110 | 131 |
|
111 |
for (UUID subtreeUuid : subtreeSet){ |
|
112 |
uuidSet.add(subtreeUuid); |
|
113 |
List<TaxonNodeDto> records = getTaxonNodeService().pageChildNodesDTOs(subtreeUuid, |
|
114 |
recursive, doSynonyms, null, null, null).getRecords(); |
|
115 |
for (TaxonNodeDto dto : records){ |
|
116 |
uuidSet.add(dto.getUuid()); |
|
132 |
List<TaxonNode> result = new ArrayList<>(); |
|
133 |
for (TaxonNode node : allNodes){ |
|
134 |
if(node.getParent()== null){ //root (or invalid) node |
|
135 |
continue; |
|
136 |
} |
|
137 |
node = CdmBase.deproxy(node); |
|
138 |
Taxon taxon = CdmBase.deproxy(node.getTaxon()); |
|
139 |
if (taxon == null){ |
|
140 |
String message = "There is a taxon node without taxon. id=" + node.getId(); |
|
141 |
state.getResult().addWarning(message); |
|
142 |
continue; |
|
143 |
} |
|
144 |
result.add(node); |
|
117 | 145 |
} |
146 |
state.setAllNodes(result); |
|
147 |
} catch (Exception e) { |
|
148 |
String message = "Unexpected exception when trying to compute all taxon nodes"; |
|
149 |
state.getResult().addException(e, message); |
|
118 | 150 |
} |
119 |
List<TaxonNode> allNodes = getTaxonNodeService().find(uuidSet);
|
|
151 |
}
|
|
120 | 152 |
|
121 |
List<TaxonNode> result = new ArrayList<>(); |
|
122 |
for (TaxonNode node : allNodes){ |
|
123 |
if(node.getParent()== null){ //root (or invalid) node |
|
124 |
continue; |
|
125 |
} |
|
126 |
node = CdmBase.deproxy(node); |
|
127 |
Taxon taxon = CdmBase.deproxy(node.getTaxon()); |
|
128 |
if (taxon == null){ |
|
129 |
String message = "There is a taxon node without taxon. id=" + node.getId(); |
|
130 |
state.getResult().addWarning(message); |
|
131 |
continue; |
|
153 |
|
|
154 |
/** |
|
155 |
* @param subtreeUuid |
|
156 |
* @return |
|
157 |
*/ |
|
158 |
private UUID taxonNodeUuid(UUID subtreeUuid) { |
|
159 |
TaxonNode node = taxonNodeService.find(subtreeUuid); |
|
160 |
if (node == null){ |
|
161 |
Classification classification = classificationService.find(subtreeUuid); |
|
162 |
if (classification != null){ |
|
163 |
node = classification.getRootNode(); |
|
164 |
}else{ |
|
165 |
throw new IllegalArgumentException("Subtree identifier does not exist: " + subtreeUuid); |
|
132 | 166 |
} |
133 |
result.add(node); |
|
134 | 167 |
} |
135 |
state.setAllNodes(result);
|
|
168 |
return node.getUuid();
|
|
136 | 169 |
} |
137 | 170 |
|
138 |
|
|
139 | 171 |
/** |
140 | 172 |
* Creates the locationId, locality, countryCode triple |
141 | 173 |
* @param record |
Also available in: Unified diff
ref #6755 first preliminary version of DwC-A export web service