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
.io
.common
.DbImportBase
;
23 import eu
.etaxonomy
.cdm
.io
.common
.IPartitionedIO
;
24 import eu
.etaxonomy
.cdm
.io
.common
.ResultSetPartitioner
;
25 import eu
.etaxonomy
.cdm
.model
.common
.CdmBase
;
26 import eu
.etaxonomy
.cdm
.model
.taxon
.Classification
;
27 import eu
.etaxonomy
.cdm
.model
.taxon
.Synonym
;
28 import eu
.etaxonomy
.cdm
.model
.taxon
.SynonymRelationshipType
;
29 import eu
.etaxonomy
.cdm
.model
.taxon
.Taxon
;
30 import eu
.etaxonomy
.cdm
.model
.taxon
.TaxonBase
;
40 @SuppressWarnings("serial")
41 public class RedListGefaesspflanzenImportClassification
extends DbImportBase
<RedListGefaesspflanzenImportState
, RedListGefaesspflanzenImportConfigurator
> {
43 private static final Logger logger
= Logger
.getLogger(RedListGefaesspflanzenImportClassification
.class);
45 private static final String tableName
= "Rote Liste Gefäßpflanzen";
47 private static final String pluralString
= "classifications";
49 public RedListGefaesspflanzenImportClassification() {
50 super(tableName
, pluralString
);
54 protected String
getIdQuery(RedListGefaesspflanzenImportState state
) {
55 return "SELECT NAMNR "
56 + "FROM V_TAXATLAS_D20_EXPORT t "
61 protected String
getRecordQuery(RedListGefaesspflanzenImportConfigurator config
) {
62 String result
= " SELECT * "
63 + " FROM V_TAXATLAS_D20_EXPORT t "
64 + " WHERE t.NAMNR IN (@IDSET)";
65 result
= result
.replace("@IDSET", IPartitionedIO
.ID_LIST_TOKEN
);
70 protected void doInvoke(RedListGefaesspflanzenImportState state
) {
71 makeClassification(state
);
72 super.doInvoke(state
);
77 public boolean doPartition(ResultSetPartitioner partitioner
, RedListGefaesspflanzenImportState state
) {
78 ResultSet rs
= partitioner
.getResultSet();
79 Classification classification
= getClassificationService().load(state
.getConfig().getClassificationUuid());
82 makeSingleTaxonNode(state
, rs
, classification
);
85 } catch (SQLException e
) {
89 logger
.info("Update classification (1000 nodes)");
90 getClassificationService().saveOrUpdate(classification
);
94 private void makeSingleTaxonNode(RedListGefaesspflanzenImportState state
, ResultSet rs
, Classification classification
)
96 String id
= String
.valueOf(rs
.getLong("NAMNR"));
97 String parentId
= String
.valueOf(rs
.getLong("LOWER"));
98 String gueltString
= rs
.getString("GUELT");
100 TaxonBase taxonBase
= state
.getRelatedObject(Namespace
.TAXON_NAMESPACE
, id
, TaxonBase
.class);
101 Taxon parent
= (Taxon
) state
.getRelatedObject(Namespace
.TAXON_NAMESPACE
, parentId
, TaxonBase
.class);
104 if(taxonBase
.getName().getAppendedPhrase().contains("auct.")){
105 //TODO why can't I add synonymy as misapplications
106 // parent.addMisappliedName(misappliedNameTaxon, citation, microcitation)
109 else if(taxonBase
.isInstanceOf(Taxon
.class)){
110 classification
.addParentChild(parent
, (Taxon
)taxonBase
, null, null);
112 else if(taxonBase
.isInstanceOf(Synonym
.class)){
114 if(gueltString
.equals("b")){
115 parent
.addHomotypicSynonym((Synonym
) taxonBase
, null, null);
116 parent
.getName().addBasionym(taxonBase
.getName());
120 //TODO: how to correctly add a synonym?
121 parent
.addSynonym((Synonym
) taxonBase
, SynonymRelationshipType
.HETEROTYPIC_SYNONYM_OF(), null, null);
122 // parent.addSynonym((Synonym) taxonBase, SynonymRelationshipType.SYNONYM_OF(), null, null);
128 public Map
<Object
, Map
<String
, ?
extends CdmBase
>> getRelatedObjectsForPartition(ResultSet rs
,
129 RedListGefaesspflanzenImportState state
) {
130 Map
<Object
, Map
<String
, ?
extends CdmBase
>> result
= new HashMap
<>();
132 Set
<String
> idSet
= new HashSet
<String
>();
135 idSet
.add(String
.valueOf(rs
.getLong("NAMNR")));
136 idSet
.add(String
.valueOf(rs
.getLong("LOWER")));
138 } catch (SQLException e
) {
141 Map
<String
, TaxonBase
> taxonMap
= (Map
<String
, TaxonBase
>) getCommonService().getSourcedObjectsByIdInSource(TaxonBase
.class, idSet
, Namespace
.TAXON_NAMESPACE
);
142 result
.put(Namespace
.TAXON_NAMESPACE
, taxonMap
);
146 private void makeClassification(RedListGefaesspflanzenImportState state
) {
147 Classification classification
= Classification
.NewInstance(state
.getConfig().getClassificationName());
148 classification
.setUuid(state
.getConfig().getClassificationUuid());
149 getClassificationService().save(classification
);
153 protected boolean doCheck(RedListGefaesspflanzenImportState state
) {
158 protected boolean isIgnore(RedListGefaesspflanzenImportState state
) {