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
.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
;
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);
53 private boolean isCheck
;
55 private Map
<Object
,Classification
> treeMap
= new HashMap
<Object
,Classification
>();
57 private Map
<Reference
<?
>,UUID
> treeUuidMap
= new HashMap
<Reference
<?
>,UUID
>();
59 private Map
<String
,UUID
> classificationKeyUuidMap
= new HashMap
<String
,UUID
>();
61 private IInputTransformer inputTransformer
;
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
>();
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
>();
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
>();
77 private Map
<UUID
, ReferenceSystem
> referenceSystemMap
= new HashMap
<UUID
, ReferenceSystem
>();
78 private Map
<UUID
, Rank
> rankMap
= new HashMap
<UUID
, Rank
>();
80 protected IService
<CdmBase
> service
= null;
82 protected ImportStateBase(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
));
95 if (getTransformer() == null){
96 IInputTransformer newTransformer
= config
.getTransformer();
97 // if (newTransformer == null){
98 // newTransformer = new DefaultTransf();
100 setTransformer(newTransformer
);
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
>>();
111 public Map
<String
, MapWrapper
<?
extends CdmBase
>> getStores() {
116 * @param stores the stores to set
118 public void setStores(Map
<String
, MapWrapper
<?
extends CdmBase
>> stores
) {
119 this.stores
= stores
;
123 public MapWrapper
<?
extends CdmBase
> getStore(String storeLabel
){
124 return (MapWrapper
<?
extends CdmBase
>) stores
.get(storeLabel
);
129 * @return the treeMap
131 public Classification
getTree(Object ref
) {
132 return treeMap
.get(ref
);
136 * @param treeMap the treeMap to set
138 public void putTree(Object ref
, Classification tree
) {
140 this.treeMap
.put(ref
, tree
);
144 public int countTrees(){
145 return treeUuidMap
.size();
149 * @return the treeUuid
151 public UUID
getTreeUuid(Reference ref
) {
152 return treeUuidMap
.get(ref
);
155 public void putTreeUuid(Reference ref
, Classification tree
) {
156 if (tree
!= null && tree
.getUuid() != null){
157 this.treeUuidMap
.put(ref
, tree
.getUuid());
161 public int countTreeUuids(){
162 return treeUuidMap
.size();
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
174 public void putClassificationUuidInt(int classificationKeyId
, Classification classification
) {
175 putClassificationUuid(String
.valueOf(classificationKeyId
), classification
);
178 public void putClassificationUuid(String treeKey
, Classification tree
) {
179 if (tree
!= null && tree
.getUuid() != null){
180 this.classificationKeyUuidMap
.put(treeKey
, tree
.getUuid());
184 public UUID
getTreeUuidByIntTreeKey(int treeKey
) {
185 return classificationKeyUuidMap
.get(String
.valueOf(treeKey
));
188 public UUID
getTreeUuidByTreeKey(String treeKey
) {
189 return classificationKeyUuidMap
.get(treeKey
);
193 public ExtensionType
getExtensionType(UUID uuid
){
194 return extensionTypeMap
.get(uuid
);
197 public void putExtensionType(ExtensionType extensionType
){
198 extensionTypeMap
.put(extensionType
.getUuid(), extensionType
);
201 public MarkerType
getMarkerType(UUID uuid
){
202 return markerTypeMap
.get(uuid
);
205 public void putMarkerType(MarkerType markerType
){
206 markerTypeMap
.put(markerType
.getUuid(), markerType
);
209 public AnnotationType
getAnnotationType(UUID uuid
){
210 return annotationTypeMap
.get(uuid
);
213 public void putAnnotationType(AnnotationType annotationType
){
214 annotationTypeMap
.put(annotationType
.getUuid(), annotationType
);
217 public NamedArea
getNamedArea(UUID uuid
){
218 return namedAreaMap
.get(uuid
);
221 public void putNamedArea(NamedArea namedArea
){
222 namedAreaMap
.put(namedArea
.getUuid(), namedArea
);
225 public NamedAreaLevel
getNamedAreaLevel(UUID uuid
){
226 return namedAreaLevelMap
.get(uuid
);
230 public void putNamedAreaLevel(NamedAreaLevel namedAreaLevel
){
231 namedAreaLevelMap
.put(namedAreaLevel
.getUuid(), namedAreaLevel
);
234 public Rank
getRank(UUID uuid
){
235 return rankMap
.get(uuid
);
239 public void putRank(Rank rank
){
240 rankMap
.put(rank
.getUuid(), rank
);
243 public State
getStateTerm(UUID uuid
){
244 return stateTermMap
.get(uuid
);
247 public void putStateTerm(State stateTerm
){
248 stateTermMap
.put(stateTerm
.getUuid(), stateTerm
);
251 public Feature
getFeature(UUID uuid
){
252 return featureMap
.get(uuid
);
255 public void putFeature(Feature feature
){
256 featureMap
.put(feature
.getUuid(), feature
);
259 public TaxonRelationshipType
getTaxonRelationshipType(UUID uuid
){
260 return taxonRelationshipTypeMap
.get(uuid
);
263 public void putTaxonRelationshipType(TaxonRelationshipType relType
){
264 taxonRelationshipTypeMap
.put(relType
.getUuid(), relType
);
268 public PresenceTerm
getPresenceTerm(UUID uuid
){
269 return presenceTermMap
.get(uuid
);
272 public void putPresenceTerm(PresenceTerm presenceTerm
){
273 presenceTermMap
.put(presenceTerm
.getUuid(), presenceTerm
);
276 public Language
getLanguage(UUID uuid
){
277 return languageMap
.get(uuid
);
280 public void putLanguage(Language language
){
281 languageMap
.put(language
.getUuid(), language
);
285 public ReferenceSystem
getReferenceSystem(UUID uuid
){
286 return referenceSystemMap
.get(uuid
);
289 public void putReferenceSystem(ReferenceSystem referenceSystem
){
290 referenceSystemMap
.put(referenceSystem
.getUuid(), referenceSystem
);
294 //TODO make this abstract or find another way to force that the
296 public IInputTransformer
getTransformer(){
297 return inputTransformer
;
300 public void setTransformer(IInputTransformer transformer
){
301 this.inputTransformer
= transformer
;
305 * Returns true, if this import is in validation state. Flase otherwise
308 public boolean isCheck() {
316 public void setCheck(boolean isCheck
) {
317 this.isCheck
= isCheck
;