Project

General

Profile

Download (3.12 KB) Statistics
| Branch: | Revision:
1
/**
2
* Copyright (C) 2016 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
package eu.etaxonomy.cdm.io.greece;
10

    
11
import java.util.Arrays;
12
import java.util.HashMap;
13
import java.util.List;
14
import java.util.Set;
15

    
16
import org.apache.log4j.Logger;
17
import org.springframework.stereotype.Component;
18

    
19
import eu.etaxonomy.cdm.io.mexico.SimpleExcelTaxonImportState;
20
import eu.etaxonomy.cdm.model.common.Language;
21
import eu.etaxonomy.cdm.model.description.Feature;
22
import eu.etaxonomy.cdm.model.description.TaxonDescription;
23
import eu.etaxonomy.cdm.model.description.TextData;
24
import eu.etaxonomy.cdm.model.taxon.Taxon;
25

    
26
/**
27
 * Import for the Flora Hellenica taxon comments.
28
 *
29
 * @author a.mueller
30
 * @date 14.12.2016
31
 */
32

    
33
@Component
34
public class FloraHellenicaCommentsImport<CONFIG extends FloraHellenicaImportConfigurator>
35
        extends FloraHellenicaImportBase<CONFIG>{
36

    
37
    private static final long serialVersionUID = -3565782012921316901L;
38
    private static final Logger logger = Logger.getLogger(FloraHellenicaCommentsImport.class);
39

    
40
    private static final String TAXON = "Taxon";
41
    private static final String UNIQUE_ID_ACCEPTED = "Unique ID of taxon name (Includes valid and excluded taxa IDs)";
42
    private static final String COMMENT = "Comment";
43

    
44

    
45
   private  static List<String> expectedKeys= Arrays.asList(new String[]{
46
            UNIQUE_ID_ACCEPTED,
47
            TAXON,
48
            COMMENT
49
    });
50

    
51
    @Override
52
    protected String getWorksheetName() {
53
        return "comments";
54
    }
55

    
56
    /**
57
     * {@inheritDoc}
58
     */
59
    @Override
60
    protected void firstPass(SimpleExcelTaxonImportState<CONFIG> state) {
61

    
62
        String line = state.getCurrentLine() + ": ";
63
        HashMap<String, String> record = state.getOriginalRecord();
64

    
65
        Set<String> keys = record.keySet();
66
        for (String key: keys) {
67
            if (! expectedKeys.contains(key)){
68
                logger.warn(line + "Unexpected Key: " + key);
69
            }
70
        }
71

    
72
        String noStr = getValue(record, "Unique ID");
73
        makeComment(state, line, record, noStr);
74
    }
75

    
76

    
77
    /**
78
     * @param state
79
     * @param line
80
     * @param record
81
     * @param noStr
82
     * @return
83
     */
84
    private void makeComment(SimpleExcelTaxonImportState<CONFIG> state, String line,
85
            HashMap<String, String> record,
86
            String noStr) {
87

    
88
        Taxon acceptedTaxon = getAcceptedTaxon(record, state, UNIQUE_ID_ACCEPTED);
89
        if (acceptedTaxon == null){
90
            logger.warn(line + "Accepted not found: " + record.get(UNIQUE_ID_ACCEPTED));
91
            return;
92
        }
93

    
94
        String commentStr = getValue(record, COMMENT);
95

    
96
        TaxonDescription desc = getTaxonDescription(acceptedTaxon);
97
        TextData comment = TextData.NewInstance(Feature.NOTES(), commentStr, Language.ENGLISH(), null);
98
        desc.addElement(comment);
99
        comment.addImportSource(noStr, getWorksheetName(), getSourceCitation(state), null);
100
        getTaxonService().saveOrUpdate(acceptedTaxon);
101
        return ;
102
    }
103

    
104
}
(1-1/9)