Project

General

Profile

Revision 6d5513e4

ID6d5513e475bc36ff4ffc2604a4bfa25c987eb6e3
Parent 7af2531f
Child 637814c1

Added by Andreas Müller about 7 years ago

fix not running ABCD import test, still needs further fixing for OriginalSource handling

View differences:

cdmlib-io/src/main/java/eu/etaxonomy/cdm/io/specimen/abcd206/in/Abcd206Import.java
32 32

  
33 33
import eu.etaxonomy.cdm.api.application.ICdmApplicationConfiguration;
34 34
import eu.etaxonomy.cdm.api.facade.DerivedUnitFacade;
35
import eu.etaxonomy.cdm.common.CdmUtils;
35 36
import eu.etaxonomy.cdm.common.UriUtils;
36 37
import eu.etaxonomy.cdm.io.specimen.SpecimenImportBase;
37 38
import eu.etaxonomy.cdm.io.specimen.SpecimenUserInteraction;
......
400 401
                IdentifiableSource sour = getIdentifiableSource(reference,citationDetail);
401 402

  
402 403
                try{
403
                    if(sour.getCitationMicroReference() !=null && !sour.getCitationMicroReference().isEmpty()) {
404
                        dataHolder.docSources.add(sour.getCitation().getTitleCache()+ "---"+sour.getCitationMicroReference());
405
                    } else {
406
                        dataHolder.docSources.add(sour.getCitation().getTitleCache());
404
                    if (sour.getCitation() != null){ 
405
	                    if(StringUtils.isNotBlank(sour.getCitationMicroReference())) {
406
	                        dataHolder.docSources.add(sour.getCitation().getTitleCache()+ "---"+sour.getCitationMicroReference());
407
	                    } else {
408
	                        dataHolder.docSources.add(sour.getCitation().getTitleCache());
409
	                    }
407 410
                    }
408 411
                }catch(Exception e){
409 412
                    logger.warn("oups");
410 413
                }
414
                //TODO what do we need tmp for?
411 415
                String tmp = sour.getCitation().getTitleCache();
412
                if (!sour.getCitationMicroReference().isEmpty()) {
413
                    tmp+=" ("+sour.getCitationMicroReference()+")";
416
                if (StringUtils.isNotBlank(sour.getCitationMicroReference())) {
417
                    tmp +=" ("+sour.getCitationMicroReference()+")";
414 418
                }
415 419
                reference.addSource(sour);
416 420
                getReferenceService().saveOrUpdate(reference);
......
518 522
     * @param citationDetail
519 523
     * @return
520 524
     */
525
    //FIXME this method is highly critical, because
526
    //  * it will have serious performance and memory problems with large databases
527
    //        (databases may easily have >1 Mio source records)
528
    //  * it does not make sense to search for existing sources and then clone them
529
    //    we need to search for existing references instead and use them (if exist) 
530
    //    for our new source.
521 531
    private IdentifiableSource getIdentifiableSource(Reference<?> reference, String citationDetail) {
522 532

  
523 533
        List<OriginalSourceBase> issTmp = getCommonService().list(IdentifiableSource.class, null, null, null, null);
524 534

  
525

  
526
        try {
527
            for (OriginalSourceBase<?> osb:issTmp){
528
                if (osb.getCitation().getTitleCache().equalsIgnoreCase(reference.getTitleCache())
529
                        && osb.getCitationMicroReference().equalsIgnoreCase(citationDetail)) {
530
                    System.out.println("REFERENCE FOUND RETURN EXISTING SOURCE");
531
                    return (IdentifiableSource) osb.clone();
532
                }
533
            }
534
        } catch (CloneNotSupportedException e) {
535
            // TODO Auto-generated catch block
536
            e.printStackTrace();
537
        }
538

  
535
        
536
        if (reference != null){
537
        	try {
538
	        	for (OriginalSourceBase<?> osb: issTmp){
539
	                if (osb.getCitation() != null && osb.getCitation().getTitleCache().equalsIgnoreCase(reference.getTitleCache())){
540
	                	String osbDetail = osb.getCitationMicroReference();
541
	                	if (StringUtils.isBlank(osbDetail) && StringUtils.isBlank(citationDetail)
542
	                			|| osbDetail != null && osbDetail.equalsIgnoreCase(citationDetail) ) {
543
		                    System.out.println("REFERENCE FOUND RETURN EXISTING SOURCE");
544
		                    return (IdentifiableSource) osb.clone();
545
	                	}
546
	                }
547
	            }
548
	        } catch (CloneNotSupportedException e) {
549
	            throw new RuntimeException(e);
550
	        } catch (Exception e1){
551
	        	e1.printStackTrace();
552
	        }
553
        }
554
        	
539 555
        IdentifiableSource sour = IdentifiableSource.NewInstance(OriginalSourceType.Import,null,null, reference,citationDetail);
540 556
        return sour;
541 557
    }

Also available in: Unified diff

Add picture from clipboard (Maximum size: 40 MB)