Revision ba5dcea5
Added by Andreas Müller almost 6 years ago
cdmlib-io/src/main/java/eu/etaxonomy/cdm/io/cdmLight/CdmLightClassificationExport.java | ||
---|---|---|
76 | 76 |
import eu.etaxonomy.cdm.model.taxon.Synonym; |
77 | 77 |
import eu.etaxonomy.cdm.model.taxon.Taxon; |
78 | 78 |
import eu.etaxonomy.cdm.model.taxon.TaxonNode; |
79 |
import eu.etaxonomy.cdm.model.taxon.TaxonRelationship; |
|
80 |
import eu.etaxonomy.cdm.model.taxon.TaxonRelationshipType; |
|
79 | 81 |
import eu.etaxonomy.cdm.strategy.exceptions.UnknownCdmTypeException; |
80 | 82 |
|
81 | 83 |
/** |
... | ... | |
145 | 147 |
|
146 | 148 |
@SuppressWarnings("unchecked") |
147 | 149 |
TaxonNodeOutStreamPartitioner<XmlExportState> partitioner |
148 |
= TaxonNodeOutStreamPartitioner.NewInstance( |
|
149 |
this, state, state.getConfig().getTaxonNodeFilter(), |
|
150 |
100, monitor, null); |
|
150 |
= TaxonNodeOutStreamPartitioner.NewInstance(
|
|
151 |
this, state, state.getConfig().getTaxonNodeFilter(),
|
|
152 |
100, monitor, null);
|
|
151 | 153 |
|
152 | 154 |
|
153 | 155 |
monitor.subTask("Start partitioning"); |
154 | 156 |
|
155 | 157 |
TaxonNode node = partitioner.next(); |
156 | 158 |
while (node != null){ |
157 |
handleTaxonNode(state, node); |
|
158 |
node = partitioner.next(); |
|
159 |
handleTaxonNode(state, node);
|
|
160 |
node = partitioner.next();
|
|
159 | 161 |
} |
160 | 162 |
|
161 | 163 |
|
... | ... | |
175 | 177 |
* @param classificationUuid |
176 | 178 |
*/ |
177 | 179 |
private void handleTaxonNode(CdmLightExportState state, TaxonNode taxonNode) { |
178 |
try { |
|
179 |
// TaxonNode taxonNode = getTaxonNodeService().find(taxonNodeUuid); |
|
180 | 180 |
|
181 | 181 |
if (taxonNode == null){ |
182 | 182 |
String message = "TaxonNode for given taxon node UUID not found. "; |
183 | 183 |
//TODO |
184 | 184 |
state.getResult().addWarning(message); |
185 | 185 |
}else{ |
186 |
TaxonNode root = taxonNode; |
|
187 |
if (root.hasTaxon()){ |
|
188 |
handleTaxon(state, root); |
|
189 |
}else{ |
|
190 |
// for (TaxonNode child : root.getChildNodes()){ |
|
191 |
// handleTaxon(state, child); |
|
192 |
// //TODO progress monitor |
|
193 |
// } |
|
186 |
try { |
|
187 |
TaxonNode root = taxonNode; |
|
188 |
if (root.hasTaxon()){ |
|
189 |
handleTaxon(state, root); |
|
190 |
}else{ |
|
191 |
// for (TaxonNode child : root.getChildNodes()){ |
|
192 |
// handleTaxon(state, child); |
|
193 |
// //TODO progress monitor |
|
194 |
// } |
|
195 |
} |
|
196 |
} catch (Exception e) { |
|
197 |
state.getResult().addException(e, "An unexpected error occurred when handling classification " + |
|
198 |
taxonNode.getUuid() + ": " + e.getMessage() + e.getStackTrace()); |
|
194 | 199 |
} |
195 | 200 |
} |
196 |
} catch (Exception e) { |
|
197 |
state.getResult().addException(e, "An unexpected error occurred when handling classification " + |
|
198 |
taxonNode.getUuid() + ": " + e.getMessage() + e.getStackTrace()); |
|
199 |
} |
|
200 | 201 |
} |
201 | 202 |
|
202 | 203 |
/** |
... | ... | |
223 | 224 |
for (Synonym syn : taxon.getSynonyms()){ |
224 | 225 |
handleSynonym(state, syn); |
225 | 226 |
} |
226 |
|
|
227 |
for (TaxonRelationship rel : taxon.getProParteAndPartialSynonymRelations()){ |
|
228 |
handleProPartePartialMisapplied(state, rel); |
|
229 |
} |
|
230 |
for (TaxonRelationship rel : taxon.getMisappliedNameRelations()){ |
|
231 |
handleProPartePartialMisapplied(state, rel); |
|
232 |
} |
|
227 | 233 |
|
228 | 234 |
CdmLightExportTable table = CdmLightExportTable.TAXON; |
229 | 235 |
String[] csvLine = new String[table.getSize()]; |
... | ... | |
256 | 262 |
} |
257 | 263 |
} |
258 | 264 |
|
265 |
|
|
259 | 266 |
/** |
260 | 267 |
* @param state |
261 | 268 |
* @param taxon |
... | ... | |
704 | 711 |
csvLine[table.getIndex(CdmLightExportTable.NAME_FK)] = getId(state, name); |
705 | 712 |
csvLine[table.getIndex(CdmLightExportTable.SEC_REFERENCE_FK)] = getId(state, synonym.getSec()); |
706 | 713 |
csvLine[table.getIndex(CdmLightExportTable.SEC_REFERENCE)] = getTitleCache(synonym.getSec()); |
707 |
if (synonym.isProParte()) { |
|
708 |
csvLine[table.getIndex(CdmLightExportTable.IS_PRO_PARTE)] = "1"; |
|
709 |
}else { |
|
710 |
csvLine[table.getIndex(CdmLightExportTable.IS_PRO_PARTE)] = "0"; |
|
711 |
} |
|
712 | 714 |
|
713 | 715 |
state.getProcessor().put(table, synonym, csvLine); |
714 | 716 |
} catch (Exception e) { |
... | ... | |
718 | 720 |
} |
719 | 721 |
|
720 | 722 |
|
723 |
/** |
|
724 |
* Handles Misapplied names (including pro parte and partial as well as |
|
725 |
* pro parte and partial synonyms |
|
726 |
* @param state |
|
727 |
* @param rel |
|
728 |
*/ |
|
729 |
private void handleProPartePartialMisapplied(CdmLightExportState state, TaxonRelationship rel) { |
|
730 |
try { |
|
731 |
Taxon ppSyonym = rel.getFromTaxon(); |
|
732 |
if (isUnpublished(state.getConfig(), ppSyonym)){ |
|
733 |
return; |
|
734 |
} |
|
735 |
TaxonName name = ppSyonym.getName(); |
|
736 |
handleName(state, name); |
|
737 |
|
|
738 |
CdmLightExportTable table = CdmLightExportTable.SYNONYM; |
|
739 |
String[] csvLine = new String[table.getSize()]; |
|
740 |
|
|
741 |
csvLine[table.getIndex(CdmLightExportTable.SYNONYM_ID)] = getId(state, rel); |
|
742 |
csvLine[table.getIndex(CdmLightExportTable.TAXON_FK)] = getId(state, rel.getToTaxon()); |
|
743 |
csvLine[table.getIndex(CdmLightExportTable.NAME_FK)] = getId(state, name); |
|
744 |
|
|
745 |
//TODO pro parte synonyms have to references, the synonym relationship reference |
|
746 |
//and the sec reference of the Taxon representing the synonym. |
|
747 |
//As we currently do have only 1 reference column in CDM light the synonym relationship |
|
748 |
//reference is used here. This is according to how pro parte synonyms were mapped to |
|
749 |
//concept relationships in #7334 |
|
750 |
Reference secRef = rel.getCitation(); |
|
751 |
csvLine[table.getIndex(CdmLightExportTable.SEC_REFERENCE_FK)] = getId(state, secRef); |
|
752 |
csvLine[table.getIndex(CdmLightExportTable.SEC_REFERENCE)] = getTitleCache(secRef); |
|
753 |
|
|
754 |
// Reference secRef = ppSyonym.getSec(); |
|
755 |
// csvLine[table.getIndex(CdmLightExportTable.SEC_REFERENCE_FK)] = getId(state, secRef); |
|
756 |
// csvLine[table.getIndex(CdmLightExportTable.SEC_REFERENCE)] = getTitleCache(secRef); |
|
757 |
// Reference synSecRef = rel.getCitation(); |
|
758 |
// csvLine[table.getIndex(CdmLightExportTable.SYN_SEC_REFERENCE_FK)] = getId(state, secRef); |
|
759 |
// csvLine[table.getIndex(CdmLightExportTable.SYN_SEC_REFERENCE)] = getTitleCache(secRef); |
|
760 |
|
|
761 |
//pro parte type |
|
762 |
TaxonRelationshipType type = rel.getType(); |
|
763 |
csvLine[table.getIndex(CdmLightExportTable.IS_PRO_PARTE)] = type.isProParte()? "1":"0"; |
|
764 |
csvLine[table.getIndex(CdmLightExportTable.IS_PARTIAL)] = type.isPartial()? "1":"0"; |
|
765 |
csvLine[table.getIndex(CdmLightExportTable.IS_MISAPPLIED)] = type.isAnyMisappliedName()? "1":"0"; |
|
766 |
if (type.isPartial()) { |
|
767 |
String message = "Partial synonyms/misapplied names not yet handled by CDM light. Created " |
|
768 |
+ "pro parte synonym/misapplied name instead for " + rel.getId(); |
|
769 |
state.getResult().addWarning(message, "handleProParteSynonym", ppSyonym.getTitleCache()); |
|
770 |
csvLine[table.getIndex(CdmLightExportTable.IS_PRO_PARTE)] = "1"; |
|
771 |
} |
|
772 |
|
|
773 |
state.getProcessor().put(table, ppSyonym, csvLine); |
|
774 |
} catch (Exception e) { |
|
775 |
state.getResult().addException(e, "An unexpected error occurred when handling " |
|
776 |
+ "pro parte/partial synonym relationship " + |
|
777 |
cdmBaseStr(rel) + ": " + e.getMessage()); |
|
778 |
} |
|
779 |
|
|
780 |
} |
|
781 |
|
|
782 |
|
|
721 | 783 |
/** |
722 | 784 |
* @param state |
723 | 785 |
* @param name |
Also available in: Unified diff
ref #7334 adapt DwCA and CDM light export to new pro parte synonym handling, also add misapplied name handling to CDM light