Project

General

Profile

Revision 2f973202

ID2f9732022e97eb872bef7beba334c1696ee62b7d
Parent 6b381b7d
Child e46ded05

Added by Andreas Müller over 3 years ago

fix #5258 add accessed to WebPage cache strategy

View differences:

cdmlib-model/src/main/java/eu/etaxonomy/cdm/strategy/cache/reference/DefaultReferenceCacheStrategy.java
12 12

  
13 13
import org.apache.commons.lang.StringUtils;
14 14
import org.apache.log4j.Logger;
15
import org.joda.time.DateTime;
16
import org.joda.time.format.DateTimeFormat;
17
import org.joda.time.format.DateTimeFormatter;
15 18

  
16 19
import eu.etaxonomy.cdm.common.CdmUtils;
17 20
import eu.etaxonomy.cdm.model.agent.TeamOrPersonBase;
......
136 139
        }else{
137 140
            result = titleCacheDefaultReference(reference, isNotAbbrev);
138 141
        }
142
        if (reference.getType() == ReferenceType.WebPage){
143
            //might become UTF8.EN_DASH in future
144
            result = CdmUtils.concat(" - ", result, reference.getUri().toString());
145
        }
146
        if(reference.getAccessed() != null){
147
            //TODO still a bit preliminary, also brackets may change in future
148
            result = result + " [accessed " + getAccessedString(reference.getAccessed()) +"]";
149
        }
150
        return result;
151
    }
152

  
153

  
154
    /**
155
     * @param accessed
156
     * @return
157
     */
158
    private String getAccessedString(DateTime accessed) {
159
        DateTimeFormatter formatter = DateTimeFormat.forPattern("yyyy-MM-dd HH:mm");
160
        String result = formatter.print(accessed);
161
        if (result.endsWith(" 00:00")){
162
            result = result.replace(" 00:00", "");
163
        }
139 164
        return result;
140 165
    }
141 166

  
cdmlib-model/src/test/java/eu/etaxonomy/cdm/strategy/cache/reference/DefaultReferenceCacheStrategyTest.java
14 14
import java.net.URI;
15 15

  
16 16
import org.apache.log4j.Logger;
17
import org.joda.time.DateTime;
17 18
import org.junit.Assert;
18 19
import org.junit.Before;
19 20
import org.junit.BeforeClass;
20
import org.junit.Ignore;
21 21
import org.junit.Test;
22 22

  
23 23
import eu.etaxonomy.cdm.model.agent.Person;
......
694 694
// ********************************** WEB PAGE ********************************************/
695 695

  
696 696
    @Test
697
    @Ignore //under development
698 697
    public void testWebPageGetTitleCache(){
698
        //still preliminary, may be modified in future
699 699
        webPage1.setTitle("Flora of Israel Online");
700 700
        webPage1.setUri(URI.create("http://flora.huji.ac.il"));
701 701
        webPage1.setAuthorship(webPageTeam1);
702
        webPage1.setDatePublished(TimePeriodParser.parseString("[accessed in 2011]"));
703
        //taken from Berlin Model, may be modified in future
704
        Assert.assertEquals("Unexpected title cache.", "Authorteam, D. - Flora of Israel Online - http://flora.huji.ac.il [accessed in 2011]", webPage1.getTitleCache());
702
        webPage1.setAccessed(DateTime.parse("2001-01-05"));
703
        Assert.assertEquals("Unexpected title cache.",
704
                "Authorteam, D., Flora of Israel Online - http://flora.huji.ac.il [accessed 2001-01-05]",
705
                webPage1.getTitleCache());
705 706
    }
706 707

  
707 708
//  @Test

Also available in: Unified diff

Add picture from clipboard (Maximum size: 40 MB)