Project

General

Profile

Download (11.9 KB) Statistics
| Branch: | Tag: | Revision:
1
/**
2
* Copyright (C) 2007 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

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

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

    
16
import org.apache.log4j.Logger;
17

    
18
import eu.etaxonomy.cdm.api.service.IService;
19
import eu.etaxonomy.cdm.io.common.mapping.IInputTransformer;
20
import eu.etaxonomy.cdm.model.common.AnnotationType;
21
import eu.etaxonomy.cdm.model.common.CdmBase;
22
import eu.etaxonomy.cdm.model.common.ExtensionType;
23
import eu.etaxonomy.cdm.model.common.Language;
24
import eu.etaxonomy.cdm.model.common.MarkerType;
25
import eu.etaxonomy.cdm.model.description.Feature;
26
import eu.etaxonomy.cdm.model.description.MeasurementUnit;
27
import eu.etaxonomy.cdm.model.description.PresenceAbsenceTerm;
28
import eu.etaxonomy.cdm.model.description.State;
29
import eu.etaxonomy.cdm.model.description.StatisticalMeasure;
30
import eu.etaxonomy.cdm.model.location.NamedArea;
31
import eu.etaxonomy.cdm.model.location.NamedAreaLevel;
32
import eu.etaxonomy.cdm.model.location.ReferenceSystem;
33
import eu.etaxonomy.cdm.model.name.Rank;
34
import eu.etaxonomy.cdm.model.reference.Reference;
35
import eu.etaxonomy.cdm.model.taxon.Classification;
36
import eu.etaxonomy.cdm.model.taxon.TaxonRelationshipType;
37
import eu.etaxonomy.cdm.model.term.DefinedTerm;
38
import eu.etaxonomy.cdm.model.term.DefinedTermBase;
39

    
40
/**
41
 * @author a.mueller
42
 * @since 11.05.2009
43
 */
44
public abstract class ImportStateBase<CONFIG extends ImportConfiguratorBase, IO extends CdmImportBase>
45
        extends IoStateBase<CONFIG, IO, ImportResult> {
46

    
47
    @SuppressWarnings("unused")
48
	private static final Logger logger = Logger.getLogger(ImportStateBase.class);
49

    
50

    
51
    private boolean success = true;
52

    
53
	//States
54
	private boolean isCheck;
55

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

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

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

    
62
	private Map<String, Object> anyStatusItemMap = new HashMap<>();
63

    
64
	private IInputTransformer inputTransformer;
65

    
66

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

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

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

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

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

    
89

    
90

    
91
	protected IService<CdmBase> service = null;
92

    
93
	protected ImportStateBase(CONFIG config){
94
		this.config = config;
95
		stores.put(ICdmIO.TEAM_STORE, new MapWrapper<>(service));
96
		stores.put(ICdmIO.REFERENCE_STORE, new MapWrapper<>(service));
97
		stores.put(ICdmIO.NOMREF_STORE, new MapWrapper<>(service));
98
		stores.put(ICdmIO.TAXONNAME_STORE, new MapWrapper<>(service));
99
		stores.put(ICdmIO.TAXON_STORE, new MapWrapper<>(service));
100
		stores.put(ICdmIO.SPECIMEN_STORE, new MapWrapper<>(service));
101

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

    
110
	}
111

    
112

    
113

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

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

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

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

    
139

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

    
143

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

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

    
158

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

    
163

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

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

    
180
	public int countTrees(){
181
		return treeUuidMap.size();
182
	}
183

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

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

    
197
	public int countTreeUuids(){
198
		return treeUuidMap.size();
199
	}
200

    
201

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

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

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

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

    
226

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

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

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

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

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

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

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

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

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

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

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

    
271

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

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

    
280

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

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

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

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

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

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

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

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

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

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

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

    
325

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

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

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

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

    
342

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

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

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

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

    
359

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

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

    
368
	public Object getStatusItem(String key){
369
        return anyStatusItemMap.get(key);
370
    }
371

    
372
    public void putStatusItem(String key, Object statusItem){
373
        anyStatusItemMap.put(key, statusItem);
374
    }
375

    
376

    
377

    
378
	//TODO make this abstract or find another way to force that the
379
	//transformer exists
380
	public IInputTransformer getTransformer(){
381
		return inputTransformer;
382
	}
383

    
384
	public void setTransformer(IInputTransformer transformer){
385
		this.inputTransformer = transformer;
386
	}
387

    
388
	/**
389
	 * Returns true, if this import is in validation state. False otherwise
390
	 * @return
391
	 */
392
	public boolean isCheck() {
393
		return isCheck;
394
	}
395

    
396
	/**
397
	 * @see #isCheck
398
	 * @param isCheck
399
	 */
400
	public void setCheck(boolean isCheck) {
401
		this.isCheck = isCheck;
402
	}
403

    
404

    
405
    public void setSuccess(boolean success) {
406
        this.success = success;
407
    }
408

    
409
    public void setUnsuccessfull(){
410
        this.success = false;
411
    }
412

    
413
    public boolean isSuccess() {
414
        return success;
415
    }
416
    /**
417
     * Returns the import report as a byte array
418
     * @return
419
     */
420
    public byte[] getReportAsByteArray() {
421
        return null;
422
    }
423

    
424
}
(42-42/63)