specimen facade refactoring and introducing specimen facade configurator
[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.occurrence.Collection;
19 import eu.etaxonomy.cdm.model.occurrence.DerivedUnitBase;
20 import eu.etaxonomy.cdm.model.occurrence.Specimen;
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
37 /* (non-Javadoc)
38 * @see eu.etaxonomy.cdm.strategy.StrategyBase#getUuid()
39 */
40 @Override
41 protected UUID getUuid() {
42 return uuid;
43 }
44
45
46
47 /* (non-Javadoc)
48 * @see eu.etaxonomy.cdm.strategy.cache.common.IIdentifiableEntityCacheStrategy#getTitleCache(eu.etaxonomy.cdm.model.common.IdentifiableEntity)
49 */
50 @Override
51 public String getTitleCache(DerivedUnitBase specimen) {
52 String ALTITUDE_PREFIX = "alt. ";
53 String ALTITUDE_POSTFIX = " m";
54
55 String result = "";
56
57 DerivedUnitFacade facade;
58 try {
59 facade = DerivedUnitFacade.NewInstance(specimen);
60 //country
61 //TODO
62
63 // FIXME hasGatheringEvent needed;
64 //locality
65 result = CdmUtils.concat(", ", result, facade.getLocalityText());
66 //elevation
67 if (facade.getAbsoluteElevation() != null){
68 result = CdmUtils.concat(", " , result, ALTITUDE_PREFIX);
69 result += facade.getAbsoluteElevation() + ALTITUDE_POSTFIX;
70 }
71 //ecology
72 result = CdmUtils.concat(", ", result, facade.getEcology());
73 //gathering period
74 //TODO period.toString ??
75 result = CdmUtils.concat(", ", result, facade.getGatheringPeriod().toString());
76
77 //Herbarium & accession number
78 String code = getCode(facade);
79 String collectionData = CdmUtils.concat(" ", code, facade.getAccessionNumber());
80 if (CdmUtils.isNotEmpty(collectionData)) {
81 result = (result + " (" + collectionData + ")").trim();
82 }
83
84 //plant description
85 result = CdmUtils.concat("; ", result, facade.getPlantDescription());
86 if (CdmUtils.isNotEmpty(result)){
87 result += ".";
88 }
89
90 } catch (DerivedUnitFacadeNotSupportedException e) {
91 e.printStackTrace();
92 }
93
94
95 return result;
96 }
97
98
99
100 /**
101 * @param facade
102 */
103 private String getCode(DerivedUnitFacade facade) {
104 String code = facade.getCollection().getCode();
105 if (CdmUtils.isEmpty(code)){
106 Institution institution = facade.getCollection().getInstitute();
107 if (institution != null){
108 code = institution.getCode();
109 }
110 if (CdmUtils.isEmpty(code)){
111 Collection superCollection = facade.getCollection().getSuperCollection();
112 if (superCollection != null){
113 code = superCollection.getCode();
114 }
115 }
116 }
117 return code;
118 }
119
120
121 }