Project

General

Profile

« Previous | Next » 

Revision a4e75107

Added by Katja Luther almost 8 years ago

View differences:

.gitattributes
392 392
cdm-pesi/src/main/java/eu/etaxonomy/cdm/io/pesi/indexFungorum/IndexFungorumImportConfigurator.java -text
393 393
cdm-pesi/src/main/java/eu/etaxonomy/cdm/io/pesi/indexFungorum/IndexFungorumImportState.java -text
394 394
cdm-pesi/src/main/java/eu/etaxonomy/cdm/io/pesi/indexFungorum/IndexFungorumSpeciesImport.java -text
395
cdm-pesi/src/main/java/eu/etaxonomy/cdm/io/pesi/indexFungorum/IndexFungorumSubSpeciesImport.java -text
395 396
cdm-pesi/src/main/java/eu/etaxonomy/cdm/io/pesi/indexFungorum/IndexFungorumSupraGeneraImport.java -text
396 397
cdm-pesi/src/main/java/eu/etaxonomy/cdm/io/pesi/indexFungorum/IndexFungorumTransformer.java -text
397 398
cdm-pesi/src/main/java/eu/etaxonomy/cdm/io/pesi/merging/FaunaEuErmsMerging.java -text
cdm-pesi/src/main/java/eu/etaxonomy/cdm/io/pesi/indexFungorum/IndexFungorumSubSpeciesImport.java
1
package eu.etaxonomy.cdm.io.pesi.indexFungorum;
2

  
3
import java.sql.ResultSet;
4
import java.util.ArrayList;
5
import java.util.List;
6
import java.util.Map;
7
import java.util.UUID;
8

  
9
import org.apache.log4j.Logger;
10
import org.springframework.stereotype.Component;
11
import org.springframework.transaction.TransactionStatus;
12

  
13
import eu.etaxonomy.cdm.api.service.config.MatchingTaxonConfigurator;
14
import eu.etaxonomy.cdm.hibernate.HibernateProxyHelper;
15
import eu.etaxonomy.cdm.model.common.CdmBase;
16
import eu.etaxonomy.cdm.model.name.NonViralName;
17
import eu.etaxonomy.cdm.model.name.TaxonNameBase;
18
import eu.etaxonomy.cdm.model.taxon.Classification;
19
import eu.etaxonomy.cdm.model.taxon.Taxon;
20
import eu.etaxonomy.cdm.model.taxon.TaxonBase;
21

  
22
/**
23
 * @author k.luther
24
 * @created 19.08.2014
25
 */
26
@Component
27
public class IndexFungorumSubSpeciesImport extends IndexFungorumImportBase {
28
	private static final Logger logger = Logger.getLogger(IndexFungorumSpeciesImport.class);
29

  
30
	private static final String pluralString = "subSpecies";
31
	
32
	
33
	public IndexFungorumSubSpeciesImport(){
34
		super(pluralString, null, null);
35

  
36
	}
37
	
38
	public IndexFungorumSubSpeciesImport(String pluralString,
39
			String dbTableName, Class cdmTargetClass) {
40
		super(pluralString, dbTableName, cdmTargetClass);
41
		
42
	}
43

  
44
	@Override
45
	public Map<Object, Map<String, ? extends CdmBase>> getRelatedObjectsForPartition(
46
			ResultSet rs, IndexFungorumImportState state) {
47
		// TODO Auto-generated method stub
48
		return null;
49
	}
50

  
51
	@Override
52
	protected String getRecordQuery(IndexFungorumImportConfigurator config) {
53
		// TODO Auto-generated method stub
54
		return null;
55
	}
56

  
57
	@Override
58
	protected boolean doCheck(IndexFungorumImportState state) {
59
		// TODO Auto-generated method stub
60
		return false;
61
	}
62

  
63
	@Override
64
	protected boolean isIgnore(IndexFungorumImportState state) {
65
		// TODO Auto-generated method stub
66
		return false;
67
	}
68
	
69
	@Override
70
    protected void doInvoke(IndexFungorumImportState state){
71
		System.out.println("create infraspecific - specific relationship: " + state.getInfraspecificTaxaUUIDs().size() + " taxa");
72
		
73
		 List<String> propertyPaths = new ArrayList<String>();
74
         propertyPaths.add("taxonNodes.*");
75
         propertyPaths.add("taxonNodes.classification");
76
         propertyPaths.add("taxonNodes.childNodes.*");
77
         propertyPaths.add("taxonNodes.childNodes.taxon.*");
78
         propertyPaths.add("taxonNodes.parent.*");
79
         propertyPaths.add("taxonNodes.parent.taxon.*");
80
         Classification classification = getClassification(state);
81
        for (UUID infraspecificTaxonUUID: state.getInfraspecificTaxaUUIDs()){
82
        	TransactionStatus txStatus = startTransaction();
83
        	Taxon infraspecificTaxon = (Taxon)getTaxonService().load(infraspecificTaxonUUID, propertyPaths);
84
            //HibernateProxyHelper.deproxy(infraspecificTaxon);
85
            TaxonNameBase name = infraspecificTaxon.getName();
86

  
87
            UUID uuid = getNameService().saveOrUpdate(name);
88
            String parentNameString = getParentNameInfraSpecific(name);
89
            System.out.println("Parent name string: " + parentNameString);
90
            MatchingTaxonConfigurator matchingConfig = new MatchingTaxonConfigurator();
91
            matchingConfig.setTaxonNameTitle(parentNameString);
92
           
93
            matchingConfig.setPropertyPath(propertyPaths);
94
            List<TaxonBase> potentialParents = getTaxonService().findTaxaByName(matchingConfig);
95
                    //Taxon.class, parentNameString + "sec. ", MatchMode.BEGINNING, , pageSize, pageNumber, orderHints, propertyPaths)
96
                    //.searchNames(String uninomial,String infraGenericEpithet, String specificEpithet, String infraspecificEpithet, Rank rank, Integer pageSize, Integer pageNumber, List<OrderHint> orderHints,
97
            if (potentialParents.size()>1){
98
                for (TaxonBase potentialParent:potentialParents){
99
                    if (potentialParent.getTitleCache().equals(parentNameString + " sec*")){
100
                        classification.addParentChild((Taxon)potentialParent, (Taxon)infraspecificTaxon, null, null);
101
                    }
102
                }
103
            }else if (!potentialParents.isEmpty()){
104
                Taxon parent = HibernateProxyHelper.deproxy(potentialParents.get(0), Taxon.class);
105
                Taxon child = (Taxon)getTaxonService().load(infraspecificTaxon.getUuid(), propertyPaths);
106
                classification.addParentChild(parent, child, null, null);
107
            } else{
108
                System.out.println("No parent for: " + name.getTitleCache());
109
            }
110
            getTaxonService().saveOrUpdate(infraspecificTaxon);
111
            commitTransaction(txStatus);
112
        }
113
	}
114
	/**
115
     * @param taxon
116
     * @return
117
     */
118
    private String getParentNameInfraSpecific(TaxonNameBase taxonName){
119
       NonViralName<NonViralName> name =  HibernateProxyHelper.deproxy(taxonName, NonViralName.class);
120
       String parentName = name.getGenusOrUninomial() + " " + name.getSpecificEpithet();
121

  
122
       return parentName;
123
    }
124

  
125
}

Also available in: Unified diff