Project

General

Profile

Revision 30d532b8

ID30d532b8fc78b7533ec0b72097fb644209f243f9
Parent 34b111d7
Child f0559e00

Added by Andreas Müller over 3 years ago

ref #6449 Avoid empty titleCaches if only one cache is protected

View differences:

cdmlib-model/src/main/java/eu/etaxonomy/cdm/model/reference/Reference.java
368 368

  
369 369
//*************************** GETTER / SETTER ******************************************/
370 370

  
371
    // @Transient  - must not be transient, since this property needs to to be included in all serializations produced by the remote layer
372
    @Override
373
    public String getTitleCache(){
374
        String result = super.getTitleCache();
375
        if (isBlank(result)){
376
            this.titleCache = this.getAbbrevTitleCache(true);
377
        }
378
        return titleCache;
379
    }
371 380

  
372 381
	@Override
373 382
	public String getAbbrevTitleCache() {
374
		if (protectedAbbrevTitleCache){
383
		return getAbbrevTitleCache(false);
384
	}
385

  
386
	/**
387
	 * Implements {@link #getAbbrevTitleCache()} but allows to
388
	 * avoid never ending recursions if both caches are empty
389
	 * avoidRecursion should only be <code>true</code> if called
390
	 * by {@link #getTitleCache()}
391
	 * @param avoidRecursion
392
	 * @return
393
	 */
394
	private String getAbbrevTitleCache(boolean avoidRecursion) {
395
        if (protectedAbbrevTitleCache){
375 396
            return this.abbrevTitleCache;
376 397
        }
377 398
        // is reference dirty, i.e. equal NULL?
......
379 400
            this.abbrevTitleCache = generateAbbrevTitle();
380 401
            this.abbrevTitleCache = getTruncatedCache(this.abbrevTitleCache) ;
381 402
        }
403
        if (isBlank(abbrevTitleCache) && !avoidRecursion){
404
            this.abbrevTitleCache = this.getTitleCache();
405
        }
382 406
        return abbrevTitleCache;
383
	}
407
    }
384 408

  
385
	@Override
409

  
410
    @Override
386 411
	@Deprecated
387 412
	public void setAbbrevTitleCache(String abbrevTitleCache) {
388 413
		this.abbrevTitleCache = abbrevTitleCache;
cdmlib-model/src/test/java/eu/etaxonomy/cdm/model/reference/ReferenceTest.java
1
/**
2
* Copyright (C) 2017 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.model.reference;
10

  
11
import org.junit.Assert;
12
import org.junit.Before;
13
import org.junit.Test;
14

  
15

  
16
/**
17
 * @author a.mueller
18
 * @date 02.03.2017
19
 *
20
 */
21
public class ReferenceTest {
22

  
23
    private Reference genericRef;
24

  
25
    /**
26
     * @throws java.lang.Exception
27
     */
28
    @Before
29
    public void setUp() throws Exception {
30
        genericRef = ReferenceFactory.newGeneric();
31
    }
32

  
33
    @Test
34
    public void testOnlyProtectedTitleCache() {
35
        String titleCache = "Any reference title cache";
36
        genericRef.setTitleCache(titleCache, true);
37
        Assert.assertEquals(titleCache, genericRef.getTitleCache());
38
        Assert.assertEquals(titleCache, genericRef.getAbbrevTitleCache());
39
    }
40

  
41
    @Test
42
    public void testOnlyProtectedAbbrevTitleCache() {
43
        String titleCache = "A. ref. tit. ca.";
44
        genericRef.setAbbrevTitleCache(titleCache, true);
45
        Assert.assertEquals(titleCache, genericRef.getAbbrevTitleCache());
46
        Assert.assertEquals(titleCache, genericRef.getTitleCache());
47
    }
48

  
49
    /**
50
     * Test to avoid infinite recursion here.
51
     */
52
    @Test
53
    public void testTwoEmptyTitleCaches() {
54
        Assert.assertEquals("", genericRef.getAbbrevTitleCache());
55
        Assert.assertEquals("", genericRef.getTitleCache());
56
    }
57

  
58
}

Also available in: Unified diff

Add picture from clipboard (Maximum size: 40 MB)