Merged from trunk to statistics branch
[cdmlib.git] / cdmlib-io / src / main / java / eu / etaxonomy / cdm / io / specimen / abcd206 / in / Abcd206ImportConfigurator.java
1 /**
2 * Copyright (C) 2007 EDIT
3 * European Distributed Institute of Taxonomy
4 * http://www.e-taxonomy.eu
5 *
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.
8 */
9
10 package eu.etaxonomy.cdm.io.specimen.abcd206.in;
11
12
13 import java.io.InputStream;
14 import java.net.URI;
15 import java.util.HashMap;
16 import java.util.Map;
17 import java.util.UUID;
18
19 import org.apache.log4j.Logger;
20
21 import eu.etaxonomy.cdm.common.UriUtils;
22 import eu.etaxonomy.cdm.database.ICdmDataSource;
23 import eu.etaxonomy.cdm.io.common.IImportConfigurator;
24 import eu.etaxonomy.cdm.io.common.IMatchingImportConfigurator;
25 import eu.etaxonomy.cdm.io.common.ImportConfiguratorBase;
26 import eu.etaxonomy.cdm.io.common.mapping.IInputTransformer;
27 import eu.etaxonomy.cdm.io.specimen.SpecimenUserInteraction;
28 import eu.etaxonomy.cdm.model.agent.Person;
29 import eu.etaxonomy.cdm.model.agent.Team;
30 import eu.etaxonomy.cdm.model.reference.Reference;
31
32 /**
33 * @author p.kelbert
34 * @created 20.10.2008
35 * @version 1.0
36 */
37 public class Abcd206ImportConfigurator extends ImportConfiguratorBase<Abcd206ImportState, InputStream> implements IImportConfigurator, IMatchingImportConfigurator {
38 private static final Logger logger = Logger.getLogger(Abcd206ImportConfigurator.class);
39
40 private static String sourceReferenceTitle = null;
41 private boolean parseNameAutomatically = false;
42 private boolean reuseExistingMetadata = true;
43 private String taxonReference = null;
44 private boolean addIndividualsAssociationsSuchAsSpecimenAndObservations = true;
45 private boolean reuseExistingDescriptiveGroups = false;
46 private boolean reuseExistingTaxaWhenPossible = true;
47 private final Map<UUID, UUID> taxonToDescriptionMap = new HashMap<UUID, UUID>();
48 private Map<String, Team> titleCacheTeam;
49 private Map<String, Person> titleCachePerson;
50 private String defaultAuthor="";
51 private boolean allowReuseOtherClassifications =true;
52
53
54 private final SpecimenUserInteraction specimenUserInteraction = new SpecimenUserInteraction();
55
56 private Map<String,UUID> namedAreaDecisions = new HashMap<String,UUID>();
57
58 //TODO
59 private static IInputTransformer defaultTransformer = null;
60
61 private URI sourceUri;
62
63 @Override
64 @SuppressWarnings("unchecked")
65 protected void makeIoClassList(){
66 System.out.println("makeIOClassList");
67 ioClassList = new Class[]{
68 Abcd206Import.class,
69 };
70 };
71
72 public static Abcd206ImportConfigurator NewInstance(URI uri,ICdmDataSource destination){
73 return new Abcd206ImportConfigurator(null, uri, destination, false);
74 }
75
76 /**
77 * @param uri
78 * @param object
79 * @param b
80 * @return
81 */
82 public static Abcd206ImportConfigurator NewInstance(URI uri, ICdmDataSource destination, boolean interact) {
83 return new Abcd206ImportConfigurator(null, uri, destination, interact);
84 }
85
86 /**
87 * @param uri
88 * @param object
89 * @param b
90 * @return
91 */
92 public static Abcd206ImportConfigurator NewInstance(InputStream stream, ICdmDataSource destination, boolean interact) {
93 return new Abcd206ImportConfigurator(stream, null, destination, interact);
94 }
95
96
97
98 /**
99 * @param berlinModelSource
100 * @param sourceReference
101 * @param destination
102 */
103 private Abcd206ImportConfigurator(InputStream stream, URI uri, ICdmDataSource destination, boolean interact) {
104 super(defaultTransformer);
105 if (stream != null){
106 setSource(stream);
107 }else{
108 this.sourceUri = uri;
109 }
110 setDestination(destination);
111 setSourceReferenceTitle("ABCD classic");
112 setInteractWithUser(interact);
113 }
114
115
116
117
118
119 /* (non-Javadoc)
120 * @see eu.etaxonomy.cdm.io.common.IImportConfigurator#getNewState()
121 */
122 @Override
123 public Abcd206ImportState getNewState() {
124 return new Abcd206ImportState(this);
125 }
126
127
128 @Override
129 public InputStream getSource(){
130 if (super.getSource() != null){
131 return super.getSource();
132 }else if (this.sourceUri != null){
133 try {
134 InputStream is = UriUtils.getInputStream(sourceUri);
135 setSource(is);
136 return is;
137 } catch (Exception e) {
138 throw new RuntimeException(e);
139 }
140 }else{
141 return null;
142 }
143 }
144
145 /**
146 * @param file
147 */
148 @Override
149 public void setSource(InputStream is) {
150 this.sourceUri = null;
151 super.setSource(is);
152 }
153
154 public URI getSourceUri(){
155 return this.sourceUri;
156 }
157
158 /**
159 * @param file
160 */
161 public void setSourceUri(URI sourceUri) {
162 this.sourceUri = sourceUri;
163 super.setSource(null);
164 }
165
166
167 @Override
168 public String getSourceReferenceTitle(){
169 return this.sourceReferenceTitle;
170 }
171
172 @Override
173 public void setSourceReferenceTitle(String name){
174 this.sourceReferenceTitle=name;
175 }
176
177 /* (non-Javadoc)
178 * @see eu.etaxonomy.cdm.io.common.ImportConfiguratorBase#getSourceReference()
179 */
180 @Override
181 public Reference getSourceReference() {
182 //TODO
183 return sourceReference;
184 }
185
186 public void setTaxonReference(String taxonReference) {
187 this.taxonReference = taxonReference;
188 }
189
190 public Reference getTaxonReference() {
191 //TODO
192 if (this.taxonReference == null){
193 logger.info("getTaxonReference not yet fully implemented");
194 }
195 return sourceReference;
196 }
197
198 public void setParseNameAutomatically(boolean doParsing){
199 this.parseNameAutomatically=doParsing;
200 }
201
202 public boolean isParseNameAutomatically(){
203 return this.parseNameAutomatically;
204 }
205
206 public void setReuseExistingMetadata(boolean reuseMetadata){
207 this.reuseExistingMetadata = reuseMetadata;
208 }
209
210 public boolean isReUseExistingMetadata(){
211 return this.reuseExistingMetadata;
212 }
213
214 public void setAddIndividualsAssociationsSuchAsSpecimenAndObservations(
215 boolean doCreateIndividualsAssociations) {
216 this.addIndividualsAssociationsSuchAsSpecimenAndObservations = doCreateIndividualsAssociations;
217 }
218
219 /**
220 * Create an IndividualsAssociations for each determination element in the ABCD data. ABCD has no such concept as IndividualsAssociations so the only way to
221 *
222 * @return
223 */
224 public boolean isAddIndividualsAssociationsSuchAsSpecimenAndObservations() {
225 return addIndividualsAssociationsSuchAsSpecimenAndObservations;
226 }
227
228 /**
229 * @param doReuseExistingDescription the doReuseExistingDescription to set
230 * NOT USED YET
231 */
232 public void reuseExistingDescriptiveGroups(boolean doReuseExistingDescription) {
233 this.reuseExistingDescriptiveGroups = doReuseExistingDescription;
234 }
235
236 /**
237 * @return the doReuseExistingDescription
238 */
239 public boolean isReuseExistingDescriptiveGroups() {
240 return reuseExistingDescriptiveGroups;
241 }
242
243 /* (non-Javadoc)
244 * @see eu.etaxonomy.cdm.io.common.IMatchingImportConfigurator#isDoMatchTaxa()
245 */
246 @Override
247 public boolean isReuseExistingTaxaWhenPossible() {
248 return reuseExistingTaxaWhenPossible;
249 }
250
251 /* (non-Javadoc)
252 * @see eu.etaxonomy.cdm.io.common.IMatchingImportConfigurator#setDoMatchTaxa(boolean)
253 */
254 @Override
255 public void setReuseExistingTaxaWhenPossible(boolean doMatchTaxa) {
256 this.reuseExistingTaxaWhenPossible = doMatchTaxa;
257 }
258
259 /**
260 * @return
261 */
262 public Map<UUID, UUID> getTaxonToDescriptionMap() {
263 // TODO Auto-generated method stub
264 return taxonToDescriptionMap ;
265 }
266
267
268
269 public Map<String, Team> getTeams() {
270 return titleCacheTeam;
271 }
272
273 public void setTeams(Map<String, Team> titleCacheTeam) {
274 this.titleCacheTeam = titleCacheTeam;
275 }
276
277 public Map<String, Person> getPersons() {
278 return titleCachePerson;
279 }
280
281 public void setPersons(Map<String, Person> titleCachePerson) {
282 this.titleCachePerson = titleCachePerson;
283 }
284
285 /**
286 * @param string
287 */
288 public void setDefaultAuthor(String string) {
289 defaultAuthor=string;
290
291 }
292
293 public String getDefaultAuthor(){
294 return defaultAuthor;
295 }
296
297 public Map<String,UUID> getNamedAreaDecisions() {
298 return namedAreaDecisions;
299 }
300
301 public void setNamedAreaDecisions(Map<String,UUID> namedAreaDecisions) {
302 this.namedAreaDecisions = namedAreaDecisions;
303 }
304
305 public void putNamedAreaDecision(String areaStr,UUID uuid){
306 this.namedAreaDecisions.put(areaStr,uuid);
307 }
308
309 public UUID getNamedAreaDecision(String areaStr){
310 return namedAreaDecisions.get(areaStr);
311 }
312
313
314 /**
315 * @return the allowReuseOtherClassifications
316 */
317 public boolean isAllowReuseOtherClassifications() {
318 return allowReuseOtherClassifications;
319 }
320
321 /**
322 * @param allowReuseOtherClassifications the allowReuseOtherClassifications to set
323 */
324 public void setAllowReuseOtherClassifications(boolean allowReuseOtherClassifications) {
325 this.allowReuseOtherClassifications = allowReuseOtherClassifications;
326 }
327
328 /**
329 * @return the specimenUserInteraction
330 */
331 public SpecimenUserInteraction getSpecimenUserInteraction() {
332 return specimenUserInteraction;
333 }
334
335
336
337
338 }