1
|
/**
|
2
|
* Copyright (C) 2007 EDIT
|
3
|
* European Distributed Institute of Taxonomy
|
4
|
* http://www.e-taxonomy.eu
|
5
|
*
|
6
|
* The contents of this file are subject to the Mozilla Public License Version 1.1
|
7
|
* See LICENSE.TXT at the top of this package for the full license terms.
|
8
|
*/
|
9
|
|
10
|
package eu.etaxonomy.cdm.io.algaterra;
|
11
|
|
12
|
import java.sql.ResultSet;
|
13
|
import java.sql.SQLException;
|
14
|
import java.sql.Timestamp;
|
15
|
import java.util.HashMap;
|
16
|
import java.util.HashSet;
|
17
|
import java.util.Map;
|
18
|
import java.util.Set;
|
19
|
import java.util.UUID;
|
20
|
|
21
|
import org.apache.commons.lang.StringUtils;
|
22
|
import org.apache.log4j.Logger;
|
23
|
import org.joda.time.DateTime;
|
24
|
import org.springframework.stereotype.Component;
|
25
|
|
26
|
import eu.etaxonomy.cdm.api.facade.DerivedUnitFacade;
|
27
|
import eu.etaxonomy.cdm.api.facade.DerivedUnitFacadeNotSupportedException;
|
28
|
import eu.etaxonomy.cdm.io.algaterra.validation.AlgaTerraTypeImportValidator;
|
29
|
import eu.etaxonomy.cdm.io.berlinModel.in.BerlinModelImportBase;
|
30
|
import eu.etaxonomy.cdm.io.berlinModel.in.BerlinModelImportConfigurator;
|
31
|
import eu.etaxonomy.cdm.io.berlinModel.in.BerlinModelImportState;
|
32
|
import eu.etaxonomy.cdm.io.berlinModel.in.BerlinModelRefDetailImport;
|
33
|
import eu.etaxonomy.cdm.io.berlinModel.in.BerlinModelReferenceImport;
|
34
|
import eu.etaxonomy.cdm.io.berlinModel.in.BerlinModelTaxonNameImport;
|
35
|
import eu.etaxonomy.cdm.io.common.IImportConfigurator.EDITOR;
|
36
|
import eu.etaxonomy.cdm.io.common.IOValidator;
|
37
|
import eu.etaxonomy.cdm.io.common.ResultSetPartitioner;
|
38
|
import eu.etaxonomy.cdm.model.common.AnnotatableEntity;
|
39
|
import eu.etaxonomy.cdm.model.common.Annotation;
|
40
|
import eu.etaxonomy.cdm.model.common.AnnotationType;
|
41
|
import eu.etaxonomy.cdm.model.common.CdmBase;
|
42
|
import eu.etaxonomy.cdm.model.common.DefinedTerm;
|
43
|
import eu.etaxonomy.cdm.model.common.IdentifiableSource;
|
44
|
import eu.etaxonomy.cdm.model.common.Language;
|
45
|
import eu.etaxonomy.cdm.model.common.User;
|
46
|
import eu.etaxonomy.cdm.model.name.BotanicalName;
|
47
|
import eu.etaxonomy.cdm.model.name.Rank;
|
48
|
import eu.etaxonomy.cdm.model.name.SpecimenTypeDesignation;
|
49
|
import eu.etaxonomy.cdm.model.name.SpecimenTypeDesignationStatus;
|
50
|
import eu.etaxonomy.cdm.model.name.TaxonNameBase;
|
51
|
import eu.etaxonomy.cdm.model.occurrence.Collection;
|
52
|
import eu.etaxonomy.cdm.model.occurrence.DerivedUnit;
|
53
|
import eu.etaxonomy.cdm.model.occurrence.FieldUnit;
|
54
|
import eu.etaxonomy.cdm.model.occurrence.SpecimenOrObservationType;
|
55
|
import eu.etaxonomy.cdm.model.reference.Reference;
|
56
|
|
57
|
/**
|
58
|
* @author a.mueller
|
59
|
* @created 20.03.2008
|
60
|
*/
|
61
|
@Component
|
62
|
public class AlgaTerraTypeImport extends AlgaTerraSpecimenImportBase {
|
63
|
private static final Logger logger = Logger.getLogger(AlgaTerraTypeImport.class);
|
64
|
|
65
|
|
66
|
private static int modCount = 5000;
|
67
|
private static final String pluralString = "types";
|
68
|
private static final String dbTableName = "TypeDesignation"; //??
|
69
|
|
70
|
@Override
|
71
|
protected String getLocalityString(){
|
72
|
return "TypeLocality";
|
73
|
}
|
74
|
|
75
|
public AlgaTerraTypeImport(){
|
76
|
super(dbTableName, pluralString);
|
77
|
}
|
78
|
|
79
|
|
80
|
@Override
|
81
|
protected String getIdQuery(BerlinModelImportState state) {
|
82
|
String result = " SELECT TypeDesignationId "
|
83
|
+ " FROM TypeDesignation "
|
84
|
+ " ORDER BY NameFk ";
|
85
|
return result;
|
86
|
}
|
87
|
|
88
|
@Override
|
89
|
protected String getRecordQuery(BerlinModelImportConfigurator config) {
|
90
|
String strQuery =
|
91
|
|
92
|
" SELECT ts.*, ts.TypeSpecimenId as unitId, td.*, gz.ID as GazetteerId, gz.L1Code, gz.L2Code, gz.L3Code, gz.L4Code, gz.ISOCountry, gz.Country, gz.subL4, ts.WaterBody, " +
|
93
|
" ts.RefFk as tsRefFk, ts.RefDetailFk as tsRefDetailFk, ts.MaterialCategoryFK as tsMaterialCategoryFK, td.RefFk as tdRefFk, td.RefDetailFk as tdRefDetailFk, " +
|
94
|
" RefDet.Details as tdRefDetails, " +
|
95
|
" td.created_When as tdCreated_When, tsd.created_When as tsdCreated_When, td.updated_when as tdUpdated_when, " +
|
96
|
" td.created_who as tdCreated_who, tsd.created_who as tsdCreated_who, td.updated_who tdUpdated_who, " +
|
97
|
" mc.* " +
|
98
|
" FROM TypeSpecimenDesignation tsd "
|
99
|
+ " LEFT OUTER JOIN TypeSpecimen AS ts ON tsd.TypeSpecimenFk = ts.TypeSpecimenId "
|
100
|
+ " FULL OUTER JOIN TypeDesignation td ON td.TypeDesignationId = tsd.TypeDesignationFk "
|
101
|
+ " LEFT OUTER JOIN TDWGGazetteer gz ON ts.TDWGGazetteerFk = gz.ID "
|
102
|
+ " LEFT OUTER JOIN RefDetail refDet ON td.RefDetailFk = refDet.RefDetailId AND td.RefFk = refDet.RefFk "
|
103
|
+ " LEFT OUTER JOIN MaterialCategory mc ON mc.MaterialCategoryId = ts.MaterialCategoryFK "
|
104
|
+ " WHERE (td.TypeDesignationId IN (" + ID_LIST_TOKEN + ") )"
|
105
|
+ " ORDER BY NameFk "
|
106
|
;
|
107
|
return strQuery;
|
108
|
}
|
109
|
|
110
|
@Override
|
111
|
public boolean doPartition(ResultSetPartitioner partitioner, BerlinModelImportState bmState) {
|
112
|
boolean success = true;
|
113
|
|
114
|
AlgaTerraImportState state = (AlgaTerraImportState)bmState;
|
115
|
|
116
|
//TODO check that no duplicate vocabularies will be created, also remove redundant code here
|
117
|
// and in Specimen importer
|
118
|
try {
|
119
|
makeVocabulariesAndFeatures(state);
|
120
|
} catch (SQLException e1) {
|
121
|
logger.warn("Exception occurred when trying to create Type specimen vocabularies: " + e1.getMessage());
|
122
|
e1.printStackTrace();
|
123
|
}
|
124
|
|
125
|
|
126
|
|
127
|
Set<TaxonNameBase> namesToSave = new HashSet<TaxonNameBase>();
|
128
|
|
129
|
Map<String, TaxonNameBase> taxonNameMap = partitioner.getObjectMap(BerlinModelTaxonNameImport.NAMESPACE);
|
130
|
Map<String, DerivedUnit> ecoFactMap = partitioner.getObjectMap(AlgaTerraEcoFactImport.ECO_FACT_FIELD_OBSERVATION_NAMESPACE);
|
131
|
Map<String, DerivedUnit> typeSpecimenMap = partitioner.getObjectMap(TYPE_SPECIMEN_FIELD_OBSERVATION_NAMESPACE);
|
132
|
Map<String, Reference> refMap = partitioner.getObjectMap(BerlinModelReferenceImport.REFERENCE_NAMESPACE);
|
133
|
Map<String, Reference> refDetailMap = partitioner.getObjectMap(BerlinModelRefDetailImport.REFDETAIL_NAMESPACE);
|
134
|
|
135
|
|
136
|
ResultSet rs = partitioner.getResultSet();
|
137
|
|
138
|
try {
|
139
|
|
140
|
int i = 0;
|
141
|
|
142
|
//for each reference
|
143
|
while (rs.next()){
|
144
|
|
145
|
if ((i++ % modCount) == 0 && i!= 1 ){ logger.info("Type designations handled: " + (i-1));}
|
146
|
|
147
|
int nameId = rs.getInt("nameFk");
|
148
|
int typeSpecimenId = rs.getInt("TypeSpecimenId");
|
149
|
int typeDesignationId = rs.getInt("TypeDesignationId");
|
150
|
Integer typeStatusFk = nullSafeInt(rs, "typeStatusFk");
|
151
|
Integer ecoFactId = nullSafeInt(rs, "ecoFactFk");
|
152
|
Integer tdRefFk = nullSafeInt(rs, "tdRefFk");
|
153
|
Integer tdRefDetailFk = nullSafeInt(rs, "tdRefDetailFk");
|
154
|
String tdRefDetails = rs.getString("tdRefDetails");
|
155
|
Boolean restrictedFlag = nullSafeBoolean(rs, "RestrictedFlag");
|
156
|
|
157
|
String typeSpecimenPhrase = rs.getString("TypeSpecimenPhrase");
|
158
|
Integer tsMaterialCategoryFK = nullSafeInt(rs, "MaterialCategoryFK");
|
159
|
|
160
|
boolean isIcon = typeSpecimenPhrase != null && typeSpecimenPhrase.toLowerCase().startsWith("\u005bicon");
|
161
|
|
162
|
try {
|
163
|
|
164
|
//source ref
|
165
|
Reference sourceRef = state.getTransactionalSourceReference();
|
166
|
|
167
|
//facade
|
168
|
SpecimenOrObservationType type = SpecimenOrObservationType.PreservedSpecimen;
|
169
|
if (isIcon){
|
170
|
//TODO handle images correctly for these specimen
|
171
|
type = SpecimenOrObservationType.StillImage;
|
172
|
}else if (typeStatusFk != null && typeStatusFk.equals(39)){
|
173
|
type = SpecimenOrObservationType.LivingSpecimen;
|
174
|
}else if (tsMaterialCategoryFK != null && tsMaterialCategoryFK.equals(4)){
|
175
|
type = SpecimenOrObservationType.Fossil;
|
176
|
}
|
177
|
|
178
|
|
179
|
if (tsMaterialCategoryFK != null && typeStatusFk != null &&
|
180
|
( typeStatusFk.equals(39) && !tsMaterialCategoryFK.equals(14) || ! typeStatusFk.equals(39) && tsMaterialCategoryFK.equals(14) )){
|
181
|
logger.warn("Living Specimen type status should be 39 and materialCategoryFk 14 but one of them wasn't");
|
182
|
}
|
183
|
|
184
|
|
185
|
DerivedUnitFacade facade = getDerivedUnit(state, typeSpecimenId, typeSpecimenMap, type, ecoFactMap, ecoFactId, sourceRef);
|
186
|
|
187
|
//field observation
|
188
|
handleFieldObservationSpecimen(rs, facade, state, partitioner);
|
189
|
|
190
|
// handleTypeSpecimenSpecificFieldObservation(rs,facade, state);
|
191
|
|
192
|
//TODO divide like in EcoFact (if necessary)
|
193
|
handleTypeSpecimenSpecificSpecimen(rs,facade, state, refMap, typeSpecimenId);
|
194
|
|
195
|
handleFirstDerivedSpecimen(rs, facade, state, partitioner);
|
196
|
|
197
|
|
198
|
//Designation
|
199
|
TaxonNameBase<?,?> name = getTaxonName(state, taxonNameMap, nameId);
|
200
|
SpecimenTypeDesignation designation = SpecimenTypeDesignation.NewInstance();
|
201
|
SpecimenTypeDesignationStatus status = getSpecimenTypeDesignationStatusByKey(typeStatusFk);
|
202
|
if (typeStatusFk != null && typeStatusFk.equals(39)){
|
203
|
designation.addAnnotation(Annotation.NewInstance("Type status: Authentic strain", AnnotationType.EDITORIAL(), Language.DEFAULT()));
|
204
|
}
|
205
|
|
206
|
designation.setTypeSpecimen(facade.innerDerivedUnit());
|
207
|
designation.setTypeStatus(status);
|
208
|
if (tdRefFk != null){
|
209
|
Reference typeDesigRef = getReferenceFromMaps(refDetailMap, refMap, String.valueOf(tdRefDetailFk), String.valueOf(tdRefFk));
|
210
|
if (typeDesigRef == null){
|
211
|
logger.warn("Type designation reference not found in maps: " + tdRefFk);
|
212
|
}else{
|
213
|
designation.setCitation(typeDesigRef);
|
214
|
}
|
215
|
}
|
216
|
if (isNotBlank(tdRefDetails)){
|
217
|
designation.setCitationMicroReference(tdRefDetails);
|
218
|
}
|
219
|
|
220
|
//ID: Type designations do not allow OriginalSources
|
221
|
designation.addAnnotation(Annotation.NewInstance("Id in BerlinModel-TypeDesignation: " + String.valueOf(typeDesignationId), AnnotationType.TECHNICAL(), Language.UNDETERMINED()));
|
222
|
|
223
|
if (restrictedFlag != null &&restrictedFlag.equals(true)){
|
224
|
logger.warn("Restricted Flag is expected to be null or 0. TypeDesignationId" + typeDesignationId);
|
225
|
}
|
226
|
|
227
|
//Created, Updated
|
228
|
this.doCreatedUpdated(state, designation, rs);
|
229
|
|
230
|
if (name != null){
|
231
|
name.addTypeDesignation(designation, true); //TODO check if true is correct
|
232
|
}else{
|
233
|
logger.warn("Name could not be found for type designation " + typeDesignationId);
|
234
|
}
|
235
|
namesToSave.add(name);
|
236
|
|
237
|
|
238
|
} catch (Exception e) {
|
239
|
logger.warn("Exception in TypeDesignation: TypeDesignationId " + typeDesignationId + ". " + e.getMessage());
|
240
|
e.printStackTrace();
|
241
|
}
|
242
|
|
243
|
}
|
244
|
|
245
|
// logger.warn("Specimen: " + countSpecimen + ", Descriptions: " + countDescriptions );
|
246
|
|
247
|
logger.warn("Names to save: " + namesToSave.size());
|
248
|
getNameService().save(namesToSave);
|
249
|
|
250
|
return success;
|
251
|
} catch (SQLException e) {
|
252
|
logger.error("SQLException:" + e);
|
253
|
return false;
|
254
|
}
|
255
|
}
|
256
|
|
257
|
/**
|
258
|
* same as {@link BerlinModelImportBase#doCreatedUpdatedNotes}, but handles multiple similar fields
|
259
|
* @throws SQLException
|
260
|
*/
|
261
|
private void doCreatedUpdated(BerlinModelImportState state, AnnotatableEntity annotatableEntity, ResultSet rs) throws SQLException{
|
262
|
BerlinModelImportConfigurator config = state.getConfig();
|
263
|
Object createdWhen = rs.getObject("tsdCreated_When");
|
264
|
Object tdCreatedWhen = rs.getObject("tdCreated_When");
|
265
|
if (tdCreatedWhen != null){
|
266
|
createdWhen = tdCreatedWhen;
|
267
|
}
|
268
|
|
269
|
String createdWho = rs.getString("tsdCreated_Who");
|
270
|
String tdCreatedWho = rs.getString("tdCreated_Who");
|
271
|
if (tdCreatedWho != null){
|
272
|
createdWho = tdCreatedWho;
|
273
|
}
|
274
|
|
275
|
Object updatedWhen = rs.getObject("tdUpdated_When");
|
276
|
String updatedWho = rs.getString("tdUpdated_who");
|
277
|
|
278
|
//Created When, Who, Updated When Who
|
279
|
if (config.getEditor() == null || config.getEditor().equals(EDITOR.NO_EDITORS)){
|
280
|
//do nothing
|
281
|
}else if (config.getEditor().equals(EDITOR.EDITOR_AS_ANNOTATION)){
|
282
|
String createdAnnotationString = "Berlin Model record was created By: " + String.valueOf(createdWho) + " (" + String.valueOf(createdWhen) + ") ";
|
283
|
if (updatedWhen != null && updatedWho != null){
|
284
|
createdAnnotationString += " and updated By: " + String.valueOf(updatedWho) + " (" + String.valueOf(updatedWhen) + ")";
|
285
|
}
|
286
|
Annotation annotation = Annotation.NewInstance(createdAnnotationString, Language.DEFAULT());
|
287
|
annotation.setCommentator(config.getCommentator());
|
288
|
annotation.setAnnotationType(AnnotationType.TECHNICAL());
|
289
|
annotatableEntity.addAnnotation(annotation);
|
290
|
}else if (config.getEditor().equals(EDITOR.EDITOR_AS_EDITOR)){
|
291
|
User creator = getUser(state, createdWho);
|
292
|
User updator = getUser(state, updatedWho);
|
293
|
DateTime created = getDateTime(createdWhen);
|
294
|
DateTime updated = getDateTime(updatedWhen);
|
295
|
annotatableEntity.setCreatedBy(creator);
|
296
|
annotatableEntity.setUpdatedBy(updator);
|
297
|
annotatableEntity.setCreated(created);
|
298
|
annotatableEntity.setUpdated(updated);
|
299
|
}else {
|
300
|
logger.warn("Editor type not yet implemented: " + config.getEditor());
|
301
|
}
|
302
|
}
|
303
|
|
304
|
|
305
|
private DateTime getDateTime(Object timeString){
|
306
|
if (timeString == null){
|
307
|
return null;
|
308
|
}
|
309
|
DateTime dateTime = null;
|
310
|
if (timeString instanceof Timestamp){
|
311
|
Timestamp timestamp = (Timestamp)timeString;
|
312
|
dateTime = new DateTime(timestamp);
|
313
|
}else{
|
314
|
logger.warn("time ("+timeString+") is not a timestamp. Datetime set to current date. ");
|
315
|
dateTime = new DateTime();
|
316
|
}
|
317
|
return dateTime;
|
318
|
}
|
319
|
|
320
|
|
321
|
@Override
|
322
|
protected String getDerivedUnitNameSpace(){
|
323
|
return TYPE_SPECIMEN_DERIVED_UNIT_NAMESPACE;
|
324
|
}
|
325
|
|
326
|
@Override
|
327
|
protected String getFieldObservationNameSpace(){
|
328
|
return TYPE_SPECIMEN_FIELD_OBSERVATION_NAMESPACE;
|
329
|
}
|
330
|
|
331
|
/**
|
332
|
* @param state
|
333
|
* @param taxonNameMap
|
334
|
* @param nameId
|
335
|
* @return
|
336
|
*/
|
337
|
private TaxonNameBase<?,?> getTaxonName(AlgaTerraImportState state, Map<String, TaxonNameBase> taxonNameMap, int nameId) {
|
338
|
TaxonNameBase<?,?> result;
|
339
|
if (state.getConfig().isDoTaxonNames()){
|
340
|
result = taxonNameMap.get(String.valueOf(nameId));
|
341
|
}else{
|
342
|
//for testing
|
343
|
result = BotanicalName.NewInstance(Rank.SPECIES());
|
344
|
}
|
345
|
return result;
|
346
|
}
|
347
|
|
348
|
private void handleTypeSpecimenSpecificSpecimen(ResultSet rs, DerivedUnitFacade facade, AlgaTerraImportState state, Map<String, Reference> refMap, int typeSpecimenId) throws SQLException {
|
349
|
|
350
|
|
351
|
//TODO
|
352
|
|
353
|
|
354
|
|
355
|
DerivedUnit derivedUnit = facade.innerDerivedUnit();
|
356
|
|
357
|
Integer tsMaterialCategoryFK = nullSafeInt(rs, "tsMaterialCategoryFK");
|
358
|
String matCat = rs.getString("MaterialCategory");
|
359
|
if (tsMaterialCategoryFK != null){
|
360
|
if (tsMaterialCategoryFK.equals(16)){
|
361
|
tsMaterialCategoryFK = 9;
|
362
|
}
|
363
|
UUID uuid = materialCategoryMapping.get(tsMaterialCategoryFK);
|
364
|
if (uuid == null){
|
365
|
logger.warn("Uuid was null. This should not happen.");
|
366
|
}
|
367
|
DefinedTerm kindOfUnit = getKindOfUnit(state, uuid, matCat, null, null, null); //all terms should exist already
|
368
|
facade.setKindOfUnit(kindOfUnit);
|
369
|
}else{
|
370
|
logger.warn("Material Category was null. This is not expected");
|
371
|
}
|
372
|
|
373
|
|
374
|
//collection
|
375
|
String barcode = rs.getString("Barcode");
|
376
|
if (StringUtils.isNotBlank(barcode)){
|
377
|
facade.setBarcode(barcode);
|
378
|
}
|
379
|
|
380
|
//RefFk + RefDetailFk
|
381
|
Integer refFk = nullSafeInt(rs, "tsRefFk");
|
382
|
if (refFk != null){
|
383
|
|
384
|
Reference ref = refMap.get(String.valueOf(refFk));
|
385
|
if (ref == null){
|
386
|
logger.warn("TypeSpecimen reference (" + refFk + ")not found in biblioRef. TypeSpecimenId: " + typeSpecimenId);
|
387
|
}else{
|
388
|
IdentifiableSource source = IdentifiableSource.NewPrimarySourceInstance(ref, null);
|
389
|
derivedUnit.addSource(source);
|
390
|
}
|
391
|
}
|
392
|
|
393
|
Integer refDetailFk = nullSafeInt(rs, "tsRefDetailFk");
|
394
|
if (refDetailFk != null){
|
395
|
logger.warn("TypeSpecimen.RefDetailFk should always be NULL but wasn't: " + typeSpecimenId);
|
396
|
}
|
397
|
|
398
|
}
|
399
|
|
400
|
/**
|
401
|
* @param state
|
402
|
* @param ecoFactId
|
403
|
* @param derivedUnitMap
|
404
|
* @param type
|
405
|
* @param ecoFactId2
|
406
|
* @param ecoFactMap
|
407
|
* @param sourceRef
|
408
|
* @return
|
409
|
*/
|
410
|
private DerivedUnitFacade getDerivedUnit(AlgaTerraImportState state, int typeSpecimenId, Map<String, DerivedUnit> typeSpecimenMap, SpecimenOrObservationType type, Map<String, DerivedUnit> ecoFactMap, Integer ecoFactId2, Reference sourceRef) {
|
411
|
//TODO implement ecoFact map - if not all null anymore
|
412
|
String typeKey = String.valueOf(typeSpecimenId);
|
413
|
DerivedUnit derivedUnit = typeSpecimenMap.get(typeKey);
|
414
|
DerivedUnitFacade facade;
|
415
|
if (derivedUnit == null){
|
416
|
facade = DerivedUnitFacade.NewInstance(type);
|
417
|
typeSpecimenMap.put(typeKey, derivedUnit);
|
418
|
}else{
|
419
|
try {
|
420
|
facade = DerivedUnitFacade.NewInstance(derivedUnit);
|
421
|
facade.addSource(IdentifiableSource.NewDataImportInstance(typeKey, "TypeSpecimen", sourceRef));
|
422
|
} catch (DerivedUnitFacadeNotSupportedException e) {
|
423
|
logger.error(e.getMessage());
|
424
|
facade = DerivedUnitFacade.NewInstance(type);
|
425
|
}
|
426
|
}
|
427
|
|
428
|
return facade;
|
429
|
}
|
430
|
|
431
|
|
432
|
private SpecimenTypeDesignationStatus getSpecimenTypeDesignationStatusByKey(Integer typeStatusFk) {
|
433
|
if (typeStatusFk == null){ return SpecimenTypeDesignationStatus.TYPE();
|
434
|
}else if (typeStatusFk == 1) { return SpecimenTypeDesignationStatus.HOLOTYPE();
|
435
|
}else if (typeStatusFk == 2) { return SpecimenTypeDesignationStatus.LECTOTYPE();
|
436
|
}else if (typeStatusFk == 3) { return SpecimenTypeDesignationStatus.NEOTYPE();
|
437
|
}else if (typeStatusFk == 4) { return SpecimenTypeDesignationStatus.EPITYPE();
|
438
|
}else if (typeStatusFk == 5) { return SpecimenTypeDesignationStatus.ISOLECTOTYPE();
|
439
|
}else if (typeStatusFk == 6) { return SpecimenTypeDesignationStatus.ISONEOTYPE();
|
440
|
}else if (typeStatusFk == 7) { return SpecimenTypeDesignationStatus.ISOTYPE();
|
441
|
}else if (typeStatusFk == 8) { return SpecimenTypeDesignationStatus.PARANEOTYPE();
|
442
|
}else if (typeStatusFk == 9) { return SpecimenTypeDesignationStatus.PARATYPE();
|
443
|
}else if (typeStatusFk == 10) { return SpecimenTypeDesignationStatus.SECOND_STEP_LECTOTYPE();
|
444
|
}else if (typeStatusFk == 11) { return SpecimenTypeDesignationStatus.SECOND_STEP_NEOTYPE();
|
445
|
}else if (typeStatusFk == 12) { return SpecimenTypeDesignationStatus.SYNTYPE();
|
446
|
}else if (typeStatusFk == 13) { return SpecimenTypeDesignationStatus.PARALECTOTYPE();
|
447
|
}else if (typeStatusFk == 14) { return SpecimenTypeDesignationStatus.ISOEPITYPE();
|
448
|
}else if (typeStatusFk == 21) { return SpecimenTypeDesignationStatus.ICONOTYPE();
|
449
|
}else if (typeStatusFk == 22) { return SpecimenTypeDesignationStatus.PHOTOTYPE();
|
450
|
}else if (typeStatusFk == 30) { return SpecimenTypeDesignationStatus.TYPE();
|
451
|
}else if (typeStatusFk == 38) { return SpecimenTypeDesignationStatus.ISOEPITYPE();
|
452
|
}else if (typeStatusFk == 39) { return SpecimenTypeDesignationStatus.ORIGINAL_MATERIAL(); //but add annotation
|
453
|
}else if (typeStatusFk == 40) { return SpecimenTypeDesignationStatus.ORIGINAL_MATERIAL();
|
454
|
}else{
|
455
|
logger.warn("typeStatusFk undefined for " + typeStatusFk);
|
456
|
return SpecimenTypeDesignationStatus.TYPE();
|
457
|
}
|
458
|
|
459
|
}
|
460
|
|
461
|
|
462
|
@Override
|
463
|
public Map<Object, Map<String, ? extends CdmBase>> getRelatedObjectsForPartition(ResultSet rs, BerlinModelImportState state) {
|
464
|
String nameSpace;
|
465
|
Class<?> cdmClass;
|
466
|
Set<String> idSet;
|
467
|
Map<Object, Map<String, ? extends CdmBase>> result = new HashMap<Object, Map<String, ? extends CdmBase>>();
|
468
|
|
469
|
try{
|
470
|
Set<String> nameIdSet = new HashSet<String>();
|
471
|
Set<String> ecoFieldObservationIdSet = new HashSet<String>();
|
472
|
Set<String> typeSpecimenIdSet = new HashSet<String>();
|
473
|
// Set<String> termsIdSet = new HashSet<String>();
|
474
|
Set<String> collectionIdSet = new HashSet<String>();
|
475
|
Set<String> referenceIdSet = new HashSet<String>();
|
476
|
Set<String> refDetailIdSet = new HashSet<String>();
|
477
|
|
478
|
while (rs.next()){
|
479
|
handleForeignKey(rs, nameIdSet, "nameFk");
|
480
|
handleForeignKey(rs, ecoFieldObservationIdSet, "ecoFactFk");
|
481
|
handleForeignKey(rs, typeSpecimenIdSet, "TypeSpecimenId");
|
482
|
handleForeignKey(rs, collectionIdSet, "CollectionFk");
|
483
|
handleForeignKey(rs, referenceIdSet, "tsRefFk");
|
484
|
handleForeignKey(rs, referenceIdSet, "tdRefFk");
|
485
|
handleForeignKey(rs, refDetailIdSet, "tdRefDetailFk");
|
486
|
}
|
487
|
|
488
|
//name map
|
489
|
nameSpace = BerlinModelTaxonNameImport.NAMESPACE;
|
490
|
cdmClass = TaxonNameBase.class;
|
491
|
idSet = nameIdSet;
|
492
|
Map<String, TaxonNameBase> objectMap = (Map<String, TaxonNameBase>)getCommonService().getSourcedObjectsByIdInSource(cdmClass, idSet, nameSpace);
|
493
|
result.put(nameSpace, objectMap);
|
494
|
|
495
|
//eco fact field observation map
|
496
|
nameSpace = AlgaTerraTypeImport.ECO_FACT_FIELD_OBSERVATION_NAMESPACE;
|
497
|
cdmClass = FieldUnit.class;
|
498
|
idSet = ecoFieldObservationIdSet;
|
499
|
Map<String, FieldUnit> fieldObservationMap = (Map<String, FieldUnit>)getCommonService().getSourcedObjectsByIdInSource(cdmClass, idSet, nameSpace);
|
500
|
result.put(nameSpace, fieldObservationMap);
|
501
|
|
502
|
//type specimen map
|
503
|
nameSpace = AlgaTerraTypeImport.TYPE_SPECIMEN_FIELD_OBSERVATION_NAMESPACE;
|
504
|
cdmClass = FieldUnit.class;
|
505
|
idSet = typeSpecimenIdSet;
|
506
|
Map<String, FieldUnit> typeSpecimenMap = (Map<String, FieldUnit>)getCommonService().getSourcedObjectsByIdInSource(cdmClass, idSet, nameSpace);
|
507
|
result.put(nameSpace, typeSpecimenMap);
|
508
|
|
509
|
|
510
|
//collections
|
511
|
nameSpace = AlgaTerraCollectionImport.NAMESPACE_COLLECTION;
|
512
|
cdmClass = Collection.class;
|
513
|
idSet = collectionIdSet;
|
514
|
Map<String, Collection> collectionMap = (Map<String, Collection>)getCommonService().getSourcedObjectsByIdInSource(cdmClass, idSet, nameSpace);
|
515
|
result.put(nameSpace, collectionMap);
|
516
|
|
517
|
//sub-collections
|
518
|
nameSpace = AlgaTerraCollectionImport.NAMESPACE_SUBCOLLECTION;
|
519
|
cdmClass = Collection.class;
|
520
|
idSet = collectionIdSet;
|
521
|
Map<String, Collection> subCollectionMap = (Map<String, Collection>)getCommonService().getSourcedObjectsByIdInSource(cdmClass, idSet, nameSpace);
|
522
|
result.put(nameSpace, subCollectionMap);
|
523
|
|
524
|
//reference map
|
525
|
nameSpace = BerlinModelReferenceImport.REFERENCE_NAMESPACE;
|
526
|
cdmClass = Reference.class;
|
527
|
idSet = referenceIdSet;
|
528
|
Map<String, Reference> referenceMap = (Map<String, Reference>)getCommonService().getSourcedObjectsByIdInSource(cdmClass, idSet, nameSpace);
|
529
|
result.put(nameSpace, referenceMap);
|
530
|
|
531
|
//refDetail map
|
532
|
nameSpace = BerlinModelRefDetailImport.REFDETAIL_NAMESPACE;
|
533
|
cdmClass = Reference.class;
|
534
|
idSet = refDetailIdSet;
|
535
|
Map<String, Reference> refDetailMap= (Map<String, Reference>)getCommonService().getSourcedObjectsByIdInSource(cdmClass, idSet, nameSpace);
|
536
|
result.put(nameSpace, refDetailMap);
|
537
|
|
538
|
|
539
|
|
540
|
} catch (SQLException e) {
|
541
|
throw new RuntimeException(e);
|
542
|
}
|
543
|
return result;
|
544
|
}
|
545
|
|
546
|
/* (non-Javadoc)
|
547
|
* @see eu.etaxonomy.cdm.io.common.CdmIoBase#doCheck(eu.etaxonomy.cdm.io.common.IoStateBase)
|
548
|
*/
|
549
|
@Override
|
550
|
protected boolean doCheck(BerlinModelImportState state){
|
551
|
IOValidator<BerlinModelImportState> validator = new AlgaTerraTypeImportValidator();
|
552
|
return validator.validate(state);
|
553
|
}
|
554
|
|
555
|
|
556
|
/* (non-Javadoc)
|
557
|
* @see eu.etaxonomy.cdm.io.common.CdmIoBase#isIgnore(eu.etaxonomy.cdm.io.common.IImportConfigurator)
|
558
|
*/
|
559
|
@Override
|
560
|
protected boolean isIgnore(BerlinModelImportState state){
|
561
|
return ! state.getConfig().isDoTypes();
|
562
|
}
|
563
|
|
564
|
}
|