some improvements to the specimen cache strategy
[cdmlib.git] / cdmlib-services / src / main / java / eu / etaxonomy / cdm / api / facade / DerivedUnitFacadeCacheStrategy.java
1 // $Id$
2 /**
3 * Copyright (C) 2009 EDIT
4 * European Distributed Institute of Taxonomy
5 * http://www.e-taxonomy.eu
6 *
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.
9 */
10 package eu.etaxonomy.cdm.api.facade;
11
12 import java.util.UUID;
13
14 import org.apache.log4j.Logger;
15
16 import eu.etaxonomy.cdm.common.CdmUtils;
17 import eu.etaxonomy.cdm.model.agent.Institution;
18 import eu.etaxonomy.cdm.model.common.TimePeriod;
19 import eu.etaxonomy.cdm.model.occurrence.Collection;
20 import eu.etaxonomy.cdm.model.occurrence.DerivedUnitBase;
21 import eu.etaxonomy.cdm.strategy.StrategyBase;
22 import eu.etaxonomy.cdm.strategy.cache.common.IIdentifiableEntityCacheStrategy;
23
24 /**
25 * @author a.mueller
26 * @date 03.06.2010
27 *
28 */
29 public class DerivedUnitFacadeCacheStrategy extends StrategyBase implements IIdentifiableEntityCacheStrategy<DerivedUnitBase> {
30 private static final long serialVersionUID = 1578628591216605619L;
31 @SuppressWarnings("unused")
32 private static final Logger logger = Logger.getLogger(DerivedUnitFacadeCacheStrategy.class);
33
34 private static final UUID uuid = UUID.fromString("df4672c1-ce5c-4724-af6d-91e2b326d4a4");
35
36 /* (non-Javadoc)
37 * @see eu.etaxonomy.cdm.strategy.StrategyBase#getUuid()
38 */
39 @Override
40 protected UUID getUuid() {
41 return uuid;
42 }
43
44 private boolean includeEmptySeconds = false;
45 private boolean includeReferenceSystem = true;
46
47
48 /* (non-Javadoc)
49 * @see eu.etaxonomy.cdm.strategy.cache.common.IIdentifiableEntityCacheStrategy#getTitleCache(eu.etaxonomy.cdm.model.common.IdentifiableEntity)
50 */
51 @Override
52 public String getTitleCache(DerivedUnitBase derivedUnit) {
53 String ALTITUDE_PREFIX = "alt. ";
54 String ALTITUDE_POSTFIX = " m";
55
56 String result = "";
57
58 DerivedUnitFacade facade;
59 try {
60 facade = DerivedUnitFacade.NewInstance(derivedUnit);
61 //country
62 //TODO
63
64 // FIXME hasGatheringEvent needed;
65 //locality
66 result = CdmUtils.concat(", ", result, facade.getLocalityText());
67
68 //elevation
69 if (facade.getAbsoluteElevation() != null){
70 result = CdmUtils.concat(", " , result, ALTITUDE_PREFIX);
71 result += facade.getAbsoluteElevation() + ALTITUDE_POSTFIX;
72 }
73
74 //exact locality
75 if (facade.getExactLocation() != null){
76 String exactLocation = facade.getExactLocation().toSexagesimalString(this.includeEmptySeconds, this.includeReferenceSystem);
77 result = CdmUtils.concat(", ", result, exactLocation);
78 }
79
80 //ecology
81 result = CdmUtils.concat(", ", result, facade.getEcology());
82
83 //gathering period
84 //TODO period.toString ??
85 TimePeriod gatheringPeriod = facade.getGatheringPeriod();
86 result = CdmUtils.concat(", ", result, (gatheringPeriod == null? null : gatheringPeriod.toString()));
87
88 //Herbarium & accession number
89 String code = getCode(facade);
90 String collectionData = CdmUtils.concat(" ", code, facade.getAccessionNumber());
91 if (CdmUtils.isNotEmpty(collectionData)) {
92 result = (result + " (" + collectionData + ")").trim();
93 }
94
95 //plant description
96 result = CdmUtils.concat("; ", result, facade.getPlantDescription());
97 if (CdmUtils.isNotEmpty(result)){
98 result += ".";
99 }
100
101 } catch (DerivedUnitFacadeNotSupportedException e) {
102 e.printStackTrace();
103 }
104
105
106 return result;
107 }
108
109
110
111 /**
112 * @param facade
113 */
114 private String getCode(DerivedUnitFacade facade) {
115 String code = facade.getCollection().getCode();
116 if (CdmUtils.isEmpty(code)){
117 Institution institution = facade.getCollection().getInstitute();
118 if (institution != null){
119 code = institution.getCode();
120 }
121 if (CdmUtils.isEmpty(code)){
122 Collection superCollection = facade.getCollection().getSuperCollection();
123 if (superCollection != null){
124 code = superCollection.getCode();
125 }
126 }
127 }
128 return code;
129 }
130
131 // ************************** GETTER / SETTER ******************************************************
132
133 public boolean isIncludeSeconds() {
134 return includeEmptySeconds;
135 }
136
137
138
139 public void setIncludeSeconds(boolean includeSeconds) {
140 this.includeEmptySeconds = includeSeconds;
141 }
142
143
144
145 public void setIncludeReferenceSystem(boolean includeReferenceSystem) {
146 this.includeReferenceSystem = includeReferenceSystem;
147 }
148
149
150
151 public boolean isIncludeReferenceSystem() {
152 return includeReferenceSystem;
153 }
154
155
156 }