Project

General

Profile

« Previous | Next » 

Revision 1437e192

Added by Andreas Müller almost 5 years ago

ref #8509 improve isPesi taxon handling for export

View differences:

cdm-pesi/src/main/java/eu/etaxonomy/cdm/io/pesi/out/PesiExportBase.java
340 340
	    //handle accepted taxa
341 341
		if (taxonBase.isInstanceOf(Taxon.class)){
342 342
			Taxon taxon = CdmBase.deproxy(taxonBase, Taxon.class);
343
			if (! taxon.isPublish()){
344
				taxon = null;
345
				return false;
346
			}
347
			for (Marker marker : taxon.getMarkers()){
348
				//probably not needed anymore after #1780 was fixed, also #4046 interesting
349
				if (marker.getValue() == false && marker.getMarkerType().equals(MarkerType.PUBLISH())){
350
					taxon = null;
351
					return false;
352
				//probably not needed any more after #2786 was fixed
353
				}else if (marker.getValue() == true && marker.getMarkerType().getUuid().equals(BerlinModelTransformer.uuidMisappliedCommonName)){
354
					logger.warn("Misapplied common name still exists");
355
					taxon = null;
356
					return false;
357
				}
358
			}
359

  
360
			//handle PESI accepted taxa
361
			if (! taxon.isMisapplication()){
362
				for (Marker marker : taxon.getMarkers()){
363
					if (marker.getValue() == false && marker.getMarkerType().equals(MarkerType.PUBLISH())){
364
						taxon = null;
365
						return false;
366
					}
367
				}
368
				return true;
369
			//handle misapplied names
370
			}else{
371
				if (excludeMisappliedNames){
372
					taxon = null;
373
					return false;
374
				}
375
				for (Marker marker : taxon.getMarkers()){
376
					//probably not needed any more after #2786 was fixed
377
					if (marker.getValue() == true && marker.getMarkerType().getUuid().equals(BerlinModelTransformer.uuidMisappliedCommonName)){
378
						logger.warn("Misapplied common name still exists");
379
						taxon = null;
380
						return false;
381
					}
382
				}
383
				for (TaxonRelationship taxRel : taxon.getRelationsFromThisTaxon()){
384
					if (taxRel.getType().equals(TaxonRelationshipType.MISAPPLIED_NAME_FOR())){
385
//						logger.warn(taxRel.getUuid() + "; " + taxRel.getToTaxon().getUuid() + " + " + taxRel.getToTaxon().getTitleCache());
386
						if (isPesiTaxon(taxRel.getToTaxon(), true)){
387
							taxon = null;
388
							return true;
389
						}
390
					}
391
				}
392
				if (logger.isDebugEnabled()){ logger.debug("Misapplied name has no accepted PESI taxon: " +  taxon.getUuid() + ", (" +  taxon.getTitleCache() + ")");}
393
				taxon = null;
394
				return false;
395
			}
343
			return isPesiAcceptedTaxon(excludeMisappliedNames, taxon);
396 344
		//handle synonyms
397 345
		}else if (taxonBase.isInstanceOf(Synonym.class)){
398 346
			Synonym synonym = CdmBase.deproxy(taxonBase, Synonym.class);
399
			boolean hasAcceptedPesiTaxon = false;
400
			hasAcceptedPesiTaxon = isPesiTaxon(synonym.getAcceptedTaxon());
401

  
402
			if (!hasAcceptedPesiTaxon) {if (logger.isDebugEnabled()){logger.debug("Synonym has no accepted PESI taxon: " +  synonym.getUuid() + ", (" +  synonym.getTitleCache() + ")");}}
403
			synonym = null;
404
			return hasAcceptedPesiTaxon;
347
			return isPesiSynonym(synonym);
405 348
		}else {
406 349
			throw new RuntimeException("Unknown taxon base type: " + taxonBase.getClass());
407 350
		}
408 351
	}
409 352

  
353
    private static boolean isPesiSynonym(Synonym synonym) {
354
        boolean hasAcceptedPesiTaxon = false;
355
        hasAcceptedPesiTaxon = isPesiTaxon(synonym.getAcceptedTaxon());
356

  
357
        if (!hasAcceptedPesiTaxon) {if (logger.isDebugEnabled()){logger.debug("Synonym has no accepted PESI taxon: " +  synonym.getUuid() + ", (" +  synonym.getTitleCache() + ")");}}
358
        synonym = null;
359
        return hasAcceptedPesiTaxon;
360
    }
361

  
362
    private static boolean isPesiAcceptedTaxon(boolean excludeMisappliedNames, Taxon taxon) {
363
        if (! taxon.isPublish()){
364
        	taxon = null;
365
        	return false;
366
        }
367
        for (Marker marker : taxon.getMarkers()){
368
        	//probably not needed anymore after #1780 was fixed, also #4046 interesting
369
        	if (marker.getValue() == false && marker.getMarkerType().equals(MarkerType.PUBLISH())){
370
        		taxon = null;
371
        		return false;
372
        	//probably not needed any more after #2786 was fixed
373
        	}else if (marker.getValue() == true && marker.getMarkerType().getUuid().equals(BerlinModelTransformer.uuidMisappliedCommonName)){
374
        		logger.warn("Misapplied common name still exists");
375
        		taxon = null;
376
        		return false;
377
        	}
378
        }
379

  
380
        //handle PESI accepted taxa
381
        if (! taxon.isMisapplication()){
382
        	for (Marker marker : taxon.getMarkers()){
383
        		if (marker.getValue() == false && marker.getMarkerType().equals(MarkerType.PUBLISH())){
384
        			taxon = null;
385
        			return false;
386
        		}
387
        	}
388
        	return true;
389
        //handle misapplied names
390
        }else{
391
        	if (excludeMisappliedNames){
392
        		taxon = null;
393
        		return false;
394
        	}
395
        	for (Marker marker : taxon.getMarkers()){
396
        		//probably not needed any more after #2786 was fixed
397
        		if (marker.getValue() == true && marker.getMarkerType().getUuid().equals(BerlinModelTransformer.uuidMisappliedCommonName)){
398
        			logger.warn("Misapplied common name still exists");
399
        			taxon = null;
400
        			return false;
401
        		}
402
        	}
403
        	for (TaxonRelationship taxRel : taxon.getRelationsFromThisTaxon()){
404
        		if (taxRel.getType().equals(TaxonRelationshipType.MISAPPLIED_NAME_FOR())){
405
//						logger.warn(taxRel.getUuid() + "; " + taxRel.getToTaxon().getUuid() + " + " + taxRel.getToTaxon().getTitleCache());
406
        			if (isPesiTaxon(taxRel.getToTaxon(), true)){
407
        				taxon = null;
408
        				return true;
409
        			}
410
        		}
411
        	}
412
        	if (logger.isDebugEnabled()){ logger.debug("Misapplied name has no accepted PESI taxon: " +  taxon.getUuid() + ", (" +  taxon.getTitleCache() + ")");}
413
        	taxon = null;
414
        	return false;
415
        }
416
    }
417

  
410 418
	@Override
411 419
    protected Object getDbIdCdmWithExceptions(CdmBase cdmBase, PesiExportState state) {
412 420
		if (cdmBase.isInstanceOf(TaxonName.class)){

Also available in: Unified diff