summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorpshi2011-11-21 05:24:11 (EST)
committer mwu2011-11-21 05:24:11 (EST)
commit1f98f6c7bebb2c4d15e00594a74e7e2fff1940bd (patch)
tree02781567b42f698b1995d37c2022bd458b7684b5
parent7cfa0245d04ef46ac84f964f3dd77f69463d4e8a (diff)
downloadorg.eclipse.birt-1f98f6c7bebb2c4d15e00594a74e7e2fff1940bd.zip
org.eclipse.birt-1f98f6c7bebb2c4d15e00594a74e7e2fff1940bd.tar.gz
org.eclipse.birt-1f98f6c7bebb2c4d15e00594a74e7e2fff1940bd.tar.bz2
support previous week to date in model adapter, update unit test
-rw-r--r--data/org.eclipse.birt.report.data.adapter/src/org/eclipse/birt/report/data/adapter/api/timeFunction/BaseTimeFunction.java7
-rw-r--r--data/org.eclipse.birt.report.data.adapter/src/org/eclipse/birt/report/data/adapter/api/timeFunction/IBuildInBaseTimeFunction.java1
-rw-r--r--data/org.eclipse.birt.report.data.adapter/src/org/eclipse/birt/report/data/adapter/api/timeFunction/TimeFunctionHandle.java6
-rw-r--r--data/org.eclipse.birt.report.data.adapter/src/org/eclipse/birt/report/data/adapter/api/timeFunction/TimeFunctionManager.java42
-rw-r--r--data/org.eclipse.birt.report.data.adapter/src/org/eclipse/birt/report/data/adapter/i18n/Messages.properties2
-rw-r--r--data/org.eclipse.birt.report.data.adapter/src/org/eclipse/birt/report/data/adapter/i18n/ResourceConstants.java2
-rw-r--r--data/org.eclipse.birt.report.data.adapter/src/org/eclipse/birt/report/data/adapter/impl/ModelAdapter.java24
-rw-r--r--data/org.eclipse.birt.report.data.adapter/test/org/eclipse/birt/report/data/adapter/internal/script/TimeFunctionManagerTest.java4
8 files changed, 74 insertions, 14 deletions
diff --git a/data/org.eclipse.birt.report.data.adapter/src/org/eclipse/birt/report/data/adapter/api/timeFunction/BaseTimeFunction.java b/data/org.eclipse.birt.report.data.adapter/src/org/eclipse/birt/report/data/adapter/api/timeFunction/BaseTimeFunction.java
index d9b2c59..0a34900 100644
--- a/data/org.eclipse.birt.report.data.adapter/src/org/eclipse/birt/report/data/adapter/api/timeFunction/BaseTimeFunction.java
+++ b/data/org.eclipse.birt.report.data.adapter/src/org/eclipse/birt/report/data/adapter/api/timeFunction/BaseTimeFunction.java
@@ -122,6 +122,13 @@ public class BaseTimeFunction implements ITimeFunction
Message.getMessage( ResourceConstants.TIMEFUNCITON_N1 ),
true ) );
}
+ else if ( this.name.equals( IBuildInBaseTimeFunction.PREVIOUS_WEEK_TO_DATE ) )
+ {
+ arguments.add( new ArgumentInfo( IArgumentInfo.N_PERIOD1,
+ Message.getMessage( ResourceConstants.TIMEFUNCITON_N1_DISPLAYNAME ),
+ Message.getMessage( ResourceConstants.TIMEFUNCITON_N1 ),
+ true ) );
+ }
else
if( this.name.equals( IBuildInBaseTimeFunction.PREVIOUS_MONTH_TO_DATE ) )
{
diff --git a/data/org.eclipse.birt.report.data.adapter/src/org/eclipse/birt/report/data/adapter/api/timeFunction/IBuildInBaseTimeFunction.java b/data/org.eclipse.birt.report.data.adapter/src/org/eclipse/birt/report/data/adapter/api/timeFunction/IBuildInBaseTimeFunction.java
index a6fe185..d37350f 100644
--- a/data/org.eclipse.birt.report.data.adapter/src/org/eclipse/birt/report/data/adapter/api/timeFunction/IBuildInBaseTimeFunction.java
+++ b/data/org.eclipse.birt.report.data.adapter/src/org/eclipse/birt/report/data/adapter/api/timeFunction/IBuildInBaseTimeFunction.java
@@ -31,6 +31,7 @@ public interface IBuildInBaseTimeFunction
public static final String PREVIOUS_YEAR = "PREVIOUS YEAR";
public static final String MONTH_TO_DATE_LAST_YEAR = "MONTH TO DATE LAST YEAR";
public static final String QUARTER_TO_DATE_LAST_YEAR = "QUARTER TO DATE LAST YEAR";
+ public static final String PREVIOUS_WEEK_TO_DATE = "PREVIOUS WEEK TO DATE";
public static final String PREVIOUS_MONTH_TO_DATE = "PREVIOUS MONTH TO DATE";
public static final String PREVIOUS_QUARTER_TO_DATE = "PREVIOUS QUARTER TO DATE";
public static final String PREVIOUS_YEAR_TO_DATE = "PREVIOUS YEAR TO DATE";
diff --git a/data/org.eclipse.birt.report.data.adapter/src/org/eclipse/birt/report/data/adapter/api/timeFunction/TimeFunctionHandle.java b/data/org.eclipse.birt.report.data.adapter/src/org/eclipse/birt/report/data/adapter/api/timeFunction/TimeFunctionHandle.java
index 789fcc4..1e32725 100644
--- a/data/org.eclipse.birt.report.data.adapter/src/org/eclipse/birt/report/data/adapter/api/timeFunction/TimeFunctionHandle.java
+++ b/data/org.eclipse.birt.report.data.adapter/src/org/eclipse/birt/report/data/adapter/api/timeFunction/TimeFunctionHandle.java
@@ -76,6 +76,12 @@ public class TimeFunctionHandle
local ),
Message.getMessage( ResourceConstants.TIMEFUNCITON_PREVIOUS_MONTH_DES,
local ) ) );
+ baseTimeFunctionMap.put( IBuildInBaseTimeFunction.PREVIOUS_WEEK_TO_DATE,
+ new BaseTimeFunction( IBuildInBaseTimeFunction.PREVIOUS_WEEK_TO_DATE,
+ Message.getMessage( ResourceConstants.TIMEFUNCITON_PREVIOUS_WEEK_TO_DATE,
+ local ),
+ Message.getMessage( ResourceConstants.TIMEFUNCITON_PREVIOUS_WEEK_TO_DATE_DES,
+ local ) ) );
baseTimeFunctionMap.put( IBuildInBaseTimeFunction.PREVIOUS_MONTH_TO_DATE,
new BaseTimeFunction( IBuildInBaseTimeFunction.PREVIOUS_MONTH_TO_DATE,
Message.getMessage( ResourceConstants.TIMEFUNCITON_PREVIOUS_MONTH_TO_DATE,
diff --git a/data/org.eclipse.birt.report.data.adapter/src/org/eclipse/birt/report/data/adapter/api/timeFunction/TimeFunctionManager.java b/data/org.eclipse.birt.report.data.adapter/src/org/eclipse/birt/report/data/adapter/api/timeFunction/TimeFunctionManager.java
index ec03cdf..5e8811a 100644
--- a/data/org.eclipse.birt.report.data.adapter/src/org/eclipse/birt/report/data/adapter/api/timeFunction/TimeFunctionManager.java
+++ b/data/org.eclipse.birt.report.data.adapter/src/org/eclipse/birt/report/data/adapter/api/timeFunction/TimeFunctionManager.java
@@ -45,16 +45,14 @@ public class TimeFunctionManager
List<String> timeType = new ArrayList<String>( );
if ( dim != null && dim.isTimeType( ) )
{
- String mostDetailedLevel = null, startingLevels = null;
+ String startingLevels = null;
if ( !timeLevelsInXtab.isEmpty( ) && !isStaticReferenceDate )
{
startingLevels = timeLevelsInXtab.get( 0 ).toString( );
- mostDetailedLevel = timeLevelsInXtab.get( timeLevelsInXtab.size( ) - 1 )
- .toString( );
}
TabularHierarchyHandle hierhandle = (TabularHierarchyHandle) dim.getDefaultHierarchy( );
List levels = hierhandle.getContents( TabularHierarchyHandle.LEVELS_PROP );
- for ( int i = 0; i < levels.size( ); i++ )
+ for ( int i = 0, j = 0; i < levels.size( ); i++ )
{
TabularLevelHandle level = (TabularLevelHandle) levels.get( i );
if ( startingLevels != null
@@ -64,16 +62,20 @@ public class TimeFunctionManager
.equalsIgnoreCase( DesignChoiceConstants.DATE_TIME_LEVEL_TYPE_YEAR ) )
return availableFunctions;
}
-
- if ( mostDetailedLevel != null
- && level.getName( ).equals( mostDetailedLevel ) )
+ if (timeLevelsInXtab.isEmpty() || isStaticReferenceDate)
{
timeType.add( level.getDateTimeLevelType( ) );
- break;
}
else
{
- timeType.add( level.getDateTimeLevelType( ) );
+ if (level.getName().equals(timeLevelsInXtab.get(j)))
+ {
+ timeType.add( level.getDateTimeLevelType( ) );
+ if ( ++j >= timeLevelsInXtab.size() )
+ {
+ break;
+ }
+ }
}
}
// no year level in time dimension
@@ -99,7 +101,9 @@ public class TimeFunctionManager
periodType.add( IArgumentInfo.Period_Type.YEAR );
}
- if ( timeType.contains( DesignChoiceConstants.DATE_TIME_LEVEL_TYPE_QUARTER ) )
+ if ( timeType.contains( DesignChoiceConstants.DATE_TIME_LEVEL_TYPE_QUARTER )
+ || timeType.contains( DesignChoiceConstants.DATE_TIME_LEVEL_TYPE_WEEK_OF_YEAR )
+ || timeType.contains( DesignChoiceConstants.DATE_TIME_LEVEL_TYPE_DAY_OF_YEAR))
{
availableFunctions.add( handle.getFunction( IBuildInBaseTimeFunction.CURRENT_QUARTER ) );
availableFunctions.add( handle.getFunction( IBuildInBaseTimeFunction.PREVIOUS_QUARTER ) );
@@ -109,7 +113,9 @@ public class TimeFunctionManager
periodType.add( IArgumentInfo.Period_Type.QUARTER );
}
- if ( timeType.contains( DesignChoiceConstants.DATE_TIME_LEVEL_TYPE_MONTH ) )
+ if ( timeType.contains( DesignChoiceConstants.DATE_TIME_LEVEL_TYPE_MONTH )
+ || timeType.contains( DesignChoiceConstants.DATE_TIME_LEVEL_TYPE_WEEK_OF_YEAR )
+ || timeType.contains( DesignChoiceConstants.DATE_TIME_LEVEL_TYPE_DAY_OF_YEAR) )
{
availableFunctions.add( handle.getFunction( IBuildInBaseTimeFunction.CURRENT_MONTH ) );
availableFunctions.add( handle.getFunction( IBuildInBaseTimeFunction.PREVIOUS_MONTH ) );
@@ -129,10 +135,12 @@ public class TimeFunctionManager
periodType.add( IArgumentInfo.Period_Type.DAY );
}
// for WTD, only support static reference date
- if ( isStaticReferenceDate
- && timeType.contains( DesignChoiceConstants.DATE_TIME_LEVEL_TYPE_WEEK_OF_YEAR ) )
+ if ( timeLevelsInXtab.isEmpty()
+ && (timeType.contains( DesignChoiceConstants.DATE_TIME_LEVEL_TYPE_WEEK_OF_YEAR )
+ || timeType.contains( DesignChoiceConstants.DATE_TIME_LEVEL_TYPE_DAY_OF_YEAR )))
{
availableFunctions.add( handle.getFunction( IBuildInBaseTimeFunction.WEEK_TO_DATE ) );
+ availableFunctions.add( handle.getFunction( IBuildInBaseTimeFunction.PREVIOUS_WEEK_TO_DATE ) );
periodType.add( IArgumentInfo.Period_Type.WEEK );
}
@@ -148,6 +156,7 @@ public class TimeFunctionManager
return availableFunctions;
}
+
/**
* get a list of TimeFunction instances for the specified type under default
* local
@@ -187,6 +196,10 @@ public class TimeFunctionManager
{
return handle.getFunction( IBuildInBaseTimeFunction.PREVIOUS_MONTH );
}
+ else if ( IBuildInBaseTimeFunction.PREVIOUS_WEEK_TO_DATE.equals( name ) )
+ {
+ return handle.getFunction( IBuildInBaseTimeFunction.PREVIOUS_WEEK_TO_DATE );
+ }
else if ( IBuildInBaseTimeFunction.PREVIOUS_MONTH_TO_DATE.equals( name ) )
{
return handle.getFunction( IBuildInBaseTimeFunction.PREVIOUS_MONTH_TO_DATE );
@@ -346,7 +359,8 @@ public class TimeFunctionManager
DesignChoiceConstants.DATE_TIME_LEVEL_TYPE_DAY_OF_YEAR
};
}
- if ( IBuildInBaseTimeFunction.WEEK_TO_DATE.equals( calculationType ) )
+ if ( IBuildInBaseTimeFunction.WEEK_TO_DATE.equals( calculationType )
+ || IBuildInBaseTimeFunction.PREVIOUS_WEEK_TO_DATE.equals( calculationType ))
{
return new String[]{
DesignChoiceConstants.DATE_TIME_LEVEL_TYPE_WEEK_OF_YEAR
diff --git a/data/org.eclipse.birt.report.data.adapter/src/org/eclipse/birt/report/data/adapter/i18n/Messages.properties b/data/org.eclipse.birt.report.data.adapter/src/org/eclipse/birt/report/data/adapter/i18n/Messages.properties
index 5eb2b7f..0db7e9e 100644
--- a/data/org.eclipse.birt.report.data.adapter/src/org/eclipse/birt/report/data/adapter/i18n/Messages.properties
+++ b/data/org.eclipse.birt.report.data.adapter/src/org/eclipse/birt/report/data/adapter/i18n/Messages.properties
@@ -48,6 +48,8 @@ timeFunction.CURRENT_MONTH.name = Current Month
timeFunction.CURRENT_MONTH.description = Calculate the specified metric for current month
timeFunction.PREVIOUS_MONTH.name = Previous Month
timeFunction.PREVIOUS_MONTH.description = Calculate the specified metric for previous N month
+timeFunction.PREVIOUS_WEEK_TO_DATE.name = Previous Week to Date
+timeFunction.PREVIOUS_WEEK_TO_DATE.description = Calculate the specified metric for week to date of previous N month
timeFunction.PREVIOUS_MONTH_TO_DATE.name = Previous Month to Date
timeFunction.PREVIOUS_MONTH_TO_DATE.description = Calculate the specified metric for month to date of previous N month
timeFunction.PREVIOUS_QUARTER.name = Previous Quarter
diff --git a/data/org.eclipse.birt.report.data.adapter/src/org/eclipse/birt/report/data/adapter/i18n/ResourceConstants.java b/data/org.eclipse.birt.report.data.adapter/src/org/eclipse/birt/report/data/adapter/i18n/ResourceConstants.java
index 11f67c6..0b25320 100644
--- a/data/org.eclipse.birt.report.data.adapter/src/org/eclipse/birt/report/data/adapter/i18n/ResourceConstants.java
+++ b/data/org.eclipse.birt.report.data.adapter/src/org/eclipse/birt/report/data/adapter/i18n/ResourceConstants.java
@@ -50,6 +50,8 @@ public class ResourceConstants
public final static String TIMEFUNCITON_CURRENT_MONTH_DES = "timeFunction.CURRENT_MONTH.description";
public final static String TIMEFUNCITON_PREVIOUS_MONTH = "timeFunction.PREVIOUS_MONTH.name";
public final static String TIMEFUNCITON_PREVIOUS_MONTH_DES = "timeFunction.PREVIOUS_MONTH.description";
+ public final static String TIMEFUNCITON_PREVIOUS_WEEK_TO_DATE = "timeFunction.PREVIOUS_WEEK_TO_DATE.name";
+ public final static String TIMEFUNCITON_PREVIOUS_WEEK_TO_DATE_DES = "timeFunction.PREVIOUS_WEEK_TO_DATE.description";
public final static String TIMEFUNCITON_PREVIOUS_MONTH_TO_DATE = "timeFunction.PREVIOUS_MONTH_TO_DATE.name";
public final static String TIMEFUNCITON_PREVIOUS_MONTH_TO_DATE_DES = "timeFunction.PREVIOUS_MONTH_TO_DATE.description";
public final static String TIMEFUNCITON_PREVIOUS_QUARTER = "timeFunction.PREVIOUS_QUARTER.name";
diff --git a/data/org.eclipse.birt.report.data.adapter/src/org/eclipse/birt/report/data/adapter/impl/ModelAdapter.java b/data/org.eclipse.birt.report.data.adapter/src/org/eclipse/birt/report/data/adapter/impl/ModelAdapter.java
index bb71c3c..3c7dd59 100644
--- a/data/org.eclipse.birt.report.data.adapter/src/org/eclipse/birt/report/data/adapter/impl/ModelAdapter.java
+++ b/data/org.eclipse.birt.report.data.adapter/src/org/eclipse/birt/report/data/adapter/impl/ModelAdapter.java
@@ -539,6 +539,10 @@ public class ModelAdapter implements IModelAdapter
{
baseTimePeriod = new TimePeriod( 0, TimePeriodType.QUARTER );
}
+ else if ( IBuildInBaseTimeFunction.PREVIOUS_WEEK_TO_DATE.equals( calculateType ) )
+ {
+ baseTimePeriod = new TimePeriod( 0, TimePeriodType.WEEK );
+ }
else if ( IBuildInBaseTimeFunction.PREVIOUS_MONTH_TO_DATE.equals( calculateType ) )
{
baseTimePeriod = new TimePeriod( 0, TimePeriodType.MONTH );
@@ -640,6 +644,26 @@ public class ModelAdapter implements IModelAdapter
relativeTimePeriod = new TimePeriod( 0 - Integer.valueOf( n ),
TimePeriodType.YEAR );
}
+ else if ( IBuildInBaseTimeFunction.PREVIOUS_WEEK_TO_DATE.equals( calculateType ) )
+ {
+ Iterator iter = periodHandle.calculationArgumentsIterator( );
+ String n = null;
+ while ( iter.hasNext( ) )
+ {
+ CalculationArgumentHandle argument = (CalculationArgumentHandle) iter.next( );
+ if ( IArgumentInfo.N_PERIOD1.equals( argument.getName( ) ) )
+ {
+ n = argument.getValue( ).getStringExpression( );
+ break;
+ }
+ }
+ if ( n == null || n.trim( ).equals( "" ) )
+ {
+ n = "1";
+ }
+ relativeTimePeriod = new TimePeriod( 0 - Integer.valueOf( n ),
+ TimePeriodType.WEEK );
+ }
else if ( IBuildInBaseTimeFunction.PREVIOUS_MONTH_TO_DATE.equals( calculateType )
|| IBuildInBaseTimeFunction.PREVIOUS_MONTH.equals( calculateType ) )
{
diff --git a/data/org.eclipse.birt.report.data.adapter/test/org/eclipse/birt/report/data/adapter/internal/script/TimeFunctionManagerTest.java b/data/org.eclipse.birt.report.data.adapter/test/org/eclipse/birt/report/data/adapter/internal/script/TimeFunctionManagerTest.java
index 8786b91..9a8cb31 100644
--- a/data/org.eclipse.birt.report.data.adapter/test/org/eclipse/birt/report/data/adapter/internal/script/TimeFunctionManagerTest.java
+++ b/data/org.eclipse.birt.report.data.adapter/test/org/eclipse/birt/report/data/adapter/internal/script/TimeFunctionManagerTest.java
@@ -276,6 +276,10 @@ public class TimeFunctionManagerTest extends TestCase
timeTypes = TimeFunctionManager.getTimeType( computedHandle );
assertTrue( timeTypes[0].equals( DesignChoiceConstants.DATE_TIME_LEVEL_TYPE_QUARTER ) );
+ computedHandle.setCalculationType( IBuildInBaseTimeFunction.PREVIOUS_WEEK_TO_DATE );
+ timeTypes = TimeFunctionManager.getTimeType( computedHandle );
+ assertTrue( timeTypes[0].equals( DesignChoiceConstants.DATE_TIME_LEVEL_TYPE_WEEK_OF_YEAR ) );
+
computedHandle.setCalculationType( IBuildInBaseTimeFunction.PREVIOUS_MONTH_TO_DATE );
timeTypes = TimeFunctionManager.getTimeType( computedHandle );
assertTrue( timeTypes[0].equals( DesignChoiceConstants.DATE_TIME_LEVEL_TYPE_MONTH ) );