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