Project

General

Profile

Download (8.47 KB) Statistics
| Branch: | Tag: | Revision:
1
// $Id$
2
/**
3
* Copyright (C) 2007 EDIT
4
* European Distributed Institute of Taxonomy 
5
* http://www.e-taxonomy.eu
6
* 
7
* The contents of this file are subject to the Mozilla Public License Version 1.1
8
* See LICENSE.TXT at the top of this package for the full license terms.
9
*/
10

    
11
package eu.etaxonomy.cdm.io.common;
12

    
13
import java.util.HashMap;
14
import java.util.Map;
15
import java.util.UUID;
16

    
17
import org.apache.log4j.Logger;
18

    
19
import eu.etaxonomy.cdm.api.service.IService;
20
import eu.etaxonomy.cdm.io.common.mapping.IInputTransformer;
21
import eu.etaxonomy.cdm.model.agent.Person;
22
import eu.etaxonomy.cdm.model.agent.TeamOrPersonBase;
23
import eu.etaxonomy.cdm.model.common.AnnotationType;
24
import eu.etaxonomy.cdm.model.common.CdmBase;
25
import eu.etaxonomy.cdm.model.common.ExtensionType;
26
import eu.etaxonomy.cdm.model.common.Language;
27
import eu.etaxonomy.cdm.model.common.MarkerType;
28
import eu.etaxonomy.cdm.model.common.User;
29
import eu.etaxonomy.cdm.model.description.Feature;
30
import eu.etaxonomy.cdm.model.description.PresenceTerm;
31
import eu.etaxonomy.cdm.model.location.NamedArea;
32
import eu.etaxonomy.cdm.model.location.NamedAreaLevel;
33
import eu.etaxonomy.cdm.model.location.ReferenceSystem;
34
import eu.etaxonomy.cdm.model.name.TaxonNameBase;
35
import eu.etaxonomy.cdm.model.occurrence.Specimen;
36
import eu.etaxonomy.cdm.model.reference.Reference;
37
import eu.etaxonomy.cdm.model.taxon.TaxonBase;
38
import eu.etaxonomy.cdm.model.taxon.Classification;
39

    
40
/**
41
 * @author a.mueller
42
 * @created 11.05.2009
43
 * @version 1.0
44
 */
45
public abstract class ImportStateBase<CONFIG extends ImportConfiguratorBase, IO extends CdmImportBase> extends IoStateBase<CONFIG, IO> {
46
	@SuppressWarnings("unused")
47
	private static final Logger logger = Logger.getLogger(ImportStateBase.class);
48
	
49
	//States
50
	private boolean isCheck;
51
	
52
	private Map<Object,Classification> treeMap = new HashMap<Object,Classification>();
53

    
54
	private Map<Reference,UUID> treeUuidMap = new HashMap<Reference,UUID>();
55

    
56
	private Map<String,UUID> classificationKeyUuidMap = new HashMap<String,UUID>();
57
	
58
	private IInputTransformer inputTransformer;
59

    
60
	
61
	private Map<UUID, ExtensionType> extensionTypeMap = new HashMap<UUID, ExtensionType>();
62
	private Map<UUID, MarkerType> markerTypeMap = new HashMap<UUID, MarkerType>();
63
	private Map<UUID, AnnotationType> annotationTypeMap = new HashMap<UUID, AnnotationType>();
64
	
65
	private Map<UUID, NamedArea> namedAreaMap = new HashMap<UUID, NamedArea>();
66
	private Map<UUID, NamedAreaLevel> namedAreaLevelMap = new HashMap<UUID, NamedAreaLevel>();
67
	private Map<UUID, Feature> featureMap = new HashMap<UUID, Feature>();
68
	private Map<UUID, PresenceTerm> presenceTermMap = new HashMap<UUID, PresenceTerm>();;
69
	private Map<UUID, Language> languageMap = new HashMap<UUID, Language>();
70
	
71
	private Map<UUID, ReferenceSystem> referenceSystemMap = new HashMap<UUID, ReferenceSystem>();
72
	
73
	protected ImportStateBase(CONFIG config){
74
		this.config = config;
75
		stores.put(ICdmIO.USER_STORE, new MapWrapper<User>(service));
76
		stores.put(ICdmIO.PERSON_STORE, new MapWrapper<Person>(service));
77
		stores.put(ICdmIO.TEAM_STORE, new MapWrapper<TeamOrPersonBase<?>>(service));
78
		stores.put(ICdmIO.REFERENCE_STORE, new MapWrapper<Reference>(service));
79
		stores.put(ICdmIO.NOMREF_STORE, new MapWrapper<Reference>(service));
80
		stores.put(ICdmIO.NOMREF_DETAIL_STORE, new MapWrapper<Reference>(service));
81
		stores.put(ICdmIO.REF_DETAIL_STORE, new MapWrapper<Reference>(service));
82
		stores.put(ICdmIO.TAXONNAME_STORE, new MapWrapper<TaxonNameBase<?,?>>(service));
83
		stores.put(ICdmIO.TAXON_STORE, new MapWrapper<TaxonBase>(service));
84
		stores.put(ICdmIO.SPECIMEN_STORE, new MapWrapper<Specimen>(service));
85
		
86
		if (getTransformer() == null){
87
			IInputTransformer newTransformer = config.getTransformer();
88
//			if (newTransformer == null){
89
//				newTransformer = new DefaultTransf();
90
//			}
91
			setTransformer(newTransformer);
92
		}
93
	}
94
	
95
	//different type of stores that are used by the known imports
96
	protected Map<String, MapWrapper<? extends CdmBase>> stores = new HashMap<String, MapWrapper<? extends CdmBase>>();
97
	
98
	protected IService<CdmBase> service = null;
99

    
100
	/**
101
	 * @return the stores
102
	 */
103
	public Map<String, MapWrapper<? extends CdmBase>> getStores() {
104
		return stores;
105
	}
106

    
107
	/**
108
	 * @param stores the stores to set
109
	 */
110
	public void setStores(Map<String, MapWrapper<? extends CdmBase>> stores) {
111
		this.stores = stores;
112
	}
113

    
114

    
115
 	public MapWrapper<? extends CdmBase> getStore(String storeLabel){
116
 		return (MapWrapper<? extends CdmBase>) stores.get(storeLabel);
117
 	}
118
	
119

    
120
	/**
121
	 * @return the treeMap
122
	 */
123
	public Classification getTree(Object ref) {
124
		return treeMap.get(ref);
125
	}
126

    
127
	/**
128
	 * @param treeMap the treeMap to set
129
	 */
130
	public void putTree(Object ref, Classification tree) {
131
		if (tree != null){
132
			this.treeMap.put(ref, tree);
133
		}
134
	}
135
	
136
	public int countTrees(){
137
		return treeUuidMap.size();
138
	}
139
	
140
	/**
141
	 * @return the treeUuid
142
	 */
143
	public UUID getTreeUuid(Reference ref) {
144
		return treeUuidMap.get(ref);
145
	}
146

    
147
	public void putTreeUuid(Reference ref, Classification tree) {
148
		if (tree != null &&  tree.getUuid() != null){
149
			this.treeUuidMap.put(ref, tree.getUuid());
150
		}
151
	}
152

    
153
	public int countTreeUuids(){
154
		return treeUuidMap.size();
155
	}
156

    
157
	
158
	
159
	
160
	/**
161
	 * Adds a classification uuid to the classification uuid map,
162
	 * which maps a key for the classification to its UUID in the CDM
163
	 * @param classificationKeyId
164
	 * @param classification
165
	 */
166
	public void putClassificationUuidInt(int classificationKeyId, Classification classification) {
167
		putClassificationUuid(String.valueOf(classificationKeyId), classification);
168
	}
169

    
170
	public void putClassificationUuid(String treeKey, Classification tree) {
171
		if (tree != null &&  tree.getUuid() != null){
172
			this.classificationKeyUuidMap.put(treeKey, tree.getUuid());
173
		}
174
	}
175
	
176
	public UUID getTreeUuidByIntTreeKey(int treeKey) {
177
		return classificationKeyUuidMap.get(String.valueOf(treeKey));
178
	}
179
	
180
	public UUID getTreeUuidByTreeKey(String treeKey) {
181
		return classificationKeyUuidMap.get(treeKey);
182
	}
183
	
184
	
185
	public ExtensionType getExtensionType(UUID uuid){
186
		return extensionTypeMap.get(uuid);
187
	}
188
	
189
	public void putExtensionType(ExtensionType extensionType){
190
		extensionTypeMap.put(extensionType.getUuid(), extensionType);
191
	}
192

    
193
	public MarkerType getMarkerType(UUID uuid){
194
		return markerTypeMap.get(uuid);
195
	}
196
	
197
	public void putMarkerType(MarkerType markerType){
198
		markerTypeMap.put(markerType.getUuid(), markerType);
199
	}
200
	
201
	public AnnotationType getAnnotationType(UUID uuid){
202
		return annotationTypeMap.get(uuid);
203
	}
204
	
205
	public void putAnnotationType(AnnotationType annotationType){
206
		annotationTypeMap.put(annotationType.getUuid(), annotationType);
207
	}
208
	
209
	public NamedArea getNamedArea(UUID uuid){
210
		return namedAreaMap.get(uuid);
211
	}
212
	
213
	public void putNamedArea(NamedArea namedArea){
214
		namedAreaMap.put(namedArea.getUuid(), namedArea);
215
	}
216
	
217
	public NamedAreaLevel getNamedAreaLevel(UUID uuid){
218
		return namedAreaLevelMap.get(uuid);
219
	}
220

    
221
	
222
	public void putNamedAreaLevel(NamedAreaLevel namedAreaLevel){
223
		namedAreaLevelMap.put(namedAreaLevel.getUuid(), namedAreaLevel);
224
	}
225

    
226
	
227
	public Feature getFeature(UUID uuid){
228
		return featureMap.get(uuid);
229
	}
230
	
231
	public void putFeature(Feature feature){
232
		featureMap.put(feature.getUuid(), feature);
233
	}
234
	
235
	public PresenceTerm getPresenceTerm(UUID uuid){
236
		return presenceTermMap.get(uuid);
237
	}
238
	
239
	public void putPresenceTerm(PresenceTerm presenceTerm){
240
		presenceTermMap.put(presenceTerm.getUuid(), presenceTerm);
241
	}
242

    
243
	public Language getLanguage(UUID uuid){
244
		return languageMap.get(uuid);
245
	}
246
	
247
	public void putLanguage(Language language){
248
		languageMap.put(language.getUuid(), language);
249
	}
250
	
251
	
252
	public ReferenceSystem getReferenceSystem(UUID uuid){
253
		return referenceSystemMap.get(uuid);
254
	}
255
	
256
	public void putReferenceSystem(ReferenceSystem referenceSystem){
257
		referenceSystemMap.put(referenceSystem.getUuid(), referenceSystem);
258
	}
259
	
260
	
261
	//TODO make this abstract or find another way to force that the
262
	//transformer exists
263
	public IInputTransformer getTransformer(){
264
		return inputTransformer;
265
	}
266
	
267
	public void setTransformer(IInputTransformer transformer){
268
		this.inputTransformer = transformer;
269
	}
270

    
271
	/**
272
	 * Returns true, if this import is in validation state. Flase otherwise
273
	 * @return
274
	 */
275
	public boolean isCheck() {
276
		return isCheck;
277
	}
278
	
279
	/**
280
	 * @see #isCheck
281
	 * @param isCheck
282
	 */
283
	public void setCheck(boolean isCheck) {
284
		this.isCheck = isCheck;
285
	}
286

    
287

    
288
	
289
}
(33-33/48)