minor
[cdmlib.git] / cdmlib-io / src / main / java / eu / etaxonomy / cdm / io / specimen / excel / in / SpecimenRow.java
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.TaxonNameBase;
24 import eu.etaxonomy.cdm.model.reference.Reference;
25
26 /**
27 * @author a.mueller
28 * @created 08.04.2011
29 * @version 1.0
30 */
31 public class SpecimenRow extends ExcelRowBase{
32 @SuppressWarnings("unused")
33 private static final Logger logger = Logger.getLogger(SpecimenRow.class);
34
35 private String basisOfRecord;
36
37 private String country;
38 private String isoCountry;
39 private String locality;
40 private String latitude;
41 private String longitude;
42 private String referenceSystem;
43 private String errorRadius;
44 private String altitude;
45 private String altitudeMax;
46 private String fieldNotes;
47 private String collectingDate;
48 private String collectingDateEnd;
49 private String collectorsNumber;
50 private String primaryCollector;
51
52 private String sex;
53
54 private String accessionNumber;
55 private String barcode;
56
57 // private String author;
58
59 // private String family;
60 // private String genus;
61 // private String specificEpithet;
62 private String collectionCode;
63 private String collection;
64
65
66 private TreeMap<Integer, IdentifiableSource> sources = new TreeMap<Integer, IdentifiableSource>();
67 private TreeMap<Integer, String> collectors = new TreeMap<Integer, String>();
68 private TreeMap<Integer, String> unitNotes = new TreeMap<Integer, String>();
69 private TreeMap<Integer, SpecimenTypeDesignation> types = new TreeMap<Integer, SpecimenTypeDesignation>();
70 private TreeMap<Integer, DeterminationLight> determinations = new TreeMap<Integer, DeterminationLight>();
71 private List<PostfixTerm> levels = new ArrayList<PostfixTerm>();
72
73
74
75 public SpecimenRow() {
76 }
77
78
79
80 // may be public if necessary
81 protected class DeterminationLight{
82 String taxonUuid;
83 String family;
84 String genus;
85 String rank;
86 String fullName;
87 String speciesEpi;
88 String infraSpeciesEpi;
89 String author;
90 String modifier;
91 String determinedBy;
92 String determinedWhen;
93 String notes;
94
95 public boolean hasTaxonInformation() {
96 boolean result = StringUtils.isNotBlank(taxonUuid)
97 || StringUtils.isNotBlank(family)
98 || StringUtils.isNotBlank(genus)
99 || StringUtils.isNotBlank(rank)
100 || StringUtils.isNotBlank(fullName)
101 || StringUtils.isNotBlank(speciesEpi)
102 || StringUtils.isNotBlank(author)
103 || StringUtils.isNotBlank(infraSpeciesEpi);
104 return result;
105 }
106
107 }
108
109
110 // **************************** GETTER / SETTER *********************************/
111
112 public void setBasisOfRecord(String basisOfRecord) {
113 this.basisOfRecord = basisOfRecord;
114 }
115
116
117 public String getBasisOfRecord() {
118 return basisOfRecord;
119 }
120
121
122 public void setCountry(String country) {
123 this.country = country;
124 }
125
126
127 public String getCountry() {
128 return country;
129 }
130
131
132 public void setIsoCountry(String isoCountry) {
133 this.isoCountry = isoCountry;
134 }
135
136
137 public String getIsoCountry() {
138 return isoCountry;
139 }
140
141
142 public void setLocality(String locality) {
143 this.locality = locality;
144 }
145
146
147 public String getLocality() {
148 return locality;
149 }
150
151
152 public void setFieldNotes(String fieldNotes) {
153 this.fieldNotes = fieldNotes;
154 }
155
156
157 public String getFieldNotes() {
158 return fieldNotes;
159 }
160
161
162 public void setAccessionNumber(String accessionNumber) {
163 this.accessionNumber = accessionNumber;
164 }
165
166
167 public String getAccessionNumber() {
168 return accessionNumber;
169 }
170
171
172 public void setBarcode(String barcode) {
173 this.barcode = barcode;
174 }
175 //
176 // /**
177 // * @return the author
178 // */
179 // public String getAuthor() {
180 // return author;
181 // }
182 //
183 //
184 // /**
185 // * @param author the author to set
186 // */
187 // public void setAuthor(String author) {
188 // this.author = author;
189 // }
190
191
192 /**
193 * @return the absoluteElevation
194 */
195 public String getAltitude() {
196 return altitude;
197 }
198
199
200 /**
201 * @param absoluteElevation the absoluteElevation to set
202 */
203 public void setAltitude(String altitude) {
204 this.altitude = altitude;
205 }
206
207
208 /**
209 * @return the collectionCode
210 */
211 public String getCollectionCode() {
212 return collectionCode;
213 }
214
215
216 /**
217 * @param collectionCode the collectionCode to set
218 */
219 public void setCollectionCode(String collectionCode) {
220 this.collectionCode = collectionCode;
221 }
222
223
224 /**
225 * @return the collectingDate
226 */
227 public String getCollectingDate() {
228 return collectingDate;
229 }
230
231
232 /**
233 * @param collectingDate the collectingDate to set
234 */
235 public void setCollectingDate(String collectingDate) {
236 this.collectingDate = collectingDate;
237 }
238
239
240 /**
241 * @return the collectorsNumber
242 */
243 public String getCollectorsNumber() {
244 return collectorsNumber;
245 }
246
247
248 /**
249 * @param collectorsNumber the collectorsNumber to set
250 */
251 public void setCollectorsNumber(String collectorsNumber) {
252 this.collectorsNumber = collectorsNumber;
253 }
254
255
256 /**
257 * @return the barcode
258 */
259 public String getBarcode() {
260 return barcode;
261 }
262
263
264 /**
265 * @return the collectingDateEnd
266 */
267 public String getCollectingDateEnd() {
268 return collectingDateEnd;
269 }
270
271
272 /**
273 * @param collectingDateEnd the collectingDateEnd to set
274 */
275 public void setCollectingDateEnd(String collectingDateEnd) {
276 this.collectingDateEnd = collectingDateEnd;
277 }
278
279
280 /**
281 * @return the latitude
282 */
283 public String getLatitude() {
284 return latitude;
285 }
286
287
288 /**
289 * @param latitude the latitude to set
290 */
291 public void setLatitude(String latitude) {
292 this.latitude = latitude;
293 }
294
295
296 /**
297 * @return the longitude
298 */
299 public String getLongitude() {
300 return longitude;
301 }
302
303
304 /**
305 * @param longitude the longitude to set
306 */
307 public void setLongitude(String longitude) {
308 this.longitude = longitude;
309 }
310
311
312 public void putIdInSource(int key, String id){
313 IdentifiableSource source = getOrMakeSource(key);
314 source.setIdInSource(id);
315 }
316 public void putSourceReference(int key, Reference<?> reference){
317 IdentifiableSource source = getOrMakeSource(key);
318 source.setCitation(reference);
319 }
320
321 public List<IdentifiableSource> getSources() {
322 return getOrdered(sources);
323 }
324
325
326 public void setCollectors(String value) {
327 //TODO better parse somewhere else? Quick and dirty implementation
328 List<String> authors = new ArrayList<String>();
329 String[] splits = value.split("&");
330 for (String split: splits){
331 split = split.trim();
332 authors.add(split);
333 }
334 int index = 1;
335 for (int i = 0; i < authors.size() ; i++){
336 String author = authors.get(i);
337 if (i < authors.size()-1){
338 String[] internalSplits = author.split(",");
339 for (String internal : internalSplits){
340 internal = internal.trim();
341 this.collectors.put(index++, internal);
342 }
343 }else{
344 this.collectors.put(index++, author);
345 }
346 }
347 }
348
349 public void putCollector(int key, String collector){
350 this.collectors.put(key, collector);
351 }
352
353 public List<String> getCollectors() {
354 return getOrdered(collectors);
355 }
356
357 public void putUnitNote(int key, String unitNote){
358 this.unitNotes.put(key, unitNote);
359 }
360
361 public List<String> getUnitNotes() {
362 return getOrdered(unitNotes);
363 }
364
365
366
367 /**
368 * @param key
369 * @return
370 */
371 private IdentifiableSource getOrMakeSource(int key) {
372 IdentifiableSource source = sources.get(key);
373 if (source == null){
374 source = IdentifiableSource.NewInstance();
375 sources.put(key, source);
376 }
377 return source;
378 }
379
380
381 public void putTypeCategory(int key, SpecimenTypeDesignationStatus status){
382 SpecimenTypeDesignation designation = getOrMakeTypeDesignation(key);
383 designation.setTypeStatus(status);
384 }
385 public void putTypifiedName(int key, TaxonNameBase<?,?> name){
386 if (name != null){
387 SpecimenTypeDesignation designation = getOrMakeTypeDesignation(key);
388 name.addTypeDesignation(designation, false);
389 }
390 }
391
392 public List<SpecimenTypeDesignation> getTypeDesignations() {
393 return getOrdered(types);
394 }
395
396
397 private SpecimenTypeDesignation getOrMakeTypeDesignation(int key) {
398 SpecimenTypeDesignation designation = types.get(key);
399 if (designation == null){
400 designation = SpecimenTypeDesignation.NewInstance();
401 types.put(key, designation);
402 }
403 return designation;
404 }
405
406 public void putDeterminationFamily(int key, String family){
407 DeterminationLight determinationEvent = getOrMakeDetermination(key);
408 determinationEvent.family = family;
409 }
410
411 public void putDeterminationFullName(int key, String fullName){
412 DeterminationLight determinationEvent = getOrMakeDetermination(key);
413 determinationEvent.fullName = fullName;
414 }
415
416 public void putDeterminationTaxonUuid(int key, String taxonUuid){
417 DeterminationLight determinationEvent = getOrMakeDetermination(key);
418 determinationEvent.taxonUuid = taxonUuid;
419 }
420
421 public void putDeterminationRank(int key, String rank){
422 DeterminationLight determinationEvent = getOrMakeDetermination(key);
423 determinationEvent.rank = rank;
424 }
425
426 public void putDeterminationGenus(int key, String genus){
427 DeterminationLight determinationEvent = getOrMakeDetermination(key);
428 determinationEvent.genus = genus;
429 }
430
431 public void putDeterminationSpeciesEpi(int key, String speciesEpi){
432 DeterminationLight determinationEvent = getOrMakeDetermination(key);
433 determinationEvent.speciesEpi = speciesEpi;
434 }
435
436 public void putDeterminationInfraSpeciesEpi(int key, String infraSpeciesEpi){
437 DeterminationLight determinationEvent = getOrMakeDetermination(key);
438 determinationEvent.infraSpeciesEpi = infraSpeciesEpi;
439 }
440
441 public void putDeterminationAuthor(int key, String author){
442 DeterminationLight determinationEvent = getOrMakeDetermination(key);
443 determinationEvent.author = author;
444 }
445
446 public void putDeterminationDeterminedBy(int key, String determinedBy){
447 DeterminationLight determinationEvent = getOrMakeDetermination(key);
448 determinationEvent.determinedBy = determinedBy;
449 }
450
451 public void putDeterminationDeterminedWhen(int key, String determinedWhen){
452 DeterminationLight determinationEvent = getOrMakeDetermination(key);
453 determinationEvent.determinedWhen = determinedWhen;
454 }
455
456 public void putDeterminationDeterminationNotes(int key, String notes){
457 DeterminationLight determinationEvent = getOrMakeDetermination(key);
458 determinationEvent.notes = notes;
459 }
460
461 public void putDeterminationDeterminationModifier(int key, String modifier){
462 DeterminationLight determinationEvent = getOrMakeDetermination(key);
463 determinationEvent.modifier = modifier;
464 }
465
466
467 public List<DeterminationLight> getDetermination() {
468 List<DeterminationLight> result = getOrdered(determinations);
469 if (determinations.size() > 1 && getCommonDetermination()!= null ){
470 result.remove(getCommonDetermination());
471 }
472 return result;
473 }
474
475 /**
476 * Returns the determination with key "0".
477 * @return
478 */
479 public DeterminationLight getCommonDetermination() {
480 if (determinations.get(0) != null){
481 return determinations.get(0);
482 }
483 return null;
484 }
485
486
487
488 private DeterminationLight getOrMakeDetermination(int key) {
489 DeterminationLight determination = this.determinations.get(key);
490 if (determination == null){
491 determination = new DeterminationLight();
492 this.determinations.put(key, determination);
493 }
494 return determination;
495 }
496
497
498 private<T extends Object> List<T> getOrdered(TreeMap<?, T> tree) {
499 List<T> result = new ArrayList<T>();
500 for (T value : tree.values()){
501 result.add(value);
502 }
503 return result;
504 }
505
506 public void setSex(String sex) {
507 this.sex = sex;
508 }
509
510
511 public String getSex() {
512 return sex;
513 }
514
515
516 /**
517 * @return the referenceSystem
518 */
519 public String getReferenceSystem() {
520 return referenceSystem;
521 }
522
523
524 /**
525 * @param referenceSystem the referenceSystem to set
526 */
527 public void setReferenceSystem(String referenceSystem) {
528 this.referenceSystem = referenceSystem;
529 }
530
531
532 /**
533 * @return the errorRadius
534 */
535 public String getErrorRadius() {
536 return errorRadius;
537 }
538
539
540 /**
541 * @param errorRadius the errorRadius to set
542 */
543 public void setErrorRadius(String errorRadius) {
544 this.errorRadius = errorRadius;
545 }
546
547
548 public void setCollection(String collection) {
549 this.collection = collection;
550 }
551
552
553 public String getCollection() {
554 return collection;
555 }
556
557
558 public void addLeveledArea(String levelPostfix, String value) {
559 PostfixTerm area = new PostfixTerm();
560 area.term = value;
561 area.postfix = levelPostfix;
562 this.levels.add(area);
563 }
564
565 public List<PostfixTerm> getLeveledAreas(){
566 return levels;
567 }
568
569 public void setAltitudeMax(String altitudeMax) {
570 this.altitudeMax = altitudeMax;
571 }
572
573
574 public String getAltitudeMax() {
575 return altitudeMax;
576 }
577
578
579 /**
580 * @param primaryCollector the primaryCollector to set
581 */
582 public void setPrimaryCollector(String primaryCollector) {
583 this.primaryCollector = primaryCollector;
584 }
585
586
587 /**
588 * @return the primaryCollector
589 */
590 public String getPrimaryCollector() {
591 return primaryCollector;
592 }
593
594 }