AlgaTerra categorical data and flat classifications
[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.ExtensionType;
26 import eu.etaxonomy.cdm.model.common.Language;
27 import eu.etaxonomy.cdm.model.common.MarkerType;
28 import eu.etaxonomy.cdm.model.common.User;
29 import eu.etaxonomy.cdm.model.description.Feature;
30 import eu.etaxonomy.cdm.model.description.PresenceTerm;
31 import eu.etaxonomy.cdm.model.description.State;
32 import eu.etaxonomy.cdm.model.location.NamedArea;
33 import eu.etaxonomy.cdm.model.location.NamedAreaLevel;
34 import eu.etaxonomy.cdm.model.location.ReferenceSystem;
35 import eu.etaxonomy.cdm.model.name.Rank;
36 import eu.etaxonomy.cdm.model.name.TaxonNameBase;
37 import eu.etaxonomy.cdm.model.occurrence.Specimen;
38 import eu.etaxonomy.cdm.model.reference.Reference;
39 import eu.etaxonomy.cdm.model.taxon.Classification;
40 import eu.etaxonomy.cdm.model.taxon.TaxonBase;
41 import eu.etaxonomy.cdm.model.taxon.TaxonRelationshipType;
42
43 /**
44 * @author a.mueller
45 * @created 11.05.2009
46 * @version 1.0
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
68 private Map<UUID, NamedArea> namedAreaMap = new HashMap<UUID, NamedArea>();
69 private Map<UUID, NamedAreaLevel> namedAreaLevelMap = new HashMap<UUID, NamedAreaLevel>();
70 private Map<UUID, Feature> featureMap = new HashMap<UUID, Feature>();
71 private Map<UUID, State> stateTermMap = new HashMap<UUID, State>();
72
73 private Map<UUID, PresenceTerm> presenceTermMap = new HashMap<UUID, PresenceTerm>();;
74 private Map<UUID, Language> languageMap = new HashMap<UUID, Language>();
75 private Map<UUID, TaxonRelationshipType> taxonRelationshipTypeMap = new HashMap<UUID, TaxonRelationshipType>();
76
77 private Map<UUID, ReferenceSystem> referenceSystemMap = new HashMap<UUID, ReferenceSystem>();
78 private Map<UUID, Rank> rankMap = new HashMap<UUID, Rank>();
79
80 protected IService<CdmBase> service = null;
81
82 protected ImportStateBase(CONFIG config){
83 this.config = config;
84 stores.put(ICdmIO.USER_STORE, new MapWrapper<User>(service));
85 stores.put(ICdmIO.PERSON_STORE, new MapWrapper<Person>(service));
86 stores.put(ICdmIO.TEAM_STORE, new MapWrapper<TeamOrPersonBase<?>>(service));
87 stores.put(ICdmIO.REFERENCE_STORE, new MapWrapper<Reference>(service));
88 stores.put(ICdmIO.NOMREF_STORE, new MapWrapper<Reference>(service));
89 stores.put(ICdmIO.NOMREF_DETAIL_STORE, new MapWrapper<Reference>(service));
90 stores.put(ICdmIO.REF_DETAIL_STORE, new MapWrapper<Reference>(service));
91 stores.put(ICdmIO.TAXONNAME_STORE, new MapWrapper<TaxonNameBase<?,?>>(service));
92 stores.put(ICdmIO.TAXON_STORE, new MapWrapper<TaxonBase>(service));
93 stores.put(ICdmIO.SPECIMEN_STORE, new MapWrapper<Specimen>(service));
94
95 if (getTransformer() == null){
96 IInputTransformer newTransformer = config.getTransformer();
97 // if (newTransformer == null){
98 // newTransformer = new DefaultTransf();
99 // }
100 setTransformer(newTransformer);
101 }
102 }
103
104 //different type of stores that are used by the known imports
105 protected Map<String, MapWrapper<? extends CdmBase>> stores = new HashMap<String, MapWrapper<? extends CdmBase>>();
106
107
108 /**
109 * @return the stores
110 */
111 public Map<String, MapWrapper<? extends CdmBase>> getStores() {
112 return stores;
113 }
114
115 /**
116 * @param stores the stores to set
117 */
118 public void setStores(Map<String, MapWrapper<? extends CdmBase>> stores) {
119 this.stores = stores;
120 }
121
122
123 public MapWrapper<? extends CdmBase> getStore(String storeLabel){
124 return (MapWrapper<? extends CdmBase>) stores.get(storeLabel);
125 }
126
127
128 /**
129 * @return the treeMap
130 */
131 public Classification getTree(Object ref) {
132 return treeMap.get(ref);
133 }
134
135 /**
136 * @param treeMap the treeMap to set
137 */
138 public void putTree(Object ref, Classification tree) {
139 if (tree != null){
140 this.treeMap.put(ref, tree);
141 }
142 }
143
144 public int countTrees(){
145 return treeUuidMap.size();
146 }
147
148 /**
149 * @return the treeUuid
150 */
151 public UUID getTreeUuid(Reference ref) {
152 return treeUuidMap.get(ref);
153 }
154
155 public void putTreeUuid(Reference ref, Classification tree) {
156 if (tree != null && tree.getUuid() != null){
157 this.treeUuidMap.put(ref, tree.getUuid());
158 }
159 }
160
161 public int countTreeUuids(){
162 return treeUuidMap.size();
163 }
164
165
166
167
168 /**
169 * Adds a classification uuid to the classification uuid map,
170 * which maps a key for the classification to its UUID in the CDM
171 * @param classificationKeyId
172 * @param classification
173 */
174 public void putClassificationUuidInt(int classificationKeyId, Classification classification) {
175 putClassificationUuid(String.valueOf(classificationKeyId), classification);
176 }
177
178 public void putClassificationUuid(String treeKey, Classification tree) {
179 if (tree != null && tree.getUuid() != null){
180 this.classificationKeyUuidMap.put(treeKey, tree.getUuid());
181 }
182 }
183
184 public UUID getTreeUuidByIntTreeKey(int treeKey) {
185 return classificationKeyUuidMap.get(String.valueOf(treeKey));
186 }
187
188 public UUID getTreeUuidByTreeKey(String treeKey) {
189 return classificationKeyUuidMap.get(treeKey);
190 }
191
192
193 public ExtensionType getExtensionType(UUID uuid){
194 return extensionTypeMap.get(uuid);
195 }
196
197 public void putExtensionType(ExtensionType extensionType){
198 extensionTypeMap.put(extensionType.getUuid(), extensionType);
199 }
200
201 public MarkerType getMarkerType(UUID uuid){
202 return markerTypeMap.get(uuid);
203 }
204
205 public void putMarkerType(MarkerType markerType){
206 markerTypeMap.put(markerType.getUuid(), markerType);
207 }
208
209 public AnnotationType getAnnotationType(UUID uuid){
210 return annotationTypeMap.get(uuid);
211 }
212
213 public void putAnnotationType(AnnotationType annotationType){
214 annotationTypeMap.put(annotationType.getUuid(), annotationType);
215 }
216
217 public NamedArea getNamedArea(UUID uuid){
218 return namedAreaMap.get(uuid);
219 }
220
221 public void putNamedArea(NamedArea namedArea){
222 namedAreaMap.put(namedArea.getUuid(), namedArea);
223 }
224
225 public NamedAreaLevel getNamedAreaLevel(UUID uuid){
226 return namedAreaLevelMap.get(uuid);
227 }
228
229
230 public void putNamedAreaLevel(NamedAreaLevel namedAreaLevel){
231 namedAreaLevelMap.put(namedAreaLevel.getUuid(), namedAreaLevel);
232 }
233
234 public Rank getRank(UUID uuid){
235 return rankMap.get(uuid);
236 }
237
238
239 public void putRank(Rank rank){
240 rankMap.put(rank.getUuid(), rank);
241 }
242
243 public State getStateTerm(UUID uuid){
244 return stateTermMap.get(uuid);
245 }
246
247 public void putStateTerm(State stateTerm){
248 stateTermMap.put(stateTerm.getUuid(), stateTerm);
249 }
250
251 public Feature getFeature(UUID uuid){
252 return featureMap.get(uuid);
253 }
254
255 public void putFeature(Feature feature){
256 featureMap.put(feature.getUuid(), feature);
257 }
258
259 public TaxonRelationshipType getTaxonRelationshipType(UUID uuid){
260 return taxonRelationshipTypeMap.get(uuid);
261 }
262
263 public void putTaxonRelationshipType(TaxonRelationshipType relType){
264 taxonRelationshipTypeMap.put(relType.getUuid(), relType);
265 }
266
267
268 public PresenceTerm getPresenceTerm(UUID uuid){
269 return presenceTermMap.get(uuid);
270 }
271
272 public void putPresenceTerm(PresenceTerm presenceTerm){
273 presenceTermMap.put(presenceTerm.getUuid(), presenceTerm);
274 }
275
276 public Language getLanguage(UUID uuid){
277 return languageMap.get(uuid);
278 }
279
280 public void putLanguage(Language language){
281 languageMap.put(language.getUuid(), language);
282 }
283
284
285 public ReferenceSystem getReferenceSystem(UUID uuid){
286 return referenceSystemMap.get(uuid);
287 }
288
289 public void putReferenceSystem(ReferenceSystem referenceSystem){
290 referenceSystemMap.put(referenceSystem.getUuid(), referenceSystem);
291 }
292
293
294 //TODO make this abstract or find another way to force that the
295 //transformer exists
296 public IInputTransformer getTransformer(){
297 return inputTransformer;
298 }
299
300 public void setTransformer(IInputTransformer transformer){
301 this.inputTransformer = transformer;
302 }
303
304 /**
305 * Returns true, if this import is in validation state. Flase otherwise
306 * @return
307 */
308 public boolean isCheck() {
309 return isCheck;
310 }
311
312 /**
313 * @see #isCheck
314 * @param isCheck
315 */
316 public void setCheck(boolean isCheck) {
317 this.isCheck = isCheck;
318 }
319
320
321 }