|
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.Map;
|
|
16 |
import java.util.UUID;
|
|
17 |
|
|
18 |
import org.apache.log4j.Logger;
|
|
19 |
import org.springframework.stereotype.Component;
|
|
20 |
|
|
21 |
import eu.etaxonomy.cdm.io.common.DbImportBase;
|
|
22 |
import eu.etaxonomy.cdm.io.common.ResultSetPartitioner;
|
|
23 |
import eu.etaxonomy.cdm.model.common.CdmBase;
|
|
24 |
import eu.etaxonomy.cdm.model.name.BotanicalName;
|
|
25 |
import eu.etaxonomy.cdm.model.name.Rank;
|
|
26 |
import eu.etaxonomy.cdm.model.taxon.Taxon;
|
|
27 |
|
|
28 |
/**
|
|
29 |
*
|
|
30 |
* @author pplitzner
|
|
31 |
* @date Mar 1, 2016
|
|
32 |
*
|
|
33 |
*/
|
|
34 |
|
|
35 |
@Component
|
|
36 |
@SuppressWarnings("serial")
|
|
37 |
public class RedListGefaesspflanzenImportFamily extends DbImportBase<RedListGefaesspflanzenImportState, RedListGefaesspflanzenImportConfigurator> {
|
|
38 |
|
|
39 |
private static final Logger logger = Logger.getLogger(RedListGefaesspflanzenImportFamily.class);
|
|
40 |
|
|
41 |
private static final String tableName = "Rote Liste Gefäßpflanzen";
|
|
42 |
|
|
43 |
private static final String pluralString = "families";
|
|
44 |
|
|
45 |
|
|
46 |
public RedListGefaesspflanzenImportFamily() {
|
|
47 |
super(tableName, pluralString);
|
|
48 |
}
|
|
49 |
|
|
50 |
@Override
|
|
51 |
protected String getIdQuery(RedListGefaesspflanzenImportState state) {
|
|
52 |
return null;
|
|
53 |
}
|
|
54 |
|
|
55 |
@Override
|
|
56 |
protected String getRecordQuery(RedListGefaesspflanzenImportConfigurator config) {
|
|
57 |
return null;
|
|
58 |
}
|
|
59 |
|
|
60 |
@Override
|
|
61 |
protected void doInvoke(RedListGefaesspflanzenImportState state) {
|
|
62 |
try {
|
|
63 |
importFamilies(state);
|
|
64 |
} catch (SQLException e) {
|
|
65 |
e.printStackTrace();
|
|
66 |
}
|
|
67 |
}
|
|
68 |
|
|
69 |
|
|
70 |
private void importFamilies(RedListGefaesspflanzenImportState state) throws SQLException {
|
|
71 |
Map<String, UUID> familyMap = new HashMap<>();
|
|
72 |
|
|
73 |
String query = "SELECT DISTINCT f.FAMILIE "
|
|
74 |
+ " FROM V_TAXATLAS_D20_FAMILIEN f";
|
|
75 |
|
|
76 |
ResultSet rs = state.getConfig().getSource().getResultSet(query);
|
|
77 |
while(rs.next()){
|
|
78 |
String familieStr = rs.getString("FAMILIE");
|
|
79 |
BotanicalName name = BotanicalName.NewInstance(Rank.FAMILY());
|
|
80 |
name.setGenusOrUninomial(familieStr);
|
|
81 |
Taxon family = Taxon.NewInstance(name, null);
|
|
82 |
familyMap.put(familieStr, family.getUuid());
|
|
83 |
getTaxonService().saveOrUpdate(family);
|
|
84 |
}
|
|
85 |
state.setFamilyMap(familyMap);
|
|
86 |
}
|
|
87 |
|
|
88 |
@Override
|
|
89 |
public boolean doPartition(ResultSetPartitioner partitioner, RedListGefaesspflanzenImportState state) {
|
|
90 |
return true;
|
|
91 |
}
|
|
92 |
|
|
93 |
@Override
|
|
94 |
public Map<Object, Map<String, ? extends CdmBase>> getRelatedObjectsForPartition(ResultSet rs,
|
|
95 |
RedListGefaesspflanzenImportState state) {
|
|
96 |
Map<Object, Map<String, ? extends CdmBase>> result = new HashMap<>();
|
|
97 |
return result;
|
|
98 |
}
|
|
99 |
|
|
100 |
@Override
|
|
101 |
protected boolean doCheck(RedListGefaesspflanzenImportState state) {
|
|
102 |
return false;
|
|
103 |
}
|
|
104 |
|
|
105 |
@Override
|
|
106 |
protected boolean isIgnore(RedListGefaesspflanzenImportState state) {
|
|
107 |
return false;
|
|
108 |
}
|
|
109 |
|
|
110 |
}
|
#5448 Import families