Import synonyms of other classifications #5448
[cdmlib-apps.git] / app-import / src / main / java / eu / etaxonomy / cdm / io / redlist / gefaesspflanzen / RedListGefaesspflanzenImportNames.java
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.redlist.gefaesspflanzen;
11
12 import java.sql.ResultSet;
13 import java.sql.SQLException;
14 import java.util.HashMap;
15 import java.util.HashSet;
16 import java.util.Map;
17 import java.util.Set;
18
19 import org.apache.log4j.Logger;
20 import org.springframework.stereotype.Component;
21
22 import eu.etaxonomy.cdm.common.CdmUtils;
23 import eu.etaxonomy.cdm.hibernate.HibernateProxyHelper;
24 import eu.etaxonomy.cdm.io.common.DbImportBase;
25 import eu.etaxonomy.cdm.io.common.IPartitionedIO;
26 import eu.etaxonomy.cdm.io.common.ImportHelper;
27 import eu.etaxonomy.cdm.io.common.ResultSetPartitioner;
28 import eu.etaxonomy.cdm.io.common.mapping.UndefinedTransformerMethodException;
29 import eu.etaxonomy.cdm.model.agent.AgentBase;
30 import eu.etaxonomy.cdm.model.agent.TeamOrPersonBase;
31 import eu.etaxonomy.cdm.model.common.CdmBase;
32 import eu.etaxonomy.cdm.model.common.Language;
33 import eu.etaxonomy.cdm.model.description.CommonTaxonName;
34 import eu.etaxonomy.cdm.model.description.TaxonDescription;
35 import eu.etaxonomy.cdm.model.name.BotanicalName;
36 import eu.etaxonomy.cdm.model.name.NomenclaturalStatus;
37 import eu.etaxonomy.cdm.model.name.NomenclaturalStatusType;
38 import eu.etaxonomy.cdm.model.name.NonViralName;
39 import eu.etaxonomy.cdm.model.name.Rank;
40 import eu.etaxonomy.cdm.model.name.TaxonNameBase;
41 import eu.etaxonomy.cdm.model.taxon.Synonym;
42 import eu.etaxonomy.cdm.model.taxon.Taxon;
43 import eu.etaxonomy.cdm.model.taxon.TaxonBase;
44 import eu.etaxonomy.cdm.model.taxon.TaxonRelationship;
45 import eu.etaxonomy.cdm.model.taxon.TaxonRelationshipType;
46 import eu.etaxonomy.cdm.strategy.parser.NonViralNameParserImpl;
47
48 /**
49 *
50 * @author pplitzner
51 * @date Mar 1, 2016
52 *
53 */
54
55 @Component
56 @SuppressWarnings("serial")
57 public class RedListGefaesspflanzenImportNames extends DbImportBase<RedListGefaesspflanzenImportState, RedListGefaesspflanzenImportConfigurator> {
58
59 private static final Logger logger = Logger.getLogger(RedListGefaesspflanzenImportNames.class);
60
61 private static final String tableName = "Rote Liste Gefäßpflanzen";
62
63 private static final String pluralString = "names";
64
65 public RedListGefaesspflanzenImportNames() {
66 super(tableName, pluralString);
67 }
68
69 @Override
70 protected String getIdQuery(RedListGefaesspflanzenImportState state) {
71 return "SELECT NAMNR "
72 + "FROM V_TAXATLAS_D20_EXPORT t "
73 + " ORDER BY NAMNR";
74 }
75
76 @Override
77 protected String getRecordQuery(RedListGefaesspflanzenImportConfigurator config) {
78 String result = " SELECT * "
79 + " FROM V_TAXATLAS_D20_EXPORT t "
80 + " WHERE t.NAMNR IN (@IDSET)";
81 result = result.replace("@IDSET", IPartitionedIO.ID_LIST_TOKEN);
82 return result;
83 }
84
85 @Override
86 protected void doInvoke(RedListGefaesspflanzenImportState state) {
87 super.doInvoke(state);
88 }
89
90
91 @Override
92 public boolean doPartition(ResultSetPartitioner partitioner, RedListGefaesspflanzenImportState state) {
93 ResultSet rs = partitioner.getResultSet();
94 Set<TaxonNameBase<?,?>> namesToSave = new HashSet<TaxonNameBase<?,?>>();
95 Set<TaxonBase<?>> taxaToSave = new HashSet<TaxonBase<?>>();
96 try {
97 while (rs.next()){
98 makeSingleNameAndTaxon(state, rs, namesToSave, taxaToSave);
99
100 }
101 } catch (SQLException e) {
102 e.printStackTrace();
103 }
104
105 getNameService().saveOrUpdate((TaxonNameBase) namesToSave);
106 getTaxonService().saveOrUpdate((TaxonBase) taxaToSave);
107 return true;
108 }
109
110 private void makeSingleNameAndTaxon(RedListGefaesspflanzenImportState state, ResultSet rs, Set<TaxonNameBase<?,?>> namesToSave, Set<TaxonBase<?>> taxaToSave)
111 throws SQLException {
112 long id = rs.getLong(RedListUtil.NAMNR);
113 String clTaxonString = rs.getString(RedListUtil.CL_TAXON);
114 String relationE = rs.getString(RedListUtil.E);
115 String relationW = rs.getString(RedListUtil.W);
116 String relationK = rs.getString(RedListUtil.K);
117 String relationAW = rs.getString(RedListUtil.AW);
118 String relationAO = rs.getString(RedListUtil.AO);
119 String relationR = rs.getString(RedListUtil.R);
120 String relationO = rs.getString(RedListUtil.O);
121 String relationS = rs.getString(RedListUtil.S);
122
123 //---NAME---
124 NonViralName<?> name = importName(state, rs, namesToSave);
125
126
127 //--- AUTHORS ---
128 importAuthors(state, rs, name);
129
130 //---TAXON---
131 TaxonBase<?> taxonBase = importTaxon(rs, name);
132 if(taxonBase==null){
133 RedListUtil.logMessage(id, "Taxon for name "+name+" could not be created.", logger);
134 return;
135 }
136
137 //---CONCEPT RELATIONSHIPS---
138 //checklist
139 TaxonBase<?> checklistTaxon = null;
140 if(CdmUtils.isNotBlank(clTaxonString) && !clTaxonString.trim().equals("-")){
141 checklistTaxon = (TaxonBase<?>) taxonBase.clone();
142 //TODO what to do with synonyms?
143 if(checklistTaxon.isInstanceOf(Taxon.class)){
144 TaxonRelationship relation = HibernateProxyHelper.deproxy(checklistTaxon, Taxon.class).addTaxonRelation(HibernateProxyHelper.deproxy(taxonBase, Taxon.class), TaxonRelationshipType.CONGRUENT_TO(), null, null);
145 relation.setDoubtful(true);
146 }
147
148 ImportHelper.setOriginalSource(checklistTaxon, state.getTransactionalSourceReference(), id, RedListUtil.TAXON_CHECKLISTE_NAMESPACE);
149 taxaToSave.add(checklistTaxon);
150 }
151 //E, W, K, AW, AO, R, O, S
152 addConceptRelation(relationE, RedListUtil.CLASSIFICATION_NAMESPACE_E, taxonBase, checklistTaxon, taxaToSave, id, state);
153 addConceptRelation(relationW, RedListUtil.CLASSIFICATION_NAMESPACE_W, taxonBase, checklistTaxon, taxaToSave, id, state);
154 addConceptRelation(relationK, RedListUtil.CLASSIFICATION_NAMESPACE_K, taxonBase, checklistTaxon, taxaToSave, id, state);
155 addConceptRelation(relationAW, RedListUtil.CLASSIFICATION_NAMESPACE_AW, taxonBase, checklistTaxon, taxaToSave, id, state);
156 addConceptRelation(relationAO, RedListUtil.CLASSIFICATION_NAMESPACE_AO, taxonBase, checklistTaxon, taxaToSave, id, state);
157 addConceptRelation(relationR, RedListUtil.CLASSIFICATION_NAMESPACE_R, taxonBase, checklistTaxon, taxaToSave, id, state);
158 addConceptRelation(relationO, RedListUtil.CLASSIFICATION_NAMESPACE_O, taxonBase, checklistTaxon, taxaToSave, id, state);
159 addConceptRelation(relationS, RedListUtil.CLASSIFICATION_NAMESPACE_S, taxonBase, checklistTaxon, taxaToSave, id, state);
160
161 //NOTE: the source has to be added after cloning or otherwise the clone would also get the source
162 ImportHelper.setOriginalSource(taxonBase, state.getTransactionalSourceReference(), id, RedListUtil.TAXON_GESAMTLISTE_NAMESPACE);
163 taxaToSave.add(taxonBase);
164 }
165
166 private void addConceptRelation(String relationString, String classificationNamespace, TaxonBase<?> gesamtListeTaxon, TaxonBase<?> checkListenTaxon, Set<TaxonBase<?>> taxaToSave, long id, RedListGefaesspflanzenImportState state){
167 if(CdmUtils.isNotBlank(relationString) && !relationString.equals(".")){
168 String substring = relationString.substring(relationString.length()-1, relationString.length());
169 TaxonRelationshipType taxonRelationshipTypeByKey = new RedListGefaesspflanzenTransformer().getTaxonRelationshipTypeByKey(substring);
170 if(taxonRelationshipTypeByKey==null){
171 RedListUtil.logMessage(id, "Could not interpret relationship "+relationString+" for taxon "+gesamtListeTaxon.generateTitle(), logger);
172 }
173 //there is no type "included in" so we have to reverse the direction
174 if(substring.equals("<")){
175 cloneTaxon(gesamtListeTaxon, checkListenTaxon, taxonRelationshipTypeByKey, taxaToSave, id, classificationNamespace, true, false, state);
176 }
177 else{
178 cloneTaxon(gesamtListeTaxon, checkListenTaxon, taxonRelationshipTypeByKey, taxaToSave, id, classificationNamespace, false, false, state);
179 }
180 }
181 }
182
183 /**
184 * 1. clone new taxon of gesamtListeTaxon with the same name (in that classification)<br>
185 * 2. create concept relationship from clone to gesamtListeTaxon/checklisteTaxon or from its accepted taxon if it is synonym<br>
186 *<br>
187 * <b>NOTE:</b> the {@link TaxonRelationshipType} passed as parameter is
188 * directed <b>from the clone</b> to the taxon.<br>
189 * This can be changed with parameter <i>reverseRelation</i>
190 * @return cloned taxon
191 */
192 private Taxon cloneTaxon(final TaxonBase<?> gesamtListeTaxon, final TaxonBase<?> checklisteTaxon, TaxonRelationshipType relationFromCloneToTaxon, Set<TaxonBase<?>> taxaToSave, long id, String sourceNameSpace, boolean reverseRelation, boolean doubtful, RedListGefaesspflanzenImportState state){
193 Taxon acceptedGesamtListeTaxon = getAcceptedTaxon(gesamtListeTaxon);
194 Taxon acceptedChecklistTaxon = getAcceptedTaxon(checklisteTaxon);
195 Taxon clonedTaxon = null;
196
197 if(gesamtListeTaxon.isInstanceOf(Taxon.class)){
198 clonedTaxon = HibernateProxyHelper.deproxy(gesamtListeTaxon.clone(), Taxon.class);
199 }
200 else if(gesamtListeTaxon.isInstanceOf(Synonym.class)){
201 clonedTaxon = Taxon.NewInstance(gesamtListeTaxon.getName(), gesamtListeTaxon.getSec());
202 }
203 else{
204 RedListUtil.logMessage(id, "Taxon base "+gesamtListeTaxon+" is neither taxon nor synonym! Taxon could not be cloned", logger);
205 return null;
206 }
207
208 if(reverseRelation){
209 if(acceptedGesamtListeTaxon!=null){
210 TaxonRelationship taxonRelation = acceptedGesamtListeTaxon.addTaxonRelation(clonedTaxon, relationFromCloneToTaxon, null, null);
211 taxonRelation.setDoubtful(doubtful);
212 }
213 if(acceptedChecklistTaxon!=null) {
214 TaxonRelationship taxonRelation = acceptedChecklistTaxon.addTaxonRelation(clonedTaxon, relationFromCloneToTaxon, null, null);
215 taxonRelation.setDoubtful(doubtful);
216 }
217 }
218 else {
219 if(acceptedGesamtListeTaxon!=null){
220 TaxonRelationship taxonRelation = clonedTaxon.addTaxonRelation(acceptedGesamtListeTaxon, relationFromCloneToTaxon, null, null);
221 taxonRelation.setDoubtful(doubtful);
222 }
223 if(acceptedChecklistTaxon!=null) {
224 TaxonRelationship taxonRelation = clonedTaxon.addTaxonRelation(acceptedChecklistTaxon, relationFromCloneToTaxon, null, null);
225 taxonRelation.setDoubtful(doubtful);
226 }
227 }
228
229 ImportHelper.setOriginalSource(clonedTaxon, state.getTransactionalSourceReference(), id, sourceNameSpace);
230 taxaToSave.add(clonedTaxon);
231 return clonedTaxon;
232 }
233
234 private TaxonBase<?> importTaxon(ResultSet rs, NonViralName<?> name) throws SQLException {
235
236 long id = rs.getLong(RedListUtil.NAMNR);
237 String taxNameString = rs.getString(RedListUtil.TAXNAME);
238 String gueltString = rs.getString(RedListUtil.GUELT);
239 String trivialString = rs.getString(RedListUtil.TRIVIAL);
240 String authorBasiString = rs.getString(RedListUtil.AUTOR_BASI);
241 String hybString = rs.getString(RedListUtil.HYB);
242
243 TaxonBase<?> taxonBase = null;
244 if(authorBasiString.trim().contains(RedListUtil.AUCT)){
245 taxonBase = Taxon.NewInstance(name, null);
246 taxonBase.setAppendedPhrase(RedListUtil.AUCT);
247 }
248 else if(gueltString.equals(RedListUtil.GUELT_ACCEPTED_TAXON)){
249 taxonBase = Taxon.NewInstance(name, null);
250 }
251 else if(gueltString.equals(RedListUtil.GUELT_SYNONYM) || gueltString.equals(RedListUtil.GUELT_BASIONYM)){
252 taxonBase = Synonym.NewInstance(name, null);
253 }
254 else{
255 return null;
256 }
257
258 //common name
259 if(taxonBase.isInstanceOf(Taxon.class) && trivialString!=null){
260 Taxon taxon = HibernateProxyHelper.deproxy(taxonBase, Taxon.class);
261 TaxonDescription description = TaxonDescription.NewInstance(taxon);
262 description.addElement(CommonTaxonName.NewInstance(trivialString, Language.getDefaultLanguage()));
263 }
264
265 //check taxon name consistency
266 checkTaxonNameConsistency(id, taxNameString, hybString, taxonBase);
267 return taxonBase;
268 }
269
270 private void importAuthors(RedListGefaesspflanzenImportState state, ResultSet rs, NonViralName<?> name) throws SQLException {
271
272 long id = rs.getLong(RedListUtil.NAMNR);
273 String nomZusatzString = rs.getString(RedListUtil.NOM_ZUSATZ);
274 String taxZusatzString = rs.getString(RedListUtil.TAX_ZUSATZ);
275 String zusatzString = rs.getString(RedListUtil.ZUSATZ);
276 String authorKombString = rs.getString(RedListUtil.AUTOR_KOMB);
277 String authorBasiString = rs.getString(RedListUtil.AUTOR_BASI);
278
279 //combination author
280 if(authorKombString.contains(RedListUtil.EX)){
281 //TODO: what happens with multiple ex authors??
282 String[] kombSplit = authorKombString.split(RedListUtil.EX);
283 if(kombSplit.length!=2){
284 RedListUtil.logMessage(id, "Multiple ex combination authors found", logger);
285 }
286 for (int i = 0; i < kombSplit.length; i++) {
287 if(i==0){
288 //first author is ex author
289 TeamOrPersonBase<?> authorKomb = (TeamOrPersonBase<?>) state.getRelatedObject(RedListUtil.AUTHOR_NAMESPACE, kombSplit[i]);
290 name.setExCombinationAuthorship(authorKomb);
291 }
292 else{
293 TeamOrPersonBase<?> authorKomb = (TeamOrPersonBase<?>) state.getRelatedObject(RedListUtil.AUTHOR_NAMESPACE, kombSplit[i]);
294 name.setCombinationAuthorship(authorKomb);
295 }
296 }
297 }
298 else if(authorKombString.trim().contains(RedListUtil.AUCT)){
299 RedListUtil.logMessage(id, "AUCT information in "+RedListUtil.AUTOR_KOMB+" column", logger);
300 }
301 else if(CdmUtils.isNotBlank(authorKombString)){
302 TeamOrPersonBase<?> authorKomb = (TeamOrPersonBase<?>) state.getRelatedObject(RedListUtil.AUTHOR_NAMESPACE, authorKombString);
303 name.setCombinationAuthorship(authorKomb);
304 }
305 //basionym author
306 if(authorBasiString.contains(RedListUtil.EX)){
307 String[] basiSplit = authorBasiString.split(RedListUtil.EX);
308 for (int i = 0; i < basiSplit.length; i++) {
309 if(basiSplit.length!=2){
310 RedListUtil.logMessage(id, "Multiple ex basionymn authors found", logger);
311 }
312 if(i==0){
313 TeamOrPersonBase<?> authorBasi= (TeamOrPersonBase<?>) state.getRelatedObject(RedListUtil.AUTHOR_NAMESPACE, basiSplit[i]);
314 if(CdmUtils.isBlank(authorKombString)){
315 name.setExCombinationAuthorship(authorBasi);
316 }
317 else{
318 name.setExBasionymAuthorship(authorBasi);
319 }
320 }
321 else{
322 TeamOrPersonBase<?> authorBasi= (TeamOrPersonBase<?>) state.getRelatedObject(RedListUtil.AUTHOR_NAMESPACE, basiSplit[i]);
323 if(CdmUtils.isBlank(authorKombString)){
324 name.setCombinationAuthorship(authorBasi);
325 }
326 else{
327 name.setBasionymAuthorship(authorBasi);
328 }
329 }
330 }
331 }
332 else if(CdmUtils.isNotBlank(authorBasiString)){
333 //this seems to be a convention in the source database: When there is only a single author then only the "AUTOR_BASI" column is used
334 TeamOrPersonBase<?> authorBasi= (TeamOrPersonBase<?>) state.getRelatedObject(RedListUtil.AUTHOR_NAMESPACE, authorBasiString);
335 if(CdmUtils.isBlank(authorKombString)){
336 name.setCombinationAuthorship(authorBasi);
337 }
338 else{
339 name.setBasionymAuthorship(authorBasi);
340 }
341 }
342
343 //check authorship consistency
344 String authorString = rs.getString(RedListUtil.AUTOR);
345 String authorshipCache = name.getAuthorshipCache();
346 checkAuthorShipConsistency(id, nomZusatzString, taxZusatzString, zusatzString, authorString, authorshipCache);
347 }
348
349 private NonViralName<?> importName(RedListGefaesspflanzenImportState state, ResultSet rs, Set<TaxonNameBase<?,?>> namesToSave) throws SQLException {
350
351 long id = rs.getLong(RedListUtil.NAMNR);
352 String taxNameString = rs.getString(RedListUtil.TAXNAME);
353 String rangString = rs.getString(RedListUtil.RANG);
354 String ep1String = rs.getString(RedListUtil.EPI1);
355 String ep2String = rs.getString(RedListUtil.EPI2);
356 String ep3String = rs.getString(RedListUtil.EPI3);
357 String nomZusatzString = rs.getString(RedListUtil.NOM_ZUSATZ);
358 String hybString = rs.getString(RedListUtil.HYB);
359
360 if(CdmUtils.isBlank(taxNameString) && CdmUtils.isBlank(ep1String)){
361 RedListUtil.logMessage(id, "No name found!", logger);
362 }
363
364 Rank rank = makeRank(id, state, rangString, ep3String!=null);
365 NonViralName<?> name = BotanicalName.NewInstance(rank);
366
367 //ep1 should always be present
368 if(CdmUtils.isBlank(ep1String)){
369 RedListUtil.logMessage(id, RedListUtil.EPI1+" is empty!", logger);
370 }
371 name.setGenusOrUninomial(ep1String);
372 if(CdmUtils.isNotBlank(ep2String)){
373 name.setSpecificEpithet(ep2String);
374 }
375 if(CdmUtils.isNotBlank(ep3String)){
376 name.setInfraSpecificEpithet(ep3String);
377 }
378 //nomenclatural status
379 if(CdmUtils.isNotBlank(nomZusatzString)){
380 NomenclaturalStatusType status = makeNomenclaturalStatus(id, state, nomZusatzString);
381 if(status!=null){
382 name.addStatus(NomenclaturalStatus.NewInstance(status));
383 }
384 }
385 //hybrid
386 if(CdmUtils.isNotBlank(hybString)){
387 if(hybString.equals(RedListUtil.HYB_X)){
388 name.setBinomHybrid(true);
389 }
390 else if(hybString.equals(RedListUtil.HYB_G)){
391 name.setMonomHybrid(true);
392 }
393 else if(hybString.equals(RedListUtil.HYB_XF)){
394 name.setHybridFormula(true);
395 if(ep1String.contains(RedListUtil.HYB_SIGN)){
396 RedListUtil.logMessage(id, "EPI1 has hybrid signs but with flag: "+RedListUtil.HYB_XF, logger);
397 }
398 else if(ep2String.contains(RedListUtil.HYB_SIGN)){
399 String[] split = ep2String.split(RedListUtil.HYB_SIGN);
400 if(split.length!=2){
401 RedListUtil.logMessage(id, "Multiple hybrid signs found in "+ep2String, logger);
402 }
403 String hybridFormula1 = ep1String+" "+split[0].trim();
404 String hybridFormula2 = ep1String+" "+split[1].trim();
405 if(CdmUtils.isNotBlank(ep3String)){
406 hybridFormula1 += " "+ep3String;
407 hybridFormula2 += " "+ep3String;
408 }
409 String fullFormula = hybridFormula1+" "+RedListUtil.HYB_SIGN+" "+hybridFormula2;
410 name = NonViralNameParserImpl.NewInstance().parseFullName(fullFormula);
411 }
412 else if(ep3String.contains(RedListUtil.HYB_SIGN)){
413 String[] split = ep3String.split(RedListUtil.HYB_SIGN);
414 if(split.length!=2){
415 RedListUtil.logMessage(id, "Multiple hybrid signs found in "+ep3String, logger);
416 }
417 String hybridFormula1 = ep1String+" "+ep2String+" "+split[0];
418 String hybridFormula2 = ep1String+" "+ep2String+" "+split[1];
419 String fullFormula = hybridFormula1+" "+RedListUtil.HYB_SIGN+" "+hybridFormula2;
420 name = NonViralNameParserImpl.NewInstance().parseFullName(fullFormula);
421 }
422 }
423 else if(hybString.equals(RedListUtil.HYB_N)){
424 name = NonViralNameParserImpl.NewInstance().parseFullName(ep1String+" "+ep2String+" nothosubsp. "+ep3String);
425 }
426 else if(hybString.equals(RedListUtil.HYB_GF)){
427 if(ep1String.contains(RedListUtil.HYB_SIGN)){
428 name = NonViralNameParserImpl.NewInstance().parseFullName(ep1String);
429 }
430 else{
431 RedListUtil.logMessage(id, "HYB is "+hybString+" but "+RedListUtil.HYB+" does not contain "+RedListUtil.HYB_SIGN, logger);
432 }
433 }
434 else{
435 logger.error("HYB value "+hybString+" not yet handled");
436 }
437 }
438 //add source
439 ImportHelper.setOriginalSource(name, state.getTransactionalSourceReference(), id, RedListUtil.NAME_NAMESPACE);
440
441 namesToSave.add(name);
442 return name;
443 }
444
445 private void checkAuthorShipConsistency(long id, String nomZusatzString, String taxZusatzString,
446 String zusatzString, String authorString, String authorshipCache) {
447 if(CdmUtils.isNotBlank(zusatzString)){
448 authorString = authorString.replace(", "+zusatzString, "");
449 }
450 if(CdmUtils.isNotBlank(nomZusatzString)){
451 authorString = authorString.replace(", "+nomZusatzString, "");
452 }
453 if(CdmUtils.isNotBlank(taxZusatzString)){
454 authorString = authorString.replace(", "+taxZusatzString, "");
455 }
456 if(authorString.equals(RedListUtil.AUCT)){
457 authorString = "";
458 }
459 if(!authorString.equals(authorshipCache)){
460 RedListUtil.logMessage(id, "Authorship inconsistent! name.authorhshipCache <-> Column "+RedListUtil.AUTOR+": "+authorshipCache+" <-> "+authorString, logger);
461 }
462 }
463
464 private void checkTaxonNameConsistency(long id, String taxNameString, String hybString, TaxonBase<?> taxonBase) {
465 if(hybString.equals(RedListUtil.HYB_XF)){
466 if(HibernateProxyHelper.deproxy(taxonBase.getName(),NonViralName.class).getHybridChildRelations().isEmpty()){
467 RedListUtil.logMessage(id, "Hybrid name but no hybrid child relations", logger);
468 return;
469 }
470 return;
471 }
472
473
474 String nameCache = HibernateProxyHelper.deproxy(taxonBase.getName(), NonViralName.class).getNameCache().trim();
475
476 if(taxNameString.endsWith("agg.")){
477 taxNameString = taxNameString.replace("agg.", "aggr.");
478 }
479 if(hybString.equals(RedListUtil.HYB_X)){
480 taxNameString = taxNameString.replace(RedListUtil.HYB_SIGN+" ", RedListUtil.HYB_SIGN);//hybrid sign has no space after it in titleCache for binomial hybrids
481 }
482 if(taxNameString.endsWith("- Gruppe")){
483 taxNameString.replaceAll("- Gruppe", "species group");
484 }
485 if(taxNameString.endsWith("- group")){
486 taxNameString.replaceAll("- group", "species group");
487 }
488 taxNameString = taxNameString.replace("[ranglos]", "[unranked]");
489 if(!taxNameString.trim().equals(nameCache)){
490 RedListUtil.logMessage(id, "Taxon name inconsistent! taxon.titleCache <-> Column "+RedListUtil.TAXNAME+": "+nameCache+" <-> "+taxNameString, logger);
491 }
492 }
493
494 private Rank makeRank(long id, RedListGefaesspflanzenImportState state, String rankStr, boolean hasSpecificEpithet) {
495 Rank rank = null;
496 try {
497 if(rankStr.equals("ORA")){
498 //special handling for ORA because of two possibilities
499 if(hasSpecificEpithet){
500 return Rank.UNRANKED_INFRASPECIFIC();
501 }
502 else{
503 return Rank.UNRANKED_INFRAGENERIC();
504 }
505 }
506 else{
507 rank = state.getTransformer().getRankByKey(rankStr);
508 }
509 } catch (UndefinedTransformerMethodException e) {
510 e.printStackTrace();
511 }
512 if(rank==null){
513 RedListUtil.logMessage(id, rankStr+" could not be associated to a known rank.", logger);
514 }
515 return rank;
516 }
517
518 private NomenclaturalStatusType makeNomenclaturalStatus(long id, RedListGefaesspflanzenImportState state, String nomZusatzString) {
519 NomenclaturalStatusType status = null;
520 try {
521 status = state.getTransformer().getNomenclaturalStatusByKey(nomZusatzString);
522 } catch (UndefinedTransformerMethodException e) {
523 e.printStackTrace();
524 }
525 if(status==null){
526 RedListUtil.logMessage(id, nomZusatzString+" could not be associated to a known nomenclatural status.", logger);
527 }
528 return status;
529 }
530
531
532
533 @Override
534 public Map<Object, Map<String, ? extends CdmBase>> getRelatedObjectsForPartition(ResultSet rs,
535 RedListGefaesspflanzenImportState state) {
536 Map<Object, Map<String, ? extends CdmBase>> result = new HashMap<>();
537 Map<String, AgentBase<?>> authorMap = new HashMap<String, AgentBase<?>>();
538
539 try {
540 while (rs.next()){
541 String authorKombString = rs.getString(RedListUtil.AUTOR_KOMB);
542
543 if(authorKombString.contains(RedListUtil.EX)){
544 String[] kombSplit = authorKombString.split(RedListUtil.EX);
545 for (int i = 0; i < kombSplit.length; i++) {
546 if(!authorMap.containsKey(kombSplit[i])){
547 authorMap.put(kombSplit[i], getAgentService().load(state.getAuthorMap().get(kombSplit[i])));
548 }
549 }
550 }
551 else if(CdmUtils.isNotBlank(authorKombString) && !authorMap.containsKey(authorKombString)){
552 authorMap.put(authorKombString, getAgentService().load(state.getAuthorMap().get(authorKombString)));
553 }
554
555 String authorBasiString = rs.getString(RedListUtil.AUTOR_BASI);
556 //basionym author
557 if(authorBasiString.contains(RedListUtil.EX)){
558 String[] basiSplit = authorBasiString.split(RedListUtil.EX);
559 for (int i = 0; i < basiSplit.length; i++) {
560 if(!authorMap.containsKey(basiSplit[i])){
561 authorMap.put(basiSplit[i], getAgentService().load(state.getAuthorMap().get(basiSplit[i])));
562 }
563 }
564 }
565 else if(CdmUtils.isNotBlank(authorBasiString) && !authorMap.containsKey(authorBasiString)){
566 authorMap.put(authorBasiString, getAgentService().load(state.getAuthorMap().get(authorBasiString)));
567 }
568 }
569 } catch (SQLException e) {
570 e.printStackTrace();
571 }
572 result.put(RedListUtil.AUTHOR_NAMESPACE, authorMap);
573
574 return result;
575 }
576
577 @Override
578 protected boolean doCheck(RedListGefaesspflanzenImportState state) {
579 return false;
580 }
581
582 @Override
583 protected boolean isIgnore(RedListGefaesspflanzenImportState state) {
584 return false;
585 }
586
587 }