Project

General

Profile

Download (2.76 KB) Statistics
| Branch: | Tag: | Revision:
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.reference.Reference;
23
import eu.etaxonomy.cdm.model.taxon.Taxon;
24

    
25
/**
26
 * @author a.mueller
27
 * @date 22.11.2011
28
 *
29
 */
30
public class GbifImageCsv2CdmConverter extends PartitionableConverterBase<DwcaDataImportConfiguratorBase, DwcaDataImportStateBase<DwcaDataImportConfiguratorBase>>
31
						implements IPartitionableConverter<StreamItem, IReader<CdmBase>, String>{
32

    
33
	@SuppressWarnings("unused")
34
	private static final Logger logger = Logger.getLogger(GbifImageCsv2CdmConverter.class);
35

    
36
	private static final String CORE_ID = "coreId";
37

    
38
	/**
39
	 * @param state
40
	 */
41
	public GbifImageCsv2CdmConverter(DwcaDataImportStateBase state) {
42
		super(state);
43
	}
44

    
45
	@Override
46
    public IReader<MappedCdmBase<? extends CdmBase>> map(StreamItem item ){
47
		List<MappedCdmBase<? extends CdmBase>> resultList = new ArrayList<>();
48

    
49
		Map<String, String> csv = item.map;
50
		Reference sourceReference = state.getTransactionalSourceReference();
51
		String sourceReferecenDetail = null;
52

    
53
		String id = getSourceId(item);
54
		Taxon taxon = getTaxonBase(id, item, Taxon.class, state);
55
		if (taxon != null){
56

    
57
//			xxx;
58

    
59
		}else{
60
			String message = "Can't retrieve taxon from database for id '%s'";
61
			fireWarningEvent(String.format(message, id), item, 12);
62
		}
63

    
64
		//return
65
		return new ListReader<>(resultList);
66
	}
67

    
68

    
69

    
70

    
71
	@Override
72
	public String getSourceId(StreamItem item) {
73
		String id = item.get(CORE_ID);
74
		return id;
75
	}
76

    
77

    
78
//********************** PARTITIONABLE **************************************/
79

    
80
	@Override
81
	protected void makeForeignKeysForItem(StreamItem item, Map<String, Set<String>> fkMap) {
82
		String value;
83
		String key;
84
		//taxon
85
		if ( hasValue(value = item.get(CORE_ID))){
86
			key = TermUri.DWC_TAXON.toString();
87
			Set<String> keySet = getKeySet(key, fkMap);
88
			keySet.add(value);
89
		}
90

    
91
	}
92

    
93

    
94
	@Override
95
	public Set<String> requiredSourceNamespaces() {
96
		Set<String> result = new HashSet<>();
97
 		result.add(TermUri.DWC_TAXON.toString());
98
 		return result;
99
	}
100

    
101
//******************* TO STRING ******************************************/
102

    
103
	@Override
104
	public String toString(){
105
		return this.getClass().getName();
106
	}
107

    
108

    
109
}
(18-18/37)