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.logging.log4j.LogManager;import org.apache.logging.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
|
import eu.etaxonomy.cdm.model.term.DefinedTerm;
|
21
|
|
22
|
/**
|
23
|
* A default cache strategy for {@link DnaSample}.
|
24
|
*
|
25
|
* TODO This is a <b>preliminary</b> implementation to have at least one default cache strategy.
|
26
|
* It will need improvement later on.
|
27
|
*
|
28
|
* #5575
|
29
|
*
|
30
|
* Also see DerivedUnitFacadeCacheStrategy in Service Layer.
|
31
|
*
|
32
|
* @author a.mueller
|
33
|
* @since 09.01.2021
|
34
|
*/
|
35
|
public class DnaSampleDefaultCacheStrategy
|
36
|
extends OccurrenceCacheStrategyBase<DnaSample>{
|
37
|
|
38
|
private static final long serialVersionUID = -7166834437359037691L;
|
39
|
|
40
|
@SuppressWarnings("unused")
|
41
|
private static final Logger logger = LogManager.getLogger(DnaSampleDefaultCacheStrategy.class);
|
42
|
|
43
|
private static final UUID uuid = UUID.fromString("48e72fbc-9714-4df6-b031-ba361fbf3f59");
|
44
|
|
45
|
@Override
|
46
|
protected UUID getUuid() {
|
47
|
return uuid;
|
48
|
}
|
49
|
|
50
|
@Override
|
51
|
protected String doGetTitleCache(DnaSample dnaSample) {
|
52
|
String result = getCollectionAndAccession(dnaSample);
|
53
|
//sample designation
|
54
|
if (isBlank(result)){
|
55
|
result = dnaSample.getIdentifierString(DefinedTerm.uuidSampleDesignation);
|
56
|
}
|
57
|
//any other identifier
|
58
|
if (isBlank(result)){
|
59
|
if (!dnaSample.getIdentifiers().isEmpty()){
|
60
|
result = dnaSample.getIdentifiers().get(0).getIdentifier();
|
61
|
}
|
62
|
}
|
63
|
if (isBlank(result)){
|
64
|
if (!dnaSample.getDefinition().isEmpty()){
|
65
|
Language key = dnaSample.getDefinition().keySet().iterator().next();
|
66
|
result = truncate(dnaSample.getDefinition().get(key).getText(), 50);
|
67
|
}
|
68
|
}
|
69
|
if (isBlank(result)){
|
70
|
if (!dnaSample.getSequences().isEmpty()){
|
71
|
Sequence seq = dnaSample.getSequences().iterator().next();
|
72
|
if (seq != null){
|
73
|
result = seq.getSequenceString();
|
74
|
}
|
75
|
}
|
76
|
}
|
77
|
if (isBlank(result)){
|
78
|
if (!dnaSample.getSources().isEmpty()){
|
79
|
for (IdentifiableSource source : dnaSample.getSources()){
|
80
|
if (isNotBlank(source.getIdInSource())){
|
81
|
result = CdmUtils.concat(":", source.getIdNamespace(), source.getIdInSource());
|
82
|
}
|
83
|
}
|
84
|
}
|
85
|
}
|
86
|
|
87
|
return result;
|
88
|
}
|
89
|
|
90
|
//NOTE: this is a first implementation, it may be adapted in future
|
91
|
@Override
|
92
|
protected String doGetIdentityCache(DnaSample dnaSample) {
|
93
|
String result = getCollectionAndAccession(dnaSample);
|
94
|
//sample designation
|
95
|
if (isBlank(result)){
|
96
|
result = dnaSample.getIdentifierString(DefinedTerm.uuidSampleDesignation);
|
97
|
}
|
98
|
//any other identifier
|
99
|
if (isBlank(result)){
|
100
|
if (!dnaSample.getIdentifiers().isEmpty()){
|
101
|
result = dnaSample.getIdentifiers().get(0).getIdentifier();
|
102
|
}
|
103
|
}
|
104
|
if (isBlank(result)){
|
105
|
return doGetTitleCache(dnaSample);
|
106
|
}else{
|
107
|
return result;
|
108
|
}
|
109
|
}
|
110
|
}
|