2 * Copyright (C) 2009 EDIT
3 * European Distributed Institute of Taxonomy
4 * http://www.e-taxonomy.eu
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.
10 package eu
.etaxonomy
.cdm
.io
.specimen
.excel
.in
;
12 import java
.util
.ArrayList
;
13 import java
.util
.List
;
14 import java
.util
.TreeMap
;
16 import org
.apache
.commons
.lang
.StringUtils
;
17 import org
.apache
.log4j
.Logger
;
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
;
32 public class SpecimenRow
extends ExcelRowBase
{
33 @SuppressWarnings("unused")
34 private static final Logger logger
= Logger
.getLogger(SpecimenRow
.class);
36 private String basisOfRecord
;
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
;
55 private String accessionNumber
;
56 private String barcode
;
58 // private String author;
60 // private String family;
61 // private String genus;
62 // private String specificEpithet;
63 private String collectionCode
;
64 private String collection
;
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
>();
76 public SpecimenRow() {
81 // may be public if necessary
82 protected class DeterminationLight
{
89 String infraSpeciesEpi
;
93 String determinedWhen
;
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
);
111 // **************************** GETTER / SETTER *********************************/
113 public void setBasisOfRecord(String basisOfRecord
) {
114 this.basisOfRecord
= basisOfRecord
;
118 public String
getBasisOfRecord() {
119 return basisOfRecord
;
123 public void setCountry(String country
) {
124 this.country
= country
;
128 public String
getCountry() {
133 public void setIsoCountry(String isoCountry
) {
134 this.isoCountry
= isoCountry
;
138 public String
getIsoCountry() {
143 public void setLocality(String locality
) {
144 this.locality
= locality
;
148 public String
getLocality() {
153 public void setFieldNotes(String fieldNotes
) {
154 this.fieldNotes
= fieldNotes
;
158 public String
getFieldNotes() {
163 public void setAccessionNumber(String accessionNumber
) {
164 this.accessionNumber
= accessionNumber
;
168 public String
getAccessionNumber() {
169 return accessionNumber
;
173 public void setBarcode(String barcode
) {
174 this.barcode
= barcode
;
178 // * @return the author
180 // public String getAuthor() {
186 // * @param author the author to set
188 // public void setAuthor(String author) {
189 // this.author = author;
194 * @return the absoluteElevation
196 public String
getAltitude() {
202 * @param absoluteElevation the absoluteElevation to set
204 public void setAltitude(String altitude
) {
205 this.altitude
= altitude
;
210 * @return the collectionCode
212 public String
getCollectionCode() {
213 return collectionCode
;
218 * @param collectionCode the collectionCode to set
220 public void setCollectionCode(String collectionCode
) {
221 this.collectionCode
= collectionCode
;
226 * @return the collectingDate
228 public String
getCollectingDate() {
229 return collectingDate
;
234 * @param collectingDate the collectingDate to set
236 public void setCollectingDate(String collectingDate
) {
237 this.collectingDate
= collectingDate
;
242 * @return the collectorsNumber
244 public String
getCollectorsNumber() {
245 return collectorsNumber
;
250 * @param collectorsNumber the collectorsNumber to set
252 public void setCollectorsNumber(String collectorsNumber
) {
253 this.collectorsNumber
= collectorsNumber
;
258 * @return the barcode
260 public String
getBarcode() {
266 * @return the collectingDateEnd
268 public String
getCollectingDateEnd() {
269 return collectingDateEnd
;
274 * @param collectingDateEnd the collectingDateEnd to set
276 public void setCollectingDateEnd(String collectingDateEnd
) {
277 this.collectingDateEnd
= collectingDateEnd
;
282 * @return the latitude
284 public String
getLatitude() {
290 * @param latitude the latitude to set
292 public void setLatitude(String latitude
) {
293 this.latitude
= latitude
;
298 * @return the longitude
300 public String
getLongitude() {
306 * @param longitude the longitude to set
308 public void setLongitude(String longitude
) {
309 this.longitude
= longitude
;
313 public void putIdInSource(int key
, String id
){
314 IdentifiableSource source
= getOrMakeSource(key
, OriginalSourceType
.Import
);
315 source
.setIdInSource(id
);
317 public void putSourceReference(int key
, Reference
<?
> reference
){
318 IdentifiableSource source
= getOrMakeSource(key
, OriginalSourceType
.Unknown
);
319 source
.setCitation(reference
);
322 public List
<IdentifiableSource
> getSources() {
323 return getOrdered(sources
);
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();
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
);
345 this.collectors
.put(index
++, author
);
350 public void putCollector(int key
, String collector
){
351 this.collectors
.put(key
, collector
);
354 public List
<String
> getCollectors() {
355 return getOrdered(collectors
);
358 public void putUnitNote(int key
, String unitNote
){
359 this.unitNotes
.put(key
, unitNote
);
362 public List
<String
> getUnitNotes() {
363 return getOrdered(unitNotes
);
372 private IdentifiableSource
getOrMakeSource(int key
, OriginalSourceType type
) {
373 IdentifiableSource source
= sources
.get(key
);
375 source
= IdentifiableSource
.NewInstance(type
);
376 sources
.put(key
, source
);
382 public void putTypeCategory(int key
, SpecimenTypeDesignationStatus status
){
383 SpecimenTypeDesignation designation
= getOrMakeTypeDesignation(key
);
384 designation
.setTypeStatus(status
);
386 public void putTypifiedName(int key
, TaxonNameBase
<?
,?
> name
){
388 SpecimenTypeDesignation designation
= getOrMakeTypeDesignation(key
);
389 name
.addTypeDesignation(designation
, false);
393 public List
<SpecimenTypeDesignation
> getTypeDesignations() {
394 return getOrdered(types
);
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
);
407 public void putDeterminationFamily(int key
, String family
){
408 DeterminationLight determinationEvent
= getOrMakeDetermination(key
);
409 determinationEvent
.family
= family
;
412 public void putDeterminationFullName(int key
, String fullName
){
413 DeterminationLight determinationEvent
= getOrMakeDetermination(key
);
414 determinationEvent
.fullName
= fullName
;
417 public void putDeterminationTaxonUuid(int key
, String taxonUuid
){
418 DeterminationLight determinationEvent
= getOrMakeDetermination(key
);
419 determinationEvent
.taxonUuid
= taxonUuid
;
422 public void putDeterminationRank(int key
, String rank
){
423 DeterminationLight determinationEvent
= getOrMakeDetermination(key
);
424 determinationEvent
.rank
= rank
;
427 public void putDeterminationGenus(int key
, String genus
){
428 DeterminationLight determinationEvent
= getOrMakeDetermination(key
);
429 determinationEvent
.genus
= genus
;
432 public void putDeterminationSpeciesEpi(int key
, String speciesEpi
){
433 DeterminationLight determinationEvent
= getOrMakeDetermination(key
);
434 determinationEvent
.speciesEpi
= speciesEpi
;
437 public void putDeterminationInfraSpeciesEpi(int key
, String infraSpeciesEpi
){
438 DeterminationLight determinationEvent
= getOrMakeDetermination(key
);
439 determinationEvent
.infraSpeciesEpi
= infraSpeciesEpi
;
442 public void putDeterminationAuthor(int key
, String author
){
443 DeterminationLight determinationEvent
= getOrMakeDetermination(key
);
444 determinationEvent
.author
= author
;
447 public void putDeterminationDeterminedBy(int key
, String determinedBy
){
448 DeterminationLight determinationEvent
= getOrMakeDetermination(key
);
449 determinationEvent
.determinedBy
= determinedBy
;
452 public void putDeterminationDeterminedWhen(int key
, String determinedWhen
){
453 DeterminationLight determinationEvent
= getOrMakeDetermination(key
);
454 determinationEvent
.determinedWhen
= determinedWhen
;
457 public void putDeterminationDeterminationNotes(int key
, String notes
){
458 DeterminationLight determinationEvent
= getOrMakeDetermination(key
);
459 determinationEvent
.notes
= notes
;
462 public void putDeterminationDeterminationModifier(int key
, String modifier
){
463 DeterminationLight determinationEvent
= getOrMakeDetermination(key
);
464 determinationEvent
.modifier
= modifier
;
468 public List
<DeterminationLight
> getDetermination() {
469 List
<DeterminationLight
> result
= getOrdered(determinations
);
470 if (determinations
.size() > 1 && getCommonDetermination()!= null ){
471 result
.remove(getCommonDetermination());
477 * Returns the determination with key "0".
480 public DeterminationLight
getCommonDetermination() {
481 if (determinations
.get(0) != null){
482 return determinations
.get(0);
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
);
495 return determination
;
499 private<T
extends Object
> List
<T
> getOrdered(TreeMap
<?
, T
> tree
) {
500 List
<T
> result
= new ArrayList
<T
>();
501 for (T value
: tree
.values()){
507 public void setSex(String sex
) {
512 public String
getSex() {
518 * @return the referenceSystem
520 public String
getReferenceSystem() {
521 return referenceSystem
;
526 * @param referenceSystem the referenceSystem to set
528 public void setReferenceSystem(String referenceSystem
) {
529 this.referenceSystem
= referenceSystem
;
534 * @return the errorRadius
536 public String
getErrorRadius() {
542 * @param errorRadius the errorRadius to set
544 public void setErrorRadius(String errorRadius
) {
545 this.errorRadius
= errorRadius
;
549 public void setCollection(String collection
) {
550 this.collection
= collection
;
554 public String
getCollection() {
559 public void addLeveledArea(String levelPostfix
, String value
) {
560 PostfixTerm area
= new PostfixTerm();
562 area
.postfix
= levelPostfix
;
563 this.levels
.add(area
);
566 public List
<PostfixTerm
> getLeveledAreas(){
570 public void setAltitudeMax(String altitudeMax
) {
571 this.altitudeMax
= altitudeMax
;
575 public String
getAltitudeMax() {
581 * @param primaryCollector the primaryCollector to set
583 public void setPrimaryCollector(String primaryCollector
) {
584 this.primaryCollector
= primaryCollector
;
589 * @return the primaryCollector
591 public String
getPrimaryCollector() {
592 return primaryCollector
;