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