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