Project

General

Profile

Download (4.1 KB) Statistics
| Branch: | Tag: | 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
package eu.etaxonomy.cdm.io.dwca.out;
10

    
11
import java.io.FileNotFoundException;
12
import java.io.IOException;
13
import java.io.UnsupportedEncodingException;
14
import java.util.Set;
15

    
16
import org.apache.commons.lang.StringUtils;
17
import org.apache.log4j.Logger;
18

    
19
import eu.etaxonomy.cdm.common.CdmUtils;
20
import eu.etaxonomy.cdm.model.common.CdmBase;
21
import eu.etaxonomy.cdm.model.description.DescriptionElementSource;
22
import eu.etaxonomy.cdm.model.location.Country;
23
import eu.etaxonomy.cdm.model.location.NamedArea;
24
import eu.etaxonomy.cdm.model.reference.IOriginalSource;
25
import eu.etaxonomy.cdm.model.reference.ISourceable;
26
import eu.etaxonomy.cdm.model.taxon.TaxonBase;
27
import eu.etaxonomy.cdm.model.taxon.TaxonNode;
28

    
29
/**
30
 * @author a.mueller
31
 * @since 18.04.2011
32
 *
33
 */
34
public abstract class DwcaDataExportBase extends DwcaExportBase{
35

    
36
    private static final long serialVersionUID = -5467295551060073610L;
37

    
38
    @SuppressWarnings("unused")
39
    private static final Logger logger = Logger.getLogger(DwcaDataExportBase.class);
40

    
41
    abstract protected void handleTaxonNode(DwcaTaxExportState state, TaxonNode node)throws IOException, FileNotFoundException, UnsupportedEncodingException;
42

    
43

    
44

    
45

    
46
    /**
47
     * Creates the locationId, locality, countryCode triple
48
     * @param state
49
     * @param record
50
     * @param area
51
     */
52
    protected void handleArea(DwcaTaxExportState state, IDwcaAreaRecord record, NamedArea area, TaxonBase<?> taxon, boolean required) {
53
        if (area != null){
54
            record.setLocationId(area);
55
            record.setLocality(area.getLabel());
56
            if (area.isInstanceOf(Country.class)){
57
                Country country = CdmBase.deproxy(area, Country.class);
58
                record.setCountryCode(country.getIso3166_A2());
59
            }
60
        }else{
61
            if (required){
62
                String message = "Description requires area but area does not exist for taxon " + getTaxonLogString(taxon);
63
                state.getResult().addWarning(message);
64
            }
65
        }
66
    }
67

    
68

    
69
    protected String getTaxonLogString(TaxonBase<?> taxon) {
70
        return taxon.getTitleCache() + "(" + taxon.getId() + ")";
71
    }
72

    
73

    
74
    protected String getSources(ISourceable<?> sourceable, DwcaTaxExportConfigurator config) {
75
        String result = "";
76
        for (IOriginalSource<?> source: sourceable.getSources()){
77
            if (StringUtils.isBlank(source.getIdInSource())){//idInSource indicates that this source is only data provenance, may be changed in future
78
                if (source.getCitation() != null){
79
                    String ref = source.getCitation().getTitleCache();
80
                    result = CdmUtils.concat(config.getSetSeparator(), result, ref);
81
                }
82
            }
83
        }
84
        return result;
85
    }
86

    
87
    protected String getSources3(ISourceable<?> sourceable, DwcaTaxExportConfigurator config) {
88
        String result = "";
89
        for (IOriginalSource<?> source: sourceable.getSources()){
90
                if (source.getCitation() != null){
91
                    String ref = source.getCitation().getTitleCache();
92
                    result = CdmUtils.concat(config.getSetSeparator(), result, ref);
93
                }
94
        }
95
        return result;
96
    }
97

    
98
    protected String getSources2(Set<DescriptionElementSource> sources, DwcaTaxExportConfigurator config) {
99
        String result = "";
100
        for(DescriptionElementSource source: sources){
101
            if (StringUtils.isBlank(source.getIdInSource())){//idInSource indicates that this source is only data provenance, may be changed in future
102
                if (source.getCitation() != null){
103
                    String ref = source.getCitation().getTitleCache();
104
                    result = CdmUtils.concat(config.getSetSeparator(), result, ref);
105
                }
106
            }
107
        }
108
        return result;
109
    }
110

    
111
    @Override
112
    public abstract boolean isIgnore(DwcaTaxExportState state);
113

    
114
}
(1-1/33)