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