Revision 1a0cbb31
Added by Andreas Müller about 16 years ago
.gitattributes | ||
---|---|---|
46 | 46 |
cdmlib-io/src/main/java/eu/etaxonomy/cdm/io/berlinModel/BerlinModelReferenceIO.java -text |
47 | 47 |
cdmlib-io/src/main/java/eu/etaxonomy/cdm/io/berlinModel/BerlinModelTaxonIO.java -text |
48 | 48 |
cdmlib-io/src/main/java/eu/etaxonomy/cdm/io/berlinModel/BerlinModelTaxonNameIO.java -text |
49 |
cdmlib-io/src/main/java/eu/etaxonomy/cdm/io/berlinModel/BerlinModelTaxonNameRelationIO.java -text |
|
50 |
cdmlib-io/src/main/java/eu/etaxonomy/cdm/io/berlinModel/BerlinModelTaxonRelationIO.java -text |
|
49 | 51 |
cdmlib-io/src/main/java/eu/etaxonomy/cdm/io/berlinModel/BerlinModelTransformer.java -text |
50 | 52 |
cdmlib-io/src/main/java/eu/etaxonomy/cdm/io/berlinModel/BerlinModelTypesIO.java -text |
51 | 53 |
cdmlib-io/src/main/java/eu/etaxonomy/cdm/io/berlinModel/CdmBooleanMapper.java -text |
cdmlib-io/src/main/java/eu/etaxonomy/cdm/io/berlinModel/BerlinModelImport.java | ||
---|---|---|
7 | 7 |
|
8 | 8 |
import eu.etaxonomy.cdm.api.application.CdmApplicationController; |
9 | 9 |
import eu.etaxonomy.cdm.api.service.IService; |
10 |
import eu.etaxonomy.cdm.database.DataSourceNotFoundException; |
|
11 | 10 |
import eu.etaxonomy.cdm.io.common.MapWrapper; |
12 | 11 |
import eu.etaxonomy.cdm.io.common.Source; |
13 | 12 |
import eu.etaxonomy.cdm.model.agent.TeamOrPersonBase; |
14 |
import eu.etaxonomy.cdm.model.common.init.TermNotFoundException; |
|
15 | 13 |
import eu.etaxonomy.cdm.model.name.TaxonNameBase; |
16 | 14 |
import eu.etaxonomy.cdm.model.reference.ReferenceBase; |
17 | 15 |
import eu.etaxonomy.cdm.model.taxon.TaxonBase; |
... | ... | |
81 | 79 |
|
82 | 80 |
//check RelNames |
83 | 81 |
if(bmiConfig.isDoRelNames()){ |
84 |
result &= BerlinModelTaxonNameIO.checkRelations(bmiConfig);
|
|
82 |
result &= BerlinModelTaxonNameRelationIO.check(bmiConfig);
|
|
85 | 83 |
} |
86 | 84 |
|
87 | 85 |
//check nameFacts |
... | ... | |
106 | 104 |
|
107 | 105 |
//check RelPTaxa |
108 | 106 |
if(bmiConfig.isDoRelTaxa()){ |
109 |
result &= BerlinModelTaxonIO.checkRelations(bmiConfig);
|
|
107 |
result &= BerlinModelTaxonRelationIO.check(bmiConfig);
|
|
110 | 108 |
} |
111 | 109 |
|
112 | 110 |
//check Facts |
... | ... | |
184 | 182 |
|
185 | 183 |
//make and save RelNames |
186 | 184 |
if(bmiConfig.isDoRelNames()){ |
187 |
if (! BerlinModelTaxonNameIO.invokeRelations(bmiConfig, cdmApp, taxonNameStore, referenceStore)){
|
|
185 |
if (! BerlinModelTaxonNameRelationIO.invoke(bmiConfig, cdmApp, taxonNameStore, referenceStore)){
|
|
188 | 186 |
return false; |
189 | 187 |
} |
190 | 188 |
}else{ |
... | ... | |
231 | 229 |
|
232 | 230 |
//make and save RelPTaxa |
233 | 231 |
if(bmiConfig.isDoRelTaxa()){ |
234 |
if (! BerlinModelTaxonIO.invokeRelations(bmiConfig, cdmApp, taxonStore, referenceStore)){
|
|
232 |
if (! BerlinModelTaxonRelationIO.invoke(bmiConfig, cdmApp, taxonStore, referenceStore)){
|
|
235 | 233 |
return false; |
236 | 234 |
} |
237 | 235 |
}else{ |
cdmlib-io/src/main/java/eu/etaxonomy/cdm/io/berlinModel/BerlinModelTaxonIO.java | ||
---|---|---|
43 | 43 |
return result; |
44 | 44 |
} |
45 | 45 |
|
46 |
public static boolean checkRelations(BerlinModelImportConfigurator bmiConfig){ |
|
47 |
boolean result = true; |
|
48 |
logger.warn("Checking for TaxonRelations not yet fully implemented"); |
|
49 |
result &= checkTaxonStatus(bmiConfig); |
|
50 |
//result &= checkArticlesWithoutJournal(bmiConfig); |
|
51 |
|
|
52 |
return result; |
|
53 |
} |
|
54 |
|
|
55 |
private static boolean checkTaxonStatus(BerlinModelImportConfigurator bmiConfig){ |
|
56 |
try { |
|
57 |
boolean result = true; |
|
58 |
Source source = bmiConfig.getSource(); |
|
59 |
String strQueryPartOfJournal = " SELECT RelPTaxon.RelQualifierFk, RelPTaxon.relPTaxonId, PTaxon.PTNameFk, PTaxon.PTRefFk, PTaxon_1.PTNameFk AS Expr1, PTaxon.RIdentifier, PTaxon_1.RIdentifier AS Expr3, Name.FullNameCache " + |
|
60 |
" FROM RelPTaxon " + |
|
61 |
" INNER JOIN PTaxon ON RelPTaxon.PTNameFk1 = PTaxon.PTNameFk AND RelPTaxon.PTRefFk1 = PTaxon.PTRefFk " + |
|
62 |
" INNER JOIN PTaxon AS PTaxon_1 ON RelPTaxon.PTNameFk2 = PTaxon_1.PTNameFk AND RelPTaxon.PTRefFk2 = PTaxon_1.PTRefFk " + |
|
63 |
" INNER JOIN Name ON PTaxon.PTNameFk = Name.NameId " + |
|
64 |
" WHERE (dbo.PTaxon.StatusFk = 1) AND ((RelPTaxon.RelQualifierFk = 7) OR (RelPTaxon.RelQualifierFk = 6) OR (RelPTaxon.RelQualifierFk = 2)) "; |
|
65 |
ResultSet rs = source.getResultSet(strQueryPartOfJournal); |
|
66 |
boolean firstRow = true; |
|
67 |
int i = 0; |
|
68 |
while (rs.next()){ |
|
69 |
i++; |
|
70 |
if (firstRow){ |
|
71 |
System.out.println("========================================================"); |
|
72 |
logger.warn("There are taxa that have a 'is synonym of' - relationship but having taxon status 'accepted'!"); |
|
73 |
System.out.println("========================================================"); |
|
74 |
} |
|
75 |
int rIdentifier = rs.getInt("RIdentifier"); |
|
76 |
int nameFk = rs.getInt("PTNameFk"); |
|
77 |
int refFk = rs.getInt("PTRefFk"); |
|
78 |
int relPTaxonId = rs.getInt("relPTaxonId"); |
|
79 |
String taxonName = rs.getString("FullNameCache"); |
|
80 |
|
|
81 |
System.out.println("RIdentifier:" + rIdentifier + "\n name: " + nameFk + |
|
82 |
"\n taxonName: " + taxonName + "\n refId: " + refFk + "\n RelPTaxonId: " + relPTaxonId ); |
|
83 |
result = firstRow = false; |
|
84 |
} |
|
85 |
if (i > 0){ |
|
86 |
System.out.println(" "); |
|
87 |
} |
|
88 |
|
|
89 |
return result; |
|
90 |
} catch (SQLException e) { |
|
91 |
e.printStackTrace(); |
|
92 |
return false; |
|
93 |
} |
|
94 |
} |
|
95 |
|
|
96 |
|
|
97 | 46 |
public static boolean invoke(BerlinModelImportConfigurator bmiConfig, CdmApplicationController cdmApp, |
98 | 47 |
MapWrapper<TaxonBase> taxonMap, MapWrapper<TaxonNameBase> taxonNameMap, MapWrapper<ReferenceBase> referenceMap, MapWrapper<ReferenceBase> nomRefMap){ |
99 | 48 |
Source source = bmiConfig.getSource(); |
... | ... | |
103 | 52 |
logger.info("start makeTaxa ..."); |
104 | 53 |
|
105 | 54 |
ITaxonService taxonService = cdmApp.getTaxonService(); |
106 |
boolean delete = bmiConfig.isDeleteAll(); |
|
107 | 55 |
|
108 | 56 |
try { |
109 | 57 |
//get data from database |
... | ... | |
208 | 156 |
|
209 | 157 |
} |
210 | 158 |
|
211 |
|
|
212 |
public static boolean invokeRelations(BerlinModelImportConfigurator bmiConfig, CdmApplicationController cdmApp, |
|
213 |
MapWrapper<TaxonBase> taxonMap, MapWrapper<ReferenceBase> referenceMap){ |
|
214 |
|
|
215 |
Set<TaxonBase> taxonStore = new HashSet<TaxonBase>(); |
|
216 |
Source source = bmiConfig.getSource(); |
|
217 |
String dbAttrName; |
|
218 |
String cdmAttrName; |
|
219 |
|
|
220 |
logger.info("start makeTaxonRelationships ..."); |
|
221 |
|
|
222 |
ITaxonService taxonService = cdmApp.getTaxonService(); |
|
223 |
boolean delete = bmiConfig.isDeleteAll(); |
|
224 |
|
|
225 |
try { |
|
226 |
//get data from database |
|
227 |
String strQuery = |
|
228 |
" SELECT RelPTaxon.*, FromTaxon.RIdentifier as taxon1Id, ToTaxon.RIdentifier as taxon2Id " + |
|
229 |
" FROM PTaxon as FromTaxon INNER JOIN " + |
|
230 |
" RelPTaxon ON FromTaxon.PTNameFk = RelPTaxon.PTNameFk1 AND FromTaxon.PTRefFk = RelPTaxon.PTRefFk1 INNER JOIN " + |
|
231 |
" PTaxon AS ToTaxon ON RelPTaxon.PTNameFk2 = ToTaxon.PTNameFk AND RelPTaxon.PTRefFk2 = ToTaxon.PTRefFk "+ |
|
232 |
" WHERE (1=1)"; |
|
233 |
ResultSet rs = source.getResultSet(strQuery) ; |
|
234 |
|
|
235 |
int i = 0; |
|
236 |
//for each reference |
|
237 |
while (rs.next()){ |
|
238 |
|
|
239 |
if ((i++ % modCount) == 0){ logger.info("RelPTaxa handled: " + (i-1));} |
|
240 |
|
|
241 |
int relPTaxonId = rs.getInt("RelPTaxonId"); |
|
242 |
int taxon1Id = rs.getInt("taxon1Id"); |
|
243 |
int taxon2Id = rs.getInt("taxon2Id"); |
|
244 |
int relRefFk = rs.getInt("relRefFk"); |
|
245 |
int relQualifierFk = rs.getInt("relQualifierFk"); |
|
246 |
|
|
247 |
TaxonBase taxon1 = taxonMap.get(taxon1Id); |
|
248 |
TaxonBase taxon2 = taxonMap.get(taxon2Id); |
|
249 |
|
|
250 |
//TODO |
|
251 |
ReferenceBase citation = null; |
|
252 |
String microcitation = null; |
|
253 |
|
|
254 |
if (taxon2 != null && taxon1 != null){ |
|
255 |
if (relQualifierFk == TAX_REL_IS_INCLUDED_IN){ |
|
256 |
((Taxon)taxon2).addTaxonomicChild((Taxon)taxon1, citation, microcitation); |
|
257 |
}else if (relQualifierFk == TAX_REL_IS_SYNONYM_OF){ |
|
258 |
((Taxon)taxon2).addSynonym((Synonym)taxon1, SynonymRelationshipType.SYNONYM_OF()); |
|
259 |
}else if (relQualifierFk == TAX_REL_IS_HOMOTYPIC_SYNONYM_OF){ |
|
260 |
if (taxon1 instanceof Synonym){ |
|
261 |
((Taxon)taxon2).addHomotypicSynonym((Synonym)taxon1, citation, microcitation); |
|
262 |
}else{ |
|
263 |
logger.error("Taxon (ID = " + taxon1.getId()+ ", RIdentifier = " + taxon1Id + ") can't be casted to Synonym"); |
|
264 |
} |
|
265 |
}else if (relQualifierFk == TAX_REL_IS_HETEROTYPIC_SYNONYM_OF){ |
|
266 |
if (Synonym.class.isAssignableFrom(taxon1.getClass())){ |
|
267 |
((Taxon)taxon2).addSynonym((Synonym)taxon1, SynonymRelationshipType.HETEROTYPIC_SYNONYM_OF()); |
|
268 |
}else{ |
|
269 |
logger.error("Taxon (ID = " + taxon1.getId()+ ", RIdentifier = " + taxon1Id + ") can not be casted to Synonym"); |
|
270 |
} |
|
271 |
}else if (relQualifierFk == TAX_REL_IS_MISAPPLIED_NAME_OF){ |
|
272 |
((Taxon)taxon2).addMisappliedName((Taxon)taxon1, citation, microcitation); |
|
273 |
}else { |
|
274 |
//TODO |
|
275 |
logger.warn("TaxonRelationShipType " + relQualifierFk + " not yet implemented"); |
|
276 |
} |
|
277 |
taxonStore.add(taxon2); |
|
278 |
|
|
279 |
//TODO |
|
280 |
//Reference |
|
281 |
//ID |
|
282 |
//etc. |
|
283 |
}else{ |
|
284 |
//TODO |
|
285 |
logger.warn("Taxa for RelPTaxon " + relPTaxonId + " do not exist in store"); |
|
286 |
} |
|
287 |
} |
|
288 |
logger.info("Taxa to save: " + taxonStore.size()); |
|
289 |
taxonService.saveTaxonAll(taxonStore); |
|
290 |
|
|
291 |
logger.info("end makeRelTaxa ..."); |
|
292 |
return true; |
|
293 |
} catch (SQLException e) { |
|
294 |
logger.error("SQLException:" + e); |
|
295 |
return false; |
|
296 |
} |
|
297 |
|
|
298 |
} |
|
299 |
|
|
300 |
|
|
301 | 159 |
} |
cdmlib-io/src/main/java/eu/etaxonomy/cdm/io/berlinModel/BerlinModelTaxonNameIO.java | ||
---|---|---|
7 | 7 |
import static eu.etaxonomy.cdm.io.berlinModel.BerlinModelTransformer.NAME_REL_IS_REJECTED_TYPE_OF; |
8 | 8 |
import static eu.etaxonomy.cdm.io.berlinModel.BerlinModelTransformer.NAME_REL_IS_REPLACED_SYNONYM_FOR; |
9 | 9 |
import static eu.etaxonomy.cdm.io.berlinModel.BerlinModelTransformer.NAME_REL_IS_TYPE_OF; |
10 |
import static eu.etaxonomy.cdm.io.berlinModel.BerlinModelTransformer.NAME_ST_COMB_INVAL; |
|
11 |
import static eu.etaxonomy.cdm.io.berlinModel.BerlinModelTransformer.NAME_ST_NOM_ALTERN; |
|
12 |
import static eu.etaxonomy.cdm.io.berlinModel.BerlinModelTransformer.NAME_ST_NOM_AMBIG; |
|
13 |
import static eu.etaxonomy.cdm.io.berlinModel.BerlinModelTransformer.NAME_ST_NOM_CONFUS; |
|
14 |
import static eu.etaxonomy.cdm.io.berlinModel.BerlinModelTransformer.NAME_ST_NOM_CONS; |
|
15 |
import static eu.etaxonomy.cdm.io.berlinModel.BerlinModelTransformer.NAME_ST_NOM_CONS_PROP; |
|
16 |
import static eu.etaxonomy.cdm.io.berlinModel.BerlinModelTransformer.NAME_ST_NOM_DUB; |
|
17 |
import static eu.etaxonomy.cdm.io.berlinModel.BerlinModelTransformer.NAME_ST_NOM_ILLEG; |
|
18 |
import static eu.etaxonomy.cdm.io.berlinModel.BerlinModelTransformer.NAME_ST_NOM_INVAL; |
|
19 |
import static eu.etaxonomy.cdm.io.berlinModel.BerlinModelTransformer.NAME_ST_NOM_NOV; |
|
20 |
import static eu.etaxonomy.cdm.io.berlinModel.BerlinModelTransformer.NAME_ST_NOM_NUD; |
|
21 |
import static eu.etaxonomy.cdm.io.berlinModel.BerlinModelTransformer.NAME_ST_NOM_PROVIS; |
|
22 |
import static eu.etaxonomy.cdm.io.berlinModel.BerlinModelTransformer.NAME_ST_NOM_REJ; |
|
23 |
import static eu.etaxonomy.cdm.io.berlinModel.BerlinModelTransformer.NAME_ST_NOM_REJ_PROP; |
|
24 |
import static eu.etaxonomy.cdm.io.berlinModel.BerlinModelTransformer.NAME_ST_NOM_SUPERFL; |
|
25 |
import static eu.etaxonomy.cdm.io.berlinModel.BerlinModelTransformer.NAME_ST_NOM_UTIQUE_REJ; |
|
26 |
import static eu.etaxonomy.cdm.io.berlinModel.BerlinModelTransformer.NAME_ST_NOM_UTIQUE_REJ_PROP; |
|
27 |
import static eu.etaxonomy.cdm.io.berlinModel.BerlinModelTransformer.NAME_ST_ORTH_CONS; |
|
28 |
import static eu.etaxonomy.cdm.io.berlinModel.BerlinModelTransformer.NAME_ST_ORTH_CONS_PROP; |
|
29 | 10 |
|
30 | 11 |
import java.sql.ResultSet; |
31 | 12 |
import java.sql.SQLException; |
... | ... | |
45 | 26 |
import eu.etaxonomy.cdm.model.name.BotanicalName; |
46 | 27 |
import eu.etaxonomy.cdm.model.name.CultivarPlantName; |
47 | 28 |
import eu.etaxonomy.cdm.model.name.NameRelationshipType; |
48 |
import eu.etaxonomy.cdm.model.name.NomenclaturalStatus; |
|
49 |
import eu.etaxonomy.cdm.model.name.NomenclaturalStatusType; |
|
50 | 29 |
import eu.etaxonomy.cdm.model.name.NonViralName; |
51 | 30 |
import eu.etaxonomy.cdm.model.name.Rank; |
52 | 31 |
import eu.etaxonomy.cdm.model.name.TaxonNameBase; |
... | ... | |
70 | 49 |
return result; |
71 | 50 |
} |
72 | 51 |
|
73 |
public static boolean checkRelations(BerlinModelImportConfigurator bmiConfig){ |
|
74 |
boolean result = true; |
|
75 |
logger.warn("Checking for TaxonNameRelations not yet implemented"); |
|
76 |
//result &= checkArticlesWithoutJournal(bmiConfig); |
|
77 |
//result &= checkPartOfJournal(bmiConfig); |
|
78 |
|
|
79 |
return result; |
|
80 |
} |
|
81 |
|
|
82 | 52 |
public static boolean invoke(BerlinModelImportConfigurator bmiConfig, CdmApplicationController cdmApp, |
83 | 53 |
MapWrapper<TaxonNameBase> taxonNameMap, MapWrapper<ReferenceBase> nomRefMap, MapWrapper<ReferenceBase> referenceMap, MapWrapper<TeamOrPersonBase> authorMap){ |
84 | 54 |
|
... | ... | |
304 | 274 |
} |
305 | 275 |
} |
306 | 276 |
|
307 |
|
|
308 |
public static boolean invokeRelations(BerlinModelImportConfigurator bmiConfig, CdmApplicationController cdmApp, |
|
309 |
MapWrapper<TaxonNameBase> nameMap, MapWrapper<ReferenceBase> referenceMap){ |
|
310 |
|
|
311 |
Set<TaxonNameBase> nameStore = new HashSet<TaxonNameBase>(); |
|
312 |
Source source = bmiConfig.getSource(); |
|
313 |
String dbAttrName; |
|
314 |
String cdmAttrName; |
|
315 |
|
|
316 |
logger.info("start makeNameRelationships ..."); |
|
317 |
|
|
318 |
INameService nameService = cdmApp.getNameService(); |
|
319 |
boolean delete = bmiConfig.isDeleteAll(); |
|
320 |
|
|
321 |
try { |
|
322 |
//get data from database |
|
323 |
String strQuery = |
|
324 |
" SELECT RelName.*, FromName.nameId as name1Id, ToName.nameId as name2Id, RefDetail.Details " + |
|
325 |
" FROM Name as FromName INNER JOIN " + |
|
326 |
" RelName ON FromName.NameId = RelName.NameFk1 INNER JOIN " + |
|
327 |
" Name AS ToName ON RelName.NameFk2 = ToName.NameId LEFT OUTER JOIN "+ |
|
328 |
" RefDetail ON RelName.RefDetailFK = RefDetail.RefDetailId " + |
|
329 |
" WHERE (1=1)"; |
|
330 |
ResultSet rs = source.getResultSet(strQuery) ; |
|
331 |
|
|
332 |
int i = 0; |
|
333 |
//for each reference |
|
334 |
while (rs.next()){ |
|
335 |
|
|
336 |
if ((i++ % modCount) == 0){ logger.info("RelName handled: " + (i-1));} |
|
337 |
|
|
338 |
int relNameId = rs.getInt("RelNameId"); |
|
339 |
int name1Id = rs.getInt("name1Id"); |
|
340 |
int name2Id = rs.getInt("name2Id"); |
|
341 |
int relRefFk = rs.getInt("refFk"); |
|
342 |
String details = rs.getString("details"); |
|
343 |
int relQualifierFk = rs.getInt("relNameQualifierFk"); |
|
344 |
|
|
345 |
TaxonNameBase nameFrom = nameMap.get(name1Id); |
|
346 |
TaxonNameBase nameTo = nameMap.get(name2Id); |
|
347 |
|
|
348 |
ReferenceBase citation = referenceMap.get(relRefFk); |
|
349 |
//TODO (preliminaryFlag = true testen |
|
350 |
String microcitation = details; |
|
351 |
|
|
352 |
if (nameFrom != null && nameTo != null){ |
|
353 |
if (relQualifierFk == NAME_REL_IS_BASIONYM_FOR){ |
|
354 |
//TODO references, mikroref, etc |
|
355 |
nameTo.addBasionym(nameFrom); |
|
356 |
}else if (relQualifierFk == NAME_REL_IS_LATER_HOMONYM_OF){ |
|
357 |
String rule = null; //TODO |
|
358 |
nameFrom.addRelationshipToName(nameTo, NameRelationshipType.LATER_HOMONYM(), rule) ; |
|
359 |
//TODO reference |
|
360 |
}else if (relQualifierFk == NAME_REL_IS_REPLACED_SYNONYM_FOR){ |
|
361 |
String rule = null; //TODO |
|
362 |
nameFrom.addRelationshipToName(nameTo, NameRelationshipType.REPLACED_SYNONYM(), rule) ; |
|
363 |
//TODO reference |
|
364 |
}else if (relQualifierFk == NAME_REL_IS_TYPE_OF || relQualifierFk == NAME_REL_IS_REJECTED_TYPE_OF || relQualifierFk == NAME_REL_IS_CONSERVED_TYPE_OF ){ |
|
365 |
//TODO |
|
366 |
String originalNameString = null; |
|
367 |
boolean isRejectedType = (relQualifierFk == NAME_REL_IS_REJECTED_TYPE_OF); |
|
368 |
boolean isConservedType = (relQualifierFk == NAME_REL_IS_CONSERVED_TYPE_OF); |
|
369 |
nameTo.addNameTypeDesignation(nameFrom, citation, microcitation, originalNameString, isRejectedType, isConservedType); |
|
370 |
}else if (relQualifierFk == NAME_REL_IS_ORTHOGRAPHIC_VARIANT_OF){ |
|
371 |
String rule = null; //TODO |
|
372 |
nameFrom.addRelationshipToName(nameTo, NameRelationshipType.ORTHOGRAPHIC_VARIANT(), rule) ; |
|
373 |
//TODO reference |
|
374 |
}else { |
|
375 |
//TODO |
|
376 |
logger.warn("NameRelationShipType " + relQualifierFk + " not yet implemented"); |
|
377 |
} |
|
378 |
nameStore.add(nameFrom); |
|
379 |
|
|
380 |
//TODO |
|
381 |
//ID |
|
382 |
//etc. |
|
383 |
}else{ |
|
384 |
//TODO |
|
385 |
if (nameFrom == null){ |
|
386 |
logger.warn("from TaxonName for RelName (" + relNameId + ") does not exist in store"); |
|
387 |
} |
|
388 |
if (nameTo == null){ |
|
389 |
logger.warn("to TaxonNames for RelName (" + relNameId + ") does not exist in store"); |
|
390 |
} |
|
391 |
} |
|
392 |
} |
|
393 |
logger.info("TaxonName to save: " + nameStore.size()); |
|
394 |
nameService.saveTaxonNameAll(nameStore); |
|
395 |
|
|
396 |
logger.info("end makeRelName ..."); |
|
397 |
return true; |
|
398 |
} catch (SQLException e) { |
|
399 |
logger.error("SQLException:" + e); |
|
400 |
return false; |
|
401 |
} |
|
402 |
|
|
403 |
} |
|
404 |
|
|
405 | 277 |
} |
cdmlib-io/src/main/java/eu/etaxonomy/cdm/io/berlinModel/BerlinModelTaxonNameRelationIO.java | ||
---|---|---|
1 |
package eu.etaxonomy.cdm.io.berlinModel; |
|
2 |
|
|
3 |
import static eu.etaxonomy.cdm.io.berlinModel.BerlinModelTransformer.NAME_REL_IS_BASIONYM_FOR; |
|
4 |
import static eu.etaxonomy.cdm.io.berlinModel.BerlinModelTransformer.NAME_REL_IS_CONSERVED_TYPE_OF; |
|
5 |
import static eu.etaxonomy.cdm.io.berlinModel.BerlinModelTransformer.NAME_REL_IS_LATER_HOMONYM_OF; |
|
6 |
import static eu.etaxonomy.cdm.io.berlinModel.BerlinModelTransformer.NAME_REL_IS_ORTHOGRAPHIC_VARIANT_OF; |
|
7 |
import static eu.etaxonomy.cdm.io.berlinModel.BerlinModelTransformer.NAME_REL_IS_REJECTED_TYPE_OF; |
|
8 |
import static eu.etaxonomy.cdm.io.berlinModel.BerlinModelTransformer.NAME_REL_IS_REPLACED_SYNONYM_FOR; |
|
9 |
import static eu.etaxonomy.cdm.io.berlinModel.BerlinModelTransformer.NAME_REL_IS_TYPE_OF; |
|
10 |
|
|
11 |
import java.sql.ResultSet; |
|
12 |
import java.sql.SQLException; |
|
13 |
import java.util.HashSet; |
|
14 |
import java.util.Set; |
|
15 |
|
|
16 |
import org.apache.log4j.Logger; |
|
17 |
|
|
18 |
import eu.etaxonomy.cdm.api.application.CdmApplicationController; |
|
19 |
import eu.etaxonomy.cdm.api.service.INameService; |
|
20 |
import eu.etaxonomy.cdm.io.common.MapWrapper; |
|
21 |
import eu.etaxonomy.cdm.io.common.Source; |
|
22 |
import eu.etaxonomy.cdm.model.name.NameRelationshipType; |
|
23 |
import eu.etaxonomy.cdm.model.name.TaxonNameBase; |
|
24 |
import eu.etaxonomy.cdm.model.reference.ReferenceBase; |
|
25 |
|
|
26 |
|
|
27 |
public class BerlinModelTaxonNameRelationIO extends BerlinModelIOBase { |
|
28 |
private static final Logger logger = Logger.getLogger(BerlinModelTaxonNameRelationIO.class); |
|
29 |
|
|
30 |
private static int modCount = 5000; |
|
31 |
|
|
32 |
public static boolean check(BerlinModelImportConfigurator config){ |
|
33 |
boolean result = true; |
|
34 |
logger.warn("Checking for TaxonNameRelations not yet implemented"); |
|
35 |
//result &= checkArticlesWithoutJournal(bmiConfig); |
|
36 |
//result &= checkPartOfJournal(bmiConfig); |
|
37 |
|
|
38 |
return result; |
|
39 |
} |
|
40 |
|
|
41 |
public static boolean invoke(BerlinModelImportConfigurator config, CdmApplicationController cdmApp, |
|
42 |
MapWrapper<TaxonNameBase> nameMap, MapWrapper<ReferenceBase> referenceMap){ |
|
43 |
|
|
44 |
Set<TaxonNameBase> nameStore = new HashSet<TaxonNameBase>(); |
|
45 |
Source source = config.getSource(); |
|
46 |
String dbAttrName; |
|
47 |
String cdmAttrName; |
|
48 |
|
|
49 |
logger.info("start makeNameRelationships ..."); |
|
50 |
|
|
51 |
INameService nameService = cdmApp.getNameService(); |
|
52 |
try { |
|
53 |
//get data from database |
|
54 |
String strQuery = |
|
55 |
" SELECT RelName.*, FromName.nameId as name1Id, ToName.nameId as name2Id, RefDetail.Details " + |
|
56 |
" FROM Name as FromName INNER JOIN " + |
|
57 |
" RelName ON FromName.NameId = RelName.NameFk1 INNER JOIN " + |
|
58 |
" Name AS ToName ON RelName.NameFk2 = ToName.NameId LEFT OUTER JOIN "+ |
|
59 |
" RefDetail ON RelName.RefDetailFK = RefDetail.RefDetailId " + |
|
60 |
" WHERE (1=1)"; |
|
61 |
ResultSet rs = source.getResultSet(strQuery) ; |
|
62 |
|
|
63 |
int i = 0; |
|
64 |
//for each reference |
|
65 |
while (rs.next()){ |
|
66 |
|
|
67 |
if ((i++ % modCount) == 0){ logger.info("RelName handled: " + (i-1));} |
|
68 |
|
|
69 |
int relNameId = rs.getInt("RelNameId"); |
|
70 |
int name1Id = rs.getInt("name1Id"); |
|
71 |
int name2Id = rs.getInt("name2Id"); |
|
72 |
int relRefFk = rs.getInt("refFk"); |
|
73 |
String details = rs.getString("details"); |
|
74 |
int relQualifierFk = rs.getInt("relNameQualifierFk"); |
|
75 |
|
|
76 |
TaxonNameBase nameFrom = nameMap.get(name1Id); |
|
77 |
TaxonNameBase nameTo = nameMap.get(name2Id); |
|
78 |
|
|
79 |
ReferenceBase citation = referenceMap.get(relRefFk); |
|
80 |
//TODO (preliminaryFlag = true testen |
|
81 |
String microcitation = details; |
|
82 |
|
|
83 |
if (nameFrom != null && nameTo != null){ |
|
84 |
if (relQualifierFk == NAME_REL_IS_BASIONYM_FOR){ |
|
85 |
//TODO references, mikroref, etc |
|
86 |
nameTo.addBasionym(nameFrom); |
|
87 |
}else if (relQualifierFk == NAME_REL_IS_LATER_HOMONYM_OF){ |
|
88 |
String rule = null; //TODO |
|
89 |
nameFrom.addRelationshipToName(nameTo, NameRelationshipType.LATER_HOMONYM(), rule) ; |
|
90 |
//TODO reference |
|
91 |
}else if (relQualifierFk == NAME_REL_IS_REPLACED_SYNONYM_FOR){ |
|
92 |
String rule = null; //TODO |
|
93 |
nameFrom.addRelationshipToName(nameTo, NameRelationshipType.REPLACED_SYNONYM(), rule) ; |
|
94 |
//TODO reference |
|
95 |
}else if (relQualifierFk == NAME_REL_IS_TYPE_OF || relQualifierFk == NAME_REL_IS_REJECTED_TYPE_OF || relQualifierFk == NAME_REL_IS_CONSERVED_TYPE_OF ){ |
|
96 |
//TODO |
|
97 |
String originalNameString = null; |
|
98 |
boolean isRejectedType = (relQualifierFk == NAME_REL_IS_REJECTED_TYPE_OF); |
|
99 |
boolean isConservedType = (relQualifierFk == NAME_REL_IS_CONSERVED_TYPE_OF); |
|
100 |
nameTo.addNameTypeDesignation(nameFrom, citation, microcitation, originalNameString, isRejectedType, isConservedType); |
|
101 |
}else if (relQualifierFk == NAME_REL_IS_ORTHOGRAPHIC_VARIANT_OF){ |
|
102 |
String rule = null; //TODO |
|
103 |
nameFrom.addRelationshipToName(nameTo, NameRelationshipType.ORTHOGRAPHIC_VARIANT(), rule) ; |
|
104 |
//TODO reference |
|
105 |
}else { |
|
106 |
//TODO |
|
107 |
logger.warn("NameRelationShipType " + relQualifierFk + " not yet implemented"); |
|
108 |
} |
|
109 |
nameStore.add(nameFrom); |
|
110 |
|
|
111 |
//TODO |
|
112 |
//ID |
|
113 |
//etc. |
|
114 |
}else{ |
|
115 |
//TODO |
|
116 |
if (nameFrom == null){ |
|
117 |
logger.warn("from TaxonName for RelName (" + relNameId + ") does not exist in store"); |
|
118 |
} |
|
119 |
if (nameTo == null){ |
|
120 |
logger.warn("to TaxonNames for RelName (" + relNameId + ") does not exist in store"); |
|
121 |
} |
|
122 |
} |
|
123 |
} |
|
124 |
logger.info("TaxonName to save: " + nameStore.size()); |
|
125 |
nameService.saveTaxonNameAll(nameStore); |
|
126 |
|
|
127 |
logger.info("end makeRelName ..."); |
|
128 |
return true; |
|
129 |
} catch (SQLException e) { |
|
130 |
logger.error("SQLException:" + e); |
|
131 |
return false; |
|
132 |
} |
|
133 |
|
|
134 |
} |
|
135 |
|
|
136 |
} |
cdmlib-io/src/main/java/eu/etaxonomy/cdm/io/berlinModel/BerlinModelTaxonRelationIO.java | ||
---|---|---|
1 |
/** |
|
2 |
* |
|
3 |
*/ |
|
4 |
package eu.etaxonomy.cdm.io.berlinModel; |
|
5 |
|
|
6 |
import static eu.etaxonomy.cdm.io.berlinModel.BerlinModelTransformer.*; |
|
7 |
|
|
8 |
import java.sql.ResultSet; |
|
9 |
import java.sql.SQLException; |
|
10 |
import java.util.HashSet; |
|
11 |
import java.util.Set; |
|
12 |
|
|
13 |
import org.apache.log4j.Logger; |
|
14 |
|
|
15 |
import eu.etaxonomy.cdm.api.application.CdmApplicationController; |
|
16 |
import eu.etaxonomy.cdm.api.service.ITaxonService; |
|
17 |
import eu.etaxonomy.cdm.io.common.ImportHelper; |
|
18 |
import eu.etaxonomy.cdm.io.common.MapWrapper; |
|
19 |
import eu.etaxonomy.cdm.io.common.Source; |
|
20 |
import eu.etaxonomy.cdm.model.name.TaxonNameBase; |
|
21 |
import eu.etaxonomy.cdm.model.reference.ReferenceBase; |
|
22 |
import eu.etaxonomy.cdm.model.taxon.Synonym; |
|
23 |
import eu.etaxonomy.cdm.model.taxon.SynonymRelationshipType; |
|
24 |
import eu.etaxonomy.cdm.model.taxon.Taxon; |
|
25 |
import eu.etaxonomy.cdm.model.taxon.TaxonBase; |
|
26 |
|
|
27 |
|
|
28 |
/** |
|
29 |
* @author a.mueller |
|
30 |
* |
|
31 |
*/ |
|
32 |
public class BerlinModelTaxonRelationIO extends BerlinModelIOBase { |
|
33 |
private static final Logger logger = Logger.getLogger(BerlinModelTaxonRelationIO.class); |
|
34 |
|
|
35 |
private static int modCount = 30000; |
|
36 |
|
|
37 |
public static boolean check(BerlinModelImportConfigurator bmiConfig){ |
|
38 |
boolean result = true; |
|
39 |
logger.warn("Checking for TaxonRelations not yet fully implemented"); |
|
40 |
result &= checkTaxonStatus(bmiConfig); |
|
41 |
//result &= checkArticlesWithoutJournal(bmiConfig); |
|
42 |
|
|
43 |
return result; |
|
44 |
} |
|
45 |
|
|
46 |
private static boolean checkTaxonStatus(BerlinModelImportConfigurator bmiConfig){ |
|
47 |
try { |
|
48 |
boolean result = true; |
|
49 |
Source source = bmiConfig.getSource(); |
|
50 |
String strQueryPartOfJournal = " SELECT RelPTaxon.RelQualifierFk, RelPTaxon.relPTaxonId, PTaxon.PTNameFk, PTaxon.PTRefFk, PTaxon_1.PTNameFk AS Expr1, PTaxon.RIdentifier, PTaxon_1.RIdentifier AS Expr3, Name.FullNameCache " + |
|
51 |
" FROM RelPTaxon " + |
|
52 |
" INNER JOIN PTaxon ON RelPTaxon.PTNameFk1 = PTaxon.PTNameFk AND RelPTaxon.PTRefFk1 = PTaxon.PTRefFk " + |
|
53 |
" INNER JOIN PTaxon AS PTaxon_1 ON RelPTaxon.PTNameFk2 = PTaxon_1.PTNameFk AND RelPTaxon.PTRefFk2 = PTaxon_1.PTRefFk " + |
|
54 |
" INNER JOIN Name ON PTaxon.PTNameFk = Name.NameId " + |
|
55 |
" WHERE (dbo.PTaxon.StatusFk = 1) AND ((RelPTaxon.RelQualifierFk = 7) OR (RelPTaxon.RelQualifierFk = 6) OR (RelPTaxon.RelQualifierFk = 2)) "; |
|
56 |
ResultSet rs = source.getResultSet(strQueryPartOfJournal); |
|
57 |
boolean firstRow = true; |
|
58 |
int i = 0; |
|
59 |
while (rs.next()){ |
|
60 |
i++; |
|
61 |
if (firstRow){ |
|
62 |
System.out.println("========================================================"); |
|
63 |
logger.warn("There are taxa that have a 'is synonym of' - relationship but having taxon status 'accepted'!"); |
|
64 |
System.out.println("========================================================"); |
|
65 |
} |
|
66 |
int rIdentifier = rs.getInt("RIdentifier"); |
|
67 |
int nameFk = rs.getInt("PTNameFk"); |
|
68 |
int refFk = rs.getInt("PTRefFk"); |
|
69 |
int relPTaxonId = rs.getInt("relPTaxonId"); |
|
70 |
String taxonName = rs.getString("FullNameCache"); |
|
71 |
|
|
72 |
System.out.println("RIdentifier:" + rIdentifier + "\n name: " + nameFk + |
|
73 |
"\n taxonName: " + taxonName + "\n refId: " + refFk + "\n RelPTaxonId: " + relPTaxonId ); |
|
74 |
result = firstRow = false; |
|
75 |
} |
|
76 |
if (i > 0){ |
|
77 |
System.out.println(" "); |
|
78 |
} |
|
79 |
|
|
80 |
return result; |
|
81 |
} catch (SQLException e) { |
|
82 |
e.printStackTrace(); |
|
83 |
return false; |
|
84 |
} |
|
85 |
} |
|
86 |
|
|
87 |
public static boolean invoke(BerlinModelImportConfigurator config, CdmApplicationController cdmApp, |
|
88 |
MapWrapper<TaxonBase> taxonMap, MapWrapper<ReferenceBase> referenceMap){ |
|
89 |
|
|
90 |
Set<TaxonBase> taxonStore = new HashSet<TaxonBase>(); |
|
91 |
Source source = config.getSource(); |
|
92 |
String dbAttrName; |
|
93 |
String cdmAttrName; |
|
94 |
|
|
95 |
logger.info("start makeTaxonRelationships ..."); |
|
96 |
|
|
97 |
ITaxonService taxonService = cdmApp.getTaxonService(); |
|
98 |
|
|
99 |
try { |
|
100 |
//get data from database |
|
101 |
String strQuery = |
|
102 |
" SELECT RelPTaxon.*, FromTaxon.RIdentifier as taxon1Id, ToTaxon.RIdentifier as taxon2Id " + |
|
103 |
" FROM PTaxon as FromTaxon INNER JOIN " + |
|
104 |
" RelPTaxon ON FromTaxon.PTNameFk = RelPTaxon.PTNameFk1 AND FromTaxon.PTRefFk = RelPTaxon.PTRefFk1 INNER JOIN " + |
|
105 |
" PTaxon AS ToTaxon ON RelPTaxon.PTNameFk2 = ToTaxon.PTNameFk AND RelPTaxon.PTRefFk2 = ToTaxon.PTRefFk "+ |
|
106 |
" WHERE (1=1)"; |
|
107 |
ResultSet rs = source.getResultSet(strQuery) ; |
|
108 |
|
|
109 |
int i = 0; |
|
110 |
//for each reference |
|
111 |
while (rs.next()){ |
|
112 |
|
|
113 |
if ((i++ % modCount) == 0){ logger.info("RelPTaxa handled: " + (i-1));} |
|
114 |
|
|
115 |
int relPTaxonId = rs.getInt("RelPTaxonId"); |
|
116 |
int taxon1Id = rs.getInt("taxon1Id"); |
|
117 |
int taxon2Id = rs.getInt("taxon2Id"); |
|
118 |
int relRefFk = rs.getInt("relRefFk"); |
|
119 |
int relQualifierFk = rs.getInt("relQualifierFk"); |
|
120 |
|
|
121 |
TaxonBase taxon1 = taxonMap.get(taxon1Id); |
|
122 |
TaxonBase taxon2 = taxonMap.get(taxon2Id); |
|
123 |
|
|
124 |
//TODO |
|
125 |
ReferenceBase citation = null; |
|
126 |
String microcitation = null; |
|
127 |
|
|
128 |
if (taxon2 != null && taxon1 != null){ |
|
129 |
if (relQualifierFk == TAX_REL_IS_INCLUDED_IN){ |
|
130 |
((Taxon)taxon2).addTaxonomicChild((Taxon)taxon1, citation, microcitation); |
|
131 |
}else if (relQualifierFk == TAX_REL_IS_SYNONYM_OF){ |
|
132 |
((Taxon)taxon2).addSynonym((Synonym)taxon1, SynonymRelationshipType.SYNONYM_OF()); |
|
133 |
}else if (relQualifierFk == TAX_REL_IS_HOMOTYPIC_SYNONYM_OF){ |
|
134 |
if (taxon1 instanceof Synonym){ |
|
135 |
((Taxon)taxon2).addHomotypicSynonym((Synonym)taxon1, citation, microcitation); |
|
136 |
}else{ |
|
137 |
logger.error("Taxon (ID = " + taxon1.getId()+ ", RIdentifier = " + taxon1Id + ") can't be casted to Synonym"); |
|
138 |
} |
|
139 |
}else if (relQualifierFk == TAX_REL_IS_HETEROTYPIC_SYNONYM_OF){ |
|
140 |
if (Synonym.class.isAssignableFrom(taxon1.getClass())){ |
|
141 |
((Taxon)taxon2).addSynonym((Synonym)taxon1, SynonymRelationshipType.HETEROTYPIC_SYNONYM_OF()); |
|
142 |
}else{ |
|
143 |
logger.error("Taxon (ID = " + taxon1.getId()+ ", RIdentifier = " + taxon1Id + ") can not be casted to Synonym"); |
|
144 |
} |
|
145 |
}else if (relQualifierFk == TAX_REL_IS_MISAPPLIED_NAME_OF){ |
|
146 |
((Taxon)taxon2).addMisappliedName((Taxon)taxon1, citation, microcitation); |
|
147 |
}else { |
|
148 |
//TODO |
|
149 |
logger.warn("TaxonRelationShipType " + relQualifierFk + " not yet implemented"); |
|
150 |
} |
|
151 |
taxonStore.add(taxon2); |
|
152 |
|
|
153 |
//TODO |
|
154 |
//Reference |
|
155 |
//ID |
|
156 |
//etc. |
|
157 |
}else{ |
|
158 |
//TODO |
|
159 |
logger.warn("Taxa for RelPTaxon " + relPTaxonId + " do not exist in store"); |
|
160 |
} |
|
161 |
} |
|
162 |
logger.info("Taxa to save: " + taxonStore.size()); |
|
163 |
taxonService.saveTaxonAll(taxonStore); |
|
164 |
|
|
165 |
logger.info("end makeRelTaxa ..."); |
|
166 |
return true; |
|
167 |
} catch (SQLException e) { |
|
168 |
logger.error("SQLException:" + e); |
|
169 |
return false; |
|
170 |
} |
|
171 |
|
|
172 |
} |
|
173 |
|
|
174 |
|
|
175 |
} |
Also available in: Unified diff