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