- added new config option "Move new taxa to default classification"
[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 @Deprecated
42 //FIXME what does this do?
43 private boolean parseNameAutomatically = false;
44 private boolean reuseExistingMetadata = true;
45 private String taxonReference = null;
46 private boolean addIndividualsAssociationsSuchAsSpecimenAndObservations = true;
47 private boolean reuseExistingDescriptiveGroups = false;
48 private boolean reuseExistingTaxaWhenPossible = true;
49 private final Map<UUID, UUID> taxonToDescriptionMap = new HashMap<UUID, UUID>();
50 private Map<String, Team> titleCacheTeam;
51 private Map<String, Person> titleCachePerson;
52 private String defaultAuthor="";
53 private boolean allowReuseOtherClassifications =true;
54 private boolean addMediaAsMediaSpecimen = false;
55 private boolean determinationOnFieldUnitLevel = false;
56 private boolean deduplicateReferences = false;
57 private boolean deduplicateClassifications = false;
58 private boolean ignoreAuthorship = false;
59 private boolean removeCountryFromLocalityText = false;
60 private boolean moveNewTaxaToDefaultClassification = false;
61
62 private boolean mapUnitIdToCatalogNumber = true;
63 private boolean mapUnitIdToAccessionNumber = false;
64 private boolean mapUnitIdToBarcode = false;
65
66 private final SpecimenUserInteraction specimenUserInteraction = new SpecimenUserInteraction();
67
68 private Map<String,UUID> namedAreaDecisions = new HashMap<String,UUID>();
69
70 //TODO
71 private static IInputTransformer defaultTransformer = null;
72
73 private URI sourceUri;
74 private URI reportUri;
75
76
77 @Override
78 @SuppressWarnings("unchecked")
79 protected void makeIoClassList(){
80 System.out.println("makeIOClassList");
81 ioClassList = new Class[]{
82 Abcd206Import.class,
83 };
84 };
85
86 public static Abcd206ImportConfigurator NewInstance(URI uri,ICdmDataSource destination){
87 return new Abcd206ImportConfigurator(null, uri, destination, false);
88 }
89
90 /**
91 * @param uri
92 * @param object
93 * @param b
94 * @return
95 */
96 public static Abcd206ImportConfigurator NewInstance(URI uri, ICdmDataSource destination, boolean interact) {
97 return new Abcd206ImportConfigurator(null, uri, destination, interact);
98 }
99
100 /**
101 * @param uri
102 * @param object
103 * @param b
104 * @return
105 */
106 public static Abcd206ImportConfigurator NewInstance(InputStream stream, ICdmDataSource destination, boolean interact) {
107 return new Abcd206ImportConfigurator(stream, null, destination, interact);
108 }
109
110
111
112 /**
113 * @param berlinModelSource
114 * @param sourceReference
115 * @param destination
116 */
117 private Abcd206ImportConfigurator(InputStream stream, URI uri, ICdmDataSource destination, boolean interact) {
118 super(defaultTransformer);
119 if (stream != null){
120 setSource(stream);
121 }else{
122 this.sourceUri = uri;
123 }
124 setDestination(destination);
125 setSourceReferenceTitle("ABCD classic");
126 setInteractWithUser(interact);
127 }
128
129
130
131
132
133 /* (non-Javadoc)
134 * @see eu.etaxonomy.cdm.io.common.IImportConfigurator#getNewState()
135 */
136 @Override
137 public Abcd206ImportState getNewState() {
138 return new Abcd206ImportState(this);
139 }
140
141
142 @Override
143 public InputStream getSource(){
144 if (super.getSource() != null){
145 return super.getSource();
146 }else if (this.sourceUri != null){
147 try {
148 InputStream is = UriUtils.getInputStream(sourceUri);
149 setSource(is);
150 return is;
151 } catch (Exception e) {
152 throw new RuntimeException(e);
153 }
154 }else{
155 return null;
156 }
157 }
158
159 /**
160 * @param file
161 */
162 @Override
163 public void setSource(InputStream is) {
164 this.sourceUri = null;
165 super.setSource(is);
166 }
167
168 public URI getSourceUri(){
169 return this.sourceUri;
170 }
171
172 /**
173 * @param file
174 */
175 public void setSourceUri(URI sourceUri) {
176 this.sourceUri = sourceUri;
177 super.setSource(null);
178 }
179
180
181 @Override
182 public String getSourceReferenceTitle(){
183 return this.sourceReferenceTitle;
184 }
185
186 @Override
187 public void setSourceReferenceTitle(String name){
188 this.sourceReferenceTitle=name;
189 }
190
191 /* (non-Javadoc)
192 * @see eu.etaxonomy.cdm.io.common.ImportConfiguratorBase#getSourceReference()
193 */
194 @Override
195 public Reference getSourceReference() {
196 //TODO
197 return sourceReference;
198 }
199
200 public void setTaxonReference(String taxonReference) {
201 this.taxonReference = taxonReference;
202 }
203
204 public Reference getTaxonReference() {
205 //TODO
206 if (this.taxonReference == null){
207 logger.info("getTaxonReference not yet fully implemented");
208 }
209 return sourceReference;
210 }
211 @Deprecated
212 public void setParseNameAutomatically(boolean doParsing){
213 this.parseNameAutomatically=doParsing;
214 }
215 @Deprecated
216 public boolean isParseNameAutomatically(){
217 return this.parseNameAutomatically;
218 }
219
220 public void setReuseExistingMetadata(boolean reuseMetadata){
221 this.reuseExistingMetadata = reuseMetadata;
222 }
223
224 public boolean isReUseExistingMetadata(){
225 return this.reuseExistingMetadata;
226 }
227
228 public void setAddIndividualsAssociationsSuchAsSpecimenAndObservations(
229 boolean doCreateIndividualsAssociations) {
230 this.addIndividualsAssociationsSuchAsSpecimenAndObservations = doCreateIndividualsAssociations;
231 }
232
233 /**
234 * Create an IndividualsAssociations for each determination element in the ABCD data. ABCD has no such concept as IndividualsAssociations so the only way to
235 *
236 * @return
237 */
238 public boolean isAddIndividualsAssociationsSuchAsSpecimenAndObservations() {
239 return addIndividualsAssociationsSuchAsSpecimenAndObservations;
240 }
241
242 /**
243 * @param doReuseExistingDescription the doReuseExistingDescription to set
244 * NOT USED YET
245 */
246 public void reuseExistingDescriptiveGroups(boolean doReuseExistingDescription) {
247 this.reuseExistingDescriptiveGroups = doReuseExistingDescription;
248 }
249
250 /**
251 * @return the doReuseExistingDescription
252 */
253 public boolean isReuseExistingDescriptiveGroups() {
254 return reuseExistingDescriptiveGroups;
255 }
256
257 /* (non-Javadoc)
258 * @see eu.etaxonomy.cdm.io.common.IMatchingImportConfigurator#isDoMatchTaxa()
259 */
260 @Override
261 public boolean isReuseExistingTaxaWhenPossible() {
262 return reuseExistingTaxaWhenPossible;
263 }
264
265 /* (non-Javadoc)
266 * @see eu.etaxonomy.cdm.io.common.IMatchingImportConfigurator#setDoMatchTaxa(boolean)
267 */
268 @Override
269 public void setReuseExistingTaxaWhenPossible(boolean doMatchTaxa) {
270 this.reuseExistingTaxaWhenPossible = doMatchTaxa;
271 }
272
273 /**
274 * @return
275 */
276 public Map<UUID, UUID> getTaxonToDescriptionMap() {
277 // TODO Auto-generated method stub
278 return taxonToDescriptionMap ;
279 }
280
281
282
283 public Map<String, Team> getTeams() {
284 return titleCacheTeam;
285 }
286
287 public void setTeams(Map<String, Team> titleCacheTeam) {
288 this.titleCacheTeam = titleCacheTeam;
289 }
290
291 public Map<String, Person> getPersons() {
292 return titleCachePerson;
293 }
294
295 public void setPersons(Map<String, Person> titleCachePerson) {
296 this.titleCachePerson = titleCachePerson;
297 }
298
299 /**
300 * @param string
301 */
302 public void setDefaultAuthor(String string) {
303 defaultAuthor=string;
304
305 }
306
307 public String getDefaultAuthor(){
308 return defaultAuthor;
309 }
310
311 public Map<String,UUID> getNamedAreaDecisions() {
312 return namedAreaDecisions;
313 }
314
315 public void setNamedAreaDecisions(Map<String,UUID> namedAreaDecisions) {
316 this.namedAreaDecisions = namedAreaDecisions;
317 }
318
319 public void putNamedAreaDecision(String areaStr,UUID uuid){
320 this.namedAreaDecisions.put(areaStr,uuid);
321 }
322
323 public UUID getNamedAreaDecision(String areaStr){
324 return namedAreaDecisions.get(areaStr);
325 }
326
327 /**
328 * @return the doAddMediaAsMediaSpecimen
329 */
330 public boolean isAddMediaAsMediaSpecimen() {
331 return addMediaAsMediaSpecimen;
332 }
333
334 public void setAddMediaAsMediaSpecimen(boolean addMediaAsMediaSpecimen) {
335 this.addMediaAsMediaSpecimen = addMediaAsMediaSpecimen;
336 }
337
338 public boolean isDeterminationOnFieldUnitLevel() {
339 return determinationOnFieldUnitLevel;
340 }
341
342 public void setDeterminationOnFieldUnitLevel(boolean determinationOnFieldUnitLevel) {
343 this.determinationOnFieldUnitLevel = determinationOnFieldUnitLevel;
344 }
345
346
347 public boolean isDeduplicateClassifications() {
348 return deduplicateClassifications;
349 }
350
351 public void setDeduplicateClassifications(boolean deduplicateClassifications) {
352 this.deduplicateClassifications = deduplicateClassifications;
353 }
354
355 public boolean isDeduplicateReferences() {
356 return deduplicateReferences;
357 }
358
359 public void setDeduplicateReferences(boolean deduplicateReferences) {
360 this.deduplicateReferences = deduplicateReferences;
361 }
362
363 public boolean isAllowReuseOtherClassifications() {
364 return allowReuseOtherClassifications;
365 }
366
367 public void setAllowReuseOtherClassifications(boolean allowReuseOtherClassifications) {
368 this.allowReuseOtherClassifications = allowReuseOtherClassifications;
369 }
370
371 public SpecimenUserInteraction getSpecimenUserInteraction() {
372 return specimenUserInteraction;
373 }
374
375 public void setReportUri(URI reportUri) {
376 this.reportUri = reportUri;
377 }
378
379 public URI getReportUri() {
380 return reportUri;
381 }
382
383 public void setIgnoreAuthorship(boolean ignoreAuthorship) {
384 this.ignoreAuthorship = ignoreAuthorship;
385 }
386
387 public boolean isIgnoreAuthorship() {
388 return ignoreAuthorship;
389 }
390
391 public boolean isMapUnitIdToAccessionNumber() {
392 return mapUnitIdToAccessionNumber;
393 }
394
395 public boolean isMapUnitIdToBarcode() {
396 return mapUnitIdToBarcode;
397 }
398
399 public boolean isMapUnitIdToCatalogNumber() {
400 return mapUnitIdToCatalogNumber;
401 }
402
403 public void setMapUnitIdToAccessionNumber(boolean mapUnitIdToAccessionNumber) {
404 this.mapUnitIdToAccessionNumber = mapUnitIdToAccessionNumber;
405 }
406
407 public void setMapUnitIdToBarcode(boolean mapUnitIdToBarcode) {
408 this.mapUnitIdToBarcode = mapUnitIdToBarcode;
409 }
410
411 public void setMapUnitIdToCatalogNumber(boolean mapUnitIdToCatalogNumber) {
412 this.mapUnitIdToCatalogNumber = mapUnitIdToCatalogNumber;
413 }
414
415 public void setRemoveCountryFromLocalityText(boolean removeCountryFromLocalityText) {
416 this.removeCountryFromLocalityText = removeCountryFromLocalityText;
417 }
418
419 public boolean isRemoveCountryFromLocalityText() {
420 return removeCountryFromLocalityText;
421 }
422
423 public boolean isMoveNewTaxaToDefaultClassification() {
424 return moveNewTaxaToDefaultClassification;
425 }
426
427 public void setMoveNewTaxaToDefaultClassification(boolean moveNewTaxaToDefaultClassification) {
428 this.moveNewTaxaToDefaultClassification = moveNewTaxaToDefaultClassification;
429 }
430
431 }