Project

General

Profile

« Previous | Next » 

Revision e5920e99

Added by Katja Luther almost 8 years ago

View differences:

cdm-pesi/src/main/java/eu/etaxonomy/cdm/io/pesi/indexFungorum/IndexFungorumImportConfigurator.java
50 50
				, IndexFungorumHigherClassificationImport.class
51 51
				, IndexFungorumGeneraImport.class
52 52
				, IndexFungorumSpeciesImport.class
53
				, IndexFungorumSubSpeciesImport.class
53 54
				, IndexFungorumDistributionImport.class
54 55
		};	
55 56
	}
cdm-pesi/src/main/java/eu/etaxonomy/cdm/io/pesi/indexFungorum/IndexFungorumImportState.java
10 10

  
11 11
package eu.etaxonomy.cdm.io.pesi.indexFungorum;
12 12

  
13
import java.util.ArrayList;
13 14
import java.util.HashMap;
15
import java.util.HashSet;
16
import java.util.List;
14 17
import java.util.Map;
18
import java.util.Set;
19
import java.util.UUID;
15 20

  
16 21
import org.apache.log4j.Logger;
17 22

  
......
37 42
	private Map<Integer, Map<Integer,Rank>> rankMap;
38 43

  
39 44
	private Map<String, TaxonBase> speciesMap;
45
	
46
	private List<UUID> infraspecificTaxaUUIDs = new ArrayList<UUID>();
40 47

  
41 48

  
42 49

  
43 50

  
44
    public IndexFungorumImportState(IndexFungorumImportConfigurator config) {
51
    public List<UUID> getInfraspecificTaxaUUIDs() {
52
		return infraspecificTaxaUUIDs;
53
	}
54

  
55

  
56
	public void setInfraspecificTaxaUUIDs(List<UUID> infraspecificTaxaUUIDs) {
57
		this.infraspecificTaxaUUIDs = infraspecificTaxaUUIDs;
58
	}
59

  
60

  
61
	public IndexFungorumImportState(IndexFungorumImportConfigurator config) {
45 62
		super(config);
46 63
	}
47 64

  
cdm-pesi/src/main/java/eu/etaxonomy/cdm/io/pesi/indexFungorum/IndexFungorumSpeciesImport.java
40 40
import eu.etaxonomy.cdm.model.taxon.Classification;
41 41
import eu.etaxonomy.cdm.model.taxon.Taxon;
42 42
import eu.etaxonomy.cdm.model.taxon.TaxonBase;
43
import eu.etaxonomy.cdm.model.taxon.TaxonNode;
43 44
import eu.etaxonomy.cdm.strategy.parser.NonViralNameParserImpl;
44 45

  
45 46

  
......
53 54

  
54 55
	private static final String pluralString = "species";
55 56
	private static final String dbTableName = "[tblPESIfungi-IFdata]";
56
	private final Set<UUID> infraspecificTaxaUUIDs = new HashSet<UUID>();
57
	
57 58

  
58 59
	public IndexFungorumSpeciesImport(){
59 60
		super(pluralString, dbTableName, null);
......
89 90
	@Override
90 91
    protected void doInvoke(IndexFungorumImportState state){
91 92
        System.out.println("start make " + getPluralString() + " ...");
92
        IndexFungorumImportConfigurator config = state.getConfig();
93
        Source source = config.getSource();
94

  
95 93
        super.doInvoke(state);
96
        Classification classification = getClassification(state);
97
        List<TaxonBase> infraspecificTaxa = new ArrayList<TaxonBase>();
98
        for (UUID uuid: infraspecificTaxaUUIDs){
99
            infraspecificTaxa.add(getTaxonService().load(uuid));
100
        }
101

  
102
        System.out.println("create infraspecific - specific relationship: " + infraspecificTaxa.size() + " taxa");
103
        for (TaxonBase infraspecificTaxon: infraspecificTaxa){
104
            HibernateProxyHelper.deproxy(infraspecificTaxon);
105
            TaxonNameBase name = infraspecificTaxon.getName();
106

  
107
            UUID uuid = getNameService().saveOrUpdate(name);
108
            String parentNameString = getParentNameInfraSpecific(name);
109
            System.out.println("Parent name string: " + parentNameString);
110
            MatchingTaxonConfigurator matchingConfig = new MatchingTaxonConfigurator();
111
            matchingConfig.setTaxonNameTitle(parentNameString);
112
            List<String> propertyPaths = new ArrayList<String>();
113
            propertyPaths.add("taxonNodes.*");
114
            propertyPaths.add("taxonNodes.classification");
115
            propertyPaths.add("taxonNodes.childNodes.*");
116
            propertyPaths.add("taxonNodes.childNodes.taxon.*");
117
            propertyPaths.add("taxonNodes.parent.*");
118
            propertyPaths.add("taxonNodes.parent.taxon.*");
119
            matchingConfig.setPropertyPath(propertyPaths);
120
            List<TaxonBase> potentialParents = getTaxonService().findTaxaByName(matchingConfig);
121
                    //Taxon.class, parentNameString + "sec. ", MatchMode.BEGINNING, , pageSize, pageNumber, orderHints, propertyPaths)
122
                    //.searchNames(String uninomial,String infraGenericEpithet, String specificEpithet, String infraspecificEpithet, Rank rank, Integer pageSize, Integer pageNumber, List<OrderHint> orderHints,
123
            if (potentialParents.size()>1){
124
                for (TaxonBase potentialParent:potentialParents){
125
                    if (potentialParent.getTitleCache().equals(parentNameString + " sec*")){
126
                        classification.addParentChild((Taxon)potentialParent, (Taxon)infraspecificTaxon, null, null);
127
                    }
128
                }
129
            }else if (!potentialParents.isEmpty()){
130
                Taxon parent = HibernateProxyHelper.deproxy(potentialParents.get(0), Taxon.class);
131
                Taxon child = (Taxon)getTaxonService().load(infraspecificTaxon.getUuid(), propertyPaths);
132
                classification.addParentChild(parent, child, null, null);
133
            } else{
134
                System.out.println("No parent for: " + name.getTitleCache());
135
            }
136
            getTaxonService().saveOrUpdate(infraspecificTaxon);
137
        }
94
        
95
       
138 96

  
139 97

  
140 98
	}
......
188 146
				//save
189 147

  
190 148
				UUID uuidTaxon = getTaxonService().saveOrUpdate(taxon);
191
				getNameService().saveOrUpdate(name);
149
				//getNameService().saveOrUpdate(name);
192 150
				if (name.isInfraSpecific()){
193
                    infraspecificTaxaUUIDs.add(uuidTaxon);
151
                    state.getInfraspecificTaxaUUIDs().add(uuidTaxon);
194 152
                }
195 153

  
196 154
			}
......
206 164
	}
207 165

  
208 166

  
209
	/**
210
     * @param taxon
211
     * @return
212
     */
213
    private String getParentNameInfraSpecific(TaxonNameBase taxonName){
214
       NonViralName<NonViralName> name =  HibernateProxyHelper.deproxy(taxonName, NonViralName.class);
215
       String parentName = name.getGenusOrUninomial() + " " + name.getSpecificEpithet();
216

  
217
       return parentName;
218
    }
167
	
219 168

  
220 169

  
221 170

  

Also available in: Unified diff