Hi Adrian, I've been thinking about this too. I think there will be a
lot of merit in combining the power of minilang + the power of groovy.
I'm still reading about groovying meta programming and DSL's, and I
don't yet understand the service engine under the hood, so I'm really
just thinking aloud here:
Could the groovy service class instance have the following methods
injected: entityOne(), makeValue(), returnSuccess(), createEntity(),
etc? That way, we wouldn't need a reference to the ScriptUtil class:
Map createPartyRole() {
partyRole = entityOne('PartyRole')
if (partyRole == null) {
partyRole = makeValue('PartyRole')
partyRole.setPKFields(parameters, true)
createEntity(partyRole, true)
}
returnSuccess()
}
Also, I was wondering whether we could manipulate the lists returned by
GenericValue like so:
party.getRelated("PartyRole").each() { roleTypeId ->
switch roleTypeId
{
case 'CONTENT_USER':
// doSomething(party)
break
case 'XYZ':
// doSomethingElse(party)
break
}
}
... just some thoughts
Chris
Adrian Crum wrote:
I have been working on some ideas with the goal of making Groovy a
viable alternative to mini-language. I already committed some code
that allows methods within a Groovy script to be called, so that
multiple services can be included in one file - just like in Java or
mini-language.
My next step is to create a Groovy script that contains utility
methods that mimic many of the existing mini-language elements -
particularly the ones that do a lot of work in one line. The utility
script (ScriptUtil) will be in the Groovy context so it will be easy
to access. For example:
<simple-method method-name="createPartyRole">
<entity-one entity-name="PartyRole" value-field="partyRole"/>
<if-empty field="partyRole">
<make-value entity-name="PartyRole" value-field="newEntity"/>
<set-pk-fields map="parameters" value-field="newEntity"/>
<create-value value-field="newEntity"/>
</if-empty>
</simple-method>
becomes
Map createPartyRole() {
partyRole = ScriptUtil.entityOne("PartyRole");
if (partyRole == null) {
partyRole = ScriptUtil.makeValue("PartyRole");
partyRole.setPKFields(parameters, true);
delegator.create(partyRole, true);
}
return ServiceUtil.returnSuccess();
}
The ScriptUtil methods will duplicate the mini-language Java code so
they will be interchangeable.
The bottom line is, I'm trying to bring some of mini-language's ease
of use to Groovy. Before I proceed any further, I wanted to find out
if there was any interest in it.
What do you think?
-Adrian