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.Institution;
|
19
|
import eu.etaxonomy.cdm.model.occurrence.Collection;
|
20
|
import eu.etaxonomy.cdm.model.occurrence.DerivedUnit;
|
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<DerivedUnit> {
|
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
|
@Override
|
37
|
protected UUID getUuid() {
|
38
|
return uuid;
|
39
|
}
|
40
|
|
41
|
private boolean includeEmptySeconds = false;
|
42
|
private boolean includeReferenceSystem = true;
|
43
|
|
44
|
|
45
|
@Override
|
46
|
public String getTitleCache(DerivedUnit derivedUnit) {
|
47
|
DerivedUnitFacadeFieldUnitCacheStrategy fieldStrategy = new DerivedUnitFacadeFieldUnitCacheStrategy();
|
48
|
|
49
|
String result = "";
|
50
|
|
51
|
DerivedUnitFacade facade;
|
52
|
try {
|
53
|
DerivedUnitFacadeConfigurator config = DerivedUnitFacadeConfigurator.NewInstance();
|
54
|
config.setFirePropertyChangeEvents(false);
|
55
|
facade = DerivedUnitFacade.NewInstance(derivedUnit, config);
|
56
|
result += fieldStrategy.getFieldData(facade);
|
57
|
|
58
|
//Exsiccatum
|
59
|
String exsiccatum = null;
|
60
|
try {
|
61
|
exsiccatum = facade.getExsiccatum();
|
62
|
} catch (MethodNotSupportedByDerivedUnitTypeException e) {
|
63
|
//NO exsiccatum if this facade doe not represent a specimen
|
64
|
}
|
65
|
result = CdmUtils.concat("; ", result, exsiccatum);
|
66
|
|
67
|
//Herbarium & identifier
|
68
|
String code = getCode(facade);
|
69
|
String identifier = facade.getAccessionNumber();
|
70
|
String collectionData = CdmUtils.concat(" ", code, identifier);
|
71
|
if (StringUtils.isNotBlank(collectionData)) {
|
72
|
result = (result + " (" + collectionData + ")").trim();
|
73
|
}
|
74
|
|
75
|
//result
|
76
|
result = fieldStrategy.addPlantDescription(result, facade);
|
77
|
|
78
|
|
79
|
} catch (DerivedUnitFacadeNotSupportedException e) {
|
80
|
e.printStackTrace();
|
81
|
}
|
82
|
|
83
|
|
84
|
return result;
|
85
|
}
|
86
|
|
87
|
|
88
|
/**
|
89
|
* @param facade
|
90
|
*/
|
91
|
private String getCode(DerivedUnitFacade facade) {
|
92
|
String code = "";
|
93
|
if(facade.getCollection() != null){
|
94
|
code = facade.getCollection().getCode();
|
95
|
if (StringUtils.isBlank(code)){
|
96
|
Institution institution = facade.getCollection().getInstitute();
|
97
|
if (institution != null){
|
98
|
code = institution.getCode();
|
99
|
}
|
100
|
if (StringUtils.isBlank(code)){
|
101
|
Collection superCollection = facade.getCollection().getSuperCollection();
|
102
|
if (superCollection != null){
|
103
|
code = superCollection.getCode();
|
104
|
}
|
105
|
}
|
106
|
}
|
107
|
}
|
108
|
return code;
|
109
|
}
|
110
|
|
111
|
// ************************** GETTER / SETTER ******************************************************
|
112
|
|
113
|
public boolean isIncludeSeconds() {
|
114
|
return includeEmptySeconds;
|
115
|
}
|
116
|
|
117
|
public void setIncludeSeconds(boolean includeSeconds) {
|
118
|
this.includeEmptySeconds = includeSeconds;
|
119
|
}
|
120
|
|
121
|
public void setIncludeReferenceSystem(boolean includeReferenceSystem) {
|
122
|
this.includeReferenceSystem = includeReferenceSystem;
|
123
|
}
|
124
|
|
125
|
public boolean isIncludeReferenceSystem() {
|
126
|
return includeReferenceSystem;
|
127
|
}
|
128
|
|
129
|
}
|