Revision c483dd7e
Added by Katja Luther over 9 years ago
cdm-pesi/src/main/java/eu/etaxonomy/cdm/io/pesi/indexFungorum/IndexFungorumImportBase.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 |
*/ |
... | ... | |
39 | 39 |
import eu.etaxonomy.cdm.model.common.Marker; |
40 | 40 |
import eu.etaxonomy.cdm.model.common.MarkerType; |
41 | 41 |
import eu.etaxonomy.cdm.model.common.OriginalSourceType; |
42 |
import eu.etaxonomy.cdm.model.common.TimePeriod; |
|
43 | 42 |
import eu.etaxonomy.cdm.model.name.NonViralName; |
44 | 43 |
import eu.etaxonomy.cdm.model.reference.Reference; |
45 | 44 |
import eu.etaxonomy.cdm.model.reference.ReferenceFactory; |
... | ... | |
55 | 54 |
*/ |
56 | 55 |
public abstract class IndexFungorumImportBase extends CdmImportBase<IndexFungorumImportConfigurator, IndexFungorumImportState> implements ICdmIO<IndexFungorumImportState>, IPartitionedIO<IndexFungorumImportState> { |
57 | 56 |
private static final Logger logger = Logger.getLogger(IndexFungorumImportBase.class); |
58 |
|
|
57 |
|
|
59 | 58 |
//NAMESPACES |
60 | 59 |
protected static final String NAMESPACE_REFERENCE = "reference"; |
61 | 60 |
protected static final String NAMESPACE_TAXON = "Taxon"; |
62 | 61 |
protected static final String NAMESPACE_SUPRAGENERIC_NAMES = "SupragenericNames"; |
63 | 62 |
protected static final String NAMESPACE_GENERA = "Genera"; |
64 | 63 |
protected static final String NAMESPACE_SPECIES = "Species"; |
65 |
|
|
66 |
|
|
64 |
|
|
65 |
|
|
67 | 66 |
protected static final String INCERTAE_SEDIS = "Incertae sedis"; |
68 | 67 |
protected static final String FOSSIL_FUNGI = "Fossil Fungi"; |
69 | 68 |
|
70 | 69 |
protected static final String SOURCE_REFERENCE = "SOURCE_REFERENCE"; |
71 | 70 |
|
72 | 71 |
|
73 |
|
|
74 | 72 |
|
75 |
private String pluralString; |
|
76 |
private String dbTableName; |
|
73 |
|
|
74 |
private final String pluralString; |
|
75 |
private final String dbTableName; |
|
77 | 76 |
//TODO needed? |
78 |
private Class cdmTargetClass; |
|
77 |
private final Class cdmTargetClass; |
|
78 |
|
|
79 |
|
|
79 | 80 |
|
80 |
|
|
81 |
|
|
82 | 81 |
/** |
83 | 82 |
* @param dbTableName |
84 |
* @param dbTableName2
|
|
83 |
* @param dbTableName2 |
|
85 | 84 |
*/ |
86 | 85 |
public IndexFungorumImportBase(String pluralString, String dbTableName, Class cdmTargetClass) { |
87 | 86 |
this.pluralString = pluralString; |
... | ... | |
89 | 88 |
this.cdmTargetClass = cdmTargetClass; |
90 | 89 |
} |
91 | 90 |
|
92 |
protected void doInvoke(IndexFungorumImportState state){ |
|
93 |
logger.info("start make " + getPluralString() + " ..."); |
|
91 |
@Override |
|
92 |
protected void doInvoke(IndexFungorumImportState state){ |
|
93 |
System.out.println("start make " + getPluralString() + " ..."); |
|
94 | 94 |
IndexFungorumImportConfigurator config = state.getConfig(); |
95 | 95 |
Source source = config.getSource(); |
96 |
|
|
96 |
|
|
97 |
|
|
97 | 98 |
String strIdQuery = getIdQuery(); |
99 |
|
|
98 | 100 |
String strRecordQuery = getRecordQuery(config); |
99 | 101 |
|
100 | 102 |
int recordsPerTransaction = config.getRecordsPerTransaction(); |
... | ... | |
108 | 110 |
state.setUnsuccessfull(); |
109 | 111 |
return; |
110 | 112 |
} |
111 |
|
|
113 |
|
|
112 | 114 |
logger.info("end make " + getPluralString() + " ... " + getSuccessString(true)); |
113 | 115 |
return; |
114 | 116 |
} |
115 |
|
|
116 | 117 |
|
117 | 118 |
|
118 |
|
|
119 |
|
|
120 |
public boolean doPartition(ResultSetPartitioner partitioner, IndexFungorumImportState state) { |
|
119 |
|
|
120 |
|
|
121 |
|
|
122 |
|
|
123 |
|
|
124 |
@Override |
|
125 |
public boolean doPartition(ResultSetPartitioner partitioner, IndexFungorumImportState state) { |
|
121 | 126 |
boolean success = true ; |
122 | 127 |
Set objectsToSave = new HashSet<CdmBase>(); |
123 |
|
|
128 |
|
|
124 | 129 |
// DbImportMapping<?, ?> mapping = getMapping(); |
125 | 130 |
// mapping.initialize(state, cdmTargetClass); |
126 |
|
|
131 |
|
|
127 | 132 |
ResultSet rs = partitioner.getResultSet(); |
128 | 133 |
try{ |
129 | 134 |
while (rs.next()){ |
... | ... | |
133 | 138 |
logger.error("SQLException:" + e); |
134 | 139 |
return false; |
135 | 140 |
} |
136 |
|
|
141 |
|
|
137 | 142 |
partitioner.startDoSave(); |
138 | 143 |
getCommonService().save(objectsToSave); |
139 | 144 |
return success; |
... | ... | |
145 | 150 |
*/ |
146 | 151 |
protected abstract String getRecordQuery(IndexFungorumImportConfigurator config); |
147 | 152 |
|
153 |
|
|
148 | 154 |
/** |
149 | 155 |
* @return |
150 | 156 |
*/ |
... | ... | |
152 | 158 |
String result = " SELECT id FROM " + getTableName(); |
153 | 159 |
return result; |
154 | 160 |
} |
155 |
|
|
161 |
|
|
156 | 162 |
/* (non-Javadoc) |
157 | 163 |
* @see eu.etaxonomy.cdm.io.berlinModel.in.IPartitionedIO#getPluralString() |
158 | 164 |
*/ |
159 |
public String getPluralString(){ |
|
165 |
@Override |
|
166 |
public String getPluralString(){ |
|
160 | 167 |
return pluralString; |
161 | 168 |
} |
162 | 169 |
|
... | ... | |
167 | 174 |
return this.dbTableName; |
168 | 175 |
} |
169 | 176 |
|
170 |
|
|
177 |
|
|
171 | 178 |
protected boolean resultSetHasColumn(ResultSet rs, String columnName){ |
172 | 179 |
try { |
173 | 180 |
ResultSetMetaData metaData = rs.getMetaData(); |
... | ... | |
182 | 189 |
return false; |
183 | 190 |
} |
184 | 191 |
} |
185 |
|
|
192 |
|
|
186 | 193 |
protected boolean checkSqlServerColumnExists(Source source, String tableName, String columnName){ |
187 | 194 |
String strQuery = "SELECT Count(t.id) as n " + |
188 | 195 |
" FROM sysobjects AS t " + |
189 | 196 |
" INNER JOIN syscolumns AS c ON t.id = c.id " + |
190 |
" WHERE (t.xtype = 'U') AND " +
|
|
191 |
" (t.name = '" + tableName + "') AND " +
|
|
197 |
" WHERE (t.xtype = 'U') AND " + |
|
198 |
" (t.name = '" + tableName + "') AND " + |
|
192 | 199 |
" (c.name = '" + columnName + "')"; |
193 |
ResultSet rs = source.getResultSet(strQuery) ;
|
|
200 |
ResultSet rs = source.getResultSet(strQuery) ; |
|
194 | 201 |
int n; |
195 | 202 |
try { |
196 | 203 |
rs.next(); |
... | ... | |
200 | 207 |
e.printStackTrace(); |
201 | 208 |
return false; |
202 | 209 |
} |
203 |
|
|
210 |
|
|
204 | 211 |
} |
205 |
|
|
212 |
|
|
206 | 213 |
/** |
207 | 214 |
* Returns a map that holds all values of a ResultSet. This is needed if a value needs to |
208 | 215 |
* be accessed twice |
... | ... | |
242 | 249 |
idSet.add(id); |
243 | 250 |
} |
244 | 251 |
} |
245 |
|
|
252 |
|
|
246 | 253 |
/** |
247 | 254 |
* Returns true if i is a multiple of recordsPerTransaction |
248 | 255 |
* @param i |
... | ... | |
253 | 260 |
startTransaction(); |
254 | 261 |
return (i % recordsPerLoop) == 0; |
255 | 262 |
} |
256 |
|
|
263 |
|
|
257 | 264 |
protected void doLogPerLoop(int count, int recordsPerLog, String pluralString){ |
258 | 265 |
if ((count % recordsPerLog ) == 0 && count!= 0 ){ logger.info(pluralString + " handled: " + (count));} |
259 | 266 |
} |
260 |
|
|
267 |
|
|
261 | 268 |
|
262 | 269 |
protected void makeAuthorAndPublication(IndexFungorumImportState state, ResultSet rs, NonViralName name) throws SQLException { |
263 | 270 |
//authors |
... | ... | |
266 | 273 |
if (StringUtils.isNotBlank(authorStr)){ |
267 | 274 |
try { |
268 | 275 |
parser.parseAuthors(name, authorStr); |
269 |
} catch (StringNotParsableException e){
|
|
270 |
logger.warn("Authorstring not parsable: " + authorStr); |
|
276 |
} catch (StringNotParsableException e){ |
|
277 |
//logger.warn("Authorstring not parsable: " + authorStr);
|
|
271 | 278 |
name.setAuthorshipCache(authorStr); |
272 | 279 |
} |
273 | 280 |
} |
274 |
|
|
281 |
|
|
275 | 282 |
//page |
276 | 283 |
String page = rs.getString("PAGE"); |
277 | 284 |
if (StringUtils.isNotBlank(page)){ |
278 | 285 |
name.setNomenclaturalMicroReference(page); |
279 | 286 |
} |
280 |
|
|
287 |
|
|
281 | 288 |
//Reference |
282 | 289 |
Reference<?> ref = ReferenceFactory.newGeneric(); |
283 | 290 |
boolean hasInReference = false; |
... | ... | |
293 | 300 |
logger.warn("'AUTHORS' is blank for not empty PUBLISHING_AUTHORS. This is not yet handled."); |
294 | 301 |
} |
295 | 302 |
} |
296 |
|
|
303 |
|
|
297 | 304 |
//inRef + inRefAuthor |
298 | 305 |
if (pubAuthor != null){ |
299 | 306 |
Reference<?> inRef = ReferenceFactory.newGeneric(); |
... | ... | |
301 | 308 |
ref.setInReference(inRef); |
302 | 309 |
hasInReference = true; |
303 | 310 |
} |
304 |
|
|
311 |
|
|
305 | 312 |
//refAuthor |
306 | 313 |
TeamOrPersonBase<?> refAuthor = CdmBase.deproxy(name.getCombinationAuthorTeam(), TeamOrPersonBase.class); |
307 | 314 |
if (refAuthor == null){ |
... | ... | |
343 | 350 |
} |
344 | 351 |
} |
345 | 352 |
ref.setVolume(volume); |
346 |
|
|
353 |
|
|
347 | 354 |
//year |
348 | 355 |
String yearOfPubl = rs.getString("YEAR OF PUBLICATION"); |
349 | 356 |
String yearOnPubl = rs.getString("YEAR ON PUBLICATION"); |
... | ... | |
357 | 364 |
if (year != null){ |
358 | 365 |
ref.setDatePublished(TimePeriodParser.parseString(year)); |
359 | 366 |
} |
360 |
|
|
367 |
|
|
361 | 368 |
//preliminary, set protected titlecache as Generic Cache Generation with in references currently doesn't fully work yet |
362 | 369 |
String titleCache = CdmUtils.concat(", ", pubAuthorStr, title); |
363 | 370 |
if ( StringUtils.isNotBlank(pubAuthorStr)){ |
... | ... | |
367 | 374 |
titleCache = CdmUtils.concat(": ", titleCache, page); |
368 | 375 |
titleCache = CdmUtils.concat(". ", titleCache, year); |
369 | 376 |
ref.setTitleCache(titleCache, true); |
370 |
|
|
377 |
|
|
371 | 378 |
//set nom ref |
372 | 379 |
if (StringUtils.isNotBlank(titleCache)){ |
373 | 380 |
name.setNomenclaturalReference(ref); |
374 | 381 |
} |
375 | 382 |
} |
376 |
|
|
383 |
|
|
377 | 384 |
|
378 | 385 |
protected MarkerType getNoLastActionMarkerType(IndexFungorumImportState state) { |
379 |
return getMarkerType(state, DbLastActionMapper.uuidMarkerTypeHasNoLastAction,
|
|
386 |
return getMarkerType(state, DbLastActionMapper.uuidMarkerTypeHasNoLastAction, |
|
380 | 387 |
"has no last action", "No last action information available", "no last action"); |
381 | 388 |
} |
382 | 389 |
|
... | ... | |
388 | 395 |
String strId = (id == null ? null : String.valueOf(id)); |
389 | 396 |
IdentifiableSource source = IdentifiableSource.NewInstance(OriginalSourceType.Import, strId, namespace, sourceReference, null); |
390 | 397 |
taxon.addSource(source); |
391 |
|
|
398 |
|
|
392 | 399 |
//no last action |
393 | 400 |
MarkerType hasNoLastAction = getNoLastActionMarkerType(state); |
394 | 401 |
taxon.addMarker(Marker.NewInstance(hasNoLastAction, true)); |
... | ... | |
415 | 422 |
MarkerType missingGUID = getMarkerType(state, PesiTransformer.uuidMarkerGuidIsMissing, "GUID is missing", "GUID is missing", null); |
416 | 423 |
return missingGUID; |
417 | 424 |
} |
418 |
|
|
425 |
|
|
419 | 426 |
|
420 | 427 |
protected Classification getClassification(IndexFungorumImportState state) { |
421 | 428 |
Classification result; |
... | ... | |
425 | 432 |
result = makeTreeMemSave(state, sourceReference); |
426 | 433 |
} else { |
427 | 434 |
result = getClassificationService().find(classificationUuid); |
428 |
}
|
|
435 |
} |
|
429 | 436 |
return result; |
430 | 437 |
} |
431 | 438 |
|
432 |
|
|
433 | 439 |
|
434 | 440 |
|
435 |
|
|
441 |
|
|
442 |
|
|
436 | 443 |
} |
Also available in: Unified diff