Project

General

Profile

Download (11.9 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.TeamOrPersonBase;
22
import eu.etaxonomy.cdm.model.common.AnnotationType;
23
import eu.etaxonomy.cdm.model.common.CdmBase;
24
import eu.etaxonomy.cdm.model.common.DefinedTerm;
25
import eu.etaxonomy.cdm.model.common.DefinedTermBase;
26
import eu.etaxonomy.cdm.model.common.ExtensionType;
27
import eu.etaxonomy.cdm.model.common.Language;
28
import eu.etaxonomy.cdm.model.common.MarkerType;
29
import eu.etaxonomy.cdm.model.description.Feature;
30
import eu.etaxonomy.cdm.model.description.MeasurementUnit;
31
import eu.etaxonomy.cdm.model.description.PresenceAbsenceTerm;
32
import eu.etaxonomy.cdm.model.description.State;
33
import eu.etaxonomy.cdm.model.description.StatisticalMeasure;
34
import eu.etaxonomy.cdm.model.location.NamedArea;
35
import eu.etaxonomy.cdm.model.location.NamedAreaLevel;
36
import eu.etaxonomy.cdm.model.location.ReferenceSystem;
37
import eu.etaxonomy.cdm.model.name.Rank;
38
import eu.etaxonomy.cdm.model.name.TaxonNameBase;
39
import eu.etaxonomy.cdm.model.occurrence.DerivedUnit;
40
import eu.etaxonomy.cdm.model.reference.Reference;
41
import eu.etaxonomy.cdm.model.taxon.Classification;
42
import eu.etaxonomy.cdm.model.taxon.TaxonBase;
43
import eu.etaxonomy.cdm.model.taxon.TaxonRelationshipType;
44

    
45
/**
46
 * @author a.mueller
47
 * @created 11.05.2009
48
 */
49
public abstract class ImportStateBase<CONFIG extends ImportConfiguratorBase, IO extends CdmImportBase> extends IoStateBase<CONFIG, IO> {
50
	@SuppressWarnings("unused")
51
	private static final Logger logger = Logger.getLogger(ImportStateBase.class);
52

    
53
	//States
54
	private boolean isCheck;
55

    
56
	private Map<Object,Classification> treeMap = new HashMap<Object,Classification>();
57

    
58
	private Map<Reference,UUID> treeUuidMap = new HashMap<Reference,UUID>();
59

    
60
	private Map<String,UUID> classificationKeyUuidMap = new HashMap<String,UUID>();
61

    
62
	private IInputTransformer inputTransformer;
63

    
64

    
65
	private Map<UUID, ExtensionType> extensionTypeMap = new HashMap<UUID, ExtensionType>();
66
	private Map<UUID, MarkerType> markerTypeMap = new HashMap<UUID, MarkerType>();
67
	private Map<UUID, AnnotationType> annotationTypeMap = new HashMap<UUID, AnnotationType>();
68
	private Map<UUID, DefinedTerm> identifierTypeMap = new HashMap<UUID, DefinedTerm>();
69

    
70
	private Map<UUID, NamedArea> namedAreaMap = new HashMap<UUID, NamedArea>();
71
	private Map<UUID, NamedAreaLevel> namedAreaLevelMap = new HashMap<UUID, NamedAreaLevel>();
72
	private Map<UUID, Feature> featureMap = new HashMap<UUID, Feature>();
73
	private Map<UUID, State> stateTermMap = new HashMap<UUID, State>();
74
	private Map<UUID, MeasurementUnit> measurementUnitMap = new HashMap<UUID, MeasurementUnit>();
75

    
76
	private Map<UUID, StatisticalMeasure> statisticalMeasureMap = new HashMap<UUID, StatisticalMeasure>();
77
	private Map<UUID, DefinedTerm> modifierMap = new HashMap<UUID, DefinedTerm>();
78

    
79
	private Map<UUID, PresenceAbsenceTerm> presenceTermMap = new HashMap<UUID, PresenceAbsenceTerm>();
80
	private Map<UUID, Language> languageMap = new HashMap<UUID, Language>();
81
	private Map<UUID, TaxonRelationshipType> taxonRelationshipTypeMap = new HashMap<UUID, TaxonRelationshipType>();
82

    
83
	private Map<UUID, ReferenceSystem> referenceSystemMap = new HashMap<UUID, ReferenceSystem>();
84
	private Map<UUID, Rank> rankMap = new HashMap<UUID, Rank>();
85
	private Map<UUID, DefinedTerm> kindOfUnitMap = new HashMap<UUID, DefinedTerm>();
86

    
87

    
88

    
89
	protected IService<CdmBase> service = null;
90

    
91
	protected ImportStateBase(CONFIG config){
92
		this.config = config;
93
		stores.put(ICdmIO.TEAM_STORE, new MapWrapper<TeamOrPersonBase<?>>(service));
94
		stores.put(ICdmIO.REFERENCE_STORE, new MapWrapper<Reference>(service));
95
		stores.put(ICdmIO.NOMREF_STORE, new MapWrapper<Reference>(service));
96
		stores.put(ICdmIO.TAXONNAME_STORE, new MapWrapper<TaxonNameBase<?,?>>(service));
97
		stores.put(ICdmIO.TAXON_STORE, new MapWrapper<TaxonBase>(service));
98
		stores.put(ICdmIO.SPECIMEN_STORE, new MapWrapper<DerivedUnit>(service));
99

    
100
		if (getTransformer() == null){
101
			IInputTransformer newTransformer = config.getTransformer();
102
//			if (newTransformer == null){
103
//				newTransformer = new DefaultTransf();
104
//			}
105
			setTransformer(newTransformer);
106
		}
107

    
108
	}
109

    
110

    
111

    
112
	/**
113
	 * Resets (empties) all maps which map a uuid to a {@link DefinedTermBase term}.
114
	 * This is usually needed when a a new transaction is opened and user defined terms are reused.
115
	 */
116
	public void resetUuidTermMaps(){
117
		extensionTypeMap = new HashMap<UUID, ExtensionType>();
118
		markerTypeMap = new HashMap<UUID, MarkerType>();
119
		annotationTypeMap = new HashMap<UUID, AnnotationType>();
120

    
121
		namedAreaMap = new HashMap<UUID, NamedArea>();
122
		namedAreaLevelMap = new HashMap<UUID, NamedAreaLevel>();
123
		featureMap = new HashMap<UUID, Feature>();
124
		stateTermMap = new HashMap<UUID, State>();
125
		measurementUnitMap = new HashMap<UUID, MeasurementUnit>();
126
		statisticalMeasureMap = new HashMap<UUID, StatisticalMeasure>();
127
		modifierMap = new HashMap<UUID, DefinedTerm>();
128

    
129
		presenceTermMap = new HashMap<UUID, PresenceAbsenceTerm>();;
130
		languageMap = new HashMap<UUID, Language>();
131
		taxonRelationshipTypeMap = new HashMap<UUID, TaxonRelationshipType>();
132

    
133
		referenceSystemMap = new HashMap<UUID, ReferenceSystem>();
134
		rankMap = new HashMap<UUID, Rank>();
135
	}
136

    
137

    
138
	//different type of stores that are used by the known imports
139
	protected Map<String, MapWrapper<? extends CdmBase>> stores = new HashMap<String, MapWrapper<? extends CdmBase>>();
140

    
141

    
142
	/**
143
	 * @return the stores
144
	 */
145
	public Map<String, MapWrapper<? extends CdmBase>> getStores() {
146
		return stores;
147
	}
148

    
149
	/**
150
	 * @param stores the stores to set
151
	 */
152
	public void setStores(Map<String, MapWrapper<? extends CdmBase>> stores) {
153
		this.stores = stores;
154
	}
155

    
156

    
157
 	public MapWrapper<? extends CdmBase> getStore(String storeLabel){
158
 		return stores.get(storeLabel);
159
 	}
160

    
161

    
162
	/**
163
	 * @return the treeMap
164
	 */
165
	public Classification getTree(Object ref) {
166
		return treeMap.get(ref);
167
	}
168

    
169
	/**
170
	 * @param treeMap the treeMap to set
171
	 */
172
	public void putTree(Object ref, Classification tree) {
173
		if (tree != null){
174
			this.treeMap.put(ref, tree);
175
		}
176
	}
177

    
178
	public int countTrees(){
179
		return treeUuidMap.size();
180
	}
181

    
182
	/**
183
	 * @return the treeUuid
184
	 */
185
	public UUID getTreeUuid(Reference ref) {
186
		return treeUuidMap.get(ref);
187
	}
188

    
189
	public void putTreeUuid(Reference ref, Classification tree) {
190
		if (tree != null &&  tree.getUuid() != null){
191
			this.treeUuidMap.put(ref, tree.getUuid());
192
		}
193
	}
194

    
195
	public int countTreeUuids(){
196
		return treeUuidMap.size();
197
	}
198

    
199

    
200
	/**
201
	 * Adds a classification uuid to the classification uuid map,
202
	 * which maps a key for the classification to its UUID in the CDM
203
	 * @param classificationKeyId
204
	 * @param classification
205
	 */
206
	public void putClassificationUuidInt(int classificationKeyId, Classification classification) {
207
		putClassificationUuid(String.valueOf(classificationKeyId), classification);
208
	}
209

    
210
	public void putClassificationUuid(String treeKey, Classification tree) {
211
		if (tree != null &&  tree.getUuid() != null){
212
			this.classificationKeyUuidMap.put(treeKey, tree.getUuid());
213
		}
214
	}
215

    
216
	public UUID getTreeUuidByIntTreeKey(int treeKey) {
217
		return classificationKeyUuidMap.get(String.valueOf(treeKey));
218
	}
219

    
220
	public UUID getTreeUuidByTreeKey(String treeKey) {
221
		return classificationKeyUuidMap.get(treeKey);
222
	}
223

    
224

    
225
	public DefinedTerm getIdentifierType(UUID uuid){
226
		return identifierTypeMap.get(uuid);
227
	}
228

    
229
	public void putIdentifierType(DefinedTerm identifierType){
230
		identifierTypeMap.put(identifierType.getUuid(), identifierType);
231
	}
232

    
233
	public ExtensionType getExtensionType(UUID uuid){
234
		return extensionTypeMap.get(uuid);
235
	}
236

    
237
	public void putExtensionType(ExtensionType extensionType){
238
		extensionTypeMap.put(extensionType.getUuid(), extensionType);
239
	}
240

    
241
	public MarkerType getMarkerType(UUID uuid){
242
		return markerTypeMap.get(uuid);
243
	}
244

    
245
	public void putMarkerType(MarkerType markerType){
246
		markerTypeMap.put(markerType.getUuid(), markerType);
247
	}
248

    
249
	public AnnotationType getAnnotationType(UUID uuid){
250
		return annotationTypeMap.get(uuid);
251
	}
252

    
253
	public void putAnnotationType(AnnotationType annotationType){
254
		annotationTypeMap.put(annotationType.getUuid(), annotationType);
255
	}
256

    
257
	public NamedArea getNamedArea(UUID uuid){
258
		return namedAreaMap.get(uuid);
259
	}
260

    
261
	public void putNamedArea(NamedArea namedArea){
262
		namedAreaMap.put(namedArea.getUuid(), namedArea);
263
	}
264

    
265
	public NamedAreaLevel getNamedAreaLevel(UUID uuid){
266
		return namedAreaLevelMap.get(uuid);
267
	}
268

    
269

    
270
	public void putNamedAreaLevel(NamedAreaLevel namedAreaLevel){
271
		namedAreaLevelMap.put(namedAreaLevel.getUuid(), namedAreaLevel);
272
	}
273

    
274
	public Rank getRank(UUID uuid){
275
		return rankMap.get(uuid);
276
	}
277

    
278

    
279
	public void putRank(Rank rank){
280
		rankMap.put(rank.getUuid(), rank);
281
	}
282

    
283
	public State getStateTerm(UUID uuid){
284
		return stateTermMap.get(uuid);
285
	}
286

    
287
	public void putStateTerm(State stateTerm){
288
		stateTermMap.put(stateTerm.getUuid(), stateTerm);
289
	}
290

    
291
	public Feature getFeature(UUID uuid){
292
		return featureMap.get(uuid);
293
	}
294

    
295
	public void putFeature(Feature feature){
296
		featureMap.put(feature.getUuid(), feature);
297
	}
298

    
299
	public DefinedTerm getKindOfUnit(UUID uuid){
300
		return kindOfUnitMap.get(uuid);
301
	}
302

    
303
	public void putKindOfUnit(DefinedTerm unit){
304
		kindOfUnitMap.put(unit.getUuid(), unit);
305
	}
306

    
307
	public MeasurementUnit getMeasurementUnit(UUID uuid){
308
		return measurementUnitMap.get(uuid);
309
	}
310

    
311
	public void putMeasurementUnit(MeasurementUnit unit){
312
		measurementUnitMap.put(unit.getUuid(), unit);
313
	}
314

    
315
	public void putStatisticalMeasure(StatisticalMeasure unit){
316
		statisticalMeasureMap.put(unit.getUuid(), unit);
317
	}
318

    
319
	public StatisticalMeasure getStatisticalMeasure(UUID uuid){
320
		return statisticalMeasureMap.get(uuid);
321
	}
322

    
323

    
324
	public DefinedTerm getModifier(UUID uuid){
325
		return modifierMap.get(uuid);
326
	}
327

    
328
	public void putModifier(DefinedTerm unit){
329
		modifierMap.put(unit.getUuid(), unit);
330
	}
331

    
332
	public TaxonRelationshipType getTaxonRelationshipType(UUID uuid){
333
		return taxonRelationshipTypeMap.get(uuid);
334
	}
335

    
336
	public void putTaxonRelationshipType(TaxonRelationshipType relType){
337
		taxonRelationshipTypeMap.put(relType.getUuid(), relType);
338
	}
339

    
340

    
341
	public PresenceAbsenceTerm getPresenceAbsenceTerm(UUID uuid){
342
		return presenceTermMap.get(uuid);
343
	}
344

    
345
	public void putPresenceAbsenceTerm(PresenceAbsenceTerm presenceTerm){
346
		presenceTermMap.put(presenceTerm.getUuid(), presenceTerm);
347
	}
348

    
349
	public Language getLanguage(UUID uuid){
350
		return languageMap.get(uuid);
351
	}
352

    
353
	public void putLanguage(Language language){
354
		languageMap.put(language.getUuid(), language);
355
	}
356

    
357

    
358
	public ReferenceSystem getReferenceSystem(UUID uuid){
359
		return referenceSystemMap.get(uuid);
360
	}
361

    
362
	public void putReferenceSystem(ReferenceSystem referenceSystem){
363
		referenceSystemMap.put(referenceSystem.getUuid(), referenceSystem);
364
	}
365

    
366

    
367
	//TODO make this abstract or find another way to force that the
368
	//transformer exists
369
	public IInputTransformer getTransformer(){
370
		return inputTransformer;
371
	}
372

    
373
	public void setTransformer(IInputTransformer transformer){
374
		this.inputTransformer = transformer;
375
	}
376

    
377
	/**
378
	 * Returns true, if this import is in validation state. Flase otherwise
379
	 * @return
380
	 */
381
	public boolean isCheck() {
382
		return isCheck;
383
	}
384

    
385
	/**
386
	 * @see #isCheck
387
	 * @param isCheck
388
	 */
389
	public void setCheck(boolean isCheck) {
390
		this.isCheck = isCheck;
391
	}
392

    
393
    /**
394
     * Returns the import report as a byte array
395
     * @return
396
     */
397
    public byte[] getReportAsByteArray() {
398
        return null;
399
    }
400

    
401

    
402
}
(42-42/59)