Project

General

Profile

Revision 78fc87fb

ID78fc87fb979fdb2af7fa9f04a104f6f6dd43838f
Parent 9659a577
Child 9601d0f2

Added by Andreas Müller over 9 years ago

improve NamedArea with level title cache (also include test)

View differences:

.gitattributes
920 920
cdmlib-model/src/test/java/eu/etaxonomy/cdm/model/description/PolytomousKeyTest.java -text
921 921
cdmlib-model/src/test/java/eu/etaxonomy/cdm/model/description/PresenceAbsenceTermBaseTest.java -text
922 922
cdmlib-model/src/test/java/eu/etaxonomy/cdm/model/description/TextDataTest.java -text
923
cdmlib-model/src/test/java/eu/etaxonomy/cdm/model/location/NamedAreaTest.java -text
923 924
cdmlib-model/src/test/java/eu/etaxonomy/cdm/model/location/PointTest.java -text
924 925
cdmlib-model/src/test/java/eu/etaxonomy/cdm/model/location/TdwgAreaTest.java -text
925 926
cdmlib-model/src/test/java/eu/etaxonomy/cdm/model/media/MediaTest.java -text
cdmlib-model/src/main/java/eu/etaxonomy/cdm/model/location/NamedArea.java
33 33
import javax.xml.bind.annotation.XmlSeeAlso;
34 34
import javax.xml.bind.annotation.XmlType;
35 35

  
36
import org.apache.commons.lang.StringUtils;
36 37
import org.apache.log4j.Logger;
37 38
import org.hibernate.annotations.Cascade;
38 39
import org.hibernate.annotations.CascadeType;
......
488 489
			String areaString = getPreferredAreaLabel(namedArea, representation);
489 490
			
490 491
			title.append(areaString);
491
			if (! area.getClass().equals(NamedArea.class)){
492
			if (area.getLevel() == null){
492 493
				title.append(" - ");
493 494
				title.append(area.getClass().getSimpleName());
494
			}
495
			if(area.getLevel() != null){
495
			}else{
496 496
				title.append(" - ");
497 497
				Representation levelRepresentation = area.getLevel().getPreferredRepresentation(language);
498 498
				String levelString = getPreferredAreaLabel(area.getLevel(), levelRepresentation);
499 499
				title.append(levelString);
500 500
			}
501
			if(! CdmUtils.isEmpty(representation.getAbbreviatedLabel())){
502
				title.append(" - ");
503
				title.append(representation.getAbbreviatedLabel());
504
			}
505 501
		}
506 502
		return title.toString();
507 503
	}
508 504

  
509 505
	/**
510
	 * @param namedArea
506
	 * @param definedTerm
511 507
	 * @param representation
512 508
	 * @return
513 509
	 */
514
	private static String getPreferredAreaLabel(DefinedTermBase<?> namedArea, Representation representation) {
510
	private static String getPreferredAreaLabel(DefinedTermBase<?> definedTerm, Representation representation) {
515 511
		String areaString = null;
516 512
		if (representation != null){
517 513
			areaString = representation.getLabel();
518
			if (areaString == null){
514
			if (StringUtils.isBlank(areaString)){
519 515
				areaString = representation.getAbbreviatedLabel();
520 516
			}
521
			if (areaString == null){
517
			if (StringUtils.isBlank(areaString)){
522 518
				areaString = representation.getText();
523 519
			}
524 520
		}
525
		if (areaString == null){
526
			areaString = namedArea.getTitleCache();
521
		if (StringUtils.isBlank(areaString)){
522
			areaString = definedTerm.getTitleCache();
527 523
		}
528
		if (areaString == null){
524
		if (StringUtils.isBlank(areaString)){
529 525
			areaString = "no title";
530 526
		}
531 527
		return areaString;
cdmlib-model/src/test/java/eu/etaxonomy/cdm/model/location/NamedAreaTest.java
1
// $Id$
2
/**
3
* Copyright (C) 2009 EDIT
4
* European Distributed Institute of Taxonomy 
5
* http://www.e-taxonomy.eu
6
* 
7
* The contents of this file are subject to the Mozilla Public License Version 1.1
8
* See LICENSE.TXT at the top of this package for the full license terms.
9
*/
10
package eu.etaxonomy.cdm.model.location;
11

  
12
import org.apache.log4j.Logger;
13
import org.junit.Assert;
14
import org.junit.Before;
15
import org.junit.BeforeClass;
16
import org.junit.Test;
17

  
18
import eu.etaxonomy.cdm.model.common.DefaultTermInitializer;
19
import eu.etaxonomy.cdm.model.common.Language;
20

  
21
/**
22
 * @author a.mueller
23
 * @date 26.05.2011
24
 *
25
 */
26
public class NamedAreaTest {
27
	@SuppressWarnings("unused")
28
	private static final Logger logger = Logger.getLogger(NamedAreaTest.class);
29
	
30
	private NamedArea namedArea1;
31
	private NamedAreaLevel level1;
32
	private NamedAreaType areaType1;
33
	
34
	
35
	/**
36
	 * @throws java.lang.Exception
37
	 */
38
	@BeforeClass
39
	public static void setUpBeforeClass() throws Exception {
40
		DefaultTermInitializer initializer = new DefaultTermInitializer();
41
		initializer.initialize();
42
	}
43

  
44
	/**
45
	 * @throws java.lang.Exception
46
	 */
47
	@Before
48
	public void setUp() throws Exception {
49
		namedArea1 = NamedArea.NewInstance("Description for Named Area 1", "Named Area 1", "NA1");
50
		level1 = NamedAreaLevel.NewInstance("Description for level 1", "Level 1", "L1");
51
		namedArea1.setLevel(level1);
52
	}
53
	
54
	@Test
55
	public void NewInstanceStringStringStringTest(){
56
		Assert.assertEquals("Description for Named Area 1", namedArea1.getDescription());
57
		Assert.assertEquals("Named Area 1", namedArea1.getLabel());
58
		Assert.assertEquals("NA1", namedArea1.getRepresentation(Language.DEFAULT()).getAbbreviatedLabel());
59
	}
60

  
61
	
62
	@Test
63
	public void labelWithLevelTest(){
64
		Assert.assertEquals("Named Area 1 - Level 1", NamedArea.labelWithLevel(namedArea1, Language.DEFAULT()));
65
		Assert.assertEquals("Germany - WaterbodyOrCountry", NamedArea.labelWithLevel(WaterbodyOrCountry.GERMANY(), Language.DEFAULT()));
66
		Assert.assertEquals("Germany - TDWG Level 3", NamedArea.labelWithLevel(TdwgArea.getAreaByTdwgAbbreviation("GER"), Language.DEFAULT()));
67
		NamedArea namedArea2 = NamedArea.NewInstance("Description for Named Area 2", "", "NA2");
68
		Assert.assertEquals("NA2 - NamedArea", NamedArea.labelWithLevel(namedArea2, Language.DEFAULT()));
69
		NamedArea namedArea3 = NamedArea.NewInstance("Description for Named Area 3", null, " ");
70
		Assert.assertEquals("Description for Named Area 3 - NamedArea", NamedArea.labelWithLevel(namedArea3, Language.DEFAULT()));
71
		
72
		//TODO include Vocabulay information
73
	}
74

  
75
}

Also available in: Unified diff

Add picture from clipboard (Maximum size: 40 MB)