Project

General

Profile

Download (13.9 KB) Statistics
| Branch: | Tag: | Revision:
1
/**
2
* Copyright (C) 2009 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.excel.in;
11

    
12
import java.util.ArrayList;
13
import java.util.List;
14
import java.util.TreeMap;
15

    
16
import org.apache.commons.lang.StringUtils;
17
import org.apache.log4j.Logger;
18

    
19
import eu.etaxonomy.cdm.io.excel.common.ExcelRowBase;
20
import eu.etaxonomy.cdm.model.common.IdentifiableSource;
21
import eu.etaxonomy.cdm.model.name.SpecimenTypeDesignation;
22
import eu.etaxonomy.cdm.model.name.SpecimenTypeDesignationStatus;
23
import eu.etaxonomy.cdm.model.name.TaxonName;
24
import eu.etaxonomy.cdm.model.reference.OriginalSourceType;
25
import eu.etaxonomy.cdm.model.reference.Reference;
26

    
27
/**
28
 * @author a.mueller
29
 * @since 08.04.2011
30
 * @version 1.0
31
 */
32
public class SpecimenRow extends ExcelRowBase{
33
	@SuppressWarnings("unused")
34
	private static final Logger logger = Logger.getLogger(SpecimenRow.class);
35

    
36
	private String basisOfRecord;
37

    
38
	private String country;
39
	private String isoCountry;
40
	private String locality;
41
	private String latitude;
42
	private String longitude;
43
	private String referenceSystem;
44
	private String errorRadius;
45
	private String altitude;
46
	private String altitudeMax;
47
	private String fieldNotes;
48
	private String collectingDate;
49
	private String collectingDateEnd;
50
	private String collectorsNumber;
51
	private String primaryCollector;
52
	private String language;
53

    
54
	private String sex;
55

    
56
	private String accessionNumber;
57
	private String barcode;
58

    
59
	//	private String author;
60

    
61
//	private String family;
62
//	private String genus;
63
//	private String specificEpithet;
64
	private String collectionCode;
65
	private String collection;
66

    
67

    
68
	private TreeMap<Integer, IdentifiableSource> sources = new TreeMap<Integer, IdentifiableSource>();
69
	private TreeMap<Integer, String> collectors = new TreeMap<Integer, String>();
70
	private TreeMap<Integer, String> unitNotes = new TreeMap<Integer, String>();
71
	private TreeMap<Integer, SpecimenTypeDesignation> types = new TreeMap<Integer, SpecimenTypeDesignation>();
72
	private TreeMap<Integer, DeterminationLight> determinations = new TreeMap<Integer, DeterminationLight>();
73
	private List<PostfixTerm> levels  = new ArrayList<PostfixTerm>();
74

    
75

    
76

    
77
	public SpecimenRow() {
78
	}
79

    
80

    
81

    
82
	//	may be public if necessary
83
	protected class DeterminationLight{
84
		String taxonUuid;
85
		String family;
86
		String genus;
87
		String rank;
88
		String fullName;
89
		String speciesEpi;
90
		String infraSpeciesEpi;
91
		String author;
92
		String modifier;
93
		String determinedBy;
94
		String determinedWhen;
95
		String notes;
96

    
97
		public boolean hasTaxonInformation() {
98
			boolean result = StringUtils.isNotBlank(taxonUuid)
99
			 	|| StringUtils.isNotBlank(family)
100
			 	|| StringUtils.isNotBlank(genus)
101
			 	|| StringUtils.isNotBlank(rank)
102
			 	|| StringUtils.isNotBlank(fullName)
103
			 	|| StringUtils.isNotBlank(speciesEpi)
104
				|| StringUtils.isNotBlank(author)
105
				|| StringUtils.isNotBlank(infraSpeciesEpi);
106
			return result;
107
		}
108

    
109
	}
110

    
111

    
112
// **************************** GETTER / SETTER *********************************/
113

    
114
	public void setBasisOfRecord(String basisOfRecord) {
115
		this.basisOfRecord = basisOfRecord;
116
	}
117

    
118

    
119
	public String getBasisOfRecord() {
120
		return basisOfRecord;
121
	}
122

    
123

    
124
	public void setCountry(String country) {
125
		this.country = country;
126
	}
127

    
128

    
129
	public String getCountry() {
130
		return country;
131
	}
132

    
133

    
134
	public void setIsoCountry(String isoCountry) {
135
		this.isoCountry = isoCountry;
136
	}
137

    
138

    
139
	public String getIsoCountry() {
140
		return isoCountry;
141
	}
142

    
143

    
144
	public void setLocality(String locality) {
145
		this.locality = locality;
146
	}
147

    
148

    
149
	public String getLocality() {
150
		return locality;
151
	}
152

    
153

    
154
	public void setFieldNotes(String fieldNotes) {
155
		this.fieldNotes = fieldNotes;
156
	}
157

    
158

    
159
	public String getFieldNotes() {
160
		return fieldNotes;
161
	}
162

    
163

    
164
	public void setAccessionNumber(String accessionNumber) {
165
		this.accessionNumber = accessionNumber;
166
	}
167

    
168

    
169
	public String getAccessionNumber() {
170
		return accessionNumber;
171
	}
172

    
173

    
174
	public void setBarcode(String barcode) {
175
		this.barcode = barcode;
176
	}
177
//
178
//	/**
179
//	 * @return the author
180
//	 */
181
//	public String getAuthor() {
182
//		return author;
183
//	}
184
//
185
//
186
//	/**
187
//	 * @param author the author to set
188
//	 */
189
//	public void setAuthor(String author) {
190
//		this.author = author;
191
//	}
192

    
193

    
194
	/**
195
	 * @return the absoluteElevation
196
	 */
197
	public String getAltitude() {
198
		return altitude;
199
	}
200

    
201

    
202
	/**
203
	 * @param absoluteElevation the absoluteElevation to set
204
	 */
205
	public void setAltitude(String altitude) {
206
		this.altitude = altitude;
207
	}
208

    
209

    
210
	/**
211
	 * @return the collectionCode
212
	 */
213
	public String getCollectionCode() {
214
		return collectionCode;
215
	}
216

    
217

    
218
	/**
219
	 * @param collectionCode the collectionCode to set
220
	 */
221
	public void setCollectionCode(String collectionCode) {
222
		this.collectionCode = collectionCode;
223
	}
224

    
225

    
226
	/**
227
	 * @return the collectingDate
228
	 */
229
	public String getCollectingDate() {
230
		return collectingDate;
231
	}
232

    
233

    
234
	/**
235
	 * @param collectingDate the collectingDate to set
236
	 */
237
	public void setCollectingDate(String collectingDate) {
238
		this.collectingDate = collectingDate;
239
	}
240

    
241

    
242
	/**
243
	 * @return the collectorsNumber
244
	 */
245
	public String getCollectorsNumber() {
246
		return collectorsNumber;
247
	}
248

    
249

    
250
	/**
251
	 * @param collectorsNumber the collectorsNumber to set
252
	 */
253
	public void setCollectorsNumber(String collectorsNumber) {
254
		this.collectorsNumber = collectorsNumber;
255
	}
256

    
257

    
258
	/**
259
	 * @return the barcode
260
	 */
261
	public String getBarcode() {
262
		return barcode;
263
	}
264

    
265

    
266
	/**
267
	 * @return the collectingDateEnd
268
	 */
269
	public String getCollectingDateEnd() {
270
		return collectingDateEnd;
271
	}
272

    
273

    
274
	/**
275
	 * @param collectingDateEnd the collectingDateEnd to set
276
	 */
277
	public void setCollectingDateEnd(String collectingDateEnd) {
278
		this.collectingDateEnd = collectingDateEnd;
279
	}
280

    
281

    
282
	/**
283
	 * @return the latitude
284
	 */
285
	public String getLatitude() {
286
		return latitude;
287
	}
288

    
289

    
290
	/**
291
	 * @param latitude the latitude to set
292
	 */
293
	public void setLatitude(String latitude) {
294
		this.latitude = latitude;
295
	}
296

    
297

    
298
	/**
299
	 * @return the longitude
300
	 */
301
	public String getLongitude() {
302
		return longitude;
303
	}
304

    
305

    
306
	/**
307
	 * @param longitude the longitude to set
308
	 */
309
	public void setLongitude(String longitude) {
310
		this.longitude = longitude;
311
	}
312

    
313

    
314
	@Override
315
    public void putIdInSource(int key, String id){
316
		IdentifiableSource source = getOrMakeSource(key, OriginalSourceType.Import);
317
		source.setIdInSource(id);
318
	}
319
	@Override
320
    public void putSourceReference(int key, Reference reference){
321
		IdentifiableSource source = getOrMakeSource(key, OriginalSourceType.Unknown);
322
		source.setCitation(reference);
323
	}
324

    
325
	@Override
326
    public List<IdentifiableSource> getSources() {
327
		return getOrdered(sources);
328
	}
329

    
330

    
331
	public void setCollectors(String value) {
332
		//TODO better parse somewhere else? Quick and dirty implementation
333
		List<String> authors = new ArrayList<String>();
334
		String[] splits = value.split("&");
335
		for (String split: splits){
336
			split = split.trim();
337
			authors.add(split);
338
		}
339
		int index = 1;
340
		for (int i = 0; i < authors.size() ; i++){
341
			String author = authors.get(i);
342
			if (i < authors.size()-1){
343
				String[] internalSplits = author.split(",");
344
				for (String internal : internalSplits){
345
					internal = internal.trim();
346
					this.collectors.put(index++, internal);
347
				}
348
			}else{
349
				this.collectors.put(index++, author);
350
			}
351
		}
352
	}
353

    
354
	public void putCollector(int key, String collector){
355
		this.collectors.put(key, collector);
356
	}
357

    
358
	public List<String> getCollectors() {
359
		return getOrdered(collectors);
360
	}
361

    
362
	public void putUnitNote(int key, String unitNote){
363
		this.unitNotes.put(key, unitNote);
364
	}
365

    
366
	public List<String> getUnitNotes() {
367
		return getOrdered(unitNotes);
368
	}
369

    
370

    
371

    
372
	/**
373
	 * @param key
374
	 * @return
375
	 */
376
	private IdentifiableSource getOrMakeSource(int key, OriginalSourceType type) {
377
		IdentifiableSource  source = sources.get(key);
378
		if (source == null){
379
			source = IdentifiableSource.NewInstance(type);
380
			sources.put(key, source);
381
		}
382
		return source;
383
	}
384

    
385

    
386
	@Override
387
    public void putTypeCategory(int key, SpecimenTypeDesignationStatus status){
388
		SpecimenTypeDesignation designation = getOrMakeTypeDesignation(key);
389
		designation.setTypeStatus(status);
390
	}
391
	@Override
392
    public void putTypifiedName(int key, TaxonName name){
393
		if (name != null){
394
			SpecimenTypeDesignation designation = getOrMakeTypeDesignation(key);
395
			name.addTypeDesignation(designation, false);
396
		}
397
	}
398

    
399
	@Override
400
    public List<SpecimenTypeDesignation> getTypeDesignations() {
401
		return getOrdered(types);
402
	}
403

    
404

    
405
	private SpecimenTypeDesignation getOrMakeTypeDesignation(int key) {
406
		SpecimenTypeDesignation designation = types.get(key);
407
		if (designation == null){
408
			designation = SpecimenTypeDesignation.NewInstance();
409
			types.put(key, designation);
410
		}
411
		return designation;
412
	}
413

    
414
	public void putDeterminationFamily(int key, String family){
415
		DeterminationLight determinationEvent = getOrMakeDetermination(key);
416
		determinationEvent.family = family;
417
	}
418

    
419
	public void putDeterminationFullName(int key, String fullName){
420
		DeterminationLight determinationEvent = getOrMakeDetermination(key);
421
		determinationEvent.fullName = fullName;
422
	}
423

    
424
	public void putDeterminationTaxonUuid(int key, String taxonUuid){
425
		DeterminationLight determinationEvent = getOrMakeDetermination(key);
426
		determinationEvent.taxonUuid = taxonUuid;
427
	}
428

    
429
	public void putDeterminationRank(int key, String rank){
430
		DeterminationLight determinationEvent = getOrMakeDetermination(key);
431
		determinationEvent.rank = rank;
432
	}
433

    
434
	public void putDeterminationGenus(int key, String genus){
435
		DeterminationLight determinationEvent = getOrMakeDetermination(key);
436
		determinationEvent.genus = genus;
437
	}
438

    
439
	public void putDeterminationSpeciesEpi(int key, String speciesEpi){
440
		DeterminationLight determinationEvent = getOrMakeDetermination(key);
441
		determinationEvent.speciesEpi = speciesEpi;
442
	}
443

    
444
	public void putDeterminationInfraSpeciesEpi(int key, String infraSpeciesEpi){
445
		DeterminationLight determinationEvent = getOrMakeDetermination(key);
446
		determinationEvent.infraSpeciesEpi = infraSpeciesEpi;
447
	}
448

    
449
	public void putDeterminationAuthor(int key, String author){
450
		DeterminationLight determinationEvent = getOrMakeDetermination(key);
451
		determinationEvent.author = author;
452
	}
453

    
454
	public void putDeterminationDeterminedBy(int key, String determinedBy){
455
		DeterminationLight determinationEvent = getOrMakeDetermination(key);
456
		determinationEvent.determinedBy = determinedBy;
457
	}
458

    
459
	public void putDeterminationDeterminedWhen(int key, String determinedWhen){
460
		DeterminationLight determinationEvent = getOrMakeDetermination(key);
461
		determinationEvent.determinedWhen = determinedWhen;
462
	}
463

    
464
	public void putDeterminationDeterminationNotes(int key, String notes){
465
		DeterminationLight determinationEvent = getOrMakeDetermination(key);
466
		determinationEvent.notes = notes;
467
	}
468

    
469
	public void putDeterminationDeterminationModifier(int key, String modifier){
470
		DeterminationLight determinationEvent = getOrMakeDetermination(key);
471
		determinationEvent.modifier = modifier;
472
	}
473

    
474

    
475
	public List<DeterminationLight> getDetermination() {
476
		List<DeterminationLight> result = getOrdered(determinations);
477
		if (determinations.size() > 1 && getCommonDetermination()!= null ){
478
			result.remove(getCommonDetermination());
479
		}
480
		return result;
481
	}
482

    
483
	/**
484
	 * Returns the determination with key "0".
485
	 * @return
486
	 */
487
	public DeterminationLight getCommonDetermination() {
488
		if (determinations.get(0) != null){
489
			return determinations.get(0);
490
		}
491
		return null;
492
	}
493

    
494

    
495

    
496
	private DeterminationLight getOrMakeDetermination(int key) {
497
		DeterminationLight determination = this.determinations.get(key);
498
		if (determination == null){
499
			determination = new DeterminationLight();
500
			this.determinations.put(key, determination);
501
		}
502
		return determination;
503
	}
504

    
505

    
506
	private<T extends Object> List<T> getOrdered(TreeMap<?, T> tree) {
507
		List<T> result = new ArrayList<T>();
508
		for (T value : tree.values()){
509
			result.add(value);
510
		}
511
		return result;
512
	}
513

    
514
	public void setSex(String sex) {
515
		this.sex = sex;
516
	}
517

    
518

    
519
	public String getSex() {
520
		return sex;
521
	}
522

    
523

    
524
	/**
525
	 * @return the referenceSystem
526
	 */
527
	public String getReferenceSystem() {
528
		return referenceSystem;
529
	}
530

    
531

    
532
	/**
533
	 * @param referenceSystem the referenceSystem to set
534
	 */
535
	public void setReferenceSystem(String referenceSystem) {
536
		this.referenceSystem = referenceSystem;
537
	}
538

    
539

    
540
	/**
541
	 * @return the errorRadius
542
	 */
543
	public String getErrorRadius() {
544
		return errorRadius;
545
	}
546

    
547

    
548
	/**
549
	 * @param errorRadius the errorRadius to set
550
	 */
551
	public void setErrorRadius(String errorRadius) {
552
		this.errorRadius = errorRadius;
553
	}
554

    
555

    
556
	public void setCollection(String collection) {
557
		this.collection = collection;
558
	}
559

    
560

    
561
	public String getCollection() {
562
		return collection;
563
	}
564

    
565

    
566
	public void addLeveledArea(String levelPostfix, String value) {
567
		PostfixTerm area = new PostfixTerm();
568
		area.term = value;
569
		area.postfix = levelPostfix;
570
		this.levels.add(area);
571
	}
572

    
573
	public List<PostfixTerm> getLeveledAreas(){
574
		return levels;
575
	}
576

    
577
	public void setAltitudeMax(String altitudeMax) {
578
		this.altitudeMax = altitudeMax;
579
	}
580

    
581

    
582
	public String getAltitudeMax() {
583
		return altitudeMax;
584
	}
585

    
586

    
587
	/**
588
	 * @param primaryCollector the primaryCollector to set
589
	 */
590
	public void setPrimaryCollector(String primaryCollector) {
591
		this.primaryCollector = primaryCollector;
592
	}
593

    
594

    
595
	/**
596
	 * @return the primaryCollector
597
	 */
598
	public String getPrimaryCollector() {
599
		return primaryCollector;
600
	}
601

    
602

    
603
	public String getLanguage() {
604
		return language;
605
	}
606

    
607

    
608
	public void setLanguage(String language) {
609
		this.language = language;
610
	}
611

    
612
}
(9-9/12)