summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorpshi2011-12-07 03:13:58 (EST)
committer mwu2011-12-07 03:13:58 (EST)
commita8a192cb179e47a3e172c3da64bdd3b0b0b63ef5 (patch)
tree4cb45ba96ffa9013344e6658344e116cf828e443
parent04f0f2faff279aed75920af040cfbcacf75b50b9 (diff)
downloadorg.eclipse.birt-a8a192cb179e47a3e172c3da64bdd3b0b0b63ef5.zip
org.eclipse.birt-a8a192cb179e47a3e172c3da64bdd3b0b0b63ef5.tar.gz
org.eclipse.birt-a8a192cb179e47a3e172c3da64bdd3b0b0b63ef5.tar.bz2
fix 45771 Exception is thrown out when using parameter value as The
first N.
-rw-r--r--data/org.eclipse.birt.report.data.adapter/src/org/eclipse/birt/report/data/adapter/impl/ModelAdapter.java58
1 files changed, 31 insertions, 27 deletions
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 e233a44..aabbf71 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
@@ -629,9 +629,11 @@ public class ModelAdapter implements IModelAdapter
*
* @param periodHandle
* @return
+ * @throws BirtException
+ * @throws DataException
*/
private ITimePeriod populateRelativeTimePeriod(
- ComputedColumnHandle periodHandle )
+ ComputedColumnHandle periodHandle ) throws DataException, BirtException
{
String calculateType = periodHandle.getCalculationType( );
TimePeriod relativeTimePeriod = null;
@@ -651,11 +653,7 @@ public class ModelAdapter implements IModelAdapter
break;
}
}
- if ( n == null || n.trim( ).equals( "" ) )
- {
- n = "1";
- }
- relativeTimePeriod = new TimePeriod( 0 - Integer.valueOf( n ),
+ relativeTimePeriod = new TimePeriod( 0 - evaluatePeriodsN( n ),
TimePeriodType.YEAR );
}
else if ( IBuildInBaseTimeFunction.PREVIOUS_WEEK_TO_DATE.equals( calculateType ) )
@@ -671,11 +669,7 @@ public class ModelAdapter implements IModelAdapter
break;
}
}
- if ( n == null || n.trim( ).equals( "" ) )
- {
- n = "1";
- }
- relativeTimePeriod = new TimePeriod( 0 - Integer.valueOf( n ),
+ relativeTimePeriod = new TimePeriod( 0 - evaluatePeriodsN( n ),
TimePeriodType.WEEK );
}
else if ( IBuildInBaseTimeFunction.PREVIOUS_MONTH_TO_DATE.equals( calculateType )
@@ -692,11 +686,7 @@ public class ModelAdapter implements IModelAdapter
break;
}
}
- if ( n == null || n.trim( ).equals( "" ) )
- {
- n = "1";
- }
- relativeTimePeriod = new TimePeriod( 0 - Integer.valueOf( n ),
+ relativeTimePeriod = new TimePeriod( 0 - evaluatePeriodsN( n ),
TimePeriodType.MONTH );
}
else if ( IBuildInBaseTimeFunction.PREVIOUS_QUARTER_TO_DATE.equals( calculateType )
@@ -713,11 +703,7 @@ public class ModelAdapter implements IModelAdapter
break;
}
}
- if ( n == null || n.trim( ).equals( "" ) )
- {
- n = "1";
- }
- relativeTimePeriod = new TimePeriod( 0 - Integer.valueOf( n ),
+ relativeTimePeriod = new TimePeriod( 0 - evaluatePeriodsN( n ),
TimePeriodType.QUARTER );
}
else if ( IBuildInBaseTimeFunction.PREVIOUS_YEAR_TO_DATE.equals( calculateType )
@@ -734,11 +720,7 @@ public class ModelAdapter implements IModelAdapter
break;
}
}
- if ( n == null || n.trim( ).equals( "" ) )
- {
- n = "1";
- }
- relativeTimePeriod = new TimePeriod( 0 - Integer.valueOf( n ),
+ relativeTimePeriod = new TimePeriod( 0 - evaluatePeriodsN( n ),
TimePeriodType.YEAR );
}
else if ( IBuildInBaseTimeFunction.CURRENT_PERIOD_FROM_N_PERIOD_AGO.equals( calculateType )
@@ -759,12 +741,34 @@ public class ModelAdapter implements IModelAdapter
n = argument.getValue( ).getStringExpression( );
}
}
- relativeTimePeriod = new TimePeriod( 0 - Integer.valueOf( n ),
+ relativeTimePeriod = new TimePeriod( 0 - evaluatePeriodsN( n ),
DataAdapterUtil.toTimePeriodType( period2 ) );
}
return relativeTimePeriod;
}
+ private int evaluatePeriodsN( 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