Revision 3cbea5bb
Added by Andreas Müller over 3 years ago
app-import/src/main/java/eu/etaxonomy/cdm/io/berlinModel/in/BerlinModelTaxonRelationImport.java | ||
---|---|---|
34 | 34 |
import org.springframework.stereotype.Component; |
35 | 35 |
import org.springframework.transaction.TransactionStatus; |
36 | 36 |
|
37 |
import eu.etaxonomy.cdm.common.CdmUtils; |
|
37 | 38 |
import eu.etaxonomy.cdm.common.ResultWrapper; |
38 | 39 |
import eu.etaxonomy.cdm.io.berlinModel.BerlinModelTransformer; |
39 | 40 |
import eu.etaxonomy.cdm.io.berlinModel.in.validation.BerlinModelTaxonRelationImportValidator; |
... | ... | |
43 | 44 |
import eu.etaxonomy.cdm.model.common.AnnotatableEntity; |
44 | 45 |
import eu.etaxonomy.cdm.model.common.CdmBase; |
45 | 46 |
import eu.etaxonomy.cdm.model.common.IdentifiableSource; |
47 |
import eu.etaxonomy.cdm.model.name.NameRelationshipType; |
|
48 |
import eu.etaxonomy.cdm.model.name.NomenclaturalStatus; |
|
49 |
import eu.etaxonomy.cdm.model.name.NomenclaturalStatusType; |
|
50 |
import eu.etaxonomy.cdm.model.name.TaxonName; |
|
46 | 51 |
import eu.etaxonomy.cdm.model.reference.Reference; |
52 |
import eu.etaxonomy.cdm.model.reference.ReferenceFactory; |
|
47 | 53 |
import eu.etaxonomy.cdm.model.taxon.Classification; |
48 | 54 |
import eu.etaxonomy.cdm.model.taxon.Synonym; |
49 | 55 |
import eu.etaxonomy.cdm.model.taxon.SynonymType; |
... | ... | |
53 | 59 |
import eu.etaxonomy.cdm.model.taxon.TaxonRelationship; |
54 | 60 |
import eu.etaxonomy.cdm.model.taxon.TaxonRelationshipType; |
55 | 61 |
import eu.etaxonomy.cdm.strategy.exceptions.UnknownCdmTypeException; |
62 |
import eu.etaxonomy.cdm.strategy.parser.NonViralNameParserImpl; |
|
63 |
import eu.etaxonomy.cdm.strategy.parser.TimePeriodParser; |
|
56 | 64 |
|
57 | 65 |
/** |
58 | 66 |
* @author a.mueller |
... | ... | |
65 | 73 |
private static final Logger logger = Logger.getLogger(BerlinModelTaxonRelationImport.class); |
66 | 74 |
|
67 | 75 |
public static final String TREE_NAMESPACE = "PTRefFk"; |
76 |
private static final Integer AUCT_REF_ID = 5959; |
|
68 | 77 |
|
69 | 78 |
private static int modCount = 30000; |
70 | 79 |
private static final String pluralString = "taxon relations"; |
... | ... | |
253 | 262 |
int relPTaxonId = rs.getInt("RelPTaxonId"); |
254 | 263 |
Integer taxon1Id = nullSafeInt(rs, "taxon1Id"); |
255 | 264 |
Integer taxon2Id = nullSafeInt(rs, "taxon2Id"); |
265 |
Integer ptRefFk1 = nullSafeInt(rs, "PTRefFk1"); |
|
266 |
|
|
256 | 267 |
int relQualifierFk = -1; |
257 | 268 |
try { |
258 | 269 |
Integer relRefFk = nullSafeInt(rs,"relRefFk"); |
... | ... | |
289 | 300 |
if (relQualifierFk == TAX_REL_IS_INCLUDED_IN){ |
290 | 301 |
taxonRelationship = makeTaxonomicallyIncluded(state, classificationMap, treeRefFk, fromTaxon, toTaxon, citation, microcitation); |
291 | 302 |
}else if (relQualifierFk == TAX_REL_IS_MISAPPLIED_NAME_OF){ |
292 |
taxonRelationship = toTaxon.addMisappliedName(fromTaxon, citation, microcitation); |
|
303 |
boolean isProParte = "p.p.".equals(notes); |
|
304 |
if (isProParte){ |
|
305 |
notes = null; |
|
306 |
} |
|
307 |
boolean isDoubtful = "?".equals(notes); |
|
308 |
if (isDoubtful){ |
|
309 |
notes = null; |
|
310 |
} |
|
311 |
|
|
312 |
if (notes!= null && notes.startsWith("{non ") && notes.endsWith("}")){ |
|
313 |
notes = notes.substring(1, notes.length() - 1); |
|
314 |
} |
|
315 |
//handle auct. author |
|
316 |
if (fromTaxon.getSec() == null || fromTaxon.getSec().getTitleCache().startsWith("auct.")){ |
|
317 |
String existingSecTitle = fromTaxon.getSec() == null ? null : fromTaxon.getSec().getTitleCache().trim(); |
|
318 |
String existingAppendedPhrase = fromTaxon.getAppendedPhrase(); |
|
319 |
if (fromTaxon.getSec() == null && isBlank(existingAppendedPhrase)){ |
|
320 |
existingAppendedPhrase = "auct."; |
|
321 |
} |
|
322 |
fromTaxon.setSec(null); |
|
323 |
if (isNotBlank(existingAppendedPhrase) && isNotBlank(notes)){ |
|
324 |
logger.warn("Misapplied name has >1 MA relation with a note, RelId: " + relPTaxonId); |
|
325 |
} |
|
326 |
|
|
327 |
String newAppendedPhrase = CdmUtils.concat(", ", existingSecTitle, notes); |
|
328 |
fromTaxon.setAppendedPhrase(CdmUtils.concat("; ", existingAppendedPhrase, newAppendedPhrase)); |
|
329 |
if (isBlank(fromTaxon.getAppendedPhrase())){ |
|
330 |
logger.warn("Appended phrase is empty. This is probably not correct. RelID: " + relPTaxonId); |
|
331 |
}else if ("auct.".equals(fromTaxon.getAppendedPhrase())){ |
|
332 |
fromTaxon.setAppendedPhrase(null); |
|
333 |
} |
|
334 |
notes = null; |
|
335 |
}else if (notes != null && notes.startsWith("non ")){ |
|
336 |
fromTaxon.setAppendedPhrase(CdmUtils.concat(", ", fromTaxon.getAppendedPhrase(), notes)); |
|
337 |
notes = null; |
|
338 |
} |
|
339 |
|
|
340 |
if (isProParte){ |
|
341 |
taxonRelationship = toTaxon.addProParteMisappliedName(fromTaxon, citation, microcitation); |
|
342 |
}else{ |
|
343 |
taxonRelationship = toTaxon.addMisappliedName(fromTaxon, citation, microcitation); |
|
344 |
} |
|
345 |
if (isDoubtful){ |
|
346 |
((TaxonRelationship)taxonRelationship).setDoubtful(true); |
|
347 |
} |
|
293 | 348 |
}else if (relQualifierFk == TAX_REL_IS_PROPARTE_SYN_OF || |
294 | 349 |
//TODO homo/hetero |
295 | 350 |
relQualifierFk == TAX_REL_IS_PROPARTE_HOMOTYPIC_SYNONYM_OF || |
... | ... | |
326 | 381 |
success = false; |
327 | 382 |
logger.warn("Synonym relationship type not yet implemented: " + relQualifierFk); |
328 | 383 |
} |
384 |
// |
|
385 |
notes = handleSynonymNotes(state, toTaxon, synonym, notes, relPTaxonId); |
|
329 | 386 |
}else if (isConceptRelationship){ |
330 | 387 |
ResultWrapper<Boolean> isInverse = ResultWrapper.NewInstance(false); |
331 | 388 |
ResultWrapper<Boolean> isDoubtful = ResultWrapper.NewInstance(false); |
... | ... | |
358 | 415 |
success = false; |
359 | 416 |
} |
360 | 417 |
|
361 |
if (taxonRelationship != null){ |
|
418 |
if (taxonRelationship != null && isNotBlank(notes)){
|
|
362 | 419 |
doNotes(taxonRelationship, notes); |
363 |
}else if (isNotBlank(notes)){ |
|
364 |
logger.warn("Notes for synonym relationship or unknown taxon relationship not handled. RelID: " + relPTaxonId + ". Note: " + notes); |
|
420 |
} |
|
421 |
if (isNotBlank(notes)){ |
|
422 |
logger.warn("Notes in RelPTaxon should all be handled explicitly and should not exist as notes anymore. RelID: " + relPTaxonId + ". Note: " + notes); |
|
365 | 423 |
} |
366 | 424 |
taxaToSave.add(taxon2); |
367 | 425 |
|
... | ... | |
396 | 454 |
} |
397 | 455 |
|
398 | 456 |
|
399 |
private void handleAllRelatedTaxa(BerlinModelImportState state, Taxon taxon, Map<Integer, Classification> classificationMap, Integer secRefFk) { |
|
457 |
/** |
|
458 |
* @param toTaxon |
|
459 |
* @param synonym |
|
460 |
* @param notes |
|
461 |
* @return |
|
462 |
*/ |
|
463 |
private String handleSynonymNotes(BerlinModelImportState state, Taxon toTaxon, Synonym synonym, String notes, int relId) { |
|
464 |
if (state.getConfig().isEuroMed() && isNotBlank(notes)){ |
|
465 |
notes = notes.trim(); |
|
466 |
if (notes.startsWith("[non ") && notes.endsWith("]")){ |
|
467 |
notes = notes.substring(5, notes.length()-1).trim(); |
|
468 |
String[] splits = notes.split(", nec "); |
|
469 |
for (String split : splits){ |
|
470 |
String nameStr = split.replace("<i>", "").replace("</i>", ""); |
|
471 |
NonViralNameParserImpl parser = NonViralNameParserImpl.NewInstance(); |
|
472 |
TaxonName name; |
|
473 |
NomenclaturalStatusType status = null; |
|
474 |
if (nameStr.endsWith(", nom. rej.") || nameStr.endsWith(", nom. cons.")||nameStr.endsWith(", nom. illeg.")){ |
|
475 |
String statusStr = nameStr.endsWith(", nom. rej.")? ", nom. rej.": |
|
476 |
nameStr.endsWith(", nom. cons.")? ", nom. cons.": |
|
477 |
", nom. illeg."; |
|
478 |
nameStr = nameStr.replace(statusStr, ""); |
|
479 |
statusStr = statusStr.replace(", ", ""); |
|
480 |
try { |
|
481 |
status = NomenclaturalStatusType.getNomenclaturalStatusTypeByAbbreviation(statusStr, null); |
|
482 |
} catch (UnknownCdmTypeException e) { |
|
483 |
logger.warn("NomStatusType not recognized: "+ statusStr + ", RelId: " + relId); |
|
484 |
} |
|
485 |
} |
|
486 |
|
|
487 |
if (nameStr.contains(",") || nameStr.contains(" in ") ){ |
|
488 |
name = parser.parseReferencedName(nameStr, state.getConfig().getNomenclaturalCode(), null); |
|
489 |
}else if (nameStr.matches(".*\\s\\d{4}")){ |
|
490 |
String nameStr2 = nameStr.substring(0, nameStr.length() - 5).trim(); |
|
491 |
String yearStr = nameStr.substring(nameStr.length()-4); |
|
492 |
name = (TaxonName)parser.parseFullName(nameStr2, state.getConfig().getNomenclaturalCode(), null); |
|
493 |
Reference nomRef = name.getNomenclaturalReference(); |
|
494 |
if (nomRef == null){ |
|
495 |
nomRef = ReferenceFactory.newGeneric(); |
|
496 |
name.setNomenclaturalReference(nomRef); |
|
497 |
} |
|
498 |
nomRef.setDatePublished(TimePeriodParser.parseStringVerbatim(yearStr)); |
|
499 |
}else if (nameStr.endsWith(" 1831-1832")){ |
|
500 |
String nameStr2 = nameStr.substring(0, nameStr.length() - 10).trim(); |
|
501 |
name = (TaxonName)parser.parseFullName(nameStr2, state.getConfig().getNomenclaturalCode(), null); |
|
502 |
Reference nomRef = name.getNomenclaturalReference(); |
|
503 |
if (nomRef == null){ |
|
504 |
nomRef = ReferenceFactory.newGeneric(); |
|
505 |
name.setNomenclaturalReference(nomRef); |
|
506 |
} |
|
507 |
nomRef.setDatePublished(TimePeriodParser.parseStringVerbatim("1831-1832")); |
|
508 |
}else{ |
|
509 |
name = parser.parseReferencedName(nameStr, state.getConfig().getNomenclaturalCode(), null); |
|
510 |
} |
|
511 |
if (name.isProtectedTitleCache() || name.isProtectedNameCache() |
|
512 |
|| name.getNomenclaturalReference() != null && (name.getNomenclaturalReference().isProtectedAbbrevTitleCache()|| name.getNomenclaturalReference().isProtectedTitleCache() )){ |
|
513 |
logger.warn("Blocking name for synonym relation could not be parsed: " + nameStr + ", RelId: "+ relId); |
|
514 |
} |
|
515 |
if (status != null){ |
|
516 |
name.addStatus(NomenclaturalStatus.NewInstance(status)); |
|
517 |
} |
|
518 |
synonym.getName().addRelationshipFromName(name, NameRelationshipType.BLOCKING_NAME_FOR(), null, null, null); |
|
519 |
|
|
520 |
getNameService().saveOrUpdate(name); |
|
521 |
} |
|
522 |
return null; |
|
523 |
}else{ |
|
524 |
return notes; |
|
525 |
} |
|
526 |
}else{ |
|
527 |
return notes; |
|
528 |
} |
|
529 |
} |
|
530 |
|
|
531 |
private void handleAllRelatedTaxa(BerlinModelImportState state, Taxon taxon, |
|
532 |
Map<Integer, Classification> classificationMap, Integer secRefFk) { |
|
400 | 533 |
if (taxon.getTaxonNodes().size() > 0){ |
401 | 534 |
return; |
402 | 535 |
}else{ |
Also available in: Unified diff
E+M latest changes to taxon relations import