Hello
I found some idea to improve the groovy DSL during my first try to
convert mini-lang.
I don't know if it's possible or logical at this time but I just sharing
my mind :)
****
entity-one : with the minilang is really usefull to call directly a
entity like that
<entity-one entity-name="Product" value-name="product"/>
currently with groovy
GenericValue product = from("Product").where([productId:
productId).findOne()
we lose the automapping so I imagine a syntax like that :
GenericValue product = from("Product").autoMap(groovyCtx).findOne()
or
GenericValue product = from("Product").findOne(groovyCtx)
or
GenericValue product = from("Product").resolveOne(groovyCtx)
or something like that
Make valid service context :
in minilang
<set-service-fields service-name="createProduct" map="context"
to-map="createProductMap"/>
Currently with groovy we need to call the dispatchcontext
Map createProductMap =
dispatcher.getDispatchContext().makeValidContext('createProduct', 'IN',
parameters)
My idea would be like that
Map createProductMap = prepare service: 'createProduct' //to pool
from groovyCtx
or
Map createProductMap = prepare service: 'createProduct' with:
parameters //to pool from parameters
or
Map createProductMap = prepare service: 'createProduct' with:
parameters mode: 'IN' //to pool from parameters and indicate the mode
It's would be the same to prepare a genericValue:
GenericValue product = prepare entity: 'Product' with: parameters
Resolve a label
in minilang
<fail-property resource="AccountingUiLabels"
property="AccountingCreatePaymentPermissionError"/>
in groovy
String message =
UtilProperties.getMessage('AccountingErrorUiLabels',
'AccountingUpdateRateAmountAlreadyExist', locale)
My idea
String message = message: 'AccountingUpdateRateAmountAlreadyExist',
from: 'AccountingErrorUiLabels', with: 'messageCtx'
Security control
in minilang
<if-has-permission permission="ACCOUNTING" action="_CREATE"/>
in groovy
if (security.hasPermission("ACCOUNTING_CREATE", userLogin))
My idea
if (has permission: 'ACCOUNTING_CREATE')
*******
I tried to implement "prepapre" for fun with success below :)
Index:
framework/service/src/main/java/org/apache/ofbiz/service/engine/GroovyBaseScript.groovy
===================================================================
---
framework/service/src/main/java/org/apache/ofbiz/service/engine/GroovyBaseScript.groovy
(révision 1800195)
+++
framework/service/src/main/java/org/apache/ofbiz/service/engine/GroovyBaseScript.groovy
(copie de travail)
@@ -19,6 +19,8 @@
package org.apache.ofbiz.service.engine
import org.apache.ofbiz.base.util.Debug
+import org.apache.ofbiz.entity.finder.PrimaryKeyFinder
+import org.apache.ofbiz.entity.model.ModelEntity
import org.apache.ofbiz.entity.util.EntityQuery
import org.apache.ofbiz.service.ServiceUtil
import org.apache.ofbiz.service.ExecutionServiceException
@@ -47,6 +49,15 @@
return runService((String)args.get('service'),
(Map)args.get('with', new HashMap()))
}
+ Map prepare(Map args) throws ExecutionServiceException {
+ if ((String)args.get('service')) {
+ return result =
binding.getVariable('dispatcher').getDispatchContext().makeValidContext((String)
args.get('service'), "IN", (Map) args.get('with',
binding.getVariable('parameters')))
+ }
+ if ((String)args.get('entity')) {
+ return result =
binding.getVariable('delegator').makeValidValue((String)
args.get('entity'), (Map) args.get('with',
binding.getVariable('parameters')))
+ }
+ }
+
Map makeValue(String entityName) throws ExecutionServiceException {
return result =
binding.getVariable('delegator').makeValue(entityName)
}
@@ -63,6 +74,13 @@
return
EntityQuery.use(binding.getVariable('delegator')).select(fields)
}
+ Map fromOneAuto(def entity) {
+ Debug.logError( ' ' + binding.getVariables(), '######')
+ return result =
PrimaryKeyFinder.runFind(binding.getVariable('delegator').getModelEntity(entity),
+ binding.getVariables(),
binding.getVariable('delegator'), true, true, null, null)
+
+ }
+
def success(String message) {
// TODO: implement some clever i18n mechanism based on the
userLogin and locale in the binding
if (this.binding.hasVariable('request')) {
Index:
applications/accounting/groovyScripts/payment/FindInvoicesByDueDate.groovy
===================================================================
---
applications/accounting/groovyScripts/payment/FindInvoicesByDueDate.groovy
(révision 1800195)
+++
applications/accounting/groovyScripts/payment/FindInvoicesByDueDate.groovy
(copie de travail)
@@ -20,7 +20,7 @@
context.invoicePaymentInfoList = []
if (parameters.invoiceTypeId) { // it's not the initialisation but a
real search request
- serviceCtx =
dispatcher.getDispatchContext().makeValidContext("getInvoicePaymentInfoListByDueDateOffset",
"IN", parameters)
+ serviceCtx = prepare service:
'getInvoicePaymentInfoListByDueDateOffset'
result = runService("getInvoicePaymentInfoListByDueDateOffset",
serviceCtx)
context.invoicePaymentInfoList = result.invoicePaymentInfoList
}
Index: applications/accounting/groovyScripts/rate/RateServices.groovy
===================================================================
--- applications/accounting/groovyScripts/rate/RateServices.groovy
(révision 1800245)
+++ applications/accounting/groovyScripts/rate/RateServices.groovy
(copie de travail)
@@ -31,7 +31,7 @@
* Service to create a rate amount value, if a existing value is
present expire it before
*/
def updateRateAmount() {
- GenericValue newEntity = delegator.makeValidValue('RateAmount',
parameters)
+ GenericValue newEntity = prepare entity: 'RateAmount'
if (!newEntity.rateCurrencyUomId) {
newEntity.rateCurrencyUomId =
UtilProperties.getPropertyValue('general.properties',
'currency.uom.id.default')
}
@@ -65,11 +65,11 @@
* Service to expire a rate amount value
*/
def expireRateAmount() {
- GenericValue lookedUpValue = delegator.makeValidValue('RateAmount',
parameters)
+ GenericValue lookedUpValue = prepare entity: 'RateAmount'
if (!lookedUpValue.rateCurrencyUomId) {
lookedUpValue.rateCurrencyUomId =
UtilProperties.getPropertyValue('general.properties',
'currency.uom.id.default')
}
- lookedUpValue =
from('RateAmount').where(lookedUpValue.getFields(lookedUpValue.getModelEntity().getPkFieldNames())).queryOne()
+ lookedUpValue = fromOneAuto('RateAmount')
if (lookedUpValue) {
Timestamp previousDay =
UtilDateTime.adjustTimestamp(UtilDateTime.nowTimestamp(), 5, -1)
lookedUpValue.thruDate = UtilDateTime.getDayEnd(previousDay)
@@ -93,7 +93,7 @@
GenericValue partyRate = EntityUtil.getFirst(partyRates)
partyRate.thruDate = UtilDateTime.nowTimestamp()
}
- GenericValue newEntity = delegator.makeValidValue('PartyRate',
parameters)
+ GenericValue newEntity = prepare entity: 'PartyRate'
if (!newEntity.fromDate) newEntity.fromDate =
UtilDateTime.nowTimestamp()
newEntity.create()
Index:
framework/base/src/main/java/org/apache/ofbiz/base/OfbizDslDescriptorForIntelliJ.gdsl
===================================================================
---
framework/base/src/main/java/org/apache/ofbiz/base/OfbizDslDescriptorForIntelliJ.gdsl
(révision 1800195)
+++
framework/base/src/main/java/org/apache/ofbiz/base/OfbizDslDescriptorForIntelliJ.gdsl
(copie de travail)
@@ -29,6 +29,7 @@
method name: 'runService', type: 'java.util.Map', params:
[serviceName: 'String', inputMap: 'java.util.Map']
method name: 'run', type: 'java.util.Map', params: [args:
'java.util.Map']
+ method name: 'prepare', type: 'java.util.Map', params: [args:
'java.util.Map']
method name: 'makeValue', type: 'java.util.Map', params:
[entityName: 'String']
method name: 'select', type:
'org.apache.ofbiz.entity.util.EntityQuery', params: [entity:
'java.util.Set']
method name: 'select', type:
'org.apache.ofbiz.entity.util.EntityQuery', params: [entity: 'String...']
--
logoNrd <https://nereide.fr/>
Nicolas Malin
The apache way <http://theapacheway.com/> : *Openness* Technical
decisions are made publicly
informat...@nereide.fr
8 rue des Déportés 37000 TOURS, 02 47 50 30 54
Apache OFBiz <http://ofbiz.apache.org/>|The Apache Way
<http://theapacheway.com/>|ofbiz-fr <http://www.ofbiz-fr.org/>|réseau LE
<http://www.libre-entreprise.org/>