Project

General

Profile

Download (2.77 KB) Statistics
| Branch: | Tag: | Revision:
1
/**
2
* Copyright (C) 2007 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.occurrence;
10

    
11
import java.util.UUID;
12

    
13
import org.apache.log4j.Logger;
14

    
15
import eu.etaxonomy.cdm.common.CdmUtils;
16
import eu.etaxonomy.cdm.model.common.IdentifiableSource;
17
import eu.etaxonomy.cdm.model.common.Language;
18
import eu.etaxonomy.cdm.model.molecular.DnaSample;
19
import eu.etaxonomy.cdm.model.molecular.Sequence;
20

    
21
/**
22
 * A default cache strategy for {@link DnaSample}.
23
 *
24
 * TODO This is a <b>preliminary</b> implementation to have at least one default cache strategy.
25
 * It will need improvement later on.
26
 *
27
 *  #5575
28
 *
29
 * Also see DerivedUnitFacadeCacheStrategy in Service Layer.
30
 *
31
 * @author a.mueller
32
 * @since 09.01.2021
33
 */
34
public class DnaSampleDefaultCacheStrategy
35
        extends OccurrenceCacheStrategyBase<DnaSample>{
36

    
37
    private static final long serialVersionUID = -7166834437359037691L;
38

    
39
    @SuppressWarnings("unused")
40
	private static final Logger logger = Logger.getLogger(DnaSampleDefaultCacheStrategy.class);
41

    
42
	private static final UUID uuid = UUID.fromString("48e72fbc-9714-4df6-b031-ba361fbf3f59");
43

    
44
	@Override
45
	protected UUID getUuid() {
46
		return uuid;
47
	}
48

    
49
	@Override
50
    protected String doGetTitleCache(DnaSample dnaSample) {
51
		String result = getCollectionAndAccession(dnaSample);
52
		//TODO still very unclear what to use, currently it is best practice to create
53
		//a protected titleCache when creating the DnaSample so the application
54
		//decides what title to give
55
		if (isBlank(result)){
56
		    if (!dnaSample.getIdentifiers().isEmpty()){
57
		        result = dnaSample.getIdentifiers().get(0).getIdentifier();
58
		    }
59
		}
60
        if (isBlank(result)){
61
            if (!dnaSample.getDefinition().isEmpty()){
62
                Language key = dnaSample.getDefinition().keySet().iterator().next();
63
                result = truncate(dnaSample.getDefinition().get(key).getText(), 50);
64
            }
65
        }
66
        if (isBlank(result)){
67
            if (!dnaSample.getSequences().isEmpty()){
68
                Sequence seq = dnaSample.getSequences().iterator().next();
69
                if (seq != null){
70
                    result = seq.getSequenceString();
71
                }
72
            }
73
        }
74
        if (isBlank(result)){
75
            if (!dnaSample.getSources().isEmpty()){
76
                for (IdentifiableSource source : dnaSample.getSources()){
77
                    if (isNotBlank(source.getIdInSource())){
78
                        result = CdmUtils.concat(":", source.getIdNamespace(), source.getIdInSource());
79
                    }
80
                }
81
            }
82

    
83
        }
84

    
85
		return result;
86
	}
87
}
(2-2/4)