Project

General

Profile

Download (3.56 KB) Statistics
| Branch: | Revision:
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
 * @author pplitzner
34
 * @since Mar 1, 2016
35
 */
36
@Component
37
public class RedListGefaesspflanzenImportFamily extends DbImportBase<RedListGefaesspflanzenImportState, RedListGefaesspflanzenImportConfigurator> {
38

    
39
    private static final long serialVersionUID = -3691432549643754281L;
40

    
41
    @SuppressWarnings("unused")
42
    private static final Logger logger = Logger.getLogger(RedListGefaesspflanzenImportFamily.class);
43

    
44
    private static final String tableName = "Rote Liste Gefäßpflanzen";
45

    
46
    private static final String pluralString = "families";
47

    
48

    
49
    public RedListGefaesspflanzenImportFamily() {
50
        super(tableName, pluralString);
51
    }
52

    
53
    @Override
54
    protected String getIdQuery(RedListGefaesspflanzenImportState state) {
55
        return null;
56
    }
57

    
58
    @Override
59
    protected String getRecordQuery(RedListGefaesspflanzenImportConfigurator config) {
60
        return null;
61
    }
62

    
63
    @Override
64
    protected void doInvoke(RedListGefaesspflanzenImportState state) {
65
        try {
66
            Collection<TaxonBase> families = importFamilies(state);
67
            getTaxonService().save(families);
68
        } catch (SQLException e) {
69
            e.printStackTrace();
70
        }
71
    }
72

    
73

    
74
    private Collection<TaxonBase> importFamilies(RedListGefaesspflanzenImportState state) throws SQLException {
75

    
76
        Map<String, UUID> familyMap = new HashMap<>();
77
        Collection<TaxonBase> families = new ArrayList<>();
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(@SuppressWarnings("rawtypes") 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
        return new HashMap<>();
104
    }
105

    
106
    @Override
107
    protected boolean doCheck(RedListGefaesspflanzenImportState state) {
108
        return false;
109
    }
110

    
111
    @Override
112
    protected boolean isIgnore(RedListGefaesspflanzenImportState state) {
113
        return false;
114
    }
115

    
116
}
(4-4/9)