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
;
17 import org
.apache
.log4j
.Logger
;
18 import org
.springframework
.stereotype
.Component
;
20 import eu
.etaxonomy
.cdm
.io
.common
.DbImportBase
;
21 import eu
.etaxonomy
.cdm
.io
.common
.IPartitionedIO
;
22 import eu
.etaxonomy
.cdm
.io
.common
.ResultSetPartitioner
;
23 import eu
.etaxonomy
.cdm
.model
.common
.CdmBase
;
24 import eu
.etaxonomy
.cdm
.model
.taxon
.Classification
;
25 import eu
.etaxonomy
.cdm
.model
.taxon
.Synonym
;
26 import eu
.etaxonomy
.cdm
.model
.taxon
.Taxon
;
27 import eu
.etaxonomy
.cdm
.model
.taxon
.TaxonBase
;
37 @SuppressWarnings("serial")
38 public class RedListGefaesspflanzenImportClassification
extends DbImportBase
<RedListGefaesspflanzenImportState
, RedListGefaesspflanzenImportConfigurator
> {
40 private static final Logger logger
= Logger
.getLogger(RedListGefaesspflanzenImportClassification
.class);
42 private static final String tableName
= "Rote Liste Gefäßpflanzen";
44 private static final String pluralString
= "classifications";
46 public RedListGefaesspflanzenImportClassification() {
47 super(tableName
, pluralString
);
51 protected String
getIdQuery(RedListGefaesspflanzenImportState state
) {
52 return "SELECT NAMNR "
53 + "FROM V_TAXATLAS_D20_EXPORT t "
58 protected String
getRecordQuery(RedListGefaesspflanzenImportConfigurator config
) {
59 String result
= " SELECT * "
60 + " FROM V_TAXATLAS_D20_EXPORT t "
61 + " WHERE t.NAMNR IN (@IDSET)";
62 result
= result
.replace("@IDSET", IPartitionedIO
.ID_LIST_TOKEN
);
67 protected void doInvoke(RedListGefaesspflanzenImportState state
) {
68 makeClassification(state
);
69 super.doInvoke(state
);
74 public boolean doPartition(ResultSetPartitioner partitioner
, RedListGefaesspflanzenImportState state
) {
75 ResultSet rs
= partitioner
.getResultSet();
76 Classification classification
= getClassificationService().load(state
.getConfig().getClassificationUuid());
79 makeSingleTaxonNode(state
, rs
, classification
);
82 } catch (SQLException e
) {
86 getClassificationService().saveOrUpdate(classification
);
90 private void makeSingleTaxonNode(RedListGefaesspflanzenImportState state
, ResultSet rs
, Classification classification
)
92 long id
= rs
.getLong("NAMNR");
93 long parentId
= rs
.getLong("LOWER");
94 String gueltString
= rs
.getString("GUELT");
96 TaxonBase taxonBase
= getTaxonService().load(state
.getTaxonMap().get(id
));
97 Taxon parent
= (Taxon
) getTaxonService().load(state
.getTaxonMap().get(parentId
));
99 if(taxonBase
.isInstanceOf(Taxon
.class)){
100 classification
.addParentChild(parent
, (Taxon
)taxonBase
, null, null);
102 else if(taxonBase
.isInstanceOf(Synonym
.class)){
103 if(gueltString
.equals("b")){
107 //TODO: how to correctly add a synonym?
108 parent
.addHomotypicSynonym((Synonym
) taxonBase
, null, null);
114 public Map
<Object
, Map
<String
, ?
extends CdmBase
>> getRelatedObjectsForPartition(ResultSet rs
,
115 RedListGefaesspflanzenImportState state
) {
116 Map
<Object
, Map
<String
, ?
extends CdmBase
>> result
= new HashMap
<>();
120 private void makeClassification(RedListGefaesspflanzenImportState state
) {
121 Classification classification
= Classification
.NewInstance(state
.getConfig().getClassificationName());
122 classification
.setUuid(state
.getConfig().getClassificationUuid());
123 getClassificationService().save(classification
);
127 protected boolean doCheck(RedListGefaesspflanzenImportState state
) {
132 protected boolean isIgnore(RedListGefaesspflanzenImportState state
) {