Project

General

Profile

Download (3.52 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.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> familyMapGL = new HashMap<>();
72
        Map<String, UUID> familyMapCL = new HashMap<>();
73

    
74
        String query = "SELECT DISTINCT f.FAMILIE "
75
                + " FROM GATTUNG_FAMILIE f";
76

    
77
        ResultSet rs = state.getConfig().getSource().getResultSet(query);
78
        while(rs.next()){
79
            String familieStr = rs.getString("FAMILIE");
80
            BotanicalName name = BotanicalName.NewInstance(Rank.FAMILY());
81
            name.setGenusOrUninomial(familieStr);
82
            Taxon familyGL = Taxon.NewInstance(name, null);
83
            familyMapGL.put(familieStr, familyGL.getUuid());
84
            getTaxonService().saveOrUpdate(familyGL);
85
            //clone for checkliste
86
            Taxon familyCL = (Taxon) familyGL.clone();
87
            familyMapCL.put(familieStr, familyCL.getUuid());
88
            getTaxonService().save(familyCL);
89
        }
90
        state.setFamilyMapGesamtListe(familyMapGL);
91
        state.setFamilyMapCheckliste(familyMapCL);
92
    }
93

    
94
    @Override
95
    public boolean doPartition(ResultSetPartitioner partitioner, RedListGefaesspflanzenImportState state) {
96
        return true;
97
    }
98

    
99
    @Override
100
    public Map<Object, Map<String, ? extends CdmBase>> getRelatedObjectsForPartition(ResultSet rs,
101
            RedListGefaesspflanzenImportState state) {
102
        Map<Object, Map<String, ? extends CdmBase>> result = new HashMap<>();
103
        return result;
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)