Revision 75f6d666
Added by Andreas Müller over 4 years ago
cdm-pesi/src/main/java/eu/etaxonomy/cdm/io/pesi/out/PesiRelTaxonExport.java | ||
---|---|---|
19 | 19 |
|
20 | 20 |
import eu.etaxonomy.cdm.io.common.Source; |
21 | 21 |
import eu.etaxonomy.cdm.io.common.mapping.out.DbAnnotationMapper; |
22 |
import eu.etaxonomy.cdm.io.common.mapping.out.DbFixedIntegerMapper; |
|
23 |
import eu.etaxonomy.cdm.io.common.mapping.out.DbFixedStringMapper; |
|
22 | 24 |
import eu.etaxonomy.cdm.io.common.mapping.out.DbObjectMapper; |
23 | 25 |
import eu.etaxonomy.cdm.io.common.mapping.out.MethodMapper; |
24 | 26 |
import eu.etaxonomy.cdm.model.common.CdmBase; |
... | ... | |
31 | 33 |
import eu.etaxonomy.cdm.model.taxon.Synonym; |
32 | 34 |
import eu.etaxonomy.cdm.model.taxon.Taxon; |
33 | 35 |
import eu.etaxonomy.cdm.model.taxon.TaxonBase; |
36 |
import eu.etaxonomy.cdm.model.taxon.TaxonNode; |
|
34 | 37 |
import eu.etaxonomy.cdm.model.taxon.TaxonRelationship; |
35 | 38 |
|
36 | 39 |
/** |
... | ... | |
54 | 57 |
|
55 | 58 |
private PesiExportMapping mapping; |
56 | 59 |
private PesiExportMapping synonymMapping; |
60 |
private PesiExportMapping taxonNodeMapping; |
|
57 | 61 |
|
58 | 62 |
public PesiRelTaxonExport() { |
59 | 63 |
super(); |
... | ... | |
89 | 93 |
synonymMapping = getSynonymMapping(); |
90 | 94 |
synonymMapping.initialize(state); |
91 | 95 |
|
96 |
// Get specific mappings: (CDM) Synonym -> (PESI) RelTaxon |
|
97 |
taxonNodeMapping = getTaxonNodeMapping(); |
|
98 |
taxonNodeMapping.initialize(state); |
|
99 |
|
|
100 |
|
|
92 | 101 |
//Export taxon relations |
93 | 102 |
success &= doPhase01(state, mapping); |
94 | 103 |
|
104 |
//Export taxon nodes |
|
105 |
success &= doPhase01b(state, taxonNodeMapping); |
|
106 |
|
|
95 | 107 |
// Export name relations |
96 | 108 |
success &= doPhase02(state, mapping); |
97 | 109 |
|
... | ... | |
181 | 193 |
return success; |
182 | 194 |
} |
183 | 195 |
|
196 |
private boolean doPhase01b(PesiExportState state, PesiExportMapping taxonNodeMapping) { |
|
197 |
logger.info("PHASE 1b: Taxonnodes ..."); |
|
198 |
boolean success = true; |
|
199 |
|
|
200 |
int limit = state.getConfig().getLimitSave(); |
|
201 |
// Start transaction |
|
202 |
TransactionStatus txStatus = startTransaction(true); |
|
203 |
logger.debug("Started new transaction. Fetching some " + pluralString + " (max: " + limit + ") ..."); |
|
204 |
|
|
205 |
List<TaxonNode> list; |
|
206 |
|
|
207 |
//taxon nodes |
|
208 |
int partitionCount = 0; |
|
209 |
int totalCount = 0; |
|
210 |
while ((list = getNextTaxonNodePartition(limit, partitionCount++, null)) != null) { |
|
211 |
totalCount = totalCount + list.size(); |
|
212 |
logger.info("Read " + list.size() + " PESI taxon nodes. Limit: " + limit + ". Total: " + totalCount ); |
|
213 |
for (TaxonNode tn : list){ |
|
214 |
try { |
|
215 |
taxonNodeMapping.invoke(tn); |
|
216 |
} catch (Exception e) { |
|
217 |
logger.error(e.getMessage() + ". TaxonNode: " + tn.getUuid()); |
|
218 |
e.printStackTrace(); |
|
219 |
} |
|
220 |
} |
|
221 |
|
|
222 |
commitTransaction(txStatus); |
|
223 |
txStatus = startTransaction(); |
|
224 |
} |
|
225 |
commitTransaction(txStatus); |
|
226 |
return success; |
|
227 |
} |
|
228 |
|
|
184 | 229 |
private boolean doPhase02(PesiExportState state, PesiExportMapping mapping2) { |
185 | 230 |
logger.info("PHASE 2: Name Relationships ..."); |
186 | 231 |
boolean success = true; |
... | ... | |
314 | 359 |
return state.getDbId(synonym); |
315 | 360 |
} |
316 | 361 |
|
362 |
/** |
|
363 |
* Returns the <code>TaxonFk1</code> attribute. It corresponds to a CDM <code>Synonym</code>. |
|
364 |
* @param synonym The {@link Synonym synonym}. |
|
365 |
* @param state The {@link PesiExportState PesiExportState}. |
|
366 |
* @return The <code>TaxonFk1</code> attribute. |
|
367 |
* @see MethodMapper |
|
368 |
*/ |
|
369 |
@SuppressWarnings("unused") |
|
370 |
private static Integer getParent(TaxonNode taxonNode, PesiExportState state) { |
|
371 |
TaxonNode parent = taxonNode == null? null : taxonNode.getParent(); |
|
372 |
Taxon parentTaxon = parent == null? null: parent.getTaxon(); |
|
373 |
return state.getDbId(parentTaxon); |
|
374 |
} |
|
375 |
|
|
317 | 376 |
/** |
318 | 377 |
* Returns the <code>TaxonFk2</code> attribute. It corresponds to a CDM <code>SynonymRelationship</code>. |
319 | 378 |
* @param relationship The {@link RelationshipBase Relationship}. |
... | ... | |
455 | 514 |
return mapping; |
456 | 515 |
} |
457 | 516 |
|
517 |
PesiExportMapping getTaxonNodeMapping() { |
|
518 |
PesiExportMapping mapping = new PesiExportMapping(dbTableName); |
|
519 |
|
|
520 |
mapping.addMapper(MethodMapper.NewInstance("TaxonFk2", this.getClass(), "getParent", TaxonNode.class, PesiExportState.class)); |
|
521 |
mapping.addMapper(DbObjectMapper.NewInstance("taxon", "TaxonFk1")); |
|
522 |
mapping.addMapper(DbFixedIntegerMapper.NewInstance(101, "RelTaxonQualifierFk")); |
|
523 |
mapping.addMapper(DbFixedStringMapper.NewInstance("is taxonomically included in", "RelQualifierCache")); |
|
524 |
// mapping.addMapper(DbAnnotationMapper.NewExludedInstance(getLastActionAnnotationTypes(), "Notes")); |
|
525 |
|
|
526 |
return mapping; |
|
527 |
} |
|
528 |
|
|
529 |
|
|
458 | 530 |
|
459 | 531 |
@Override |
460 | 532 |
protected boolean doCheck(PesiExportState state) { |
Also available in: Unified diff
ref #8509 add included taxon relationship export to PESI