1
|
/**
|
2
|
* Copyright (C) 2009 EDIT
|
3
|
* European Distributed Institute of Taxonomy
|
4
|
* http://www.e-taxonomy.eu
|
5
|
*
|
6
|
* The contents of this file are subject to the Mozilla Public License Version 1.1
|
7
|
* See LICENSE.TXT at the top of this package for the full license terms.
|
8
|
*/
|
9
|
package eu.etaxonomy.cdm.api.facade;
|
10
|
|
11
|
import java.util.UUID;
|
12
|
|
13
|
import org.apache.commons.lang.StringUtils;
|
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.DerivedUnit;
|
20
|
import eu.etaxonomy.cdm.strategy.StrategyBase;
|
21
|
import eu.etaxonomy.cdm.strategy.cache.common.IIdentifiableEntityCacheStrategy;
|
22
|
|
23
|
/**
|
24
|
* @author a.mueller
|
25
|
* @date 03.06.2010
|
26
|
*
|
27
|
*/
|
28
|
public class DerivedUnitFacadeCacheStrategy extends StrategyBase implements IIdentifiableEntityCacheStrategy<DerivedUnit> {
|
29
|
private static final long serialVersionUID = 1578628591216605619L;
|
30
|
@SuppressWarnings("unused")
|
31
|
private static final Logger logger = Logger.getLogger(DerivedUnitFacadeCacheStrategy.class);
|
32
|
|
33
|
private static final UUID uuid = UUID.fromString("df4672c1-ce5c-4724-af6d-91e2b326d4a4");
|
34
|
|
35
|
@Override
|
36
|
protected UUID getUuid() {
|
37
|
return uuid;
|
38
|
}
|
39
|
|
40
|
private boolean includeEmptySeconds = false;
|
41
|
private boolean includeReferenceSystem = true;
|
42
|
|
43
|
@Override
|
44
|
public String getTitleCache(DerivedUnit derivedUnit) {
|
45
|
return getTitleCache(derivedUnit, false);
|
46
|
}
|
47
|
|
48
|
|
49
|
public String getTitleCache(DerivedUnit derivedUnit, boolean skipFieldUnit) {
|
50
|
DerivedUnitFacadeFieldUnitCacheStrategy fieldStrategy = new DerivedUnitFacadeFieldUnitCacheStrategy();
|
51
|
|
52
|
String result = "";
|
53
|
|
54
|
DerivedUnitFacade facade;
|
55
|
try {
|
56
|
DerivedUnitFacadeConfigurator config = DerivedUnitFacadeConfigurator.NewInstance();
|
57
|
config.setFirePropertyChangeEvents(false);
|
58
|
facade = DerivedUnitFacade.NewInstance(derivedUnit, config);
|
59
|
|
60
|
if(!skipFieldUnit){
|
61
|
result += fieldStrategy.getFieldData(facade);
|
62
|
}
|
63
|
//Exsiccatum
|
64
|
String exsiccatum = null;
|
65
|
try {
|
66
|
exsiccatum = facade.getExsiccatum();
|
67
|
} catch (MethodNotSupportedByDerivedUnitTypeException e) {
|
68
|
//NO exsiccatum if this facade doe not represent a specimen
|
69
|
}
|
70
|
result = CdmUtils.concat("; ", result, exsiccatum);
|
71
|
|
72
|
//Herbarium & identifier
|
73
|
String code = getCode(facade);
|
74
|
String identifier = getUnitNumber(facade /*, code*/);
|
75
|
String collectionData = CdmUtils.concat(" ", code, identifier);
|
76
|
if (StringUtils.isNotBlank(collectionData)) {
|
77
|
result = (result + " (" + collectionData + ")").trim();
|
78
|
}
|
79
|
|
80
|
//result
|
81
|
result = fieldStrategy.addPlantDescription(result, facade);
|
82
|
|
83
|
|
84
|
} catch (DerivedUnitFacadeNotSupportedException e) {
|
85
|
e.printStackTrace();
|
86
|
}
|
87
|
|
88
|
|
89
|
return result;
|
90
|
}
|
91
|
|
92
|
|
93
|
/**
|
94
|
* Computes the unit number which might be an accession number, barcode, catalogue number, ...
|
95
|
* In future if the unit number starts with the same string as the barcode
|
96
|
* it might be replaced.
|
97
|
* @param facade the derived unit facade
|
98
|
*/
|
99
|
private String getUnitNumber(DerivedUnitFacade facade) {
|
100
|
String result;
|
101
|
if (isNotBlank(facade.getAccessionNumber())){
|
102
|
result = facade.getAccessionNumber();
|
103
|
}else if (isNotBlank(facade.getBarcode())){
|
104
|
result = facade.getBarcode();
|
105
|
}else{
|
106
|
result = facade.getCatalogNumber();
|
107
|
}
|
108
|
return result;
|
109
|
|
110
|
}
|
111
|
|
112
|
|
113
|
/**
|
114
|
* @param facade
|
115
|
*/
|
116
|
private String getCode(DerivedUnitFacade facade) {
|
117
|
String code = "";
|
118
|
if(facade.getCollection() != null){
|
119
|
code = facade.getCollection().getCode();
|
120
|
if (StringUtils.isBlank(code)){
|
121
|
Institution institution = facade.getCollection().getInstitute();
|
122
|
if (institution != null){
|
123
|
code = institution.getCode();
|
124
|
}
|
125
|
if (StringUtils.isBlank(code)){
|
126
|
Collection superCollection = facade.getCollection().getSuperCollection();
|
127
|
if (superCollection != null){
|
128
|
code = superCollection.getCode();
|
129
|
}
|
130
|
}
|
131
|
}
|
132
|
}
|
133
|
return code;
|
134
|
}
|
135
|
|
136
|
// ************************** GETTER / SETTER ******************************************************
|
137
|
|
138
|
public boolean isIncludeSeconds() {
|
139
|
return includeEmptySeconds;
|
140
|
}
|
141
|
|
142
|
public void setIncludeSeconds(boolean includeSeconds) {
|
143
|
this.includeEmptySeconds = includeSeconds;
|
144
|
}
|
145
|
|
146
|
public void setIncludeReferenceSystem(boolean includeReferenceSystem) {
|
147
|
this.includeReferenceSystem = includeReferenceSystem;
|
148
|
}
|
149
|
|
150
|
public boolean isIncludeReferenceSystem() {
|
151
|
return includeReferenceSystem;
|
152
|
}
|
153
|
|
154
|
}
|