Project

General

Profile

Download (7.02 KB) Statistics
| Branch: | Revision:
1
/**
2
* Copyright (C) 2007 EDIT
3
* European Distributed Institute of Taxonomy
4
* http://www.e-taxonomy.eu
5
*
6
* The contents of this file are subject to the Mozilla Public License Version 1.1
7
* See LICENSE.TXT at the top of this package for the full license terms.
8
*/
9

    
10
package eu.etaxonomy.cdm.io.redlist;
11

    
12
import java.sql.ResultSet;
13
import java.sql.SQLException;
14
import java.util.HashMap;
15
import java.util.HashSet;
16
import java.util.Map;
17
import java.util.Set;
18
import java.util.UUID;
19

    
20
import org.apache.log4j.Logger;
21
import org.springframework.stereotype.Component;
22

    
23
import eu.etaxonomy.cdm.io.common.IOValidator;
24
import eu.etaxonomy.cdm.io.common.ResultSetPartitioner;
25
import eu.etaxonomy.cdm.io.common.mapping.DbImportMapping;
26
import eu.etaxonomy.cdm.io.common.mapping.IMappingImport;
27
import eu.etaxonomy.cdm.io.redlist.validation.RoteListeDbTaxonImportValidator;
28
import eu.etaxonomy.cdm.model.common.CdmBase;
29
import eu.etaxonomy.cdm.model.name.BotanicalName;
30
import eu.etaxonomy.cdm.model.name.Rank;
31
import eu.etaxonomy.cdm.model.name.TaxonNameFactory;
32
import eu.etaxonomy.cdm.model.taxon.Taxon;
33
import eu.etaxonomy.cdm.model.taxon.TaxonBase;
34
import eu.etaxonomy.cdm.strategy.parser.NonViralNameParserImpl;
35

    
36

    
37
/**
38
 * TODO do we still need this class?
39
 * @author a.mueller
40
 * @created 27.08.2012
41
 */
42
@Component
43
public class RoteListeDbTaxonImport  extends RoteListeDbImportBase<TaxonBase> implements IMappingImport<TaxonBase, RoteListeDbImportState>{
44
	@SuppressWarnings("unused")
45
	private static final Logger logger = Logger.getLogger(RoteListeDbTaxonImport.class);
46

    
47
	private NonViralNameParserImpl parser = NonViralNameParserImpl.NewInstance();
48

    
49
	private Map<UUID, Taxon> higherTaxonMap;
50

    
51
	private Integer TREE_ID = null;
52

    
53
	private DbImportMapping mapping;
54

    
55
	private int modCount = 10000;
56
	private static final String pluralString = "taxa";
57
	private static final String dbTableName = "checklist";
58
	private static final Class cdmTargetClass = TaxonBase.class;
59
	private static final String strOrderBy = " ORDER BY family, genus, species ";
60

    
61
	public RoteListeDbTaxonImport(){
62
		super(pluralString, dbTableName, cdmTargetClass);
63
	}
64

    
65

    
66
	@Override
67
	protected String getIdQuery() {
68
		String strQuery = " SELECT pk FROM " + dbTableName +
69
						strOrderBy;
70
		return strQuery;
71
	}
72

    
73
	@Override
74
	protected DbImportMapping getMapping() {
75
		if (mapping == null){
76
			mapping = new DbImportMapping();
77

    
78
// 			mapping.addMapper(DbImportObjectCreationMapper.NewInstance(this, "pk", TAXON_NAMESPACE)); //id + tu_status
79
//
80
//			UUID uuidKew = RoteListeDbTransformer.uuidAcceptedKew;
81
//			mapping.addMapper(DbImportMarkerMapper.NewInstance("accepted kew", uuidKew, "Accepted Kew", "Accepted Kew", "Kew", null));
82

    
83
		}
84

    
85
		return mapping;
86
	}
87

    
88
	@Override
89
	protected String getRecordQuery(RoteListeDbImportConfigurator config) {
90
		String strSelect = " SELECT * ";
91
		String strFrom = " FROM checklist";
92
		String strWhere = " WHERE ( pk IN (" + ID_LIST_TOKEN + ") )";
93
		String strRecordQuery = strSelect + strFrom + strWhere + strOrderBy;
94
		return strRecordQuery;
95
	}
96

    
97

    
98
	@Override
99
	public boolean doPartition(ResultSetPartitioner partitioner, RoteListeDbImportState state) {
100
		boolean success = super.doPartition(partitioner, state);
101
//		higherTaxonMap = new HashMap<UUID, Taxon>();
102
//		state.setGenevaReference(null);
103
		return success;
104
	}
105

    
106

    
107
	@Override
108
	public Map<Object, Map<String, ? extends CdmBase>> getRelatedObjectsForPartition(ResultSet rs, RoteListeDbImportState state) {
109
		String nameSpace;
110
		Class<?> cdmClass;
111
		Set<String> idSet;
112
		Set<String> referenceIdSet = new HashSet<String>();
113

    
114
		Map<Object, Map<String, ? extends CdmBase>> result = new HashMap<Object, Map<String, ? extends CdmBase>>();
115

    
116
		try{
117
			while (rs.next()){
118
				handleForeignKey(rs, referenceIdSet, "source");
119
			}
120

    
121
//			//reference map
122
//			nameSpace = REFERENCE_NAMESPACE;
123
//			cdmClass = Reference.class;
124
//			idSet = referenceIdSet;
125
//			Map<String, Reference> referenceMap = (Map<String, Reference>)getCommonService().getSourcedObjectsByIdInSource(cdmClass, referenceIdSet, nameSpace);
126
//			result.put(REFERENCE_NAMESPACE, referenceMap);
127

    
128
		} catch (SQLException e) {
129
			throw new RuntimeException(e);
130
		}
131
		return result;
132
	}
133

    
134

    
135
	@Override
136
	public TaxonBase createObject(ResultSet rs, RoteListeDbImportState state) throws SQLException {
137
		BotanicalName speciesName = TaxonNameFactory.NewBotanicalInstance(Rank.SPECIES());
138

    
139
//		Reference sec = state.getConfig().getSourceReference();
140
//		getReferenceService().saveOrUpdate(sec);
141
//
142
//		String familyString = rs.getString("family");
143
//		String genusString = rs.getString("genus");
144
//		String speciesString = rs.getString("species");
145
//		String authorityString = rs.getString("authority");
146
//
147
//		if (logger.isDebugEnabled()){
148
//			System.out.println(familyString + " " + genusString + " " + speciesString);
149
//		}
150
//
151
//		Taxon speciesTaxon = Taxon.NewInstance(speciesName, sec);;
152
//		speciesName.setGenusOrUninomial(genusString);
153
//		speciesName.setSpecificEpithet(speciesString);
154
//		parser.handleAuthors(speciesName, CdmUtils.concat(" ", new String[] {"", genusString, speciesString, authorityString}), authorityString);
155
//
156
//		//family
157
//		Taxon familyTaxon = null;
158
//		if (StringUtils.isNotBlank(familyString)){
159
//			familyTaxon = getHigherTaxon(state, familyString, null);
160
//			if (familyTaxon == null){
161
//				BotanicalName familyName = TaxonNameFactory.NewBotanicalInstance(Rank.FAMILY());
162
//				familyName.setGenusOrUninomial(familyString);
163
//				familyTaxon = Taxon.NewInstance(familyName, sec);
164
//				saveHigherTaxon(state, familyTaxon, familyString, null);
165
//			}
166
//			getTaxonService().saveOrUpdate(familyTaxon);
167
//		}
168
//
169
//
170
//		//genus
171
//		Taxon genusTaxon = getHigherTaxon(state, familyString, genusString);
172
//		if (genusTaxon == null){
173
//			BotanicalName genusName = TaxonNameFactory.NewBotanicalInstance(Rank.GENUS());
174
//			genusName.setGenusOrUninomial(genusString);
175
//			genusTaxon = Taxon.NewInstance(genusName, sec);
176
//			saveHigherTaxon(state, genusTaxon, familyString, genusString);
177
//			if (familyTaxon != null){
178
//				makeTaxonomicallyIncluded(state, TREE_ID, genusTaxon, familyTaxon, null, null);
179
//			}
180
//		}
181
//		makeTaxonomicallyIncluded(state, TREE_ID, speciesTaxon, genusTaxon, null, null);
182
//		getTaxonService().saveOrUpdate(genusTaxon);
183
//
184
//		String sourceString = rs.getString("source");
185
//		String sourceId = rs.getString("source_id");
186
//
187
//		Reference sourceRef = state.getRelatedObject(REFERENCE_NAMESPACE, sourceString, Reference.class);
188
//		speciesTaxon.addSource(sourceId, REFERENCE_NAMESPACE, sourceRef, null);
189
//
190
//
191
//		//distribution
192
//		handleDistribution(rs, speciesTaxon);
193
//
194
//		return speciesTaxon;
195

    
196
		return null;
197
	}
198

    
199

    
200
	@Override
201
	protected boolean doCheck(RoteListeDbImportState state){
202
		IOValidator<RoteListeDbImportState> validator = new RoteListeDbTaxonImportValidator();
203
		return validator.validate(state);
204
	}
205

    
206

    
207
	@Override
208
	protected boolean isIgnore(RoteListeDbImportState state){
209
		return ! state.getConfig().isDoTaxa();
210
	}
211

    
212

    
213

    
214
}
(4-4/5)