Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.

Bug 191445

Summary: [Scripting usability] Expressions in report design should use a new syntax to differentiate them from static strings
Product: z_Archived Reporter: David Michonneau <dmichonneau>
Component: BIRTAssignee: Xiaoxiao Wu <xwu>
Status: VERIFIED FIXED QA Contact: Maggie Shen <lshen>
Severity: normal    
Priority: P3 CC: bluesoldier, jasonweathersby, jouyang, lzhu, qwang, rkanguri, rlu, scottr, wenfeng.fwd, whe, wyan, xxue, yli, zqian
Version: 2.2.0Keywords: plan
Target Milestone: 2.5.0 RC3   
Hardware: PC   
OS: Windows XP   
Whiteboard: Autoed,G
Bug Depends on: 260309, 269923, 275273    
Bug Blocks: 264273    

Description David Michonneau CLA 2007-06-07 06:17:08 EDT
It has now become a usability issue for report designers to input expressions or strings in the various input boxes of the UI. Typically if the user needs to input a string, he will not quote it, and it will result as an error at runtime if the engine was expecting an expression there.

It is also a performance issue to parse and evaluate string constants with the JS engine, when it is not needed.

To remedy to those problems, we need a new syntax for expression using a = sign as a prefix, so it can be clearly identified as an expression and not a simple string.

Required changes are as follows:

UI :
Expression builder needs to prepend = to the expression written by the user upon exit  (unless it was already there in the expression, but we  shouldn't assume it nor require it)

Engine:
Engine will parse expressions differently: if it starts with = it will evaluate the reminder of the expression as before. If it doesn't start with =, it will assume a string constant without quotes (or number constant if it is expecting a numeric value). It shouldn't run any JS evaluation or parsing in that case, in order to improve performance.

Model:
To ensure backward compatibility, model should replace old expressions in old designs with the new syntax using = as prefix. Expressions as quoted strings should be replaced with the same string without quotes
Comment 1 Wenfeng Li CLA 2007-06-07 14:16:22 EDT
+1 for this enhancement
Comment 2 Gary Xue CLA 2007-06-11 14:37:01 EDT
See related discussions at Bug 190422.
The current proposal is that we should have a script-type property associated with expressions. It will start with Constant and Javascript types. It will also be desirable for us to introduce extension points to support external script types and calculation engines.
Comment 3 Wenfeng Li CLA 2008-12-29 15:20:11 EST
Suggest to support constant, JavaScript, and structure expressions in 2.5.0.  Structure expression would be evaulated by BIRT's data engine, it might be less flexible but could have much higher performance for simple expression such as +, -, *, /, for calculated field or sum for aggregation, etc..
Comment 4 Rick Lu CLA 2009-01-04 02:46:31 EST
(In reply to comment #3)
> Suggest to support constant, JavaScript, and structure expressions in 2.5.0. 
> Structure expression would be evaulated by BIRT's data engine, it might be less
> flexible but could have much higher performance for simple expression such as
> +, -, *, /, for calculated field or sum for aggregation, etc..
> 

For the old design file, the design file parser cannot distinguish JavaScript and structure expression. So, the parser with the backward compatibility cannot set the correct type. Or, we should set all expressions to JavaScript type?
Comment 5 Wenfeng Li CLA 2009-01-04 22:29:45 EST
(In reply to comment #4)
> (In reply to comment #3)
> > Suggest to support constant, JavaScript, and structure expressions in 2.5.0. 
> > Structure expression would be evaulated by BIRT's data engine, it might be less
> > flexible but could have much higher performance for simple expression such as
> > +, -, *, /, for calculated field or sum for aggregation, etc..
> > 
> For the old design file, the design file parser cannot distinguish JavaScript
> and structure expression. So, the parser with the backward compatibility cannot
> set the correct type. Or, we should set all expressions to JavaScript type?

Can we use the design version to maintain backward comp?  that is, all design files that are in older version, the expressions are JS.   For newer version, can we use either 
1) an attribute to indicate the exp type for the property value.
or
2) prefix for the property value to indicate the exp type, for example, 
   no '=' prefix or =constant:<value>  as a constant value
   =js:<expression>  as a JavaScript expression
   =<expression> or =birt:<expression> as a birt structure expression

Approach (1) is clean but could be too verbose in the XML design file.  (2) could be a pratical solution if the parser performance is not significantly degraded due to prefix processing for each property value.

   

Comment 6 Wei Yan CLA 2009-01-04 22:47:00 EST
prefer for the 1st solution as the 2nd solution means:

1. The expression is not a valid javascript expression. The user must learn an extended syntax for BIRT. 

2. it is hard for user to maintain the program as backward comptatability. Although the API  setProperty(String expr),   String getProperty() are not changed, the parameter value and return value is changed.   
Comment 7 Wenfeng Li CLA 2009-01-05 00:45:21 EST
(In reply to comment #6)
> prefer for the 1st solution as the 2nd solution means:
> 1. The expression is not a valid javascript expression. The user must learn an
> extended syntax for BIRT. 
> 2. it is hard for user to maintain the program as backward comptatability.
> Although the API  setProperty(String expr),   String getProperty() are not
> changed, the parameter value and return value is changed.   

With solution (2), at API level, I think getValue should return the constant or expression without the prefix, and has a separate call to return the value type.  The choices between (1) and (2) would be inside ROM how it persists the values.   
Comment 8 Rick Lu CLA 2009-01-05 01:16:25 EST
(In reply to comment #7)
> (In reply to comment #6)
> 
> With solution (2), at API level, I think getValue should return the constant or
> expression without the prefix, and has a separate call to return the value
> type.  The choices between (1) and (2) would be inside ROM how it persists the
> values.   
> 

From Model view, both solutions are OK to implement. They will not have much performance degradation here. The solution 1 adds another property to parser and solution 2 need to parse the string in the memory. 

We needs to provide getExpressionType/setExpressionType methods. However, if the user creates the design on Model APIs without calling new methods, the preview result may be error. So, in default, the expression type is javascript. This case applies to the old API user or the user changes the XML manually.
Comment 9 Wenfeng Li CLA 2009-01-05 02:36:48 EST
(In reply to comment #8)
> (In reply to comment #7)
> > (In reply to comment #6)
> > 
> > With solution (2), at API level, I think getValue should return the constant or
> > expression without the prefix, and has a separate call to return the value
> > type.  The choices between (1) and (2) would be inside ROM how it persists the
> > values.   
> > 
> From Model view, both solutions are OK to implement. They will not have much
> performance degradation here. The solution 1 adds another property to parser
> and solution 2 need to parse the string in the memory. 
> We needs to provide getExpressionType/setExpressionType methods. However, if
> the user creates the design on Model APIs without calling new methods, the
> preview result may be error. So, in default, the expression type is javascript.
> This case applies to the old API user or the user changes the XML manually.

Is it correct that some of the properties only take constant values currently?  

In that case, the default of a property type could either be constant or javascript expression depends on the ROM metadata? 

Do we want to make it consitent in 2.5.0 that all defaults are constants?  or we want to maintain backward compatibility to have the detaulf to follow current ROM metadata?

Please check how much larger and verbose it becomes if all property values have to include a type.  Maybe we only need to specify a type if the value is not a constant?


Comment 10 Rick Lu CLA 2009-01-05 03:07:58 EST
The conversion from the old design to the new one:

1. ROM expression ==> ROM expression, with the type is JavaScript
2. ROM string ==> ROM expression, with the type is Constant

Currently, ROM only has case 1. So, in default, the expression type is JavaScript for case 1. The "abc" is treated as JavaScript.

The case 2 is for some enhancements like ScalarParameter.defaultValue ( it is string type now). 

Only expressions need the type, right? This change won't affect integer, string type ,etc.
Comment 11 Wenfeng Li CLA 2009-01-05 04:41:22 EST
(In reply to comment #10)
> The conversion from the old design to the new one:
> 1. ROM expression ==> ROM expression, with the type is JavaScript
> 2. ROM string ==> ROM expression, with the type is Constant
> Currently, ROM only has case 1. So, in default, the expression type is
> JavaScript for case 1. The "abc" is treated as JavaScript.
> The case 2 is for some enhancements like ScalarParameter.defaultValue ( it is
> string type now). 
> Only expressions need the type, right? This change won't affect integer, string
> type ,etc.

Does it make sense to allow all properties of ROM can be evaluated from an expression?  I think a ROM property value shall have two types: one is the value type which can be integer, string, date, datetime, etc.  another tpye is expression type, which can be constant, js expression, birt expression, etc..  The value type is the data type of the value, while the expression type is about how the value is/should be calculated.

I think it is not clean to have "expression" and "integer", "string" in the same type system domain.  They are of different aspect of a property value.  By separating them into different attributes of the property value, we can allow type checking of an expression's returning value type and the defined property value type.

The question is shall we make the default expression type of all properties to be constant to make the new API easier to use? or some defaults being constant and some other defaults being js expression for backward compatibility of the API?   





Comment 12 Jun Ouyang CLA 2009-01-15 00:32:08 EST
Need model support this feature first.
Comment 13 Rick Lu CLA 2009-01-21 00:40:10 EST
Need more time to do this change.
Comment 14 Scott Rosenbaum CLA 2009-02-26 12:30:14 EST
I am having a bit of difficulty understanding the scope of this API change.  In the PDF it references that only getAllTocs, and getAllBookmarks as changing.  My sense is that the changes will be more far reaching than that.

The way that I read this is that anywhere someone is doing a 

String expr = (String)romObj.getPropert("ExprProp");

is going to have to change.

Is this correct?

Can you provide a bit more detail as to the scope of the change and how this will impact developers that have written DEAPI code?

Comment 15 Rick Lu CLA 2009-02-26 21:54:31 EST
(In reply to comment #14)
> I am having a bit of difficulty understanding the scope of this API change.  In
> the PDF it references that only getAllTocs, and getAllBookmarks as changing. 
> My sense is that the changes will be more far reaching than that.
> 
> The way that I read this is that anywhere someone is doing a 
> 
> String expr = (String)romObj.getPropert("ExprProp");
> 
> is going to have to change.
> 
> Is this correct?
> 
> Can you provide a bit more detail as to the scope of the change and how this
> will impact developers that have written DEAPI code?
> 

Yes, String expr = (String)romObj.getPropert("ExprProp") must be changed. Otherwise, it will have ClassCastException. The suggestion is to use  String expr = romObj.getStringPropert("ExprProp"). 

This has been talked about on page 3 of the PDF. Maybe I should highlight this one...
Comment 16 Scott Rosenbaum CLA 2009-02-26 22:03:41 EST
I don't think we can make this change.  We have too many people that will be upset if they have to change all of their code.  

Would it not be better to add a function:

  romObj.getExpressionProperty("exprProperty");

If you want to use the 'new' function you use that, but it allows the legacy code to continue to work.

sr
Comment 17 Rick Lu CLA 2009-03-01 22:02:15 EST
(In reply to comment #16)
> I don't think we can make this change.  We have too many people that will be
> upset if they have to change all of their code.  
> 
> Would it not be better to add a function:
> 
>   romObj.getExpressionProperty("exprProperty");
> 
> If you want to use the 'new' function you use that, but it allows the legacy
> code to continue to work.
> 
> sr
> 

OK. We won't break the return value. element.getExpressionProperty/setExpressionProperty should be used instead.
Comment 18 Rick Lu CLA 2009-03-04 01:08:31 EST
ROM part has been finished. Each expression has the value and the type. Reassign to UI team.
Comment 19 Chen Chao CLA 2009-04-23 05:50:58 EDT
Fixed the designer part, now reassign it to dte part.

DTE should replace the old exprssion button with the new expression button in the dataset editor and  dataset parameter dialog.
Comment 20 Lin Zhu CLA 2009-04-23 05:54:21 EDT
As it is closed to M7, we will fix problem in RC1.
Comment 21 Xiaoxiao Wu CLA 2009-05-12 06:51:04 EDT
1. In the Property Binding page within the Data Set Editor, each property is binding to an ExpressionButton which has both "Constant" input and "criptExpression" building functions. The former expression builder buttons are discarded here.
2. In the data set parameter's New/Edit dialog within the Data Set Editor, the expression builder button working for the default value's input is replaced with an ExpressionButton.

DtE part has been fixed.
Comment 22 Lin Zhu CLA 2009-05-14 10:37:46 EDT
Same should be done in property binding page of data source editor. Reopen the bug.
Comment 23 Lin Zhu CLA 2009-05-20 21:15:42 EDT
Suggest to fix the problem in RC3.
Comment 24 Xiaoxiao Wu CLA 2009-06-01 08:13:05 EDT
For the data source property binding page, all the expression builder buttons are replaced with new-style constant/expression button.

And to make the expression and the constant value work correctly, the adapter logic from model to DtE has also been modified.

So mark this bug as FIXED.
Comment 25 Maggie Shen CLA 2009-06-02 05:27:15 EDT
verified on build 2.5.0 v20090602-0630 and BRDpro090529.

constant is supported for the followings:
Image Builder,Flash builder,HTML button builder(no fixed),data set editor,data source editor -property binding,report parameter - default value,data set parameter - default value, hyperlink builder - URI location.