Project

General

Profile

Download (6.08 KB) Statistics
| Branch: | Tag: | Revision:
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.model.agent.Person;
21
import eu.etaxonomy.cdm.model.agent.TeamOrPersonBase;
22
import eu.etaxonomy.cdm.model.common.AnnotationType;
23
import eu.etaxonomy.cdm.model.common.CdmBase;
24
import eu.etaxonomy.cdm.model.common.ExtensionType;
25
import eu.etaxonomy.cdm.model.common.MarkerType;
26
import eu.etaxonomy.cdm.model.common.User;
27
import eu.etaxonomy.cdm.model.description.Feature;
28
import eu.etaxonomy.cdm.model.location.NamedArea;
29
import eu.etaxonomy.cdm.model.name.TaxonNameBase;
30
import eu.etaxonomy.cdm.model.occurrence.Specimen;
31
import eu.etaxonomy.cdm.model.reference.ReferenceBase;
32
import eu.etaxonomy.cdm.model.taxon.TaxonBase;
33
import eu.etaxonomy.cdm.model.taxon.TaxonomicTree;
34

    
35
/**
36
 * @author a.mueller
37
 * @created 11.05.2009
38
 * @version 1.0
39
 */
40
public abstract class ImportStateBase<CONFIG extends ImportConfiguratorBase, IO extends CdmImportBase> extends IoStateBase<CONFIG, IO> {
41
	@SuppressWarnings("unused")
42
	private static final Logger logger = Logger.getLogger(ImportStateBase.class);
43
	
44
	private Map<Object,TaxonomicTree> treeMap = new HashMap<Object,TaxonomicTree>();
45

    
46
	private Map<ReferenceBase,UUID> treeUuidMap = new HashMap<ReferenceBase,UUID>();
47

    
48
	private Map<String,UUID> taxonomicTreeKeyUuidMap = new HashMap<String,UUID>();
49
	
50
	private Map<UUID, ExtensionType> extensionTypeMap = new HashMap<UUID, ExtensionType>();
51
	private Map<UUID, MarkerType> markerTypeMap = new HashMap<UUID, MarkerType>();
52
	private Map<UUID, AnnotationType> annotationTypeMap = new HashMap<UUID, AnnotationType>();
53
	
54
	private Map<UUID, NamedArea> namedAreaMap = new HashMap<UUID, NamedArea>();
55
	private Map<UUID, Feature> featureMap = new HashMap<UUID, Feature>();
56
	
57

    
58
	
59
	protected ImportStateBase(CONFIG config){
60
		this.config = config;
61
		stores.put(ICdmIO.USER_STORE, new MapWrapper<User>(service));
62
		stores.put(ICdmIO.PERSON_STORE, new MapWrapper<Person>(service));
63
		stores.put(ICdmIO.TEAM_STORE, new MapWrapper<TeamOrPersonBase<?>>(service));
64
		stores.put(ICdmIO.REFERENCE_STORE, new MapWrapper<ReferenceBase>(service));
65
		stores.put(ICdmIO.NOMREF_STORE, new MapWrapper<ReferenceBase>(service));
66
		stores.put(ICdmIO.NOMREF_DETAIL_STORE, new MapWrapper<ReferenceBase>(service));
67
		stores.put(ICdmIO.REF_DETAIL_STORE, new MapWrapper<ReferenceBase>(service));
68
		stores.put(ICdmIO.TAXONNAME_STORE, new MapWrapper<TaxonNameBase<?,?>>(service));
69
		stores.put(ICdmIO.TAXON_STORE, new MapWrapper<TaxonBase>(service));
70
		stores.put(ICdmIO.SPECIMEN_STORE, new MapWrapper<Specimen>(service));
71
	}
72
	
73
	//different type of stores that are used by the known imports
74
	protected Map<String, MapWrapper<? extends CdmBase>> stores = new HashMap<String, MapWrapper<? extends CdmBase>>();
75
	
76
	protected IService<CdmBase> service = null;
77

    
78
	/**
79
	 * @return the stores
80
	 */
81
	public Map<String, MapWrapper<? extends CdmBase>> getStores() {
82
		return stores;
83
	}
84

    
85
	/**
86
	 * @param stores the stores to set
87
	 */
88
	public void setStores(Map<String, MapWrapper<? extends CdmBase>> stores) {
89
		this.stores = stores;
90
	}
91

    
92

    
93
 	public MapWrapper<? extends CdmBase> getStore(String storeLabel){
94
 		return (MapWrapper<? extends CdmBase>) stores.get(storeLabel);
95
 	}
96
	
97

    
98
	/**
99
	 * @return the treeMap
100
	 */
101
	public TaxonomicTree getTree(Object ref) {
102
		return treeMap.get(ref);
103
	}
104

    
105
	/**
106
	 * @param treeMap the treeMap to set
107
	 */
108
	public void putTree(Object ref, TaxonomicTree tree) {
109
		if (tree != null){
110
			this.treeMap.put(ref, tree);
111
		}
112
	}
113
	
114
	public int countTrees(){
115
		return treeUuidMap.size();
116
	}
117
	
118
	/**
119
	 * @return the treeUuid
120
	 */
121
	public UUID getTreeUuid(ReferenceBase ref) {
122
		return treeUuidMap.get(ref);
123
	}
124

    
125
	public void putTreeUuid(ReferenceBase ref, TaxonomicTree tree) {
126
		if (tree != null &&  tree.getUuid() != null){
127
			this.treeUuidMap.put(ref, tree.getUuid());
128
		}
129
	}
130

    
131
	public int countTreeUuids(){
132
		return treeUuidMap.size();
133
	}
134

    
135
	
136
	
137
	
138
	/**
139
	 * Adds a taxonomic tree uuid to the taxonomic tree uuid map,
140
	 * which maps a key for the taxonomic tree to its UUID in the CDM
141
	 * @param treeKeyId
142
	 * @param tree
143
	 */
144
	public void putTaxonomicTreeUuidInt(int treeKeyId, TaxonomicTree tree) {
145
		putTaxonomicTreeUuid(String.valueOf(treeKeyId), tree);
146
	}
147

    
148
	public void putTaxonomicTreeUuid(String treeKey, TaxonomicTree tree) {
149
		if (tree != null &&  tree.getUuid() != null){
150
			this.taxonomicTreeKeyUuidMap.put(treeKey, tree.getUuid());
151
		}
152
	}
153
	
154
	public UUID getTreeUuidByIntTreeKey(int treeKey) {
155
		return taxonomicTreeKeyUuidMap.get(String.valueOf(treeKey));
156
	}
157
	
158
	public UUID getTreeUuidByTreeKey(String treeKey) {
159
		return taxonomicTreeKeyUuidMap.get(treeKey);
160
	}
161
	
162
	
163
	public ExtensionType getExtensionType(UUID uuid){
164
		return extensionTypeMap.get(uuid);
165
	}
166
	
167
	public void putExtensionType(ExtensionType extensionType){
168
		extensionTypeMap.put(extensionType.getUuid(), extensionType);
169
	}
170

    
171
	public MarkerType getMarkerType(UUID uuid){
172
		return markerTypeMap.get(uuid);
173
	}
174
	
175
	public void putMarkerType(MarkerType markerType){
176
		markerTypeMap.put(markerType.getUuid(), markerType);
177
	}
178
	
179
	public AnnotationType getAnnotationType(UUID uuid){
180
		return annotationTypeMap.get(uuid);
181
	}
182
	
183
	public void putAnnotationType(AnnotationType annotationType){
184
		annotationTypeMap.put(annotationType.getUuid(), annotationType);
185
	}
186
	
187
	public NamedArea getNamedArea(UUID uuid){
188
		return namedAreaMap.get(uuid);
189
	}
190
	
191
	public void putNamedArea(NamedArea namedArea){
192
		namedAreaMap.put(namedArea.getUuid(), namedArea);
193
	}
194

    
195
	
196
	public Feature getFeature(UUID uuid){
197
		return featureMap.get(uuid);
198
	}
199
	
200
	public void putFeature(Feature feature){
201
		featureMap.put(feature.getUuid(), feature);
202
	}
203
	
204

    
205
	
206
}
(29-29/41)