summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorpshi2012-01-16 22:31:45 (EST)
committer mwu2012-01-16 22:31:45 (EST)
commitfb4e9c97650268eb6bf57cc34d9eb22265c2f2b2 (patch)
treefdda13c96be94f92f85921c3dbe1f69a74b1df2d
parent5af04230115b7d13c05716d0eaf516890dabaa2c (diff)
downloadorg.eclipse.birt-fb4e9c97650268eb6bf57cc34d9eb22265c2f2b2.zip
org.eclipse.birt-fb4e9c97650268eb6bf57cc34d9eb22265c2f2b2.tar.gz
org.eclipse.birt-fb4e9c97650268eb6bf57cc34d9eb22265c2f2b2.tar.bz2
fix 46608, support trailing n days and trailing n months
-rw-r--r--data/org.eclipse.birt.report.data.adapter/src/org/eclipse/birt/report/data/adapter/api/timeFunction/BaseTimeFunction.java14
-rw-r--r--data/org.eclipse.birt.report.data.adapter/src/org/eclipse/birt/report/data/adapter/api/timeFunction/IBuildInBaseTimeFunction.java16
-rw-r--r--data/org.eclipse.birt.report.data.adapter/src/org/eclipse/birt/report/data/adapter/api/timeFunction/TimeFunctionHandle.java12
-rw-r--r--data/org.eclipse.birt.report.data.adapter/src/org/eclipse/birt/report/data/adapter/api/timeFunction/TimeFunctionManager.java19
-rw-r--r--data/org.eclipse.birt.report.data.adapter/src/org/eclipse/birt/report/data/adapter/i18n/Messages.properties20
-rw-r--r--data/org.eclipse.birt.report.data.adapter/src/org/eclipse/birt/report/data/adapter/i18n/ResourceConstants.java6
-rw-r--r--data/org.eclipse.birt.report.data.adapter/src/org/eclipse/birt/report/data/adapter/impl/ModelAdapter.java59
7 files changed, 125 insertions, 21 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 fd5d902..99b6ce8 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
@@ -210,6 +210,20 @@ public class BaseTimeFunction implements ITimeFunction
( (ArgumentInfo) period2 ).setPeriodChoices( period_type2 );
arguments.add( period2);
}
+ else if( this.name.equals( IBuildInBaseTimeFunction.TRAILING_N_MONTHS ))
+ {
+ arguments.add( new ArgumentInfo( IArgumentInfo.N_PERIOD1,
+ Message.getMessage( ResourceConstants.TIMEFUNCITON_N1_MONTH_DISPLAYNAME ),
+ Message.getMessage( ResourceConstants.TIMEFUNCITON_N1_MONTH ),
+ true ) );
+ }
+ else if( this.name.equals( IBuildInBaseTimeFunction.TRAILING_N_DAYS ))
+ {
+ arguments.add( new ArgumentInfo( IArgumentInfo.N_PERIOD1,
+ Message.getMessage( ResourceConstants.TIMEFUNCITON_N1_DAY_DISPLAYNAME ),
+ Message.getMessage( ResourceConstants.TIMEFUNCITON_N1_DAY ),
+ true ) );
+ }
else if ( this.name.equals( IBuildInBaseTimeFunction.TRAILING_N_PERIOD_FROM_N_PERIOD_AGO ) )
{
( (ArgumentInfo) period1 ).setPeriodChoices( period_type1 );
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 5662ab8..45bcdb1 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
@@ -26,18 +26,20 @@ public interface IBuildInBaseTimeFunction
public static final String CURRENT_YEAR = "CURRENT YEAR";
public static final String WEEK_TO_DATE = "WEEK TO DATE";
- public static final String PREVIOUS_MONTH = "PREVIOUS MONTH";
- public static final String PREVIOUS_QUARTER = "PREVIOUS QUARTER";
- public static final String PREVIOUS_YEAR = "PREVIOUS YEAR";
+ public static final String PREVIOUS_MONTH = "PREVIOUS N MONTH";
+ public static final String PREVIOUS_QUARTER = "PREVIOUS N QUARTER";
+ public static final String PREVIOUS_YEAR = "PREVIOUS N YEAR";
public static final String WEEK_TO_DATE_LAST_YEAR = "WEEK TO DATE LAST 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";
+ public static final String PREVIOUS_WEEK_TO_DATE = "PREVIOUS N WEEK TO DATE";
+ public static final String PREVIOUS_MONTH_TO_DATE = "PREVIOUS N MONTH TO DATE";
+ public static final String PREVIOUS_QUARTER_TO_DATE = "PREVIOUS N QUARTER TO DATE";
+ public static final String PREVIOUS_YEAR_TO_DATE = "PREVIOUS N YEAR TO DATE";
public static final String CURRENT_PERIOD_FROM_N_PERIOD_AGO = "CURRENT PERIOD FROM N PERIODS AGO";
public static final String PERIOD_TO_DATE_FROM_N_PERIOD_AGO = "PERIOD TO DATE FROM N PERIODS AGO";
+ public static final String TRAILING_N_MONTHS = "TRAILING N MONTHS";
+ public static final String TRAILING_N_DAYS = "TRAILING N DAYS";
public static final String TRAILING_N_PERIOD_FROM_N_PERIOD_AGO = "TRAILING N PERIODS FROM N PERIODS AGO";
public static final String NEXT_N_PERIODS = "NEXT_N_PERIODS";
}
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 be87188..5783c46 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
@@ -204,6 +204,18 @@ public class TimeFunctionHandle
local ),
Message.getMessage( ResourceConstants.TIMEFUNCITON_PERIOD_TO_DATE_FROM_N_PERIOD_AGO_DES,
local ) ) );
+ baseTimeFunctionMap.put( IBuildInBaseTimeFunction.TRAILING_N_MONTHS,
+ new BaseTimeFunction( IBuildInBaseTimeFunction.TRAILING_N_MONTHS,
+ Message.getMessage( ResourceConstants.TIMEFUNCITON_TRAILING_N_MONTHS,
+ local ),
+ Message.getMessage( ResourceConstants.TIMEFUNCITON_TRAILING_N_MONTHS,
+ local ) ) );
+ baseTimeFunctionMap.put( IBuildInBaseTimeFunction.TRAILING_N_DAYS,
+ new BaseTimeFunction( IBuildInBaseTimeFunction.TRAILING_N_DAYS,
+ Message.getMessage( ResourceConstants.TIMEFUNCITON_TRAILING_N_DAYS,
+ local ),
+ Message.getMessage( ResourceConstants.TIMEFUNCITON_TRAILING_N_DAYS,
+ local ) ) );
baseTimeFunctionMap.put( IBuildInBaseTimeFunction.TRAILING_N_PERIOD_FROM_N_PERIOD_AGO,
new BaseTimeFunction( IBuildInBaseTimeFunction.TRAILING_N_PERIOD_FROM_N_PERIOD_AGO,
Message.getMessage( ResourceConstants.TIMEFUNCITON_TRAILING_N_PERIOD_FROM_N_PERIOD_AGO,
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 e76efc2..429427e 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
@@ -154,7 +154,8 @@ public class TimeFunctionManager
availableFunctions.add( handle.getFunction( IBuildInBaseTimeFunction.MONTH_TO_DATE ) );
// availableFunctions.add( handle.getFunction( IBuildInBaseTimeFunction.TRAILING_12_MONTHS ) );
availableFunctions.add( handle.getFunction( IBuildInBaseTimeFunction.MONTH_TO_DATE_LAST_YEAR ) );
-
+ availableFunctions.add( handle.getFunction( IBuildInBaseTimeFunction.TRAILING_N_MONTHS ) );
+
periodType.add( new Period_Type( IArgumentInfo.Period_Type.Period_Type_ENUM.MONTH, locale ) );
periodToDateType.add( new Period_Type( IArgumentInfo.Period_Type.Period_Type_ENUM.MONTH, locale, true ) );
}
@@ -176,7 +177,9 @@ public class TimeFunctionManager
// availableFunctions.add( handle.getFunction( IBuildInBaseTimeFunction.TRAILING_60_DAYS ) );
// availableFunctions.add( handle.getFunction( IBuildInBaseTimeFunction.TRAILING_90_DAYS ) );
// availableFunctions.add( handle.getFunction( IBuildInBaseTimeFunction.TRAILING_120_DAYS ) );
+ availableFunctions.add( handle.getFunction( IBuildInBaseTimeFunction.TRAILING_N_DAYS ) );
periodType.add( new Period_Type( IArgumentInfo.Period_Type.Period_Type_ENUM.DAY, locale ) );
+
}
availableFunctions.add( new BaseTimeFunction( handle.getFunction( IBuildInBaseTimeFunction.CURRENT_PERIOD_FROM_N_PERIOD_AGO ),
@@ -323,6 +326,14 @@ public class TimeFunctionManager
{
return handle.getFunction( IBuildInBaseTimeFunction.PERIOD_TO_DATE_FROM_N_PERIOD_AGO );
}
+ else if ( IBuildInBaseTimeFunction.TRAILING_N_MONTHS.equals( name ) )
+ {
+ return handle.getFunction( IBuildInBaseTimeFunction.TRAILING_N_MONTHS );
+ }
+ else if ( IBuildInBaseTimeFunction.TRAILING_N_DAYS.equals( name ) )
+ {
+ return handle.getFunction( IBuildInBaseTimeFunction.TRAILING_N_DAYS );
+ }
else if ( IBuildInBaseTimeFunction.TRAILING_N_PERIOD_FROM_N_PERIOD_AGO.equals( name ) )
{
return handle.getFunction( IBuildInBaseTimeFunction.TRAILING_N_PERIOD_FROM_N_PERIOD_AGO );
@@ -383,7 +394,8 @@ public class TimeFunctionManager
|| IBuildInBaseTimeFunction.PREVIOUS_MONTH_TO_DATE.equals( calculationType )
|| IBuildInBaseTimeFunction.MONTH_TO_DATE.equals( calculationType )
|| IBuildInBaseTimeFunction.TRAILING_12_MONTHS.equals( calculationType )
- || IBuildInBaseTimeFunction.MONTH_TO_DATE_LAST_YEAR.equals( calculationType ) )
+ || IBuildInBaseTimeFunction.MONTH_TO_DATE_LAST_YEAR.equals( calculationType )
+ || IBuildInBaseTimeFunction.TRAILING_N_MONTHS.equals( calculationType ) )
{
return new String[]{
DesignChoiceConstants.DATE_TIME_LEVEL_TYPE_MONTH
@@ -392,7 +404,8 @@ public class TimeFunctionManager
if ( IBuildInBaseTimeFunction.TRAILING_30_DAYS.equals( calculationType )
|| IBuildInBaseTimeFunction.TRAILING_60_DAYS.equals( calculationType )
|| IBuildInBaseTimeFunction.TRAILING_90_DAYS.equals( calculationType )
- || IBuildInBaseTimeFunction.TRAILING_120_DAYS.equals( calculationType ) )
+ || IBuildInBaseTimeFunction.TRAILING_120_DAYS.equals( calculationType )
+ || IBuildInBaseTimeFunction.TRAILING_N_DAYS.equals( calculationType ) )
{
return new String[]{
DesignChoiceConstants.DATE_TIME_LEVEL_TYPE_DAY_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 86b64ab..b50cf59 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
@@ -46,17 +46,17 @@ timeFunction.CURRENT_QUARTER.name = Current Quarter
timeFunction.CURRENT_QUARTER.description = Calculate the specified metric for current quarter
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.name = Previous N 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.name = Previous N Week to Date
timeFunction.PREVIOUS_WEEK_TO_DATE.description = Calculate the specified metric for week to date of previous N week
-timeFunction.PREVIOUS_MONTH_TO_DATE.name = Previous Month to Date
+timeFunction.PREVIOUS_MONTH_TO_DATE.name = Previous N 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
+timeFunction.PREVIOUS_QUARTER.name = Previous N Quarter
timeFunction.PREVIOUS_QUARTER.description = Calculate the specified metric for previous N quarter
-timeFunction.PREVIOUS_QUARTER_TO_DATE.name = Previous Quarter to Date
+timeFunction.PREVIOUS_QUARTER_TO_DATE.name = Previous N Quarter to Date
timeFunction.PREVIOUS_QUARTER_TO_DATE.description = Calculate the specified metric for same quarter from previous N quarter
-timeFunction.PREVIOUS_PREVIOUS_YEAR.name = Previous Year
+timeFunction.PREVIOUS_PREVIOUS_YEAR.name = Previous N Year
timeFunction.PREVIOUS_PREVIOUS_YEAR.description = Calculate the specified metric for previous N year
timeFunction.TRAILING_30_DAYS.name = Trailing 30 Days
timeFunction.TRAILING_30_DAYS.description = Calculate the specified metric for last 30 days
@@ -74,7 +74,7 @@ timeFunction.QUARTER_TO_DATE.name = Quarter to Date(QTD)
timeFunction.QUARTER_TO_DATE.description = Calculate the specified metric for same quarter
timeFunction.MONTH_TO_DATE.name = Month to Date(MTD)
timeFunction.MONTH_TO_DATE.description = Calculate the specified metric for same month
-timeFunction.PREVIOUS_YEAR_TO_DATE.name = Previous Year to Date
+timeFunction.PREVIOUS_YEAR_TO_DATE.name = Previous N Year to Date
timeFunction.PREVIOUS_YEAR_TO_DATE.description = Calculate the specified metric for same year in previous N year
timeFunction.WEEK_TO_DATE_LAST_YEAR.name = Week to Date Last Year
timeFunction.WEEK_TO_DATE_LAST_YEAR.description = Calculate the specified metric for same week in previous N year
@@ -92,6 +92,10 @@ timeFunction.PERIOD_TO_DATE_FROM_N_PERIOD_AGO.name = Period to Date
timeFunction.PERIOD_TO_DATE_FROM_N_PERIOD_AGO.description = Calculate the specified metric for same period from N period ago
timeFunction.TRAILING_N_PERIOD_FROM_N_PERIOD_AGO.name = Trailing N Periods
timeFunction.TRAILING_N_PERIOD_FROM_N_PERIOD_AGO.description = Calculate the specified metric for trailing N period from N period ago
+timeFunction.TRAILING_N_MONTHS.name = Trailing N Months
+timeFunction.TRAILING_N_MONTHS.description = Calculate the specified metric for last N months
+timeFunction.TRAILING_N_DAYS.name = Trailing N Days
+timeFunction.TRAILING_N_DAYS.description = Calculate the specified metric for last N days
timeFunction.NEXT_N_PERIODS.name = Next N Periods
timeFunction.NEXT_N_PERIODS.description = Calculate the specified metric for next N periods
@@ -125,6 +129,8 @@ timeFunction.N2.Week.displayName = Number of Week(s) Ago
timeFunction.N1.Week = N value for number of Week(s) ago
timeFunction.N2.Week = N value for number of Week(s) ago
+timeFunction.N1.Day.displayName = Number of Day(s) Ago
+
timeFunction.PERIODCHOICE.YEAR_displayName =YEAR
timeFunction.PERIODCHOICE.QUARTER_displayName =QUARTER
timeFunction.PERIODCHOICE.MONTH_displayName =MONTH
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 6251db4..91c9afb 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
@@ -94,6 +94,10 @@ public class ResourceConstants
public final static String TIMEFUNCITON_PERIOD_TO_DATE_FROM_N_PERIOD_AGO_DES = "timeFunction.PERIOD_TO_DATE_FROM_N_PERIOD_AGO.description";
public final static String TIMEFUNCITON_TRAILING_N_PERIOD_FROM_N_PERIOD_AGO = "timeFunction.TRAILING_N_PERIOD_FROM_N_PERIOD_AGO.name";
public final static String TIMEFUNCITON_TRAILING_N_PERIOD_FROM_N_PERIOD_AGO_DES ="timeFunction.TRAILING_N_PERIOD_FROM_N_PERIOD_AGO.description";
+ public final static String TIMEFUNCITON_TRAILING_N_MONTHS = "timeFunction.TRAILING_N_MONTHS.name";
+ public final static String TIMEFUNCITON_TRAILING_N_MONTHS_DES ="timeFunction.TRAILING_N_MONTHS.description";
+ public final static String TIMEFUNCITON_TRAILING_N_DAYS = "timeFunction.TRAILING_N_DAYS.name";
+ public final static String TIMEFUNCITON_TRAILING_N_DAYS_DES ="timeFunction.TRAILING_N_DAYS.description";
public final static String TIMEFUNCITON_NEXT_N_PERIODS = "timeFunction.NEXT_N_PERIODS.name";
public final static String TIMEFUNCITON_NEXT_N_PERIODS_DES = "timeFunction.NEXT_N_PERIODS.description";
@@ -111,6 +115,7 @@ public class ResourceConstants
public final static String TIMEFUNCITON_N2_MONTH = "timeFunction.N2.Month";
public final static String TIMEFUNCITON_N1_WEEK = "timeFunction.N1.Week";
public final static String TIMEFUNCITON_N2_WEEK = "timeFunction.N2.Week";
+ public final static String TIMEFUNCITON_N1_DAY = "timeFunction.N1.Day";
public final static String TIMEFUNCITON_PERIOD1_DISPLAYNAME = "timeFunction.PERIOD1.displayName";
public final static String TIMEFUNCITON_PERIOD2_DISPLAYNAME = "timeFunction.PERIOD2.displayName";
@@ -125,6 +130,7 @@ public class ResourceConstants
public final static String TIMEFUNCITON_N2_MONTH_DISPLAYNAME = "timeFunction.N2.Month.displayName";
public final static String TIMEFUNCITON_N1_WEEK_DISPLAYNAME = "timeFunction.N1.Week.displayName";
public final static String TIMEFUNCITON_N2_WEEK_DISPLAYNAME = "timeFunction.N2.Week.displayName";
+ public final static String TIMEFUNCITON_N1_DAY_DISPLAYNAME = "timeFunction.N1.Day.displayName";
public final static String TIMEFUNCITON_PERIODCHOICE_YEAR_DISPLAYNAME = "timeFunction.PERIODCHOICE.YEAR_displayName";
public final static String TIMEFUNCITON_PERIODCHOICE_QUARTER_DISPLAYNAME = "timeFunction.PERIODCHOICE.QUARTER_displayName";
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 d41748a..aa8d6eb 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
@@ -475,7 +475,7 @@ public class ModelAdapter implements IModelAdapter
}
private ITimePeriod populateBaseTimePeriod(
- ComputedColumnHandle periodHandle )
+ ComputedColumnHandle periodHandle ) throws DataException, BirtException
{
String calculateType = periodHandle.getCalculationType( );
TimePeriod baseTimePeriod = null;
@@ -593,6 +593,36 @@ public class ModelAdapter implements IModelAdapter
DataAdapterUtil.toTimePeriodType( period1 ) );
}
}
+ else if ( IBuildInBaseTimeFunction.TRAILING_N_MONTHS.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( );
+ }
+ }
+ baseTimePeriod = new TimePeriod( 0 - evaluatePeriodsNForTrailingFunction( n ),
+ TimePeriodType.MONTH );
+ }
+ else if ( IBuildInBaseTimeFunction.TRAILING_N_DAYS.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( );
+ }
+ }
+ baseTimePeriod = new TimePeriod( 0 - evaluatePeriodsNForTrailingFunction( n ),
+ TimePeriodType.DAY );
+ }
else if ( IBuildInBaseTimeFunction.TRAILING_N_PERIOD_FROM_N_PERIOD_AGO.equals( calculateType ) )
{
Iterator iter = periodHandle.calculationArgumentsIterator( );
@@ -609,7 +639,7 @@ public class ModelAdapter implements IModelAdapter
n = argument.getValue( ).getStringExpression( );
}
}
- baseTimePeriod = new TimePeriod( 0 - Integer.valueOf( n ),
+ baseTimePeriod = new TimePeriod( 0 - evaluatePeriodsNForTrailingFunction( n ),
DataAdapterUtil.toTimePeriodType( period1 ) );
}
else if ( IBuildInBaseTimeFunction.NEXT_N_PERIODS.equals( calculateType ) )
@@ -628,7 +658,7 @@ public class ModelAdapter implements IModelAdapter
n = argument.getValue( ).getStringExpression( );
}
}
- baseTimePeriod = new TimePeriod( Integer.valueOf( n ),
+ baseTimePeriod = new TimePeriod( evaluatePeriodsNForTrailingFunction( n ),
DataAdapterUtil.toTimePeriodType( period1 ) );
}
return baseTimePeriod;
@@ -762,7 +792,7 @@ public class ModelAdapter implements IModelAdapter
int num = 0;
if ( n == null || n.trim( ).equals( "" ) )
{
- n = "1";
+ n = "0";
}
try
{
@@ -778,6 +808,27 @@ public class ModelAdapter implements IModelAdapter
return num;
}
+ private int evaluatePeriodsNForTrailingFunction( String n )
+ throws DataException, BirtException
+ {
+ int num = 0;
+ if ( n == null || n.trim( ).equals( "" ) )
+ {
+ n = "1";
+ }
+ try
+ {
+ num = Integer.valueOf( n );
+ }
+ catch ( Exception e )
+ {
+ num = (Integer) ScriptEvalUtil.evalExpr( new ScriptExpression( n ),
+ this.context.getDataEngineContext( ).getScriptContext( ),
+ "",
+ 0 );
+ }
+ return num;
+ }
/**
*
* @param handle