Project

General

Profile

« Previous | Next » 

Revision 8422c0cd

Added by Andreas Müller almost 8 years ago

Remove generics from Reference in cdmlib-app #5830

View differences:

cdm-eflora/src/main/java/eu/etaxonomy/cdm/io/eflora/centralAfrica/checklist/CentralAfricaChecklistTaxonImport.java
1 1
/**
2 2
* Copyright (C) 2007 EDIT
3
* European Distributed Institute of Taxonomy 
3
* European Distributed Institute of Taxonomy
4 4
* http://www.e-taxonomy.eu
5
* 
5
*
6 6
* The contents of this file are subject to the Mozilla Public License Version 1.1
7 7
* See LICENSE.TXT at the top of this package for the full license terms.
8 8
*/
......
56 56
@Component
57 57
public class CentralAfricaChecklistTaxonImport  extends CentralAfricaChecklistImportBase<TaxonBase> implements IMappingImport<TaxonBase, CentralAfricaChecklistImportState>{
58 58
	private static final Logger logger = Logger.getLogger(CentralAfricaChecklistTaxonImport.class);
59
	
59

  
60 60
	private NonViralNameParserImpl parser = NonViralNameParserImpl.NewInstance();
61
	
61

  
62 62
	private Map<UUID, Taxon> higherTaxonMap;
63
	
63

  
64 64
	private Integer TREE_ID = null;
65
	
65

  
66 66
	private DbImportMapping<?,?> mapping;
67
	
67

  
68 68
	private int modCount = 10000;
69 69
	private static final String pluralString = "taxa";
70 70
	private static final String dbTableName = "checklist";
......
74 74
	public CentralAfricaChecklistTaxonImport(){
75 75
		super(pluralString, dbTableName, cdmTargetClass);
76 76
	}
77
	
78
	
77

  
78

  
79 79

  
80 80
	/* (non-Javadoc)
81 81
	 * @see eu.etaxonomy.cdm.io.erms.ErmsImportBase#getIdQuery()
......
91 91
	/* (non-Javadoc)
92 92
	 * @see eu.etaxonomy.cdm.io.eflora.centralAfrica.checklist.CentralAfricaChecklistImportBase#getMapping()
93 93
	 */
94
	protected DbImportMapping getMapping() {
94
	@Override
95
    protected DbImportMapping getMapping() {
95 96
		if (mapping == null){
96 97
			mapping = new DbImportMapping();
97
			
98

  
98 99
 			mapping.addMapper(DbImportObjectCreationMapper.NewInstance(this, "pk", TAXON_NAMESPACE)); //id + tu_status
99
		
100

  
100 101
			UUID uuidKew = CentralAfricaChecklistTransformer.uuidAcceptedKew;
101 102
			mapping.addMapper(DbImportMarkerMapper.NewInstance("accepted kew", uuidKew, "Accepted Kew", "Accepted Kew", "Kew", null));
102
			
103

  
103 104
			UUID uuidGeneva = CentralAfricaChecklistTransformer.uuidAcceptedGeneva;
104 105
			mapping.addMapper(DbImportMarkerMapper.NewInstance("accepted geneva", uuidGeneva, "Accepted Geneva", "Accepted Geneva", "Geneva", null));
105 106

  
106 107
			UUID uuidItis = CentralAfricaChecklistTransformer.uuidAcceptedItis;
107 108
			mapping.addMapper(DbImportMarkerMapper.NewInstance("accepted itis", uuidItis, "Accepted ITIS", "Accepted ITIS", "ITIS", null));
108 109
		}
109
		
110

  
110 111
		return mapping;
111 112
	}
112 113

  
......
122 123
		return strRecordQuery;
123 124
	}
124 125

  
125
	
126

  
126 127
	@Override
127 128
	public boolean doPartition(ResultSetPartitioner partitioner, CentralAfricaChecklistImportState state) {
128 129
		higherTaxonMap = new HashMap<UUID, Taxon>();
......
145 146
		Class<?> cdmClass;
146 147
		Set<String> idSet;
147 148
		Set<String> referenceIdSet = new HashSet<String>();
148
		
149

  
149 150
		Map<Object, Map<String, ? extends CdmBase>> result = new HashMap<Object, Map<String, ? extends CdmBase>>();
150
		
151

  
151 152
		try{
152 153
			while (rs.next()){
153 154
				handleForeignKey(rs, referenceIdSet, "source");
......
165 166
		}
166 167
		return result;
167 168
	}
168
	
169

  
169 170
	@Override
170 171
	public TaxonBase<?> createObject(ResultSet rs, CentralAfricaChecklistImportState state) throws SQLException {
171 172
		BotanicalName speciesName = BotanicalName.NewInstance(Rank.SPECIES());
172
		
173
		Reference<?> sec = state.getConfig().getSourceReference();
173

  
174
		Reference sec = state.getConfig().getSourceReference();
174 175
		getReferenceService().saveOrUpdate(sec);
175
		
176

  
176 177
		String familyString = rs.getString("family");
177 178
		String genusString = rs.getString("genus");
178 179
		String speciesString = rs.getString("species");
179 180
		String authorityString = rs.getString("authority");
180
		
181

  
181 182
		if (logger.isDebugEnabled()){
182 183
			System.out.println(familyString + " " + genusString + " " + speciesString);
183 184
		}
184
		
185

  
185 186
		Taxon speciesTaxon = Taxon.NewInstance(speciesName, sec);;
186 187
		speciesName.setGenusOrUninomial(genusString);
187 188
		speciesName.setSpecificEpithet(speciesString);
188 189
		parser.handleAuthors(speciesName, CdmUtils.concat(" ", new String[] {"", genusString, speciesString, authorityString}), authorityString);
189
		
190

  
190 191
		//family
191 192
		Taxon familyTaxon = null;
192 193
		if (StringUtils.isNotBlank(familyString)){
......
197 198
				familyTaxon = Taxon.NewInstance(familyName, sec);
198 199
				saveHigherTaxon(state, familyTaxon, familyString, null);
199 200
			}
200
			getTaxonService().saveOrUpdate(familyTaxon);	
201
			getTaxonService().saveOrUpdate(familyTaxon);
201 202
		}
202
		
203
		
203

  
204

  
204 205
		//genus
205 206
		Taxon genusTaxon = getHigherTaxon(state, familyString, genusString);
206 207
		if (genusTaxon == null){
......
217 218

  
218 219
		String sourceString = rs.getString("source");
219 220
		String sourceId = rs.getString("source_id");
220
		
221
		Reference<?> sourceRef = state.getRelatedObject(REFERENCE_NAMESPACE, sourceString, Reference.class);
221

  
222
		Reference sourceRef = state.getRelatedObject(REFERENCE_NAMESPACE, sourceString, Reference.class);
222 223
		speciesTaxon.addSource(OriginalSourceType.Import, sourceId, REFERENCE_NAMESPACE, sourceRef, null);
223
		
224

  
224 225
		//geneva id
225
		Reference<?> genevaReference = state.getGenevaReference();
226
		Reference genevaReference = state.getGenevaReference();
226 227
		Object genevaId = rs.getObject("geneva_ID");
227 228
		speciesTaxon.addSource(OriginalSourceType.Import, String.valueOf(genevaId), null, genevaReference, null);
228
		
229

  
229 230
		//distribution
230 231
		handleDistribution(rs, speciesTaxon);
231
		
232

  
232 233
		return speciesTaxon;
233 234
	}
234
	
235

  
235 236
	private void handleDistribution(ResultSet rs, Taxon speciesTaxon) throws SQLException {
236 237
		TaxonDescription description = TaxonDescription.NewInstance(speciesTaxon);
237
		
238

  
238 239
		Boolean isCongo = rs.getBoolean("drc");
239 240
		Boolean isBurundi = rs.getBoolean("burundi");
240 241
		Boolean isRwanda = rs.getBoolean("rwanda");
......
273 274
	private Taxon getHigherTaxon(CentralAfricaChecklistImportState state, String family, String genus) {
274 275
		String higherName = normalizeHigherTaxonName(family, genus);
275 276
		UUID uuid = state.getHigherTaxon(higherName);
276
		
277

  
277 278
		Taxon taxon = null;
278 279
		if (uuid != null){
279 280
			taxon = higherTaxonMap.get(uuid);
......
302 303
//		UUID uuid = state.getTreeUuid(sec);
303 304
//		Classification tree;
304 305
//		tree = state.getTree(sec);
305
//		
306
//
306 307
//		if (tree == null){
307 308
//			tree = makeTreeMemSave(state, sec);
308 309
//		}
......
314 315
//		}
315 316
//		return (childNode != null);
316 317
//	}
317
	
318

  
318 319
	//TODO use Mapper
319
	private boolean makeTaxonomicallyIncluded(CentralAfricaChecklistImportState state, Integer treeRefFk, Taxon child, Taxon parent, Reference<?> citation, String microCitation){
320
	private boolean makeTaxonomicallyIncluded(CentralAfricaChecklistImportState state, Integer treeRefFk, Taxon child, Taxon parent, Reference citation, String microCitation){
320 321
		String treeKey;
321 322
		UUID treeUuid;
322 323
		if (treeRefFk == null){
......
340 341
			}
341 342
			state.addRelatedObject(DbImportTaxIncludedInMapper.TAXONOMIC_TREE_NAMESPACE, treeKey, tree);
342 343
		}
343
		
344

  
344 345
		TaxonNode childNode = tree.addParentChild(parent, child, citation, microCitation);
345 346
		return (childNode != null);
346 347
	}
347 348

  
348 349

  
349
	private Reference<?> makeGenevaReference(CentralAfricaChecklistImportState state) {
350
		Reference<?> result = ReferenceFactory.newDatabase();
350
	private Reference makeGenevaReference(CentralAfricaChecklistImportState state) {
351
		Reference result = ReferenceFactory.newDatabase();
351 352
		result.setTitleCache(state.getConfig().getGenevaReferenceTitle(), true);
352 353
		result.setUuid(state.getConfig().getUuidGenevaReference());
353 354
		return result;
......
358 359
		IOValidator<CentralAfricaChecklistImportState> validator = new CentralAfricaChecklistTaxonImportValidator();
359 360
		return validator.validate(state);
360 361
	}
361
	
362

  
362 363
	@Override
363 364
	protected boolean isIgnore(CentralAfricaChecklistImportState state){
364 365
		return ! state.getConfig().isDoTaxa();

Also available in: Unified diff