Project

General

Profile

« Previous | Next » 

Revision b37b6a0f

Added by Patrick Plitzner about 8 years ago

Refactor duplicate code

View differences:

app-import/src/main/java/eu/etaxonomy/cdm/io/redlist/gefaesspflanzen/Namespace.java
1
// $Id$
2
/**
3
* Copyright (C) 2016 EDIT
4
* European Distributed Institute of Taxonomy
5
* http://www.e-taxonomy.eu
6
*
7
* The contents of this file are subject to the Mozilla Public License Version 1.1
8
* See LICENSE.TXT at the top of this package for the full license terms.
9
*/
10
package eu.etaxonomy.cdm.io.redlist.gefaesspflanzen;
11

  
12
/**
13
 * @author pplitzner
14
 * @date Mar 7, 2016
15
 *
16
 */
17
public interface Namespace {
18

  
19
    public static final String NAME_NAMESPACE = "name";
20
    public static final String TAXON_NAMESPACE = "taxon";
21
    public static final String AUTHOR_NAMESPACE = "author";
22
}
app-import/src/main/java/eu/etaxonomy/cdm/io/redlist/gefaesspflanzen/RedListGefaesspflanzenImportAuthor.java
34 34
@Component
35 35
@SuppressWarnings("serial")
36 36
public class RedListGefaesspflanzenImportAuthor extends DbImportBase<RedListGefaesspflanzenImportState, RedListGefaesspflanzenImportConfigurator> {
37

  
37 38
    private static final Logger logger = Logger.getLogger(RedListGefaesspflanzenImportAuthor.class);
38 39

  
39 40
    private static final String tableName = "Rote Liste Gefäßpflanzen";
......
94 95

  
95 96
    private void makePerson(RedListGefaesspflanzenImportState state, String authorName) {
96 97
        //check if misapplied name
97
        if(authorName.trim().equals("auct.")){
98
        if(authorName.trim().equals(RedListUtil.AUCT)){
98 99
            return;
99 100
        }
100 101
        TeamOrPersonBase teamOrPerson;
app-import/src/main/java/eu/etaxonomy/cdm/io/redlist/gefaesspflanzen/RedListGefaesspflanzenImportClassification.java
97 97
        String parentId = String.valueOf(rs.getLong("LOWER"));
98 98
        String gueltString = rs.getString("GUELT");
99 99

  
100
        TaxonBase taxonBase = state.getRelatedObject(Namespace.TAXON_NAMESPACE, id, TaxonBase.class);
101
        Taxon parent = (Taxon) state.getRelatedObject(Namespace.TAXON_NAMESPACE, parentId, TaxonBase.class);
100
        TaxonBase taxonBase = state.getRelatedObject(RedListUtil.TAXON_NAMESPACE, id, TaxonBase.class);
101
        Taxon parent = (Taxon) state.getRelatedObject(RedListUtil.TAXON_NAMESPACE, parentId, TaxonBase.class);
102 102

  
103 103
        //taxon
104 104
        if(taxonBase.isInstanceOf(Taxon.class)){
105 105
            //misapplied name
106 106
            String appendedPhrase = taxonBase.getName().getAppendedPhrase();
107
            if(appendedPhrase!=null && appendedPhrase.contains("auct.")){
107
            if(appendedPhrase!=null && appendedPhrase.contains(RedListUtil.AUCT)){
108 108
                parent.addMisappliedName((Taxon) taxonBase, null, null);
109 109
            }
110 110
            else{
......
140 140
        } catch (SQLException e) {
141 141
            e.printStackTrace();
142 142
        }
143
        Map<String, TaxonBase> taxonMap = (Map<String, TaxonBase>) getCommonService().getSourcedObjectsByIdInSource(TaxonBase.class, idSet, Namespace.TAXON_NAMESPACE);
144
        result.put(Namespace.TAXON_NAMESPACE, taxonMap);
143
        Map<String, TaxonBase> taxonMap = (Map<String, TaxonBase>) getCommonService().getSourcedObjectsByIdInSource(TaxonBase.class, idSet, RedListUtil.TAXON_NAMESPACE);
144
        result.put(RedListUtil.TAXON_NAMESPACE, taxonMap);
145 145
        return result;
146 146
    }
147 147

  
app-import/src/main/java/eu/etaxonomy/cdm/io/redlist/gefaesspflanzen/RedListGefaesspflanzenImportNames.java
149 149
            for (int i = 0; i < kombSplit.length; i++) {
150 150
                if(i==0){
151 151
                    //first author is ex author
152
                    TeamOrPersonBase authorKomb = (TeamOrPersonBase) state.getRelatedObject(Namespace.AUTHOR_NAMESPACE, kombSplit[i]);
152
                    TeamOrPersonBase authorKomb = (TeamOrPersonBase) state.getRelatedObject(RedListUtil.AUTHOR_NAMESPACE, kombSplit[i]);
153 153
                    name.setExCombinationAuthorship(authorKomb);
154 154
                }
155 155
                else{
156
                    TeamOrPersonBase authorKomb = (TeamOrPersonBase) state.getRelatedObject(Namespace.AUTHOR_NAMESPACE, kombSplit[i]);
156
                    TeamOrPersonBase authorKomb = (TeamOrPersonBase) state.getRelatedObject(RedListUtil.AUTHOR_NAMESPACE, kombSplit[i]);
157 157
                    name.setCombinationAuthorship(authorKomb);
158 158
                }
159 159
            }
160 160
        }
161
        else if(authorKombString.trim().equals("auct.")){
161
        else if(authorKombString.trim().equals(RedListUtil.AUCT)){
162 162
            logger.warn("NAMNR: "+id+" AUCT information in AUTOR_KOMB column");
163 163
        }
164 164
        else if(!CdmUtils.isBlank(authorKombString)){
165
            TeamOrPersonBase authorKomb = (TeamOrPersonBase) state.getRelatedObject(Namespace.AUTHOR_NAMESPACE, authorKombString);
165
            TeamOrPersonBase authorKomb = (TeamOrPersonBase) state.getRelatedObject(RedListUtil.AUTHOR_NAMESPACE, authorKombString);
166 166
            name.setCombinationAuthorship(authorKomb);
167 167
        }
168 168
        //basionym author
......
173 173
                    logger.error("NAMNR: "+id+" Multiple ex basionymn authors found");
174 174
                }
175 175
                if(i==0){
176
                    TeamOrPersonBase authorBasi= (TeamOrPersonBase) state.getRelatedObject(Namespace.AUTHOR_NAMESPACE, basiSplit[i]);
176
                    TeamOrPersonBase authorBasi= (TeamOrPersonBase) state.getRelatedObject(RedListUtil.AUTHOR_NAMESPACE, basiSplit[i]);
177 177
                    if(CdmUtils.isBlank(authorKombString)){
178 178
                        name.setExCombinationAuthorship(authorBasi);
179 179
                    }
......
182 182
                    }
183 183
                }
184 184
                else{
185
                    TeamOrPersonBase authorBasi= (TeamOrPersonBase) state.getRelatedObject(Namespace.AUTHOR_NAMESPACE, basiSplit[i]);
185
                    TeamOrPersonBase authorBasi= (TeamOrPersonBase) state.getRelatedObject(RedListUtil.AUTHOR_NAMESPACE, basiSplit[i]);
186 186
                    if(CdmUtils.isBlank(authorKombString)){
187 187
                        name.setCombinationAuthorship(authorBasi);
188 188
                    }
......
192 192
                }
193 193
            }
194 194
        }
195
        else if(authorBasiString.trim().equals("auct.")){
195
        else if(authorBasiString.trim().equals(RedListUtil.AUCT)){
196 196
            name.setAppendedPhrase(authorBasiString);
197 197
        }
198 198
        else if(!CdmUtils.isBlank(authorBasiString)){
199 199
            //this seems to be a convention in the source database: When there is only a single author then only the "AUTOR_BASI" column is used
200
            TeamOrPersonBase authorBasi= (TeamOrPersonBase) state.getRelatedObject(Namespace.AUTHOR_NAMESPACE, authorBasiString);
200
            TeamOrPersonBase authorBasi= (TeamOrPersonBase) state.getRelatedObject(RedListUtil.AUTHOR_NAMESPACE, authorBasiString);
201 201
            if(CdmUtils.isBlank(authorKombString)){
202 202
                name.setCombinationAuthorship(authorBasi);
203 203
            }
......
216 216
//        if(CdmUtils.isBlank(authorKombString) && !CdmUtils.isBlank(authorBasiString)){
217 217
//            authorString = "("+authorString+")";
218 218
//        }
219
        if(authorString.equals("auct.")){
219
        if(authorString.equals(RedListUtil.AUCT)){
220 220
            authorString = "";
221 221
        }
222 222
        if(!authorString.equals(authorshipCache)){
......
224 224
        }
225 225

  
226 226
        //id
227
        ImportHelper.setOriginalSource(name, state.getTransactionalSourceReference(), id, Namespace.NAME_NAMESPACE);
227
        ImportHelper.setOriginalSource(name, state.getTransactionalSourceReference(), id, RedListUtil.NAME_NAMESPACE);
228 228
        state.getNameMap().put(id, name.getUuid());
229 229

  
230 230
        namesToSave.add(name);
231 231

  
232 232
        //---TAXON---
233 233
        TaxonBase taxonBase = null;
234
        if(gueltString.equals("1") || (name.getAppendedPhrase()!=null && name.getAppendedPhrase().equals("auct."))){
234
        if(gueltString.equals("1") || (name.getAppendedPhrase()!=null && name.getAppendedPhrase().equals(RedListUtil.AUCT))){
235 235
            taxonBase = Taxon.NewInstance(name, null);
236 236
        }
237 237
        else if(gueltString.equals("x") || gueltString.equals("b")){
......
245 245
        taxaToSave.add(taxonBase);
246 246

  
247 247
        //id
248
        ImportHelper.setOriginalSource(taxonBase, state.getTransactionalSourceReference(), id, Namespace.TAXON_NAMESPACE);
248
        ImportHelper.setOriginalSource(taxonBase, state.getTransactionalSourceReference(), id, RedListUtil.TAXON_NAMESPACE);
249 249
        state.getTaxonMap().put(id, taxonBase.getUuid());
250 250
    }
251 251

  
......
303 303
        } catch (SQLException e) {
304 304
            e.printStackTrace();
305 305
        }
306
        result.put(Namespace.AUTHOR_NAMESPACE, authorMap);
306
        result.put(RedListUtil.AUTHOR_NAMESPACE, authorMap);
307 307

  
308 308
        return result;
309 309
    }
app-import/src/main/java/eu/etaxonomy/cdm/io/redlist/gefaesspflanzen/RedListUtil.java
1
// $Id$
2
/**
3
* Copyright (C) 2016 EDIT
4
* European Distributed Institute of Taxonomy
5
* http://www.e-taxonomy.eu
6
*
7
* The contents of this file are subject to the Mozilla Public License Version 1.1
8
* See LICENSE.TXT at the top of this package for the full license terms.
9
*/
10
package eu.etaxonomy.cdm.io.redlist.gefaesspflanzen;
11

  
12
/**
13
 * @author pplitzner
14
 * @date Mar 7, 2016
15
 *
16
 */
17
public class RedListUtil {
18

  
19
    public static final String NAME_NAMESPACE = "name";
20
    public static final String TAXON_NAMESPACE = "taxon";
21
    public static final String AUTHOR_NAMESPACE = "author";
22
    public static final String AUCT = "auct.";
23

  
24
    public static logError(){
25

  
26
    }
27
}

Also available in: Unified diff