Project

General

Profile

« Previous | Next » 

Revision b463135c

Added by Patrick Plitzner over 6 years ago

Add name import

View differences:

app-import/src/main/java/eu/etaxonomy/cdm/io/redlist/gefaesspflanzen/RedListGefaesspflanzenImportNames.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.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.io.common.mapping.UndefinedTransformerMethodException;
27
import eu.etaxonomy.cdm.model.common.CdmBase;
28
import eu.etaxonomy.cdm.model.name.BotanicalName;
29
import eu.etaxonomy.cdm.model.name.Rank;
30
import eu.etaxonomy.cdm.model.name.TaxonNameBase;
31

  
32
/**
33
 * @author a.mueller
34
 * @created 05.01.2016
35
 */
36

  
37
@Component
38
@SuppressWarnings("serial")
39
public class RedListGefaesspflanzenImportNames extends DbImportBase<RedListGefaesspflanzenImportState, RedListGefaesspflanzenImportConfigurator> {
40
    private static final Logger logger = Logger.getLogger(RedListGefaesspflanzenImportNames.class);
41

  
42
    private static final String tableName = "Rote Liste Gefäßpflanzen";
43

  
44
    private static final String pluralString = "names";
45

  
46
    private static final String TAXON_NAMESPACE = "name";
47

  
48
    public RedListGefaesspflanzenImportNames() {
49
        super(tableName, pluralString);
50
    }
51

  
52
    @Override
53
    protected String getIdQuery(RedListGefaesspflanzenImportState state) {
54
        return "SELECT NAMNR "
55
                + "FROM V_TAXATLAS_D20_EXPORT t "
56
                + " ORDER BY NAMNR";
57
    }
58

  
59
    @Override
60
    protected String getRecordQuery(RedListGefaesspflanzenImportConfigurator config) {
61
        String result = " SELECT * "
62
                + " FROM V_TAXATLAS_D20_EXPORT t "
63
                + " WHERE t.NAMNR IN (@IDSET)";
64
        result = result.replace("@IDSET", IPartitionedIO.ID_LIST_TOKEN);
65
        return result;
66
    }
67

  
68
    @Override
69
    protected void doInvoke(RedListGefaesspflanzenImportState state) {
70
        super.doInvoke(state);
71
    }
72

  
73

  
74
    @Override
75
    public boolean doPartition(ResultSetPartitioner partitioner, RedListGefaesspflanzenImportState state) {
76
        ResultSet rs = partitioner.getResultSet();
77
        Set<TaxonNameBase> taxaToSave = new HashSet<TaxonNameBase>();
78
        try {
79
            while (rs.next()){
80
                makeSingleName(state, rs, taxaToSave);
81

  
82
            }
83
        } catch (SQLException e) {
84
            e.printStackTrace();
85
        }
86

  
87
        getNameService().saveOrUpdate(taxaToSave);
88
        return true;
89
    }
90

  
91
    private void makeSingleName(RedListGefaesspflanzenImportState state, ResultSet rs, Set<TaxonNameBase> namesToSave)
92
            throws SQLException {
93
        long id = rs.getLong("NAMNR");
94
        String taxNameString = rs.getString("TAXNAME");
95
        String rangString = rs.getString("RANG");
96
        String ep1String = rs.getString("EPI1");
97
        String ep2String = rs.getString("EPI2");
98
        String ep3String = rs.getString("EPI3");
99
        String nomZusatzString = rs.getString("NOM_ZUSATZ");
100
        String zusatzString = rs.getString("ZUSATZ");
101

  
102

  
103
        BotanicalName name = BotanicalName.NewInstance(makeRank(state, rangString));
104

  
105
        //id
106
        ImportHelper.setOriginalSource(name, state.getTransactionalSourceReference(), id, TAXON_NAMESPACE);
107
    }
108

  
109
    private Rank makeRank(RedListGefaesspflanzenImportState state, String rankStr) {
110
        Rank rank = null;
111
        try {
112
            rank = state.getTransformer().getRankByKey(rankStr);
113
        } catch (UndefinedTransformerMethodException e) {
114
            e.printStackTrace();
115
        }
116
        return rank;
117
    }
118

  
119

  
120

  
121
    @Override
122
    public Map<Object, Map<String, ? extends CdmBase>> getRelatedObjectsForPartition(ResultSet rs,
123
            RedListGefaesspflanzenImportState state) {
124
        Map<Object, Map<String, ? extends CdmBase>> result = new HashMap<>();
125
//        Map<String, TeamOrPersonBase<?>> authorMap = new HashMap<>();
126
//        Set<String> authorKombSet = new HashSet<>();
127
//        Set<String> referenceIdSet = new HashSet<String>();
128
//
129
//        try {
130
//            while (rs.next()){
131
//                String authorStr = rs.getString("tax_author_name");
132
//                authorKombSet.add(authorStr);
133
//                handleForeignKey(rs, referenceIdSet, "tax_document");
134
//            }
135
//        } catch (SQLException e) {
136
//            e.printStackTrace();
137
//        }
138
//
139
//        //Authors
140
//        Set<UUID> uuidSet = new HashSet<>();
141
//        for (String authorStr : authorKombSet){
142
//            UUID uuid = state.getAuthorUuid(authorStr);
143
//            uuidSet.add(uuid);
144
//        }
145
//        List<TeamOrPersonBase<?>> authors = (List)getAgentService().find(uuidSet);
146
//        Map<UUID, TeamOrPersonBase<?>> authorUuidMap = new HashMap<>();
147
//        for (TeamOrPersonBase<?> author : authors){
148
//            authorUuidMap.put(author.getUuid(), author);
149
//        }
150
//
151
//        for (String authorStr : authorKombSet){
152
//            UUID uuid = state.getAuthorUuid(authorStr);
153
//            TeamOrPersonBase<?> author = authorUuidMap.get(uuid);
154
//            authorMap.put(authorStr, author);
155
//        }
156
//        result.put(AUTHOR_NAMESPACE, authorMap);
157
//
158
//        //reference map
159
//        String nameSpace = REFERENCE_NAMESPACE;
160
//        Class<?> cdmClass = Reference.class;
161
//        Set<String> idSet = referenceIdSet;
162
//        Map<String, Reference<?>> referenceMap = (Map<String, Reference<?>>)getCommonService().getSourcedObjectsByIdInSource(cdmClass, idSet, nameSpace);
163
//        result.put(nameSpace, referenceMap);
164
//
165
//        //secundum
166
//        UUID secUuid = state.getConfig().getSecUuid();
167
//        Reference<?> secRef = getReferenceService().find(secUuid);
168
//        referenceMap.put(secUuid.toString(), secRef);
169

  
170
        return result;
171
    }
172

  
173
    @Override
174
    protected boolean doCheck(RedListGefaesspflanzenImportState state) {
175
        return false;
176
    }
177

  
178
    @Override
179
    protected boolean isIgnore(RedListGefaesspflanzenImportState state) {
180
        return false;
181
    }
182

  
183
}

Also available in: Unified diff