2 * Copyright (C) 2007 EDIT
3 * European Distributed Institute of Taxonomy
4 * http://www.e-taxonomy.eu
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.
10 package eu
.etaxonomy
.cdm
.io
.redlist
.gefaesspflanzen
;
12 import java
.sql
.ResultSet
;
13 import java
.sql
.SQLException
;
14 import java
.util
.HashMap
;
15 import java
.util
.HashSet
;
18 import java
.util
.regex
.Matcher
;
19 import java
.util
.regex
.Pattern
;
21 import org
.apache
.log4j
.Logger
;
22 import org
.springframework
.stereotype
.Component
;
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
.CultivarPlantName
;
41 import eu
.etaxonomy
.cdm
.model
.name
.NomenclaturalCode
;
42 import eu
.etaxonomy
.cdm
.model
.name
.NomenclaturalStatus
;
43 import eu
.etaxonomy
.cdm
.model
.name
.NomenclaturalStatusType
;
44 import eu
.etaxonomy
.cdm
.model
.name
.NonViralName
;
45 import eu
.etaxonomy
.cdm
.model
.name
.Rank
;
46 import eu
.etaxonomy
.cdm
.model
.name
.TaxonNameBase
;
47 import eu
.etaxonomy
.cdm
.model
.taxon
.Synonym
;
48 import eu
.etaxonomy
.cdm
.model
.taxon
.Taxon
;
49 import eu
.etaxonomy
.cdm
.model
.taxon
.TaxonBase
;
50 import eu
.etaxonomy
.cdm
.model
.taxon
.TaxonRelationship
;
51 import eu
.etaxonomy
.cdm
.model
.taxon
.TaxonRelationshipType
;
52 import eu
.etaxonomy
.cdm
.strategy
.parser
.NonViralNameParserImpl
;
62 @SuppressWarnings("serial")
63 public class RedListGefaesspflanzenImportNames
extends DbImportBase
<RedListGefaesspflanzenImportState
, RedListGefaesspflanzenImportConfigurator
> {
65 private static final Logger logger
= Logger
.getLogger(RedListGefaesspflanzenImportNames
.class);
67 private static final String tableName
= "Rote Liste Gefäßpflanzen";
69 private static final String pluralString
= "names";
71 private static final boolean STRICT_TITLE_CHECK
= false;
73 public RedListGefaesspflanzenImportNames() {
74 super(tableName
, pluralString
);
78 protected String
getIdQuery(RedListGefaesspflanzenImportState state
) {
79 return "SELECT NAMNR "
80 + "FROM V_TAXATLAS_D20_EXPORT t "
85 protected String
getRecordQuery(RedListGefaesspflanzenImportConfigurator config
) {
86 String result
= " SELECT * "
87 + " FROM V_TAXATLAS_D20_EXPORT t "
88 + " WHERE t.NAMNR IN (@IDSET)";
89 result
= result
.replace("@IDSET", IPartitionedIO
.ID_LIST_TOKEN
);
94 protected void doInvoke(RedListGefaesspflanzenImportState state
) {
95 super.doInvoke(state
);
100 public boolean doPartition(ResultSetPartitioner partitioner
, RedListGefaesspflanzenImportState state
) {
101 ResultSet rs
= partitioner
.getResultSet();
102 Set
<TaxonNameBase
> namesToSave
= new HashSet
<TaxonNameBase
>();
103 Set
<TaxonBase
> taxaToSave
= new HashSet
<TaxonBase
>();
106 makeSingleNameAndTaxon(state
, rs
, namesToSave
, taxaToSave
);
109 } catch (SQLException e
) {
113 getNameService().saveOrUpdate(namesToSave
);
114 getTaxonService().saveOrUpdate(taxaToSave
);
118 private void makeSingleNameAndTaxon(RedListGefaesspflanzenImportState state
, ResultSet rs
, Set
<TaxonNameBase
> namesToSave
, Set
<TaxonBase
> taxaToSave
)
119 throws SQLException
{
120 long id
= rs
.getLong(RedListUtil
.NAMNR
);
121 String clTaxonString
= rs
.getString(RedListUtil
.CL_TAXON
);
122 String relationE
= rs
.getString(RedListUtil
.E
);
123 String relationW
= rs
.getString(RedListUtil
.W
);
124 String relationK
= rs
.getString(RedListUtil
.K
);
125 String relationAW
= rs
.getString(RedListUtil
.AW
);
126 String relationAO
= rs
.getString(RedListUtil
.AO
);
127 String relationR
= rs
.getString(RedListUtil
.R
);
128 String relationO
= rs
.getString(RedListUtil
.O
);
129 String relationS
= rs
.getString(RedListUtil
.S
);
132 NonViralName
<?
> name
= importName(state
, rs
, namesToSave
);
136 importAuthors(state
, rs
, name
);
139 TaxonBase
<?
> taxonBase
= importTaxon(rs
, name
);
141 RedListUtil
.logMessage(id
, "Taxon for name "+name
+" could not be created.", logger
);
145 //---CONCEPT RELATIONSHIPS---
146 //E, W, K, AW, AO, R, O, S
147 cloneTaxon(taxonBase
, relationE
, RedListUtil
.CLASSIFICATION_NAMESPACE_E
, taxaToSave
, id
, state
);
148 cloneTaxon(taxonBase
, relationW
, RedListUtil
.CLASSIFICATION_NAMESPACE_W
, taxaToSave
, id
, state
);
149 cloneTaxon(taxonBase
, relationK
, RedListUtil
.CLASSIFICATION_NAMESPACE_K
, taxaToSave
, id
, state
);
150 cloneTaxon(taxonBase
, relationAW
, RedListUtil
.CLASSIFICATION_NAMESPACE_AW
, taxaToSave
, id
, state
);
151 cloneTaxon(taxonBase
, relationAO
, RedListUtil
.CLASSIFICATION_NAMESPACE_AO
, taxaToSave
, id
, state
);
152 cloneTaxon(taxonBase
, relationR
, RedListUtil
.CLASSIFICATION_NAMESPACE_R
, taxaToSave
, id
, state
);
153 cloneTaxon(taxonBase
, relationO
, RedListUtil
.CLASSIFICATION_NAMESPACE_O
, taxaToSave
, id
, state
);
154 cloneTaxon(taxonBase
, relationS
, RedListUtil
.CLASSIFICATION_NAMESPACE_S
, taxaToSave
, id
, state
);
156 TaxonBase
<?
> checklistTaxon
= null;
157 if(CdmUtils
.isNotBlank(clTaxonString
) && !clTaxonString
.trim().equals("-")){
158 checklistTaxon
= (TaxonBase
<?
>) taxonBase
.clone();
159 if(checklistTaxon
.isInstanceOf(Taxon
.class)){
160 TaxonRelationship relation
= HibernateProxyHelper
.deproxy(checklistTaxon
, Taxon
.class).addTaxonRelation(HibernateProxyHelper
.deproxy(taxonBase
, Taxon
.class), TaxonRelationshipType
.CONGRUENT_TO(), null, null);
161 relation
.setDoubtful(true);
164 ImportHelper
.setOriginalSource(checklistTaxon
, state
.getTransactionalSourceReference(), id
, RedListUtil
.TAXON_CHECKLISTE_NAMESPACE
);
165 taxaToSave
.add(checklistTaxon
);
168 //NOTE: the source has to be added after cloning or otherwise the clone would also get the source
169 ImportHelper
.setOriginalSource(taxonBase
, state
.getTransactionalSourceReference(), id
, RedListUtil
.TAXON_GESAMTLISTE_NAMESPACE
);
170 taxaToSave
.add(taxonBase
);
173 private void cloneTaxon(final TaxonBase
<?
> gesamtListeTaxon
, String relationString
, String sourceNameSpace
, Set
<TaxonBase
> taxaToSave
, long id
, RedListGefaesspflanzenImportState state
){
174 if(CdmUtils
.isNotBlank(relationString
) && !relationString
.equals(".")){
175 Taxon clonedTaxon
= null;
177 if(gesamtListeTaxon
.isInstanceOf(Taxon
.class)){
178 clonedTaxon
= HibernateProxyHelper
.deproxy(gesamtListeTaxon
.clone(), Taxon
.class);
180 else if(gesamtListeTaxon
.isInstanceOf(Synonym
.class)){
181 clonedTaxon
= Taxon
.NewInstance(gesamtListeTaxon
.getName(), gesamtListeTaxon
.getSec());
184 RedListUtil
.logMessage(id
, "Taxon base "+gesamtListeTaxon
+" is neither taxon nor synonym! Taxon could not be cloned", logger
);
187 ImportHelper
.setOriginalSource(clonedTaxon
, state
.getTransactionalSourceReference(), id
, sourceNameSpace
);
188 taxaToSave
.add(clonedTaxon
);
192 private TaxonBase
<?
> importTaxon(ResultSet rs
, NonViralName
<?
> name
) throws SQLException
{
194 long id
= rs
.getLong(RedListUtil
.NAMNR
);
195 String taxNameString
= rs
.getString(RedListUtil
.TAXNAME
);
196 String gueltString
= rs
.getString(RedListUtil
.GUELT
);
197 String trivialString
= rs
.getString(RedListUtil
.TRIVIAL
);
198 String authorBasiString
= rs
.getString(RedListUtil
.AUTOR_BASI
);
199 String hybString
= rs
.getString(RedListUtil
.HYB
);
200 String florString
= rs
.getString(RedListUtil
.FLOR
);
201 String atlasIdxString
= rs
.getString(RedListUtil
.ATLAS_IDX
);
202 String kartString
= rs
.getString(RedListUtil
.KART
);
203 String rl2015String
= rs
.getString(RedListUtil
.RL2015
);
204 String ehrdString
= rs
.getString(RedListUtil
.EHRD
);
205 String wisskString
= rs
.getString(RedListUtil
.WISSK
);
207 TaxonBase
<?
> taxonBase
= null;
208 if(authorBasiString
.trim().contains(RedListUtil
.AUCT
)){
209 taxonBase
= Taxon
.NewInstance(name
, null);
210 taxonBase
.setAppendedPhrase(RedListUtil
.AUCT
);
212 else if(gueltString
.equals(RedListUtil
.GUELT_ACCEPTED_TAXON
)){
213 taxonBase
= Taxon
.NewInstance(name
, null);
215 else if(gueltString
.equals(RedListUtil
.GUELT_SYNONYM
) || gueltString
.equals(RedListUtil
.GUELT_BASIONYM
)){
216 taxonBase
= Synonym
.NewInstance(name
, null);
223 if(taxonBase
.isInstanceOf(Taxon
.class) && trivialString
!=null){
224 Taxon taxon
= HibernateProxyHelper
.deproxy(taxonBase
, Taxon
.class);
225 TaxonDescription description
= TaxonDescription
.NewInstance(taxon
);
226 description
.addElement(CommonTaxonName
.NewInstance(trivialString
, Language
.GERMAN()));
230 addAnnotation(RedListUtil
.FLOR
+": "+florString
, taxonBase
);
231 addAnnotation(RedListUtil
.ATLAS_IDX
+": "+atlasIdxString
, taxonBase
);
232 addAnnotation(RedListUtil
.KART
+": "+kartString
, taxonBase
);
233 addAnnotation(RedListUtil
.RL2015
+": "+rl2015String
, taxonBase
);
234 addAnnotation(RedListUtil
.EHRD
+": "+ehrdString
, taxonBase
);
235 addAnnotation(RedListUtil
.WISSK
+": "+wisskString
, taxonBase
);
237 //check taxon name consistency
238 checkTaxonConsistency(id
, taxNameString
, hybString
, taxonBase
);
242 private void addAnnotation(String string
, TaxonBase
<?
> taxonBase
) {
243 if(CdmUtils
.isNotBlank(string
)){
244 taxonBase
.addAnnotation(Annotation
.NewInstance(string
, AnnotationType
.TECHNICAL(), Language
.GERMAN()));
248 private void importAuthors(RedListGefaesspflanzenImportState state
, ResultSet rs
, NonViralName
<?
> name
) throws SQLException
{
250 long id
= rs
.getLong(RedListUtil
.NAMNR
);
251 String nomZusatzString
= rs
.getString(RedListUtil
.NOM_ZUSATZ
);
252 String taxZusatzString
= rs
.getString(RedListUtil
.TAX_ZUSATZ
);
253 String zusatzString
= rs
.getString(RedListUtil
.ZUSATZ
);
254 String authorKombString
= rs
.getString(RedListUtil
.AUTOR_KOMB
);
255 String authorBasiString
= rs
.getString(RedListUtil
.AUTOR_BASI
);
256 String hybString
= rs
.getString(RedListUtil
.HYB
);
259 if(authorKombString
.contains(RedListUtil
.EX
)){
260 //TODO: what happens with multiple ex authors??
261 String
[] kombSplit
= authorKombString
.split(RedListUtil
.EX
);
262 if(kombSplit
.length
!=2){
263 RedListUtil
.logMessage(id
, "Multiple ex combination authors found", logger
);
265 for (int i
= 0; i
< kombSplit
.length
; i
++) {
267 //first author is ex author
268 TeamOrPersonBase
<?
> authorKomb
= (TeamOrPersonBase
<?
>) state
.getRelatedObject(RedListUtil
.AUTHOR_NAMESPACE
, kombSplit
[i
]);
269 name
.setExCombinationAuthorship(authorKomb
);
272 TeamOrPersonBase
<?
> authorKomb
= (TeamOrPersonBase
<?
>) state
.getRelatedObject(RedListUtil
.AUTHOR_NAMESPACE
, kombSplit
[i
]);
273 name
.setCombinationAuthorship(authorKomb
);
277 else if(authorKombString
.trim().contains(RedListUtil
.AUCT
)){
278 RedListUtil
.logMessage(id
, "AUCT information in "+RedListUtil
.AUTOR_KOMB
+" column", logger
);
280 else if(CdmUtils
.isNotBlank(authorKombString
)){
281 TeamOrPersonBase
<?
> authorKomb
= (TeamOrPersonBase
<?
>) state
.getRelatedObject(RedListUtil
.AUTHOR_NAMESPACE
, authorKombString
);
282 name
.setCombinationAuthorship(authorKomb
);
285 if(authorBasiString
.contains(RedListUtil
.EX
)){
286 String
[] basiSplit
= authorBasiString
.split(RedListUtil
.EX
);
287 for (int i
= 0; i
< basiSplit
.length
; i
++) {
288 if(basiSplit
.length
!=2){
289 RedListUtil
.logMessage(id
, "Multiple ex basionymn authors found", logger
);
292 TeamOrPersonBase
<?
> authorBasi
= (TeamOrPersonBase
<?
>) state
.getRelatedObject(RedListUtil
.AUTHOR_NAMESPACE
, basiSplit
[i
]);
293 if(CdmUtils
.isBlank(authorKombString
)){
294 name
.setExCombinationAuthorship(authorBasi
);
297 name
.setExBasionymAuthorship(authorBasi
);
301 TeamOrPersonBase
<?
> authorBasi
= (TeamOrPersonBase
<?
>) state
.getRelatedObject(RedListUtil
.AUTHOR_NAMESPACE
, basiSplit
[i
]);
302 if(CdmUtils
.isBlank(authorKombString
)){
303 name
.setCombinationAuthorship(authorBasi
);
306 name
.setBasionymAuthorship(authorBasi
);
311 else if(CdmUtils
.isNotBlank(authorBasiString
)){
312 //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
313 TeamOrPersonBase
<?
> authorBasi
= (TeamOrPersonBase
<?
>) state
.getRelatedObject(RedListUtil
.AUTHOR_NAMESPACE
, authorBasiString
);
314 if(CdmUtils
.isBlank(authorKombString
)){
315 name
.setCombinationAuthorship(authorBasi
);
318 name
.setBasionymAuthorship(authorBasi
);
322 //check authorship consistency
323 String authorString
= rs
.getString(RedListUtil
.AUTOR
);
324 checkNameConsistency(id
, nomZusatzString
, taxZusatzString
, zusatzString
, authorString
, hybString
, name
);
327 private NonViralName
<?
> importName(RedListGefaesspflanzenImportState state
, ResultSet rs
, Set
<TaxonNameBase
> namesToSave
) throws SQLException
{
329 long id
= rs
.getLong(RedListUtil
.NAMNR
);
330 String taxNameString
= rs
.getString(RedListUtil
.TAXNAME
);
331 String rangString
= rs
.getString(RedListUtil
.RANG
);
332 String ep1String
= rs
.getString(RedListUtil
.EPI1
);
333 String ep2String
= rs
.getString(RedListUtil
.EPI2
);
334 String ep3String
= rs
.getString(RedListUtil
.EPI3
);
335 String nomZusatzString
= rs
.getString(RedListUtil
.NOM_ZUSATZ
);
336 String hybString
= rs
.getString(RedListUtil
.HYB
);
337 String formelString
= rs
.getString(RedListUtil
.FORMEL
);
339 if(CdmUtils
.isBlank(taxNameString
) && CdmUtils
.isBlank(ep1String
)){
340 RedListUtil
.logMessage(id
, "No name found!", logger
);
343 NonViralName
<?
> name
= null;
344 Rank rank
= makeRank(id
, state
, rangString
, ep3String
!=null);
346 if(rank
!= null && rank
.equals(Rank
.CULTIVAR())){
347 CultivarPlantName cultivar
= CultivarPlantName
.NewInstance(rank
);
348 cultivar
.setGenusOrUninomial(ep1String
);
349 cultivar
.setSpecificEpithet(ep2String
);
350 cultivar
.setCultivarName(ep3String
);
355 name
= BotanicalName
.NewInstance(rank
);
357 //ep1 should always be present
358 if(CdmUtils
.isBlank(ep1String
)){
359 RedListUtil
.logMessage(id
, RedListUtil
.EPI1
+" is empty!", logger
);
361 name
.setGenusOrUninomial(ep1String
);
362 if(CdmUtils
.isNotBlank(ep2String
)){
363 if(rank
!=null && rank
.isInfraGenericButNotSpeciesGroup()){
364 name
.setInfraGenericEpithet(ep2String
);
367 name
.setSpecificEpithet(ep2String
);
370 if(CdmUtils
.isNotBlank(ep3String
)){
371 name
.setInfraSpecificEpithet(ep3String
);
375 //nomenclatural status
376 if(CdmUtils
.isNotBlank(nomZusatzString
)){
377 NomenclaturalStatusType statusType
= makeNomenclaturalStatus(id
, state
, nomZusatzString
);
378 if(statusType
!=null){
379 NomenclaturalStatus status
= NomenclaturalStatus
.NewInstance(statusType
);
380 //special case for invalid names where the DB entry contains
381 //additional information in brackets e.g. "nom. inval. (sine basion.)"
382 if(statusType
.equals(NomenclaturalStatusType
.INVALID())){
383 Pattern pattern
= Pattern
.compile("\\((.*?)\\)");
384 Matcher matcher
= pattern
.matcher(nomZusatzString
);
386 status
.setRuleConsidered(matcher
.group(1));
389 name
.addStatus(status
);
393 if(CdmUtils
.isNotBlank(hybString
)){
394 //save hybrid formula
395 if(CdmUtils
.isNotBlank(formelString
)){
396 Annotation annotation
= Annotation
.NewDefaultLanguageInstance(formelString
);
397 annotation
.setAnnotationType(AnnotationType
.TECHNICAL());
398 name
.addAnnotation(annotation
);
400 //more than two hybrids not yet handled by name parser
401 //TODO: use parser when implemented to fully support hybrids
402 if(taxNameString
.split(RedListUtil
.HYB_SIGN
).length
>2){
403 name
= BotanicalName
.NewInstance(rank
);
404 name
.setTitleCache(taxNameString
, true);
406 else if(hybString
.equals(RedListUtil
.HYB_X
)){
407 name
.setBinomHybrid(true);
409 else if(hybString
.equals(RedListUtil
.HYB_G
)){
410 name
.setMonomHybrid(true);
412 else if(hybString
.equals(RedListUtil
.HYB_XF
)){
413 name
.setHybridFormula(true);
414 if(ep1String
.contains(RedListUtil
.HYB_SIGN
)){
415 RedListUtil
.logMessage(id
, "EPI1 has hybrid signs but with flag: "+RedListUtil
.HYB_XF
, logger
);
417 else if(ep2String
.contains(RedListUtil
.HYB_SIGN
)){
418 String
[] split
= ep2String
.split(RedListUtil
.HYB_SIGN
);
419 String hybridFormula1
= ep1String
+" "+split
[0].trim();
420 String hybridFormula2
= ep1String
+" "+split
[1].trim();
421 if(CdmUtils
.isNotBlank(ep3String
)){
422 hybridFormula1
+= " "+ep3String
;
423 hybridFormula2
+= " "+ep3String
;
425 String fullFormula
= hybridFormula1
+" "+RedListUtil
.HYB_SIGN
+" "+hybridFormula2
;
426 name
= NonViralNameParserImpl
.NewInstance().parseFullName(fullFormula
, NomenclaturalCode
.ICNAFP
, rank
);
428 else if(ep3String
.contains(RedListUtil
.HYB_SIGN
)){
429 String
[] split
= ep3String
.split(RedListUtil
.HYB_SIGN
);
430 String hybridFormula1
= ep1String
+" "+ep2String
+" "+split
[0];
431 String hybridFormula2
= ep1String
+" "+ep2String
+" "+split
[1];
432 String fullFormula
= hybridFormula1
+" "+RedListUtil
.HYB_SIGN
+" "+hybridFormula2
;
433 name
= NonViralNameParserImpl
.NewInstance().parseFullName(fullFormula
, NomenclaturalCode
.ICNAFP
, rank
);
436 else if(hybString
.equals(RedListUtil
.HYB_N
)){
437 name
= NonViralNameParserImpl
.NewInstance().parseFullName(taxNameString
, NomenclaturalCode
.ICNAFP
, rank
);
439 else if(hybString
.equals(RedListUtil
.HYB_GF
)){
440 if(ep1String
.contains(RedListUtil
.HYB_SIGN
)){
441 name
= NonViralNameParserImpl
.NewInstance().parseFullName(ep1String
, NomenclaturalCode
.ICNAFP
, rank
);
444 RedListUtil
.logMessage(id
, "HYB is "+hybString
+" but "+RedListUtil
.HYB
+" does not contain "+RedListUtil
.HYB_SIGN
, logger
);
447 else if(hybString
.equals(RedListUtil
.HYB_XS
)){
451 logger
.error("HYB value "+hybString
+" not yet handled");
456 ImportHelper
.setOriginalSource(name
, state
.getTransactionalSourceReference(), id
, RedListUtil
.NAME_NAMESPACE
);
458 namesToSave
.add(name
);
462 private void checkNameConsistency(long id
, String nomZusatzString
, String taxZusatzString
,
463 String zusatzString
, String authorString
, String hybString
, NonViralName
<?
> name
) {
464 String authorshipCache
= name
.getAuthorshipCache();
465 if(hybString
.equals(RedListUtil
.HYB_XF
)){
466 if(name
.getHybridChildRelations().isEmpty()){
467 RedListUtil
.logMessage(id
, "Hybrid formula but no hybrid child relations: "+name
.getTitleCache(), logger
);
473 if(CdmUtils
.isNotBlank(zusatzString
)){
474 authorString
= authorString
.replace(", "+zusatzString
, "");
476 if(CdmUtils
.isNotBlank(nomZusatzString
)){
477 authorString
= authorString
.replace(", "+nomZusatzString
, "");
479 if(CdmUtils
.isNotBlank(taxZusatzString
)){
480 authorString
= authorString
.replace(", "+taxZusatzString
, "");
482 if(authorString
.equals(RedListUtil
.AUCT
)){
485 if(STRICT_TITLE_CHECK
){
486 if(!authorString
.equals(authorshipCache
)){
487 RedListUtil
.logMessage(id
, "Authorship inconsistent! name.authorhshipCache <-> Column "+RedListUtil
.AUTOR
+": "+authorshipCache
+" <-> "+authorString
, logger
);
491 if(CdmUtils
.isNotBlank(authorString
) && !authorString
.startsWith(authorshipCache
)){
492 RedListUtil
.logMessage(id
, "Authorship inconsistent! name.authorhshipCache <-> Column "+RedListUtil
.AUTOR
+": "+authorshipCache
+" <-> "+authorString
, logger
);
497 private void checkTaxonConsistency(long id
, String taxNameString
, String hybString
, TaxonBase
<?
> taxonBase
) {
498 String nameCache
= HibernateProxyHelper
.deproxy(taxonBase
.getName(), NonViralName
.class).getNameCache().trim();
499 taxNameString
= taxNameString
.trim();
500 taxNameString
= taxNameString
.replaceAll(" +", " ");
502 if(taxNameString
.endsWith("agg.")){
503 taxNameString
= taxNameString
.replace("agg.", "aggr.");
506 if(hybString
.equals(RedListUtil
.HYB_X
) || hybString
.equals(RedListUtil
.HYB_N
)){
507 taxNameString
= taxNameString
.replace(" "+RedListUtil
.HYB_SIGN
+" ", " "+RedListUtil
.HYB_SIGN
);//hybrid sign has no space after it in titleCache for binomial hybrids
508 taxNameString
= taxNameString
.replace(" x ", " "+RedListUtil
.HYB_SIGN
);//in some cases a standard 'x' is used
510 else if(hybString
.equals(RedListUtil
.HYB_G
)){
511 taxNameString
= taxNameString
.replace("X ", RedListUtil
.HYB_SIGN
);
513 else if(hybString
.equals(RedListUtil
.HYB_GF
)){
514 taxNameString
= taxNameString
.replace(" "+RedListUtil
.HYB_SIGN
, " x");
517 if(taxNameString
.endsWith("- Gruppe")){
518 taxNameString
= taxNameString
.replaceAll("- Gruppe", "species group");
520 if(taxNameString
.endsWith("- group")){
521 taxNameString
= taxNameString
.replaceAll("- group", "species group");
524 taxNameString
= taxNameString
.replace("[ranglos]", "[unranked]");
525 if(taxonBase
.getName().getRank()!=null && taxonBase
.getName().getRank().equals(Rank
.PROLES())){
526 taxNameString
= taxNameString
.replace("proles", "prol.");
528 if(STRICT_TITLE_CHECK
){
529 if(!taxNameString
.trim().equals(nameCache
)){
530 RedListUtil
.logMessage(id
, "Taxon name inconsistent! taxon.nameCache <-> Column "+RedListUtil
.TAXNAME
+": "+nameCache
+" <-> "+taxNameString
, logger
);
534 if(!taxNameString
.startsWith(nameCache
)){
535 RedListUtil
.logMessage(id
, "Taxon name inconsistent! taxon.nameCache <-> Column "+RedListUtil
.TAXNAME
+": "+nameCache
+" <-> "+taxNameString
, logger
);
540 private Rank
makeRank(long id
, RedListGefaesspflanzenImportState state
, String rankStr
, boolean hasSpecificEpithet
) {
543 if(rankStr
.equals("ORA")){
544 //special handling for ORA because of two possibilities
545 if(hasSpecificEpithet
){
546 return Rank
.UNRANKED_INFRASPECIFIC();
549 return Rank
.UNRANKED_INFRAGENERIC();
553 rank
= state
.getTransformer().getRankByKey(rankStr
);
555 } catch (UndefinedTransformerMethodException e
) {
559 RedListUtil
.logMessage(id
, rankStr
+" could not be associated to a known rank.", logger
);
564 private NomenclaturalStatusType
makeNomenclaturalStatus(long id
, RedListGefaesspflanzenImportState state
, String nomZusatzString
) {
565 NomenclaturalStatusType status
= null;
567 status
= state
.getTransformer().getNomenclaturalStatusByKey(nomZusatzString
);
568 } catch (UndefinedTransformerMethodException e
) {
572 RedListUtil
.logMessage(id
, nomZusatzString
+" could not be associated to a known nomenclatural status.", logger
);
580 public Map
<Object
, Map
<String
, ?
extends CdmBase
>> getRelatedObjectsForPartition(ResultSet rs
,
581 RedListGefaesspflanzenImportState state
) {
582 Map
<Object
, Map
<String
, ?
extends CdmBase
>> result
= new HashMap
<>();
583 Map
<String
, AgentBase
<?
>> authorMap
= new HashMap
<String
, AgentBase
<?
>>();
587 String authorKombString
= rs
.getString(RedListUtil
.AUTOR_KOMB
);
589 if(authorKombString
.contains(RedListUtil
.EX
)){
590 String
[] kombSplit
= authorKombString
.split(RedListUtil
.EX
);
591 for (int i
= 0; i
< kombSplit
.length
; i
++) {
592 if(!authorMap
.containsKey(kombSplit
[i
])){
593 authorMap
.put(kombSplit
[i
], getAgentService().load(state
.getAuthorMap().get(kombSplit
[i
])));
597 else if(CdmUtils
.isNotBlank(authorKombString
) && !authorMap
.containsKey(authorKombString
)){
598 authorMap
.put(authorKombString
, getAgentService().load(state
.getAuthorMap().get(authorKombString
)));
601 String authorBasiString
= rs
.getString(RedListUtil
.AUTOR_BASI
);
603 if(authorBasiString
.contains(RedListUtil
.EX
)){
604 String
[] basiSplit
= authorBasiString
.split(RedListUtil
.EX
);
605 for (int i
= 0; i
< basiSplit
.length
; i
++) {
606 if(!authorMap
.containsKey(basiSplit
[i
])){
607 authorMap
.put(basiSplit
[i
], getAgentService().load(state
.getAuthorMap().get(basiSplit
[i
])));
611 else if(CdmUtils
.isNotBlank(authorBasiString
) && !authorMap
.containsKey(authorBasiString
)){
612 authorMap
.put(authorBasiString
, getAgentService().load(state
.getAuthorMap().get(authorBasiString
)));
615 } catch (SQLException e
) {
618 result
.put(RedListUtil
.AUTHOR_NAMESPACE
, authorMap
);
624 protected boolean doCheck(RedListGefaesspflanzenImportState state
) {
629 protected boolean isIgnore(RedListGefaesspflanzenImportState state
) {