Project

General

Profile

Revision ae538f84

IDae538f84d062f7f5add7875d51ebbf827702e5b2
Parent d5e984f6
Child c8c58de5

Added by Patrick Plitzner about 5 years ago

#5448 Fix import of hybrids due to merge conflicts

View differences:

app-import/src/main/java/eu/etaxonomy/cdm/io/redlist/gefaesspflanzen/RedListGefaesspflanzenImportNames.java
38 38
import eu.etaxonomy.cdm.model.description.TaxonDescription;
39 39
import eu.etaxonomy.cdm.model.name.BotanicalName;
40 40
import eu.etaxonomy.cdm.model.name.CultivarPlantName;
41
import eu.etaxonomy.cdm.model.name.NomenclaturalCode;
41 42
import eu.etaxonomy.cdm.model.name.NomenclaturalStatus;
42 43
import eu.etaxonomy.cdm.model.name.NomenclaturalStatusType;
43 44
import eu.etaxonomy.cdm.model.name.NonViralName;
......
234 235
        addAnnotation(RedListUtil.WISSK+": "+wisskString, taxonBase);
235 236

  
236 237
        //check taxon name consistency
237
        checkTaxonNameConsistency(id, taxNameString, hybString, taxonBase);
238
        checkTaxonConsistency(id, taxNameString, hybString, taxonBase);
238 239
        return taxonBase;
239 240
    }
240 241

  
......
252 253
        String zusatzString = rs.getString(RedListUtil.ZUSATZ);
253 254
        String authorKombString = rs.getString(RedListUtil.AUTOR_KOMB);
254 255
        String authorBasiString = rs.getString(RedListUtil.AUTOR_BASI);
256
        String hybString = rs.getString(RedListUtil.HYB);
255 257

  
256 258
        //combination author
257 259
        if(authorKombString.contains(RedListUtil.EX)){
......
319 321

  
320 322
        //check authorship consistency
321 323
        String authorString = rs.getString(RedListUtil.AUTOR);
322
        String authorshipCache = name.getAuthorshipCache();
323
        checkAuthorShipConsistency(id, nomZusatzString, taxZusatzString, zusatzString, authorString, authorshipCache);
324
        checkNameConsistency(id, nomZusatzString, taxZusatzString, zusatzString, authorString, hybString, name);
324 325
    }
325 326

  
326 327
    private NonViralName<?> importName(RedListGefaesspflanzenImportState state, ResultSet rs, Set<TaxonNameBase> namesToSave) throws SQLException {
......
366 367
                    name.setSpecificEpithet(ep2String);
367 368
                }
368 369
            }
369
        }
370
        //hybrid
371
        if(CdmUtils.isNotBlank(hybString)){
372
            //save hybrid formula
373
            if(CdmUtils.isNotBlank(formelString)){
374
                Annotation annotation = Annotation.NewDefaultLanguageInstance(formelString);
375
                annotation.setAnnotationType(AnnotationType.TECHNICAL());
376
                name.addAnnotation(annotation);
370
            if(CdmUtils.isNotBlank(ep3String)){
371
                name.setInfraSpecificEpithet(ep3String);
377 372
            }
378 373

  
379
            if(hybString.equals(RedListUtil.HYB_X)){
380
                name.setBinomHybrid(true);
381
                if(CdmUtils.isNotBlank(ep3String)){
382
                    name.setInfraSpecificEpithet(ep3String);
383
                }
384
                //nomenclatural status
385
                if(CdmUtils.isNotBlank(nomZusatzString)){
386
                    NomenclaturalStatusType statusType = makeNomenclaturalStatus(id, state, nomZusatzString);
387
                    if(statusType!=null){
388
                        NomenclaturalStatus status = NomenclaturalStatus.NewInstance(statusType);
389
                        //special case for invalid names where the DB entry contains
390
                        //additional information in brackets e.g. "nom. inval. (sine basion.)"
391
                        if(statusType.equals(NomenclaturalStatusType.INVALID())){
392
                            Pattern pattern = Pattern.compile("\\((.*?)\\)");
393
                            Matcher matcher = pattern.matcher(nomZusatzString);
394
                            if (matcher.find()){
395
                                status.setRuleConsidered(matcher.group(1));
396
                            }
374

  
375
            //nomenclatural status
376
            if(CdmUtils.isNotBlank(nomZusatzString)){
377
                NomenclaturalStatusType statusType = makeNomenclaturalStatus(id, state, nomZusatzString);
378
                if(statusType!=null){
379
                    NomenclaturalStatus status = NomenclaturalStatus.NewInstance(statusType);
380
                    //special case for invalid names where the DB entry contains
381
                    //additional information in brackets e.g. "nom. inval. (sine basion.)"
382
                    if(statusType.equals(NomenclaturalStatusType.INVALID())){
383
                        Pattern pattern = Pattern.compile("\\((.*?)\\)");
384
                        Matcher matcher = pattern.matcher(nomZusatzString);
385
                        if (matcher.find()){
386
                            status.setRuleConsidered(matcher.group(1));
397 387
                        }
398
                        name.addStatus(status);
399 388
                    }
389
                    name.addStatus(status);
400 390
                }
401
                //hybrid
402
                if(CdmUtils.isNotBlank(hybString)){
403
                    if(hybString.equals(RedListUtil.HYB_X)){
404
                        name.setBinomHybrid(true);
405
                    }
406
                    else if(hybString.equals(RedListUtil.HYB_G)){
407
                        name.setMonomHybrid(true);
391
            }
392
            //hybrid
393
            if(CdmUtils.isNotBlank(hybString)){
394
                //save hybrid formula
395
                if(CdmUtils.isNotBlank(formelString)){
396
                    Annotation annotation = Annotation.NewDefaultLanguageInstance(formelString);
397
                    annotation.setAnnotationType(AnnotationType.TECHNICAL());
398
                    name.addAnnotation(annotation);
399
                }
400

  
401
                if(hybString.equals(RedListUtil.HYB_X)){
402
                    name.setBinomHybrid(true);
403
                }
404
                else if(hybString.equals(RedListUtil.HYB_G)){
405
                    name.setMonomHybrid(true);
406
                }
407
                else if(hybString.equals(RedListUtil.HYB_XF)){
408
                    name.setHybridFormula(true);
409
                    if(ep1String.contains(RedListUtil.HYB_SIGN)){
410
                        RedListUtil.logMessage(id, "EPI1 has hybrid signs but with flag: "+RedListUtil.HYB_XF, logger);
408 411
                    }
409
                    else if(hybString.equals(RedListUtil.HYB_XF)){
410
                        name.setHybridFormula(true);
411
                        if(ep1String.contains(RedListUtil.HYB_SIGN)){
412
                            RedListUtil.logMessage(id, "EPI1 has hybrid signs but with flag: "+RedListUtil.HYB_XF, logger);
413
                        }
414
                        else if(ep2String.contains(RedListUtil.HYB_SIGN)){
415
                            String[] split = ep2String.split(RedListUtil.HYB_SIGN);
416
                            if(split.length!=2){
417
                                RedListUtil.logMessage(id, "Multiple hybrid signs found in "+ep2String, logger);
418
                            }
419
                            String hybridFormula1 = ep1String+" "+split[0].trim();
420
                            String hybridFormula2 = ep1String+" "+split[1].trim();
421
                            if(CdmUtils.isNotBlank(ep3String)){
422
                                hybridFormula1 += " "+ep3String;
423
                                hybridFormula2 += " "+ep3String;
424
                            }
425
                            String fullFormula = hybridFormula1+" "+RedListUtil.HYB_SIGN+" "+hybridFormula2;
426
                            name = NonViralNameParserImpl.NewInstance().parseFullName(fullFormula);
412
                    else if(ep2String.contains(RedListUtil.HYB_SIGN)){
413
                        String[] split = ep2String.split(RedListUtil.HYB_SIGN);
414
                        if(split.length!=2){
415
                            RedListUtil.logMessage(id, "Multiple hybrid signs found in "+ep2String, logger);
427 416
                        }
428
                        else if(ep3String.contains(RedListUtil.HYB_SIGN)){
429
                            String[] split = ep3String.split(RedListUtil.HYB_SIGN);
430
                            if(split.length!=2){
431
                                RedListUtil.logMessage(id, "Multiple hybrid signs found in "+ep3String, logger);
432
                            }
433
                            String hybridFormula1 = ep1String+" "+ep2String+" "+split[0];
434
                            String hybridFormula2 = ep1String+" "+ep2String+" "+split[1];
435
                            String fullFormula = hybridFormula1+" "+RedListUtil.HYB_SIGN+" "+hybridFormula2;
436
                            name = NonViralNameParserImpl.NewInstance().parseFullName(fullFormula);
417
                        String hybridFormula1 = ep1String+" "+split[0].trim();
418
                        String hybridFormula2 = ep1String+" "+split[1].trim();
419
                        if(CdmUtils.isNotBlank(ep3String)){
420
                            hybridFormula1 += " "+ep3String;
421
                            hybridFormula2 += " "+ep3String;
437 422
                        }
423
                        String fullFormula = hybridFormula1+" "+RedListUtil.HYB_SIGN+" "+hybridFormula2;
424
                        name = NonViralNameParserImpl.NewInstance().parseFullName(fullFormula, NomenclaturalCode.ICNAFP, rank);
438 425
                    }
439
                    else if(hybString.equals(RedListUtil.HYB_N)){
440
                        name = NonViralNameParserImpl.NewInstance().parseFullName(ep1String+" "+ep2String+" nothosubsp. "+ep3String);
441
                    }
442
                    else if(hybString.equals(RedListUtil.HYB_GF)){
443
                        if(ep1String.contains(RedListUtil.HYB_SIGN)){
444
                            name = NonViralNameParserImpl.NewInstance().parseFullName(ep1String);
445
                        }
446
                        else{
447
                            RedListUtil.logMessage(id, "HYB is "+hybString+" but "+RedListUtil.HYB+" does not contain "+RedListUtil.HYB_SIGN, logger);
426
                    else if(ep3String.contains(RedListUtil.HYB_SIGN)){
427
                        String[] split = ep3String.split(RedListUtil.HYB_SIGN);
428
                        if(split.length!=2){
429
                            RedListUtil.logMessage(id, "Multiple hybrid signs found in "+ep3String, logger);
448 430
                        }
431
                        String hybridFormula1 = ep1String+" "+ep2String+" "+split[0];
432
                        String hybridFormula2 = ep1String+" "+ep2String+" "+split[1];
433
                        String fullFormula = hybridFormula1+" "+RedListUtil.HYB_SIGN+" "+hybridFormula2;
434
                        name = NonViralNameParserImpl.NewInstance().parseFullName(fullFormula);
449 435
                    }
450
                    else if(hybString.equals(RedListUtil.HYB_XS)){
451
                        //nothing to do
436
                }
437
                else if(hybString.equals(RedListUtil.HYB_N)){
438
                    name = NonViralNameParserImpl.NewInstance().parseFullName(taxNameString);
439
                }
440
                else if(hybString.equals(RedListUtil.HYB_GF)){
441
                    if(ep1String.contains(RedListUtil.HYB_SIGN)){
442
                        name = NonViralNameParserImpl.NewInstance().parseFullName(ep1String);
452 443
                    }
453 444
                    else{
454
                        logger.error("HYB value "+hybString+" not yet handled");
445
                        RedListUtil.logMessage(id, "HYB is "+hybString+" but "+RedListUtil.HYB+" does not contain "+RedListUtil.HYB_SIGN, logger);
455 446
                    }
456 447
                }
448
                else if(hybString.equals(RedListUtil.HYB_XS)){
449
                    //nothing to do
450
                }
457 451
                else{
458 452
                    logger.error("HYB value "+hybString+" not yet handled");
459 453
                }
......
466 460
        return name;
467 461
    }
468 462

  
469
    private void checkAuthorShipConsistency(long id, String nomZusatzString, String taxZusatzString,
470
            String zusatzString, String authorString, String authorshipCache) {
463
    private void checkNameConsistency(long id, String nomZusatzString, String taxZusatzString,
464
            String zusatzString, String authorString, String hybString, NonViralName<?> name) {
465
        String authorshipCache = name.getAuthorshipCache();
466
        if(hybString.equals(RedListUtil.HYB_XF)){
467
            if(name.getHybridChildRelations().isEmpty()){
468
                RedListUtil.logMessage(id, "Hybrid formula but no hybrid child relations: "+name.getTitleCache(), logger);
469
                return;
470
            }
471
            return;
472
        }
473

  
471 474
        if(CdmUtils.isNotBlank(zusatzString)){
472 475
            authorString = authorString.replace(", "+zusatzString, "");
473 476
        }
......
492 495
        }
493 496
    }
494 497

  
495
    private void checkTaxonNameConsistency(long id, String taxNameString, String hybString, TaxonBase<?> taxonBase) {
496
        if(hybString.equals(RedListUtil.HYB_XF)){
497
            if(HibernateProxyHelper.deproxy(taxonBase.getName(),NonViralName.class).getHybridChildRelations().isEmpty()){
498
                RedListUtil.logMessage(id, "Hybrid name but no hybrid child relations: "+taxonBase.getTitleCache(), logger);
499
                return;
500
            }
501
            return;
502
        }
503

  
504

  
498
    private void checkTaxonConsistency(long id, String taxNameString, String hybString, TaxonBase<?> taxonBase) {
505 499
        String nameCache = HibernateProxyHelper.deproxy(taxonBase.getName(), NonViralName.class).getNameCache().trim();
506 500
        taxNameString = taxNameString.trim();
507 501
        taxNameString.replaceAll(" +", " ");
......
521 515
            taxNameString = taxNameString.replace(" "+RedListUtil.HYB_SIGN, " x");
522 516
        }
523 517

  
524
        if(taxNameString.endsWith("- Gruppe")){String a ="Festuca ×xx Lolium <-> Festuca ×× Lolium";
518
        if(taxNameString.endsWith("- Gruppe")){
525 519
            taxNameString = taxNameString.replaceAll("- Gruppe", "species group");
526 520
        }
527 521
        if(taxNameString.endsWith("- group")){
......
531 525
        taxNameString = taxNameString.replace("[ranglos]", "[unranked]");
532 526
        if(STRICT_TITLE_CHECK){
533 527
            if(!taxNameString.trim().equals(nameCache)){
534
                RedListUtil.logMessage(id, "Taxon name inconsistent! taxon.titleCache <-> Column "+RedListUtil.TAXNAME+": "+nameCache+" <-> "+taxNameString, logger);
528
                RedListUtil.logMessage(id, "Taxon name inconsistent! taxon.nameCache <-> Column "+RedListUtil.TAXNAME+": "+nameCache+" <-> "+taxNameString, logger);
535 529
            }
536 530
        }
537 531
        else{
538 532
            if(!taxNameString.startsWith(nameCache)){
539
                RedListUtil.logMessage(id, "Taxon name inconsistent! taxon.titleCache <-> Column "+RedListUtil.TAXNAME+": "+nameCache+" <-> "+taxNameString, logger);
533
                RedListUtil.logMessage(id, "Taxon name inconsistent! taxon.nameCache <-> Column "+RedListUtil.TAXNAME+": "+nameCache+" <-> "+taxNameString, logger);
540 534
            }
541 535
        }
542 536
    }

Also available in: Unified diff

Add picture from clipboard (Maximum size: 40 MB)