Project

General

Profile

« Previous | Next » 

Revision 61157129

Added by Andreas Müller almost 3 years ago

ref #9326, ref #3764 fix secion in book-section handling and some cleanup in ReferenceDefaultCacheStrategy

View differences:

cdmlib-model/src/main/java/eu/etaxonomy/cdm/strategy/cache/reference/ReferenceDefaultCacheStrategy.java
55 55

  
56 56
    private final static UUID uuid = UUID.fromString("63e669ca-c6be-4a8a-b157-e391c22580f9");
57 57

  
58
    //article
59
    public static final String UNDEFINED_JOURNAL = "undefined journal " + UTF8.EN_DASH;
60 58
    private static final String afterAuthor = ": ";
61

  
62
    //book
63

  
64
    //(book?) section
65
    private static final String afterSectionAuthor = ": ";
66 59
    private static final String afterInRefAuthor = ", ";  //TODO needs discussion
67 60

  
61
    //article
62
    public static final String UNDEFINED_JOURNAL = "undefined journal " + UTF8.EN_DASH;
68 63

  
69 64
    //in reference
70
    private String biblioInSeparator = UTF8.EN_DASH + " In: "; //#9529
65
    private static String biblioInSeparator = " " + UTF8.EN_DASH + " In: "; //#9529
71 66
    private String biblioArticleInSeparator = UTF8.EN_DASH + " "; //#9529
67
    private String webpageUriSeparator = " "+UTF8.EN_DASH+" ";
72 68

  
73 69
    //common
74 70
    private static final String blank = " ";
......
126 122
            result = titleCacheDefaultReference(reference, isNotAbbrev);
127 123
        }
128 124
        if (reference.getType() == ReferenceType.WebPage && reference.getUri() != null && !result.contains(reference.getUri().toString())){
129
            result = CdmUtils.concat(" "+UTF8.EN_DASH+" ", result, reference.getUri().toString());
125
            result = CdmUtils.concat(webpageUriSeparator, result, reference.getUri().toString());
130 126
        }
131 127
        if(reference.getAccessed() != null){
132 128
            //TODO still a bit preliminary, also brackets may change in future
......
214 210

  
215 211
    //section, book section or generic with inRef
216 212
    private String titleCacheRealInRef(Reference reference, boolean isAbbrev) {
217
        ReferenceType type = reference.getType();
213

  
218 214
        Reference inRef = reference.getInReference();
219
        boolean hasInRef = (inRef != null);
220 215

  
221
        String inRefAuthorAndTitle;
222
        //copy from InRefDefaultCacheStrategyBase
223
        if (inRef != null){
224
            String inRefTitle = TitleWithoutYearAndAuthorHelper.getTitleWithoutYearAndAuthor(inRef, isAbbrev, false);
225
            TeamOrPersonBase<?> inRefAuthor = inRef.getAuthorship();
226
            String authorStr = (inRefAuthor == null)? "" : CdmUtils.getPreferredNonEmptyString(inRefAuthor.getTitleCache(),
227
                    inRefAuthor.getNomenclaturalTitle(), isAbbrev, trim);
228
            inRefAuthorAndTitle = CdmUtils.concat(afterInRefAuthor, authorStr, inRefTitle);
229
        }else{
230
            inRefAuthorAndTitle = String.format("- undefined %s -", getUndefinedLabel(type));
216
        String inRefPart = getInRefAuthorAndTitle(inRef, reference.getType(), isAbbrev);
217
        if (inRef != null && !inRef.isArticle()){
218
            inRefPart = addInRefPages(inRef, inRefPart);
219
        }
220
        inRefPart = CdmUtils.addTrailingDotIfNotExists(inRefPart);
221
        inRefPart = biblioInSeparator + inRefPart;
222
        if (inRef != null && inRef.isBookSection()){
223
            String inInRefPart = getInRefAuthorAndTitle(inRef.getInReference(), inRef.getType(), isAbbrev);
224
            inInRefPart = CdmUtils.addTrailingDotIfNotExists(inInRefPart);
225
            inInRefPart = biblioInSeparator + inInRefPart;
226
            inRefPart += inInRefPart;
231 227
        }
232
        inRefAuthorAndTitle = CdmUtils.addTrailingDotIfNotExists(inRefAuthorAndTitle);
233

  
234
        //in
235
        String result = biblioInSeparator + inRefAuthorAndTitle;
236 228

  
237 229
        //section title
238 230
        String title = CdmUtils.getPreferredNonEmptyString(
......
241 233
            title = title.substring(0, title.length() - 1);
242 234
        }
243 235
        //pages
244
        String pages = getPages(reference);
245
        if (isNotBlank(pages)){
246
            title = CdmUtils.concat(", ", title, pages);
247
        }
236
        title = addInRefPages(reference, title);
237

  
238
        String result;
248 239
        if (title.length() > 0){
249
            result = title.trim() + "." + blank + result;
240
            result = title.trim() + "." + inRefPart;
241
        }else{
242
            result = inRefPart;
250 243
        }
251 244

  
252 245
        //section author
......
256 249

  
257 250
        //date
258 251
        String dateStr = null;
259
        VerbatimTimePeriod date = (reference.getDatePublished() != null && ! reference.getDatePublished().isEmpty())? reference.getDatePublished() : null;
260
        if (date == null && hasInRef && reference.getInReference().getDatePublished() != null && !reference.getInReference().getDatePublished().isEmpty()){
252
        VerbatimTimePeriod date = reference.hasDatePublished() ? reference.getDatePublished() : null;
253
        if (date == null && inRef != null && inRef.hasDatePublished()){
261 254
            date = reference.getInReference().getDatePublished();
255
            if (date == null && inRef.isSection() && inRef.getInReference() != null && inRef.getInReference().hasDatePublished()){
256
                date = inRef.getInReference().getDatePublished();
257
            }
262 258
        }
263 259
        if (date != null){
264 260
            dateStr = date.getYear();
......
266 262

  
267 263
        String authorAndYear = CdmUtils.concat(" ", authorStr, dateStr);
268 264

  
269
        String sep = result.startsWith(biblioInSeparator)? " ": afterSectionAuthor;
265
        String sep = result.startsWith(biblioInSeparator)? "": afterAuthor;
270 266
        result = CdmUtils.concat(sep, authorAndYear, result);
271 267

  
272 268
        return result;
273 269
    }
274 270

  
271
    private String addInRefPages(Reference reference, String title) {
272
        String pages = getPages(reference);
273
        if (isNotBlank(pages)){
274
            title = CdmUtils.concat(", ", title, pages);
275
        }
276
        return title;
277
    }
278

  
279
    private String getInRefAuthorAndTitle(Reference inRef, ReferenceType type, boolean isAbbrev) {
280
        String inRefAuthorAndTitle;
281
        if (inRef != null){
282
            String inRefTitle = TitleWithoutYearAndAuthorHelper.getTitleWithoutYearAndAuthor(inRef, isAbbrev, false);
283
            TeamOrPersonBase<?> inRefAuthor = inRef.getAuthorship();
284
            String authorStr = (inRefAuthor == null)? "" : CdmUtils.getPreferredNonEmptyString(inRefAuthor.getTitleCache(),
285
                    inRefAuthor.getNomenclaturalTitle(), isAbbrev, trim);
286
            inRefAuthorAndTitle = CdmUtils.concat(afterInRefAuthor, authorStr, inRefTitle);
287
        }else{
288
            inRefAuthorAndTitle = String.format("- undefined %s -", getUndefinedLabel(type));
289
        }
290

  
291
        return inRefAuthorAndTitle;
292
    }
293

  
275 294
    private static final String pageNoRe = "[0-9iIvVxXlLcCdDmM]+";
276 295
    private String getPages(Reference reference) {
277 296

  
278
        if (isBlank(reference.getPages())){
297
        if (reference == null || isBlank(reference.getPages())){
279 298
            return null;
280 299
        }else if (reference.getPages().matches(pageNoRe + "\\s*[-"+UTF8.EN_DASH+"]\\s*"+ pageNoRe)){
281 300
            return "pp. " + reference.getPages();
......
380 399
        }else if (type == ReferenceType.Generic){
381 400
            return "generic reference";
382 401
        }else if (type == ReferenceType.Section){
383
            return "in reference";
402
            return "in-reference";
384 403
        } else {
385
            return type.getLabel();
404
            return "in-reference for " + type.getLabel();
386 405
        }
387 406
    }
388 407

  
cdmlib-model/src/main/java/eu/etaxonomy/cdm/strategy/cache/reference/TitleWithoutYearAndAuthorHelper.java
64 64
            return getTitleWithoutYearAndAuthorWebPage(ref, isAbbrev);
65 65
        }else if (type == ReferenceType.Thesis) {
66 66
            return getTitleWithoutYearAndAuthorThesis(ref, isAbbrev);
67
        }else if (type == ReferenceType.Section || type == ReferenceType.BookSection){
67
        }else if(type == ReferenceType.BookSection){
68
            return getTitleWithoutYearAndAuthorBookSection(ref, isAbbrev);
69
        }else if (type == ReferenceType.Section || type == ReferenceType.BookSection ){
68 70
            // not needed in Section
69 71
            logger.warn("Questionable procedure call. Procedure not implemented because not needed. ");
70 72
            return null;
......
149 151
            title =  title.substring(1, len-1); //  SUBSTRING(@TitelAbbrev,1,@LEN-1)
150 152
        }
151 153

  
152

  
153 154
        boolean needsComma = false;
154 155
        //titelAbbrev
155 156
        if (!"".equals(title) ){
......
196 197
        nomRefCache += volumePart;
197 198

  
198 199
        //delete .
199
        while (nomRefCache.endsWith(".")){
200
            nomRefCache = nomRefCache.substring(0, nomRefCache.length()-1);
201
        }
200
        nomRefCache = CdmUtils.removeTrailingDots(nomRefCache);
202 201

  
203 202
        return nomRefCache.trim();
204 203
    }
205 204

  
205
    private static String getTitleWithoutYearAndAuthorBookSection(Reference ref, boolean isAbbrev){
206
        if (ref == null){
207
            return null;
208
        }
209
        String title = CdmUtils.getPreferredNonEmptyString(ref.getTitle(), ref.getAbbrevTitle(), isAbbrev, true);
210
        title = CdmUtils.removeTrailingDots(title);
211

  
212
        return title.trim();
213
    }
214

  
206 215
    public static  String getTitleWithoutYearAndAuthorGeneric(Reference genericReference, boolean isAbbrev){
207 216
        if (genericReference == null){
208 217
            return null;

Also available in: Unified diff