2 * Copyright (C) 2007 EDIT
3 * European Distributed Institute of Taxonomy
4 * http://www.e-taxonomy.eu
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.
9 package eu
.etaxonomy
.cdm
.io
.common
;
11 import java
.util
.HashMap
;
13 import java
.util
.UUID
;
15 import org
.apache
.log4j
.Logger
;
17 import eu
.etaxonomy
.cdm
.api
.service
.IService
;
18 import eu
.etaxonomy
.cdm
.io
.common
.mapping
.IInputTransformer
;
19 import eu
.etaxonomy
.cdm
.model
.common
.AnnotationType
;
20 import eu
.etaxonomy
.cdm
.model
.common
.CdmBase
;
21 import eu
.etaxonomy
.cdm
.model
.common
.ExtensionType
;
22 import eu
.etaxonomy
.cdm
.model
.common
.Language
;
23 import eu
.etaxonomy
.cdm
.model
.common
.MarkerType
;
24 import eu
.etaxonomy
.cdm
.model
.description
.Feature
;
25 import eu
.etaxonomy
.cdm
.model
.description
.MeasurementUnit
;
26 import eu
.etaxonomy
.cdm
.model
.description
.PresenceAbsenceTerm
;
27 import eu
.etaxonomy
.cdm
.model
.description
.State
;
28 import eu
.etaxonomy
.cdm
.model
.description
.StatisticalMeasure
;
29 import eu
.etaxonomy
.cdm
.model
.location
.NamedArea
;
30 import eu
.etaxonomy
.cdm
.model
.location
.NamedAreaLevel
;
31 import eu
.etaxonomy
.cdm
.model
.location
.ReferenceSystem
;
32 import eu
.etaxonomy
.cdm
.model
.name
.NomenclaturalStatusType
;
33 import eu
.etaxonomy
.cdm
.model
.name
.Rank
;
34 import eu
.etaxonomy
.cdm
.model
.reference
.Reference
;
35 import eu
.etaxonomy
.cdm
.model
.taxon
.Classification
;
36 import eu
.etaxonomy
.cdm
.model
.taxon
.TaxonRelationshipType
;
37 import eu
.etaxonomy
.cdm
.model
.term
.DefinedTerm
;
38 import eu
.etaxonomy
.cdm
.model
.term
.DefinedTermBase
;
39 import eu
.etaxonomy
.cdm
.model
.term
.TermVocabulary
;
45 public abstract class ImportStateBase
<CONFIG
extends ImportConfiguratorBase
, IO
extends CdmImportBase
>
46 extends IoStateBase
<CONFIG
, IO
, ImportResult
> {
48 @SuppressWarnings("unused")
49 private static final Logger logger
= Logger
.getLogger(ImportStateBase
.class);
52 private boolean success
= true;
55 private boolean isCheck
;
57 private Map
<Object
,Classification
> treeMap
= new HashMap
<>();
59 private Map
<Reference
,UUID
> treeUuidMap
= new HashMap
<>();
61 private Map
<String
,UUID
> classificationKeyUuidMap
= new HashMap
<>();
63 private Map
<String
, Object
> anyStatusItemMap
= new HashMap
<>();
65 private IInputTransformer inputTransformer
;
67 private Map
<UUID
, ExtensionType
> extensionTypeMap
= new HashMap
<>();
68 private Map
<UUID
, MarkerType
> markerTypeMap
= new HashMap
<>();
69 private Map
<UUID
, AnnotationType
> annotationTypeMap
= new HashMap
<>();
70 private Map
<UUID
, DefinedTerm
> identifierTypeMap
= new HashMap
<>();
72 private Map
<UUID
, NamedArea
> namedAreaMap
= new HashMap
<>();
73 private Map
<UUID
, NamedAreaLevel
> namedAreaLevelMap
= new HashMap
<>();
74 private Map
<UUID
, Feature
> featureMap
= new HashMap
<>();
75 private Map
<UUID
, State
> stateTermMap
= new HashMap
<>();
76 private Map
<UUID
, MeasurementUnit
> measurementUnitMap
= new HashMap
<>();
78 private Map
<UUID
, StatisticalMeasure
> statisticalMeasureMap
= new HashMap
<>();
79 private Map
<UUID
, DefinedTerm
> modifierMap
= new HashMap
<>();
81 private Map
<UUID
, PresenceAbsenceTerm
> presenceTermMap
= new HashMap
<>();
82 private Map
<UUID
, Language
> languageMap
= new HashMap
<>();
83 private Map
<UUID
, TaxonRelationshipType
> taxonRelationshipTypeMap
= new HashMap
<>();
85 private Map
<UUID
, ReferenceSystem
> referenceSystemMap
= new HashMap
<>();
86 private Map
<UUID
, Rank
> rankMap
= new HashMap
<>();
87 private Map
<UUID
, DefinedTerm
> kindOfUnitMap
= new HashMap
<>();
89 private Map
<UUID
, TermVocabulary
<?
>> termedVocabularyMap
= new HashMap
<>();
91 private Map
<UUID
, NomenclaturalStatusType
> nomenclaturalStatusTypeMap
= new HashMap
<>();
93 protected IService
<CdmBase
> service
= null;
95 protected ImportStateBase(CONFIG config
){
97 stores
.put(ICdmIO
.TEAM_STORE
, new MapWrapper
<>(service
));
98 stores
.put(ICdmIO
.REFERENCE_STORE
, new MapWrapper
<>(service
));
99 stores
.put(ICdmIO
.NOMREF_STORE
, new MapWrapper
<>(service
));
100 stores
.put(ICdmIO
.TAXONNAME_STORE
, new MapWrapper
<>(service
));
101 stores
.put(ICdmIO
.TAXON_STORE
, new MapWrapper
<>(service
));
102 stores
.put(ICdmIO
.SPECIMEN_STORE
, new MapWrapper
<>(service
));
104 if (getTransformer() == null){
105 IInputTransformer newTransformer
= config
.getTransformer();
106 // if (newTransformer == null){
107 // newTransformer = new DefaultTransf();
109 setTransformer(newTransformer
);
115 * Resets (empties) all maps which map a uuid to a {@link DefinedTermBase term}.
116 * This is usually needed when a a new transaction is opened and user defined terms are reused.
118 public void resetUuidTermMaps(){
119 extensionTypeMap
= new HashMap
<>();
120 markerTypeMap
= new HashMap
<>();
121 annotationTypeMap
= new HashMap
<>();
123 namedAreaMap
= new HashMap
<>();
124 namedAreaLevelMap
= new HashMap
<>();
125 featureMap
= new HashMap
<>();
126 stateTermMap
= new HashMap
<>();
127 measurementUnitMap
= new HashMap
<>();
128 statisticalMeasureMap
= new HashMap
<>();
129 modifierMap
= new HashMap
<>();
131 presenceTermMap
= new HashMap
<>();
132 languageMap
= new HashMap
<>();
133 taxonRelationshipTypeMap
= new HashMap
<>();
135 referenceSystemMap
= new HashMap
<>();
136 rankMap
= new HashMap
<>();
137 nomenclaturalStatusTypeMap
= new HashMap
<>();
140 //different type of stores that are used by the known imports
141 protected Map
<String
, MapWrapper
<?
extends CdmBase
>> stores
= new HashMap
<String
, MapWrapper
<?
extends CdmBase
>>();
143 public Map
<String
, MapWrapper
<?
extends CdmBase
>> getStores() {
146 public void setStores(Map
<String
, MapWrapper
<?
extends CdmBase
>> stores
) {
147 this.stores
= stores
;
149 public MapWrapper
<?
extends CdmBase
> getStore(String storeLabel
){
150 return stores
.get(storeLabel
);
153 public Classification
getTree(Object ref
) {
154 return treeMap
.get(ref
);
156 public void putTree(Object ref
, Classification tree
) {
158 this.treeMap
.put(ref
, tree
);
162 public int countTrees(){
163 return treeUuidMap
.size();
166 public UUID
getTreeUuid(Reference ref
) {
167 return treeUuidMap
.get(ref
);
170 public void putTreeUuid(Reference ref
, Classification tree
) {
171 if (tree
!= null && tree
.getUuid() != null){
172 this.treeUuidMap
.put(ref
, tree
.getUuid());
176 public int countTreeUuids(){
177 return treeUuidMap
.size();
182 * Adds a classification uuid to the classification uuid map,
183 * which maps a key for the classification to its UUID in the CDM
184 * @param classificationKeyId
185 * @param classification
187 public void putClassificationUuidInt(int classificationKeyId
, Classification classification
) {
188 putClassificationUuid(String
.valueOf(classificationKeyId
), classification
);
190 public void putClassificationUuid(String treeKey
, Classification tree
) {
191 if (tree
!= null && tree
.getUuid() != null){
192 this.classificationKeyUuidMap
.put(treeKey
, tree
.getUuid());
196 public UUID
getTreeUuidByIntTreeKey(int treeKey
) {
197 return classificationKeyUuidMap
.get(String
.valueOf(treeKey
));
199 public UUID
getTreeUuidByTreeKey(String treeKey
) {
200 return classificationKeyUuidMap
.get(treeKey
);
203 public DefinedTerm
getIdentifierType(UUID uuid
){
204 return identifierTypeMap
.get(uuid
);
206 public void putIdentifierType(DefinedTerm identifierType
){
207 identifierTypeMap
.put(identifierType
.getUuid(), identifierType
);
210 public ExtensionType
getExtensionType(UUID uuid
){
211 return extensionTypeMap
.get(uuid
);
213 public void putExtensionType(ExtensionType extensionType
){
214 extensionTypeMap
.put(extensionType
.getUuid(), extensionType
);
217 public MarkerType
getMarkerType(UUID uuid
){
218 return markerTypeMap
.get(uuid
);
220 public void putMarkerType(MarkerType markerType
){
221 markerTypeMap
.put(markerType
.getUuid(), markerType
);
224 public AnnotationType
getAnnotationType(UUID uuid
){
225 return annotationTypeMap
.get(uuid
);
227 public void putAnnotationType(AnnotationType annotationType
){
228 annotationTypeMap
.put(annotationType
.getUuid(), annotationType
);
231 public NamedArea
getNamedArea(UUID uuid
){
232 return namedAreaMap
.get(uuid
);
234 public void putNamedArea(NamedArea namedArea
){
235 namedAreaMap
.put(namedArea
.getUuid(), namedArea
);
238 public NamedAreaLevel
getNamedAreaLevel(UUID uuid
){
239 return namedAreaLevelMap
.get(uuid
);
241 public void putNamedAreaLevel(NamedAreaLevel namedAreaLevel
){
242 namedAreaLevelMap
.put(namedAreaLevel
.getUuid(), namedAreaLevel
);
245 public Rank
getRank(UUID uuid
){
246 return rankMap
.get(uuid
);
248 public void putRank(Rank rank
){
249 rankMap
.put(rank
.getUuid(), rank
);
252 public State
getStateTerm(UUID uuid
){
253 return stateTermMap
.get(uuid
);
255 public void putStateTerm(State stateTerm
){
256 stateTermMap
.put(stateTerm
.getUuid(), stateTerm
);
259 public Feature
getFeature(UUID uuid
){
260 return featureMap
.get(uuid
);
262 public void putFeature(Feature feature
){
263 featureMap
.put(feature
.getUuid(), feature
);
266 public NomenclaturalStatusType
getNomenclaturalStatusType(UUID uuid
){
267 return nomenclaturalStatusTypeMap
.get(uuid
);
269 public void putNomenclaturalStatusType(NomenclaturalStatusType feature
){
270 nomenclaturalStatusTypeMap
.put(feature
.getUuid(), feature
);
273 public DefinedTerm
getKindOfUnit(UUID uuid
){
274 return kindOfUnitMap
.get(uuid
);
276 public void putKindOfUnit(DefinedTerm unit
){
277 kindOfUnitMap
.put(unit
.getUuid(), unit
);
280 public MeasurementUnit
getMeasurementUnit(UUID uuid
){
281 return measurementUnitMap
.get(uuid
);
284 public void putMeasurementUnit(MeasurementUnit unit
){
285 measurementUnitMap
.put(unit
.getUuid(), unit
);
288 public void putStatisticalMeasure(StatisticalMeasure unit
){
289 statisticalMeasureMap
.put(unit
.getUuid(), unit
);
292 public StatisticalMeasure
getStatisticalMeasure(UUID uuid
){
293 return statisticalMeasureMap
.get(uuid
);
297 public DefinedTerm
getModifier(UUID uuid
){
298 return modifierMap
.get(uuid
);
301 public void putModifier(DefinedTerm unit
){
302 modifierMap
.put(unit
.getUuid(), unit
);
305 public TaxonRelationshipType
getTaxonRelationshipType(UUID uuid
){
306 return taxonRelationshipTypeMap
.get(uuid
);
309 public void putTaxonRelationshipType(TaxonRelationshipType relType
){
310 taxonRelationshipTypeMap
.put(relType
.getUuid(), relType
);
314 public PresenceAbsenceTerm
getPresenceAbsenceTerm(UUID uuid
){
315 return presenceTermMap
.get(uuid
);
318 public void putPresenceAbsenceTerm(PresenceAbsenceTerm presenceTerm
){
319 presenceTermMap
.put(presenceTerm
.getUuid(), presenceTerm
);
322 public Language
getLanguage(UUID uuid
){
323 return languageMap
.get(uuid
);
326 public void putLanguage(Language language
){
327 languageMap
.put(language
.getUuid(), language
);
331 public ReferenceSystem
getReferenceSystem(UUID uuid
){
332 return referenceSystemMap
.get(uuid
);
335 public void putReferenceSystem(ReferenceSystem referenceSystem
){
336 referenceSystemMap
.put(referenceSystem
.getUuid(), referenceSystem
);
340 public TermVocabulary
<?
> getTermedVocabulary(UUID uuid
) {
341 return termedVocabularyMap
.get(uuid
);
344 public void putTermedVocabularyMap(TermVocabulary
<?
> termedVocabulary
) {
345 this.termedVocabularyMap
.put(termedVocabulary
.getUuid(), termedVocabulary
);
349 public Object
getStatusItem(String key
){
350 return anyStatusItemMap
.get(key
);
353 public void putStatusItem(String key
, Object statusItem
){
354 anyStatusItemMap
.put(key
, statusItem
);
360 //TODO make this abstract or find another way to force that the
362 public IInputTransformer
getTransformer(){
363 return inputTransformer
;
366 public void setTransformer(IInputTransformer transformer
){
367 this.inputTransformer
= transformer
;
371 * Returns true, if this import is in validation state. False otherwise
374 public boolean isCheck() {
382 public void setCheck(boolean isCheck
) {
383 this.isCheck
= isCheck
;
387 public void setSuccess(boolean success
) {
388 this.success
= success
;
391 public void setUnsuccessfull(){
392 this.success
= false;
395 public boolean isSuccess() {
399 * Returns the import report as a byte array
402 public byte[] getReportAsByteArray() {