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
.commons
.lang
.StringUtils
;
15 import org
.apache
.log4j
.Logger
;
17 import eu
.etaxonomy
.cdm
.common
.CdmUtils
;
18 import eu
.etaxonomy
.cdm
.model
.agent
.AgentBase
;
19 import eu
.etaxonomy
.cdm
.model
.agent
.Institution
;
20 import eu
.etaxonomy
.cdm
.model
.agent
.Person
;
21 import eu
.etaxonomy
.cdm
.model
.agent
.Team
;
22 import eu
.etaxonomy
.cdm
.model
.common
.CdmBase
;
23 import eu
.etaxonomy
.cdm
.model
.common
.Language
;
24 import eu
.etaxonomy
.cdm
.model
.common
.Representation
;
25 import eu
.etaxonomy
.cdm
.model
.common
.TimePeriod
;
26 import eu
.etaxonomy
.cdm
.model
.location
.NamedArea
;
27 import eu
.etaxonomy
.cdm
.model
.occurrence
.Collection
;
28 import eu
.etaxonomy
.cdm
.model
.occurrence
.DerivedUnitBase
;
29 import eu
.etaxonomy
.cdm
.strategy
.StrategyBase
;
30 import eu
.etaxonomy
.cdm
.strategy
.cache
.common
.IIdentifiableEntityCacheStrategy
;
37 public class DerivedUnitFacadeCacheStrategy
extends StrategyBase
implements IIdentifiableEntityCacheStrategy
<DerivedUnitBase
> {
38 private static final long serialVersionUID
= 1578628591216605619L;
39 @SuppressWarnings("unused")
40 private static final Logger logger
= Logger
.getLogger(DerivedUnitFacadeCacheStrategy
.class);
42 private static final UUID uuid
= UUID
.fromString("df4672c1-ce5c-4724-af6d-91e2b326d4a4");
45 * @see eu.etaxonomy.cdm.strategy.StrategyBase#getUuid()
48 protected UUID
getUuid() {
52 private boolean includeEmptySeconds
= false;
53 private boolean includeReferenceSystem
= true;
57 * @see eu.etaxonomy.cdm.strategy.cache.common.IIdentifiableEntityCacheStrategy#getTitleCache(eu.etaxonomy.cdm.model.common.IdentifiableEntity)
60 public String
getTitleCache(DerivedUnitBase derivedUnit
) {
61 DerivedUnitFacadeFieldObservationCacheStrategy fieldStrategy
= new DerivedUnitFacadeFieldObservationCacheStrategy();
65 DerivedUnitFacade facade
;
67 facade
= DerivedUnitFacade
.NewInstance(derivedUnit
);
68 result
+= fieldStrategy
.getFieldData(facade
);
70 // String strCountry = null;
71 // NamedArea country = facade.getCountry();
72 // Representation repCountry = country == null ? null : country.getRepresentation(Language.DEFAULT());
73 // //TODO currently the label is the 3 digit representation of the country and text is the full text.
74 // //this is against the common way of handling text, label and labelabbrev in defined terms
75 // strCountry = repCountry == null ? null: repCountry.getText();
76 // result = CdmUtils.concat(", ", result, strCountry);
79 // result = CdmUtils.concat(", ", result, facade.getLocalityText());
82 // if (facade.getAbsoluteElevation() != null){
83 // result = CdmUtils.concat(", " , result, ALTITUDE_PREFIX);
84 // result += facade.getAbsoluteElevation() + ALTITUDE_POSTFIX;
88 // if (facade.getExactLocation() != null){
89 // String exactLocation = facade.getExactLocation().toSexagesimalString(this.includeEmptySeconds, this.includeReferenceSystem);
90 // result = CdmUtils.concat(", ", result, exactLocation);
94 // result = CdmUtils.concat(", ", result, facade.getEcology());
97 // //TODO period.toString ??
98 // TimePeriod gatheringPeriod = facade.getGatheringPeriod();
99 // result = CdmUtils.concat(", ", result, (gatheringPeriod == null? null : gatheringPeriod.toString()));
101 // //collector (team) and field number
102 // String collectorAndFieldNumber = getCollectorAndFieldNumber(facade);
103 // result = CdmUtils.concat(", ", result, collectorAndFieldNumber);
106 String exsiccatum
= null;
108 exsiccatum
= facade
.getExsiccatum();
109 } catch (MethodNotSupportedByDerivedUnitTypeException e
) {
110 //NO exsiccatum if this facade doe not represent a specimen
112 result
= CdmUtils
.concat("; ", result
, exsiccatum
);
114 //Herbarium & accession number
115 String code
= getCode(facade
);
116 String collectionData
= CdmUtils
.concat(" ", code
, facade
.getAccessionNumber());
117 if (CdmUtils
.isNotEmpty(collectionData
)) {
118 result
= (result
+ " (" + collectionData
+ ")").trim();
121 result
= fieldStrategy
.addPlantDescription(result
, facade
);
124 } catch (DerivedUnitFacadeNotSupportedException e
) {
136 private String
getCode(DerivedUnitFacade facade
) {
138 if(facade
.getCollection() != null){
139 code
= facade
.getCollection().getCode();
140 if (CdmUtils
.isEmpty(code
)){
141 Institution institution
= facade
.getCollection().getInstitute();
142 if (institution
!= null){
143 code
= institution
.getCode();
145 if (CdmUtils
.isEmpty(code
)){
146 Collection superCollection
= facade
.getCollection().getSuperCollection();
147 if (superCollection
!= null){
148 code
= superCollection
.getCode();
156 // ************************** GETTER / SETTER ******************************************************
158 public boolean isIncludeSeconds() {
159 return includeEmptySeconds
;
164 public void setIncludeSeconds(boolean includeSeconds
) {
165 this.includeEmptySeconds
= includeSeconds
;
170 public void setIncludeReferenceSystem(boolean includeReferenceSystem
) {
171 this.includeReferenceSystem
= includeReferenceSystem
;
176 public boolean isIncludeReferenceSystem() {
177 return includeReferenceSystem
;