Revision 197a9558
Added by Andreas Müller over 3 years ago
cdmlib-model/src/main/java/eu/etaxonomy/cdm/model/occurrence/MediaSpecimen.java | ||
---|---|---|
28 | 28 |
import org.hibernate.search.annotations.Indexed; |
29 | 29 |
|
30 | 30 |
import eu.etaxonomy.cdm.model.media.Media; |
31 |
import eu.etaxonomy.cdm.strategy.cache.common.IdentifiableEntityDefaultCacheStrategy;
|
|
31 |
import eu.etaxonomy.cdm.strategy.cache.occurrence.MediaSpecimenDefaultCacheStrategy;
|
|
32 | 32 |
|
33 | 33 |
/** |
34 | 34 |
* Instances of MediaSpecimen represent a specimen which IS a media (photo, drawing, ...). |
... | ... | |
86 | 86 |
|
87 | 87 |
private MediaSpecimen(SpecimenOrObservationType type) { |
88 | 88 |
super(type); |
89 |
this.cacheStrategy = new IdentifiableEntityDefaultCacheStrategy<DerivedUnit>();
|
|
89 |
this.cacheStrategy = new MediaSpecimenDefaultCacheStrategy();
|
|
90 | 90 |
} |
91 | 91 |
|
92 | 92 |
|
cdmlib-model/src/main/java/eu/etaxonomy/cdm/strategy/cache/occurrence/MediaSpecimenDefaultCacheStrategy.java | ||
---|---|---|
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.occurrence.Collection; |
|
17 |
import eu.etaxonomy.cdm.model.occurrence.MediaSpecimen; |
|
18 |
import eu.etaxonomy.cdm.strategy.StrategyBase; |
|
19 |
import eu.etaxonomy.cdm.strategy.cache.common.IIdentifiableEntityCacheStrategy; |
|
20 |
|
|
21 |
/** |
|
22 |
* A default cache strategy for MediaSpecimen. |
|
23 |
* TODO This is a <b>preliminary</b> implementation to have at least one default cache strategy. |
|
24 |
* It will need improvement later on. |
|
25 |
* |
|
26 |
* Also see DerivedUnitFacadeCacheStrategy in Service Layer. |
|
27 |
* |
|
28 |
* @author a.mueller |
|
29 |
* @since 08.01.2021 |
|
30 |
*/ |
|
31 |
public class MediaSpecimenDefaultCacheStrategy |
|
32 |
extends StrategyBase |
|
33 |
implements IIdentifiableEntityCacheStrategy<MediaSpecimen>{ |
|
34 |
|
|
35 |
private static final long serialVersionUID = 798148956185549004L; |
|
36 |
@SuppressWarnings("unused") |
|
37 |
private static final Logger logger = Logger.getLogger(MediaSpecimenDefaultCacheStrategy.class); |
|
38 |
|
|
39 |
private static final UUID uuid = UUID.fromString("2df06501-0e2f-4255-b1e6-091be7293f7c"); |
|
40 |
|
|
41 |
@Override |
|
42 |
protected UUID getUuid() { |
|
43 |
return uuid; |
|
44 |
} |
|
45 |
|
|
46 |
@Override |
|
47 |
public String getTitleCache(MediaSpecimen mediaSpecimen) { |
|
48 |
if (mediaSpecimen == null){ |
|
49 |
return null; |
|
50 |
}else{ |
|
51 |
String result = ""; |
|
52 |
//add code if it exists |
|
53 |
if (mediaSpecimen.getCollection() != null){ |
|
54 |
Collection collection = mediaSpecimen.getCollection(); |
|
55 |
if (isNotBlank(collection.getCode())){ |
|
56 |
result = CdmUtils.concat("", result, collection.getCode()); |
|
57 |
} |
|
58 |
} |
|
59 |
result = CdmUtils.concat(" ", result, CdmUtils.Ne(mediaSpecimen.getAccessionNumber())); |
|
60 |
String mediaTitle = mediaSpecimen.getMediaSpecimen() == null? null : mediaSpecimen.getMediaSpecimen().getTitleCache(); |
|
61 |
if (isNotBlank(mediaTitle)){ |
|
62 |
if (isNotBlank(result)){ |
|
63 |
result += " (" + mediaTitle +")"; |
|
64 |
}else{ |
|
65 |
result = mediaTitle; |
|
66 |
} |
|
67 |
} |
|
68 |
if (isBlank(result)){ |
|
69 |
result = mediaSpecimen.toString(); |
|
70 |
} |
|
71 |
|
|
72 |
return result; |
|
73 |
} |
|
74 |
} |
|
75 |
} |
cdmlib-model/src/test/java/eu/etaxonomy/cdm/strategy/cache/occurrence/MediaSpecimenDefaultCacheStrategyTest.java | ||
---|---|---|
1 |
/** |
|
2 |
* Copyright (C) 2021 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.junit.Assert; |
|
14 |
import org.junit.Test; |
|
15 |
|
|
16 |
import eu.etaxonomy.cdm.model.media.Media; |
|
17 |
import eu.etaxonomy.cdm.model.occurrence.Collection; |
|
18 |
import eu.etaxonomy.cdm.model.occurrence.MediaSpecimen; |
|
19 |
import eu.etaxonomy.cdm.model.occurrence.SpecimenOrObservationType; |
|
20 |
import eu.etaxonomy.cdm.test.TermTestBase; |
|
21 |
|
|
22 |
/** |
|
23 |
* @author a.mueller |
|
24 |
* @since 08.01.2021 |
|
25 |
*/ |
|
26 |
public class MediaSpecimenDefaultCacheStrategyTest extends TermTestBase { |
|
27 |
|
|
28 |
@Test |
|
29 |
public void test() { |
|
30 |
MediaSpecimen specimen = MediaSpecimen.NewInstance(SpecimenOrObservationType.Media); |
|
31 |
specimen.setUuid(UUID.fromString("b5fa679f-12a1-4f47-906a-28b41c90f019")); |
|
32 |
MediaSpecimenDefaultCacheStrategy strategy = new MediaSpecimenDefaultCacheStrategy(); |
|
33 |
|
|
34 |
Assert.assertEquals("MediaSpecimen#0<b5fa679f-12a1-4f47-906a-28b41c90f019>", strategy.getTitleCache(specimen)); |
|
35 |
|
|
36 |
Collection collection = Collection.NewInstance(); |
|
37 |
collection.setCode("B"); |
|
38 |
specimen.setCollection(collection); |
|
39 |
Assert.assertEquals("B", strategy.getTitleCache(specimen)); |
|
40 |
|
|
41 |
specimen.setAccessionNumber("123"); |
|
42 |
Assert.assertEquals("B 123", strategy.getTitleCache(specimen)); |
|
43 |
|
|
44 |
Media media = Media.NewInstance(); |
|
45 |
media.setTitleCache("Media title"); |
|
46 |
specimen.setMediaSpecimen(media); |
|
47 |
Assert.assertEquals("B 123 (Media title)", strategy.getTitleCache(specimen)); |
|
48 |
|
|
49 |
specimen.setCollection(null); |
|
50 |
specimen.setAccessionNumber(null); |
|
51 |
Assert.assertEquals("Media title", strategy.getTitleCache(specimen)); |
|
52 |
} |
|
53 |
} |
Also available in: Unified diff
ref #7612 a first (preliminary) version of MediaSpecimenDefaultCacheStrategy