1
|
/**
|
2
|
* Copyright (C) 2007 EDIT
|
3
|
* European Distributed Institute of Taxonomy
|
4
|
* http://www.e-taxonomy.eu
|
5
|
*
|
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.
|
8
|
*/
|
9
|
|
10
|
package eu.etaxonomy.cdm.io.redlist.gefaesspflanzen;
|
11
|
|
12
|
import java.sql.ResultSet;
|
13
|
import java.sql.SQLException;
|
14
|
import java.util.HashMap;
|
15
|
import java.util.HashSet;
|
16
|
import java.util.Map;
|
17
|
import java.util.Set;
|
18
|
|
19
|
import org.apache.log4j.Logger;
|
20
|
import org.springframework.stereotype.Component;
|
21
|
|
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.model.common.CdmBase;
|
27
|
import eu.etaxonomy.cdm.model.name.NonViralName;
|
28
|
import eu.etaxonomy.cdm.model.taxon.Taxon;
|
29
|
import eu.etaxonomy.cdm.model.taxon.TaxonBase;
|
30
|
import eu.etaxonomy.cdm.strategy.parser.NonViralNameParserImpl;
|
31
|
|
32
|
/**
|
33
|
*
|
34
|
* @author pplitzner
|
35
|
* @date Mar 1, 2016
|
36
|
*
|
37
|
*/
|
38
|
|
39
|
@Component
|
40
|
@SuppressWarnings("serial")
|
41
|
public class RedListGefaesspflanzenImportTaxa extends DbImportBase<RedListGefaesspflanzenImportState, RedListGefaesspflanzenImportConfigurator> {
|
42
|
private static final Logger logger = Logger.getLogger(RedListGefaesspflanzenImportTaxa.class);
|
43
|
|
44
|
private static final String tableName = "Rote Liste Gefäßpflanzen";
|
45
|
|
46
|
private static final String pluralString = "taxa";
|
47
|
|
48
|
private static final String TAXON_NAMESPACE = "taxon";
|
49
|
|
50
|
public RedListGefaesspflanzenImportTaxa() {
|
51
|
super(tableName, pluralString);
|
52
|
}
|
53
|
|
54
|
@Override
|
55
|
protected String getIdQuery(RedListGefaesspflanzenImportState state) {
|
56
|
return "SELECT NAMNR "
|
57
|
+ "FROM V_TAXATLAS_D20_EXPORT t "
|
58
|
+ " ORDER BY NAMNR";
|
59
|
}
|
60
|
|
61
|
@Override
|
62
|
protected String getRecordQuery(RedListGefaesspflanzenImportConfigurator config) {
|
63
|
String result = " SELECT * "
|
64
|
+ " FROM V_TAXATLAS_D20_EXPORT t "
|
65
|
+ " WHERE t.NAMNR IN (@IDSET)";
|
66
|
result = result.replace("@IDSET", IPartitionedIO.ID_LIST_TOKEN);
|
67
|
return result;
|
68
|
}
|
69
|
|
70
|
@Override
|
71
|
protected void doInvoke(RedListGefaesspflanzenImportState state) {
|
72
|
super.doInvoke(state);
|
73
|
}
|
74
|
|
75
|
|
76
|
@Override
|
77
|
public boolean doPartition(ResultSetPartitioner partitioner, RedListGefaesspflanzenImportState state) {
|
78
|
ResultSet rs = partitioner.getResultSet();
|
79
|
Set<TaxonBase> taxaToSave = new HashSet<>();
|
80
|
try {
|
81
|
while (rs.next()){
|
82
|
makeSingleTaxon(state, rs, taxaToSave);
|
83
|
|
84
|
}
|
85
|
} catch (SQLException e) {
|
86
|
e.printStackTrace();
|
87
|
}
|
88
|
|
89
|
getTaxonService().saveOrUpdate(taxaToSave);
|
90
|
return true;
|
91
|
}
|
92
|
|
93
|
private void makeSingleTaxon(RedListGefaesspflanzenImportState state, ResultSet rs, Set<TaxonBase> taxaToSave)
|
94
|
throws SQLException {
|
95
|
long id = rs.getLong("NAMNR");
|
96
|
String taxonNameString = rs.getString("TAXNAME");
|
97
|
|
98
|
NonViralNameParserImpl parser = NonViralNameParserImpl.NewInstance();
|
99
|
NonViralName<?> name = parser.parseFullName(taxonNameString);
|
100
|
TaxonBase taxon = Taxon.NewInstance(name, null);
|
101
|
|
102
|
taxaToSave.add(taxon);
|
103
|
|
104
|
//id
|
105
|
ImportHelper.setOriginalSource(taxon, state.getTransactionalSourceReference(), id, TAXON_NAMESPACE);
|
106
|
ImportHelper.setOriginalSource(name, state.getTransactionalSourceReference(), id, TAXON_NAMESPACE);
|
107
|
}
|
108
|
|
109
|
@Override
|
110
|
public Map<Object, Map<String, ? extends CdmBase>> getRelatedObjectsForPartition(ResultSet rs,
|
111
|
RedListGefaesspflanzenImportState state) {
|
112
|
Map<Object, Map<String, ? extends CdmBase>> result = new HashMap<>();
|
113
|
// Map<String, TeamOrPersonBase<?>> authorMap = new HashMap<>();
|
114
|
// Set<String> authorKombSet = new HashSet<>();
|
115
|
// Set<String> referenceIdSet = new HashSet<String>();
|
116
|
//
|
117
|
// try {
|
118
|
// while (rs.next()){
|
119
|
// String authorStr = rs.getString("tax_author_name");
|
120
|
// authorKombSet.add(authorStr);
|
121
|
// handleForeignKey(rs, referenceIdSet, "tax_document");
|
122
|
// }
|
123
|
// } catch (SQLException e) {
|
124
|
// e.printStackTrace();
|
125
|
// }
|
126
|
//
|
127
|
// //Authors
|
128
|
// Set<UUID> uuidSet = new HashSet<>();
|
129
|
// for (String authorStr : authorKombSet){
|
130
|
// UUID uuid = state.getAuthorUuid(authorStr);
|
131
|
// uuidSet.add(uuid);
|
132
|
// }
|
133
|
// List<TeamOrPersonBase<?>> authors = (List)getAgentService().find(uuidSet);
|
134
|
// Map<UUID, TeamOrPersonBase<?>> authorUuidMap = new HashMap<>();
|
135
|
// for (TeamOrPersonBase<?> author : authors){
|
136
|
// authorUuidMap.put(author.getUuid(), author);
|
137
|
// }
|
138
|
//
|
139
|
// for (String authorStr : authorKombSet){
|
140
|
// UUID uuid = state.getAuthorUuid(authorStr);
|
141
|
// TeamOrPersonBase<?> author = authorUuidMap.get(uuid);
|
142
|
// authorMap.put(authorStr, author);
|
143
|
// }
|
144
|
// result.put(AUTHOR_NAMESPACE, authorMap);
|
145
|
//
|
146
|
// //reference map
|
147
|
// String nameSpace = REFERENCE_NAMESPACE;
|
148
|
// Class<?> cdmClass = Reference.class;
|
149
|
// Set<String> idSet = referenceIdSet;
|
150
|
// Map<String, Reference<?>> referenceMap = (Map<String, Reference<?>>)getCommonService().getSourcedObjectsByIdInSource(cdmClass, idSet, nameSpace);
|
151
|
// result.put(nameSpace, referenceMap);
|
152
|
//
|
153
|
// //secundum
|
154
|
// UUID secUuid = state.getConfig().getSecUuid();
|
155
|
// Reference<?> secRef = getReferenceService().find(secUuid);
|
156
|
// referenceMap.put(secUuid.toString(), secRef);
|
157
|
|
158
|
return result;
|
159
|
}
|
160
|
|
161
|
@Override
|
162
|
protected boolean doCheck(RedListGefaesspflanzenImportState state) {
|
163
|
return false;
|
164
|
}
|
165
|
|
166
|
@Override
|
167
|
protected boolean isIgnore(RedListGefaesspflanzenImportState state) {
|
168
|
return false;
|
169
|
}
|
170
|
|
171
|
}
|