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