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
|
* @since 03.06.2010
|
26
|
*/
|
27
|
public class DerivedUnitFacadeCacheStrategy
|
28
|
extends StrategyBase
|
29
|
implements IIdentifiableEntityCacheStrategy<DerivedUnit> {
|
30
|
|
31
|
private static final long serialVersionUID = 1578628591216605619L;
|
32
|
@SuppressWarnings("unused")
|
33
|
private static final Logger logger = Logger.getLogger(DerivedUnitFacadeCacheStrategy.class);
|
34
|
|
35
|
private static final UUID uuid = UUID.fromString("df4672c1-ce5c-4724-af6d-91e2b326d4a4");
|
36
|
|
37
|
@Override
|
38
|
protected UUID getUuid() {return uuid;}
|
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, true);
|
46
|
}
|
47
|
|
48
|
public String getTitleCache(DerivedUnit derivedUnit, boolean skipFieldUnit, boolean addTrailingDot) {
|
49
|
|
50
|
String result = "";
|
51
|
DerivedUnitFacadeFieldUnitCacheStrategy fieldStrategy = new DerivedUnitFacadeFieldUnitCacheStrategy();
|
52
|
|
53
|
DerivedUnitFacade facade;
|
54
|
// NOTE: regarding the string representations of MediaTypes, see https://dev.e-taxonomy.eu/redmine/issues/7608
|
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
|
|
64
|
//exsiccatum
|
65
|
String exsiccatum = null;
|
66
|
try {
|
67
|
exsiccatum = facade.getExsiccatum();
|
68
|
} catch (MethodNotSupportedByDerivedUnitTypeException e) {
|
69
|
//NO exsiccatum if this facade doe not represent a specimen
|
70
|
}
|
71
|
result = CdmUtils.concat("; ", result, exsiccatum);
|
72
|
|
73
|
//Herbarium & identifier
|
74
|
String barcode = getSpecimenLabel(facade);
|
75
|
if (StringUtils.isNotBlank(barcode)) {
|
76
|
result = (result + " (" + barcode + ")").trim();
|
77
|
}
|
78
|
//result
|
79
|
result = fieldStrategy.addPlantDescription(result, facade);
|
80
|
|
81
|
if (addTrailingDot){
|
82
|
result = CdmUtils.addTrailingDotIfNotExists(result);
|
83
|
}
|
84
|
|
85
|
} catch (DerivedUnitFacadeNotSupportedException e) {
|
86
|
e.printStackTrace();
|
87
|
}
|
88
|
|
89
|
return result;
|
90
|
}
|
91
|
|
92
|
/**
|
93
|
* Produces the collection barcode which is the combination of the collection code and
|
94
|
* accession number.
|
95
|
*
|
96
|
* @param result
|
97
|
* @param facade
|
98
|
* @return
|
99
|
*/
|
100
|
public String getSpecimenLabel(DerivedUnitFacade facade) {
|
101
|
String code = getCode(facade);
|
102
|
String identifier = getUnitNumber(facade /*, code*/);
|
103
|
String collectionData = CdmUtils.concat(" ", code, identifier);
|
104
|
return collectionData;
|
105
|
}
|
106
|
|
107
|
|
108
|
/**
|
109
|
* Computes the unit number which might be an accession number, barcode, catalogue number, ...
|
110
|
* In future if the unit number starts with the same string as the barcode
|
111
|
* it might be replaced.
|
112
|
* @param facade the derived unit facade
|
113
|
*/
|
114
|
private String getUnitNumber(DerivedUnitFacade facade) {
|
115
|
String result;
|
116
|
if (isNotBlank(facade.getAccessionNumber())){
|
117
|
result = facade.getAccessionNumber();
|
118
|
}else if (isNotBlank(facade.getBarcode())){
|
119
|
result = facade.getBarcode();
|
120
|
}else{
|
121
|
result = facade.getCatalogNumber();
|
122
|
}
|
123
|
String code = getCode(facade);
|
124
|
if(result != null){
|
125
|
result = result.trim();
|
126
|
if(isNotBlank(code) && result.startsWith(code + " ")){
|
127
|
result = result.replaceAll("^" + code + "\\s", "");
|
128
|
}
|
129
|
}
|
130
|
return result;
|
131
|
}
|
132
|
|
133
|
private String getCode(DerivedUnitFacade facade) {
|
134
|
String code = "";
|
135
|
if(facade.getCollection() != null){
|
136
|
code = facade.getCollection().getCode();
|
137
|
if (StringUtils.isBlank(code)){
|
138
|
code = facade.getCollection().getName();
|
139
|
}
|
140
|
if (StringUtils.isBlank(code)){
|
141
|
Institution institution = facade.getCollection().getInstitute();
|
142
|
if (institution != null){
|
143
|
code = institution.getCode();
|
144
|
}
|
145
|
if (StringUtils.isBlank(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
|
public void setIncludeSeconds(boolean includeSeconds) {
|
163
|
this.includeEmptySeconds = includeSeconds;
|
164
|
}
|
165
|
|
166
|
public void setIncludeReferenceSystem(boolean includeReferenceSystem) {
|
167
|
this.includeReferenceSystem = includeReferenceSystem;
|
168
|
}
|
169
|
|
170
|
public boolean isIncludeReferenceSystem() {
|
171
|
return includeReferenceSystem;
|
172
|
}
|
173
|
|
174
|
}
|