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:

app-import/src/main/java/eu/etaxonomy/cdm/io/globis/GlobisImageImport.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
*/
......
55 55
@Component
56 56
public class GlobisImageImport  extends GlobisImportBase<Taxon> {
57 57
	private static final Logger logger = Logger.getLogger(GlobisImageImport.class);
58
	
58

  
59 59
	private int modCount = 1000;
60 60

  
61 61
	private UUID uuidArtNonSpecTaxMarkerType = UUID.fromString("be362085-0f5b-4314-96d1-78b9b129ef6d") ;
62 62
	private static final String pluralString = "images";
63 63
	private static final String dbTableName = "Einzelbilder";
64 64
	private static final Class<?> cdmTargetClass = Media.class;  //not needed
65
	
66
	private static UUID uuidGartRef = UUID.fromString("af85470f-6e54-4304-9d29-fd117cd56161"); 
67
	
65

  
66
	private static UUID uuidGartRef = UUID.fromString("af85470f-6e54-4304-9d29-fd117cd56161");
67

  
68 68
	public GlobisImageImport(){
69 69
		super(pluralString, dbTableName, cdmTargetClass);
70 70
	}
71 71

  
72 72

  
73
	
74
	
73

  
74

  
75 75
	/* (non-Javadoc)
76 76
	 * @see eu.etaxonomy.cdm.io.globis.GlobisImportBase#getIdQuery()
77 77
	 */
78 78
	@Override
79 79
	protected String getIdQuery() {
80
		String strRecordQuery = 
81
			" SELECT BildId " + 
82
			" FROM " + dbTableName; 
83
		return strRecordQuery;	
80
		String strRecordQuery =
81
			" SELECT BildId " +
82
			" FROM " + dbTableName;
83
		return strRecordQuery;
84 84
	}
85 85

  
86 86

  
......
91 91
	 */
92 92
	@Override
93 93
	protected String getRecordQuery(GlobisImportConfigurator config) {
94
		String strRecordQuery = 
94
		String strRecordQuery =
95 95
			" SELECT i.*, NULL as Created_When, NULL as Created_Who," +
96
				"  NULL as Updated_who, NULL as Updated_When, NULL as Notes, st.SpecCurrspecID " + 
96
				"  NULL as Updated_who, NULL as Updated_When, NULL as Notes, st.SpecCurrspecID " +
97 97
			" FROM " + getTableName() + " i " +
98 98
				" LEFT JOIN specTax st ON i.spectaxID = st.SpecTaxID " +
99 99
			" WHERE ( i.BildId IN (" + ID_LIST_TOKEN + ") )";
100 100
		return strRecordQuery;
101 101
	}
102
	
102

  
103 103

  
104 104

  
105 105
	/* (non-Javadoc)
......
108 108
	@Override
109 109
	public boolean doPartition(ResultSetPartitioner partitioner, GlobisImportState state) {
110 110
		boolean success = true;
111
		
111

  
112 112
		Set<Media> objectsToSave = new HashSet<Media>();
113
		
114
		Map<String, DerivedUnit> typeMap = (Map<String, DerivedUnit>) partitioner.getObjectMap(TYPE_NAMESPACE);
115
		
116
		Map<String, Taxon> taxonMap = (Map<String, Taxon>) partitioner.getObjectMap(TAXON_NAMESPACE);
117
		Map<String, ZoologicalName> specTaxNameMap = (Map<String, ZoologicalName>) partitioner.getObjectMap(SPEC_TAX_NAMESPACE);
118
		
113

  
114
		Map<String, DerivedUnit> typeMap = partitioner.getObjectMap(TYPE_NAMESPACE);
115

  
116
		Map<String, Taxon> taxonMap = partitioner.getObjectMap(TAXON_NAMESPACE);
117
		Map<String, ZoologicalName> specTaxNameMap = partitioner.getObjectMap(SPEC_TAX_NAMESPACE);
118

  
119 119
		ResultSet rs = partitioner.getResultSet();
120
		
121
		Reference<?> refGart = getReferenceService().find(uuidGartRef);
122
		
123
		
120

  
121
		Reference refGart = getReferenceService().find(uuidGartRef);
122

  
123

  
124 124
		try {
125
			
125

  
126 126
			int i = 0;
127 127

  
128 128
			//for each record
129 129
            while (rs.next()){
130
                
130

  
131 131
        		if ((i++ % modCount) == 0 && i!= 1 ){ logger.info(pluralString + " handled: " + (i-1));}
132
				
132

  
133 133
        		Integer bildID = rs.getInt("BildID");
134 134
        		Integer spectaxID = nullSafeInt(rs, "spectaxID");
135 135
        		Integer taxonID = nullSafeInt(rs, "SpecCurrspecID");
......
138 138
        		String bemerkungen = rs.getString("Bemerkungen");
139 139
        		String artNotSpecTax = rs.getString("Art non spectax");
140 140
        		String motiv = rs.getString("Motiv");
141
        		
142
        		//ignore: 
141

  
142
        		//ignore:
143 143
        		//	[file lab2], same as Dateiname04 but less data
144 144
        		//	Dateipfad
145 145

  
146 146
        		Set<Media> recordMedia = new HashSet<Media>();
147
        		
147

  
148 148
        		try {
149
					
149

  
150 150
        			makeAllMedia(state, rs, recordMedia, objectsToSave);
151
        			
151

  
152 152
        			String title = null;
153
        			
153

  
154 154
        			DerivedUnit specimen = null;
155 155
        			if (spectaxID != null){
156 156
        				//try to find type specimen
......
159 159
	    					String id = GlobisSpecTaxImport.getTypeId(spectaxID, collectionCode);
160 160
	    					specimen = typeMap.get(id);
161 161
        				}
162
        				
162

  
163 163
    					//try to find specTaxName
164 164
        				ZoologicalName specTaxTaxonName = specTaxNameMap.get(String.valueOf(spectaxID));
165 165
            			if (specTaxTaxonName != null){
......
170 170
    				}else{
171 171
    					title = " name " + getNameFromFileOs(rs) + (isBlank(specimenId)? "" : " (specimenId: " + specimenId + ")");
172 172
    				}
173
        			
173

  
174 174
        			//not type specimen
175 175
        			if (specimen == null){
176 176
						specimen = DerivedUnit.NewPreservedSpecimenInstance();
......
180 180
						Collection collection = getCollection(collectionCode);
181 181
						specimen.setCollection(collection);
182 182
					}
183
					
184
					
183

  
184

  
185 185
					//source
186 186
					specimen.addSource(OriginalSourceType.Import, String.valueOf(bildID), IMAGE_NAMESPACE, state.getTransactionalSourceReference(), null);
187
					
187

  
188 188
					//GART id (specimenID)
189 189
					if (isNotBlank(specimenId)){
190 190
						specimen.addSource(OriginalSourceType.Lineage, specimenId, "specimenId", refGart, null);
......
208 208
							logger.warn(artNotSpecTax + " is not a valid value for 'Art non spectax' (BildID: " + bildID + ")" );
209 209
						}
210 210
					}
211
        			
211

  
212 212
					if (spectaxID != null){
213
						
213

  
214 214
						//add to image gallery (discuss if this is also needed if taxon is already added to type specimen
215 215
//						Taxon taxon = taxonMap.get(String.valueOf(taxonID));
216 216
						ZoologicalName specTaxTaxonName = specTaxNameMap.get(String.valueOf(spectaxID));
217
						
218
//						
217

  
218
//
219 219
//						if (taxon == null){
220 220
////							taxon = specTaxMap.get(String.valueOf(spectaxID));
221 221
////							specTaxName = specTaxMap.g
......
225 225
//						}else{
226 226
//							name = CdmBase.deproxy(taxon.getName(), ZoologicalName.class);
227 227
//						}
228
						
228

  
229 229
						//TODO FIXME
230
						
230

  
231 231
						if (specTaxTaxonName == null){
232 232
							logger.warn("Name could not be found for spectaxID: " + spectaxID +  " in BildID: " + bildID);
233 233
						}else{
......
237 237
							}
238 238
							if (taxon == null){
239 239
								//FIXME
240
								Reference<?> undefinedSec = null;
240
								Reference undefinedSec = null;
241 241
								taxon = Taxon.NewInstance(specTaxTaxonName, undefinedSec);
242 242
							}
243
							
243

  
244 244
							DeterminationEvent.NewInstance(taxon, specimen);
245 245

  
246 246
						}
247
						
248
						
249 247

  
250
						
248

  
249

  
250

  
251 251
//						if (taxon != null){
252 252
//							TaxonDescription taxonDescription = getTaxonDescription(taxon, true, true);
253 253
//							if (taxonDescription.getElements().size() == 0){
......
261 261
//							}
262 262
//						}
263 263
					}
264
					
264

  
265 265
				} catch (Exception e) {
266 266
					logger.warn("Exception in Einzelbilder: bildID " + bildID + ". " + e.getMessage());
267 267
					e.printStackTrace();
268
				} 
269
                
268
				}
269

  
270 270
            }
271
           
271

  
272 272
			logger.info(pluralString + " to save: " + objectsToSave.size());
273
			getMediaService().save(objectsToSave);	
274
			
273
			getMediaService().save(objectsToSave);
274

  
275 275
			return success;
276 276
		} catch (SQLException e) {
277 277
			logger.error("SQLException:" +  e);
278 278
			return false;
279 279
		}
280 280
	}
281
	
281

  
282 282
	private Collection getCollection(String collectionCode) {
283 283
		//TODO
284 284
		return null;
......
310 310
		pathShort= pathShort.replace(fileOS, "");
311 311
		String newPath = state.getConfig().getImageBaseUrl();
312 312
		String path = pathShort.replace("image:Webversionen/", newPath);
313
		
313

  
314 314
		Media singleMedia = makeMedia(state, rs, "file OS", "Legende 1", path, objectsToSave );
315 315
		recordMedia.add(singleMedia);
316 316
		singleMedia = makeMedia(state, rs, "Dateinamen02", "Legende 2", path, objectsToSave );
......
327 327
		String fileName = rs.getString(fileNameAttr);
328 328
		String legend = rs.getString(legendAttr);
329 329
		Integer bildID = rs.getInt("BildID");
330
		
330

  
331 331
		String uriStr = path+fileName;
332 332
		uriStr = uriStr.replace(" ", "%20");
333
		
334
		URI uri = URI.create(uriStr); 
335
		
333

  
334
		URI uri = URI.create(uriStr);
335

  
336 336
//		Media media = ImageInfo.NewInstanceWithMetaData(uri, null);
337
		
337

  
338 338
		try {
339 339
			boolean readMediaData = state.getConfig().isDoReadMediaData();
340 340
			if (isBlank(legend) && readMediaData){
......
344 344
					return null;
345 345
				}
346 346
			}
347
			
347

  
348 348
			media = this.getImageMedia(uri.toString(), readMediaData);
349 349
			media.putTitle(Language.ENGLISH(), legend);
350 350
			this.doIdCreatedUpdatedNotes(state, media, rs, bildID, IMAGE_NAMESPACE);
351
			
351

  
352 352
			objectsToSave.add(media);
353
			
354
			
353

  
354

  
355 355
		} catch (MalformedURLException e) {
356 356
			e.printStackTrace();
357 357
		} catch (ClientProtocolException e) {
......
359 359
		} catch (IOException e) {
360 360
			e.printStackTrace();
361 361
		}
362
		
362

  
363 363
		return media;
364 364
	}
365
	
365

  
366 366
	private String transformCopyright2CollectionCode(String copyright){
367
		
367

  
368 368
		if (isBlank(copyright)){
369 369
			return "";
370 370
		}else if(copyright.matches("Museum f.?r Naturkunde der Humboldt-Universit.?t, Berlin")){
......
409 409
		}
410 410
	}
411 411

  
412
	
412

  
413 413
	@Override
414 414
	public Map<Object, Map<String, ? extends CdmBase>> getRelatedObjectsForPartition(ResultSet rs, GlobisImportState state) {
415 415
		String nameSpace;
......
420 420
			Set<String> currSpecIdSet = new HashSet<String>();
421 421
			Set<String> specTaxIdSet = new HashSet<String>();
422 422
			Set<String> typeIdSet = new HashSet<String>();
423
			
423

  
424 424
			while (rs.next()){
425 425
				handleForeignKey(rs, currSpecIdSet, "SpecCurrspecID");
426 426
				handleForeignKey(rs, specTaxIdSet, "spectaxID");
427 427
				handleTypeKey(rs, typeIdSet, "spectaxID", "copyright");
428 428
			}
429
			
429

  
430 430
			//specTax map
431 431
			nameSpace = SPEC_TAX_NAMESPACE;
432 432
			cdmClass = ZoologicalName.class;
......
441 441
//			Map<String, Taxon> taxonMap = (Map<String, Taxon>)getCommonService().getSourcedObjectsByIdInSource(cdmClass, idSet, nameSpace);
442 442
//			result.put(nameSpace, taxonMap);
443 443

  
444
			
444

  
445 445
			//type map
446 446
			nameSpace = GlobisSpecTaxImport.TYPE_NAMESPACE;
447 447
			cdmClass = DerivedUnit.class;
448 448
			idSet = typeIdSet;
449 449
			Map<String, DerivedUnit> typeMap = (Map<String, DerivedUnit>)getCommonService().getSourcedObjectsByIdInSource(cdmClass, idSet, nameSpace);
450 450
			result.put(nameSpace, typeMap);
451
			
452
			
451

  
452

  
453 453
		} catch (SQLException e) {
454 454
			throw new RuntimeException(e);
455 455
		}
456 456
		return result;
457 457
	}
458
	
458

  
459 459
	private void handleTypeKey(ResultSet rs, Set<String> idSet, String specTaxIdAttr, String copyrightAttr) throws SQLException {
460 460
		Integer specTaxId = nullSafeInt(rs, specTaxIdAttr);
461 461
		if (specTaxId != null){
......
466 466
			}
467 467
		}
468 468
	}
469
	
469

  
470 470
	/* (non-Javadoc)
471 471
	 * @see eu.etaxonomy.cdm.io.common.CdmIoBase#doCheck(eu.etaxonomy.cdm.io.common.IImportConfigurator)
472 472
	 */
......
475 475
		IOValidator<GlobisImportState> validator = new GlobisImageImportValidator();
476 476
		return validator.validate(state);
477 477
	}
478
	
479
	
478

  
479

  
480 480
	/* (non-Javadoc)
481 481
	 * @see eu.etaxonomy.cdm.io.common.CdmIoBase#isIgnore(eu.etaxonomy.cdm.io.common.IImportConfigurator)
482 482
	 */
483
	protected boolean isIgnore(GlobisImportState state){
483
	@Override
484
    protected boolean isIgnore(GlobisImportState state){
484 485
		return ! state.getConfig().isDoImages();
485 486
	}
486 487

  

Also available in: Unified diff