Project

General

Profile

« Previous | Next » 

Revision 5643a5ae

Added by Andreas Müller over 11 years ago

update Globis import

View differences:

app-import/src/main/java/eu/etaxonomy/cdm/io/globis/GlobisImportBase.java
33 33
import eu.etaxonomy.cdm.io.common.ResultSetPartitioner;
34 34
import eu.etaxonomy.cdm.io.common.Source;
35 35
import eu.etaxonomy.cdm.io.common.mapping.DbImportMapping;
36
import eu.etaxonomy.cdm.io.common.mapping.UndefinedTransformerMethodException;
36 37
import eu.etaxonomy.cdm.model.common.AnnotatableEntity;
37 38
import eu.etaxonomy.cdm.model.common.Annotation;
38 39
import eu.etaxonomy.cdm.model.common.AnnotationType;
......
42 43
import eu.etaxonomy.cdm.model.common.Language;
43 44
import eu.etaxonomy.cdm.model.common.MarkerType;
44 45
import eu.etaxonomy.cdm.model.common.User;
46
import eu.etaxonomy.cdm.model.location.WaterbodyOrCountry;
47
import eu.etaxonomy.cdm.model.name.ZoologicalName;
48
import eu.etaxonomy.cdm.strategy.exceptions.StringNotParsableException;
49
import eu.etaxonomy.cdm.strategy.parser.INonViralNameParser;
50
import eu.etaxonomy.cdm.strategy.parser.NonViralNameParserImpl;
45 51

  
46 52
/**
47 53
 * @author a.mueller
......
64 70
	//TODO needed?
65 71
	private Class cdmTargetClass;
66 72

  
67
	
73
	private INonViralNameParser parser = NonViralNameParserImpl.NewInstance();
74

  
68 75
	
69 76
	/**
70 77
	 * @param dbTableName
......
99 106
		return;
100 107
	}
101 108

  
109
	/**
110
	 * @param authorAndYear
111
	 * @param zooName
112
	 */
113
	protected void handleAuthorAndYear(String authorAndYear, ZoologicalName zooName) {
114
		if (isBlank(authorAndYear)){
115
			return;
116
		}
117
		try {
118
			String doubtfulAuthorAndYear = null;
119
			if(authorAndYear.matches(".+\\,\\s\\[\\d{4}\\].*")){
120
				doubtfulAuthorAndYear = authorAndYear;
121
				authorAndYear = authorAndYear.replace("[", "").replace("]", "");
122
			}
123
			if (authorAndYear.contains("?")){
124
				authorAndYear = authorAndYear.replace("H?bner", "H\u00fcbner");
125
				authorAndYear = authorAndYear.replace("Oberth?r", "Oberth\u00fcr");
126
			}
127
			
128
			parser.parseAuthors(zooName, authorAndYear);
129
			if (doubtfulAuthorAndYear != null){
130
				zooName.setAuthorshipCache(doubtfulAuthorAndYear, true);
131
			}
132
			
133
		} catch (StringNotParsableException e) {
134
			logger.warn("Author could not be parsed: " + authorAndYear);
135
			zooName.setAuthorshipCache(authorAndYear, true);
136
		}
137
	}
138
	
139

  
140
	/**
141
	 * @param state
142
	 * @param countryStr
143
	 * @return
144
	 */
145
	protected WaterbodyOrCountry getCountry(GlobisImportState state, String countryStr) {
146
		WaterbodyOrCountry country = WaterbodyOrCountry.getWaterbodyOrCountryByLabel(countryStr);
147
		if (country == null){
148
			try {
149
				country = (WaterbodyOrCountry)state.getTransformer().getNamedAreaByKey(countryStr);
150
			} catch (UndefinedTransformerMethodException e) {
151
				e.printStackTrace();
152
			}
153
		}
154
		return country;
155
	}
156

  
157
	
102 158

  
103 159
	public boolean doPartition(ResultSetPartitioner partitioner, GlobisImportState state) {
104 160
		boolean success = true ;
......
290 346
		return dateTime;
291 347
	}
292 348
	
293
	protected boolean resultSetHasColumn(ResultSet rs, String columnName){
294
		try {
295
			ResultSetMetaData metaData = rs.getMetaData();
296
			for (int i = 0; i < metaData.getColumnCount(); i++){
297
				if (metaData.getColumnName(i + 1).equalsIgnoreCase(columnName)){
298
					return true;
299
				}
300
			}
301
			return false;
302
		} catch (SQLException e) {
303
            logger.warn("Exception in resultSetHasColumn");
304
            return false;
305
		}
306
	}
307 349
	
308
	protected boolean checkSqlServerColumnExists(Source source, String tableName, String columnName){
309
		String strQuery = "SELECT  Count(t.id) as n " +
310
				" FROM sysobjects AS t " +
311
				" INNER JOIN syscolumns AS c ON t.id = c.id " +
312
				" WHERE (t.xtype = 'U') AND " + 
313
				" (t.name = '" + tableName + "') AND " + 
314
				" (c.name = '" + columnName + "')";
315
		ResultSet rs = source.getResultSet(strQuery) ;		
316
		int n;
317
		try {
318
			rs.next();
319
			n = rs.getInt("n");
320
			return n>0;
321
		} catch (SQLException e) {
322
			e.printStackTrace();
323
			return false;
324
		}
325
		
326
	}
327 350
	
328
	/**
329
	 * Returns a map that holds all values of a ResultSet. This is needed if a value needs to
330
	 * be accessed twice
331
	 * @param rs
332
	 * @return
333
	 * @throws SQLException
334
	 */
335
	protected Map<String, Object> getValueMap(ResultSet rs) throws SQLException{
336
		try{
337
			Map<String, Object> valueMap = new HashMap<String, Object>();
338
			int colCount = rs.getMetaData().getColumnCount();
339
			for (int c = 0; c < colCount ; c++){
340
				Object value = rs.getObject(c+1);
341
				String label = rs.getMetaData().getColumnLabel(c+1).toLowerCase();
342
				if (value != null && ! CdmUtils.Nz(value.toString()).trim().equals("")){
343
					valueMap.put(label, value);
344
				}
345
			}
346
			return valueMap;
347
		}catch(SQLException e){
348
			throw e;
349
		}
350
	}
351
	
352
	protected ExtensionType getExtensionType(UUID uuid, String label, String text, String labelAbbrev){
353
		ExtensionType extensionType = (ExtensionType)getTermService().find(uuid);
354
		if (extensionType == null){
355
			extensionType = ExtensionType.NewInstance(text, label, labelAbbrev);
356
			extensionType.setUuid(uuid);
357
			getTermService().save(extensionType);
358
		}
359
		return extensionType;
360
	}
361
	
362
	protected MarkerType getMarkerType(UUID uuid, String label, String text, String labelAbbrev){
363
		MarkerType markerType = (MarkerType)getTermService().find(uuid);
364
		if (markerType == null){
365
			markerType = MarkerType.NewInstance(label, text, labelAbbrev);
366
			markerType.setUuid(uuid);
367
			getTermService().save(markerType);
368
		}
369
		return markerType;
370
	}
371
	
372

  
373 351
	/**
374 352
	 * Reads a foreign key field from the result set and adds its value to the idSet.
375 353
	 * @param rs
......
385 363
		}
386 364
	}
387 365
	
366
	
367
	
368
	
388 369
	/**
389 370
	 * Returns true if i is a multiple of recordsPerTransaction
390 371
	 * @param i

Also available in: Unified diff