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.agent.TeamOrPersonBase;
|
21
|
import eu.etaxonomy.cdm.model.common.AnnotationType;
|
22
|
import eu.etaxonomy.cdm.model.common.CdmBase;
|
23
|
import eu.etaxonomy.cdm.model.common.DefinedTerm;
|
24
|
import eu.etaxonomy.cdm.model.common.DefinedTermBase;
|
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.description.Feature;
|
29
|
import eu.etaxonomy.cdm.model.description.MeasurementUnit;
|
30
|
import eu.etaxonomy.cdm.model.description.PresenceAbsenceTerm;
|
31
|
import eu.etaxonomy.cdm.model.description.State;
|
32
|
import eu.etaxonomy.cdm.model.description.StatisticalMeasure;
|
33
|
import eu.etaxonomy.cdm.model.location.NamedArea;
|
34
|
import eu.etaxonomy.cdm.model.location.NamedAreaLevel;
|
35
|
import eu.etaxonomy.cdm.model.location.ReferenceSystem;
|
36
|
import eu.etaxonomy.cdm.model.name.Rank;
|
37
|
import eu.etaxonomy.cdm.model.name.TaxonNameBase;
|
38
|
import eu.etaxonomy.cdm.model.occurrence.DerivedUnit;
|
39
|
import eu.etaxonomy.cdm.model.reference.Reference;
|
40
|
import eu.etaxonomy.cdm.model.taxon.Classification;
|
41
|
import eu.etaxonomy.cdm.model.taxon.TaxonBase;
|
42
|
import eu.etaxonomy.cdm.model.taxon.TaxonRelationshipType;
|
43
|
|
44
|
/**
|
45
|
* @author a.mueller
|
46
|
* @created 11.05.2009
|
47
|
*/
|
48
|
public abstract class ImportStateBase<CONFIG extends ImportConfiguratorBase, IO extends CdmImportBase> extends IoStateBase<CONFIG, IO> {
|
49
|
@SuppressWarnings("unused")
|
50
|
private static final Logger logger = Logger.getLogger(ImportStateBase.class);
|
51
|
|
52
|
//States
|
53
|
private boolean isCheck;
|
54
|
|
55
|
private Map<Object,Classification> treeMap = new HashMap<Object,Classification>();
|
56
|
|
57
|
private Map<Reference,UUID> treeUuidMap = new HashMap<Reference,UUID>();
|
58
|
|
59
|
private Map<String,UUID> classificationKeyUuidMap = new HashMap<String,UUID>();
|
60
|
|
61
|
private IInputTransformer inputTransformer;
|
62
|
|
63
|
|
64
|
private Map<UUID, ExtensionType> extensionTypeMap = new HashMap<UUID, ExtensionType>();
|
65
|
private Map<UUID, MarkerType> markerTypeMap = new HashMap<UUID, MarkerType>();
|
66
|
private Map<UUID, AnnotationType> annotationTypeMap = new HashMap<UUID, AnnotationType>();
|
67
|
private Map<UUID, DefinedTerm> identifierTypeMap = new HashMap<UUID, DefinedTerm>();
|
68
|
|
69
|
private Map<UUID, NamedArea> namedAreaMap = new HashMap<UUID, NamedArea>();
|
70
|
private Map<UUID, NamedAreaLevel> namedAreaLevelMap = new HashMap<UUID, NamedAreaLevel>();
|
71
|
private Map<UUID, Feature> featureMap = new HashMap<UUID, Feature>();
|
72
|
private Map<UUID, State> stateTermMap = new HashMap<UUID, State>();
|
73
|
private Map<UUID, MeasurementUnit> measurementUnitMap = new HashMap<UUID, MeasurementUnit>();
|
74
|
|
75
|
private Map<UUID, StatisticalMeasure> statisticalMeasureMap = new HashMap<UUID, StatisticalMeasure>();
|
76
|
private Map<UUID, DefinedTerm> modifierMap = new HashMap<UUID, DefinedTerm>();
|
77
|
|
78
|
private Map<UUID, PresenceAbsenceTerm> presenceTermMap = new HashMap<UUID, PresenceAbsenceTerm>();
|
79
|
private Map<UUID, Language> languageMap = new HashMap<UUID, Language>();
|
80
|
private Map<UUID, TaxonRelationshipType> taxonRelationshipTypeMap = new HashMap<UUID, TaxonRelationshipType>();
|
81
|
|
82
|
private Map<UUID, ReferenceSystem> referenceSystemMap = new HashMap<UUID, ReferenceSystem>();
|
83
|
private Map<UUID, Rank> rankMap = new HashMap<UUID, Rank>();
|
84
|
private Map<UUID, DefinedTerm> kindOfUnitMap = new HashMap<UUID, DefinedTerm>();
|
85
|
|
86
|
|
87
|
|
88
|
protected IService<CdmBase> service = null;
|
89
|
|
90
|
protected ImportStateBase(CONFIG config){
|
91
|
this.config = config;
|
92
|
stores.put(ICdmIO.TEAM_STORE, new MapWrapper<TeamOrPersonBase<?>>(service));
|
93
|
stores.put(ICdmIO.REFERENCE_STORE, new MapWrapper<Reference>(service));
|
94
|
stores.put(ICdmIO.NOMREF_STORE, new MapWrapper<Reference>(service));
|
95
|
stores.put(ICdmIO.TAXONNAME_STORE, new MapWrapper<TaxonNameBase<?,?>>(service));
|
96
|
stores.put(ICdmIO.TAXON_STORE, new MapWrapper<TaxonBase>(service));
|
97
|
stores.put(ICdmIO.SPECIMEN_STORE, new MapWrapper<DerivedUnit>(service));
|
98
|
|
99
|
if (getTransformer() == null){
|
100
|
IInputTransformer newTransformer = config.getTransformer();
|
101
|
// if (newTransformer == null){
|
102
|
// newTransformer = new DefaultTransf();
|
103
|
// }
|
104
|
setTransformer(newTransformer);
|
105
|
}
|
106
|
|
107
|
}
|
108
|
|
109
|
|
110
|
|
111
|
/**
|
112
|
* Resets (empties) all maps which map a uuid to a {@link DefinedTermBase term}.
|
113
|
* This is usually needed when a a new transaction is opened and user defined terms are reused.
|
114
|
*/
|
115
|
public void resetUuidTermMaps(){
|
116
|
extensionTypeMap = new HashMap<UUID, ExtensionType>();
|
117
|
markerTypeMap = new HashMap<UUID, MarkerType>();
|
118
|
annotationTypeMap = new HashMap<UUID, AnnotationType>();
|
119
|
|
120
|
namedAreaMap = new HashMap<UUID, NamedArea>();
|
121
|
namedAreaLevelMap = new HashMap<UUID, NamedAreaLevel>();
|
122
|
featureMap = new HashMap<UUID, Feature>();
|
123
|
stateTermMap = new HashMap<UUID, State>();
|
124
|
measurementUnitMap = new HashMap<UUID, MeasurementUnit>();
|
125
|
statisticalMeasureMap = new HashMap<UUID, StatisticalMeasure>();
|
126
|
modifierMap = new HashMap<UUID, DefinedTerm>();
|
127
|
|
128
|
presenceTermMap = new HashMap<UUID, PresenceAbsenceTerm>();;
|
129
|
languageMap = new HashMap<UUID, Language>();
|
130
|
taxonRelationshipTypeMap = new HashMap<UUID, TaxonRelationshipType>();
|
131
|
|
132
|
referenceSystemMap = new HashMap<UUID, ReferenceSystem>();
|
133
|
rankMap = new HashMap<UUID, Rank>();
|
134
|
}
|
135
|
|
136
|
|
137
|
//different type of stores that are used by the known imports
|
138
|
protected Map<String, MapWrapper<? extends CdmBase>> stores = new HashMap<String, MapWrapper<? extends CdmBase>>();
|
139
|
|
140
|
|
141
|
/**
|
142
|
* @return the stores
|
143
|
*/
|
144
|
public Map<String, MapWrapper<? extends CdmBase>> getStores() {
|
145
|
return stores;
|
146
|
}
|
147
|
|
148
|
/**
|
149
|
* @param stores the stores to set
|
150
|
*/
|
151
|
public void setStores(Map<String, MapWrapper<? extends CdmBase>> stores) {
|
152
|
this.stores = stores;
|
153
|
}
|
154
|
|
155
|
|
156
|
public MapWrapper<? extends CdmBase> getStore(String storeLabel){
|
157
|
return stores.get(storeLabel);
|
158
|
}
|
159
|
|
160
|
|
161
|
/**
|
162
|
* @return the treeMap
|
163
|
*/
|
164
|
public Classification getTree(Object ref) {
|
165
|
return treeMap.get(ref);
|
166
|
}
|
167
|
|
168
|
/**
|
169
|
* @param treeMap the treeMap to set
|
170
|
*/
|
171
|
public void putTree(Object ref, Classification tree) {
|
172
|
if (tree != null){
|
173
|
this.treeMap.put(ref, tree);
|
174
|
}
|
175
|
}
|
176
|
|
177
|
public int countTrees(){
|
178
|
return treeUuidMap.size();
|
179
|
}
|
180
|
|
181
|
/**
|
182
|
* @return the treeUuid
|
183
|
*/
|
184
|
public UUID getTreeUuid(Reference ref) {
|
185
|
return treeUuidMap.get(ref);
|
186
|
}
|
187
|
|
188
|
public void putTreeUuid(Reference ref, Classification tree) {
|
189
|
if (tree != null && tree.getUuid() != null){
|
190
|
this.treeUuidMap.put(ref, tree.getUuid());
|
191
|
}
|
192
|
}
|
193
|
|
194
|
public int countTreeUuids(){
|
195
|
return treeUuidMap.size();
|
196
|
}
|
197
|
|
198
|
|
199
|
/**
|
200
|
* Adds a classification uuid to the classification uuid map,
|
201
|
* which maps a key for the classification to its UUID in the CDM
|
202
|
* @param classificationKeyId
|
203
|
* @param classification
|
204
|
*/
|
205
|
public void putClassificationUuidInt(int classificationKeyId, Classification classification) {
|
206
|
putClassificationUuid(String.valueOf(classificationKeyId), classification);
|
207
|
}
|
208
|
|
209
|
public void putClassificationUuid(String treeKey, Classification tree) {
|
210
|
if (tree != null && tree.getUuid() != null){
|
211
|
this.classificationKeyUuidMap.put(treeKey, tree.getUuid());
|
212
|
}
|
213
|
}
|
214
|
|
215
|
public UUID getTreeUuidByIntTreeKey(int treeKey) {
|
216
|
return classificationKeyUuidMap.get(String.valueOf(treeKey));
|
217
|
}
|
218
|
|
219
|
public UUID getTreeUuidByTreeKey(String treeKey) {
|
220
|
return classificationKeyUuidMap.get(treeKey);
|
221
|
}
|
222
|
|
223
|
|
224
|
public DefinedTerm getIdentifierType(UUID uuid){
|
225
|
return identifierTypeMap.get(uuid);
|
226
|
}
|
227
|
|
228
|
public void putIdentifierType(DefinedTerm identifierType){
|
229
|
identifierTypeMap.put(identifierType.getUuid(), identifierType);
|
230
|
}
|
231
|
|
232
|
public ExtensionType getExtensionType(UUID uuid){
|
233
|
return extensionTypeMap.get(uuid);
|
234
|
}
|
235
|
|
236
|
public void putExtensionType(ExtensionType extensionType){
|
237
|
extensionTypeMap.put(extensionType.getUuid(), extensionType);
|
238
|
}
|
239
|
|
240
|
public MarkerType getMarkerType(UUID uuid){
|
241
|
return markerTypeMap.get(uuid);
|
242
|
}
|
243
|
|
244
|
public void putMarkerType(MarkerType markerType){
|
245
|
markerTypeMap.put(markerType.getUuid(), markerType);
|
246
|
}
|
247
|
|
248
|
public AnnotationType getAnnotationType(UUID uuid){
|
249
|
return annotationTypeMap.get(uuid);
|
250
|
}
|
251
|
|
252
|
public void putAnnotationType(AnnotationType annotationType){
|
253
|
annotationTypeMap.put(annotationType.getUuid(), annotationType);
|
254
|
}
|
255
|
|
256
|
public NamedArea getNamedArea(UUID uuid){
|
257
|
return namedAreaMap.get(uuid);
|
258
|
}
|
259
|
|
260
|
public void putNamedArea(NamedArea namedArea){
|
261
|
namedAreaMap.put(namedArea.getUuid(), namedArea);
|
262
|
}
|
263
|
|
264
|
public NamedAreaLevel getNamedAreaLevel(UUID uuid){
|
265
|
return namedAreaLevelMap.get(uuid);
|
266
|
}
|
267
|
|
268
|
|
269
|
public void putNamedAreaLevel(NamedAreaLevel namedAreaLevel){
|
270
|
namedAreaLevelMap.put(namedAreaLevel.getUuid(), namedAreaLevel);
|
271
|
}
|
272
|
|
273
|
public Rank getRank(UUID uuid){
|
274
|
return rankMap.get(uuid);
|
275
|
}
|
276
|
|
277
|
|
278
|
public void putRank(Rank rank){
|
279
|
rankMap.put(rank.getUuid(), rank);
|
280
|
}
|
281
|
|
282
|
public State getStateTerm(UUID uuid){
|
283
|
return stateTermMap.get(uuid);
|
284
|
}
|
285
|
|
286
|
public void putStateTerm(State stateTerm){
|
287
|
stateTermMap.put(stateTerm.getUuid(), stateTerm);
|
288
|
}
|
289
|
|
290
|
public Feature getFeature(UUID uuid){
|
291
|
return featureMap.get(uuid);
|
292
|
}
|
293
|
|
294
|
public void putFeature(Feature feature){
|
295
|
featureMap.put(feature.getUuid(), feature);
|
296
|
}
|
297
|
|
298
|
public DefinedTerm getKindOfUnit(UUID uuid){
|
299
|
return kindOfUnitMap.get(uuid);
|
300
|
}
|
301
|
|
302
|
public void putKindOfUnit(DefinedTerm unit){
|
303
|
kindOfUnitMap.put(unit.getUuid(), unit);
|
304
|
}
|
305
|
|
306
|
public MeasurementUnit getMeasurementUnit(UUID uuid){
|
307
|
return measurementUnitMap.get(uuid);
|
308
|
}
|
309
|
|
310
|
public void putMeasurementUnit(MeasurementUnit unit){
|
311
|
measurementUnitMap.put(unit.getUuid(), unit);
|
312
|
}
|
313
|
|
314
|
public void putStatisticalMeasure(StatisticalMeasure unit){
|
315
|
statisticalMeasureMap.put(unit.getUuid(), unit);
|
316
|
}
|
317
|
|
318
|
public StatisticalMeasure getStatisticalMeasure(UUID uuid){
|
319
|
return statisticalMeasureMap.get(uuid);
|
320
|
}
|
321
|
|
322
|
|
323
|
public DefinedTerm getModifier(UUID uuid){
|
324
|
return modifierMap.get(uuid);
|
325
|
}
|
326
|
|
327
|
public void putModifier(DefinedTerm unit){
|
328
|
modifierMap.put(unit.getUuid(), unit);
|
329
|
}
|
330
|
|
331
|
public TaxonRelationshipType getTaxonRelationshipType(UUID uuid){
|
332
|
return taxonRelationshipTypeMap.get(uuid);
|
333
|
}
|
334
|
|
335
|
public void putTaxonRelationshipType(TaxonRelationshipType relType){
|
336
|
taxonRelationshipTypeMap.put(relType.getUuid(), relType);
|
337
|
}
|
338
|
|
339
|
|
340
|
public PresenceAbsenceTerm getPresenceAbsenceTerm(UUID uuid){
|
341
|
return presenceTermMap.get(uuid);
|
342
|
}
|
343
|
|
344
|
public void putPresenceAbsenceTerm(PresenceAbsenceTerm presenceTerm){
|
345
|
presenceTermMap.put(presenceTerm.getUuid(), presenceTerm);
|
346
|
}
|
347
|
|
348
|
public Language getLanguage(UUID uuid){
|
349
|
return languageMap.get(uuid);
|
350
|
}
|
351
|
|
352
|
public void putLanguage(Language language){
|
353
|
languageMap.put(language.getUuid(), language);
|
354
|
}
|
355
|
|
356
|
|
357
|
public ReferenceSystem getReferenceSystem(UUID uuid){
|
358
|
return referenceSystemMap.get(uuid);
|
359
|
}
|
360
|
|
361
|
public void putReferenceSystem(ReferenceSystem referenceSystem){
|
362
|
referenceSystemMap.put(referenceSystem.getUuid(), referenceSystem);
|
363
|
}
|
364
|
|
365
|
|
366
|
//TODO make this abstract or find another way to force that the
|
367
|
//transformer exists
|
368
|
public IInputTransformer getTransformer(){
|
369
|
return inputTransformer;
|
370
|
}
|
371
|
|
372
|
public void setTransformer(IInputTransformer transformer){
|
373
|
this.inputTransformer = transformer;
|
374
|
}
|
375
|
|
376
|
/**
|
377
|
* Returns true, if this import is in validation state. Flase otherwise
|
378
|
* @return
|
379
|
*/
|
380
|
public boolean isCheck() {
|
381
|
return isCheck;
|
382
|
}
|
383
|
|
384
|
/**
|
385
|
* @see #isCheck
|
386
|
* @param isCheck
|
387
|
*/
|
388
|
public void setCheck(boolean isCheck) {
|
389
|
this.isCheck = isCheck;
|
390
|
}
|
391
|
|
392
|
/**
|
393
|
* Returns the import report as a byte array
|
394
|
* @return
|
395
|
*/
|
396
|
public byte[] getReportAsByteArray() {
|
397
|
return null;
|
398
|
}
|
399
|
|
400
|
|
401
|
}
|