3 * Copyright (C) 2007 EDIT
4 * European Distributed Institute of Taxonomy
5 * http://www.e-taxonomy.eu
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.
11 package eu
.etaxonomy
.cdm
.io
.common
;
13 import java
.util
.HashMap
;
15 import java
.util
.UUID
;
17 import org
.apache
.log4j
.Logger
;
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
;
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);
57 private boolean isCheck
;
59 private Map
<Object
,Classification
> treeMap
= new HashMap
<Object
,Classification
>();
61 private Map
<Reference
<?
>,UUID
> treeUuidMap
= new HashMap
<Reference
<?
>,UUID
>();
63 private Map
<String
,UUID
> classificationKeyUuidMap
= new HashMap
<String
,UUID
>();
65 private IInputTransformer inputTransformer
;
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
>();
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
>();
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
>();
84 private Map
<UUID
, ReferenceSystem
> referenceSystemMap
= new HashMap
<UUID
, ReferenceSystem
>();
85 private Map
<UUID
, Rank
> rankMap
= new HashMap
<UUID
, Rank
>();
87 protected IService
<CdmBase
> service
= null;
89 protected ImportStateBase(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
));
98 if (getTransformer() == null){
99 IInputTransformer newTransformer
= config
.getTransformer();
100 // if (newTransformer == null){
101 // newTransformer = new DefaultTransf();
103 setTransformer(newTransformer
);
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.
114 public void resetUuidTermMaps(){
115 extensionTypeMap
= new HashMap
<UUID
, ExtensionType
>();
116 markerTypeMap
= new HashMap
<UUID
, MarkerType
>();
117 annotationTypeMap
= new HashMap
<UUID
, AnnotationType
>();
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
>();
127 presenceTermMap
= new HashMap
<UUID
, PresenceTerm
>();;
128 languageMap
= new HashMap
<UUID
, Language
>();
129 taxonRelationshipTypeMap
= new HashMap
<UUID
, TaxonRelationshipType
>();
131 referenceSystemMap
= new HashMap
<UUID
, ReferenceSystem
>();
132 rankMap
= new HashMap
<UUID
, Rank
>();
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
>>();
143 public Map
<String
, MapWrapper
<?
extends CdmBase
>> getStores() {
148 * @param stores the stores to set
150 public void setStores(Map
<String
, MapWrapper
<?
extends CdmBase
>> stores
) {
151 this.stores
= stores
;
155 public MapWrapper
<?
extends CdmBase
> getStore(String storeLabel
){
156 return (MapWrapper
<?
extends CdmBase
>) stores
.get(storeLabel
);
161 * @return the treeMap
163 public Classification
getTree(Object ref
) {
164 return treeMap
.get(ref
);
168 * @param treeMap the treeMap to set
170 public void putTree(Object ref
, Classification tree
) {
172 this.treeMap
.put(ref
, tree
);
176 public int countTrees(){
177 return treeUuidMap
.size();
181 * @return the treeUuid
183 public UUID
getTreeUuid(Reference ref
) {
184 return treeUuidMap
.get(ref
);
187 public void putTreeUuid(Reference ref
, Classification tree
) {
188 if (tree
!= null && tree
.getUuid() != null){
189 this.treeUuidMap
.put(ref
, tree
.getUuid());
193 public int countTreeUuids(){
194 return treeUuidMap
.size();
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
204 public void putClassificationUuidInt(int classificationKeyId
, Classification classification
) {
205 putClassificationUuid(String
.valueOf(classificationKeyId
), classification
);
208 public void putClassificationUuid(String treeKey
, Classification tree
) {
209 if (tree
!= null && tree
.getUuid() != null){
210 this.classificationKeyUuidMap
.put(treeKey
, tree
.getUuid());
214 public UUID
getTreeUuidByIntTreeKey(int treeKey
) {
215 return classificationKeyUuidMap
.get(String
.valueOf(treeKey
));
218 public UUID
getTreeUuidByTreeKey(String treeKey
) {
219 return classificationKeyUuidMap
.get(treeKey
);
223 public ExtensionType
getExtensionType(UUID uuid
){
224 return extensionTypeMap
.get(uuid
);
227 public void putExtensionType(ExtensionType extensionType
){
228 extensionTypeMap
.put(extensionType
.getUuid(), extensionType
);
231 public MarkerType
getMarkerType(UUID uuid
){
232 return markerTypeMap
.get(uuid
);
235 public void putMarkerType(MarkerType markerType
){
236 markerTypeMap
.put(markerType
.getUuid(), markerType
);
239 public AnnotationType
getAnnotationType(UUID uuid
){
240 return annotationTypeMap
.get(uuid
);
243 public void putAnnotationType(AnnotationType annotationType
){
244 annotationTypeMap
.put(annotationType
.getUuid(), annotationType
);
247 public NamedArea
getNamedArea(UUID uuid
){
248 return namedAreaMap
.get(uuid
);
251 public void putNamedArea(NamedArea namedArea
){
252 namedAreaMap
.put(namedArea
.getUuid(), namedArea
);
255 public NamedAreaLevel
getNamedAreaLevel(UUID uuid
){
256 return namedAreaLevelMap
.get(uuid
);
260 public void putNamedAreaLevel(NamedAreaLevel namedAreaLevel
){
261 namedAreaLevelMap
.put(namedAreaLevel
.getUuid(), namedAreaLevel
);
264 public Rank
getRank(UUID uuid
){
265 return rankMap
.get(uuid
);
269 public void putRank(Rank rank
){
270 rankMap
.put(rank
.getUuid(), rank
);
273 public State
getStateTerm(UUID uuid
){
274 return stateTermMap
.get(uuid
);
277 public void putStateTerm(State stateTerm
){
278 stateTermMap
.put(stateTerm
.getUuid(), stateTerm
);
281 public Feature
getFeature(UUID uuid
){
282 return featureMap
.get(uuid
);
285 public void putFeature(Feature feature
){
286 featureMap
.put(feature
.getUuid(), feature
);
289 public MeasurementUnit
getMeasurementUnit(UUID uuid
){
290 return measurementUnitMap
.get(uuid
);
293 public void putStatisticalMeasure(StatisticalMeasure unit
){
294 statisticalMeasureMap
.put(unit
.getUuid(), unit
);
297 public StatisticalMeasure
getStatisticalMeasure(UUID uuid
){
298 return statisticalMeasureMap
.get(uuid
);
301 public void putMeasurementUnit(MeasurementUnit unit
){
302 measurementUnitMap
.put(unit
.getUuid(), unit
);
305 public DefinedTerm
getModifier(UUID uuid
){
306 return modifierMap
.get(uuid
);
309 public void putModifier(DefinedTerm unit
){
310 modifierMap
.put(unit
.getUuid(), unit
);
313 public TaxonRelationshipType
getTaxonRelationshipType(UUID uuid
){
314 return taxonRelationshipTypeMap
.get(uuid
);
317 public void putTaxonRelationshipType(TaxonRelationshipType relType
){
318 taxonRelationshipTypeMap
.put(relType
.getUuid(), relType
);
322 public PresenceTerm
getPresenceTerm(UUID uuid
){
323 return presenceTermMap
.get(uuid
);
326 public void putPresenceTerm(PresenceTerm presenceTerm
){
327 presenceTermMap
.put(presenceTerm
.getUuid(), presenceTerm
);
330 public Language
getLanguage(UUID uuid
){
331 return languageMap
.get(uuid
);
334 public void putLanguage(Language language
){
335 languageMap
.put(language
.getUuid(), language
);
339 public ReferenceSystem
getReferenceSystem(UUID uuid
){
340 return referenceSystemMap
.get(uuid
);
343 public void putReferenceSystem(ReferenceSystem referenceSystem
){
344 referenceSystemMap
.put(referenceSystem
.getUuid(), referenceSystem
);
348 //TODO make this abstract or find another way to force that the
350 public IInputTransformer
getTransformer(){
351 return inputTransformer
;
354 public void setTransformer(IInputTransformer transformer
){
355 this.inputTransformer
= transformer
;
359 * Returns true, if this import is in validation state. Flase otherwise
362 public boolean isCheck() {
370 public void setCheck(boolean isCheck
) {
371 this.isCheck
= isCheck
;