Project

General

Profile

Revision 8409d645

ID8409d645d7c224ddbc13e2b5a0a4aabdb6dae05b
Parent c1ae6714
Child 2211afa4

Added by Katja Luther over 3 years ago

fix siblings import and source reference import

View differences:

cdmlib-io/src/main/java/eu/etaxonomy/cdm/io/specimen/UnitsGatheringEvent.java
11 11

  
12 12

  
13 13
import java.util.HashMap;
14
import java.util.List;
15 14
import java.util.Map;
16 15
import java.util.UUID;
17 16

  
......
20 19

  
21 20
import eu.etaxonomy.cdm.api.service.IAgentService;
22 21
import eu.etaxonomy.cdm.api.service.ITermService;
23
import eu.etaxonomy.cdm.hibernate.HibernateProxyHelper;
24 22
import eu.etaxonomy.cdm.io.specimen.abcd206.in.Abcd206ImportConfigurator;
25 23
import eu.etaxonomy.cdm.io.specimen.excel.in.SpecimenSynthesysExcelImportConfigurator;
26 24
import eu.etaxonomy.cdm.io.taxonx2013.TaxonXImportConfigurator;
......
128 126
     * @param langageIso
129 127
     */
130 128
    public void setLocality(ITermService termService, String locality, String languageIso){
129

  
131 130
        LanguageString loc = null;
132
        List<LanguageString> languages = termService.getAllLanguageStrings(0, 0);
133
        boolean locFound=false;
134
        if ((languageIso == null) || (termService.getLanguageByIso(languageIso) == null)){
135
            //            if (languageIso != null && termService.getLanguageByIso(languageIso) == null ){
136
            //                logger.info("unknown iso used for the locality: "+languageIso);
137
            //            }
138
            for (LanguageString ls:languages){
139
                if (ls == null) {
140
                    continue;
141
                }
142
                ls = HibernateProxyHelper.deproxy(ls, LanguageString.class);
143
                if (ls.getText() == null){
144
                    continue;
145
                }
146
                if (ls.getText().equalsIgnoreCase(locality)){
147
                    loc=ls;
148
                    locFound=true;
149
                    //                    System.out.println("REUSE LOCALITY");
150
                }
151
            }
152
            if (!locFound){
153
                loc = LanguageString.NewInstance(locality, Language.DEFAULT());
154
                termService.saveLanguageData(loc);
155
                languages.add(loc);
156
            }
131
        if (languageIso == null){
132
            loc = LanguageString.NewInstance(locality, Language.DEFAULT());
157 133
        }else{
158
            for (LanguageString ls:languages){
159
                if (ls.getText().equalsIgnoreCase(locality) && ls.getLanguage().equals(termService.getLanguageByIso(languageIso))){
160
                    loc=ls;
161
                    locFound=true;
162
                    //                    System.out.println("REUSE LOCALITY");
163
                }
164
            }
165
            if (!locFound) {
166
                loc = LanguageString.NewInstance(locality, termService.getLanguageByIso(languageIso));
167
                termService.saveLanguageData(loc);
168
                languages.add(loc);
169
            }
134
            loc = LanguageString.NewInstance(locality, termService.getLanguageByIso(languageIso));
170 135
        }
136

  
137

  
171 138
        if (loc == null){logger.warn("PROBLEM LOCALITY");}
172 139
        this.gatheringEvent.setLocality(loc);
173 140
    }
cdmlib-io/src/main/java/eu/etaxonomy/cdm/io/specimen/abcd206/in/Abcd206Import.java
14 14
import java.net.URI;
15 15
import java.util.ArrayList;
16 16
import java.util.HashMap;
17
import java.util.HashSet;
18 17
import java.util.List;
19 18
import java.util.Map;
20 19
import java.util.Set;
......
50 49
import eu.etaxonomy.cdm.model.common.LanguageString;
51 50
import eu.etaxonomy.cdm.model.common.OriginalSourceBase;
52 51
import eu.etaxonomy.cdm.model.common.OriginalSourceType;
53
import eu.etaxonomy.cdm.model.description.DescriptionElementSource;
54 52
import eu.etaxonomy.cdm.model.location.NamedArea;
55 53
import eu.etaxonomy.cdm.model.media.Media;
56 54
import eu.etaxonomy.cdm.model.molecular.DnaSample;
......
165 163
                    if (state.getRef() == null){
166 164
                        state.setRef(ReferenceFactory.newGeneric());
167 165
                        state.getRef().setTitle("ABCD classic");
166
                        state.getRef().setUri(sourceUri);
168 167
                    }
169 168
                }
170 169
            //}
......
645 644
                    reference.setTitle(strReference);
646 645
                }
647 646

  
648
                IdentifiableSource sour = getIdentifiableSource(reference,citationDetail);
649 647

  
648
                save(reference, state);
649
                IdentifiableSource sour = getIdentifiableSource(reference, citationDetail);
650
                sour.setType(OriginalSourceType.PrimaryTaxonomicSource);
650 651
                try{
651 652
                    if (sour.getCitation() != null){
652 653
                        if(StringUtils.isNotBlank(sour.getCitationMicroReference())) {
......
658 659
                }catch(Exception e){
659 660
                    logger.warn("oups");
660 661
                }
661
                reference.addSource(sour);
662
                save(reference, state);
663
            }
664
            List<IdentifiableSource> issTmp = new ArrayList<IdentifiableSource>();//getCommonService().list(IdentifiableSource.class, null, null, null, null);
665
            List<DescriptionElementSource> issTmp2 = new ArrayList<DescriptionElementSource>();//getCommonService().list(DescriptionElementSource.class, null, null, null, null);
662
                derivedUnitFacade.addSource(sour);
666 663

  
667
            Set<OriginalSourceBase> osbSet = new HashSet<OriginalSourceBase>();
668
            if(issTmp2!=null) {
669
                osbSet.addAll(issTmp2);
670
            }
671
            if(issTmp!=null) {
672
                osbSet.addAll(issTmp);
673 664
            }
674

  
675
            addToSourceMap(sourceMap, osbSet);
676

  
677
            if( state.getConfig().isInteractWithUser()){
678
                List<OriginalSourceBase<?>>sources=null;
679
                if(!state.isDerivedUnitSourcesSet()){
680
                    sources= sui.askForSource(sourceMap, "the unit itself","",getReferenceService(), state.getDataHolder().getDocSources());
681
                    state.setDerivedUnitSources(sources);
682
                    state.setDerivedUnitSourcesSet(true);
683
                }
684
                else{
685
                    sources=state.getDerivedUnitSources();
686
                }
687
                for (OriginalSourceBase<?> sour:sources){
688
                    if(sour.isInstanceOf(IdentifiableSource.class)){
689
                        if(sourceNotLinkedToElement(derivedUnitFacade,sour)) {
690
                            derivedUnitFacade.addSource((IdentifiableSource)sour.clone());
691
                        }
692
                    }else{
693
                        if(sourceNotLinkedToElement(derivedUnitFacade,sour)) {
694
                            derivedUnitFacade.addSource(OriginalSourceType.Import,sour.getCitation(),sour.getCitationMicroReference(), ioName);
695
                        }
696
                    }
697
                }
698
            }else{
699
                for (OriginalSourceBase<?> sr : sourceMap.values()){
700
                    if(sr.isInstanceOf(IdentifiableSource.class)){
701
                        if(sourceNotLinkedToElement(derivedUnitFacade,sr)) {
702
                            derivedUnitFacade.addSource((IdentifiableSource)sr.clone());
703
                        }
704
                    }else{
705
                        if(sourceNotLinkedToElement(derivedUnitFacade,sr)) {
706
                            derivedUnitFacade.addSource(OriginalSourceType.Import,sr.getCitation(),sr.getCitationMicroReference(), ioName);
707
                        }
665
//            List<IdentifiableSource> issTmp = new ArrayList<IdentifiableSource>();//getCommonService().list(IdentifiableSource.class, null, null, null, null);
666
//            List<DescriptionElementSource> issTmp2 = new ArrayList<DescriptionElementSource>();//getCommonService().list(DescriptionElementSource.class, null, null, null, null);
667
//
668
//            Set<OriginalSourceBase> osbSet = new HashSet<OriginalSourceBase>();
669
//            if(issTmp2!=null) {
670
//                osbSet.addAll(issTmp2);
671
//            }
672
//            if(issTmp!=null) {
673
//                osbSet.addAll(issTmp);
674
//            }
675
            IdentifiableSource sour = getIdentifiableSource(state.getRef(),null);
676
            String idInSource = derivedUnitFacade.getAccessionNumber() != null? derivedUnitFacade.getAccessionNumber():derivedUnitFacade.getCatalogNumber();
677
            sour.getCitation().setUri(state.getActualAccessPoint());
678
            sour.setIdInSource(idInSource);
679
            try{
680
                if (sour.getCitation() != null){
681
                    if(StringUtils.isNotBlank(sour.getCitationMicroReference())) {
682
                        state.getDataHolder().getDocSources().add(sour.getCitation().getTitleCache()+ "---"+sour.getCitationMicroReference());
683
                    } else {
684
                        state.getDataHolder().getDocSources().add(sour.getCitation().getTitleCache());
708 685
                    }
709 686
                }
687
            }catch(Exception e){
688
                logger.warn("oups");
710 689
            }
711 690

  
691
           derivedUnitFacade.addSource(sour);
692
          // sourceMap.put(sour.getCitation().getTitleCache()+ "---"+sour.getCitationMicroReference(),sour);
693

  
694
//            if( state.getConfig().isInteractWithUser()){
695
//                List<OriginalSourceBase<?>>sources=null;
696
//                if(!state.isDerivedUnitSourcesSet()){
697
//                    sources= sui.askForSource(sourceMap, "the unit itself","",getReferenceService(), state.getDataHolder().getDocSources());
698
//                    state.setDerivedUnitSources(sources);
699
//                    state.setDerivedUnitSourcesSet(true);
700
//                }
701
//                else{
702
//                    sources=state.getDerivedUnitSources();
703
//                }
704
////                for (OriginalSourceBase<?> source:sources){
705
////                    if(source.isInstanceOf(IdentifiableSource.class)){
706
////                        if(sourceNotLinkedToElement(derivedUnitFacade,source)) {
707
////                            derivedUnitFacade.addSource((IdentifiableSource)source.clone());
708
////                        }
709
////                    }else{
710
////                        if(sourceNotLinkedToElement(derivedUnitFacade,sour)) {
711
////                            derivedUnitFacade.addSource(OriginalSourceType.Import,source.getCitation(),source.getCitationMicroReference(), ioName);
712
////                        }
713
////                    }
714
////                }
715
//            }else{
716
//                for (OriginalSourceBase<?> sr : sourceMap.values()){
717
//                    if(sr.isInstanceOf(IdentifiableSource.class)){
718
//                        if(sourceNotLinkedToElement(derivedUnitFacade,sr)) {
719
//                            derivedUnitFacade.addSource((IdentifiableSource)sr.clone());
720
//                        }
721
//                    }else{
722
//                        if(sourceNotLinkedToElement(derivedUnitFacade,sr)) {
723
//                            derivedUnitFacade.addSource(OriginalSourceType.Import,sr.getCitation(),sr.getCitationMicroReference(), ioName);
724
//                        }
725
//                    }
726
//                }
727
//            }
728

  
712 729
            save(state.getDerivedUnitBase(), state);
713 730

  
714 731
            if(logger.isDebugEnabled()) {
......
761 778
                    Element unitAssociation = (Element)unitAssociationList.item(k);
762 779
                    UnitAssociationParser unitAssociationParser = new UnitAssociationParser(currentPrefix, state.getReport(), state.getCdmRepository());
763 780
                    UnitAssociationWrapper associationWrapper = unitAssociationParser.parse(unitAssociation);
764
                    state.addActualAccesPoint(associationWrapper.getAccesPoint());
781
                    state.setActualAccessPoint(associationWrapper.getAccesPoint());
765 782
                    if(associationWrapper!=null){
766 783
                        NodeList associatedUnits = associationWrapper.getAssociatedUnits();
767 784
                        if(associatedUnits!=null){
......
835 852
                                            ){
836 853
                                        currentFieldUnit.removeDerivationEvent(currentDerivedFrom);
837 854
                                        state.getCdmRepository().getOccurrenceService().delete(currentFieldUnit);
838
                                    }
855
                                         }
839 856

  
840 857
                                    save(associatedUnit, state);
841 858
                                }
cdmlib-io/src/main/java/eu/etaxonomy/cdm/io/specimen/abcd206/in/Abcd206ImportState.java
35 35

  
36 36
	private List<String[]> associatedUnitIds = new ArrayList<String[]>();
37 37

  
38
	private Set<URI> actualAccesPoints = new HashSet<>();
38
	private Set<URI> allAccesPoints = new HashSet<>();
39

  
40
	private URI actualAccessPoint;
39 41

  
40 42

  
41 43
//****************** CONSTRUCTOR ***************************************************/
......
88 90
     * @return the actualAccesPoint
89 91
     */
90 92
    public Set<URI> getActualAccesPoint() {
91
        return actualAccesPoints;
93
        return allAccesPoints;
92 94
    }
93 95

  
94 96
    /**
95 97
     * @param actualAccesPoint the actualAccesPoint to set
96 98
     */
97 99
    public void addActualAccesPoint(URI actualAccesPoint) {
98
        this.actualAccesPoints.add(actualAccesPoint);
100
        this.allAccesPoints.add(actualAccesPoint);
101
    }
102

  
103
    /**
104
     * @return the actualAccessPoint
105
     */
106
    public URI getActualAccessPoint() {
107
        return actualAccessPoint;
108
    }
109

  
110
    /**
111
     * @param actualAccessPoint the actualAccessPoint to set
112
     */
113
    public void setActualAccessPoint(URI actualAccessPoint) {
114
        this.addActualAccesPoint(actualAccessPoint);
115
        this.actualAccessPoint = actualAccessPoint;
99 116
    }
100 117

  
101 118
//
cdmlib-io/src/main/java/eu/etaxonomy/cdm/io/specimen/abcd206/in/Abcd206XMLFieldGetter.java
297 297
        NodeList results, reference;
298 298
        results = result.getChildNodes();
299 299
        boolean referencefound = false;
300
        String[] refDetails =new String[3];;
300
        String[] refDetails =new String[3];
301

  
301 302
        for (int k = 0; k < results.getLength(); k++) {
303
            System.out.println(results.item(k).getNodeName());
304
            System.out.println(results.item(k).getTextContent());
302 305
            if (results.item(k).getNodeName().equals(prefix + "SourceReference")) {
303 306
                reference = results.item(k).getChildNodes();
304 307
                for (int l = 0; l < reference.getLength(); l++) {
cdmlib-io/src/main/java/eu/etaxonomy/cdm/io/specimen/abcd206/in/UnitAssociationParser.java
146 146
                        report.addException(exceptionMessage, e);
147 147
                    }
148 148

  
149
                    if(unitAssociationWrapper!=null){
150 149

  
151
                        if(unitAssociationWrapper.getAssociatedUnits()!=null && unitAssociationWrapper.getAssociatedUnits().getLength()>1){
152
                            String moreThanOneUnitFoundMessage = String.format("More than one unit was found for unit association to %s", unitID);
153
                            logger.warn(moreThanOneUnitFoundMessage);
154
                            report.addInfoMessage(moreThanOneUnitFoundMessage);
155
                        }
156

  
157
                    }
158 150
                    return unitAssociationWrapper;
159 151
                    }
160 152
                    else{

Also available in: Unified diff

Add picture from clipboard (Maximum size: 40 MB)