Project

General

Profile

Download (3.38 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.List;
13
import java.util.Map;
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
import eu.etaxonomy.cdm.model.taxon.TaxonNode;
26

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

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

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

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

    
45

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

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

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

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

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

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

    
77

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

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

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

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

    
103
        TaxonNode taxonNode = acceptedTaxon.getTaxonNodes().iterator().next();
104
        if(taxonNode.isExcluded()){
105
            taxonNode.putExcludedNote(Language.ENGLISH(), commentStr);
106
        }
107
        return ;
108
    }
109

    
110
}
(2-2/14)