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
;
19 import org
.apache
.log4j
.Logger
;
20 import org
.springframework
.stereotype
.Component
;
22 import eu
.etaxonomy
.cdm
.common
.CdmUtils
;
23 import eu
.etaxonomy
.cdm
.hibernate
.HibernateProxyHelper
;
24 import eu
.etaxonomy
.cdm
.io
.common
.DbImportBase
;
25 import eu
.etaxonomy
.cdm
.io
.common
.IPartitionedIO
;
26 import eu
.etaxonomy
.cdm
.io
.common
.ImportHelper
;
27 import eu
.etaxonomy
.cdm
.io
.common
.ResultSetPartitioner
;
28 import eu
.etaxonomy
.cdm
.io
.common
.mapping
.UndefinedTransformerMethodException
;
29 import eu
.etaxonomy
.cdm
.model
.agent
.AgentBase
;
30 import eu
.etaxonomy
.cdm
.model
.agent
.TeamOrPersonBase
;
31 import eu
.etaxonomy
.cdm
.model
.common
.CdmBase
;
32 import eu
.etaxonomy
.cdm
.model
.common
.Language
;
33 import eu
.etaxonomy
.cdm
.model
.description
.CommonTaxonName
;
34 import eu
.etaxonomy
.cdm
.model
.description
.TaxonDescription
;
35 import eu
.etaxonomy
.cdm
.model
.name
.BotanicalName
;
36 import eu
.etaxonomy
.cdm
.model
.name
.NomenclaturalStatus
;
37 import eu
.etaxonomy
.cdm
.model
.name
.NomenclaturalStatusType
;
38 import eu
.etaxonomy
.cdm
.model
.name
.NonViralName
;
39 import eu
.etaxonomy
.cdm
.model
.name
.Rank
;
40 import eu
.etaxonomy
.cdm
.model
.name
.TaxonNameBase
;
41 import eu
.etaxonomy
.cdm
.model
.taxon
.Synonym
;
42 import eu
.etaxonomy
.cdm
.model
.taxon
.Taxon
;
43 import eu
.etaxonomy
.cdm
.model
.taxon
.TaxonBase
;
44 import eu
.etaxonomy
.cdm
.model
.taxon
.TaxonRelationship
;
45 import eu
.etaxonomy
.cdm
.model
.taxon
.TaxonRelationshipType
;
46 import eu
.etaxonomy
.cdm
.strategy
.parser
.NonViralNameParserImpl
;
56 @SuppressWarnings("serial")
57 public class RedListGefaesspflanzenImportNames
extends DbImportBase
<RedListGefaesspflanzenImportState
, RedListGefaesspflanzenImportConfigurator
> {
59 private static final Logger logger
= Logger
.getLogger(RedListGefaesspflanzenImportNames
.class);
61 private static final String tableName
= "Rote Liste Gefäßpflanzen";
63 private static final String pluralString
= "names";
65 public RedListGefaesspflanzenImportNames() {
66 super(tableName
, pluralString
);
70 protected String
getIdQuery(RedListGefaesspflanzenImportState state
) {
71 return "SELECT NAMNR "
72 + "FROM V_TAXATLAS_D20_EXPORT t "
77 protected String
getRecordQuery(RedListGefaesspflanzenImportConfigurator config
) {
78 String result
= " SELECT * "
79 + " FROM V_TAXATLAS_D20_EXPORT t "
80 + " WHERE t.NAMNR IN (@IDSET)";
81 result
= result
.replace("@IDSET", IPartitionedIO
.ID_LIST_TOKEN
);
86 protected void doInvoke(RedListGefaesspflanzenImportState state
) {
87 super.doInvoke(state
);
92 public boolean doPartition(ResultSetPartitioner partitioner
, RedListGefaesspflanzenImportState state
) {
93 ResultSet rs
= partitioner
.getResultSet();
94 Set
<TaxonNameBase
<?
,?
>> namesToSave
= new HashSet
<TaxonNameBase
<?
,?
>>();
95 Set
<TaxonBase
<?
>> taxaToSave
= new HashSet
<TaxonBase
<?
>>();
98 makeSingleNameAndTaxon(state
, rs
, namesToSave
, taxaToSave
);
101 } catch (SQLException e
) {
105 getNameService().saveOrUpdate((TaxonNameBase
) namesToSave
);
106 getTaxonService().saveOrUpdate((TaxonBase
) taxaToSave
);
110 private void makeSingleNameAndTaxon(RedListGefaesspflanzenImportState state
, ResultSet rs
, Set
<TaxonNameBase
<?
,?
>> namesToSave
, Set
<TaxonBase
<?
>> taxaToSave
)
111 throws SQLException
{
112 long id
= rs
.getLong(RedListUtil
.NAMNR
);
113 String clTaxonString
= rs
.getString(RedListUtil
.CL_TAXON
);
114 String relationE
= rs
.getString(RedListUtil
.E
);
115 String relationW
= rs
.getString(RedListUtil
.W
);
116 String relationK
= rs
.getString(RedListUtil
.K
);
117 String relationAW
= rs
.getString(RedListUtil
.AW
);
118 String relationAO
= rs
.getString(RedListUtil
.AO
);
119 String relationR
= rs
.getString(RedListUtil
.R
);
120 String relationO
= rs
.getString(RedListUtil
.O
);
121 String relationS
= rs
.getString(RedListUtil
.S
);
124 NonViralName
<?
> name
= importName(state
, rs
, namesToSave
);
128 importAuthors(state
, rs
, name
);
131 TaxonBase
<?
> taxonBase
= importTaxon(rs
, name
);
133 RedListUtil
.logMessage(id
, "Taxon for name "+name
+" could not be created.", logger
);
137 //---CONCEPT RELATIONSHIPS---
139 TaxonBase
<?
> checklistTaxon
= null;
140 if(CdmUtils
.isNotBlank(clTaxonString
) && !clTaxonString
.trim().equals("-")){
141 checklistTaxon
= (TaxonBase
<?
>) taxonBase
.clone();
142 //TODO what to do with synonyms?
143 if(checklistTaxon
.isInstanceOf(Taxon
.class)){
144 TaxonRelationship relation
= HibernateProxyHelper
.deproxy(checklistTaxon
, Taxon
.class).addTaxonRelation(HibernateProxyHelper
.deproxy(taxonBase
, Taxon
.class), TaxonRelationshipType
.CONGRUENT_TO(), null, null);
145 relation
.setDoubtful(true);
148 ImportHelper
.setOriginalSource(checklistTaxon
, state
.getTransactionalSourceReference(), id
, RedListUtil
.TAXON_CHECKLISTE_NAMESPACE
);
149 taxaToSave
.add(checklistTaxon
);
151 //E, W, K, AW, AO, R, O, S
152 addConceptRelation(relationE
, RedListUtil
.CLASSIFICATION_NAMESPACE_E
, taxonBase
, checklistTaxon
, taxaToSave
, id
, state
);
153 addConceptRelation(relationW
, RedListUtil
.CLASSIFICATION_NAMESPACE_W
, taxonBase
, checklistTaxon
, taxaToSave
, id
, state
);
154 addConceptRelation(relationK
, RedListUtil
.CLASSIFICATION_NAMESPACE_K
, taxonBase
, checklistTaxon
, taxaToSave
, id
, state
);
155 addConceptRelation(relationAW
, RedListUtil
.CLASSIFICATION_NAMESPACE_AW
, taxonBase
, checklistTaxon
, taxaToSave
, id
, state
);
156 addConceptRelation(relationAO
, RedListUtil
.CLASSIFICATION_NAMESPACE_AO
, taxonBase
, checklistTaxon
, taxaToSave
, id
, state
);
157 addConceptRelation(relationR
, RedListUtil
.CLASSIFICATION_NAMESPACE_R
, taxonBase
, checklistTaxon
, taxaToSave
, id
, state
);
158 addConceptRelation(relationO
, RedListUtil
.CLASSIFICATION_NAMESPACE_O
, taxonBase
, checklistTaxon
, taxaToSave
, id
, state
);
159 addConceptRelation(relationS
, RedListUtil
.CLASSIFICATION_NAMESPACE_S
, taxonBase
, checklistTaxon
, taxaToSave
, id
, state
);
161 //NOTE: the source has to be added after cloning or otherwise the clone would also get the source
162 ImportHelper
.setOriginalSource(taxonBase
, state
.getTransactionalSourceReference(), id
, RedListUtil
.TAXON_GESAMTLISTE_NAMESPACE
);
163 taxaToSave
.add(taxonBase
);
166 private void addConceptRelation(String relationString
, String classificationNamespace
, TaxonBase
<?
> gesamtListeTaxon
, TaxonBase
<?
> checkListenTaxon
, Set
<TaxonBase
<?
>> taxaToSave
, long id
, RedListGefaesspflanzenImportState state
){
167 if(CdmUtils
.isNotBlank(relationString
) && !relationString
.equals(".")){
168 String substring
= relationString
.substring(relationString
.length()-1, relationString
.length());
169 TaxonRelationshipType taxonRelationshipTypeByKey
= new RedListGefaesspflanzenTransformer().getTaxonRelationshipTypeByKey(substring
);
170 if(taxonRelationshipTypeByKey
==null){
171 RedListUtil
.logMessage(id
, "Could not interpret relationship "+relationString
+" for taxon "+gesamtListeTaxon
.generateTitle(), logger
);
173 //there is no type "included in" so we have to reverse the direction
174 if(substring
.equals("<")){
175 cloneTaxon(gesamtListeTaxon
, checkListenTaxon
, taxonRelationshipTypeByKey
, taxaToSave
, id
, classificationNamespace
, true, false, state
);
178 cloneTaxon(gesamtListeTaxon
, checkListenTaxon
, taxonRelationshipTypeByKey
, taxaToSave
, id
, classificationNamespace
, false, false, state
);
184 * 1. clone new taxon of gesamtListeTaxon with the same name (in that classification)<br>
185 * 2. create concept relationship from clone to gesamtListeTaxon/checklisteTaxon or from its accepted taxon if it is synonym<br>
187 * <b>NOTE:</b> the {@link TaxonRelationshipType} passed as parameter is
188 * directed <b>from the clone</b> to the taxon.<br>
189 * This can be changed with parameter <i>reverseRelation</i>
190 * @return cloned taxon
192 private Taxon
cloneTaxon(final TaxonBase
<?
> gesamtListeTaxon
, final TaxonBase
<?
> checklisteTaxon
, TaxonRelationshipType relationFromCloneToTaxon
, Set
<TaxonBase
<?
>> taxaToSave
, long id
, String sourceNameSpace
, boolean reverseRelation
, boolean doubtful
, RedListGefaesspflanzenImportState state
){
193 Taxon acceptedGesamtListeTaxon
= getAcceptedTaxon(gesamtListeTaxon
);
194 Taxon acceptedChecklistTaxon
= getAcceptedTaxon(checklisteTaxon
);
195 Taxon clonedTaxon
= null;
197 if(gesamtListeTaxon
.isInstanceOf(Taxon
.class)){
198 clonedTaxon
= HibernateProxyHelper
.deproxy(gesamtListeTaxon
.clone(), Taxon
.class);
200 else if(gesamtListeTaxon
.isInstanceOf(Synonym
.class)){
201 clonedTaxon
= Taxon
.NewInstance(gesamtListeTaxon
.getName(), gesamtListeTaxon
.getSec());
204 RedListUtil
.logMessage(id
, "Taxon base "+gesamtListeTaxon
+" is neither taxon nor synonym! Taxon could not be cloned", logger
);
209 if(acceptedGesamtListeTaxon
!=null){
210 TaxonRelationship taxonRelation
= acceptedGesamtListeTaxon
.addTaxonRelation(clonedTaxon
, relationFromCloneToTaxon
, null, null);
211 taxonRelation
.setDoubtful(doubtful
);
213 if(acceptedChecklistTaxon
!=null) {
214 TaxonRelationship taxonRelation
= acceptedChecklistTaxon
.addTaxonRelation(clonedTaxon
, relationFromCloneToTaxon
, null, null);
215 taxonRelation
.setDoubtful(doubtful
);
219 if(acceptedGesamtListeTaxon
!=null){
220 TaxonRelationship taxonRelation
= clonedTaxon
.addTaxonRelation(acceptedGesamtListeTaxon
, relationFromCloneToTaxon
, null, null);
221 taxonRelation
.setDoubtful(doubtful
);
223 if(acceptedChecklistTaxon
!=null) {
224 TaxonRelationship taxonRelation
= clonedTaxon
.addTaxonRelation(acceptedChecklistTaxon
, relationFromCloneToTaxon
, null, null);
225 taxonRelation
.setDoubtful(doubtful
);
229 ImportHelper
.setOriginalSource(clonedTaxon
, state
.getTransactionalSourceReference(), id
, sourceNameSpace
);
230 taxaToSave
.add(clonedTaxon
);
234 private TaxonBase
<?
> importTaxon(ResultSet rs
, NonViralName
<?
> name
) throws SQLException
{
236 long id
= rs
.getLong(RedListUtil
.NAMNR
);
237 String taxNameString
= rs
.getString(RedListUtil
.TAXNAME
);
238 String gueltString
= rs
.getString(RedListUtil
.GUELT
);
239 String trivialString
= rs
.getString(RedListUtil
.TRIVIAL
);
240 String authorBasiString
= rs
.getString(RedListUtil
.AUTOR_BASI
);
241 String hybString
= rs
.getString(RedListUtil
.HYB
);
243 TaxonBase
<?
> taxonBase
= null;
244 if(authorBasiString
.trim().contains(RedListUtil
.AUCT
)){
245 taxonBase
= Taxon
.NewInstance(name
, null);
246 taxonBase
.setAppendedPhrase(RedListUtil
.AUCT
);
248 else if(gueltString
.equals(RedListUtil
.GUELT_ACCEPTED_TAXON
)){
249 taxonBase
= Taxon
.NewInstance(name
, null);
251 else if(gueltString
.equals(RedListUtil
.GUELT_SYNONYM
) || gueltString
.equals(RedListUtil
.GUELT_BASIONYM
)){
252 taxonBase
= Synonym
.NewInstance(name
, null);
259 if(taxonBase
.isInstanceOf(Taxon
.class) && trivialString
!=null){
260 Taxon taxon
= HibernateProxyHelper
.deproxy(taxonBase
, Taxon
.class);
261 TaxonDescription description
= TaxonDescription
.NewInstance(taxon
);
262 description
.addElement(CommonTaxonName
.NewInstance(trivialString
, Language
.getDefaultLanguage()));
265 //check taxon name consistency
266 checkTaxonNameConsistency(id
, taxNameString
, hybString
, taxonBase
);
270 private void importAuthors(RedListGefaesspflanzenImportState state
, ResultSet rs
, NonViralName
<?
> name
) throws SQLException
{
272 long id
= rs
.getLong(RedListUtil
.NAMNR
);
273 String nomZusatzString
= rs
.getString(RedListUtil
.NOM_ZUSATZ
);
274 String taxZusatzString
= rs
.getString(RedListUtil
.TAX_ZUSATZ
);
275 String zusatzString
= rs
.getString(RedListUtil
.ZUSATZ
);
276 String authorKombString
= rs
.getString(RedListUtil
.AUTOR_KOMB
);
277 String authorBasiString
= rs
.getString(RedListUtil
.AUTOR_BASI
);
280 if(authorKombString
.contains(RedListUtil
.EX
)){
281 //TODO: what happens with multiple ex authors??
282 String
[] kombSplit
= authorKombString
.split(RedListUtil
.EX
);
283 if(kombSplit
.length
!=2){
284 RedListUtil
.logMessage(id
, "Multiple ex combination authors found", logger
);
286 for (int i
= 0; i
< kombSplit
.length
; i
++) {
288 //first author is ex author
289 TeamOrPersonBase
<?
> authorKomb
= (TeamOrPersonBase
<?
>) state
.getRelatedObject(RedListUtil
.AUTHOR_NAMESPACE
, kombSplit
[i
]);
290 name
.setExCombinationAuthorship(authorKomb
);
293 TeamOrPersonBase
<?
> authorKomb
= (TeamOrPersonBase
<?
>) state
.getRelatedObject(RedListUtil
.AUTHOR_NAMESPACE
, kombSplit
[i
]);
294 name
.setCombinationAuthorship(authorKomb
);
298 else if(authorKombString
.trim().contains(RedListUtil
.AUCT
)){
299 RedListUtil
.logMessage(id
, "AUCT information in "+RedListUtil
.AUTOR_KOMB
+" column", logger
);
301 else if(CdmUtils
.isNotBlank(authorKombString
)){
302 TeamOrPersonBase
<?
> authorKomb
= (TeamOrPersonBase
<?
>) state
.getRelatedObject(RedListUtil
.AUTHOR_NAMESPACE
, authorKombString
);
303 name
.setCombinationAuthorship(authorKomb
);
306 if(authorBasiString
.contains(RedListUtil
.EX
)){
307 String
[] basiSplit
= authorBasiString
.split(RedListUtil
.EX
);
308 for (int i
= 0; i
< basiSplit
.length
; i
++) {
309 if(basiSplit
.length
!=2){
310 RedListUtil
.logMessage(id
, "Multiple ex basionymn authors found", logger
);
313 TeamOrPersonBase
<?
> authorBasi
= (TeamOrPersonBase
<?
>) state
.getRelatedObject(RedListUtil
.AUTHOR_NAMESPACE
, basiSplit
[i
]);
314 if(CdmUtils
.isBlank(authorKombString
)){
315 name
.setExCombinationAuthorship(authorBasi
);
318 name
.setExBasionymAuthorship(authorBasi
);
322 TeamOrPersonBase
<?
> authorBasi
= (TeamOrPersonBase
<?
>) state
.getRelatedObject(RedListUtil
.AUTHOR_NAMESPACE
, basiSplit
[i
]);
323 if(CdmUtils
.isBlank(authorKombString
)){
324 name
.setCombinationAuthorship(authorBasi
);
327 name
.setBasionymAuthorship(authorBasi
);
332 else if(CdmUtils
.isNotBlank(authorBasiString
)){
333 //this seems to be a convention in the source database: When there is only a single author then only the "AUTOR_BASI" column is used
334 TeamOrPersonBase
<?
> authorBasi
= (TeamOrPersonBase
<?
>) state
.getRelatedObject(RedListUtil
.AUTHOR_NAMESPACE
, authorBasiString
);
335 if(CdmUtils
.isBlank(authorKombString
)){
336 name
.setCombinationAuthorship(authorBasi
);
339 name
.setBasionymAuthorship(authorBasi
);
343 //check authorship consistency
344 String authorString
= rs
.getString(RedListUtil
.AUTOR
);
345 String authorshipCache
= name
.getAuthorshipCache();
346 checkAuthorShipConsistency(id
, nomZusatzString
, taxZusatzString
, zusatzString
, authorString
, authorshipCache
);
349 private NonViralName
<?
> importName(RedListGefaesspflanzenImportState state
, ResultSet rs
, Set
<TaxonNameBase
<?
,?
>> namesToSave
) throws SQLException
{
351 long id
= rs
.getLong(RedListUtil
.NAMNR
);
352 String taxNameString
= rs
.getString(RedListUtil
.TAXNAME
);
353 String rangString
= rs
.getString(RedListUtil
.RANG
);
354 String ep1String
= rs
.getString(RedListUtil
.EPI1
);
355 String ep2String
= rs
.getString(RedListUtil
.EPI2
);
356 String ep3String
= rs
.getString(RedListUtil
.EPI3
);
357 String nomZusatzString
= rs
.getString(RedListUtil
.NOM_ZUSATZ
);
358 String hybString
= rs
.getString(RedListUtil
.HYB
);
360 if(CdmUtils
.isBlank(taxNameString
) && CdmUtils
.isBlank(ep1String
)){
361 RedListUtil
.logMessage(id
, "No name found!", logger
);
364 Rank rank
= makeRank(id
, state
, rangString
, ep3String
!=null);
365 NonViralName
<?
> name
= BotanicalName
.NewInstance(rank
);
367 //ep1 should always be present
368 if(CdmUtils
.isBlank(ep1String
)){
369 RedListUtil
.logMessage(id
, RedListUtil
.EPI1
+" is empty!", logger
);
371 name
.setGenusOrUninomial(ep1String
);
372 if(CdmUtils
.isNotBlank(ep2String
)){
373 name
.setSpecificEpithet(ep2String
);
375 if(CdmUtils
.isNotBlank(ep3String
)){
376 name
.setInfraSpecificEpithet(ep3String
);
378 //nomenclatural status
379 if(CdmUtils
.isNotBlank(nomZusatzString
)){
380 NomenclaturalStatusType status
= makeNomenclaturalStatus(id
, state
, nomZusatzString
);
382 name
.addStatus(NomenclaturalStatus
.NewInstance(status
));
386 if(CdmUtils
.isNotBlank(hybString
)){
387 if(hybString
.equals(RedListUtil
.HYB_X
)){
388 name
.setBinomHybrid(true);
390 else if(hybString
.equals(RedListUtil
.HYB_G
)){
391 name
.setMonomHybrid(true);
393 else if(hybString
.equals(RedListUtil
.HYB_XF
)){
394 name
.setHybridFormula(true);
395 if(ep1String
.contains(RedListUtil
.HYB_SIGN
)){
396 RedListUtil
.logMessage(id
, "EPI1 has hybrid signs but with flag: "+RedListUtil
.HYB_XF
, logger
);
398 else if(ep2String
.contains(RedListUtil
.HYB_SIGN
)){
399 String
[] split
= ep2String
.split(RedListUtil
.HYB_SIGN
);
401 RedListUtil
.logMessage(id
, "Multiple hybrid signs found in "+ep2String
, logger
);
403 String hybridFormula1
= ep1String
+" "+split
[0].trim();
404 String hybridFormula2
= ep1String
+" "+split
[1].trim();
405 if(CdmUtils
.isNotBlank(ep3String
)){
406 hybridFormula1
+= " "+ep3String
;
407 hybridFormula2
+= " "+ep3String
;
409 String fullFormula
= hybridFormula1
+" "+RedListUtil
.HYB_SIGN
+" "+hybridFormula2
;
410 name
= NonViralNameParserImpl
.NewInstance().parseFullName(fullFormula
);
412 else if(ep3String
.contains(RedListUtil
.HYB_SIGN
)){
413 String
[] split
= ep3String
.split(RedListUtil
.HYB_SIGN
);
415 RedListUtil
.logMessage(id
, "Multiple hybrid signs found in "+ep3String
, logger
);
417 String hybridFormula1
= ep1String
+" "+ep2String
+" "+split
[0];
418 String hybridFormula2
= ep1String
+" "+ep2String
+" "+split
[1];
419 String fullFormula
= hybridFormula1
+" "+RedListUtil
.HYB_SIGN
+" "+hybridFormula2
;
420 name
= NonViralNameParserImpl
.NewInstance().parseFullName(fullFormula
);
423 else if(hybString
.equals(RedListUtil
.HYB_N
)){
424 name
= NonViralNameParserImpl
.NewInstance().parseFullName(ep1String
+" "+ep2String
+" nothosubsp. "+ep3String
);
426 else if(hybString
.equals(RedListUtil
.HYB_GF
)){
427 if(ep1String
.contains(RedListUtil
.HYB_SIGN
)){
428 name
= NonViralNameParserImpl
.NewInstance().parseFullName(ep1String
);
431 RedListUtil
.logMessage(id
, "HYB is "+hybString
+" but "+RedListUtil
.HYB
+" does not contain "+RedListUtil
.HYB_SIGN
, logger
);
435 logger
.error("HYB value "+hybString
+" not yet handled");
439 ImportHelper
.setOriginalSource(name
, state
.getTransactionalSourceReference(), id
, RedListUtil
.NAME_NAMESPACE
);
441 namesToSave
.add(name
);
445 private void checkAuthorShipConsistency(long id
, String nomZusatzString
, String taxZusatzString
,
446 String zusatzString
, String authorString
, String authorshipCache
) {
447 if(CdmUtils
.isNotBlank(zusatzString
)){
448 authorString
= authorString
.replace(", "+zusatzString
, "");
450 if(CdmUtils
.isNotBlank(nomZusatzString
)){
451 authorString
= authorString
.replace(", "+nomZusatzString
, "");
453 if(CdmUtils
.isNotBlank(taxZusatzString
)){
454 authorString
= authorString
.replace(", "+taxZusatzString
, "");
456 if(authorString
.equals(RedListUtil
.AUCT
)){
459 if(!authorString
.equals(authorshipCache
)){
460 RedListUtil
.logMessage(id
, "Authorship inconsistent! name.authorhshipCache <-> Column "+RedListUtil
.AUTOR
+": "+authorshipCache
+" <-> "+authorString
, logger
);
464 private void checkTaxonNameConsistency(long id
, String taxNameString
, String hybString
, TaxonBase
<?
> taxonBase
) {
465 if(hybString
.equals(RedListUtil
.HYB_XF
)){
466 if(HibernateProxyHelper
.deproxy(taxonBase
.getName(),NonViralName
.class).getHybridChildRelations().isEmpty()){
467 RedListUtil
.logMessage(id
, "Hybrid name but no hybrid child relations", logger
);
474 String nameCache
= HibernateProxyHelper
.deproxy(taxonBase
.getName(), NonViralName
.class).getNameCache().trim();
476 if(taxNameString
.endsWith("agg.")){
477 taxNameString
= taxNameString
.replace("agg.", "aggr.");
479 if(hybString
.equals(RedListUtil
.HYB_X
)){
480 taxNameString
= taxNameString
.replace(RedListUtil
.HYB_SIGN
+" ", RedListUtil
.HYB_SIGN
);//hybrid sign has no space after it in titleCache for binomial hybrids
482 if(taxNameString
.endsWith("- Gruppe")){
483 taxNameString
.replaceAll("- Gruppe", "species group");
485 if(taxNameString
.endsWith("- group")){
486 taxNameString
.replaceAll("- group", "species group");
488 taxNameString
= taxNameString
.replace("[ranglos]", "[unranked]");
489 if(!taxNameString
.trim().equals(nameCache
)){
490 RedListUtil
.logMessage(id
, "Taxon name inconsistent! taxon.titleCache <-> Column "+RedListUtil
.TAXNAME
+": "+nameCache
+" <-> "+taxNameString
, logger
);
494 private Rank
makeRank(long id
, RedListGefaesspflanzenImportState state
, String rankStr
, boolean hasSpecificEpithet
) {
497 if(rankStr
.equals("ORA")){
498 //special handling for ORA because of two possibilities
499 if(hasSpecificEpithet
){
500 return Rank
.UNRANKED_INFRASPECIFIC();
503 return Rank
.UNRANKED_INFRAGENERIC();
507 rank
= state
.getTransformer().getRankByKey(rankStr
);
509 } catch (UndefinedTransformerMethodException e
) {
513 RedListUtil
.logMessage(id
, rankStr
+" could not be associated to a known rank.", logger
);
518 private NomenclaturalStatusType
makeNomenclaturalStatus(long id
, RedListGefaesspflanzenImportState state
, String nomZusatzString
) {
519 NomenclaturalStatusType status
= null;
521 status
= state
.getTransformer().getNomenclaturalStatusByKey(nomZusatzString
);
522 } catch (UndefinedTransformerMethodException e
) {
526 RedListUtil
.logMessage(id
, nomZusatzString
+" could not be associated to a known nomenclatural status.", logger
);
534 public Map
<Object
, Map
<String
, ?
extends CdmBase
>> getRelatedObjectsForPartition(ResultSet rs
,
535 RedListGefaesspflanzenImportState state
) {
536 Map
<Object
, Map
<String
, ?
extends CdmBase
>> result
= new HashMap
<>();
537 Map
<String
, AgentBase
<?
>> authorMap
= new HashMap
<String
, AgentBase
<?
>>();
541 String authorKombString
= rs
.getString(RedListUtil
.AUTOR_KOMB
);
543 if(authorKombString
.contains(RedListUtil
.EX
)){
544 String
[] kombSplit
= authorKombString
.split(RedListUtil
.EX
);
545 for (int i
= 0; i
< kombSplit
.length
; i
++) {
546 if(!authorMap
.containsKey(kombSplit
[i
])){
547 authorMap
.put(kombSplit
[i
], getAgentService().load(state
.getAuthorMap().get(kombSplit
[i
])));
551 else if(CdmUtils
.isNotBlank(authorKombString
) && !authorMap
.containsKey(authorKombString
)){
552 authorMap
.put(authorKombString
, getAgentService().load(state
.getAuthorMap().get(authorKombString
)));
555 String authorBasiString
= rs
.getString(RedListUtil
.AUTOR_BASI
);
557 if(authorBasiString
.contains(RedListUtil
.EX
)){
558 String
[] basiSplit
= authorBasiString
.split(RedListUtil
.EX
);
559 for (int i
= 0; i
< basiSplit
.length
; i
++) {
560 if(!authorMap
.containsKey(basiSplit
[i
])){
561 authorMap
.put(basiSplit
[i
], getAgentService().load(state
.getAuthorMap().get(basiSplit
[i
])));
565 else if(CdmUtils
.isNotBlank(authorBasiString
) && !authorMap
.containsKey(authorBasiString
)){
566 authorMap
.put(authorBasiString
, getAgentService().load(state
.getAuthorMap().get(authorBasiString
)));
569 } catch (SQLException e
) {
572 result
.put(RedListUtil
.AUTHOR_NAMESPACE
, authorMap
);
578 protected boolean doCheck(RedListGefaesspflanzenImportState state
) {
583 protected boolean isIgnore(RedListGefaesspflanzenImportState state
) {