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
.AnnotatableEntity
;
34 import eu
.etaxonomy
.cdm
.model
.common
.Annotation
;
35 import eu
.etaxonomy
.cdm
.model
.common
.AnnotationType
;
36 import eu
.etaxonomy
.cdm
.model
.common
.CdmBase
;
37 import eu
.etaxonomy
.cdm
.model
.common
.Language
;
38 import eu
.etaxonomy
.cdm
.model
.common
.OrderedTermVocabulary
;
39 import eu
.etaxonomy
.cdm
.model
.description
.CommonTaxonName
;
40 import eu
.etaxonomy
.cdm
.model
.description
.TaxonDescription
;
41 import eu
.etaxonomy
.cdm
.model
.name
.BotanicalName
;
42 import eu
.etaxonomy
.cdm
.model
.name
.CultivarPlantName
;
43 import eu
.etaxonomy
.cdm
.model
.name
.NomenclaturalCode
;
44 import eu
.etaxonomy
.cdm
.model
.name
.NomenclaturalStatus
;
45 import eu
.etaxonomy
.cdm
.model
.name
.NomenclaturalStatusType
;
46 import eu
.etaxonomy
.cdm
.model
.name
.NonViralName
;
47 import eu
.etaxonomy
.cdm
.model
.name
.Rank
;
48 import eu
.etaxonomy
.cdm
.model
.name
.RankClass
;
49 import eu
.etaxonomy
.cdm
.model
.name
.TaxonNameBase
;
50 import eu
.etaxonomy
.cdm
.model
.taxon
.Synonym
;
51 import eu
.etaxonomy
.cdm
.model
.taxon
.Taxon
;
52 import eu
.etaxonomy
.cdm
.model
.taxon
.TaxonBase
;
53 import eu
.etaxonomy
.cdm
.model
.taxon
.TaxonRelationship
;
54 import eu
.etaxonomy
.cdm
.model
.taxon
.TaxonRelationshipType
;
55 import eu
.etaxonomy
.cdm
.strategy
.parser
.NonViralNameParserImpl
;
65 @SuppressWarnings("serial")
66 public class RedListGefaesspflanzenImportNames
extends DbImportBase
<RedListGefaesspflanzenImportState
, RedListGefaesspflanzenImportConfigurator
> {
68 private static final Logger logger
= Logger
.getLogger(RedListGefaesspflanzenImportNames
.class);
70 private static final String tableName
= "Rote Liste Gefäßpflanzen";
72 private static final String pluralString
= "names";
74 private static final boolean STRICT_TITLE_CHECK
= false;
76 public RedListGefaesspflanzenImportNames() {
77 super(tableName
, pluralString
);
81 protected String
getIdQuery(RedListGefaesspflanzenImportState state
) {
82 return "SELECT SEQNUM "
83 + "FROM V_TAXATLAS_D20_EXPORT t "
88 protected String
getRecordQuery(RedListGefaesspflanzenImportConfigurator config
) {
89 String result
= " SELECT * "
90 + " FROM V_TAXATLAS_D20_EXPORT t "
91 + " WHERE t.SEQNUM IN (@IDSET)";
92 result
= result
.replace("@IDSET", IPartitionedIO
.ID_LIST_TOKEN
);
97 protected void doInvoke(RedListGefaesspflanzenImportState state
) {
98 super.doInvoke(state
);
103 public boolean doPartition(ResultSetPartitioner partitioner
, RedListGefaesspflanzenImportState state
) {
104 ResultSet rs
= partitioner
.getResultSet();
105 Set
<TaxonNameBase
> namesToSave
= new HashSet
<TaxonNameBase
>();
106 Set
<TaxonBase
> taxaToSave
= new HashSet
<TaxonBase
>();
109 makeSingleNameAndTaxon(state
, rs
, namesToSave
, taxaToSave
);
112 } catch (SQLException e
) {
116 getNameService().saveOrUpdate(namesToSave
);
117 getTaxonService().saveOrUpdate(taxaToSave
);
121 private void makeSingleNameAndTaxon(RedListGefaesspflanzenImportState state
, ResultSet rs
, Set
<TaxonNameBase
> namesToSave
, Set
<TaxonBase
> taxaToSave
)
122 throws SQLException
{
123 long id
= rs
.getLong(RedListUtil
.NAMNR
);
124 String clTaxonString
= rs
.getString(RedListUtil
.CL_TAXON
);
125 String relationE
= rs
.getString(RedListUtil
.E
);
126 String relationW
= rs
.getString(RedListUtil
.W
);
127 String relationK
= rs
.getString(RedListUtil
.K
);
128 String relationAW
= rs
.getString(RedListUtil
.AW
);
129 String relationAO
= rs
.getString(RedListUtil
.AO
);
130 String relationR
= rs
.getString(RedListUtil
.R
);
131 String relationO
= rs
.getString(RedListUtil
.O
);
132 String relationS
= rs
.getString(RedListUtil
.S
);
135 NonViralName
<?
> name
= importName(state
, rs
, namesToSave
);
139 importAuthors(state
, rs
, name
);
142 TaxonBase
<?
> taxonBase
= importTaxon(rs
, name
, state
);
144 RedListUtil
.logMessage(id
, "Taxon for name "+name
+" could not be created.", logger
);
148 //---CONCEPT RELATIONSHIPS---
149 //E, W, K, AW, AO, R, O, S
150 cloneTaxon(taxonBase
, relationE
, RedListUtil
.CLASSIFICATION_NAMESPACE_E
, taxaToSave
, id
, state
);
151 cloneTaxon(taxonBase
, relationW
, RedListUtil
.CLASSIFICATION_NAMESPACE_W
, taxaToSave
, id
, state
);
152 cloneTaxon(taxonBase
, relationK
, RedListUtil
.CLASSIFICATION_NAMESPACE_K
, taxaToSave
, id
, state
);
153 cloneTaxon(taxonBase
, relationAW
, RedListUtil
.CLASSIFICATION_NAMESPACE_AW
, taxaToSave
, id
, state
);
154 cloneTaxon(taxonBase
, relationAO
, RedListUtil
.CLASSIFICATION_NAMESPACE_AO
, taxaToSave
, id
, state
);
155 cloneTaxon(taxonBase
, relationR
, RedListUtil
.CLASSIFICATION_NAMESPACE_R
, taxaToSave
, id
, state
);
156 cloneTaxon(taxonBase
, relationO
, RedListUtil
.CLASSIFICATION_NAMESPACE_O
, taxaToSave
, id
, state
);
157 cloneTaxon(taxonBase
, relationS
, RedListUtil
.CLASSIFICATION_NAMESPACE_S
, taxaToSave
, id
, state
);
159 TaxonBase
<?
> checklistTaxon
= null;
160 if(CdmUtils
.isNotBlank(clTaxonString
) && !clTaxonString
.trim().equals("-")){
161 checklistTaxon
= (TaxonBase
<?
>) taxonBase
.clone();
162 if(checklistTaxon
.isInstanceOf(Taxon
.class)){
163 TaxonRelationship relation
= HibernateProxyHelper
.deproxy(checklistTaxon
, Taxon
.class).addTaxonRelation(HibernateProxyHelper
.deproxy(taxonBase
, Taxon
.class), TaxonRelationshipType
.CONGRUENT_TO(), null, null);
164 relation
.setDoubtful(true);
167 ImportHelper
.setOriginalSource(checklistTaxon
, state
.getTransactionalSourceReference(), id
, RedListUtil
.TAXON_CHECKLISTE_NAMESPACE
);
168 taxaToSave
.add(checklistTaxon
);
171 //NOTE: the source has to be added after cloning or otherwise the clone would also get the source
172 ImportHelper
.setOriginalSource(taxonBase
, state
.getTransactionalSourceReference(), id
, RedListUtil
.TAXON_GESAMTLISTE_NAMESPACE
);
173 taxaToSave
.add(taxonBase
);
176 private void cloneTaxon(final TaxonBase
<?
> gesamtListeTaxon
, String relationString
, String sourceNameSpace
, Set
<TaxonBase
> taxaToSave
, long id
, RedListGefaesspflanzenImportState state
){
177 if(CdmUtils
.isNotBlank(relationString
) && !relationString
.equals(".")){
178 Taxon clonedTaxon
= null;
180 if(gesamtListeTaxon
.isInstanceOf(Taxon
.class)){
181 clonedTaxon
= HibernateProxyHelper
.deproxy(gesamtListeTaxon
.clone(), Taxon
.class);
183 else if(gesamtListeTaxon
.isInstanceOf(Synonym
.class)){
184 clonedTaxon
= Taxon
.NewInstance(gesamtListeTaxon
.getName(), gesamtListeTaxon
.getSec());
187 RedListUtil
.logMessage(id
, "Taxon base "+gesamtListeTaxon
+" is neither taxon nor synonym! Taxon could not be cloned", logger
);
190 ImportHelper
.setOriginalSource(clonedTaxon
, state
.getTransactionalSourceReference(), id
, sourceNameSpace
);
191 taxaToSave
.add(clonedTaxon
);
195 private TaxonBase
<?
> importTaxon(ResultSet rs
, NonViralName
<?
> name
, RedListGefaesspflanzenImportState state
) throws SQLException
{
197 long id
= rs
.getLong(RedListUtil
.NAMNR
);
198 String taxNameString
= rs
.getString(RedListUtil
.TAXNAME
);
199 String epi1String
= rs
.getString(RedListUtil
.EPI1
);
200 String epi2String
= rs
.getString(RedListUtil
.EPI2
);
201 String epi3String
= rs
.getString(RedListUtil
.EPI3
);
202 String gueltString
= rs
.getString(RedListUtil
.GUELT
);
203 String trivialString
= rs
.getString(RedListUtil
.TRIVIAL
);
204 String authorBasiString
= rs
.getString(RedListUtil
.AUTOR_BASI
);
205 String hybString
= rs
.getString(RedListUtil
.HYB
);
206 String florString
= rs
.getString(RedListUtil
.FLOR
);
207 String atlasIdxString
= rs
.getString(RedListUtil
.ATLAS_IDX
);
208 String kartString
= rs
.getString(RedListUtil
.KART
);
209 String rl2015String
= rs
.getString(RedListUtil
.RL2015
);
210 String ehrdString
= rs
.getString(RedListUtil
.EHRD
);
211 String wisskString
= rs
.getString(RedListUtil
.WISSK
);
213 TaxonBase
<?
> taxonBase
= null;
214 if(authorBasiString
.trim().contains(RedListUtil
.AUCT
)){
215 taxonBase
= Taxon
.NewInstance(name
, null);
216 taxonBase
.setAppendedPhrase(RedListUtil
.AUCT
);
218 else if(gueltString
.equals(RedListUtil
.GUELT_ACCEPTED_TAXON
)){
219 taxonBase
= Taxon
.NewInstance(name
, null);
221 else if(gueltString
.equals(RedListUtil
.GUELT_SYNONYM
) || gueltString
.equals(RedListUtil
.GUELT_BASIONYM
)){
222 taxonBase
= Synonym
.NewInstance(name
, null);
229 if(taxonBase
.isInstanceOf(Taxon
.class) && trivialString
!=null){
230 Taxon taxon
= HibernateProxyHelper
.deproxy(taxonBase
, Taxon
.class);
231 TaxonDescription description
= TaxonDescription
.NewInstance(taxon
);
232 description
.addElement(CommonTaxonName
.NewInstance(trivialString
, Language
.GERMAN()));
236 addAnnotation(RedListUtil
.FLOR
+": "+florString
, taxonBase
);
237 addAnnotation(RedListUtil
.ATLAS_IDX
+": "+atlasIdxString
, taxonBase
);
238 addAnnotation(RedListUtil
.KART
+": "+kartString
, taxonBase
);
239 addAnnotation(RedListUtil
.RL2015
+": "+rl2015String
, taxonBase
);
240 addAnnotation(RedListUtil
.EHRD
+": "+ehrdString
, taxonBase
);
241 addAnnotation(RedListUtil
.WISSK
+": "+wisskString
, taxonBase
);
243 //check taxon name consistency
244 checkTaxonConsistency(id
, taxNameString
, hybString
, epi1String
, epi2String
, epi3String
, taxonBase
, state
);
248 private void addAnnotation(String string
, AnnotatableEntity entity
) {
249 if(CdmUtils
.isNotBlank(string
)){
250 entity
.addAnnotation(Annotation
.NewInstance(string
, AnnotationType
.TECHNICAL(), Language
.GERMAN()));
254 private void importAuthors(RedListGefaesspflanzenImportState state
, ResultSet rs
, NonViralName
<?
> name
) throws SQLException
{
256 long id
= rs
.getLong(RedListUtil
.NAMNR
);
257 String nomZusatzString
= rs
.getString(RedListUtil
.NOM_ZUSATZ
);
258 String taxZusatzString
= rs
.getString(RedListUtil
.TAX_ZUSATZ
);
259 String zusatzString
= rs
.getString(RedListUtil
.ZUSATZ
);
260 String authorKombString
= rs
.getString(RedListUtil
.AUTOR_KOMB
);
261 String authorBasiString
= rs
.getString(RedListUtil
.AUTOR_BASI
);
262 String hybString
= rs
.getString(RedListUtil
.HYB
);
265 if(authorKombString
.contains(RedListUtil
.EX
)){
266 //TODO: what happens with multiple ex authors??
267 String
[] kombSplit
= authorKombString
.split(RedListUtil
.EX
);
268 if(kombSplit
.length
!=2){
269 RedListUtil
.logMessage(id
, "Multiple ex combination authors found", logger
);
271 for (int i
= 0; i
< kombSplit
.length
; i
++) {
273 //first author is ex author
274 TeamOrPersonBase
<?
> authorKomb
= (TeamOrPersonBase
<?
>) state
.getRelatedObject(RedListUtil
.AUTHOR_NAMESPACE
, kombSplit
[i
]);
275 name
.setExCombinationAuthorship(authorKomb
);
278 TeamOrPersonBase
<?
> authorKomb
= (TeamOrPersonBase
<?
>) state
.getRelatedObject(RedListUtil
.AUTHOR_NAMESPACE
, kombSplit
[i
]);
279 name
.setCombinationAuthorship(authorKomb
);
283 else if(authorKombString
.trim().contains(RedListUtil
.AUCT
)){
284 RedListUtil
.logMessage(id
, "AUCT information in "+RedListUtil
.AUTOR_KOMB
+" column", logger
);
286 else if(CdmUtils
.isNotBlank(authorKombString
)){
287 TeamOrPersonBase
<?
> authorKomb
= (TeamOrPersonBase
<?
>) state
.getRelatedObject(RedListUtil
.AUTHOR_NAMESPACE
, authorKombString
);
288 name
.setCombinationAuthorship(authorKomb
);
291 if(authorBasiString
.contains(RedListUtil
.EX
)){
292 String
[] basiSplit
= authorBasiString
.split(RedListUtil
.EX
);
293 for (int i
= 0; i
< basiSplit
.length
; i
++) {
294 if(basiSplit
.length
!=2){
295 RedListUtil
.logMessage(id
, "Multiple ex basionymn authors found", logger
);
298 TeamOrPersonBase
<?
> authorBasi
= (TeamOrPersonBase
<?
>) state
.getRelatedObject(RedListUtil
.AUTHOR_NAMESPACE
, basiSplit
[i
]);
299 if(CdmUtils
.isBlank(authorKombString
)){
300 name
.setExCombinationAuthorship(authorBasi
);
303 name
.setExBasionymAuthorship(authorBasi
);
307 TeamOrPersonBase
<?
> authorBasi
= (TeamOrPersonBase
<?
>) state
.getRelatedObject(RedListUtil
.AUTHOR_NAMESPACE
, basiSplit
[i
]);
308 if(CdmUtils
.isBlank(authorKombString
)){
309 name
.setCombinationAuthorship(authorBasi
);
312 name
.setBasionymAuthorship(authorBasi
);
317 else if(CdmUtils
.isNotBlank(authorBasiString
)){
318 //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
319 TeamOrPersonBase
<?
> authorBasi
= (TeamOrPersonBase
<?
>) state
.getRelatedObject(RedListUtil
.AUTHOR_NAMESPACE
, authorBasiString
);
320 if(CdmUtils
.isBlank(authorKombString
)){
321 name
.setCombinationAuthorship(authorBasi
);
324 name
.setBasionymAuthorship(authorBasi
);
328 //check authorship consistency
329 String authorString
= rs
.getString(RedListUtil
.AUTOR
);
330 checkNameConsistency(id
, nomZusatzString
, taxZusatzString
, zusatzString
, authorString
, hybString
, name
);
333 private NonViralName
<?
> importName(RedListGefaesspflanzenImportState state
, ResultSet rs
, Set
<TaxonNameBase
> namesToSave
) throws SQLException
{
335 long id
= rs
.getLong(RedListUtil
.NAMNR
);
336 String taxNameString
= rs
.getString(RedListUtil
.TAXNAME
);
337 String rangString
= rs
.getString(RedListUtil
.RANG
);
338 String ep1String
= rs
.getString(RedListUtil
.EPI1
);
339 String ep2String
= rs
.getString(RedListUtil
.EPI2
);
340 String ep3String
= rs
.getString(RedListUtil
.EPI3
);
341 String nomZusatzString
= rs
.getString(RedListUtil
.NOM_ZUSATZ
);
342 String hybString
= rs
.getString(RedListUtil
.HYB
);
343 String formelString
= rs
.getString(RedListUtil
.FORMEL
);
345 if(CdmUtils
.isBlank(taxNameString
) && CdmUtils
.isBlank(ep1String
)){
346 RedListUtil
.logMessage(id
, "No name found!", logger
);
349 NonViralName
<?
> name
= null;
350 Rank rank
= makeRank(id
, state
, rangString
, CdmUtils
.isNotBlank(ep3String
));
352 if(rank
!= null && rank
.equals(Rank
.CULTIVAR())){
353 CultivarPlantName cultivar
= CultivarPlantName
.NewInstance(rank
);
354 cultivar
.setGenusOrUninomial(ep1String
);
355 cultivar
.setSpecificEpithet(ep2String
);
356 cultivar
.setCultivarName(ep3String
);
361 name
= BotanicalName
.NewInstance(rank
);
363 //ep1 should always be present
364 if(CdmUtils
.isBlank(ep1String
)){
365 RedListUtil
.logMessage(id
, RedListUtil
.EPI1
+" is empty!", logger
);
367 name
.setGenusOrUninomial(ep1String
);
368 if(CdmUtils
.isNotBlank(ep2String
)){
369 if(rank
!=null && rank
.isInfraGenericButNotSpeciesGroup()){
370 name
.setInfraGenericEpithet(ep2String
);
373 name
.setSpecificEpithet(ep2String
);
376 if(CdmUtils
.isNotBlank(ep3String
)){
377 name
.setInfraSpecificEpithet(ep3String
);
381 //nomenclatural status
382 if(CdmUtils
.isNotBlank(nomZusatzString
)){
383 NomenclaturalStatusType statusType
= makeNomenclaturalStatus(id
, state
, nomZusatzString
);
384 if(statusType
!=null){
385 NomenclaturalStatus status
= NomenclaturalStatus
.NewInstance(statusType
);
386 //special case for invalid names where the DB entry contains
387 //additional information in brackets e.g. "nom. inval. (sine basion.)"
388 if(statusType
.equals(NomenclaturalStatusType
.INVALID()) || statusType
.equals(NomenclaturalStatusType
.REJECTED()) ){
389 Pattern pattern
= Pattern
.compile("\\((.*?)\\)");
390 Matcher matcher
= pattern
.matcher(nomZusatzString
);
392 status
.setRuleConsidered(matcher
.group(1));
395 name
.addStatus(status
);
399 if(CdmUtils
.isNotBlank(hybString
)){
400 //save hybrid formula
401 if(CdmUtils
.isNotBlank(formelString
)){
402 Annotation annotation
= Annotation
.NewDefaultLanguageInstance(formelString
);
403 annotation
.setAnnotationType(AnnotationType
.TECHNICAL());
404 name
.addAnnotation(annotation
);
406 //more than two hybrids not yet handled by name parser
407 //TODO: use parser when implemented to fully support hybrids
408 if(taxNameString
.split(RedListUtil
.HYB_SIGN
).length
>2){
409 name
= BotanicalName
.NewInstance(rank
);
410 name
.setTitleCache(taxNameString
, true);
412 else if(hybString
.equals(RedListUtil
.HYB_X
)){
413 name
.setBinomHybrid(true);
415 else if(hybString
.equals(RedListUtil
.HYB_G
)){
416 name
.setMonomHybrid(true);
418 else if(hybString
.equals(RedListUtil
.HYB_XF
) || hybString
.equals(RedListUtil
.HYB_XU
)){
419 name
.setHybridFormula(true);
420 String fullFormula
= buildHybridFormula(ep1String
, ep2String
, ep3String
, rank
);
421 name
= NonViralNameParserImpl
.NewInstance().parseFullName(fullFormula
, NomenclaturalCode
.ICNAFP
, rank
);
423 else if(hybString
.equals(RedListUtil
.HYB_N
)){
424 name
= NonViralNameParserImpl
.NewInstance().parseFullName(taxNameString
, NomenclaturalCode
.ICNAFP
, rank
);
426 else if(hybString
.equals(RedListUtil
.HYB_GF
)){
427 if(ep1String
.contains(RedListUtil
.HYB_SIGN
)){
428 name
= NonViralNameParserImpl
.NewInstance().parseFullName(ep1String
, NomenclaturalCode
.ICNAFP
, rank
);
431 RedListUtil
.logMessage(id
, "HYB is "+hybString
+" but "+RedListUtil
.HYB
+" does not contain "+RedListUtil
.HYB_SIGN
, logger
);
434 else if(hybString
.equals(RedListUtil
.HYB_XS
)){
438 logger
.error("HYB value "+hybString
+" not yet handled");
444 ImportHelper
.setOriginalSource(name
, state
.getTransactionalSourceReference(), id
, RedListUtil
.NAME_NAMESPACE
);
446 namesToSave
.add(name
);
450 private String
buildHybridFormula(String ep1String
, String ep2String
, String ep3String
, Rank rank
) {
451 String fullFormula
= null;
452 if(ep1String
.contains(RedListUtil
.HYB_SIGN
)){
453 fullFormula
= ep1String
;
455 else if(ep2String
.contains(RedListUtil
.HYB_SIGN
)){
456 String
[] split
= ep2String
.split(RedListUtil
.HYB_SIGN
);
457 String hybridFormula1
= ep1String
+" "+split
[0].trim();
458 String hybridFormula2
= ep1String
+" "+split
[1].trim();
459 //check if the genus is mentioned in EP2 or not
460 String
[] secondHybrid
= split
[1].trim().split(" ");
461 //check if the genus is abbreviated like e.g. Centaurea jacea × C. decipiens
462 if(secondHybrid
.length
>1 && secondHybrid
[0].matches("[A-Z]\\.")){
463 hybridFormula2
= ep1String
+" "+split
[1].trim().substring(3);
465 else if(secondHybrid
.length
>1 && secondHybrid
[0].matches("[A-Z].*")){
466 hybridFormula2
= split
[1].trim();
468 if(CdmUtils
.isNotBlank(ep3String
)){
469 hybridFormula1
+= " "+rank
.getAbbreviation()+" "+ep3String
;
470 hybridFormula2
+= " "+rank
.getAbbreviation()+" "+ep3String
;
472 fullFormula
= hybridFormula1
+" "+RedListUtil
.HYB_SIGN
+" "+hybridFormula2
;
474 else if(ep3String
.contains(RedListUtil
.HYB_SIGN
)){
475 String
[] split
= ep3String
.split(RedListUtil
.HYB_SIGN
);
476 String hybridFormula1
= ep1String
+" "+ep2String
+" "+rank
.getAbbreviation()+" "+split
[0].trim();
477 String hybridFormula2
= ep1String
+" "+ep2String
+" "+rank
.getAbbreviation()+" "+split
[1].trim();
478 //check if the genus is mentioned in EP3 or not
479 String
[] secondHybrid
= split
[1].trim().split(" ");
480 //check if the genus is abbreviated like e.g. Centaurea jacea jacea × C. jacea subsp. decipiens
481 if(secondHybrid
.length
>1 && secondHybrid
[0].matches("[A-Z]\\.")){
482 hybridFormula2
= ep1String
+" "+split
[1].trim().substring(3);
484 else if(secondHybrid
.length
>1 && secondHybrid
[0].matches("[A-Z].*")){
485 hybridFormula2
= split
[1].trim();
487 fullFormula
= hybridFormula1
+" "+RedListUtil
.HYB_SIGN
+" "+hybridFormula2
;
492 private void checkNameConsistency(long id
, String nomZusatzString
, String taxZusatzString
,
493 String zusatzString
, String authorString
, String hybString
, NonViralName
<?
> name
) {
494 String authorshipCache
= name
.getAuthorshipCache();
495 //FIXME: remove split length check when name parser can parse multiple hybrid parents
496 if(hybString
.equals(RedListUtil
.HYB_XF
) && name
.getTitleCache().split(RedListUtil
.HYB_SIGN
).length
==2){
497 if(name
.getHybridChildRelations().isEmpty()){
498 RedListUtil
.logMessage(id
, "Hybrid formula but no hybrid child relations: "+name
.getTitleCache(), logger
);
504 if(CdmUtils
.isNotBlank(zusatzString
)){
505 authorString
= authorString
.replace(", "+zusatzString
, "");
507 if(CdmUtils
.isNotBlank(nomZusatzString
)){
508 authorString
= authorString
.replace(", "+nomZusatzString
, "");
510 if(CdmUtils
.isNotBlank(taxZusatzString
)){
511 authorString
= authorString
.replace(", "+taxZusatzString
, "");
513 if(authorString
.equals(RedListUtil
.AUCT
)){
516 if(STRICT_TITLE_CHECK
){
517 if(!authorString
.equals(authorshipCache
)){
518 RedListUtil
.logMessage(id
, "Authorship inconsistent! name.authorhshipCache <-> Column "+RedListUtil
.AUTOR
+": "+authorshipCache
+" <-> "+authorString
, logger
);
522 if(CdmUtils
.isNotBlank(authorString
) && !authorString
.startsWith(authorshipCache
)){
523 RedListUtil
.logMessage(id
, "Authorship inconsistent! name.authorhshipCache <-> Column "+RedListUtil
.AUTOR
+": "+authorshipCache
+" <-> "+authorString
, logger
);
528 private void checkTaxonConsistency(long id
, String taxNameString
, String hybString
, String epi1String
, String epi2String
, String epi3String
, TaxonBase
<?
> taxonBase
, RedListGefaesspflanzenImportState state
) {
529 if(taxNameString
.split(RedListUtil
.HYB_SIGN
).length
>2){
530 RedListUtil
.logInfoMessage(id
, "multiple hybrid signs. No name check for "+taxNameString
, logger
);
534 String nameCache
= HibernateProxyHelper
.deproxy(taxonBase
.getName(), NonViralName
.class).getNameCache().trim();
535 taxNameString
= taxNameString
.trim();
536 taxNameString
= taxNameString
.replaceAll(" +", " ");
539 if(hybString
.equals(RedListUtil
.HYB_X
) || hybString
.equals(RedListUtil
.HYB_N
)){
540 taxNameString
= taxNameString
.replace(" "+RedListUtil
.HYB_SIGN
+" ", " "+RedListUtil
.HYB_SIGN
);//hybrid sign has no space after it in titleCache for binomial hybrids
541 taxNameString
= taxNameString
.replace(" x ", " "+RedListUtil
.HYB_SIGN
);//in some cases a standard 'x' is used
543 else if(hybString
.equals(RedListUtil
.HYB_G
)){
544 taxNameString
= taxNameString
.replace("X ", RedListUtil
.HYB_SIGN
);
546 else if(hybString
.equals(RedListUtil
.HYB_GF
)){
547 taxNameString
= taxNameString
.replace(" "+RedListUtil
.HYB_SIGN
+" ", " "+RedListUtil
.HYB_SIGN
);
549 else if(hybString
.equals(RedListUtil
.HYB_XF
)){
550 nameCache
= taxonBase
.getName().getTitleCache();
551 if(nameCache
.contains("sec")){
552 nameCache
= nameCache
.substring(0, nameCache
.indexOf("sec"));
554 if(!STRICT_TITLE_CHECK
){
555 taxNameString
= buildHybridFormula(epi1String
, epi2String
, epi3String
, taxonBase
.getName().getRank());
557 if(taxNameString
.split(RedListUtil
.HYB_SIGN
).length
==1){
558 taxNameString
= taxNameString
.replace(RedListUtil
.HYB_SIGN
+" ", RedListUtil
.HYB_SIGN
);
562 if(taxNameString
.endsWith("- Gruppe")){
563 taxNameString
= taxNameString
.replaceAll("- Gruppe", "species group");
565 if(taxNameString
.endsWith("- group")){
566 taxNameString
= taxNameString
.replaceAll("- group", "species group");
569 taxNameString
= taxNameString
.replace("agg.", "aggr.");
570 taxNameString
= taxNameString
.replace("[ranglos]", "[unranked]");
572 if(taxonBase
.getName().getRank()!=null){
573 if(taxonBase
.getName().getRank().equals(Rank
.PROLES())){
574 taxNameString
= taxNameString
.replace("proles", "prol.");
576 else if(taxonBase
.getName().getRank().equals(state
.getRank(RedListUtil
.uuidRankCollectionSpecies
))){
577 taxNameString
= taxNameString
.replace("\"Sammelart\"", "\"Coll. Species\"");
580 if(STRICT_TITLE_CHECK
){
581 if(!taxNameString
.trim().equals(nameCache
)){
582 RedListUtil
.logMessage(id
, "Taxon name inconsistent! taxon.nameCache <-> Column "+RedListUtil
.TAXNAME
+": "+nameCache
+" <-> "+taxNameString
, logger
);
586 if(!taxNameString
.startsWith(nameCache
)){
587 RedListUtil
.logMessage(id
, "Taxon name inconsistent! taxon.nameCache <-> Column "+RedListUtil
.TAXNAME
+": "+nameCache
+" <-> "+taxNameString
, logger
);
592 private Rank
makeRank(long id
, RedListGefaesspflanzenImportState state
, String rankStr
, boolean hasSpecificEpithet
) {
595 if(rankStr
.equals("ORA")){
596 //special handling for ORA because of two possibilities
597 if(hasSpecificEpithet
){
598 return Rank
.UNRANKED_INFRASPECIFIC();
601 return Rank
.UNRANKED_INFRAGENERIC();
604 else if(rankStr
.equals("SAM")){
605 return getRank(state
, RedListUtil
.uuidRankCollectionSpecies
, "Collective Species", "Collective Species", "\"Coll. Species\"", (OrderedTermVocabulary
<Rank
>) Rank
.GENUS().getVocabulary(), null, RankClass
.SpeciesGroup
);
607 else if(rankStr
.equals("SPR")){
608 return getRank(state
, RedListUtil
.uuidRankSubproles
, "Subproles", "Subproles", "subproles", (OrderedTermVocabulary
<Rank
>) Rank
.GENUS().getVocabulary(), null, RankClass
.Infraspecific
);
610 else if(rankStr
.equals("MOD")){
611 return getRank(state
, RedListUtil
.uuidRankModification
, "Modification", "Modification", "modificatio", (OrderedTermVocabulary
<Rank
>) Rank
.GENUS().getVocabulary(), null, RankClass
.Infraspecific
);
613 else if(rankStr
.equals("LUS")){
614 return getRank(state
, RedListUtil
.uuidRankLusus
, "Lusus", "Lusus", "lusus", (OrderedTermVocabulary
<Rank
>) Rank
.GENUS().getVocabulary(), null, RankClass
.Infraspecific
);
616 else if(rankStr
.equals("SPI")){
617 return getRank(state
, RedListUtil
.uuidRankSubspeciesPrincipes
, "Subspecies principes", "Subspecies principes", "subsp. princ.", (OrderedTermVocabulary
<Rank
>) Rank
.GENUS().getVocabulary(), null, RankClass
.Infraspecific
);
619 else if(rankStr
.equals("KMB")){
620 return getRank(state
, RedListUtil
.uuidRankCombination
, "Combination", "Combination", "", (OrderedTermVocabulary
<Rank
>) Rank
.GENUS().getVocabulary(), null, RankClass
.Infraspecific
);
623 rank
= state
.getTransformer().getRankByKey(rankStr
);
625 } catch (UndefinedTransformerMethodException e
) {
629 RedListUtil
.logMessage(id
, rankStr
+" could not be associated to a known rank.", logger
);
634 private NomenclaturalStatusType
makeNomenclaturalStatus(long id
, RedListGefaesspflanzenImportState state
, String nomZusatzString
) {
635 NomenclaturalStatusType status
= null;
637 status
= state
.getTransformer().getNomenclaturalStatusByKey(nomZusatzString
);
638 } catch (UndefinedTransformerMethodException e
) {
642 RedListUtil
.logMessage(id
, nomZusatzString
+" could not be associated to a known nomenclatural status.", logger
);
650 public Map
<Object
, Map
<String
, ?
extends CdmBase
>> getRelatedObjectsForPartition(ResultSet rs
,
651 RedListGefaesspflanzenImportState state
) {
652 Map
<Object
, Map
<String
, ?
extends CdmBase
>> result
= new HashMap
<>();
653 Map
<String
, AgentBase
<?
>> authorMap
= new HashMap
<String
, AgentBase
<?
>>();
657 String authorKombString
= rs
.getString(RedListUtil
.AUTOR_KOMB
);
659 if(authorKombString
.contains(RedListUtil
.EX
)){
660 String
[] kombSplit
= authorKombString
.split(RedListUtil
.EX
);
661 for (int i
= 0; i
< kombSplit
.length
; i
++) {
662 if(!authorMap
.containsKey(kombSplit
[i
])){
663 authorMap
.put(kombSplit
[i
], getAgentService().load(state
.getAuthorMap().get(kombSplit
[i
])));
667 else if(CdmUtils
.isNotBlank(authorKombString
) && !authorMap
.containsKey(authorKombString
)){
668 authorMap
.put(authorKombString
, getAgentService().load(state
.getAuthorMap().get(authorKombString
)));
671 String authorBasiString
= rs
.getString(RedListUtil
.AUTOR_BASI
);
673 if(authorBasiString
.contains(RedListUtil
.EX
)){
674 String
[] basiSplit
= authorBasiString
.split(RedListUtil
.EX
);
675 for (int i
= 0; i
< basiSplit
.length
; i
++) {
676 if(!authorMap
.containsKey(basiSplit
[i
])){
677 authorMap
.put(basiSplit
[i
], getAgentService().load(state
.getAuthorMap().get(basiSplit
[i
])));
681 else if(CdmUtils
.isNotBlank(authorBasiString
) && !authorMap
.containsKey(authorBasiString
)){
682 authorMap
.put(authorBasiString
, getAgentService().load(state
.getAuthorMap().get(authorBasiString
)));
685 } catch (SQLException e
) {
688 result
.put(RedListUtil
.AUTHOR_NAMESPACE
, authorMap
);
694 protected boolean doCheck(RedListGefaesspflanzenImportState state
) {
699 protected boolean isIgnore(RedListGefaesspflanzenImportState state
) {