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
|
import java.util.stream.Collectors;
|
13
|
|
14
|
import org.apache.commons.lang.StringUtils;
|
15
|
import org.apache.logging.log4j.LogManager;import org.apache.logging.log4j.Logger;
|
16
|
|
17
|
import eu.etaxonomy.cdm.common.CdmUtils;
|
18
|
import eu.etaxonomy.cdm.model.agent.Institution;
|
19
|
import eu.etaxonomy.cdm.model.common.Language;
|
20
|
import eu.etaxonomy.cdm.model.occurrence.Collection;
|
21
|
import eu.etaxonomy.cdm.model.occurrence.DerivedUnit;
|
22
|
import eu.etaxonomy.cdm.strategy.StrategyBase;
|
23
|
import eu.etaxonomy.cdm.strategy.cache.common.IIdentifiableEntityCacheStrategy;
|
24
|
import eu.etaxonomy.cdm.strategy.cache.occurrence.DerivedUnitDefaultCacheStrategy;
|
25
|
|
26
|
/**
|
27
|
* @author a.mueller
|
28
|
* @since 03.06.2010
|
29
|
*
|
30
|
* @deprecated with #9678 a similar cache strategy (DerivedUnitCacheStrategy)
|
31
|
* was implemented in cdmlib-model. This class may be removed in future.
|
32
|
*/
|
33
|
@Deprecated
|
34
|
public class DerivedUnitFacadeCacheStrategy
|
35
|
extends StrategyBase
|
36
|
implements IIdentifiableEntityCacheStrategy<DerivedUnit> {
|
37
|
|
38
|
private static final long serialVersionUID = 1578628591216605619L;
|
39
|
@SuppressWarnings("unused")
|
40
|
private static final Logger logger = LogManager.getLogger(DerivedUnitFacadeCacheStrategy.class);
|
41
|
|
42
|
private static final UUID uuid = UUID.fromString("df4672c1-ce5c-4724-af6d-91e2b326d4a4");
|
43
|
|
44
|
@Override
|
45
|
protected UUID getUuid() {return uuid;}
|
46
|
|
47
|
private boolean includeEmptySeconds = false;
|
48
|
private boolean includeReferenceSystem = true;
|
49
|
|
50
|
private String collectionAccessionSeperator = ": ";
|
51
|
|
52
|
private boolean addTrailingDot = false;
|
53
|
|
54
|
public static DerivedUnitFacadeCacheStrategy NewInstance(){
|
55
|
return new DerivedUnitFacadeCacheStrategy();
|
56
|
}
|
57
|
|
58
|
public static DerivedUnitFacadeCacheStrategy NewInstance(boolean addTrailingDot){
|
59
|
return new DerivedUnitFacadeCacheStrategy(addTrailingDot, null);
|
60
|
}
|
61
|
|
62
|
public static DerivedUnitFacadeCacheStrategy NewInstance( boolean addTrailingDot, String collectionAccessionSeperator){
|
63
|
return new DerivedUnitFacadeCacheStrategy(addTrailingDot, collectionAccessionSeperator);
|
64
|
}
|
65
|
|
66
|
|
67
|
//******************************* CONSTRUCTOR *******************************************/
|
68
|
|
69
|
//default value constructor
|
70
|
private DerivedUnitFacadeCacheStrategy() {}
|
71
|
|
72
|
private DerivedUnitFacadeCacheStrategy(boolean addTrailingDot, String collectionAccessionSeperator) {
|
73
|
this.addTrailingDot = addTrailingDot;
|
74
|
if (collectionAccessionSeperator != null){
|
75
|
this.collectionAccessionSeperator = collectionAccessionSeperator;
|
76
|
}
|
77
|
}
|
78
|
|
79
|
|
80
|
@Override
|
81
|
public String getTitleCache(DerivedUnit derivedUnit) {
|
82
|
return getTitleCache(derivedUnit, false);
|
83
|
}
|
84
|
|
85
|
public String getTitleCache(DerivedUnit derivedUnit, boolean skipFieldUnit) {
|
86
|
|
87
|
String result = "";
|
88
|
DerivedUnitFacadeFieldUnitCacheStrategy fieldStrategy = new DerivedUnitFacadeFieldUnitCacheStrategy();
|
89
|
|
90
|
DerivedUnitFacade facade;
|
91
|
// NOTE: regarding the string representations of MediaTypes, see https://dev.e-taxonomy.eu/redmine/issues/7608
|
92
|
try {
|
93
|
DerivedUnitFacadeConfigurator config = DerivedUnitFacadeConfigurator.NewInstance();
|
94
|
config.setFirePropertyChangeEvents(false);
|
95
|
facade = DerivedUnitFacade.NewInstance(derivedUnit, config);
|
96
|
|
97
|
if(!skipFieldUnit){
|
98
|
result += fieldStrategy.getFieldData(facade);
|
99
|
}
|
100
|
|
101
|
//exsiccatum
|
102
|
String exsiccatum = null;
|
103
|
try {
|
104
|
exsiccatum = facade.getExsiccatum();
|
105
|
} catch (MethodNotSupportedByDerivedUnitTypeException e) {
|
106
|
//NO exsiccatum if this facade doe not represent a specimen
|
107
|
}
|
108
|
result = CdmUtils.concat("; ", result, exsiccatum);
|
109
|
|
110
|
//Herbarium & identifier
|
111
|
String barcode = getSpecimenLabel(facade);
|
112
|
if (StringUtils.isNotBlank(barcode)) {
|
113
|
result = (result + " (" + barcode + ")").trim();
|
114
|
}
|
115
|
//result
|
116
|
result = fieldStrategy.addPlantDescription(result, facade);
|
117
|
|
118
|
if (addTrailingDot){
|
119
|
result = CdmUtils.addTrailingDotIfNotExists(result);
|
120
|
}
|
121
|
|
122
|
} catch (DerivedUnitFacadeNotSupportedException e) {
|
123
|
e.printStackTrace();
|
124
|
}
|
125
|
|
126
|
return result;
|
127
|
}
|
128
|
|
129
|
/**
|
130
|
* Produces the collection barcode which is the combination of the collection code and
|
131
|
* accession number.
|
132
|
*
|
133
|
* @param result
|
134
|
* @param facade
|
135
|
* @return
|
136
|
*/
|
137
|
public String getSpecimenLabel(DerivedUnitFacade facade) {
|
138
|
String code = getCode(facade);
|
139
|
String identifier = getUnitNumber(facade /*, code*/);
|
140
|
String collectionData = CdmUtils.concat(collectionAccessionSeperator, code, identifier);
|
141
|
String specimenStatusStr = getSpecimenStatusStr(facade.innerDerivedUnit());
|
142
|
collectionData = CdmUtils.concat(", " , collectionData, specimenStatusStr);
|
143
|
return collectionData;
|
144
|
}
|
145
|
|
146
|
|
147
|
/**
|
148
|
* Computes the unit number which might be an accession number, barcode, catalogue number, ...
|
149
|
* In future if the unit number starts with the same string as the barcode
|
150
|
* it might be replaced.
|
151
|
* @param facade the derived unit facade
|
152
|
*/
|
153
|
private String getUnitNumber(DerivedUnitFacade facade) {
|
154
|
String result;
|
155
|
if (isNotBlank(facade.getAccessionNumber())){
|
156
|
result = facade.getAccessionNumber();
|
157
|
}else if (isNotBlank(facade.getBarcode())){
|
158
|
result = facade.getBarcode();
|
159
|
}else{
|
160
|
result = facade.getCatalogNumber();
|
161
|
}
|
162
|
String code = getCode(facade);
|
163
|
if(result != null){
|
164
|
result = result.trim();
|
165
|
if(isNotBlank(code) && result.startsWith(code + " ")){
|
166
|
result = result.replaceAll("^" + code + "\\s", "");
|
167
|
}
|
168
|
}
|
169
|
return result;
|
170
|
}
|
171
|
|
172
|
private String getCode(DerivedUnitFacade facade) {
|
173
|
String code = "";
|
174
|
if(facade.getCollection() != null){
|
175
|
code = facade.getCollection().getCode();
|
176
|
if (StringUtils.isBlank(code)){
|
177
|
code = facade.getCollection().getName();
|
178
|
}
|
179
|
if (StringUtils.isBlank(code)){
|
180
|
Institution institution = facade.getCollection().getInstitute();
|
181
|
if (institution != null){
|
182
|
code = institution.getCode();
|
183
|
}
|
184
|
if (StringUtils.isBlank(code)){
|
185
|
Collection superCollection = facade.getCollection().getSuperCollection();
|
186
|
if (superCollection != null){
|
187
|
code = superCollection.getCode();
|
188
|
}
|
189
|
}
|
190
|
}
|
191
|
}
|
192
|
return code;
|
193
|
}
|
194
|
//copied from DerivedUnitDefaultCacheStrategy
|
195
|
private String getSpecimenStatusStr(DerivedUnit specimen) {
|
196
|
String result = null;
|
197
|
if (!specimen.getStatus().isEmpty()){
|
198
|
result = specimen.getStatus()
|
199
|
.stream()
|
200
|
.map(s->s.getType())
|
201
|
.filter(t->t != null)
|
202
|
.map(t->t.getPreferredRepresentation(Language.DEFAULT()).getLabel())
|
203
|
.sorted((s1,s2)->s1.compareTo(s2))
|
204
|
.collect(Collectors.joining(", "));
|
205
|
}
|
206
|
return result;
|
207
|
}
|
208
|
|
209
|
// ************************** GETTER / SETTER ******************************************************
|
210
|
|
211
|
public boolean isIncludeSeconds() {
|
212
|
return includeEmptySeconds;
|
213
|
}
|
214
|
|
215
|
public void setIncludeSeconds(boolean includeSeconds) {
|
216
|
this.includeEmptySeconds = includeSeconds;
|
217
|
}
|
218
|
|
219
|
public void setIncludeReferenceSystem(boolean includeReferenceSystem) {
|
220
|
this.includeReferenceSystem = includeReferenceSystem;
|
221
|
}
|
222
|
|
223
|
public boolean isIncludeReferenceSystem() {
|
224
|
return includeReferenceSystem;
|
225
|
}
|
226
|
|
227
|
public boolean isAddTrailingDot() {
|
228
|
return addTrailingDot;
|
229
|
}
|
230
|
|
231
|
public void setAddTrailingDot(boolean addTrailingDot) {
|
232
|
this.addTrailingDot = addTrailingDot;
|
233
|
}
|
234
|
|
235
|
}
|