merge-update from trunk
[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 private boolean addMediaAsMediaSpecimen = false;
53 private boolean determinationOnFieldUnitLevel = false;
54
55
56 private final SpecimenUserInteraction specimenUserInteraction = new SpecimenUserInteraction();
57
58 private Map<String,UUID> namedAreaDecisions = new HashMap<String,UUID>();
59
60 //TODO
61 private static IInputTransformer defaultTransformer = null;
62
63 private URI sourceUri;
64
65
66 @Override
67 @SuppressWarnings("unchecked")
68 protected void makeIoClassList(){
69 System.out.println("makeIOClassList");
70 ioClassList = new Class[]{
71 Abcd206Import.class,
72 };
73 };
74
75 public static Abcd206ImportConfigurator NewInstance(URI uri,ICdmDataSource destination){
76 return new Abcd206ImportConfigurator(null, uri, destination, false);
77 }
78
79 /**
80 * @param uri
81 * @param object
82 * @param b
83 * @return
84 */
85 public static Abcd206ImportConfigurator NewInstance(URI uri, ICdmDataSource destination, boolean interact) {
86 return new Abcd206ImportConfigurator(null, uri, destination, interact);
87 }
88
89 /**
90 * @param uri
91 * @param object
92 * @param b
93 * @return
94 */
95 public static Abcd206ImportConfigurator NewInstance(InputStream stream, ICdmDataSource destination, boolean interact) {
96 return new Abcd206ImportConfigurator(stream, null, destination, interact);
97 }
98
99
100
101 /**
102 * @param berlinModelSource
103 * @param sourceReference
104 * @param destination
105 */
106 private Abcd206ImportConfigurator(InputStream stream, URI uri, ICdmDataSource destination, boolean interact) {
107 super(defaultTransformer);
108 if (stream != null){
109 setSource(stream);
110 }else{
111 this.sourceUri = uri;
112 }
113 setDestination(destination);
114 setSourceReferenceTitle("ABCD classic");
115 setInteractWithUser(interact);
116 }
117
118
119
120
121
122 /* (non-Javadoc)
123 * @see eu.etaxonomy.cdm.io.common.IImportConfigurator#getNewState()
124 */
125 @Override
126 public Abcd206ImportState getNewState() {
127 return new Abcd206ImportState(this);
128 }
129
130
131 @Override
132 public InputStream getSource(){
133 if (super.getSource() != null){
134 return super.getSource();
135 }else if (this.sourceUri != null){
136 try {
137 InputStream is = UriUtils.getInputStream(sourceUri);
138 setSource(is);
139 return is;
140 } catch (Exception e) {
141 throw new RuntimeException(e);
142 }
143 }else{
144 return null;
145 }
146 }
147
148 /**
149 * @param file
150 */
151 @Override
152 public void setSource(InputStream is) {
153 this.sourceUri = null;
154 super.setSource(is);
155 }
156
157 public URI getSourceUri(){
158 return this.sourceUri;
159 }
160
161 /**
162 * @param file
163 */
164 public void setSourceUri(URI sourceUri) {
165 this.sourceUri = sourceUri;
166 super.setSource(null);
167 }
168
169
170 @Override
171 public String getSourceReferenceTitle(){
172 return this.sourceReferenceTitle;
173 }
174
175 @Override
176 public void setSourceReferenceTitle(String name){
177 this.sourceReferenceTitle=name;
178 }
179
180 /* (non-Javadoc)
181 * @see eu.etaxonomy.cdm.io.common.ImportConfiguratorBase#getSourceReference()
182 */
183 @Override
184 public Reference getSourceReference() {
185 //TODO
186 return sourceReference;
187 }
188
189 public void setTaxonReference(String taxonReference) {
190 this.taxonReference = taxonReference;
191 }
192
193 public Reference getTaxonReference() {
194 //TODO
195 if (this.taxonReference == null){
196 logger.info("getTaxonReference not yet fully implemented");
197 }
198 return sourceReference;
199 }
200
201 public void setParseNameAutomatically(boolean doParsing){
202 this.parseNameAutomatically=doParsing;
203 }
204
205 public boolean isParseNameAutomatically(){
206 return this.parseNameAutomatically;
207 }
208
209 public void setReuseExistingMetadata(boolean reuseMetadata){
210 this.reuseExistingMetadata = reuseMetadata;
211 }
212
213 public boolean isReUseExistingMetadata(){
214 return this.reuseExistingMetadata;
215 }
216
217 public void setAddIndividualsAssociationsSuchAsSpecimenAndObservations(
218 boolean doCreateIndividualsAssociations) {
219 this.addIndividualsAssociationsSuchAsSpecimenAndObservations = doCreateIndividualsAssociations;
220 }
221
222 /**
223 * Create an IndividualsAssociations for each determination element in the ABCD data. ABCD has no such concept as IndividualsAssociations so the only way to
224 *
225 * @return
226 */
227 public boolean isAddIndividualsAssociationsSuchAsSpecimenAndObservations() {
228 return addIndividualsAssociationsSuchAsSpecimenAndObservations;
229 }
230
231 /**
232 * @param doReuseExistingDescription the doReuseExistingDescription to set
233 * NOT USED YET
234 */
235 public void reuseExistingDescriptiveGroups(boolean doReuseExistingDescription) {
236 this.reuseExistingDescriptiveGroups = doReuseExistingDescription;
237 }
238
239 /**
240 * @return the doReuseExistingDescription
241 */
242 public boolean isReuseExistingDescriptiveGroups() {
243 return reuseExistingDescriptiveGroups;
244 }
245
246 /* (non-Javadoc)
247 * @see eu.etaxonomy.cdm.io.common.IMatchingImportConfigurator#isDoMatchTaxa()
248 */
249 @Override
250 public boolean isReuseExistingTaxaWhenPossible() {
251 return reuseExistingTaxaWhenPossible;
252 }
253
254 /* (non-Javadoc)
255 * @see eu.etaxonomy.cdm.io.common.IMatchingImportConfigurator#setDoMatchTaxa(boolean)
256 */
257 @Override
258 public void setReuseExistingTaxaWhenPossible(boolean doMatchTaxa) {
259 this.reuseExistingTaxaWhenPossible = doMatchTaxa;
260 }
261
262 /**
263 * @return
264 */
265 public Map<UUID, UUID> getTaxonToDescriptionMap() {
266 // TODO Auto-generated method stub
267 return taxonToDescriptionMap ;
268 }
269
270
271
272 public Map<String, Team> getTeams() {
273 return titleCacheTeam;
274 }
275
276 public void setTeams(Map<String, Team> titleCacheTeam) {
277 this.titleCacheTeam = titleCacheTeam;
278 }
279
280 public Map<String, Person> getPersons() {
281 return titleCachePerson;
282 }
283
284 public void setPersons(Map<String, Person> titleCachePerson) {
285 this.titleCachePerson = titleCachePerson;
286 }
287
288 /**
289 * @param string
290 */
291 public void setDefaultAuthor(String string) {
292 defaultAuthor=string;
293
294 }
295
296 public String getDefaultAuthor(){
297 return defaultAuthor;
298 }
299
300 public Map<String,UUID> getNamedAreaDecisions() {
301 return namedAreaDecisions;
302 }
303
304 public void setNamedAreaDecisions(Map<String,UUID> namedAreaDecisions) {
305 this.namedAreaDecisions = namedAreaDecisions;
306 }
307
308 public void putNamedAreaDecision(String areaStr,UUID uuid){
309 this.namedAreaDecisions.put(areaStr,uuid);
310 }
311
312 public UUID getNamedAreaDecision(String areaStr){
313 return namedAreaDecisions.get(areaStr);
314 }
315
316 /**
317 * @return the doAddMediaAsMediaSpecimen
318 */
319 public boolean isAddMediaAsMediaSpecimen() {
320 return addMediaAsMediaSpecimen;
321 }
322
323 public void setAddMediaAsMediaSpecimen(boolean addMediaAsMediaSpecimen) {
324 this.addMediaAsMediaSpecimen = addMediaAsMediaSpecimen;
325 }
326
327 public boolean isDeterminationOnFieldUnitLevel() {
328 return determinationOnFieldUnitLevel;
329 }
330
331 public void setDeterminationOnFieldUnitLevel(boolean determinationOnFieldUnitLevel) {
332 this.determinationOnFieldUnitLevel = determinationOnFieldUnitLevel;
333 }
334
335 /**
336 * @return the allowReuseOtherClassifications
337 */
338 public boolean isAllowReuseOtherClassifications() {
339 return allowReuseOtherClassifications;
340 }
341
342 /**
343 * @param allowReuseOtherClassifications the allowReuseOtherClassifications to set
344 */
345 public void setAllowReuseOtherClassifications(boolean allowReuseOtherClassifications) {
346 this.allowReuseOtherClassifications = allowReuseOtherClassifications;
347 }
348
349 /**
350 * @return the specimenUserInteraction
351 */
352 public SpecimenUserInteraction getSpecimenUserInteraction() {
353 return specimenUserInteraction;
354 }
355
356
357
358
359 }