29 |
29 |
import eu.etaxonomy.cdm.model.name.HybridRelationship;
|
30 |
30 |
import eu.etaxonomy.cdm.model.name.NameRelationship;
|
31 |
31 |
import eu.etaxonomy.cdm.model.name.NomenclaturalCode;
|
|
32 |
import eu.etaxonomy.cdm.model.name.NomenclaturalSource;
|
32 |
33 |
import eu.etaxonomy.cdm.model.name.TaxonName;
|
33 |
34 |
import eu.etaxonomy.cdm.model.taxon.Synonym;
|
34 |
35 |
import eu.etaxonomy.cdm.model.taxon.Taxon;
|
... | ... | |
58 |
59 |
private PesiExportMapping mapping;
|
59 |
60 |
private PesiExportMapping synonymMapping;
|
60 |
61 |
private PesiExportMapping taxonNodeMapping;
|
|
62 |
private PesiExportMapping originalSpellingMapping;
|
61 |
63 |
|
62 |
64 |
public PesiRelTaxonExport() {
|
63 |
65 |
super();
|
... | ... | |
97 |
99 |
taxonNodeMapping = getTaxonNodeMapping();
|
98 |
100 |
taxonNodeMapping.initialize(state);
|
99 |
101 |
|
100 |
|
|
101 |
102 |
//Export taxon relations
|
102 |
103 |
success &= doPhase01(state, mapping);
|
103 |
104 |
|
... | ... | |
247 |
248 |
while ((hybridList = getNextNameRelationshipPartition(HybridRelationship.class, limit, partitionCount++, null)) != null ) {
|
248 |
249 |
txStatus = handleNameRelationList(state, txStatus, hybridList);
|
249 |
250 |
}
|
|
251 |
//original spellings
|
|
252 |
List<NomenclaturalSource> originalSpellingList;
|
|
253 |
partitionCount = 0;
|
|
254 |
while ((originalSpellingList = getNextOriginalSpellingPartition(limit, partitionCount++, null)) != null ) {
|
|
255 |
txStatus = handleOriginalSpellingList(state, txStatus, originalSpellingList);
|
|
256 |
}
|
|
257 |
|
250 |
258 |
commitTransaction(txStatus);
|
251 |
259 |
logger.info("End PHASE 2: Name Relationships ...");
|
252 |
260 |
state.setCurrentFromObject(null);
|
... | ... | |
285 |
293 |
mapping.invoke(rel);
|
286 |
294 |
}
|
287 |
295 |
}
|
288 |
|
fromList = null;
|
289 |
|
toList = null;
|
290 |
|
|
291 |
296 |
} catch (Exception e) {
|
292 |
297 |
logger.error(e.getMessage() + ". Relationship: " + rel.getUuid());
|
293 |
298 |
e.printStackTrace();
|
... | ... | |
298 |
303 |
return txStatus;
|
299 |
304 |
}
|
300 |
305 |
|
|
306 |
private TransactionStatus handleOriginalSpellingList(PesiExportState state, TransactionStatus txStatus,
|
|
307 |
List<NomenclaturalSource> list) {
|
|
308 |
for (NomenclaturalSource nomSource : list){
|
|
309 |
try {
|
|
310 |
TaxonName name1 = nomSource.getNameUsedInSource();
|
|
311 |
TaxonName name2 = nomSource.getSourcedName();
|
|
312 |
List<IdentifiableEntity> fromList = new ArrayList<>();
|
|
313 |
List<IdentifiableEntity> toList = new ArrayList<>();
|
|
314 |
makeList(name1, fromList);
|
|
315 |
makeList(name2, toList);
|
|
316 |
|
|
317 |
for (IdentifiableEntity<?> fromEntity : fromList){
|
|
318 |
for (IdentifiableEntity<?> toEntity : toList){
|
|
319 |
//TODO set entities to state
|
|
320 |
state.setCurrentFromObject(fromEntity);
|
|
321 |
state.setCurrentToObject(toEntity);
|
|
322 |
originalSpellingMapping.invoke(nomSource);
|
|
323 |
}
|
|
324 |
}
|
|
325 |
} catch (Exception e) {
|
|
326 |
logger.error(e.getMessage() + ". NomenclaturalSource: " + nomSource.getUuid());
|
|
327 |
e.printStackTrace();
|
|
328 |
}
|
|
329 |
}
|
|
330 |
commitTransaction(txStatus);
|
|
331 |
txStatus = startTransaction();
|
|
332 |
return txStatus;
|
|
333 |
}
|
|
334 |
|
|
335 |
|
301 |
336 |
private void makeList(TaxonName name, List<IdentifiableEntity> list) {
|
302 |
337 |
if (! hasPesiTaxon(name)){
|
303 |
338 |
list.add(name);
|
304 |
339 |
}else{
|
305 |
|
for (TaxonBase<?> taxon: getPesiTaxa(name)){
|
|
340 |
for (TaxonBase<?> taxon: getPesiTaxa(name)){
|
306 |
341 |
list.add(taxon);
|
307 |
342 |
}
|
308 |
343 |
}
|
... | ... | |
373 |
408 |
return state.getDbId(parentTaxon);
|
374 |
409 |
}
|
375 |
410 |
|
|
411 |
/**
|
|
412 |
* Returns the id of the previously defined fromObject.
|
|
413 |
* @see MethodMapper
|
|
414 |
*/
|
|
415 |
@SuppressWarnings("unused")
|
|
416 |
private static Integer getFromObject(PesiExportState state) {
|
|
417 |
return state.getDbId(state.getCurrentFromObject());
|
|
418 |
}
|
|
419 |
/**
|
|
420 |
* Returns the id of the previously defined fromObject.
|
|
421 |
* @see MethodMapper
|
|
422 |
*/
|
|
423 |
@SuppressWarnings("unused")
|
|
424 |
private static Integer getToObject(PesiExportState state) {
|
|
425 |
return state.getDbId(state.getCurrentToObject());
|
|
426 |
}
|
|
427 |
|
376 |
428 |
/**
|
377 |
429 |
* Returns the <code>TaxonFk2</code> attribute. It corresponds to a CDM <code>SynonymRelationship</code>.
|
378 |
430 |
* @param relationship The {@link RelationshipBase Relationship}.
|
... | ... | |
448 |
500 |
if (relationship.isInstanceOf(TaxonRelationship.class)) {
|
449 |
501 |
TaxonRelationship tr = (TaxonRelationship)relationship;
|
450 |
502 |
taxonBase = (isFrom) ? tr.getFromTaxon(): tr.getToTaxon();
|
451 |
|
} else if (relationship.isInstanceOf(NameRelationship.class) || relationship.isInstanceOf(HybridRelationship.class)) {
|
|
503 |
} else if (relationship.isInstanceOf(NameRelationship.class)
|
|
504 |
|| relationship.isInstanceOf(HybridRelationship.class)) {
|
452 |
505 |
if (isFrom){
|
453 |
506 |
return state.getDbId(state.getCurrentFromObject());
|
454 |
507 |
}else{
|
... | ... | |
468 |
521 |
return null;
|
469 |
522 |
}
|
470 |
523 |
|
|
524 |
private static Integer getObjectFk(NomenclaturalSource nomSource, PesiExportState state, boolean isFrom) {
|
|
525 |
if (isFrom){
|
|
526 |
return state.getDbId(state.getCurrentFromObject());
|
|
527 |
}else{
|
|
528 |
return state.getDbId(state.getCurrentToObject());
|
|
529 |
}
|
|
530 |
}
|
|
531 |
|
471 |
532 |
@SuppressWarnings("unused") //for synonym mapping
|
472 |
533 |
private static String getSynonymTypeCache(Synonym synonym, PesiExportState state) {
|
473 |
534 |
String result = null;
|
... | ... | |
498 |
559 |
return mapping;
|
499 |
560 |
}
|
500 |
561 |
|
501 |
|
/**
|
|
562 |
/**
|
502 |
563 |
* Returns the CDM to PESI specific export mappings.
|
503 |
564 |
* @return The {@link PesiExportMapping PesiExportMapping}.
|
504 |
565 |
*/
|
... | ... | |
519 |
580 |
|
520 |
581 |
mapping.addMapper(MethodMapper.NewInstance("TaxonFk2", this.getClass(), "getParent", TaxonNode.class, PesiExportState.class));
|
521 |
582 |
mapping.addMapper(DbObjectMapper.NewInstance("taxon", "TaxonFk1"));
|
522 |
|
mapping.addMapper(DbFixedIntegerMapper.NewInstance(101, "RelTaxonQualifierFk"));
|
|
583 |
mapping.addMapper(DbFixedIntegerMapper.NewInstance(PesiTransformer.IS_TAXONOMICALLY_INCLUDED_IN, "RelTaxonQualifierFk"));
|
523 |
584 |
mapping.addMapper(DbFixedStringMapper.NewInstance("is taxonomically included in", "RelQualifierCache"));
|
524 |
585 |
// mapping.addMapper(DbAnnotationMapper.NewExludedInstance(getLastActionAnnotationTypes(), "Notes"));
|
525 |
586 |
|
526 |
587 |
return mapping;
|
527 |
588 |
}
|
528 |
589 |
|
|
590 |
PesiExportMapping getOriginalSpellingMapping() {
|
|
591 |
PesiExportMapping mapping = new PesiExportMapping(dbTableName);
|
|
592 |
|
|
593 |
mapping.addMapper(MethodMapper.NewInstance("TaxonFk1", this.getClass(), "getFromObject", PesiExportState.class));
|
|
594 |
mapping.addMapper(MethodMapper.NewInstance("TaxonFk2", this.getClass(), "getToObject", PesiExportState.class));
|
|
595 |
mapping.addMapper(DbFixedIntegerMapper.NewInstance(PesiTransformer.IS_ORIGINAL_SPELLING_FOR, "RelTaxonQualifierFk"));
|
|
596 |
mapping.addMapper(DbFixedStringMapper.NewInstance("is original spelling for", "RelQualifierCache"));
|
|
597 |
// mapping.addMapper(DbAnnotationMapper.NewExludedInstance(getLastActionAnnotationTypes(), "Notes"));
|
529 |
598 |
|
|
599 |
return mapping;
|
|
600 |
}
|
530 |
601 |
|
531 |
602 |
@Override
|
532 |
603 |
protected boolean doCheck(PesiExportState state) {
|
... | ... | |
537 |
608 |
protected boolean isIgnore(PesiExportState state) {
|
538 |
609 |
return ! state.getConfig().isDoRelTaxa();
|
539 |
610 |
}
|
540 |
|
}
|
|
611 |
}
|
ref #6591 adapt PESI import to new original spellings handling