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
.ImportHelper
;
25 import eu
.etaxonomy
.cdm
.io
.common
.ResultSetPartitioner
;
26 import eu
.etaxonomy
.cdm
.io
.common
.mapping
.UndefinedTransformerMethodException
;
27 import eu
.etaxonomy
.cdm
.model
.common
.CdmBase
;
28 import eu
.etaxonomy
.cdm
.model
.name
.NonViralName
;
29 import eu
.etaxonomy
.cdm
.model
.name
.Rank
;
30 import eu
.etaxonomy
.cdm
.model
.taxon
.Taxon
;
31 import eu
.etaxonomy
.cdm
.model
.taxon
.TaxonBase
;
32 import eu
.etaxonomy
.cdm
.strategy
.parser
.NonViralNameParserImpl
;
42 @SuppressWarnings("serial")
43 public class RedListGefaesspflanzenImportTaxa
extends DbImportBase
<RedListGefaesspflanzenImportState
, RedListGefaesspflanzenImportConfigurator
> {
44 private static final Logger logger
= Logger
.getLogger(RedListGefaesspflanzenImportTaxa
.class);
46 private static final String tableName
= "Rote Liste Gefäßpflanzen";
48 private static final String pluralString
= "taxa";
50 private static final String TAXON_NAMESPACE
= "taxon";
52 public RedListGefaesspflanzenImportTaxa() {
53 super(tableName
, pluralString
);
57 protected String
getIdQuery(RedListGefaesspflanzenImportState state
) {
58 return "SELECT NAMNR "
59 + "FROM V_TAXATLAS_D20_EXPORT t "
64 protected String
getRecordQuery(RedListGefaesspflanzenImportConfigurator config
) {
65 String result
= " SELECT * "
66 + " FROM V_TAXATLAS_D20_EXPORT t "
67 + " WHERE t.NAMNR IN (@IDSET)";
68 result
= result
.replace("@IDSET", IPartitionedIO
.ID_LIST_TOKEN
);
73 protected void doInvoke(RedListGefaesspflanzenImportState state
) {
74 super.doInvoke(state
);
79 public boolean doPartition(ResultSetPartitioner partitioner
, RedListGefaesspflanzenImportState state
) {
80 ResultSet rs
= partitioner
.getResultSet();
81 Set
<TaxonBase
> taxaToSave
= new HashSet
<>();
84 makeSingleTaxon(state
, rs
, taxaToSave
);
87 } catch (SQLException e
) {
91 getTaxonService().saveOrUpdate(taxaToSave
);
95 private void makeSingleTaxon(RedListGefaesspflanzenImportState state
, ResultSet rs
, Set
<TaxonBase
> taxaToSave
)
97 long id
= rs
.getLong("NAMNR");
98 String taxonNameString
= rs
.getString("TAXNAME");
100 NonViralNameParserImpl parser
= NonViralNameParserImpl
.NewInstance();
101 NonViralName
<?
> name
= parser
.parseFullName(taxonNameString
);
102 TaxonBase taxon
= Taxon
.NewInstance(name
, null);
104 taxaToSave
.add(taxon
);
107 ImportHelper
.setOriginalSource(taxon
, state
.getTransactionalSourceReference(), id
, TAXON_NAMESPACE
);
108 ImportHelper
.setOriginalSource(name
, state
.getTransactionalSourceReference(), id
, TAXON_NAMESPACE
);
111 private Rank
makeRank(RedListGefaesspflanzenImportState state
, String rankStr
) {
114 rank
= state
.getTransformer().getRankByKey(rankStr
);
115 } catch (UndefinedTransformerMethodException e
) {
124 public Map
<Object
, Map
<String
, ?
extends CdmBase
>> getRelatedObjectsForPartition(ResultSet rs
,
125 RedListGefaesspflanzenImportState state
) {
126 Map
<Object
, Map
<String
, ?
extends CdmBase
>> result
= new HashMap
<>();
127 // Map<String, TeamOrPersonBase<?>> authorMap = new HashMap<>();
128 // Set<String> authorKombSet = new HashSet<>();
129 // Set<String> referenceIdSet = new HashSet<String>();
132 // while (rs.next()){
133 // String authorStr = rs.getString("tax_author_name");
134 // authorKombSet.add(authorStr);
135 // handleForeignKey(rs, referenceIdSet, "tax_document");
137 // } catch (SQLException e) {
138 // e.printStackTrace();
142 // Set<UUID> uuidSet = new HashSet<>();
143 // for (String authorStr : authorKombSet){
144 // UUID uuid = state.getAuthorUuid(authorStr);
145 // uuidSet.add(uuid);
147 // List<TeamOrPersonBase<?>> authors = (List)getAgentService().find(uuidSet);
148 // Map<UUID, TeamOrPersonBase<?>> authorUuidMap = new HashMap<>();
149 // for (TeamOrPersonBase<?> author : authors){
150 // authorUuidMap.put(author.getUuid(), author);
153 // for (String authorStr : authorKombSet){
154 // UUID uuid = state.getAuthorUuid(authorStr);
155 // TeamOrPersonBase<?> author = authorUuidMap.get(uuid);
156 // authorMap.put(authorStr, author);
158 // result.put(AUTHOR_NAMESPACE, authorMap);
161 // String nameSpace = REFERENCE_NAMESPACE;
162 // Class<?> cdmClass = Reference.class;
163 // Set<String> idSet = referenceIdSet;
164 // Map<String, Reference<?>> referenceMap = (Map<String, Reference<?>>)getCommonService().getSourcedObjectsByIdInSource(cdmClass, idSet, nameSpace);
165 // result.put(nameSpace, referenceMap);
168 // UUID secUuid = state.getConfig().getSecUuid();
169 // Reference<?> secRef = getReferenceService().find(secUuid);
170 // referenceMap.put(secUuid.toString(), secRef);
176 protected boolean doCheck(RedListGefaesspflanzenImportState state
) {
181 protected boolean isIgnore(RedListGefaesspflanzenImportState state
) {