1
|
/**
|
2
|
* Copyright (C) 2009 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.in;
|
10
|
|
11
|
import java.util.ArrayList;
|
12
|
import java.util.HashSet;
|
13
|
import java.util.List;
|
14
|
import java.util.Map;
|
15
|
import java.util.Set;
|
16
|
|
17
|
import org.apache.log4j.Logger;
|
18
|
|
19
|
import eu.etaxonomy.cdm.io.dwca.TermUri;
|
20
|
import eu.etaxonomy.cdm.io.stream.StreamItem;
|
21
|
import eu.etaxonomy.cdm.model.common.CdmBase;
|
22
|
import eu.etaxonomy.cdm.model.common.Language;
|
23
|
import eu.etaxonomy.cdm.model.description.CommonTaxonName;
|
24
|
import eu.etaxonomy.cdm.model.description.TaxonDescription;
|
25
|
import eu.etaxonomy.cdm.model.reference.Reference;
|
26
|
import eu.etaxonomy.cdm.model.taxon.Taxon;
|
27
|
|
28
|
/**
|
29
|
* @author a.mueller
|
30
|
* @date 22.11.2011
|
31
|
*
|
32
|
*/
|
33
|
public class GbifVernacularNameCsv2CdmConverter extends PartitionableConverterBase<DwcaDataImportConfiguratorBase, DwcaDataImportStateBase<DwcaDataImportConfiguratorBase>>
|
34
|
implements IPartitionableConverter<StreamItem, IReader<CdmBase>, String> {
|
35
|
@SuppressWarnings("unused")
|
36
|
private static final Logger logger = Logger.getLogger(GbifVernacularNameCsv2CdmConverter.class);
|
37
|
private static final String CORE_ID = "coreId";
|
38
|
|
39
|
/**
|
40
|
* @param state
|
41
|
*/
|
42
|
public GbifVernacularNameCsv2CdmConverter(DwcaDataImportStateBase state) {
|
43
|
super(state);
|
44
|
}
|
45
|
|
46
|
|
47
|
@Override
|
48
|
public IReader<MappedCdmBase> map(StreamItem item ){
|
49
|
List<MappedCdmBase> resultList = new ArrayList<MappedCdmBase>();
|
50
|
|
51
|
Map<String, String> csv = item.map;
|
52
|
Reference sourceReference = state.getTransactionalSourceReference();
|
53
|
String sourceReferecenDetail = null;
|
54
|
|
55
|
String id = csv.get(CORE_ID);
|
56
|
Taxon taxon = getTaxonBase(id, item, Taxon.class, state);
|
57
|
if (taxon != null){
|
58
|
MappedCdmBase mcb = new MappedCdmBase(item.term, csv.get(CORE_ID), taxon);
|
59
|
String vernacular = item.get(TermUri.DWC_VERNACULAR_NAME);
|
60
|
//TODO language, area,
|
61
|
TaxonDescription desc = getTaxonDescription(taxon, false);
|
62
|
|
63
|
//TODO
|
64
|
Language language = null;
|
65
|
CommonTaxonName commonName = CommonTaxonName.NewInstance(vernacular, language);
|
66
|
desc.addElement(commonName);
|
67
|
resultList.add(mcb);
|
68
|
}else{
|
69
|
String message = "Can't retrieve taxon from database for id '%s'";
|
70
|
fireWarningEvent(String.format(message, id), item, 12);
|
71
|
}
|
72
|
|
73
|
//return
|
74
|
return new ListReader<MappedCdmBase>(resultList);
|
75
|
|
76
|
}
|
77
|
|
78
|
|
79
|
@Override
|
80
|
public String getSourceId(StreamItem item) {
|
81
|
String id = item.get(CORE_ID);
|
82
|
return id;
|
83
|
}
|
84
|
|
85
|
//**************************** PARTITIONABLE ************************************************
|
86
|
|
87
|
@Override
|
88
|
protected void makeForeignKeysForItem(StreamItem item, Map<String, Set<String>> fkMap) {
|
89
|
String value;
|
90
|
String key;
|
91
|
if ( hasValue(value = item.get(CORE_ID))){
|
92
|
key = TermUri.DWC_TAXON.toString();
|
93
|
Set<String> keySet = getKeySet(key, fkMap);
|
94
|
keySet.add(value);
|
95
|
}
|
96
|
}
|
97
|
|
98
|
|
99
|
@Override
|
100
|
public final Set<String> requiredSourceNamespaces() {
|
101
|
Set<String> result = new HashSet<String>();
|
102
|
result.add(TermUri.DWC_TAXON.toString());
|
103
|
return result;
|
104
|
}
|
105
|
|
106
|
//************************ STRING ************************************************/
|
107
|
|
108
|
|
109
|
|
110
|
@Override
|
111
|
public String toString(){
|
112
|
return this.getClass().getName();
|
113
|
}
|
114
|
|
115
|
|
116
|
|
117
|
|
118
|
|
119
|
}
|