Latest updates to Specimen Excel import
[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 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 public void putIdInSource(int key, String id){
315 IdentifiableSource source = getOrMakeSource(key, OriginalSourceType.Import);
316 source.setIdInSource(id);
317 }
318 public void putSourceReference(int key, Reference<?> reference){
319 IdentifiableSource source = getOrMakeSource(key, OriginalSourceType.Unknown);
320 source.setCitation(reference);
321 }
322
323 public List<IdentifiableSource> getSources() {
324 return getOrdered(sources);
325 }
326
327
328 public void setCollectors(String value) {
329 //TODO better parse somewhere else? Quick and dirty implementation
330 List<String> authors = new ArrayList<String>();
331 String[] splits = value.split("&");
332 for (String split: splits){
333 split = split.trim();
334 authors.add(split);
335 }
336 int index = 1;
337 for (int i = 0; i < authors.size() ; i++){
338 String author = authors.get(i);
339 if (i < authors.size()-1){
340 String[] internalSplits = author.split(",");
341 for (String internal : internalSplits){
342 internal = internal.trim();
343 this.collectors.put(index++, internal);
344 }
345 }else{
346 this.collectors.put(index++, author);
347 }
348 }
349 }
350
351 public void putCollector(int key, String collector){
352 this.collectors.put(key, collector);
353 }
354
355 public List<String> getCollectors() {
356 return getOrdered(collectors);
357 }
358
359 public void putUnitNote(int key, String unitNote){
360 this.unitNotes.put(key, unitNote);
361 }
362
363 public List<String> getUnitNotes() {
364 return getOrdered(unitNotes);
365 }
366
367
368
369 /**
370 * @param key
371 * @return
372 */
373 private IdentifiableSource getOrMakeSource(int key, OriginalSourceType type) {
374 IdentifiableSource source = sources.get(key);
375 if (source == null){
376 source = IdentifiableSource.NewInstance(type);
377 sources.put(key, source);
378 }
379 return source;
380 }
381
382
383 public void putTypeCategory(int key, SpecimenTypeDesignationStatus status){
384 SpecimenTypeDesignation designation = getOrMakeTypeDesignation(key);
385 designation.setTypeStatus(status);
386 }
387 public void putTypifiedName(int key, TaxonNameBase<?,?> name){
388 if (name != null){
389 SpecimenTypeDesignation designation = getOrMakeTypeDesignation(key);
390 name.addTypeDesignation(designation, false);
391 }
392 }
393
394 public List<SpecimenTypeDesignation> getTypeDesignations() {
395 return getOrdered(types);
396 }
397
398
399 private SpecimenTypeDesignation getOrMakeTypeDesignation(int key) {
400 SpecimenTypeDesignation designation = types.get(key);
401 if (designation == null){
402 designation = SpecimenTypeDesignation.NewInstance();
403 types.put(key, designation);
404 }
405 return designation;
406 }
407
408 public void putDeterminationFamily(int key, String family){
409 DeterminationLight determinationEvent = getOrMakeDetermination(key);
410 determinationEvent.family = family;
411 }
412
413 public void putDeterminationFullName(int key, String fullName){
414 DeterminationLight determinationEvent = getOrMakeDetermination(key);
415 determinationEvent.fullName = fullName;
416 }
417
418 public void putDeterminationTaxonUuid(int key, String taxonUuid){
419 DeterminationLight determinationEvent = getOrMakeDetermination(key);
420 determinationEvent.taxonUuid = taxonUuid;
421 }
422
423 public void putDeterminationRank(int key, String rank){
424 DeterminationLight determinationEvent = getOrMakeDetermination(key);
425 determinationEvent.rank = rank;
426 }
427
428 public void putDeterminationGenus(int key, String genus){
429 DeterminationLight determinationEvent = getOrMakeDetermination(key);
430 determinationEvent.genus = genus;
431 }
432
433 public void putDeterminationSpeciesEpi(int key, String speciesEpi){
434 DeterminationLight determinationEvent = getOrMakeDetermination(key);
435 determinationEvent.speciesEpi = speciesEpi;
436 }
437
438 public void putDeterminationInfraSpeciesEpi(int key, String infraSpeciesEpi){
439 DeterminationLight determinationEvent = getOrMakeDetermination(key);
440 determinationEvent.infraSpeciesEpi = infraSpeciesEpi;
441 }
442
443 public void putDeterminationAuthor(int key, String author){
444 DeterminationLight determinationEvent = getOrMakeDetermination(key);
445 determinationEvent.author = author;
446 }
447
448 public void putDeterminationDeterminedBy(int key, String determinedBy){
449 DeterminationLight determinationEvent = getOrMakeDetermination(key);
450 determinationEvent.determinedBy = determinedBy;
451 }
452
453 public void putDeterminationDeterminedWhen(int key, String determinedWhen){
454 DeterminationLight determinationEvent = getOrMakeDetermination(key);
455 determinationEvent.determinedWhen = determinedWhen;
456 }
457
458 public void putDeterminationDeterminationNotes(int key, String notes){
459 DeterminationLight determinationEvent = getOrMakeDetermination(key);
460 determinationEvent.notes = notes;
461 }
462
463 public void putDeterminationDeterminationModifier(int key, String modifier){
464 DeterminationLight determinationEvent = getOrMakeDetermination(key);
465 determinationEvent.modifier = modifier;
466 }
467
468
469 public List<DeterminationLight> getDetermination() {
470 List<DeterminationLight> result = getOrdered(determinations);
471 if (determinations.size() > 1 && getCommonDetermination()!= null ){
472 result.remove(getCommonDetermination());
473 }
474 return result;
475 }
476
477 /**
478 * Returns the determination with key "0".
479 * @return
480 */
481 public DeterminationLight getCommonDetermination() {
482 if (determinations.get(0) != null){
483 return determinations.get(0);
484 }
485 return null;
486 }
487
488
489
490 private DeterminationLight getOrMakeDetermination(int key) {
491 DeterminationLight determination = this.determinations.get(key);
492 if (determination == null){
493 determination = new DeterminationLight();
494 this.determinations.put(key, determination);
495 }
496 return determination;
497 }
498
499
500 private<T extends Object> List<T> getOrdered(TreeMap<?, T> tree) {
501 List<T> result = new ArrayList<T>();
502 for (T value : tree.values()){
503 result.add(value);
504 }
505 return result;
506 }
507
508 public void setSex(String sex) {
509 this.sex = sex;
510 }
511
512
513 public String getSex() {
514 return sex;
515 }
516
517
518 /**
519 * @return the referenceSystem
520 */
521 public String getReferenceSystem() {
522 return referenceSystem;
523 }
524
525
526 /**
527 * @param referenceSystem the referenceSystem to set
528 */
529 public void setReferenceSystem(String referenceSystem) {
530 this.referenceSystem = referenceSystem;
531 }
532
533
534 /**
535 * @return the errorRadius
536 */
537 public String getErrorRadius() {
538 return errorRadius;
539 }
540
541
542 /**
543 * @param errorRadius the errorRadius to set
544 */
545 public void setErrorRadius(String errorRadius) {
546 this.errorRadius = errorRadius;
547 }
548
549
550 public void setCollection(String collection) {
551 this.collection = collection;
552 }
553
554
555 public String getCollection() {
556 return collection;
557 }
558
559
560 public void addLeveledArea(String levelPostfix, String value) {
561 PostfixTerm area = new PostfixTerm();
562 area.term = value;
563 area.postfix = levelPostfix;
564 this.levels.add(area);
565 }
566
567 public List<PostfixTerm> getLeveledAreas(){
568 return levels;
569 }
570
571 public void setAltitudeMax(String altitudeMax) {
572 this.altitudeMax = altitudeMax;
573 }
574
575
576 public String getAltitudeMax() {
577 return altitudeMax;
578 }
579
580
581 /**
582 * @param primaryCollector the primaryCollector to set
583 */
584 public void setPrimaryCollector(String primaryCollector) {
585 this.primaryCollector = primaryCollector;
586 }
587
588
589 /**
590 * @return the primaryCollector
591 */
592 public String getPrimaryCollector() {
593 return primaryCollector;
594 }
595
596
597 public String getLanguage() {
598 return language;
599 }
600
601
602 public void setLanguage(String language) {
603 this.language = language;
604 }
605
606 }