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.model.common.LanguageString;
|
16
|
import eu.etaxonomy.cdm.model.occurrence.MediaSpecimen;
|
17
|
|
18
|
/**
|
19
|
* A default cache strategy for {@link MediaSpecimen}.
|
20
|
* TODO This is a <b>preliminary</b> implementation to have at least one default cache strategy.
|
21
|
* It will need improvement later on.
|
22
|
*
|
23
|
* #5573, #7612
|
24
|
*
|
25
|
* Also see DerivedUnitFacadeCacheStrategy in Service Layer.
|
26
|
*
|
27
|
* @author a.mueller
|
28
|
* @since 08.01.2021
|
29
|
*/
|
30
|
public class MediaSpecimenDefaultCacheStrategy
|
31
|
extends OccurrenceCacheStrategyBase<MediaSpecimen>{
|
32
|
|
33
|
private static final long serialVersionUID = 798148956185549004L;
|
34
|
@SuppressWarnings("unused")
|
35
|
private static final Logger logger = LogManager.getLogger(MediaSpecimenDefaultCacheStrategy.class);
|
36
|
|
37
|
private static final UUID uuid = UUID.fromString("2df06501-0e2f-4255-b1e6-091be7293f7c");
|
38
|
|
39
|
@Override
|
40
|
protected UUID getUuid() {
|
41
|
return uuid;
|
42
|
}
|
43
|
|
44
|
@Override
|
45
|
protected String doGetTitleCache(MediaSpecimen specimen) {
|
46
|
//add code if it exists
|
47
|
String result = getCollectionAndAccession(specimen);
|
48
|
if (specimen.getMediaSpecimen() != null){
|
49
|
if (isBlank(result)){
|
50
|
result = specimen.getMediaSpecimen().getTitleCache();
|
51
|
if (result.startsWith("- empty media - <")){ //empty media we do not want to handle Media level but on MediaSpecimen level
|
52
|
result = null;
|
53
|
}
|
54
|
}else{
|
55
|
LanguageString titleLs = specimen.getMediaSpecimen().getTitle();
|
56
|
if (titleLs != null && isNotBlank(titleLs.getText())) {
|
57
|
result += " (" + titleLs.getText() +")";
|
58
|
}
|
59
|
}
|
60
|
}
|
61
|
|
62
|
return result;
|
63
|
}
|
64
|
|
65
|
//NOTE: this is a first implementation, it may be adapted in future
|
66
|
@Override
|
67
|
protected String doGetIdentityCache(MediaSpecimen mediaSpecimen) {
|
68
|
String collectionAndAccession = getCollectionAndAccession(mediaSpecimen);
|
69
|
if (isBlank(collectionAndAccession)){
|
70
|
return getTitleCache(mediaSpecimen);
|
71
|
}else{
|
72
|
return collectionAndAccession;
|
73
|
}
|
74
|
}
|
75
|
}
|