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.strategy.cache.common;
|
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.model.common.Language;
|
17
|
import eu.etaxonomy.cdm.model.common.Representation;
|
18
|
import eu.etaxonomy.cdm.model.common.TermBase;
|
19
|
|
20
|
/**
|
21
|
* @author a.mueller
|
22
|
* @date 19.05.2010
|
23
|
*
|
24
|
*/
|
25
|
public class TermDefaultCacheStrategy<T extends TermBase> extends IdentifiableEntityDefaultCacheStrategy<T> implements IIdentifiableEntityCacheStrategy<T> {
|
26
|
/**
|
27
|
*
|
28
|
*/
|
29
|
private static final long serialVersionUID = 7687293307791110547L;
|
30
|
|
31
|
@SuppressWarnings("unused")
|
32
|
private static final Logger logger = Logger.getLogger(TermDefaultCacheStrategy.class);
|
33
|
|
34
|
final static UUID uuid = UUID.fromString("9cdf52c1-bac4-4b6c-a7f9-1a87401bd8f9");
|
35
|
|
36
|
@Override
|
37
|
protected UUID getUuid() {
|
38
|
return uuid;
|
39
|
}
|
40
|
|
41
|
@Override
|
42
|
public String getTitleCache(T term) {
|
43
|
String result = null;
|
44
|
if (term.getRepresentations().size() > 0) {
|
45
|
//use default representation (or if not exist any other)
|
46
|
Representation representation = term.getRepresentation(Language.DEFAULT());
|
47
|
if (representation == null){
|
48
|
representation = term.getRepresentations().iterator().next();
|
49
|
}
|
50
|
//return label, or if not exists abbreviated label, of if not exists description
|
51
|
result = representation.getLabel();
|
52
|
if (StringUtils.isBlank(result)){
|
53
|
result = representation.getAbbreviatedLabel();
|
54
|
}
|
55
|
if (StringUtils.isBlank(result)){
|
56
|
result = representation.getText();
|
57
|
representation.getDescription();
|
58
|
}
|
59
|
}
|
60
|
//if still empty return toString
|
61
|
if (StringUtils.isBlank(result)){
|
62
|
result = term.getClass().getSimpleName() + "<" + term.getUuid() + ">";
|
63
|
}
|
64
|
return result;
|
65
|
}
|
66
|
|
67
|
}
|