Access to add and change pages is restricted. See: https://cwiki.apache.org/confluence/display/OFBIZ/Wiki+access

You are viewing an old version of this page. View the current version.

Compare with Current View Page History

Version 1 Next »

This document contains the Code snippet taken from the Commit notification.
Most of tricks on Groovy are taken from the code committed by Scott Gray , Marco Risaliti and others.

1) Some important files that are responsible for Groovy handling in Ofbiz.
a) GroovyUtil.java
b) GroovyServiceTest.groovy
c)  GroovyEngine.java
d) Some *.jar files that are responsible to run the Groovy scripts are shown below.

   ofbiz/trunk/framework/base/lib/scripting/antlr-2.7.6.jar   (with props)

   ofbiz/trunk/framework/base/lib/scripting/asm-2.2.jar   (with props)
   ofbiz/trunk/framework/base/lib/scripting/asm-analysis-2.2.jar   (with props)
   ofbiz/trunk/framework/base/lib/scripting/asm-tree-2.2.jar   (with props)
   ofbiz/trunk/framework/base/lib/scripting/asm-util-2.2.jar   (with props)
   ofbiz/trunk/framework/base/lib/scripting/groovy-1.5.6.jar   (with props)

Important thing to note down in Groovy conversion is that we can use the whole bsh file as it is with groovy extension.
Following points are the features of Groovy scripting language.
The following sentence can be used instead of Beanshell one (Also including the contents of Beanshell statement to better understand the code).

2)
Beanshell :-
-productAssoc = delegator.findByPrimaryKey("ProductAssoc", UtilMisc.toMap("productId", productId, "productIdTo", productIdTo, "productAssocTypeId", productAssocTypeId, "fromDate", fromDate));

Groovy :-
+productAssoc = delegator.findByPrimaryKey("ProductAssoc", ['productId' : productId, 'productIdTo' : productIdTo, 'productAssocTypeId' : productAssocTypeId, 'fromDate' : fromDate]);

Note :- Removed the usage of UtilMis.toMap().

3)
Beanshell :-

Groovy :-

Note :-

4)
Beanshell :-

Groovy :-

Note :-

5)
Beanshell :-

Groovy :-

Note :-

6)


  • No labels