Project

General

Profile

Download (12.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
package eu.etaxonomy.cdm.io.common;
10

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

    
15
import org.apache.log4j.Logger;
16

    
17
import eu.etaxonomy.cdm.api.service.IService;
18
import eu.etaxonomy.cdm.io.common.mapping.IInputTransformer;
19
import eu.etaxonomy.cdm.io.common.utils.ImportDeduplicationHelper;
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.NomenclaturalStatusType;
34
import eu.etaxonomy.cdm.model.name.Rank;
35
import eu.etaxonomy.cdm.model.reference.Reference;
36
import eu.etaxonomy.cdm.model.taxon.Classification;
37
import eu.etaxonomy.cdm.model.taxon.TaxonRelationshipType;
38
import eu.etaxonomy.cdm.model.term.DefinedTerm;
39
import eu.etaxonomy.cdm.model.term.DefinedTermBase;
40
import eu.etaxonomy.cdm.model.term.TermVocabulary;
41

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

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

    
52
    private boolean success = true;
53

    
54
	private boolean isCheck;
55

    
56
    private ImportDeduplicationHelper deduplicationHelper;
57

    
58
	private Map<Object,Classification> treeMap = new HashMap<>();
59

    
60
	private Map<Reference,UUID> treeUuidMap = new HashMap<>();
61

    
62
	private Map<String,UUID> classificationKeyUuidMap = new HashMap<>();
63

    
64
	private Map<String, Object> anyStatusItemMap = new HashMap<>();
65

    
66
	private IInputTransformer inputTransformer;
67

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

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

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

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

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

    
90
	private Map<UUID, TermVocabulary<?>> termedVocabularyMap = new HashMap<>();
91

    
92
	private Map<UUID, NomenclaturalStatusType> nomenclaturalStatusTypeMap = new HashMap<>();
93

    
94
	protected IService<CdmBase> service = null;
95

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

    
105
		if (getTransformer() == null){
106
			IInputTransformer newTransformer = config.getTransformer();
107
//			if (newTransformer == null){
108
//				newTransformer = new DefaultTransf();
109
//			}
110
			setTransformer(newTransformer);
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 new transaction is opened and user defined terms are reused.
117
	 */
118
	public void resetUuidTermMaps(){
119
		extensionTypeMap = new HashMap<>();
120
		markerTypeMap = new HashMap<>();
121
		annotationTypeMap = new HashMap<>();
122

    
123
		namedAreaMap = new HashMap<>();
124
		namedAreaLevelMap = new HashMap<>();
125
		featureMap = new HashMap<>();
126
		stateTermMap = new HashMap<>();
127
		measurementUnitMap = new HashMap<>();
128
		statisticalMeasureMap = new HashMap<>();
129
		modifierMap = new HashMap<>();
130

    
131
		presenceTermMap = new HashMap<>();
132
		languageMap = new HashMap<>();
133
		taxonRelationshipTypeMap = new HashMap<>();
134

    
135
		referenceSystemMap = new HashMap<>();
136
		rankMap = new HashMap<>();
137
		nomenclaturalStatusTypeMap = new HashMap<>();
138
	}
139

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

    
143
	public Map<String, MapWrapper<? extends CdmBase>> getStores() {
144
		return stores;
145
	}
146
	public void setStores(Map<String, MapWrapper<? extends CdmBase>> stores) {
147
		this.stores = stores;
148
	}
149
 	public MapWrapper<? extends CdmBase> getStore(String storeLabel){
150
 		return stores.get(storeLabel);
151
 	}
152

    
153
	public Classification getTree(Object ref) {
154
		return treeMap.get(ref);
155
	}
156
	public void putTree(Object ref, Classification tree) {
157
		if (tree != null){
158
			this.treeMap.put(ref, tree);
159
		}
160
	}
161

    
162
	public int countTrees(){
163
		return treeUuidMap.size();
164
	}
165

    
166
	public UUID getTreeUuid(Reference ref) {
167
		return treeUuidMap.get(ref);
168
	}
169

    
170
	public void putTreeUuid(Reference ref, Classification tree) {
171
		if (tree != null &&  tree.getUuid() != null){
172
			this.treeUuidMap.put(ref, tree.getUuid());
173
		}
174
	}
175

    
176
	public int countTreeUuids(){
177
		return treeUuidMap.size();
178
	}
179

    
180
	/**
181
	 * Adds a classification uuid to the classification uuid map,
182
	 * which maps a key for the classification to its UUID in the CDM
183
	 * @param classificationKeyId
184
	 * @param classification
185
	 */
186
	public void putClassificationUuidInt(int classificationKeyId, Classification classification) {
187
		putClassificationUuid(String.valueOf(classificationKeyId), classification);
188
	}
189
	public void putClassificationUuid(String treeKey, Classification tree) {
190
		if (tree != null &&  tree.getUuid() != null){
191
			this.classificationKeyUuidMap.put(treeKey, tree.getUuid());
192
		}
193
	}
194

    
195
	public UUID getTreeUuidByIntTreeKey(int treeKey) {
196
		return classificationKeyUuidMap.get(String.valueOf(treeKey));
197
	}
198
	public UUID getTreeUuidByTreeKey(String treeKey) {
199
		return classificationKeyUuidMap.get(treeKey);
200
	}
201

    
202
	public DefinedTerm getIdentifierType(UUID uuid){
203
		return identifierTypeMap.get(uuid);
204
	}
205
	public void putIdentifierType(DefinedTerm identifierType){
206
		identifierTypeMap.put(identifierType.getUuid(), identifierType);
207
	}
208

    
209
	public ExtensionType getExtensionType(UUID uuid){
210
		return extensionTypeMap.get(uuid);
211
	}
212
	public void putExtensionType(ExtensionType extensionType){
213
		extensionTypeMap.put(extensionType.getUuid(), extensionType);
214
	}
215

    
216
	public MarkerType getMarkerType(UUID uuid){
217
		return markerTypeMap.get(uuid);
218
	}
219
	public void putMarkerType(MarkerType markerType){
220
		markerTypeMap.put(markerType.getUuid(), markerType);
221
	}
222

    
223
	public AnnotationType getAnnotationType(UUID uuid){
224
		return annotationTypeMap.get(uuid);
225
	}
226
	public void putAnnotationType(AnnotationType annotationType){
227
		annotationTypeMap.put(annotationType.getUuid(), annotationType);
228
	}
229

    
230
	public NamedArea getNamedArea(UUID uuid){
231
		return namedAreaMap.get(uuid);
232
	}
233
	public void putNamedArea(NamedArea namedArea){
234
		namedAreaMap.put(namedArea.getUuid(), namedArea);
235
	}
236

    
237
	public NamedAreaLevel getNamedAreaLevel(UUID uuid){
238
		return namedAreaLevelMap.get(uuid);
239
	}
240
	public void putNamedAreaLevel(NamedAreaLevel namedAreaLevel){
241
		namedAreaLevelMap.put(namedAreaLevel.getUuid(), namedAreaLevel);
242
	}
243

    
244
	public Rank getRank(UUID uuid){
245
		return rankMap.get(uuid);
246
	}
247
	public void putRank(Rank rank){
248
		rankMap.put(rank.getUuid(), rank);
249
	}
250

    
251
	public State getStateTerm(UUID uuid){
252
		return stateTermMap.get(uuid);
253
	}
254
	public void putStateTerm(State stateTerm){
255
		stateTermMap.put(stateTerm.getUuid(), stateTerm);
256
	}
257

    
258
	public Feature getFeature(UUID uuid){
259
		return featureMap.get(uuid);
260
	}
261
	public void putFeature(Feature feature){
262
		featureMap.put(feature.getUuid(), feature);
263
	}
264

    
265
	public NomenclaturalStatusType getNomenclaturalStatusType(UUID uuid){
266
        return nomenclaturalStatusTypeMap.get(uuid);
267
    }
268
    public void putNomenclaturalStatusType(NomenclaturalStatusType feature){
269
        nomenclaturalStatusTypeMap.put(feature.getUuid(), feature);
270
    }
271

    
272
	public DefinedTerm getKindOfUnit(UUID uuid){
273
		return kindOfUnitMap.get(uuid);
274
	}
275
	public void putKindOfUnit(DefinedTerm unit){
276
		kindOfUnitMap.put(unit.getUuid(), unit);
277
	}
278

    
279
	public MeasurementUnit getMeasurementUnit(UUID uuid){
280
		return measurementUnitMap.get(uuid);
281
	}
282

    
283
	public void putMeasurementUnit(MeasurementUnit unit){
284
		measurementUnitMap.put(unit.getUuid(), unit);
285
	}
286

    
287
	public void putStatisticalMeasure(StatisticalMeasure unit){
288
		statisticalMeasureMap.put(unit.getUuid(), unit);
289
	}
290

    
291
	public StatisticalMeasure getStatisticalMeasure(UUID uuid){
292
		return statisticalMeasureMap.get(uuid);
293
	}
294

    
295

    
296
	public DefinedTerm getModifier(UUID uuid){
297
		return modifierMap.get(uuid);
298
	}
299

    
300
	public void putModifier(DefinedTerm unit){
301
		modifierMap.put(unit.getUuid(), unit);
302
	}
303

    
304
	public TaxonRelationshipType getTaxonRelationshipType(UUID uuid){
305
		return taxonRelationshipTypeMap.get(uuid);
306
	}
307

    
308
	public void putTaxonRelationshipType(TaxonRelationshipType relType){
309
		taxonRelationshipTypeMap.put(relType.getUuid(), relType);
310
	}
311

    
312

    
313
	public PresenceAbsenceTerm getPresenceAbsenceTerm(UUID uuid){
314
		return presenceTermMap.get(uuid);
315
	}
316

    
317
	public void putPresenceAbsenceTerm(PresenceAbsenceTerm presenceTerm){
318
		presenceTermMap.put(presenceTerm.getUuid(), presenceTerm);
319
	}
320

    
321
	public Language getLanguage(UUID uuid){
322
		return languageMap.get(uuid);
323
	}
324

    
325
	public void putLanguage(Language language){
326
		languageMap.put(language.getUuid(), language);
327
	}
328

    
329

    
330
	public ReferenceSystem getReferenceSystem(UUID uuid){
331
		return referenceSystemMap.get(uuid);
332
	}
333

    
334
	public void putReferenceSystem(ReferenceSystem referenceSystem){
335
		referenceSystemMap.put(referenceSystem.getUuid(), referenceSystem);
336
	}
337

    
338

    
339
    public  TermVocabulary<?> getTermedVocabulary(UUID uuid) {
340
        return termedVocabularyMap.get(uuid);
341
    }
342

    
343
    public void putTermedVocabularyMap(TermVocabulary<?> termedVocabulary) {
344
        this.termedVocabularyMap.put(termedVocabulary.getUuid(), termedVocabulary);
345
    }
346

    
347

    
348
	public Object getStatusItem(String key){
349
        return anyStatusItemMap.get(key);
350
    }
351

    
352
    public void putStatusItem(String key, Object statusItem){
353
        anyStatusItemMap.put(key, statusItem);
354
    }
355

    
356

    
357

    
358

    
359
	//TODO make this abstract or find another way to force that the
360
	//transformer exists
361
	public IInputTransformer getTransformer(){
362
		return inputTransformer;
363
	}
364

    
365
	public void setTransformer(IInputTransformer transformer){
366
		this.inputTransformer = transformer;
367
	}
368

    
369
	/**
370
	 * Returns true, if this import is in validation state. False otherwise
371
	 * @return
372
	 */
373
	public boolean isCheck() {
374
		return isCheck;
375
	}
376

    
377
	/**
378
	 * @see #isCheck
379
	 * @param isCheck
380
	 */
381
	public void setCheck(boolean isCheck) {
382
		this.isCheck = isCheck;
383
	}
384

    
385

    
386
    public void setSuccess(boolean success) {
387
        this.success = success;
388
    }
389

    
390
    public void setUnsuccessfull(){
391
        this.success = false;
392
    }
393

    
394
    public boolean isSuccess() {
395
        return success;
396
    }
397
    /**
398
     * Returns the import report as a byte array
399
     * @return
400
     */
401
    public byte[] getReportAsByteArray() {
402
        return null;
403
    }
404

    
405
    public ImportDeduplicationHelper getDeduplicationHelper() {
406
        return deduplicationHelper;
407
    }
408
    public void setDeduplicationHelper(ImportDeduplicationHelper deduplicationHelper) {
409
        this.deduplicationHelper = deduplicationHelper;
410
    }
411

    
412
    @Override
413
    public void setCurrentIO(IO currentIO) {
414
        super.setCurrentIO(currentIO);
415
        if (this.deduplicationHelper != null){
416
            this.deduplicationHelper.reset();
417
        }
418
        this.deduplicationHelper = currentIO.createDeduplicationHelper(this);
419
    }
420
}
(43-43/65)