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