Project

General

Profile

« Previous | Next » 

Revision 1827bf2f

Added by Andreas Müller over 9 years ago

handle Integers in FactsImport and add IdInSource

View differences:

app-import/src/main/java/eu/etaxonomy/cdm/io/berlinModel/in/BerlinModelFactsImport.java
159 159
		return;
160 160
	}
161 161
		
162
	
163 162

  
164
	/* (non-Javadoc)
165
	 * @see eu.etaxonomy.cdm.io.berlinModel.in.BerlinModelImportBase#getIdQuery(eu.etaxonomy.cdm.io.berlinModel.in.BerlinModelImportState)
166
	 */
167 163
	@Override
168 164
	protected String getIdQuery(BerlinModelImportState state) {
169 165
		String result = super.getIdQuery(state);
......
176 172
		return result;
177 173
	}
178 174

  
179
	
180

  
181
	/* (non-Javadoc)
182
	 * @see eu.etaxonomy.cdm.io.berlinModel.in.BerlinModelImportBase#getRecordQuery(eu.etaxonomy.cdm.io.berlinModel.in.BerlinModelImportConfigurator)
183
	 */
184 175
	@Override
185 176
	protected String getRecordQuery(BerlinModelImportConfigurator config) {
186 177
			String strQuery = 
......
210 201
		return result;
211 202
	}
212 203
	
213

  
214
	/* (non-Javadoc)
215
	 * @see eu.etaxonomy.cdm.io.berlinModel.in.IPartitionedIO#doPartition(eu.etaxonomy.cdm.io.berlinModel.in.ResultSetPartitioner, eu.etaxonomy.cdm.io.berlinModel.in.BerlinModelImportState)
216
	 */
204
	@Override
217 205
	public boolean doPartition(ResultSetPartitioner partitioner, BerlinModelImportState state) {
218 206
		boolean success = true ;
219 207
		BerlinModelImportConfigurator config = state.getConfig();
......
233 221
					if ((i++ % modCount) == 0){ logger.info("Facts handled: " + (i-1));}
234 222
					
235 223
					int factId = rs.getInt("factId");
236
					Object taxonIdObj = rs.getObject("taxonId");
237
					Number taxonId = (Number)rs.getObject("taxonId");
238
					Object factRefFkObj = rs.getObject("factRefFk");
239
					Object categoryFkObj = rs.getObject("factCategoryFk");
240
					Integer categoryFk = rs.getInt("factCategoryFk");
224
					Integer taxonId = nullSafeInt(rs, "taxonId");
225
					Integer factRefFkInt = nullSafeInt(rs, "factRefFk");
226
					Integer categoryFkInt = nullSafeInt(rs, "factCategoryFk");
241 227
					String details = rs.getString("Details");
242 228
					String fact = CdmUtils.Nz(rs.getString("Fact"));
243 229
					String notes = CdmUtils.Nz(rs.getString("notes"));
244 230
					Boolean doubtfulFlag = rs.getBoolean("DoubtfulFlag");
245 231
					
246
					TaxonBase<?> taxonBase = getTaxon(taxonMap, taxonIdObj, taxonId);
247
					Feature feature = getFeature(featureMap, categoryFkObj, categoryFk) ;
232
					TaxonBase<?> taxonBase = getTaxon(taxonMap, taxonId, taxonId);
233
					Feature feature = getFeature(featureMap, categoryFkInt) ;
248 234
					
249 235
					if (taxonBase == null){
250 236
						logger.warn("Taxon for Fact " + factId + " does not exist in store");
251 237
						success = false;
252 238
					}else{
253 239
						TaxonDescription taxonDescription;
254
						if ( (taxonDescription = getMyTaxonDescripion(taxonBase, state, categoryFk, taxonIdObj, factId, fact, sourceRef)) == null){
240
						if ( (taxonDescription = getMyTaxonDescripion(taxonBase, state, categoryFkInt, taxonId, factId, fact, sourceRef)) == null){
255 241
							success = false;
256 242
							continue;
257 243
						}
......
262 248
	
263 249
						// For Cichorieae DB: If fact category is 31 (Systematics) and there is already a Systematics TextData 
264 250
						// description element append the fact text to the existing TextData
265
						if(categoryFk == 31) {
251
						if(categoryFkInt.equals(31)) {
266 252
							Set<DescriptionElementBase> descriptionElements = taxonDescription.getElements();
267 253
							for (DescriptionElementBase descriptionElement : descriptionElements) {
268 254
								String featureString = descriptionElement.getFeature().getRepresentation(Language.DEFAULT()).getLabel();
......
287 273
						}
288 274
						
289 275
						//for diptera database
290
						if (categoryFk == 99 && notes.contains("<OriginalName>")){
276
						if (categoryFkInt.equals(99) && notes.contains("<OriginalName>")){
291 277
//							notes = notes.replaceAll("<OriginalName>", "");
292 278
//							notes = notes.replaceAll("</OriginalName>", "");
293 279
							fact = notes + ": " +  fact ;
294 280
						}
295 281
						//for E+M maps
296
						if (categoryFk == 14 && state.getConfig().isRemoveHttpMapsAnchor() && fact.contains("<a href")){
282
						if (categoryFkInt.equals(14) && state.getConfig().isRemoveHttpMapsAnchor() && fact.contains("<a href")){
297 283
							//example <a href="http://euromed.luomus.fi/euromed_map.php?taxon=280629&size=medium">distribution</a>
298 284
							fact = fact.replace("<a href=\"", "").replace("\">distribution</a>", "");
299 285
						}
......
307 293
						
308 294
						//reference
309 295
						Reference<?> citation = null;
310
						String factRefFk = String.valueOf(factRefFkObj);
311
						if (factRefFkObj != null){
296
						String factRefFk = String.valueOf(factRefFkInt);
297
						if (factRefFkInt != null){
312 298
							citation = refMap.get(factRefFk);	
313
							}
314
						if (citation == null && (factRefFkObj != null)){
315
								logger.warn("Citation not found in referenceMap: " + factRefFk);
299
						}
300
						if (citation == null && (factRefFkInt != null)){
301
							logger.warn("Citation not found in referenceMap: " + factRefFk);
316 302
							success = false;
317
							}
303
						}
318 304
						if (citation != null || StringUtils.isNotBlank(details)){
319 305
							DescriptionElementSource originalSource = DescriptionElementSource.NewPrimarySourceInstance(citation, details);
320 306
							textData.addSource(originalSource);
......
356 342
						
357 343
						//notes
358 344
						doCreatedUpdatedNotes(state, textData, rs);
345
						doId(state, textData, factId, "Fact");
359 346
						
360 347
						//TODO
361 348
						//Designation References -> unclear how to map to CDM
362
						//factId -> OriginalSource for descriptionElements not yet implemented
349
						
363 350
						
364 351
						//sequence -> textData is not an identifiable entity therefore extensions are not possible
365 352
						//fact category better
......
382 369
		return success;
383 370
	}
384 371

  
385
	private TaxonDescription getMyTaxonDescripion(TaxonBase taxonBase, BerlinModelImportState state, Integer categoryFk, Object taxonIdObj, int factId, String fact, Reference<?> sourceRef) {
372
	private TaxonDescription getMyTaxonDescripion(TaxonBase taxonBase, BerlinModelImportState state, Integer categoryFk, Integer taxonId, int factId, String fact, Reference<?> sourceRef) {
386 373
		Taxon taxon = null;
387 374
		if ( taxonBase instanceof Taxon ) {
388 375
			taxon = (Taxon) taxonBase;
389 376
		}else{
390
			logger.warn("TaxonBase " + (taxonIdObj==null?"(null)":taxonIdObj) + " for Fact " + factId + " was not of type Taxon but: " + taxonBase.getClass().getSimpleName());
377
			logger.warn("TaxonBase " + (taxonId==null?"(null)":taxonId) + " for Fact " + factId + " was not of type Taxon but: " + taxonBase.getClass().getSimpleName());
391 378
			return null;
392 379
		}
393 380
		
......
493 480
	 */
494 481
	private TaxonDescription makeImage(BerlinModelImportState state, String fact, Media media, Set<TaxonDescription> descriptionSet, Taxon taxon) {
495 482
		TaxonDescription taxonDescription = null;
496
		Reference sourceRef = state.getTransactionalSourceReference();
483
		Reference<?> sourceRef = state.getTransactionalSourceReference();
497 484
		Integer size = null; 
498 485
		ImageInfo imageInfo = null;
499 486
		URI uri;
......
520 507
		return taxonDescription;
521 508
	}
522 509

  
523
	private TaxonBase getTaxon(Map<String, TaxonBase> taxonMap, Object taxonIdObj, Number taxonId){
510
	private TaxonBase getTaxon(Map<String, TaxonBase> taxonMap, Integer taxonIdObj, Number taxonId){
524 511
		if (taxonIdObj != null){
525 512
			return taxonMap.get(String.valueOf(taxonId));
526 513
		}else{
......
529 516
		
530 517
	}
531 518
	
532
	private Feature getFeature(Map<Integer, Feature>  featureMap, Object categoryFkObj, Integer categoryFk){
533
		if (categoryFkObj != null){
534
			return featureMap.get(categoryFk); 
519
	private Feature getFeature(Map<Integer, Feature>  featureMap, Integer categoryFkInt){
520
		if (categoryFkInt != null){
521
			return featureMap.get(categoryFkInt); 
535 522
		}else{
536 523
			return null;
537 524
		}
538 525
		
539 526
	}
540 527
	
541

  
542
	/* (non-Javadoc)
543
	 * @see eu.etaxonomy.cdm.io.common.CdmIoBase#doCheck(eu.etaxonomy.cdm.io.common.IoStateBase)
544
	 */
545 528
	@Override
546 529
	protected boolean doCheck(BerlinModelImportState state){
547 530
		IOValidator<BerlinModelImportState> validator = new BerlinModelFactsImportValidator();
548 531
		return validator.validate(state);
549 532
	}
550 533
				
551
	/* (non-Javadoc)
552
	 * @see eu.etaxonomy.cdm.io.common.CdmIoBase#isIgnore(eu.etaxonomy.cdm.io.common.IImportConfigurator)
553
	 */
534
	@Override
554 535
	protected boolean isIgnore(BerlinModelImportState state){
555 536
		return ! state.getConfig().isDoFacts();
556 537
	}

Also available in: Unified diff