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 NAMNR "
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.NAMNR 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 gueltString
= rs
.getString(RedListUtil
.GUELT
);
201 String trivialString
= rs
.getString(RedListUtil
.TRIVIAL
);
202 String authorBasiString
= rs
.getString(RedListUtil
.AUTOR_BASI
);
203 String hybString
= rs
.getString(RedListUtil
.HYB
);
204 String florString
= rs
.getString(RedListUtil
.FLOR
);
205 String atlasIdxString
= rs
.getString(RedListUtil
.ATLAS_IDX
);
206 String kartString
= rs
.getString(RedListUtil
.KART
);
207 String rl2015String
= rs
.getString(RedListUtil
.RL2015
);
208 String ehrdString
= rs
.getString(RedListUtil
.EHRD
);
209 String wisskString
= rs
.getString(RedListUtil
.WISSK
);
211 TaxonBase
<?
> taxonBase
= null;
212 if(authorBasiString
.trim().contains(RedListUtil
.AUCT
)){
213 taxonBase
= Taxon
.NewInstance(name
, null);
214 taxonBase
.setAppendedPhrase(RedListUtil
.AUCT
);
216 else if(gueltString
.equals(RedListUtil
.GUELT_ACCEPTED_TAXON
)){
217 taxonBase
= Taxon
.NewInstance(name
, null);
219 else if(gueltString
.equals(RedListUtil
.GUELT_SYNONYM
) || gueltString
.equals(RedListUtil
.GUELT_BASIONYM
)){
220 taxonBase
= Synonym
.NewInstance(name
, null);
227 if(taxonBase
.isInstanceOf(Taxon
.class) && trivialString
!=null){
228 Taxon taxon
= HibernateProxyHelper
.deproxy(taxonBase
, Taxon
.class);
229 TaxonDescription description
= TaxonDescription
.NewInstance(taxon
);
230 description
.addElement(CommonTaxonName
.NewInstance(trivialString
, Language
.GERMAN()));
234 addAnnotation(RedListUtil
.FLOR
+": "+florString
, taxonBase
);
235 addAnnotation(RedListUtil
.ATLAS_IDX
+": "+atlasIdxString
, taxonBase
);
236 addAnnotation(RedListUtil
.KART
+": "+kartString
, taxonBase
);
237 addAnnotation(RedListUtil
.RL2015
+": "+rl2015String
, taxonBase
);
238 addAnnotation(RedListUtil
.EHRD
+": "+ehrdString
, taxonBase
);
239 addAnnotation(RedListUtil
.WISSK
+": "+wisskString
, taxonBase
);
241 //check taxon name consistency
242 checkTaxonConsistency(id
, taxNameString
, hybString
, epi1String
, taxonBase
, state
);
246 private void addAnnotation(String string
, AnnotatableEntity entity
) {
247 if(CdmUtils
.isNotBlank(string
)){
248 entity
.addAnnotation(Annotation
.NewInstance(string
, AnnotationType
.TECHNICAL(), Language
.GERMAN()));
252 private void importAuthors(RedListGefaesspflanzenImportState state
, ResultSet rs
, NonViralName
<?
> name
) throws SQLException
{
254 long id
= rs
.getLong(RedListUtil
.NAMNR
);
255 String nomZusatzString
= rs
.getString(RedListUtil
.NOM_ZUSATZ
);
256 String taxZusatzString
= rs
.getString(RedListUtil
.TAX_ZUSATZ
);
257 String zusatzString
= rs
.getString(RedListUtil
.ZUSATZ
);
258 String authorKombString
= rs
.getString(RedListUtil
.AUTOR_KOMB
);
259 String authorBasiString
= rs
.getString(RedListUtil
.AUTOR_BASI
);
260 String hybString
= rs
.getString(RedListUtil
.HYB
);
263 if(authorKombString
.contains(RedListUtil
.EX
)){
264 //TODO: what happens with multiple ex authors??
265 String
[] kombSplit
= authorKombString
.split(RedListUtil
.EX
);
266 if(kombSplit
.length
!=2){
267 RedListUtil
.logMessage(id
, "Multiple ex combination authors found", logger
);
269 for (int i
= 0; i
< kombSplit
.length
; i
++) {
271 //first author is ex author
272 TeamOrPersonBase
<?
> authorKomb
= (TeamOrPersonBase
<?
>) state
.getRelatedObject(RedListUtil
.AUTHOR_NAMESPACE
, kombSplit
[i
]);
273 name
.setExCombinationAuthorship(authorKomb
);
276 TeamOrPersonBase
<?
> authorKomb
= (TeamOrPersonBase
<?
>) state
.getRelatedObject(RedListUtil
.AUTHOR_NAMESPACE
, kombSplit
[i
]);
277 name
.setCombinationAuthorship(authorKomb
);
281 else if(authorKombString
.trim().contains(RedListUtil
.AUCT
)){
282 RedListUtil
.logMessage(id
, "AUCT information in "+RedListUtil
.AUTOR_KOMB
+" column", logger
);
284 else if(CdmUtils
.isNotBlank(authorKombString
)){
285 TeamOrPersonBase
<?
> authorKomb
= (TeamOrPersonBase
<?
>) state
.getRelatedObject(RedListUtil
.AUTHOR_NAMESPACE
, authorKombString
);
286 name
.setCombinationAuthorship(authorKomb
);
289 if(authorBasiString
.contains(RedListUtil
.EX
)){
290 String
[] basiSplit
= authorBasiString
.split(RedListUtil
.EX
);
291 for (int i
= 0; i
< basiSplit
.length
; i
++) {
292 if(basiSplit
.length
!=2){
293 RedListUtil
.logMessage(id
, "Multiple ex basionymn authors found", logger
);
296 TeamOrPersonBase
<?
> authorBasi
= (TeamOrPersonBase
<?
>) state
.getRelatedObject(RedListUtil
.AUTHOR_NAMESPACE
, basiSplit
[i
]);
297 if(CdmUtils
.isBlank(authorKombString
)){
298 name
.setExCombinationAuthorship(authorBasi
);
301 name
.setExBasionymAuthorship(authorBasi
);
305 TeamOrPersonBase
<?
> authorBasi
= (TeamOrPersonBase
<?
>) state
.getRelatedObject(RedListUtil
.AUTHOR_NAMESPACE
, basiSplit
[i
]);
306 if(CdmUtils
.isBlank(authorKombString
)){
307 name
.setCombinationAuthorship(authorBasi
);
310 name
.setBasionymAuthorship(authorBasi
);
315 else if(CdmUtils
.isNotBlank(authorBasiString
)){
316 //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
317 TeamOrPersonBase
<?
> authorBasi
= (TeamOrPersonBase
<?
>) state
.getRelatedObject(RedListUtil
.AUTHOR_NAMESPACE
, authorBasiString
);
318 if(CdmUtils
.isBlank(authorKombString
)){
319 name
.setCombinationAuthorship(authorBasi
);
322 name
.setBasionymAuthorship(authorBasi
);
326 //check authorship consistency
327 String authorString
= rs
.getString(RedListUtil
.AUTOR
);
328 checkNameConsistency(id
, nomZusatzString
, taxZusatzString
, zusatzString
, authorString
, hybString
, name
);
331 private NonViralName
<?
> importName(RedListGefaesspflanzenImportState state
, ResultSet rs
, Set
<TaxonNameBase
> namesToSave
) throws SQLException
{
333 long id
= rs
.getLong(RedListUtil
.NAMNR
);
334 String taxNameString
= rs
.getString(RedListUtil
.TAXNAME
);
335 String rangString
= rs
.getString(RedListUtil
.RANG
);
336 String ep1String
= rs
.getString(RedListUtil
.EPI1
);
337 String ep2String
= rs
.getString(RedListUtil
.EPI2
);
338 String ep3String
= rs
.getString(RedListUtil
.EPI3
);
339 String nomZusatzString
= rs
.getString(RedListUtil
.NOM_ZUSATZ
);
340 String hybString
= rs
.getString(RedListUtil
.HYB
);
341 String formelString
= rs
.getString(RedListUtil
.FORMEL
);
343 if(CdmUtils
.isBlank(taxNameString
) && CdmUtils
.isBlank(ep1String
)){
344 RedListUtil
.logMessage(id
, "No name found!", logger
);
347 NonViralName
<?
> name
= null;
348 Rank rank
= makeRank(id
, state
, rangString
, ep3String
!=null);
350 if(rank
!= null && rank
.equals(Rank
.CULTIVAR())){
351 CultivarPlantName cultivar
= CultivarPlantName
.NewInstance(rank
);
352 cultivar
.setGenusOrUninomial(ep1String
);
353 cultivar
.setSpecificEpithet(ep2String
);
354 cultivar
.setCultivarName(ep3String
);
359 name
= BotanicalName
.NewInstance(rank
);
361 //ep1 should always be present
362 if(CdmUtils
.isBlank(ep1String
)){
363 RedListUtil
.logMessage(id
, RedListUtil
.EPI1
+" is empty!", logger
);
365 name
.setGenusOrUninomial(ep1String
);
366 if(CdmUtils
.isNotBlank(ep2String
)){
367 if(rank
!=null && rank
.isInfraGenericButNotSpeciesGroup()){
368 name
.setInfraGenericEpithet(ep2String
);
371 name
.setSpecificEpithet(ep2String
);
374 if(CdmUtils
.isNotBlank(ep3String
)){
375 name
.setInfraSpecificEpithet(ep3String
);
379 //nomenclatural status
380 if(CdmUtils
.isNotBlank(nomZusatzString
)){
381 NomenclaturalStatusType statusType
= makeNomenclaturalStatus(id
, state
, nomZusatzString
);
382 if(statusType
!=null){
383 NomenclaturalStatus status
= NomenclaturalStatus
.NewInstance(statusType
);
384 //special case for invalid names where the DB entry contains
385 //additional information in brackets e.g. "nom. inval. (sine basion.)"
386 if(statusType
.equals(NomenclaturalStatusType
.INVALID()) || statusType
.equals(NomenclaturalStatusType
.REJECTED()) ){
387 Pattern pattern
= Pattern
.compile("\\((.*?)\\)");
388 Matcher matcher
= pattern
.matcher(nomZusatzString
);
390 status
.setRuleConsidered(matcher
.group(1));
393 name
.addStatus(status
);
397 if(CdmUtils
.isNotBlank(hybString
)){
398 //save hybrid formula
399 if(CdmUtils
.isNotBlank(formelString
)){
400 Annotation annotation
= Annotation
.NewDefaultLanguageInstance(formelString
);
401 annotation
.setAnnotationType(AnnotationType
.TECHNICAL());
402 name
.addAnnotation(annotation
);
404 //more than two hybrids not yet handled by name parser
405 //TODO: use parser when implemented to fully support hybrids
406 if(taxNameString
.split(RedListUtil
.HYB_SIGN
).length
>2){
407 name
= BotanicalName
.NewInstance(rank
);
408 name
.setTitleCache(taxNameString
, true);
410 else if(hybString
.equals(RedListUtil
.HYB_X
)){
411 name
.setBinomHybrid(true);
413 else if(hybString
.equals(RedListUtil
.HYB_G
)){
414 name
.setMonomHybrid(true);
416 else if(hybString
.equals(RedListUtil
.HYB_XF
) || hybString
.equals(RedListUtil
.HYB_XU
)){
417 name
.setHybridFormula(true);
418 if(ep1String
.contains(RedListUtil
.HYB_SIGN
)){
419 name
= NonViralNameParserImpl
.NewInstance().parseFullName(ep1String
, NomenclaturalCode
.ICNAFP
, rank
);
421 else if(ep2String
.contains(RedListUtil
.HYB_SIGN
)){
422 String
[] split
= ep2String
.split(RedListUtil
.HYB_SIGN
);
423 String hybridFormula1
= ep1String
+" "+split
[0].trim();
424 String hybridFormula2
= ep1String
+" "+split
[1].trim();
425 //check if the genus is mentioned in EP2 or not
426 String
[] secondHybrid
= split
[1].trim().split(" ");
427 //check if the genus is abbreviated like e.g. Centaurea jacea × C. decipiens
428 if(secondHybrid
.length
>1 && secondHybrid
[0].matches("[A-Z]\\.")){
429 hybridFormula2
= ep1String
+" "+split
[1].trim().substring(2);
431 else if(secondHybrid
.length
>1 && secondHybrid
[0].matches("[A-Z].*")){
432 hybridFormula2
= split
[1];
434 if(CdmUtils
.isNotBlank(ep3String
)){
435 hybridFormula1
+= " "+ep3String
;
436 hybridFormula2
+= " "+ep3String
;
438 String fullFormula
= hybridFormula1
+" "+RedListUtil
.HYB_SIGN
+" "+hybridFormula2
;
439 name
= NonViralNameParserImpl
.NewInstance().parseFullName(fullFormula
, NomenclaturalCode
.ICNAFP
, rank
);
441 else if(ep3String
.contains(RedListUtil
.HYB_SIGN
)){
442 String
[] split
= ep3String
.split(RedListUtil
.HYB_SIGN
);
443 String hybridFormula1
= ep1String
+" "+ep2String
+" "+split
[0];
444 String hybridFormula2
= ep1String
+" "+ep2String
+" "+split
[1];
445 //check if the genus is mentioned in EP3 or not
446 String
[] secondHybrid
= split
[1].trim().split(" ");
447 //check if the genus is abbreviated like e.g. Centaurea jacea jacea × C. jacea subsp. decipiens
448 if(secondHybrid
.length
>1 && secondHybrid
[0].matches("[A-Z]\\.")){
449 hybridFormula2
= ep1String
+" "+split
[1].trim().substring(2);
451 else if(secondHybrid
.length
>1 && secondHybrid
[0].matches("[A-Z].*")){
452 hybridFormula2
= split
[1];
454 String fullFormula
= hybridFormula1
+" "+RedListUtil
.HYB_SIGN
+" "+hybridFormula2
;
455 name
= NonViralNameParserImpl
.NewInstance().parseFullName(fullFormula
, NomenclaturalCode
.ICNAFP
, rank
);
458 else if(hybString
.equals(RedListUtil
.HYB_N
)){
459 name
= NonViralNameParserImpl
.NewInstance().parseFullName(taxNameString
, NomenclaturalCode
.ICNAFP
, rank
);
461 else if(hybString
.equals(RedListUtil
.HYB_GF
)){
462 if(ep1String
.contains(RedListUtil
.HYB_SIGN
)){
463 name
= NonViralNameParserImpl
.NewInstance().parseFullName(ep1String
, NomenclaturalCode
.ICNAFP
, rank
);
466 RedListUtil
.logMessage(id
, "HYB is "+hybString
+" but "+RedListUtil
.HYB
+" does not contain "+RedListUtil
.HYB_SIGN
, logger
);
469 else if(hybString
.equals(RedListUtil
.HYB_XS
)){
473 logger
.error("HYB value "+hybString
+" not yet handled");
479 ImportHelper
.setOriginalSource(name
, state
.getTransactionalSourceReference(), id
, RedListUtil
.NAME_NAMESPACE
);
481 namesToSave
.add(name
);
485 private void checkNameConsistency(long id
, String nomZusatzString
, String taxZusatzString
,
486 String zusatzString
, String authorString
, String hybString
, NonViralName
<?
> name
) {
487 String authorshipCache
= name
.getAuthorshipCache();
488 //FIXME: remove split length check when name parser can parse multiple hybrid parents
489 if(hybString
.equals(RedListUtil
.HYB_XF
) && name
.getTitleCache().split(RedListUtil
.HYB_SIGN
).length
==2){
490 if(name
.getHybridChildRelations().isEmpty()){
491 RedListUtil
.logMessage(id
, "Hybrid formula but no hybrid child relations: "+name
.getTitleCache(), logger
);
497 if(CdmUtils
.isNotBlank(zusatzString
)){
498 authorString
= authorString
.replace(", "+zusatzString
, "");
500 if(CdmUtils
.isNotBlank(nomZusatzString
)){
501 authorString
= authorString
.replace(", "+nomZusatzString
, "");
503 if(CdmUtils
.isNotBlank(taxZusatzString
)){
504 authorString
= authorString
.replace(", "+taxZusatzString
, "");
506 if(authorString
.equals(RedListUtil
.AUCT
)){
509 if(STRICT_TITLE_CHECK
){
510 if(!authorString
.equals(authorshipCache
)){
511 RedListUtil
.logMessage(id
, "Authorship inconsistent! name.authorhshipCache <-> Column "+RedListUtil
.AUTOR
+": "+authorshipCache
+" <-> "+authorString
, logger
);
515 if(CdmUtils
.isNotBlank(authorString
) && !authorString
.startsWith(authorshipCache
)){
516 RedListUtil
.logMessage(id
, "Authorship inconsistent! name.authorhshipCache <-> Column "+RedListUtil
.AUTOR
+": "+authorshipCache
+" <-> "+authorString
, logger
);
521 private void checkTaxonConsistency(long id
, String taxNameString
, String hybString
, String epi1String
, TaxonBase
<?
> taxonBase
, RedListGefaesspflanzenImportState state
) {
522 if(taxNameString
.split(RedListUtil
.HYB_SIGN
).length
>2){
523 RedListUtil
.logInfoMessage(id
, "multiple hybrid signs. No name check for "+taxNameString
, logger
);
527 String nameCache
= HibernateProxyHelper
.deproxy(taxonBase
.getName(), NonViralName
.class).getNameCache().trim();
528 taxNameString
= taxNameString
.trim();
529 taxNameString
= taxNameString
.replaceAll(" +", " ");
532 if(hybString
.equals(RedListUtil
.HYB_X
) || hybString
.equals(RedListUtil
.HYB_N
)){
533 taxNameString
= taxNameString
.replace(" "+RedListUtil
.HYB_SIGN
+" ", " "+RedListUtil
.HYB_SIGN
);//hybrid sign has no space after it in titleCache for binomial hybrids
534 taxNameString
= taxNameString
.replace(" x ", " "+RedListUtil
.HYB_SIGN
);//in some cases a standard 'x' is used
536 else if(hybString
.equals(RedListUtil
.HYB_G
)){
537 taxNameString
= taxNameString
.replace("X ", RedListUtil
.HYB_SIGN
);
539 else if(hybString
.equals(RedListUtil
.HYB_GF
)){
540 taxNameString
= taxNameString
.replace(" "+RedListUtil
.HYB_SIGN
+" ", " "+RedListUtil
.HYB_SIGN
);
542 else if(hybString
.equals(RedListUtil
.HYB_XF
)){
543 nameCache
= taxonBase
.getName().getTitleCache();
544 if(nameCache
.contains("sec")){
545 nameCache
= nameCache
.substring(0, nameCache
.indexOf("sec"));
547 if(taxNameString
.matches((".*[A-Z]\\..*"))){
548 taxNameString
= taxNameString
.replaceAll("[A-Z]\\.", epi1String
);
550 if(taxNameString
.matches((".*"+RedListUtil
.HYB_SIGN
+"\\s[a-z].*"))){
551 taxNameString
= taxNameString
.replaceAll(RedListUtil
.HYB_SIGN
+" ", RedListUtil
.HYB_SIGN
+" "+epi1String
+" ");
555 if(taxNameString
.endsWith("- Gruppe")){
556 taxNameString
= taxNameString
.replaceAll("- Gruppe", "species group");
558 if(taxNameString
.endsWith("- group")){
559 taxNameString
= taxNameString
.replaceAll("- group", "species group");
562 taxNameString
= taxNameString
.replace("agg.", "aggr.");
563 taxNameString
= taxNameString
.replace("[ranglos]", "[unranked]");
565 if(taxonBase
.getName().getRank()!=null){
566 if(taxonBase
.getName().getRank().equals(Rank
.PROLES())){
567 taxNameString
= taxNameString
.replace("proles", "prol.");
569 else if(taxonBase
.getName().getRank().equals(state
.getRank(RedListUtil
.uuidRankCollectionSpecies
))){
570 taxNameString
= taxNameString
.replace("\"Sammelart\"", "\"Coll. Species\"");
573 if(STRICT_TITLE_CHECK
){
574 if(!taxNameString
.trim().equals(nameCache
)){
575 RedListUtil
.logMessage(id
, "Taxon name inconsistent! taxon.nameCache <-> Column "+RedListUtil
.TAXNAME
+": "+nameCache
+" <-> "+taxNameString
, logger
);
579 if(!taxNameString
.startsWith(nameCache
)){
580 RedListUtil
.logMessage(id
, "Taxon name inconsistent! taxon.nameCache <-> Column "+RedListUtil
.TAXNAME
+": "+nameCache
+" <-> "+taxNameString
, logger
);
585 private Rank
makeRank(long id
, RedListGefaesspflanzenImportState state
, String rankStr
, boolean hasSpecificEpithet
) {
588 if(rankStr
.equals("ORA")){
589 //special handling for ORA because of two possibilities
590 if(hasSpecificEpithet
){
591 return Rank
.UNRANKED_INFRASPECIFIC();
594 return Rank
.UNRANKED_INFRAGENERIC();
597 else if(rankStr
.equals("SAM")){
598 return getRank(state
, RedListUtil
.uuidRankCollectionSpecies
, "Collective Species", "Collective Species", "\"Coll. Species\"", (OrderedTermVocabulary
<Rank
>) Rank
.GENUS().getVocabulary(), null, RankClass
.SpeciesGroup
);
600 else if(rankStr
.equals("SPR")){
601 return getRank(state
, RedListUtil
.uuidRankSubproles
, "Subproles", "Subproles", "subproles", (OrderedTermVocabulary
<Rank
>) Rank
.GENUS().getVocabulary(), null, RankClass
.Infraspecific
);
603 else if(rankStr
.equals("MOD")){
604 return getRank(state
, RedListUtil
.uuidRankModification
, "Modification", "Modification", "modificatio", (OrderedTermVocabulary
<Rank
>) Rank
.GENUS().getVocabulary(), null, RankClass
.Infraspecific
);
606 else if(rankStr
.equals("LUS")){
607 return getRank(state
, RedListUtil
.uuidRankLusus
, "Lusus", "Lusus", "lusus", (OrderedTermVocabulary
<Rank
>) Rank
.GENUS().getVocabulary(), null, RankClass
.Infraspecific
);
609 else if(rankStr
.equals("SPI")){
610 return getRank(state
, RedListUtil
.uuidRankSubspeciesPrincipes
, "Subspecies principes", "Subspecies principes", "subsp. princ.", (OrderedTermVocabulary
<Rank
>) Rank
.GENUS().getVocabulary(), null, RankClass
.Infraspecific
);
612 else if(rankStr
.equals("KMB")){
613 return getRank(state
, RedListUtil
.uuidRankCombination
, "Combination", "Combination", "", (OrderedTermVocabulary
<Rank
>) Rank
.GENUS().getVocabulary(), null, RankClass
.Infraspecific
);
616 rank
= state
.getTransformer().getRankByKey(rankStr
);
618 } catch (UndefinedTransformerMethodException e
) {
622 RedListUtil
.logMessage(id
, rankStr
+" could not be associated to a known rank.", logger
);
627 private NomenclaturalStatusType
makeNomenclaturalStatus(long id
, RedListGefaesspflanzenImportState state
, String nomZusatzString
) {
628 NomenclaturalStatusType status
= null;
630 status
= state
.getTransformer().getNomenclaturalStatusByKey(nomZusatzString
);
631 } catch (UndefinedTransformerMethodException e
) {
635 RedListUtil
.logMessage(id
, nomZusatzString
+" could not be associated to a known nomenclatural status.", logger
);
643 public Map
<Object
, Map
<String
, ?
extends CdmBase
>> getRelatedObjectsForPartition(ResultSet rs
,
644 RedListGefaesspflanzenImportState state
) {
645 Map
<Object
, Map
<String
, ?
extends CdmBase
>> result
= new HashMap
<>();
646 Map
<String
, AgentBase
<?
>> authorMap
= new HashMap
<String
, AgentBase
<?
>>();
650 String authorKombString
= rs
.getString(RedListUtil
.AUTOR_KOMB
);
652 if(authorKombString
.contains(RedListUtil
.EX
)){
653 String
[] kombSplit
= authorKombString
.split(RedListUtil
.EX
);
654 for (int i
= 0; i
< kombSplit
.length
; i
++) {
655 if(!authorMap
.containsKey(kombSplit
[i
])){
656 authorMap
.put(kombSplit
[i
], getAgentService().load(state
.getAuthorMap().get(kombSplit
[i
])));
660 else if(CdmUtils
.isNotBlank(authorKombString
) && !authorMap
.containsKey(authorKombString
)){
661 authorMap
.put(authorKombString
, getAgentService().load(state
.getAuthorMap().get(authorKombString
)));
664 String authorBasiString
= rs
.getString(RedListUtil
.AUTOR_BASI
);
666 if(authorBasiString
.contains(RedListUtil
.EX
)){
667 String
[] basiSplit
= authorBasiString
.split(RedListUtil
.EX
);
668 for (int i
= 0; i
< basiSplit
.length
; i
++) {
669 if(!authorMap
.containsKey(basiSplit
[i
])){
670 authorMap
.put(basiSplit
[i
], getAgentService().load(state
.getAuthorMap().get(basiSplit
[i
])));
674 else if(CdmUtils
.isNotBlank(authorBasiString
) && !authorMap
.containsKey(authorBasiString
)){
675 authorMap
.put(authorBasiString
, getAgentService().load(state
.getAuthorMap().get(authorBasiString
)));
678 } catch (SQLException e
) {
681 result
.put(RedListUtil
.AUTHOR_NAMESPACE
, authorMap
);
687 protected boolean doCheck(RedListGefaesspflanzenImportState state
) {
692 protected boolean isIgnore(RedListGefaesspflanzenImportState state
) {