Project

General

Profile

Download (12.7 KB) Statistics
| Branch: | Tag: | Revision:
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.csv.redlist.demo;
11

    
12
import java.io.ByteArrayOutputStream;
13
import java.io.File;
14
import java.util.ArrayList;
15
import java.util.HashSet;
16
import java.util.List;
17
import java.util.Set;
18
import java.util.UUID;
19

    
20
import org.apache.log4j.Logger;
21

    
22
import eu.etaxonomy.cdm.database.ICdmDataSource;
23
import eu.etaxonomy.cdm.io.common.ExportResultType;
24
import eu.etaxonomy.cdm.io.common.XmlExportConfiguratorBase;
25
import eu.etaxonomy.cdm.io.common.mapping.out.IExportTransformer;
26
import eu.etaxonomy.cdm.model.description.Feature;
27
import eu.etaxonomy.cdm.model.location.NamedArea;
28

    
29

    
30
/**
31
 * @author a.oppermann
32
 * @since 17.10.2012
33
 */
34
public class CsvDemoExportConfigurator extends XmlExportConfiguratorBase<CsvDemoExportState> {
35

    
36
    private static final long serialVersionUID = -2622502140734437961L;
37

    
38
    @SuppressWarnings("unused")
39
	private static final Logger logger = Logger.getLogger(CsvDemoExportConfigurator.class);
40

    
41
	private String encoding = "UTF-8";
42
	private String linesTerminatedBy = "\r\n";
43
	private String fieldsEnclosedBy = "\"";
44
	private boolean hasHeaderLines = true;
45
	private String fieldsTerminatedBy=",";
46
	private boolean doTaxa = true;
47
	private boolean doDistributions = false;
48
	private ByteArrayOutputStream baos;
49
	private boolean isUseIdWherePossible = false;
50
	private boolean includeBasionymsInResourceRelations;
51
	private boolean includeMisappliedNamesInResourceRelations;
52
	private String defaultBibliographicCitation = null;
53
	private List<UUID> featureExclusions = new ArrayList<>();
54
	//filter on the classifications to be exported
55
	private Set<UUID> classificationUuids = new HashSet<>();
56
	private boolean withHigherClassification = false;
57
	private String setSeparator = ";";
58

    
59
	private boolean doGeographicalFilter = true;
60
	private boolean doDemoExport = false;
61
	private boolean doTaxonConceptExport = false;
62

    
63
	//attributes for export
64
	private boolean classification;
65
	private boolean taxonName;
66
	private boolean taxonNameID;
67
	private boolean author;
68
	private boolean rank;
69
	private boolean taxonStatus;
70
	private boolean taxonConceptID;
71
	private boolean synonyms;
72
	private boolean distributions;
73
	private boolean redlistFeatures;
74
	private boolean acceptedName;
75
	private boolean parentID;
76
	private boolean externalID;
77
	private boolean lastChange;
78

    
79
	private List<CsvDemoRecord> recordList;
80

    
81
	private List<Feature> features;
82
	private String classificationTitleCache;
83
	private List<NamedArea> areas;
84

    
85

    
86
    private Integer pageSize;
87

    
88
    private Integer pageNumber;
89

    
90
    private int taxonNodeListSize;
91

    
92

    
93
	//TODO
94
	private static IExportTransformer defaultTransformer = null;
95

    
96
	public static CsvDemoExportConfigurator NewInstance(ICdmDataSource source, File destinationFolder) {
97
	    return new CsvDemoExportConfigurator(source, destinationFolder);
98

    
99
	}
100

    
101
	@Override
102
	@SuppressWarnings("unchecked")
103
	protected void makeIoClassList() {
104
		ioClassList = new Class[] {
105
				CsvDemoExport.class
106
		};
107
	}
108

    
109

    
110
	/**
111
	 * This function is only to have a shortcut for
112
	 * a preselection for available fields. One can still
113
	 * select fields manually.
114
	 * <p><p>
115
	 * Only one of the parameter should be true, otherwise
116
	 * all fields are set to true and will be exported.
117
	 * <p><p>
118
	 * In future this function might be removed.
119
	 *
120
	 *
121
	 * @param doDemoExport
122
	 * @param doTaxonConceptExport
123
	 */
124
	public void createPreSelectedExport(boolean doDemoExport, boolean doTaxonConceptExport){
125
		if(doDemoExport){
126
			setDoDemoExport(true);
127
			setClassification(true);
128
			setTaxonName(true);
129
			setTaxonNameID(true);
130
			setTaxonStatus(true);
131
			setSynonyms(true);
132
			setDistributions(true);
133
			setRedlistFeatures(true);
134
		}else if(doTaxonConceptExport){
135
			setDoTaxonConceptExport(true);
136
			setTaxonName(true);
137
			setAuthor(true);
138
			setRank(true);
139
			setTaxonConceptID(true);
140
			setParentID(true);
141
			setExternalID(true);
142
			setLastChange(true);
143
		}
144
	}
145

    
146

    
147

    
148
	/**
149
	 * @param url
150
	 * @param destination
151
	 */
152
	private CsvDemoExportConfigurator(ICdmDataSource source, File destination) {
153
		super(destination, source, defaultTransformer);
154
		this.resultType = ExportResultType.BYTE_ARRAY;
155
	}
156

    
157
	@Override
158
	public File getDestination() {
159
		return super.getDestination();
160
	}
161

    
162
	/**
163
	 * @param file
164
	 */
165
	@Override
166
	public void setDestination(File fileName) {
167
		super.setDestination(fileName);
168
	}
169

    
170
	@Override
171
	public String getDestinationNameString() {
172
		if (this.getDestination() == null) {
173
			return null;
174
		} else {
175
			return this.getDestination().toString();
176
		}
177
	}
178

    
179
	@Override
180
    public CsvDemoExportState getNewState() {
181
		return new CsvDemoExportState(this);
182
	}
183

    
184
	public boolean isDoTaxa() {
185
		return doTaxa;
186
	}
187

    
188
	public void setDoTaxa(boolean doTaxa) {
189
		this.doTaxa = doTaxa;
190
	}
191

    
192

    
193
	public boolean isDoDistributions() {
194
		return doDistributions;
195
	}
196

    
197
	public void setDoDistributions(boolean doDistributions) {
198
		this.doDistributions = doDistributions;
199
	}
200

    
201
	public void setFeatureExclusions(List<UUID> featureExclusions) {
202
		this.featureExclusions = featureExclusions;
203
	}
204

    
205
	public List<UUID> getFeatureExclusions() {
206
		return featureExclusions;
207
	}
208

    
209
	public String getEncoding() {
210
		return encoding;
211
	}
212

    
213
	public void setEncoding(String encoding) {
214
		this.encoding = encoding;
215
	}
216

    
217
	public String getLinesTerminatedBy() {
218
		return linesTerminatedBy;
219
	}
220

    
221
	public void setLinesTerminatedBy(String linesTerminatedBy) {
222
		this.linesTerminatedBy = linesTerminatedBy;
223
	}
224

    
225
	public String getFieldsEnclosedBy() {
226
		return fieldsEnclosedBy;
227
	}
228

    
229
	public void setFieldsEnclosedBy(String fieldsEnclosedBy) {
230
		this.fieldsEnclosedBy = fieldsEnclosedBy;
231
	}
232

    
233
	/**
234
	 * Equals darwin core archive ignoreHeaderLines attribute
235
	 * @return
236
	 */
237
	public boolean isHasHeaderLines() {
238
		return hasHeaderLines;
239
	}
240

    
241
	public void setHasHeaderLines(boolean hasHeaderLines) {
242
		this.hasHeaderLines = hasHeaderLines;
243
	}
244

    
245
	public boolean isIncludeBasionymsInResourceRelations() {
246
		return includeBasionymsInResourceRelations;
247
	}
248

    
249
	public void setIncludeBasionymsInResourceRelations(boolean includeBasionymsInResourceRelations) {
250
		this.includeBasionymsInResourceRelations = includeBasionymsInResourceRelations;
251
	}
252

    
253
	public boolean isIncludeMisappliedNamesInResourceRelations() {
254
		return includeMisappliedNamesInResourceRelations;
255
	}
256

    
257
	public void setIncludeMisappliedNamesInResourceRelations(boolean includeMisappliedNamesInResourceRelations) {
258
		this.includeMisappliedNamesInResourceRelations = includeMisappliedNamesInResourceRelations;
259
	}
260

    
261
	public boolean isUseIdWherePossible() {
262
		return this.isUseIdWherePossible;
263
	}
264

    
265
	public void setUseIdWherePossible(boolean isUseIdWherePossible) {
266
		this.isUseIdWherePossible = isUseIdWherePossible;
267
	}
268

    
269
	public void setDefaultBibliographicCitation(String defaultBibliographicCitation) {
270
		this.defaultBibliographicCitation = defaultBibliographicCitation;
271
	}
272

    
273

    
274
	public String getDefaultBibliographicCitation() {
275
		return defaultBibliographicCitation;
276
	}
277

    
278
	/**
279
	 * The default value for the taxon.source column. This may be a column linking to a url that provides
280
	 * data about the given taxon. The id is replaced by a placeholder,
281
	 * e.g. http://wp6-cichorieae.e-taxonomy.eu/portal/?q=cdm_dataportal/taxon/{id}.
282
	 * NOTE: This may be replaced in future versions by concrete CDM server implementations.
283
	 *
284
	 * @return the taxonSourceDefault
285
	 */
286

    
287
	public boolean isWithHigherClassification() {
288
		return withHigherClassification;
289
	}
290

    
291
	public void setWithHigherClassification(boolean withHigherClassification) {
292
		this.withHigherClassification = withHigherClassification;
293
	}
294

    
295
	/**
296
	 * @return the setSeparator
297
	 */
298
	public String getSetSeparator() {
299
		return setSeparator;
300
	}
301

    
302
	/**
303
	 * @param setSeparator the setSeparator to set
304
	 */
305
	public void setSetSeparator(String setSeparator) {
306
		this.setSeparator = setSeparator;
307
	}
308

    
309
	public void setFieldsTerminatedBy(String fieldsTerminatedBy) {
310
		this.fieldsTerminatedBy = fieldsTerminatedBy;
311
	}
312

    
313
	public String getFieldsTerminatedBy() {
314
		return fieldsTerminatedBy;
315
	}
316

    
317
	public Set<UUID> getClassificationUuids() {
318
		return classificationUuids;
319
	}
320

    
321
	public void setClassificationUuids(Set<UUID> classificationUuids) {
322
		this.classificationUuids = classificationUuids;
323
	}
324

    
325
	public ByteArrayOutputStream getByteArrayOutputStream() {
326
		return baos;
327
	}
328

    
329
	public void setByteArrayOutputStream(ByteArrayOutputStream baos) {
330
		this.baos = baos;
331
	}
332

    
333
	public void setFeatures(List<Feature> features) {
334
		this.features = features;
335

    
336
	}
337

    
338
	public List<Feature>  getFeatures() {
339
		return features;
340

    
341
	}
342

    
343
	public void setClassificationTitleCache(String classificationTitleCache) {
344
		this.classificationTitleCache = classificationTitleCache;
345
	}
346

    
347
	public String getClassificationTitleCache() {
348
		return classificationTitleCache;
349
	}
350

    
351
	/**
352
	 * @param areas
353
	 */
354
	public void setNamedAreas(List<NamedArea> areas) {
355
		// TODO Auto-generated method stub
356
		this.areas = areas;
357

    
358
	}
359
	public List<NamedArea> getNamedAreas(){
360
		return areas;
361
	}
362

    
363
	public boolean isDoGeographicalFilter() {
364
		return doGeographicalFilter;
365
	}
366

    
367
	public void setDoGeographicalFilter(boolean doGeographicalFilter) {
368
		this.doGeographicalFilter = doGeographicalFilter;
369
	}
370

    
371
	public boolean isDoDemoExport() {
372
		return doDemoExport;
373
	}
374

    
375
	public void setDoDemoExport(boolean doDemoHeadlines) {
376
		this.doDemoExport = doDemoHeadlines;
377
	}
378

    
379

    
380
	public boolean isDoTaxonConceptExport() {
381
		return doTaxonConceptExport;
382
	}
383

    
384
	public void setDoTaxonConceptExport(boolean doTaxonConceptExport) {
385
		this.doTaxonConceptExport = doTaxonConceptExport;
386
	}
387

    
388
	public boolean isAuthor() {
389
		return author;
390
	}
391

    
392
	public void setAuthor(boolean author) {
393
		this.author = author;
394
	}
395

    
396
	public boolean isRank() {
397
		return rank;
398
	}
399

    
400
	public void setRank(boolean rank) {
401
		this.rank = rank;
402
	}
403

    
404
	public boolean isTaxonConceptID() {
405
		return taxonConceptID;
406
	}
407

    
408
	public void setTaxonConceptID(boolean taxonConceptID) {
409
		this.taxonConceptID = taxonConceptID;
410
	}
411

    
412
	public boolean isAcceptedName() {
413
		return acceptedName;
414
	}
415

    
416
	public void setAcceptedName(boolean acceptedName) {
417
		this.acceptedName = acceptedName;
418
	}
419
	public boolean isClassification() {
420
		return classification;
421
	}
422

    
423
	public void setClassification(boolean classification) {
424
		this.classification = classification;
425
	}
426

    
427
	public boolean isTaxonName() {
428
		return taxonName;
429
	}
430

    
431
	public void setTaxonName(boolean taxonName) {
432
		this.taxonName = taxonName;
433
	}
434

    
435
	public boolean isTaxonNameID() {
436
		return taxonNameID;
437
	}
438

    
439
	public void setTaxonNameID(boolean taxonNameID) {
440
		this.taxonNameID = taxonNameID;
441
	}
442

    
443
	public boolean isTaxonStatus() {
444
		return taxonStatus;
445
	}
446

    
447
	public void setTaxonStatus(boolean taxonStatus) {
448
		this.taxonStatus = taxonStatus;
449
	}
450

    
451
	public boolean isSynonyms() {
452
		return synonyms;
453
	}
454

    
455
	public void setSynonyms(boolean synonyms) {
456
		this.synonyms = synonyms;
457
	}
458

    
459
	public boolean isDistributions() {
460
		return distributions;
461
	}
462

    
463
	public void setDistributions(boolean distributions) {
464
		this.distributions = distributions;
465
	}
466

    
467
	public boolean isRedlistFeatures() {
468
		return redlistFeatures;
469
	}
470

    
471
	public void setRedlistFeatures(boolean redlistFeatures) {
472
		this.redlistFeatures = redlistFeatures;
473
	}
474

    
475
	public boolean isParentID() {
476
		return parentID;
477
	}
478

    
479
	public void setParentID(boolean parentID) {
480
		this.parentID = parentID;
481
	}
482

    
483
	public boolean isLastChange() {
484
		return lastChange;
485
	}
486

    
487
	public void setLastChange(boolean lastChange) {
488
		this.lastChange = lastChange;
489
	}
490

    
491
	public boolean isExternalID() {
492
		return externalID;
493
	}
494

    
495
	public void setExternalID(boolean externalID) {
496
		this.externalID = externalID;
497
	}
498
    public List<CsvDemoRecord> getRecordList() {
499
        return recordList;
500
    }
501
    public void setRecordList(List<CsvDemoRecord> recordList) {
502
        this.recordList = recordList;
503
    }
504

    
505
    public Integer getPageSize() {
506
        return pageSize;
507
    }
508
    public void setPageSize(Integer pageSize) {
509
        this.pageSize = pageSize;
510
    }
511

    
512
    public Integer getPageNumber() {
513
        return pageNumber;
514
    }
515

    
516
    public void setPageNumber(Integer pageNumber) {
517
        this.pageNumber = pageNumber;
518
    }
519

    
520

    
521
    public int getTaxonNodeListSize() {
522
        return taxonNodeListSize;
523
    }
524

    
525
    public void setTaxonNodeListSize(int size) {
526
        this.taxonNodeListSize = size;
527

    
528
    }
529

    
530
}
(3-3/10)