3 * Copyright (C) 2009 EDIT
4 * European Distributed Institute of Taxonomy
5 * http://www.e-taxonomy.eu
7 * The contents of this file are subject to the Mozilla Public License Version 1.1
8 * See LICENSE.TXT at the top of this package for the full license terms.
10 package eu
.etaxonomy
.cdm
.api
.facade
;
12 import java
.util
.UUID
;
14 import org
.apache
.log4j
.Logger
;
16 import eu
.etaxonomy
.cdm
.common
.CdmUtils
;
17 import eu
.etaxonomy
.cdm
.model
.agent
.Institution
;
18 import eu
.etaxonomy
.cdm
.model
.common
.Language
;
19 import eu
.etaxonomy
.cdm
.model
.common
.Representation
;
20 import eu
.etaxonomy
.cdm
.model
.common
.TimePeriod
;
21 import eu
.etaxonomy
.cdm
.model
.location
.NamedArea
;
22 import eu
.etaxonomy
.cdm
.model
.occurrence
.Collection
;
23 import eu
.etaxonomy
.cdm
.model
.occurrence
.DerivedUnitBase
;
24 import eu
.etaxonomy
.cdm
.strategy
.StrategyBase
;
25 import eu
.etaxonomy
.cdm
.strategy
.cache
.common
.IIdentifiableEntityCacheStrategy
;
32 public class DerivedUnitFacadeCacheStrategy
extends StrategyBase
implements IIdentifiableEntityCacheStrategy
<DerivedUnitBase
> {
33 private static final long serialVersionUID
= 1578628591216605619L;
34 @SuppressWarnings("unused")
35 private static final Logger logger
= Logger
.getLogger(DerivedUnitFacadeCacheStrategy
.class);
37 private static final UUID uuid
= UUID
.fromString("df4672c1-ce5c-4724-af6d-91e2b326d4a4");
40 * @see eu.etaxonomy.cdm.strategy.StrategyBase#getUuid()
43 protected UUID
getUuid() {
47 private boolean includeEmptySeconds
= false;
48 private boolean includeReferenceSystem
= true;
52 * @see eu.etaxonomy.cdm.strategy.cache.common.IIdentifiableEntityCacheStrategy#getTitleCache(eu.etaxonomy.cdm.model.common.IdentifiableEntity)
55 public String
getTitleCache(DerivedUnitBase derivedUnit
) {
56 String ALTITUDE_PREFIX
= "alt. ";
57 String ALTITUDE_POSTFIX
= " m";
61 DerivedUnitFacade facade
;
63 facade
= DerivedUnitFacade
.NewInstance(derivedUnit
);
65 String strCountry
= null;
66 NamedArea country
= facade
.getCountry();
67 Representation repCountry
= country
== null ?
null : country
.getRepresentation(Language
.DEFAULT());
68 //TODO currently the label is the 3 digit representation of the country and text is the full text.
69 //this is against the common way of handling text, label and labelabbrev in defined terms
70 strCountry
= repCountry
== null ?
null: repCountry
.getText();
71 result
= CdmUtils
.concat(", ", result
, strCountry
);
73 // FIXME hasGatheringEvent needed;
75 result
= CdmUtils
.concat(", ", result
, facade
.getLocalityText());
78 if (facade
.getAbsoluteElevation() != null){
79 result
= CdmUtils
.concat(", " , result
, ALTITUDE_PREFIX
);
80 result
+= facade
.getAbsoluteElevation() + ALTITUDE_POSTFIX
;
84 if (facade
.getExactLocation() != null){
85 String exactLocation
= facade
.getExactLocation().toSexagesimalString(this.includeEmptySeconds
, this.includeReferenceSystem
);
86 result
= CdmUtils
.concat(", ", result
, exactLocation
);
90 result
= CdmUtils
.concat(", ", result
, facade
.getEcology());
93 //TODO period.toString ??
94 TimePeriod gatheringPeriod
= facade
.getGatheringPeriod();
95 result
= CdmUtils
.concat(", ", result
, (gatheringPeriod
== null?
null : gatheringPeriod
.toString()));
97 //Herbarium & accession number
98 String code
= getCode(facade
);
99 String collectionData
= CdmUtils
.concat(" ", code
, facade
.getAccessionNumber());
100 if (CdmUtils
.isNotEmpty(collectionData
)) {
101 result
= (result
+ " (" + collectionData
+ ")").trim();
105 result
= CdmUtils
.concat("; ", result
, facade
.getPlantDescription());
106 if (CdmUtils
.isNotEmpty(result
)){
110 } catch (DerivedUnitFacadeNotSupportedException e
) {
123 private String
getCode(DerivedUnitFacade facade
) {
125 if(facade
.getCollection() != null){
126 code
= facade
.getCollection().getCode();
127 if (CdmUtils
.isEmpty(code
)){
128 Institution institution
= facade
.getCollection().getInstitute();
129 if (institution
!= null){
130 code
= institution
.getCode();
132 if (CdmUtils
.isEmpty(code
)){
133 Collection superCollection
= facade
.getCollection().getSuperCollection();
134 if (superCollection
!= null){
135 code
= superCollection
.getCode();
143 // ************************** GETTER / SETTER ******************************************************
145 public boolean isIncludeSeconds() {
146 return includeEmptySeconds
;
151 public void setIncludeSeconds(boolean includeSeconds
) {
152 this.includeEmptySeconds
= includeSeconds
;
157 public void setIncludeReferenceSystem(boolean includeReferenceSystem
) {
158 this.includeReferenceSystem
= includeReferenceSystem
;
163 public boolean isIncludeReferenceSystem() {
164 return includeReferenceSystem
;