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
.io
.common
.DbImportBase
;
24 import eu
.etaxonomy
.cdm
.io
.common
.IPartitionedIO
;
25 import eu
.etaxonomy
.cdm
.io
.common
.ResultSetPartitioner
;
26 import eu
.etaxonomy
.cdm
.model
.common
.CdmBase
;
27 import eu
.etaxonomy
.cdm
.model
.common
.Language
;
28 import eu
.etaxonomy
.cdm
.model
.common
.LanguageString
;
29 import eu
.etaxonomy
.cdm
.model
.taxon
.Classification
;
30 import eu
.etaxonomy
.cdm
.model
.taxon
.Synonym
;
31 import eu
.etaxonomy
.cdm
.model
.taxon
.SynonymRelationship
;
32 import eu
.etaxonomy
.cdm
.model
.taxon
.SynonymRelationshipType
;
33 import eu
.etaxonomy
.cdm
.model
.taxon
.Taxon
;
34 import eu
.etaxonomy
.cdm
.model
.taxon
.TaxonBase
;
44 @SuppressWarnings("serial")
45 public class RedListGefaesspflanzenImportClassification
extends DbImportBase
<RedListGefaesspflanzenImportState
, RedListGefaesspflanzenImportConfigurator
> {
47 private static final Logger logger
= Logger
.getLogger(RedListGefaesspflanzenImportClassification
.class);
49 private static final String tableName
= "Rote Liste Gefäßpflanzen";
51 private static final String pluralString
= "classifications";
53 public RedListGefaesspflanzenImportClassification() {
54 super(tableName
, pluralString
);
58 protected String
getIdQuery(RedListGefaesspflanzenImportState state
) {
59 return "SELECT NAMNR "
60 + "FROM V_TAXATLAS_D20_EXPORT t "
65 protected String
getRecordQuery(RedListGefaesspflanzenImportConfigurator config
) {
66 String result
= " SELECT * "
67 + " FROM V_TAXATLAS_D20_EXPORT t "
68 + " WHERE t.NAMNR IN (@IDSET)";
69 result
= result
.replace("@IDSET", IPartitionedIO
.ID_LIST_TOKEN
);
74 protected void doInvoke(RedListGefaesspflanzenImportState state
) {
75 makeClassification(state
);
76 super.doInvoke(state
);
81 public boolean doPartition(ResultSetPartitioner partitioner
, RedListGefaesspflanzenImportState state
) {
82 ResultSet rs
= partitioner
.getResultSet();
83 Classification gesamtListeClassification
= getClassificationService().load(state
.getConfig().getClassificationUuid());
84 Classification checklistClassification
= getClassificationService().load(RedListUtil
.checkListClassificationUuid
);
87 makeSingleTaxonNode(state
, rs
, gesamtListeClassification
, checklistClassification
);
90 } catch (SQLException e
) {
94 logger
.info("Update classification (1000 nodes)");
95 getClassificationService().saveOrUpdate(gesamtListeClassification
);
96 getClassificationService().saveOrUpdate(checklistClassification
);
100 private void makeSingleTaxonNode(RedListGefaesspflanzenImportState state
, ResultSet rs
, Classification gesamtListeClassification
, Classification checklistClassification
)
101 throws SQLException
{
102 long id
= rs
.getLong(RedListUtil
.NAMNR
);
103 String parentId
= String
.valueOf(rs
.getLong(RedListUtil
.LOWER
));
104 String gueltString
= rs
.getString(RedListUtil
.GUELT
);
105 String taxZusatzString
= rs
.getString(RedListUtil
.TAX_ZUSATZ
);
108 TaxonBase taxonBaseGL
= state
.getRelatedObject(RedListUtil
.TAXON_GESAMTLISTE_NAMESPACE
, String
.valueOf(id
), TaxonBase
.class);
109 Taxon parentGL
= (Taxon
) state
.getRelatedObject(RedListUtil
.TAXON_GESAMTLISTE_NAMESPACE
, parentId
, TaxonBase
.class);
110 createParentChildNodes(gesamtListeClassification
, id
, gueltString
, taxZusatzString
, taxonBaseGL
, parentGL
);
113 TaxonBase taxonBaseCL
= state
.getRelatedObject(RedListUtil
.TAXON_CHECKLISTE_NAMESPACE
, String
.valueOf(id
), TaxonBase
.class);
114 Taxon parentCL
= (Taxon
) state
.getRelatedObject(RedListUtil
.TAXON_CHECKLISTE_NAMESPACE
, parentId
, TaxonBase
.class);
115 if(taxonBaseCL
!=null){//null check necessary because not all taxa exist in the checklist
116 createParentChildNodes(checklistClassification
, id
, gueltString
, taxZusatzString
, taxonBaseCL
, parentCL
);
120 private void createParentChildNodes(Classification classification
, long id
, String gueltString
,
121 String taxZusatzString
, TaxonBase taxonBase
, Taxon parent
) {
123 RedListUtil
.logMessage(id
, "parent taxon of "+taxonBase
+" is null." , logger
);
127 RedListUtil
.logMessage(id
, "child taxon/synonym of "+parent
+" is null." , logger
);
131 if(taxonBase
.isInstanceOf(Taxon
.class)){
133 String appendedPhrase
= taxonBase
.getAppendedPhrase();
134 if(appendedPhrase
!=null && appendedPhrase
.equals(RedListUtil
.AUCT
)){
135 parent
.addMisappliedName((Taxon
) taxonBase
, null, null);
138 classification
.addParentChild(parent
, (Taxon
)taxonBase
, null, null);
141 if(CdmUtils
.isNotBlank(taxZusatzString
)){
142 if(taxZusatzString
.trim().equals("p. p.")){
143 RedListUtil
.logMessage(id
, "pro parte for accepted taxon "+taxonBase
, logger
);
148 else if(taxonBase
.isInstanceOf(Synonym
.class)){
150 if(gueltString
.equals(RedListUtil
.GUELT_BASIONYM
)){
151 parent
.addHomotypicSynonym((Synonym
) taxonBase
, null, null);
152 parent
.getName().addBasionym(taxonBase
.getName());
156 SynonymRelationship synonymRelationship
= parent
.addSynonym((Synonym
) taxonBase
, SynonymRelationshipType
.HETEROTYPIC_SYNONYM_OF(), null, null);
159 if(CdmUtils
.isNotBlank(taxZusatzString
)){
160 if(taxZusatzString
.trim().equals("p. p.")){
161 synonymRelationship
.setProParte(true);
163 else if(taxZusatzString
.trim().equals("s. l. p. p.")){
164 synonymRelationship
.setProParte(true);
165 taxonBase
.setAppendedPhrase("s. l.");
167 else if(taxZusatzString
.trim().equals("s. str. p. p.")){
168 synonymRelationship
.setProParte(true);
169 taxonBase
.setAppendedPhrase("s. str.");
171 else if(taxZusatzString
.trim().equals("s. l.")
172 || taxZusatzString
.trim().equals("s. str.")){
173 taxonBase
.setAppendedPhrase(taxZusatzString
);
176 RedListUtil
.logMessage(id
, "unknown value "+taxZusatzString
+" for column "+RedListUtil
.TAX_ZUSATZ
, logger
);
184 public Map
<Object
, Map
<String
, ?
extends CdmBase
>> getRelatedObjectsForPartition(ResultSet rs
,
185 RedListGefaesspflanzenImportState state
) {
186 Map
<Object
, Map
<String
, ?
extends CdmBase
>> result
= new HashMap
<>();
188 Set
<String
> idSet
= new HashSet
<String
>();
191 idSet
.add(String
.valueOf(rs
.getLong(RedListUtil
.NAMNR
)));
192 idSet
.add(String
.valueOf(rs
.getLong(RedListUtil
.LOWER
)));
194 } catch (SQLException e
) {
197 Map
<String
, TaxonBase
> taxonMapGesamtListe
= (Map
<String
, TaxonBase
>) getCommonService().getSourcedObjectsByIdInSource(TaxonBase
.class, idSet
, RedListUtil
.TAXON_GESAMTLISTE_NAMESPACE
);
198 result
.put(RedListUtil
.TAXON_GESAMTLISTE_NAMESPACE
, taxonMapGesamtListe
);
199 Map
<String
, TaxonBase
> taxonMapCheckliste
= (Map
<String
, TaxonBase
>) getCommonService().getSourcedObjectsByIdInSource(TaxonBase
.class, idSet
, RedListUtil
.TAXON_CHECKLISTE_NAMESPACE
);
200 result
.put(RedListUtil
.TAXON_CHECKLISTE_NAMESPACE
, taxonMapCheckliste
);
204 private void makeClassification(RedListGefaesspflanzenImportState state
) {
206 Classification classification
= Classification
.NewInstance(state
.getConfig().getClassificationName());
207 classification
.setName(LanguageString
.NewInstance("Gesamtliste", Language
.DEFAULT()));
208 classification
.setUuid(state
.getConfig().getClassificationUuid());
209 getClassificationService().save(classification
);
211 Classification checklistClassification
= Classification
.NewInstance("Checkliste");
212 checklistClassification
.setUuid(RedListUtil
.checkListClassificationUuid
);
213 getClassificationService().save(checklistClassification
);
217 protected boolean doCheck(RedListGefaesspflanzenImportState state
) {
222 protected boolean isIgnore(RedListGefaesspflanzenImportState state
) {