Project

General

Profile

Revision cb87344f

IDcb87344fc0b0287a4617cae4546b954347d40e66
Parent 02390953
Child 74081bf8

Added by Andreas Müller over 3 years ago

cleanup

View differences:

cdmlib-model/src/main/java/eu/etaxonomy/cdm/model/agent/Person.java
23 23
import javax.xml.bind.annotation.XmlRootElement;
24 24
import javax.xml.bind.annotation.XmlType;
25 25

  
26
import org.apache.commons.lang.StringUtils;
27 26
import org.apache.log4j.Logger;
28 27
import org.hibernate.annotations.Cascade;
29 28
import org.hibernate.annotations.CascadeType;
......
251 250
	 * @see  #getPrefix()
252 251
	 */
253 252
	public void setPrefix(String prefix){
254
		this.prefix = StringUtils.isBlank(prefix) ? null : prefix;
253
		this.prefix = isBlank(prefix) ? null : prefix;
255 254
	}
256 255

  
257 256

  
......
269 268
	 * @see  #getFirstname()
270 269
	 */
271 270
	public void setFirstname(String firstname){
272
		this.firstname = StringUtils.isBlank(firstname) ? null : firstname;
271
		this.firstname = isBlank(firstname) ? null : firstname;
273 272
	}
274 273

  
275 274
    /**
......
303 302
	 * @see  #getLastname()
304 303
	 */
305 304
	public void setLastname(String lastname){
306
		this.lastname = StringUtils.isBlank(lastname) ? null : lastname;
305
		this.lastname = isBlank(lastname) ? null : lastname;
307 306
	}
308 307

  
309 308

  
......
318 317
	 * @see  #getSuffix()
319 318
	 */
320 319
	public void setSuffix(String suffix){
321
		this.suffix = StringUtils.isBlank(suffix) ? null: suffix;
320
		this.suffix = isBlank(suffix) ? null: suffix;
322 321
	}
323 322

  
324 323

  
......
348 347
		this.lifespan = lifespan;
349 348
	}
350 349

  
351
//	/**
352
//	 * Generates the "full" name string of <i>this</i> person according to the strategy
353
//	 * defined in {@link eu.etaxonomy.cdm.strategy.cache.agent.PersonDefaultCacheStrategy PersonDefaultCacheStrategy}.
354
//	 * The used attributes are:
355
//	 * {@link #getPrefix() prefix}, {@link #getFirstname() firstname}, {@link #getLastname() lastname} and {@link #getSuffix() suffix}.
356
//	 * This method overrides {@link eu.etaxonomy.cdm.model.common.IdentifiableEntity#generateTitle() generateTitle}.
357
//	 * The result might be kept as {@link eu.etaxonomy.cdm.model.common.IdentifiableEntity#setTitleCache(String) titleCache} if the
358
//	 * flag {@link eu.etaxonomy.cdm.model.common.IdentifiableEntity#protectedTitleCache protectedTitleCache} is not set.
359
//	 *
360
//	 * @return  the string with the full name of <i>this</i> person
361
//	 */
362
//	@Override
363
//	public String generateTitle() {
364
//		String title = null;
365
//		if (cacheStrategy != null) {
366
//		title = cacheStrategy.getTitleCache(this);
367
//		}
368
//        return title;
369
//	}
370

  
371 350
//*********************** CLONE ********************************************************/
372 351

  
373 352
	/**
......
388 367
			e.printStackTrace();
389 368
			return null;
390 369
		}
391

  
392

  
393 370
	}
394 371

  
395 372
}
cdmlib-model/src/main/java/eu/etaxonomy/cdm/model/agent/TeamOrPersonBase.java
17 17
import javax.xml.bind.annotation.XmlTransient;
18 18
import javax.xml.bind.annotation.XmlType;
19 19

  
20
import org.apache.commons.lang.StringUtils;
21 20
import org.apache.log4j.Logger;
22 21
import org.hibernate.envers.Audited;
23 22
import org.hibernate.search.annotations.Field;
......
40 39
})
41 40
@Entity
42 41
@Audited
43
public abstract class TeamOrPersonBase<T extends TeamOrPersonBase<T>> extends AgentBase<INomenclaturalAuthorCacheStrategy<T>> implements INomenclaturalAuthor {
42
public abstract class TeamOrPersonBase<T extends TeamOrPersonBase<T>>
43
            extends AgentBase<INomenclaturalAuthorCacheStrategy<T>>
44
            implements INomenclaturalAuthor {
45

  
44 46
    private static final long serialVersionUID = 5216821307314001961L;
45 47
    public static final Logger logger = Logger.getLogger(TeamOrPersonBase.class);
46 48

  
......
72 74
    @Transient
73 75
    public String getNomenclaturalTitle() {
74 76
        String result = nomenclaturalTitle;
75
        if (StringUtils.isBlank(nomenclaturalTitle) && (isGeneratingTitleCache == false)){
77
        if (isBlank(nomenclaturalTitle) && (isGeneratingTitleCache == false)){
76 78
            result = getTitleCache();
77 79
        }
78 80
        return result;
......
83 85
     */
84 86
    @Override
85 87
    public void setNomenclaturalTitle(String nomenclaturalTitle) {
86
        this.nomenclaturalTitle = StringUtils.isBlank(nomenclaturalTitle) ? null : nomenclaturalTitle;
88
        this.nomenclaturalTitle = isBlank(nomenclaturalTitle) ? null : nomenclaturalTitle;
87 89
    }
88 90

  
89 91

  
90 92
    @Override
91
    @Transient /*
92
                TODO  is the transient annotation still needed, can't we remove this ??
93
                @Transient is an absolutely special case and thus leads to several
94
                special implementations in order to harmonize this exception again
95
                in other parts of the library:
96
                 - eu.etaxonomy.cdm.remote.controller.AgentController.doGetTitleCache()
97
                 - eu.etaxonomy.cdm.remote.json.processor.bean.TeamOrPersonBaseBeanProcessor
98

  
99
                [a.kohlbecker May 2011]
100
         */
93
    @Transient
94
    /*
95
        TODO  is the transient annotation still needed, can't we remove this ??
96
        @Transient is an absolutely special case and thus leads to several
97
        special implementations in order to harmonize this exception again
98
        in other parts of the library:
99
         - eu.etaxonomy.cdm.remote.controller.AgentController.doGetTitleCache()
100
         - eu.etaxonomy.cdm.remote.json.processor.bean.TeamOrPersonBaseBeanProcessor
101

  
102
        [a.kohlbecker May 2011]
103
    */
101 104
    public String getTitleCache() {
102 105
        isGeneratingTitleCache = true;
103 106
        String result = super.getTitleCache();
......
111 114
     * @return
112 115
     */
113 116
    protected String replaceEmptyTitleByNomTitle(String result) {
114
        if (StringUtils.isBlank(result)){
117
        if (isBlank(result)){
115 118
            result = nomenclaturalTitle;
116 119
        }
117
        if (StringUtils.isBlank(result)){
120
        if (isBlank(result)){
118 121
            result = super.getTitleCache();
119 122
        }
120 123
        return result;
121 124
    }
122 125

  
123

  
124 126
}
cdmlib-model/src/main/java/eu/etaxonomy/cdm/strategy/cache/agent/INomenclaturalAuthorCacheStrategy.java
5 5
*
6 6
* The contents of this file are subject to the Mozilla Public License Version 1.1
7 7
* See LICENSE.TXT at the top of this package for the full license terms.
8
*/ 
8
*/
9 9

  
10 10
package eu.etaxonomy.cdm.strategy.cache.agent;
11 11

  
......
13 13
import eu.etaxonomy.cdm.model.agent.TeamOrPersonBase;
14 14
import eu.etaxonomy.cdm.strategy.cache.common.IIdentifiableEntityCacheStrategy;
15 15

  
16
public interface INomenclaturalAuthorCacheStrategy<T extends TeamOrPersonBase> extends IIdentifiableEntityCacheStrategy<T> {
17
	
16
public interface INomenclaturalAuthorCacheStrategy<T extends TeamOrPersonBase>
17
        extends IIdentifiableEntityCacheStrategy<T> {
18

  
18 19
	/**
19
	 * returns the composed name string without author or year
20
	 * @param object
21
	 * @return
20
	 * The title as used in taxonomic nomenclature.
21
	 * @param agent person or team
22
	 * @return the nomenclatural title
22 23
	 */
23 24
	public String getNomenclaturalTitle(T object);
24 25

  
cdmlib-model/src/main/java/eu/etaxonomy/cdm/strategy/cache/agent/PersonDefaultCacheStrategy.java
5 5
*
6 6
* The contents of this file are subject to the Mozilla Public License Version 1.1
7 7
* See LICENSE.TXT at the top of this package for the full license terms.
8
*/ 
8
*/
9 9

  
10 10
package eu.etaxonomy.cdm.strategy.cache.agent;
11 11

  
......
20 20

  
21 21
/**
22 22
 * @author AM
23
 *
24 23
 */
25
public class PersonDefaultCacheStrategy extends StrategyBase implements
26
		INomenclaturalAuthorCacheStrategy<Person> {
24
public class PersonDefaultCacheStrategy
25
        extends StrategyBase
26
        implements INomenclaturalAuthorCacheStrategy<Person> {
27 27
	private static final long serialVersionUID = -6184639515553953112L;
28 28

  
29 29
	@SuppressWarnings("unused")
......
36 36
	static public PersonDefaultCacheStrategy NewInstance(){
37 37
		return new PersonDefaultCacheStrategy();
38 38
	}
39
	
40
	/**
41
	 * 
42
	 */
39

  
40
// ******************** CONSTRUCTOR **********************************/
43 41
	private PersonDefaultCacheStrategy() {
44 42
		super();
45 43
	}
46 44

  
47
	/* (non-Javadoc)
48
	 * @see eu.etaxonomy.cdm.strategy.StrategyBase#getUuid()
49
	 */
45

  
46

  
50 47
	@Override
51 48
	protected UUID getUuid() {
52 49
		return uuid;
53 50
	}
54 51

  
55
	/* (non-Javadoc)
56
	 * @see eu.etaxonomy.cdm.strategy.INomenclaturalAuthorCacheStrategy#getNomenclaturalTitle(eu.etaxonomy.cdm.model.name.TaxonNameBase)
57
	 */
58
	public String getNomenclaturalTitle(Person person) {
52
	@Override
53
    public String getNomenclaturalTitle(Person person) {
59 54
		return person.getNomenclaturalTitle();
60 55
	}
61 56

  
......
82 77
	}
83 78

  
84 79
	/**
85
	 * 
80
	 *
86 81
	 */
87 82
	private String addFirstNamePrefixSuffix(String oldString, Person person) {
88 83
		String result = oldString;
89
		result = CdmUtils.concat(" ", person.getFirstname(), result); 
90
		result = CdmUtils.concat(" ", person.getPrefix(), result); 
91
		result = CdmUtils.concat(" ", result, person.getSuffix()); 
84
		result = CdmUtils.concat(" ", person.getFirstname(), result);
85
		result = CdmUtils.concat(" ", person.getPrefix(), result);
86
		result = CdmUtils.concat(" ", result, person.getSuffix());
92 87
		return result;
93 88
	}
94 89

  
cdmlib-model/src/test/java/eu/etaxonomy/cdm/strategy/cache/agent/PersonDefaultCacheStrategyTest.java
1 1
/**
2 2
* Copyright (C) 2007 EDIT
3
* European Distributed Institute of Taxonomy 
3
* European Distributed Institute of Taxonomy
4 4
* http://www.e-taxonomy.eu
5
* 
5
*
6 6
* The contents of this file are subject to the Mozilla Public License Version 1.1
7 7
* See LICENSE.TXT at the top of this package for the full license terms.
8 8
*/
......
26 26
/**
27 27
 * @author a.mueller
28 28
 * @created 29.09.2009
29
 * @version 1.0
30 29
 */
31 30
public class PersonDefaultCacheStrategyTest {
32 31
	@SuppressWarnings("unused")
......
35 34
	private static Person person1;
36 35
	private static Person person2;
37 36
	private static Person person3;
38
	
37

  
39 38
	/**
40 39
	 * @throws java.lang.Exception
41 40
	 */
......
48 47
	 */
49 48
	@AfterClass
50 49
	public static void tearDownAfterClass() throws Exception {
51
		
52
		
50

  
51

  
53 52
	}
54 53

  
55 54
	/**
......
58 57
	@Before
59 58
	public void setUp() throws Exception {
60 59
		person1 = Person.NewInstance();
61
		
60

  
62 61
		person1.setFirstname("P1FN");
63 62
		person1.setLastname("P1LN");
64 63
		person1.setPrefix("Dr1.");
65 64
		person1.setSuffix("Suff1");
66
		
65

  
67 66
		person2 = Person.NewInstance();
68 67
		person2.setNomenclaturalTitle("P2NomT");
69 68
		person2.setLastname("P2LN");
70 69
		person2.setFirstname("P2FN");
71 70
		person2.setSuffix("P2Suff");
72
		
71

  
73 72
		person3 = Person.NewInstance(); //empty person
74
		
73

  
75 74
	}
76 75

  
77 76
	/**
......
80 79
	@After
81 80
	public void tearDown() throws Exception {
82 81
	}
83
	
82

  
84 83
//**************************************** TESTS **************************************
85
	
84

  
86 85
	/**
87 86
	 * Test method for {@link eu.etaxonomy.cdm.strategy.cache.agent.PersonDefaultCacheStrategy#NewInstance()}.
88 87
	 */
......
106 105
		//don't take to serious, may be also something different, but not empty
107 106
		Assert.assertEquals("Person3 title should start with Person#0", "Person#0", person3.getNomenclaturalTitle().substring(0, 8));
108 107
	}
109
	
108

  
110 109

  
111 110
	@Test
112 111
	public final void testGetTitleCache(){

Also available in: Unified diff

Add picture from clipboard (Maximum size: 40 MB)