Include FieldObservation in Specimen Facade
[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.commons.lang.StringUtils;
15 import org.apache.log4j.Logger;
16
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;
31
32 /**
33 * @author a.mueller
34 * @date 03.06.2010
35 *
36 */
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);
41
42 private static final UUID uuid = UUID.fromString("df4672c1-ce5c-4724-af6d-91e2b326d4a4");
43
44 /* (non-Javadoc)
45 * @see eu.etaxonomy.cdm.strategy.StrategyBase#getUuid()
46 */
47 @Override
48 protected UUID getUuid() {
49 return uuid;
50 }
51
52 private boolean includeEmptySeconds = false;
53 private boolean includeReferenceSystem = true;
54
55
56 /* (non-Javadoc)
57 * @see eu.etaxonomy.cdm.strategy.cache.common.IIdentifiableEntityCacheStrategy#getTitleCache(eu.etaxonomy.cdm.model.common.IdentifiableEntity)
58 */
59 @Override
60 public String getTitleCache(DerivedUnitBase derivedUnit) {
61 DerivedUnitFacadeFieldObservationCacheStrategy fieldStrategy = new DerivedUnitFacadeFieldObservationCacheStrategy();
62
63 String result = "";
64
65 DerivedUnitFacade facade;
66 try {
67 facade = DerivedUnitFacade.NewInstance(derivedUnit);
68 result += fieldStrategy.getFieldData(facade);
69 // //country
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);
77 //
78 // //locality
79 // result = CdmUtils.concat(", ", result, facade.getLocalityText());
80 //
81 // //elevation
82 // if (facade.getAbsoluteElevation() != null){
83 // result = CdmUtils.concat(", " , result, ALTITUDE_PREFIX);
84 // result += facade.getAbsoluteElevation() + ALTITUDE_POSTFIX;
85 // }
86 //
87 // //exact locality
88 // if (facade.getExactLocation() != null){
89 // String exactLocation = facade.getExactLocation().toSexagesimalString(this.includeEmptySeconds, this.includeReferenceSystem);
90 // result = CdmUtils.concat(", ", result, exactLocation);
91 // }
92 //
93 // //ecology
94 // result = CdmUtils.concat(", ", result, facade.getEcology());
95 //
96 // //gathering period
97 // //TODO period.toString ??
98 // TimePeriod gatheringPeriod = facade.getGatheringPeriod();
99 // result = CdmUtils.concat(", ", result, (gatheringPeriod == null? null : gatheringPeriod.toString()));
100 //
101 // //collector (team) and field number
102 // String collectorAndFieldNumber = getCollectorAndFieldNumber(facade);
103 // result = CdmUtils.concat(", ", result, collectorAndFieldNumber);
104
105 //Exsiccatum
106 String exsiccatum = null;
107 try {
108 exsiccatum = facade.getExsiccatum();
109 } catch (MethodNotSupportedByDerivedUnitTypeException e) {
110 //NO exsiccatum if this facade doe not represent a specimen
111 }
112 result = CdmUtils.concat("; ", result, exsiccatum);
113
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();
119 }
120
121 result = fieldStrategy.addPlantDescription(result, facade);
122
123
124 } catch (DerivedUnitFacadeNotSupportedException e) {
125 e.printStackTrace();
126 }
127
128
129 return result;
130 }
131
132
133 /**
134 * @param facade
135 */
136 private String getCode(DerivedUnitFacade facade) {
137 String code = "";
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();
144 }
145 if (CdmUtils.isEmpty(code)){
146 Collection superCollection = facade.getCollection().getSuperCollection();
147 if (superCollection != null){
148 code = superCollection.getCode();
149 }
150 }
151 }
152 }
153 return code;
154 }
155
156 // ************************** GETTER / SETTER ******************************************************
157
158 public boolean isIncludeSeconds() {
159 return includeEmptySeconds;
160 }
161
162
163
164 public void setIncludeSeconds(boolean includeSeconds) {
165 this.includeEmptySeconds = includeSeconds;
166 }
167
168
169
170 public void setIncludeReferenceSystem(boolean includeReferenceSystem) {
171 this.includeReferenceSystem = includeReferenceSystem;
172 }
173
174
175
176 public boolean isIncludeReferenceSystem() {
177 return includeReferenceSystem;
178 }
179
180
181 }