Project

General

Profile

« Previous | Next » 

Revision 531fc7bc

Added by Andreas Müller almost 8 years ago

Remove generics from Reference in cdmlib (except for cdmlib-model) #5830

View differences:

cdmlib-io/src/main/java/eu/etaxonomy/cdm/io/dwca/in/GbifDescriptionCsv2CdmConverter.java
1 1
// $Id$
2 2
/**
3 3
* Copyright (C) 2009 EDIT
4
* European Distributed Institute of Taxonomy 
4
* European Distributed Institute of Taxonomy
5 5
* http://www.e-taxonomy.eu
6
* 
6
*
7 7
* The contents of this file are subject to the Mozilla Public License Version 1.1
8 8
* See LICENSE.TXT at the top of this package for the full license terms.
9 9
*/
......
36 36
 * @date 22.11.2011
37 37
 *
38 38
 */
39
public class GbifDescriptionCsv2CdmConverter extends PartitionableConverterBase<DwcaDataImportConfiguratorBase, DwcaDataImportStateBase<DwcaDataImportConfiguratorBase>>  
39
public class GbifDescriptionCsv2CdmConverter extends PartitionableConverterBase<DwcaDataImportConfiguratorBase, DwcaDataImportStateBase<DwcaDataImportConfiguratorBase>>
40 40
						implements IPartitionableConverter<StreamItem, IReader<CdmBase>, String>{
41
	
41

  
42 42
	@SuppressWarnings("unused")
43 43
	private static final Logger logger = Logger.getLogger(GbifDescriptionCsv2CdmConverter.class);
44 44

  
45 45
	private static final String CORE_ID = "coreId";
46
	
46

  
47 47
	/**
48 48
	 * @param state
49 49
	 */
......
51 51
		super(state);
52 52
	}
53 53

  
54
	public IReader<MappedCdmBase> map(StreamItem item ){
55
		List<MappedCdmBase> resultList = new ArrayList<MappedCdmBase>(); 
56
		
54
	@Override
55
    public IReader<MappedCdmBase> map(StreamItem item ){
56
		List<MappedCdmBase> resultList = new ArrayList<MappedCdmBase>();
57

  
57 58
		Map<String, String> csv = item.map;
58
		Reference<?> sourceReference = state.getTransactionalSourceReference();
59
		Reference sourceReference = state.getTransactionalSourceReference();
59 60
		String sourceReferecenDetail = null;
60
		
61

  
61 62
		String id = getSourceId(item);
62 63
		Taxon taxon = getTaxonBase(id, item, Taxon.class, state);
63 64
		if (taxon != null){
64
			
65

  
65 66
			String description = item.get(TermUri.DC_DESCRIPTION);
66 67
			//String license = item.get(TermUri.DC_LICENSE);//lorna check - often empty in SP dwca
67
					
68

  
68 69
			//TODO: Create the Language from the TermUri.DC_LANGUAGE in the dwca
69
			Language language = getLanguage(item); 
70
									
71
			
70
			Language language = getLanguage(item);
71

  
72

  
72 73
			if (StringUtils.isNotBlank(description)){
73 74
				Feature feature = getFeatureByDcType(item, resultList);
74 75

  
75 76
				TaxonDescription taxonDescription = getTaxonDescription(taxon, false);
76
								
77

  
77 78
				//deduplicate - if this taxonDescription already got these Rights attached
78 79
				boolean addRights = true;
79 80
				String rights = item.get(TermUri.DC_RIGHTS);
80
				Set<Rights> allRights = taxonDescription.getRights();				
81
				for (Rights r : allRights) {					
81
				Set<Rights> allRights = taxonDescription.getRights();
82
				for (Rights r : allRights) {
82 83
					if (r.getText() == rights) {
83 84
						addRights = false;
84 85
					}
85 86
				}
86
				
87

  
87 88
				if (addRights && (rights != null || rights != "")) {
88 89
					Rights copyright = Rights.NewInstance(rights, language);
89 90
					taxonDescription.addRights(copyright);
90 91
				}
91
				
92

  
92 93
				TextData descElement = TextData.NewInstance(feature);
93
				
94

  
94 95
				//Language language = getLanguage(item);  //TODO
95 96
				descElement.putText(language,description);
96 97
				taxonDescription.addElement(descElement);
......
98 99
				String message = "Description is empty. Description item will not be imported.";
99 100
				fireWarningEvent(message, item, 4);
100 101
			}
101
			
102

  
102 103
			MappedCdmBase  mcb = new MappedCdmBase(item.term, csv.get(CORE_ID), taxon);
103 104
			resultList.add(mcb);
104 105
		}else{
......
106 107
			message = String.format(message, id);
107 108
			fireWarningEvent(message, item, 12);
108 109
		}
109
		
110

  
110 111
		return new ListReader<MappedCdmBase>(resultList);
111 112
	}
112 113

  
113
	
114

  
114 115
	private Language getLanguage(StreamItem item) {
115 116
		//TODO
116
		
117

  
117 118
		Language language = Language.DEFAULT();
118
		String langString = item.get(TermUri.DC_LANGUAGE);	
119
		
119
		String langString = item.get(TermUri.DC_LANGUAGE);
120

  
120 121
		/*if (langString != null) {
121 122
			if (!langString.equals("")) {
122 123
				language = getTermService().getLanguageByIso(langString.substring(0, 2));
......
130 131
	 * Determines the feature by the dc:type attribute. Tries to reuse existing
131 132
	 * features.
132 133
	 * @param item
133
	 * @param resultList 
134
	 * @param resultList
134 135
	 * @return
135 136
	 */
136 137
	private Feature getFeatureByDcType(StreamItem item, List<MappedCdmBase> resultList) {
137 138
		String descriptionType = item.get(TermUri.DC_TYPE);
138 139
		item.remove(TermUri.DC_TYPE);
139
		
140

  
140 141
		try {
141 142
			Feature feature = state.getTransformer().getFeatureByKey(descriptionType);
142 143
			if (feature != null){
......
148 149
				String message = "There is more than 1 cdm entity matching given locationId '%s'. I take an arbitrary one.";
149 150
				fireWarningEvent(String.format(message, item), item, 4);
150 151
				return features.iterator().next();
151
			}	
152
			}
152 153
			UUID featureUuid = state.getTransformer().getFeatureUuid(descriptionType);
153 154
			feature = state.getCurrentIO().getFeature(state, featureUuid, descriptionType, descriptionType, null, null);
154 155
			if (feature == null){
......
165 166
			fireWarningEvent(message, item, 8);
166 167
			return null;
167 168
		}
168
		
169

  
169 170
	}
170 171

  
171 172
	@Override
......
174 175
		return id;
175 176
	}
176 177

  
177
	
178

  
178 179
//********************** PARTITIONABLE **************************************/
179 180

  
180 181
	@Override
......
187 188
			keySet.add(value);
188 189
		}
189 190
	}
190
	
191
	
191

  
192

  
192 193
	@Override
193 194
	public Set<String> requiredSourceNamespaces() {
194 195
		Set<String> result = new HashSet<String>();
195 196
 		result.add(TermUri.DWC_TAXON.toString());
196 197
 		return result;
197 198
	}
198
	
199

  
199 200
//******************* TO STRING ******************************************/
200
	
201

  
201 202
	@Override
202 203
	public String toString(){
203 204
		return this.getClass().getName();

Also available in: Unified diff