cxf-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From serg...@apache.org
Subject svn commit: r1080726 - in /cxf/trunk/rt: frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/ext/search/ frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/ext/search/client/ frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/ext/search/ frontend/jaxrs/src...
Date Fri, 11 Mar 2011 18:53:53 GMT
Author: sergeyb
Date: Fri Mar 11 18:53:52 2011
New Revision: 1080726

URL: http://svn.apache.org/viewvc?rev=1080726&view=rev
Log:
[CXF-3370] Adding date related tests

Modified:
    cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/ext/search/FiqlParser.java
    cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/ext/search/SearchContextImpl.java
    cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/ext/search/SearchUtils.java
    cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/ext/search/client/FiqlSearchConditionBuilder.java
    cxf/trunk/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/ext/search/FiqlParserTest.java
    cxf/trunk/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/ext/search/client/FiqlSearchConditionBuilderTest.java
    cxf/trunk/rt/management-web/src/main/java/org/apache/cxf/management/web/logging/LogRecord.java
    cxf/trunk/rt/management-web/src/main/java/org/apache/cxf/management/web/logging/ReadOnlyFileStorage.java
    cxf/trunk/rt/management-web/src/main/java/org/apache/cxf/management/web/logging/atom/AtomPullServer.java
    cxf/trunk/rt/management-web/src/main/java/org/apache/cxf/management/web/logging/atom/converter/StandardConverter.java
    cxf/trunk/rt/management-web/src/test/java/org/apache/cxf/management/web/logging/ReadOnlyFileStorageTest.java

Modified: cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/ext/search/FiqlParser.java
URL: http://svn.apache.org/viewvc/cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/ext/search/FiqlParser.java?rev=1080726&r1=1080725&r2=1080726&view=diff
==============================================================================
--- cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/ext/search/FiqlParser.java
(original)
+++ cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/ext/search/FiqlParser.java
Fri Mar 11 18:53:52 2011
@@ -20,7 +20,6 @@ package org.apache.cxf.jaxrs.ext.search;
 
 import java.text.DateFormat;
 import java.text.ParseException;
-import java.text.SimpleDateFormat;
 import java.util.ArrayList;
 import java.util.Collections;
 import java.util.Date;
@@ -55,20 +54,30 @@ public class FiqlParser<T> {
     public static final String LE = "=le=";
     public static final String EQ = "==";
     public static final String NEQ = "!=";
+    
+    public static final String DEFAULT_DATE_FORMAT = "yyyy-MM-dd'T'HH:mm:ss.SSSZ";
+
+    private static final Pattern COMPARATORS_PATTERN; 
+    private static final Map<String, ConditionType> OPERATORS_MAP;
 
-    private static Map<String, ConditionType> operatorsMap;
     static {
-        operatorsMap = new HashMap<String, ConditionType>();
-        operatorsMap.put(GT, ConditionType.GREATER_THAN);
-        operatorsMap.put(GE, ConditionType.GREATER_OR_EQUALS);
-        operatorsMap.put(LT, ConditionType.LESS_THAN);
-        operatorsMap.put(LE, ConditionType.LESS_OR_EQUALS);
-        operatorsMap.put(EQ, ConditionType.EQUALS);
-        operatorsMap.put(NEQ, ConditionType.NOT_EQUALS);
+        // operatorsMap
+        OPERATORS_MAP = new HashMap<String, ConditionType>();
+        OPERATORS_MAP.put(GT, ConditionType.GREATER_THAN);
+        OPERATORS_MAP.put(GE, ConditionType.GREATER_OR_EQUALS);
+        OPERATORS_MAP.put(LT, ConditionType.LESS_THAN);
+        OPERATORS_MAP.put(LE, ConditionType.LESS_OR_EQUALS);
+        OPERATORS_MAP.put(EQ, ConditionType.EQUALS);
+        OPERATORS_MAP.put(NEQ, ConditionType.NOT_EQUALS);
+        
+        // pattern
+        String comparators = GT + "|" + GE + "|" + LT + "|" + LE + "|" + EQ + "|" + NEQ;
+        String s1 = "[\\p{ASCII}]+(" + comparators + ")";
+        COMPARATORS_PATTERN = Pattern.compile(s1);
     }
 
     private Beanspector<T> beanspector;
-
+    private Map<String, String> properties;
     /**
      * Creates FIQL parser.
      * 
@@ -76,7 +85,19 @@ public class FiqlParser<T> {
      *            accessible no-arg constructor and complementary setters to these used in
FIQL expressions.
      */
     public FiqlParser(Class<T> tclass) {
+        this(tclass, Collections.<String, String>emptyMap());
+    }
+    
+    /**
+     * Creates FIQL parser.
+     * 
+     * @param tclass - class of T used to create condition objects in built syntax tree.
Class T must have
+     *            accessible no-arg constructor and complementary setters to these used in
FIQL expressions.
+     * @param contextProperties            
+     */
+    public FiqlParser(Class<T> tclass, Map<String, String> contextProperties)
{
         beanspector = new Beanspector<T>(tclass);
+        properties = contextProperties;
     }
 
     /**
@@ -186,10 +207,7 @@ public class FiqlParser<T> {
     }
 
     private Comparison parseComparison(String expr) throws FiqlParseException {
-        String comparators = GT + "|" + GE + "|" + LT + "|" + LE + "|" + EQ + "|" + NEQ;
-        String s1 = "[\\p{ASCII}]+(" + comparators + ")";
-        Pattern p = Pattern.compile(s1);
-        Matcher m = p.matcher(expr);
+        Matcher m = COMPARATORS_PATTERN.matcher(expr);
         if (m.find()) {
             String name = expr.substring(0, m.start(1));
             String operator = m.group(1);
@@ -213,17 +231,17 @@ public class FiqlParser<T> {
             throw new FiqlParseException(e);
         }
         if (Date.class.isAssignableFrom(valueType)) {
-            DateFormat df;
             try {
-                df = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSSZ");
-                // zone in XML is "+01:00" in Java is "+0100"; stripping semicolon
-                int idx = value.lastIndexOf(':');
-                if (idx != -1) {
-                    String v = value.substring(0, idx) + value.substring(idx + 1);
-                    castedValue = df.parse(v);
-                } else {
-                    castedValue = df.parse(value);
+                DateFormat df = SearchUtils.getDateFormat(properties, DEFAULT_DATE_FORMAT);
+                String dateValue = value;
+                if (SearchUtils.isTimeZoneSupported(properties, Boolean.TRUE)) {
+                    // zone in XML is "+01:00" in Java is "+0100"; stripping semicolon
+                    int idx = value.lastIndexOf(':');
+                    if (idx != -1) {
+                        dateValue = value.substring(0, idx) + value.substring(idx + 1);
+                    }
                 }
+                castedValue = df.parse(dateValue);
             } catch (ParseException e) {
                 // is that duration?
                 try {
@@ -297,7 +315,7 @@ public class FiqlParser<T> {
                     beanspector.instantiate();
                     for (ASTNode<T> node : subnodes) {
                         FiqlParser<T>.Comparison comp = (Comparison)node;
-                        map.put(comp.getName(), operatorsMap.get(comp.getOperator()));
+                        map.put(comp.getName(), OPERATORS_MAP.get(comp.getOperator()));
                         beanspector.setValue(comp.getName(), comp.getValue());
                     }
                     return new SimpleSearchCondition<T>(map, beanspector.getBean());
@@ -348,7 +366,7 @@ public class FiqlParser<T> {
 
         public SearchCondition<T> build() throws FiqlParseException {
             T cond = createTemplate(name, value);
-            ConditionType ct = operatorsMap.get(operator);
+            ConditionType ct = OPERATORS_MAP.get(operator);
             
             if (isPrimitive(cond)) {
                 return new SimpleSearchCondition<T>(ct, cond); 

Modified: cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/ext/search/SearchContextImpl.java
URL: http://svn.apache.org/viewvc/cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/ext/search/SearchContextImpl.java?rev=1080726&r1=1080725&r2=1080726&view=diff
==============================================================================
--- cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/ext/search/SearchContextImpl.java
(original)
+++ cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/ext/search/SearchContextImpl.java
Fri Mar 11 18:53:52 2011
@@ -19,6 +19,9 @@
 
 package org.apache.cxf.jaxrs.ext.search;
 
+import java.util.LinkedHashMap;
+import java.util.Map;
+
 import javax.ws.rs.core.MultivaluedMap;
 
 import org.apache.cxf.jaxrs.utils.JAXRSUtils;
@@ -71,7 +74,11 @@ public class SearchContextImpl implement
         // we can use this method as a parser factory, ex
         // we can get parsers capable of parsing XQuery and other languages
         // depending on the properties set by a user
-        
-        return new FiqlParser<T>(cls); 
+        Map<String, String> props = new LinkedHashMap<String, String>(2);
+        props.put(SearchUtils.DATE_FORMAT_PROPERTY, 
+                  (String)message.getContextualProperty(SearchUtils.DATE_FORMAT_PROPERTY));
+        props.put(SearchUtils.TIMEZONE_SUPPORT_PROPERTY, 
+                  (String)message.getContextualProperty(SearchUtils.TIMEZONE_SUPPORT_PROPERTY));
+        return new FiqlParser<T>(cls, props); 
     }
 }

Modified: cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/ext/search/SearchUtils.java
URL: http://svn.apache.org/viewvc/cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/ext/search/SearchUtils.java?rev=1080726&r1=1080725&r2=1080726&view=diff
==============================================================================
--- cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/ext/search/SearchUtils.java
(original)
+++ cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/ext/search/SearchUtils.java
Fri Mar 11 18:53:52 2011
@@ -18,14 +18,30 @@
  */
 package org.apache.cxf.jaxrs.ext.search;
 
+import java.text.SimpleDateFormat;
+import java.util.Map;
+
 import org.apache.cxf.jaxrs.ext.search.sql.SQLPrinterVisitor;
 
 public final class SearchUtils {
     
+    public static final String DATE_FORMAT_PROPERTY = "search.date-format";
+    public static final String TIMEZONE_SUPPORT_PROPERTY = "search.timezone.support";
+    
     private SearchUtils() {
         
     }
     
+    public static SimpleDateFormat getDateFormat(Map<String, String> properties, String
defaultFormat) {
+        String dfProperty = properties.get(DATE_FORMAT_PROPERTY);
+        return new SimpleDateFormat(dfProperty == null ? defaultFormat : dfProperty);   

+    }
+    
+    public static boolean isTimeZoneSupported(Map<String, String> properties, Boolean
defaultValue) {
+        String tzProperty = properties.get(SearchUtils.TIMEZONE_SUPPORT_PROPERTY);
+        return tzProperty == null ? defaultValue : Boolean.valueOf(tzProperty);    
+    }
+    
     public static <T> String toSQL(SearchCondition<T> sc, String table, String...
columns) {
         SearchConditionVisitor<T> visitor = new SQLPrinterVisitor<T>(table, columns);
         sc.accept(visitor);

Modified: cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/ext/search/client/FiqlSearchConditionBuilder.java
URL: http://svn.apache.org/viewvc/cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/ext/search/client/FiqlSearchConditionBuilder.java?rev=1080726&r1=1080725&r2=1080726&view=diff
==============================================================================
--- cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/ext/search/client/FiqlSearchConditionBuilder.java
(original)
+++ cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/ext/search/client/FiqlSearchConditionBuilder.java
Fri Mar 11 18:53:52 2011
@@ -19,12 +19,14 @@
 package org.apache.cxf.jaxrs.ext.search.client;
 
 import java.text.DateFormat;
-import java.text.SimpleDateFormat;
+import java.util.Collections;
 import java.util.Date;
+import java.util.Map;
 
 import javax.xml.datatype.Duration;
 
 import org.apache.cxf.jaxrs.ext.search.FiqlParser;
+import org.apache.cxf.jaxrs.ext.search.SearchUtils;
 
 /**
  * Builds client-side search condition that passed to backend can be consumed by {@link FiqlParser}.
@@ -52,26 +54,41 @@ import org.apache.cxf.jaxrs.ext.search.F
  */
 public class FiqlSearchConditionBuilder implements SearchConditionBuilder {
 
+    private Map<String, String> properties;
+    
+    public FiqlSearchConditionBuilder() {
+        this (Collections.<String, String>emptyMap());    
+    }
+    
+    public FiqlSearchConditionBuilder(Map<String, String> properties) {
+        this.properties = properties;    
+    }
+    
     public String build() {
         return "";
     }
 
     public PartialCondition query() {
-        return new Builder();
+        return new Builder(properties);
     }
 
     private static class Builder implements SearchConditionBuilder.Property,
         SearchConditionBuilder.CompleteCondition, SearchConditionBuilder.PartialCondition
{
         private String result = "";
         private Builder parent;
-        private DateFormat df = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSSZ");
+        private DateFormat df;
+        private boolean timeZoneSupported;
 
-        public Builder() {
+        public Builder(Map<String, String> properties) {
             parent = null;
+            df = SearchUtils.getDateFormat(properties, FiqlParser.DEFAULT_DATE_FORMAT);
+            timeZoneSupported = SearchUtils.isTimeZoneSupported(properties, Boolean.TRUE);
         }
 
         public Builder(Builder parent) {
             this.parent = parent;
+            df = parent.getDateFormat();
+            timeZoneSupported = parent.isTimeZoneSupported();
         }
 
         public String build() {
@@ -83,6 +100,14 @@ public class FiqlSearchConditionBuilder 
             // }
         }
 
+        private DateFormat getDateFormat() {
+            return df;
+        }
+
+        private boolean isTimeZoneSupported() {
+            return timeZoneSupported;
+        }
+        
         // builds from parent but not further then exclude builder
         private String buildPartial(Builder exclude) {
             if (parent != null && !parent.equals(exclude)) {
@@ -250,9 +275,13 @@ public class FiqlSearchConditionBuilder 
 
         private String toString(Date date) {
             String s = df.format(date);
-            // zone in XML is "+01:00" in Java is "+0100"; adding semicolon
-            int len = s.length();
-            return s.substring(0, len - 2) + ":" + s.substring(len - 2, len);
+            if (timeZoneSupported) {
+                // zone in XML is "+01:00" in Java is "+0100"; adding semicolon
+                int len = s.length();
+                return s.substring(0, len - 2) + ":" + s.substring(len - 2, len);
+            } else {
+                return s;
+            }
         }
     }
 

Modified: cxf/trunk/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/ext/search/FiqlParserTest.java
URL: http://svn.apache.org/viewvc/cxf/trunk/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/ext/search/FiqlParserTest.java?rev=1080726&r1=1080725&r2=1080726&view=diff
==============================================================================
--- cxf/trunk/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/ext/search/FiqlParserTest.java
(original)
+++ cxf/trunk/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/ext/search/FiqlParserTest.java
Fri Mar 11 18:53:52 2011
@@ -22,7 +22,9 @@ import java.text.DateFormat;
 import java.text.ParseException;
 import java.text.SimpleDateFormat;
 import java.util.Date;
+import java.util.HashMap;
 import java.util.List;
+import java.util.Map;
 
 import javax.xml.datatype.DatatypeFactory;
 
@@ -142,9 +144,9 @@ public class FiqlParserTest extends Asse
     }
 
     @Test
-    public void testParseDate() throws FiqlParseException, ParseException {
+    public void testParseDateWithDefaultFormat() throws FiqlParseException, ParseException
{
         SearchCondition<Condition> filter = parser.parse("time=le=2010-03-11T18:00:00.000+00:00");
-        DateFormat df = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSSZ");
+        DateFormat df = new SimpleDateFormat(FiqlParser.DEFAULT_DATE_FORMAT);
         assertTrue(filter.isMet(new Condition("whatever", 15, df.parse("2010-03-11T18:00:00.000+0000"))));
         assertTrue(filter.isMet(new Condition(null, null, df.parse("2010-03-10T22:22:00.000+0000"))));
         assertFalse(filter.isMet(new Condition("blah", null, df.parse("2010-03-12T00:00:00.000+0000"))));
@@ -152,6 +154,21 @@ public class FiqlParserTest extends Asse
     }
 
     @Test
+    public void testParseDateWithCustomFormat() throws FiqlParseException, ParseException
{
+        Map<String, String> props = new HashMap<String, String>();
+        props.put(SearchUtils.DATE_FORMAT_PROPERTY, "yyyy-MM-dd'T'HH:mm:ss");
+        props.put(SearchUtils.TIMEZONE_SUPPORT_PROPERTY, "false");
+        parser = new FiqlParser<Condition>(Condition.class, props);
+        
+        SearchCondition<Condition> filter = parser.parse("time=le=2010-03-11T18:00:00");
+        DateFormat df = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss");
+        assertTrue(filter.isMet(new Condition("whatever", 15, df.parse("2010-03-11T18:00:00"))));
+        assertTrue(filter.isMet(new Condition(null, null, df.parse("2010-03-10T22:22:00"))));
+        assertFalse(filter.isMet(new Condition("blah", null, df.parse("2010-03-12T00:00:00"))));
+        assertFalse(filter.isMet(new Condition(null, 123, df.parse("2010-03-12T00:00:00"))));
+    }
+    
+    @Test
     public void testParseDateDuration() throws Exception {
         SearchCondition<Condition> filter = parser.parse("time=gt=-PT1M");
         Date now = new Date();

Modified: cxf/trunk/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/ext/search/client/FiqlSearchConditionBuilderTest.java
URL: http://svn.apache.org/viewvc/cxf/trunk/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/ext/search/client/FiqlSearchConditionBuilderTest.java?rev=1080726&r1=1080725&r2=1080726&view=diff
==============================================================================
--- cxf/trunk/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/ext/search/client/FiqlSearchConditionBuilderTest.java
(original)
+++ cxf/trunk/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/ext/search/client/FiqlSearchConditionBuilderTest.java
Fri Mar 11 18:53:52 2011
@@ -22,6 +22,8 @@ import java.text.DateFormat;
 import java.text.ParseException;
 import java.text.SimpleDateFormat;
 import java.util.Date;
+import java.util.HashMap;
+import java.util.Map;
 import java.util.TimeZone;
 
 import javax.xml.datatype.DatatypeConfigurationException;
@@ -30,6 +32,7 @@ import javax.xml.datatype.Duration;
 
 import static junit.framework.Assert.assertEquals;
 
+import org.apache.cxf.jaxrs.ext.search.SearchUtils;
 import org.apache.cxf.jaxrs.ext.search.client.SearchConditionBuilder.PartialCondition;
 
 import org.junit.AfterClass;
@@ -77,6 +80,21 @@ public class FiqlSearchConditionBuilderT
         String ret = b.query().is("foo").equalTo(d).build();
         assertEquals("foo==2011-03-01T12:34:00.000+00:00", ret);
     }
+    
+    @Test
+    public void testEqualToDateWithCustomFormat() throws ParseException {
+        
+        Map<String, String> props = new HashMap<String, String>();
+        props.put(SearchUtils.DATE_FORMAT_PROPERTY, "yyyy-MM-dd'T'HH:mm:ss");
+        props.put(SearchUtils.TIMEZONE_SUPPORT_PROPERTY, "false");
+        
+        Date d = df.parse("2011-03-01 12:34 +0000");
+        
+        FiqlSearchConditionBuilder bCustom = new FiqlSearchConditionBuilder(props);
+        
+        String ret = bCustom.query().is("foo").equalTo(d).build();
+        assertEquals("foo==2011-03-01T12:34:00", ret);
+    }
 
     @Test
     public void testEqualToDuration() throws ParseException, DatatypeConfigurationException
{

Modified: cxf/trunk/rt/management-web/src/main/java/org/apache/cxf/management/web/logging/LogRecord.java
URL: http://svn.apache.org/viewvc/cxf/trunk/rt/management-web/src/main/java/org/apache/cxf/management/web/logging/LogRecord.java?rev=1080726&r1=1080725&r2=1080726&view=diff
==============================================================================
--- cxf/trunk/rt/management-web/src/main/java/org/apache/cxf/management/web/logging/LogRecord.java
(original)
+++ cxf/trunk/rt/management-web/src/main/java/org/apache/cxf/management/web/logging/LogRecord.java
Fri Mar 11 18:53:52 2011
@@ -63,7 +63,7 @@ public class LogRecord {
     }
     
     public LogRecord(LogRecord copy) {
-        this.eventTimestamp = copy.getEventTimestamp();
+        this.eventTimestamp = copy.getDate();
         this.level = copy.getLevel();
         this.message = copy.getMessage();
         this.loggerName = copy.getLoggerName();
@@ -84,7 +84,7 @@ public class LogRecord {
     public static LogRecord fromJUL(java.util.logging.LogRecord julRecord) {
         Validate.notNull(julRecord, "julRecord is null");
         LogRecord record = new LogRecord();
-        record.setEventTimestamp(new Date(julRecord.getMillis()));
+        record.setDate(new Date(julRecord.getMillis()));
         record.setLevel(LogLevel.fromJUL(julRecord.getLevel()));
         record.setLoggerName(julRecord.getLoggerName());
         if (julRecord.getThrown() != null) {
@@ -106,13 +106,13 @@ public class LogRecord {
     }
     
     @XmlElement(namespace = "http://cxf.apache.org/log")
-    public Date getEventTimestamp() {
+    public Date getDate() {
         return eventTimestamp;
     }
 
-    public void setEventTimestamp(Date eventTimestamp) {
-        Validate.notNull(eventTimestamp, "eventTimestamp is null");
-        this.eventTimestamp = eventTimestamp;
+    public void setDate(Date date) {
+        Validate.notNull(date, "eventTimestamp is null");
+        this.eventTimestamp = date;
     }
 
     @XmlElement(namespace = "http://cxf.apache.org/log")

Modified: cxf/trunk/rt/management-web/src/main/java/org/apache/cxf/management/web/logging/ReadOnlyFileStorage.java
URL: http://svn.apache.org/viewvc/cxf/trunk/rt/management-web/src/main/java/org/apache/cxf/management/web/logging/ReadOnlyFileStorage.java?rev=1080726&r1=1080725&r2=1080726&view=diff
==============================================================================
--- cxf/trunk/rt/management-web/src/main/java/org/apache/cxf/management/web/logging/ReadOnlyFileStorage.java
(original)
+++ cxf/trunk/rt/management-web/src/main/java/org/apache/cxf/management/web/logging/ReadOnlyFileStorage.java
Fri Mar 11 18:53:52 2011
@@ -239,7 +239,7 @@ public class ReadOnlyFileStorage impleme
                 String fileModifiedDate = logFileInfo.getFileModified();
                 logDate = fileModifiedDate != null ? fileModifiedDate + " " + logDate : logDate;
                 Date date = recordDateFormat.parse(logDate);
-                record.setEventTimestamp(date);
+                record.setDate(date);
             } catch (Exception ex) {
                 // ignore
             }

Modified: cxf/trunk/rt/management-web/src/main/java/org/apache/cxf/management/web/logging/atom/AtomPullServer.java
URL: http://svn.apache.org/viewvc/cxf/trunk/rt/management-web/src/main/java/org/apache/cxf/management/web/logging/atom/AtomPullServer.java?rev=1080726&r1=1080725&r2=1080726&view=diff
==============================================================================
--- cxf/trunk/rt/management-web/src/main/java/org/apache/cxf/management/web/logging/atom/AtomPullServer.java
(original)
+++ cxf/trunk/rt/management-web/src/main/java/org/apache/cxf/management/web/logging/atom/AtomPullServer.java
Fri Mar 11 18:53:52 2011
@@ -394,7 +394,7 @@ public class AtomPullServer extends Abst
         sb.append("<tr><th>Date</th><th>Level</th><th>Logger</th><th>Message</th></tr>");
         for (LogRecord lr : list) {
             sb.append("<tr>");
-            sb.append("<td>" + df.format(lr.getEventTimestamp()) + "</td>");
+            sb.append("<td>" + df.format(lr.getDate()) + "</td>");
             sb.append("<td>" + lr.getLevel().toString() + "</td>");
             sb.append("<td>" + lr.getLoggerName() + "</td>");
             String message = null;
@@ -476,7 +476,7 @@ public class AtomPullServer extends Abst
     private static class LogRecordComparator implements Comparator<LogRecord> {
 
         public int compare(LogRecord r1, LogRecord r2) {
-            return r1.getEventTimestamp().compareTo(r2.getEventTimestamp()) * -1;
+            return r1.getDate().compareTo(r2.getDate()) * -1;
         }
         
     }

Modified: cxf/trunk/rt/management-web/src/main/java/org/apache/cxf/management/web/logging/atom/converter/StandardConverter.java
URL: http://svn.apache.org/viewvc/cxf/trunk/rt/management-web/src/main/java/org/apache/cxf/management/web/logging/atom/converter/StandardConverter.java?rev=1080726&r1=1080725&r2=1080726&view=diff
==============================================================================
--- cxf/trunk/rt/management-web/src/main/java/org/apache/cxf/management/web/logging/atom/converter/StandardConverter.java
(original)
+++ cxf/trunk/rt/management-web/src/main/java/org/apache/cxf/management/web/logging/atom/converter/StandardConverter.java
Fri Mar 11 18:53:52 2011
@@ -218,7 +218,7 @@ public class StandardConverter implement
         // forget about single line "addExtension().setText()" since
         // javac failure "org.apache.abdera.model.Element cannot be dereferenced"
         Element e = erec.addExtension(qn("eventTimestamp"));
-        e.setText(toAtomDateFormat(record.getEventTimestamp()));
+        e.setText(toAtomDateFormat(record.getDate()));
         e = erec.addExtension(qn("level"));
         e.setText(record.getLevel().toString());
         e = erec.addExtension(qn("loggerName"));
@@ -348,7 +348,7 @@ public class StandardConverter implement
                 entry.setSummary(records.get(0).getLoggerName() + " : " + records.get(0).getMessage());
             }
             if (records.size() > 0) {
-                entry.setUpdated(toAtomDateFormat(records.get(0).getEventTimestamp()));
+                entry.setUpdated(toAtomDateFormat(records.get(0).getDate()));
             }
         }
     }

Modified: cxf/trunk/rt/management-web/src/test/java/org/apache/cxf/management/web/logging/ReadOnlyFileStorageTest.java
URL: http://svn.apache.org/viewvc/cxf/trunk/rt/management-web/src/test/java/org/apache/cxf/management/web/logging/ReadOnlyFileStorageTest.java?rev=1080726&r1=1080725&r2=1080726&view=diff
==============================================================================
--- cxf/trunk/rt/management-web/src/test/java/org/apache/cxf/management/web/logging/ReadOnlyFileStorageTest.java
(original)
+++ cxf/trunk/rt/management-web/src/test/java/org/apache/cxf/management/web/logging/ReadOnlyFileStorageTest.java
Fri Mar 11 18:53:52 2011
@@ -24,8 +24,10 @@ import java.util.List;
 import java.util.Map;
 
 import org.apache.cxf.jaxrs.ext.search.ConditionType;
+import org.apache.cxf.jaxrs.ext.search.FiqlParser;
 import org.apache.cxf.jaxrs.ext.search.PrimitiveSearchCondition;
 import org.apache.cxf.jaxrs.ext.search.SearchCondition;
+import org.apache.cxf.jaxrs.ext.search.SearchUtils;
 
 import org.junit.After;
 import org.junit.Assert;
@@ -154,6 +156,58 @@ public class ReadOnlyFileStorageTest ext
     }
     
     @Test
+    public void testReadRecordsWithMultipleFilesAndSearchDates() throws Exception {
+        
+        List<String> locations = new ArrayList<String>();
+        locations.add(getClass().getResource("logs/2011-01-22-karaf.log").toURI().getPath());
+        locations.add(getClass().getResource("logs/2011-01-23-karaf.log").toURI().getPath());
+        storage.setLogLocations(locations);
+        
+        Map<String, String> props = new HashMap<String, String>();
+        props.put(SearchUtils.DATE_FORMAT_PROPERTY, "yyyy-MM-dd'T'HH:mm:ss SSS");
+        props.put(SearchUtils.TIMEZONE_SUPPORT_PROPERTY, "false");
+        FiqlParser<LogRecord> parser = new FiqlParser<LogRecord>(LogRecord.class,
props);
+        
+        SearchCondition<LogRecord> sc = parser.parse("date==2011-01-22T11:49:17 184");
+        
+        List<LogRecord> recordsFirstPage1 = readPage(1, sc, 2, 1);
+        List<LogRecord> recordsFirstPage2 = readPage(1, sc, 2, 1);
+        compareRecords(recordsFirstPage1, recordsFirstPage2);
+        
+        LogRecord record = recordsFirstPage1.get(0);
+        assertEquals("Initializing Timer", record.getMessage());
+    }
+    
+    @Test
+    public void testReadRecordsWithMultipleFilesAndSearchDates2() throws Exception {
+        
+        List<String> locations = new ArrayList<String>();
+        locations.add(getClass().getResource("logs/2011-01-22-karaf.log").toURI().getPath());
+        locations.add(getClass().getResource("logs/2011-01-23-karaf.log").toURI().getPath());
+        storage.setLogLocations(locations);
+        
+        Map<String, String> props = new HashMap<String, String>();
+        props.put(SearchUtils.DATE_FORMAT_PROPERTY, "yyyy-MM-dd");
+        props.put(SearchUtils.TIMEZONE_SUPPORT_PROPERTY, "false");
+        FiqlParser<LogRecord> parser = new FiqlParser<LogRecord>(LogRecord.class,
props);
+        
+        SearchCondition<LogRecord> sc = parser.parse("date=lt=2011-01-23");
+        
+        List<LogRecord> recordsFirstPage1 = readPage(1, sc, 32, 32);
+        readPage(2, sc, 32, 0);
+        List<LogRecord> recordsFirstPage2 = readPage(1, sc, 32, 32);
+                
+        compareRecords(recordsFirstPage1, recordsFirstPage2);
+        
+        LogRecord firstRecord = recordsFirstPage1.get(0);
+        assertEquals("Starting JMX OSGi agent", firstRecord.getMessage());
+        LogRecord lastRecord = recordsFirstPage1.get(31);
+        assertTrue(lastRecord.getMessage().contains("Pax Web available at"));
+        
+        readPage(2, sc, 32, 0);
+    }
+    
+    @Test
     public void testReadRecordsWithMultipleFiles2() throws Exception {
         
         List<String> locations = new ArrayList<String>();
@@ -212,7 +266,7 @@ public class ReadOnlyFileStorageTest ext
             LogRecord r1 = records1.get(i);
             LogRecord r2 = records2.get(i);
             assertEquals(r1.getLevel(), r2.getLevel());
-            assertEquals(r1.getEventTimestamp(), r2.getEventTimestamp());
+            assertEquals(r1.getDate(), r2.getDate());
             assertEquals(r1.getMessage(), r2.getMessage());
         }    
     }



Mime
View raw message