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

« Previous Version 2 Next »

This is a small guide for everybody involved in converting the Mini Language into Groovy.

Content

Groovy DSL

Services

 

 

 

Groovy DSL (dynamic scripting library)

 

 

How to get Groovy support in your IDE

The following paragraph is for Eclipse users.

It is possible to get Groovy support in Eclipse by converting the loaded project to a Groovy Project. The project itself will work as before.

To do this just follow these few steps:

  1. Right-click on the project that has to be converted
  2. Click on "Configure"
  3. Click on "Convert to Groovy Project"

Eclipse will automatically load the file OfbizDslDescriptorForEclipse.dsld , in which the known fields and methods used in Groovy Scripts are defined.


 

Known Fields

property name: 'parameters', type : 'java.util.Map'

These are the parameters given to the Groovy Script, when it is called as a service. It is equivalent to Map<String, Object> context in the Java-Service-Definition.

property name: 'context', type: 'java.util.Map'

More parameters, which are, for example, given through a screen or another Groovy Script. This is important when the script is called through an action segment of a screen.

property name: 'delegator', type: 'org.apache.ofbiz.entity.Delegator'

Normal instance of the Delegator, which is used for special database access.

property name: 'dispatcher', type: 'org.apache.ofbiz.service.LocalDispatcher'

Normal instance of the LocalDispatcher, which is used to call services and other service-like operations.

property name: 'security', type: 'org.apache.ofbiz.security.Security'

Normal instance of the Security-Interface with which permission checks are done.

 

Known Methods

method name: 'runService', type: 'java.util.Map', params: [serviceName: 'String', inputMap: 'java.util.Map']

Helping method to call services instead of dispatcher.runSync(serviceName, inputMap). Also possible: run service: serviceName, with: inputMap

method name: 'makeValue', type: 'java.util.Map', params: [entityName: 'String']

Helping method to make a GenericValue instead of delegator.makeValue(entityName). Creates an empty GenericValue of the specific entity.

method name: 'findOne', type: 'java.util.Map', params: [entityName: 'String', inputMap: 'java.util.Map']

Helping method to find one GenericValue in the database. Used instead of delegator.findOne(entityName, inputMap)

method name: 'findList', type: 'java.util.List', params: [entityName: 'String', inputMap: 'java.util.Map']

Helping method to find many GenericValue in the database. Used instead of delegator.findList(entityName, inputMap, null, null, null, false)

method name: 'select', type: 'org.apache.ofbiz.entity.util.EntityQuery', params: [entity: 'java.util.Set']

Helping method used instead of EntityQuery.use(delegator).select(...)

method name: 'select', type: 'org.apache.ofbiz.entity.util.EntityQuery', params: [entity: 'String...']

As above.

method name: 'from', type: 'org.apache.ofbiz.entity.util.EntityQuery', params: [entity: 'java.lang.Object']

Helping method used instead of EntityQuery.use(delegator).from(...)

method name: 'success', type: 'def', params: [message: 'String']

Helping method used instead of ServiceUtil.returnSuccess(message)

method name: 'failure', type: 'java.util.Map', params: [message: 'String']

Helping method used instead of ServiceUtil.returnFailure(message)

method name: 'error', type: 'def', params: [message: 'String']

Helping method used instead of ServiceUtil.returnError(message)

method name: 'logInfo', type: 'void', params: [message: 'String']

Helping method used instead of Debug.logInfo(message, fileName)

method name: 'logWarning', type: 'void', params: [message: 'String']

Helping method used instead of Debug.logWarning(message, fileName)

method name: 'logError', type: 'void', params: [message: 'String']

Helping method used instead of Debug.logError(message, fileName)

method name: 'logVerbose', type: 'void', params: [message: 'String']

Helping method used instead of Debug.logVerbose(message, fileName)


The actual definition of the methods can be found in /framework/service/src/main/java/org/apache/ofbiz/service/engine/GroovyBaseScript.groovy,
the variables dctx, dispatcher and delegator are set in the file GroovyEngine.java which can be found in the same location.


 

Services

 

From MiniLang to Groovy

To see additional examples and finished conversions, which may help with occurring questions, click: 

 

 

 

 

 

 

 

  • No labels