Project

General

Profile

« Previous | Next » 

Revision 26f749e9

Added by Andreas Müller over 13 years ago

Some bugfixes for book(section)cache strategy

View differences:

.gitattributes
2128 2128
cdmlib-model/src/test/java/eu/etaxonomy/cdm/strategy/cache/name/NonViralNameDefaultCacheStrategyTest.java -text
2129 2129
cdmlib-model/src/test/java/eu/etaxonomy/cdm/strategy/cache/name/ZoologicalNameCacheStrategyTest.java -text
2130 2130
cdmlib-model/src/test/java/eu/etaxonomy/cdm/strategy/cache/reference/ArticleDefaultCacheStrategyTest.java -text
2131
cdmlib-model/src/test/java/eu/etaxonomy/cdm/strategy/cache/reference/BookDefaultCacheStrategyTest.java -text
2131 2132
cdmlib-model/src/test/java/eu/etaxonomy/cdm/strategy/cache/reference/BookSectionDefaultCacheStrategyTest.java -text
2132 2133
cdmlib-model/src/test/java/eu/etaxonomy/cdm/strategy/cache/reference/CdDvdDefaultCacheStrategyTest.java -text
2133 2134
cdmlib-model/src/test/java/eu/etaxonomy/cdm/strategy/cache/taxon/TaxonBaseDefaultCacheStrategyTest.java -text
cdmlib-model/src/main/java/eu/etaxonomy/cdm/strategy/cache/reference/BookDefaultCacheStrategy.java
72 72
		String lastChar;
73 73
		String character =".";
74 74
		len = titelAbbrev.length();
75
		if (len > 0){lastChar = titelAbbrev.substring(len-1, len);}
75
		if (len > 0){
76
			lastChar = titelAbbrev.substring(len-1, len);
77
		}
76 78
		//lastCharIsDouble = f_core_CompareStrings(RIGHT(@TitelAbbrev,1),character);
77 79
		lastCharIsDouble = titelAbbrev.equals(character);
78 80

  
......
83 85
		
84 86
		boolean needsComma = false;
85 87
		//titelAbbrev
86
		String titelAbbrevPart = "";
87 88
		if (!"".equals(titelAbbrev)){
88 89
			nomRefCache = titelAbbrev + blank; 
89 90
		}
......
129 130
			nomRefCache = nomRefCache.substring(0, nomRefCache.length()-1);
130 131
		}
131 132
		
132
		
133
		
134

  
135
		
136
		//	--Edition and series are null or numeric
137

  
138
//		if (isNumeric(edition) ){
139
//			if (titelAbbrev.length() > 0 && edition.length() > 0 &&  series.length() > 0 && isNumeric(series) && volume.length() > 0 && refYear.length() > 0 ){
140
//				nomRefCache = titelAbbrev + blank + prefixEdition + blank + edition + comma + blank + prefixSeries + blank + series + comma + blank + volume + dot + blank + refYear + dot;
141
//			}
142
//		}
143

  
144
		
145
//		IF (len(@Authorteam) = 0 AND len(@TitelAbbrev) > 0 AND len(@Edition) > 0 AND isnumeric(@Edition)=1 AND len(@Series) > 0 AND isnumeric(@Series)=1 AND len(@Volume) > 0 AND len(@RefYear) = 0) SET @NomRefCache = @TitelAbbrev + @blank + @prefixEdition + @blank + @Edition +  @comma + @blank + @prefixSeries + @blank + @Series + @comma + @blank + @Volume + @dot
146
//		IF (len(@Authorteam) = 0 AND len(@TitelAbbrev) > 0 AND len(@Edition) > 0 AND isnumeric(@Edition)=1 AND len(@Series) > 0 AND isnumeric(@Series)=1 AND len(@Volume) = 0 AND len(@RefYear) > 0) SET @NomRefCache = @TitelAbbrev + @blank + @prefixEdition + @blank + @Edition +  @comma + @blank + @prefixSeries + @blank + @Series + @comma +  @blank + @Refyear + @dot
147
//		IF (len(@Authorteam) = 0 AND len(@TitelAbbrev) > 0 AND len(@Edition) > 0 AND isnumeric(@Edition)=1 AND len(@Series) > 0 AND isnumeric(@Series)=1 AND len(@Volume) = 0 AND len(@RefYear) = 0) SET @NomRefCache = @TitelAbbrev + @blank + @prefixEdition + @blank + @Edition +  @comma + @blank + @prefixSeries + @blank + @Series + @dot
148
//		IF (len(@Authorteam) = 0 AND len(@TitelAbbrev) > 0 AND len(@Edition) > 0 AND isnumeric(@Edition)=1 AND len(@Series) = 0 AND len(@Volume) > 0 AND len(@RefYear) = 0) SET @NomRefCache = @TitelAbbrev + @blank + @prefixEdition+ @blank + @Edition +  @comma + @blank + @Volume + @dot
149
//		IF (len(@Authorteam) = 0 AND len(@TitelAbbrev) > 0 AND len(@Edition) > 0 AND isnumeric(@Edition)=1 AND len(@Series) = 0 AND len(@Volume) = 0 AND len(@RefYear) = 0) SET @NomRefCache = @TitelAbbrev + @blank + @prefixEdition + @blank + @Edition +  @dot
150
//		IF (len(@Authorteam) = 0 AND len(@TitelAbbrev) > 0 AND len(@Edition) = 0 AND len(@Series) > 0 AND isnumeric(@Series)=1 AND len(@Volume) > 0 AND len(@RefYear) = 0) SET @NomRefCache = @TitelAbbrev + @blank + @prefixSeries + @blank + @Series + @comma + @blank + @Volume + @dot
151
//		IF (len(@Authorteam) = 0 AND len(@TitelAbbrev) > 0 AND len(@Edition) = 0 AND len(@Series) > 0 AND isnumeric(@Series)=1 AND len(@Volume) = 0 AND len(@RefYear) = 0) SET @NomRefCache = @TitelAbbrev + @blank + @prefixSeries + @blank + @Series + @dot
152
//		IF (len(@Authorteam) = 0 AND len(@TitelAbbrev) > 0 AND len(@Edition) = 0 AND len(@Series) = 0 AND len(@Volume) > 0 AND len(@RefYear) = 0) SET @NomRefCache = @TitelAbbrev + @blank + @Volume + @dot
153
//		IF (len(@Authorteam) = 0 AND len(@TitelAbbrev) > 0 AND len(@Edition) = 0 AND len(@Series) = 0 AND len(@Volume) = 0 AND len(@RefYear) = 0) SET @NomRefCache = @TitelAbbrev + @dot
154
//		IF (len(@Authorteam) = 0 AND len(@TitelAbbrev) = 0 AND len(@Edition) > 0 AND isnumeric(@Edition)=1 AND len(@Series) > 0 AND isnumeric(@Series)=1 AND len(@Volume) > 0 AND len(@RefYear) = 0) SET @NomRefCache = @prefixEdition + @blank + @Edition +  @comma + @blank + @prefixSeries + @blank + @Series + @comma + @blank + @Volume + @dot
155
//		IF (len(@Authorteam) = 0 AND len(@TitelAbbrev) = 0 AND len(@Edition) > 0 AND isnumeric(@Edition)=1 AND len(@Series) > 0 AND isnumeric(@Series)=1 AND len(@Volume) = 0 AND len(@RefYear) = 0) SET @NomRefCache = @prefixEdition + @blank + @Edition +  @comma + @blank + @prefixSeries + @blank + @Series + @dot
156
//		IF (len(@Authorteam) = 0 AND len(@TitelAbbrev) = 0 AND len(@Edition) > 0 AND isnumeric(@Edition)=1 AND len(@Series) = 0 AND len(@Volume) > 0 AND len(@RefYear) = 0) SET @NomRefCache = @prefixEdition + @blank + @Edition +  @comma + @blank + @Volume + @dot
157
//		IF (len(@Authorteam) = 0 AND len(@TitelAbbrev) = 0 AND len(@Edition) > 0 AND isnumeric(@Edition)=1 AND len(@Series) = 0 AND len(@Volume) = 0 AND len(@RefYear) = 0) SET @NomRefCache = @prefixEdition + @blank + @Edition +  @dot
158
//		IF (len(@Authorteam) = 0 AND len(@TitelAbbrev) = 0 AND len(@Edition) = 0 AND len(@Series) > 0 AND isnumeric(@Series)=1 AND len(@Volume) > 0 AND len(@RefYear) = 0) SET @NomRefCache = @prefixSeries + @blank + @Series + @comma + @blank + @Volume + @dot
159
//		IF (len(@Authorteam) = 0 AND len(@TitelAbbrev) = 0 AND len(@Edition) = 0 AND len(@Series) > 0 AND isnumeric(@Series)=1 AND len(@Volume) = 0 AND len(@RefYear) = 0) SET @NomRefCache = @prefixSeries + @blank + @Series + @dot
160
//		IF (len(@Authorteam) = 0 AND len(@TitelAbbrev) = 0 AND len(@Edition) = 0 AND len(@Series) = 0 AND len(@Volume) > 0 AND len(@RefYear) = 0) SET @NomRefCache = @Volume + @dot
161
//		IF (len(@Authorteam) = 0 AND len(@TitelAbbrev) = 0 AND len(@Edition) = 0 AND len(@Series) = 0 AND len(@Volume) = 0 AND len(@RefYear) > 0) SET @NomRefCache = @Refyear + @dot
162
//		IF (len(@Authorteam) = 0 AND len(@TitelAbbrev) = 0 AND len(@Edition) = 0 AND len(@Series) = 0 AND len(@Volume) = 0 AND len(@RefYear) = 0) SET @NomRefCache = NULL
163
//
164
//
165
//
166
//
167
//
168
//
169
//	--Edition and/or Series is not numeric
170
//
171
//		IF (len(@Authorteam) = 0 AND len(@TitelAbbrev) > 0 AND len(@Edition) > 0 AND isnumeric(@Edition)=0 AND len(@Series) > 0 AND isnumeric(@Series)=0 AND len(@Volume) > 0 AND len(@RefYear) = 0) SET @NomRefCache = @TitelAbbrev + @blank + @Edition +  @comma + @blank + @Series + @comma + @blank + @Volume + @dot
172
//		IF (len(@Authorteam) = 0 AND len(@TitelAbbrev) > 0 AND len(@Edition) > 0 AND isnumeric(@Edition)=0 AND len(@Series) > 0 AND isnumeric(@Series)=0 AND len(@Volume) = 0 AND len(@RefYear) > 0) SET @NomRefCache = @TitelAbbrev + @blank + @Edition +  @comma + @blank + @Series + @comma +  @blank + @Refyear + @dot
173
//		IF (len(@Authorteam) = 0 AND len(@TitelAbbrev) > 0 AND len(@Edition) > 0 AND isnumeric(@Edition)=0 AND len(@Series) > 0 AND isnumeric(@Series)=0 AND len(@Volume) = 0 AND len(@RefYear) = 0) SET @NomRefCache = @TitelAbbrev + @blank + @Edition +  @comma + @blank + @Series + @dot
174
//		IF (len(@Authorteam) = 0 AND len(@TitelAbbrev) > 0 AND len(@Edition) > 0 AND isnumeric(@Edition)=0 AND len(@Series) = 0 AND len(@Volume) > 0 AND len(@RefYear) = 0) SET @NomRefCache = @TitelAbbrev + @blank + @Edition +  @comma + @blank + @Volume + @dot
175
//		IF (len(@Authorteam) = 0 AND len(@TitelAbbrev) > 0 AND len(@Edition) > 0 AND isnumeric(@Edition)=0 AND len(@Series) = 0 AND len(@Volume) = 0 AND len(@RefYear) = 0) SET @NomRefCache = @TitelAbbrev + @blank + @Edition +  @dot
176
//		IF (len(@Authorteam) = 0 AND len(@TitelAbbrev) > 0 AND len(@Edition) = 0 AND len(@Series) > 0 AND isnumeric(@Series)=0 AND len(@Volume) > 0 AND len(@RefYear) = 0) SET @NomRefCache = @TitelAbbrev + @blank + @Series + @comma + @blank + @Volume + @dot
177
//
178
//		IF (len(@Authorteam) = 0 AND len(@TitelAbbrev) > 0 AND len(@Edition) = 0 AND len(@Series) > 0 AND isnumeric(@Series)=0 AND len(@Volume) = 0 AND len(@RefYear) = 0) SET @NomRefCache = @TitelAbbrev + @blank + @Series + @dot
179
//		IF (len(@Authorteam) = 0 AND len(@TitelAbbrev) = 0 AND len(@Edition) > 0 AND isnumeric(@Edition)=0 AND len(@Series) > 0 AND isnumeric(@Series)=0 AND len(@Volume) > 0 AND len(@RefYear) = 0) SET @NomRefCache = @Edition +  @comma + @blank + @Series + @comma + @blank + @Volume + @dot
180
//		IF (len(@Authorteam) = 0 AND len(@TitelAbbrev) = 0 AND len(@Edition) > 0 AND isnumeric(@Edition)=0 AND len(@Series) > 0 AND isnumeric(@Series)=0 AND len(@Volume) = 0 AND len(@RefYear) = 0) SET @NomRefCache = @Edition +  @comma + @blank + @Series + @dot
181
//		IF (len(@Authorteam) = 0 AND len(@TitelAbbrev) = 0 AND len(@Edition) > 0 AND isnumeric(@Edition)=0 AND len(@Series) = 0 AND len(@Volume) > 0 AND len(@RefYear) = 0) SET @NomRefCache = @Edition +  @comma + @blank + @Volume + @dot
182
//		IF (len(@Authorteam) = 0 AND len(@TitelAbbrev) = 0 AND len(@Edition) > 0 AND isnumeric(@Edition)=0 AND len(@Series) = 0 AND len(@Volume) = 0 AND len(@RefYear) = 0) SET @NomRefCache = @Edition +  @dot
183
//		IF (len(@Authorteam) = 0 AND len(@TitelAbbrev) = 0 AND len(@Edition) = 0 AND len(@Series) > 0 AND isnumeric(@Series)=0 AND len(@Volume) > 0 AND len(@RefYear) = 0) SET @NomRefCache = @Series + @comma + @blank + @Volume + @dot
184
//		IF (len(@Authorteam) = 0 AND len(@TitelAbbrev) = 0 AND len(@Edition) = 0 AND len(@Series) > 0 AND isnumeric(@Series)=0 AND len(@Volume) = 0 AND len(@RefYear) = 0) SET @NomRefCache = @Series + @dot
185
//
186
//
187
//
188
//
189
//	--Edition is numeric and series is not numeric
190
//		IF (len(@Authorteam) = 0 AND len(@TitelAbbrev) > 0 AND len(@Edition) > 0 AND isnumeric(@Edition)=1 AND len(@Series) > 0 AND isnumeric(@Series)=0 AND len(@Volume) > 0 AND len(@RefYear) = 0) SET @NomRefCache = @TitelAbbrev + @blank + @prefixEdition + @blank + @Edition +  @comma + @blank + @Series + @comma + @blank + @Volume + @dot
191
//		IF (len(@Authorteam) = 0 AND len(@TitelAbbrev) > 0 AND len(@Edition) > 0 AND isnumeric(@Edition)=1 AND len(@Series) > 0 AND isnumeric(@Series)=0 AND len(@Volume) = 0 AND len(@RefYear) > 0) SET @NomRefCache = @TitelAbbrev + @blank + @prefixEdition + @blank + @Edition +  @comma + @blank + @Series + @comma +  @blank + @Refyear + @dot
192
//		IF (len(@Authorteam) = 0 AND len(@TitelAbbrev) = 0 AND len(@Edition) > 0 AND isnumeric(@Edition)=1 AND len(@Series) > 0 AND isnumeric(@Series)=0 AND len(@Volume) > 0 AND len(@RefYear) = 0) SET @NomRefCache = @prefixEdition + @blank + @Edition +  @comma + @blank + @Series + @comma + @blank + @Volume + @dot
193
//		IF (len(@Authorteam) = 0 AND len(@TitelAbbrev) = 0 AND len(@Edition) > 0 AND isnumeric(@Edition)=1 AND len(@Series) > 0 AND isnumeric(@Series)=0 AND len(@Volume) = 0 AND len(@RefYear) = 0) SET @NomRefCache = @prefixEdition + @blank + @Edition+  @comma + @blank + @Series + @dot
194
//
195
//
196
//
197
//	--Series is numeric and editon is not numeric
198
//		IF (len(@Authorteam) = 0 AND len(@TitelAbbrev) > 0 AND len(@Edition) > 0 AND isnumeric(@Edition)=0 AND len(@Series) > 0 AND isnumeric(@Series)=1 AND len(@Volume) > 0 AND len(@RefYear) = 0) SET @NomRefCache = @TitelAbbrev + @blank + @Edition +  @comma + @blank + @prefixSeries + @blank + @Series + @comma + @blank + @Volume + @dot
199
//		IF (len(@Authorteam) = 0 AND len(@TitelAbbrev) > 0 AND len(@Edition) > 0 AND isnumeric(@Edition)=0 AND len(@Series) > 0 AND isnumeric(@Series)=1 AND len(@Volume) = 0 AND len(@RefYear) > 0) SET @NomRefCache = @TitelAbbrev + @blank + @Edition +  @comma + @blank + @prefixSeries + @blank + @Series + @comma +  @blank + @Refyear + @dot
200
//		IF (len(@Authorteam) = 0 AND len(@TitelAbbrev) = 0 AND len(@Edition) > 0 AND isnumeric(@Edition)=0 AND len(@Series) > 0 AND isnumeric(@Series)=1 AND len(@Volume) > 0 AND len(@RefYear) = 0) SET @NomRefCache = @Edition +  @comma + @blank + @prefixSeries + @blank + @Series + @comma + @blank + @Volume + @dot
201
//		IF (len(@Authorteam) = 0 AND len(@TitelAbbrev) = 0 AND len(@Edition) > 0 AND isnumeric(@Edition)=0 AND len(@Series) > 0 AND isnumeric(@Series)=1 AND len(@Volume) = 0 AND len(@RefYear) = 0) SET @NomRefCache = @Edition+  @comma + @blank + @prefixSeries + @blank + @Series + @dot
202
//
203
//	--Changes (Marc Geoffroy)
204
//
205
//		IF (len(@Authorteam) = 0 AND len(@TitelAbbrev) = 0)  SET @NomRefCache = NULL
206
//
207
//
208
//		Return @NomRefCache
209

  
210 133
		return nomRefCache.trim();
211 134
	}
212 135
	
cdmlib-model/src/main/java/eu/etaxonomy/cdm/strategy/cache/reference/BookSectionDefaultCacheStrategy.java
89 89
	public String getTitleCache(T bookSection) {
90 90
		boolean hasBook = (bookSection.getInBook() != null);
91 91
		String result;
92
		// get book part
92 93
		if (hasBook){
93 94
			result = bookSection.getInReference().getTitleCache();
94 95
		}else{
95 96
			result = "- undefined book -";
96 97
		}
97
		TeamOrPersonBase<?> sectionTeam = bookSection.getAuthorTeam();
98
		String sectionAuthor = CdmUtils.Nz(sectionTeam == null ? "" : sectionTeam.getTitleCache());
98
		
99
		//in
99 100
		result = inBook +  result;
101
		
102
		//section title
100 103
		String title = CdmUtils.Nz(bookSection.getTitle());
101 104
		if (title.length() > 0){
102 105
			result = title + blank + result;
103 106
		}
107
		
108
		//section author
109
		TeamOrPersonBase<?> sectionTeam = bookSection.getAuthorTeam();
110
		String sectionAuthor = CdmUtils.Nz(sectionTeam == null ? "" : sectionTeam.getTitleCache());
104 111
		result = sectionAuthor + afterSectionAuthor + result;
112
		
113
		//date
105 114
		if (bookSection.getDatePublished() != null && ! bookSection.getDatePublished().isEmpty()){
106 115
			String bookSectionDate = bookSection.getDatePublished().toString();
107 116
			if (hasBook && bookSection.getInBook().getDatePublished() != null){
108 117
				TimePeriod bookDate = bookSection.getInBook().getDatePublished();
109
				String bookDateString = bookDate.toString();
118
				String bookDateString = bookDate.getYear();
110 119
				int pos = StringUtils.lastIndexOf(result, bookDateString);
111
				result = result.substring(0, pos) + bookSectionDate + result.substring(pos + bookDateString.length());
120
				if (pos > -1 ){
121
					result = result.substring(0, pos) + bookSectionDate + result.substring(pos + bookDateString.length());
122
				}else{
123
					logger.warn("BookDateString (" + bookDateString + ") could not be found in result (" + result +")");
124
				}
112 125
			}else{
113 126
				result = result + beforeYear + bookSectionDate;
114 127
			}
cdmlib-model/src/test/java/eu/etaxonomy/cdm/strategy/cache/reference/BookDefaultCacheStrategyTest.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.strategy.cache.reference;
11

  
12

  
13
import junit.framework.Assert;
14

  
15
import org.apache.log4j.Logger;
16
import org.junit.Before;
17
import org.junit.BeforeClass;
18
import org.junit.Test;
19

  
20
import eu.etaxonomy.cdm.model.agent.Team;
21
import eu.etaxonomy.cdm.model.common.TimePeriod;
22
import eu.etaxonomy.cdm.model.reference.IBook;
23
import eu.etaxonomy.cdm.model.reference.ReferenceFactory;
24

  
25
/**
26
 * @author a.mueller
27
 * @date 16.06.2010
28
 *
29
 */
30
public class BookDefaultCacheStrategyTest {
31
	@SuppressWarnings("unused")
32
	private static final Logger logger = Logger.getLogger(BookDefaultCacheStrategyTest.class);
33
	
34
	private static IBook book1;
35
	private static Team bookTeam1;
36
	private static BookDefaultCacheStrategy defaultStrategy;
37
	private static final String detail1 = "55";
38
	
39
	/**
40
	 * @throws java.lang.Exception
41
	 */
42
	@BeforeClass
43
	public static void setUpBeforeClass() throws Exception {
44
		defaultStrategy = BookDefaultCacheStrategy.NewInstance();
45
	}
46

  
47
	/**
48
	 * @throws java.lang.Exception
49
	 */
50
	@Before
51
	public void setUp() throws Exception {
52
		book1 = ReferenceFactory.newBook();
53
		bookTeam1 = Team.NewTitledInstance("Book Author", "TT.");
54
	}
55
	
56
//**************************** TESTS ***********************************
57

  
58
	
59
	@Test
60
	public void testGetTitleCache(){
61
		book1.setTitle("My book");
62
		book1.setAuthorTeam(bookTeam1);
63
		book1.setDatePublished(TimePeriod.NewInstance(1975));
64
		
65
		Assert.assertEquals("Unexpected title cache.", "Book Author, My book. 1975", book1.getTitleCache());
66
		TimePeriod newDatePublished = TimePeriod.parseString("1975 (after Aug.)");
67
		book1.setDatePublished(newDatePublished);
68
		book1.setTitleCache(null, false);
69
		//TODO this behaviour needs to be discussed. Maybe better the complete date published string should be returned.
70
		Assert.assertEquals("Unexpected title cache.", "Book Author, My book", book1.getTitleCache());
71
		
72
		
73
	}
74
	
75

  
76
	
77
	@Test
78
	public void testGetNomenclaturalCitation(){
79
		book1.setTitle("My book");
80
		book1.setAuthorTeam(bookTeam1);
81
		book1.setDatePublished(TimePeriod.NewInstance(1975));
82
		Assert.assertEquals("My book: 55. 1975", book1.getNomenclaturalCitation(detail1));
83
	}
84
	
85
}
cdmlib-model/src/test/java/eu/etaxonomy/cdm/strategy/cache/reference/BookSectionDefaultCacheStrategyTest.java
20 20

  
21 21
import eu.etaxonomy.cdm.model.agent.Team;
22 22
import eu.etaxonomy.cdm.model.common.TimePeriod;
23
import eu.etaxonomy.cdm.model.reference.IArticle;
24 23
import eu.etaxonomy.cdm.model.reference.IBook;
25 24
import eu.etaxonomy.cdm.model.reference.IBookSection;
26
import eu.etaxonomy.cdm.model.reference.IJournal;
27
import eu.etaxonomy.cdm.model.reference.ReferenceBase;
28 25
import eu.etaxonomy.cdm.model.reference.ReferenceFactory;
29 26

  
30 27
/**

Also available in: Unified diff