Project

General

Profile

Download (2.29 KB) Statistics
| Branch: | Tag: | Revision:
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.logging.log4j.LogManager;import org.apache.logging.log4j.Logger;
14

    
15
import eu.etaxonomy.cdm.model.common.Language;
16
import eu.etaxonomy.cdm.model.term.Representation;
17
import eu.etaxonomy.cdm.model.term.TermBase;
18
import eu.etaxonomy.cdm.strategy.cache.common.IIdentifiableEntityCacheStrategy;
19
import eu.etaxonomy.cdm.strategy.cache.common.IdentifiableEntityDefaultCacheStrategy;
20

    
21
/**
22
 * @author a.mueller
23
 * @since 19.05.2010
24
 */
25
public class TermDefaultCacheStrategy<T extends TermBase> extends IdentifiableEntityDefaultCacheStrategy<T> implements IIdentifiableEntityCacheStrategy<T> {
26
	private static final long serialVersionUID = 7687293307791110547L;
27

    
28
	@SuppressWarnings("unused")
29
	private static final Logger logger = LogManager.getLogger(TermDefaultCacheStrategy.class);
30

    
31
	final static UUID uuid = UUID.fromString("9cdf52c1-bac4-4b6c-a7f9-1a87401bd8f9");
32

    
33
	@Override
34
	protected UUID getUuid() {
35
		return uuid;
36
	}
37

    
38
	@SuppressWarnings({ })
39
    public static <T extends TermBase> TermDefaultCacheStrategy<T> NewInstance(@SuppressWarnings("unused") Class<T> clazz){
40
	    return new TermDefaultCacheStrategy<T>();
41
	}
42

    
43
	private TermDefaultCacheStrategy(){}
44

    
45
	@Override
46
	public String getTitleCache(T term) {
47
		String result = null;
48
		if (term.getRepresentations().size() > 0) {
49
			//use default representation (or if not exist any other)
50
			Representation representation = term.getRepresentation(Language.DEFAULT());
51
			if (representation == null){
52
				representation = term.getRepresentations().iterator().next();
53
			}
54
			//return label, or if not exists abbreviated label, of if not exists description
55
			result = representation.getLabel();
56
			if (isBlank(result)){
57
					result = representation.getAbbreviatedLabel();
58
			}
59
			if (isBlank(result)){
60
				result = representation.getText();
61
				representation.getDescription();
62
			}
63
		}
64
		//if still empty return toString
65
		if (isBlank(result)){
66
			result = term.getClass().getSimpleName() + "<" + term.getUuid() + ">";
67
		}
68
		return result;
69
	}
70
}
    (1-1/1)