Project

General

Profile

Download (5.1 KB) Statistics
| Branch: | Tag: | Revision:
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.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;
26

    
27
/**
28
 * @author a.mueller
29
 * @date 03.06.2010
30
 *
31
 */
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);
36

    
37
	private static final UUID uuid = UUID.fromString("df4672c1-ce5c-4724-af6d-91e2b326d4a4");
38
	
39
	/* (non-Javadoc)
40
	 * @see eu.etaxonomy.cdm.strategy.StrategyBase#getUuid()
41
	 */
42
	@Override
43
	protected UUID getUuid() {
44
		return uuid;
45
	}
46

    
47
	private boolean includeEmptySeconds = false;
48
	private boolean includeReferenceSystem = true;
49
	
50

    
51
	/* (non-Javadoc)
52
	 * @see eu.etaxonomy.cdm.strategy.cache.common.IIdentifiableEntityCacheStrategy#getTitleCache(eu.etaxonomy.cdm.model.common.IdentifiableEntity)
53
	 */
54
	@Override
55
	public String getTitleCache(DerivedUnitBase derivedUnit) {
56
		String ALTITUDE_PREFIX = "alt. ";
57
		String ALTITUDE_POSTFIX = " m";
58
		
59
		String result = "";
60
		
61
		DerivedUnitFacade facade;
62
		try {
63
			facade = DerivedUnitFacade.NewInstance(derivedUnit);
64
			//country
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);
72
			
73
			// FIXME hasGatheringEvent needed;
74
			//locality
75
			result = CdmUtils.concat(", ", result, facade.getLocalityText());
76
			
77
			//elevation
78
			if (facade.getAbsoluteElevation() != null){
79
				result = CdmUtils.concat(", " , result, ALTITUDE_PREFIX);
80
				result += facade.getAbsoluteElevation() + ALTITUDE_POSTFIX;
81
			}
82
			
83
			//exact locality
84
			if (facade.getExactLocation() != null){
85
				String exactLocation = facade.getExactLocation().toSexagesimalString(this.includeEmptySeconds, this.includeReferenceSystem);
86
				result = CdmUtils.concat(", ", result, exactLocation);
87
			}
88
			
89
			//ecology
90
			result = CdmUtils.concat(", ", result, facade.getEcology());
91
			
92
			//gathering period
93
			//TODO period.toString ??
94
			TimePeriod gatheringPeriod = facade.getGatheringPeriod();
95
			result = CdmUtils.concat(", ", result, (gatheringPeriod == null? null : gatheringPeriod.toString()));
96
			
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();
102
			}
103
			
104
			//plant description
105
			result = CdmUtils.concat("; ", result, facade.getPlantDescription());
106
			if (CdmUtils.isNotEmpty(result)){
107
				result += ".";
108
			}
109
			
110
		} catch (DerivedUnitFacadeNotSupportedException e) {
111
			e.printStackTrace();
112
		}
113
		
114
		
115
		return result;
116
	}
117

    
118

    
119

    
120
	/**
121
	 * @param facade
122
	 */
123
	private String getCode(DerivedUnitFacade facade) {
124
		String code = "";
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();
131
				}
132
				if (CdmUtils.isEmpty(code)){
133
					Collection superCollection = facade.getCollection().getSuperCollection();
134
					if (superCollection != null){
135
						code = superCollection.getCode();
136
					}
137
				}
138
			}
139
		} 
140
		return code;
141
	}
142
	
143
// ************************** GETTER / SETTER ******************************************************
144
	
145
	public boolean isIncludeSeconds() {
146
		return includeEmptySeconds;
147
	}
148

    
149

    
150

    
151
	public void setIncludeSeconds(boolean includeSeconds) {
152
		this.includeEmptySeconds = includeSeconds;
153
	}
154

    
155

    
156

    
157
	public void setIncludeReferenceSystem(boolean includeReferenceSystem) {
158
		this.includeReferenceSystem = includeReferenceSystem;
159
	}
160

    
161

    
162

    
163
	public boolean isIncludeReferenceSystem() {
164
		return includeReferenceSystem;
165
	}
166

    
167
	
168
}
(2-2/5)