Version: 24.10
Groovy Service
Provides a generic Fluent API Groovy script service which can provide reusable scripts to be called by other services.
Service Invoke Parameters
Parameters are not nullable except where otherwise indicated.
Parameter | Description |
---|---|
svcDef | SvcDef A service definition value object. |
request | HttpServletRequest A HTTP servlet request. |
user | User Nullable. An authenticated user. |
request | HttpServletRequest The HTTP servlet request of the calling code. |
params | Map Nullable. A map of parameters provided by the service caller, or request parameters map if called from REST Groovy Service Invoke API. |
params.job | Job Nullable. An associated job action Job , added when the Groovy Service is called from $func.invoke() . |
params.jobAction | JobAction Nullable. An associated JobAction , added when the Groovy Service is called from $func.invoke() . |
Script Result
The script can optionally return a value.
Error Handling
If an error occurs invoking the Groovy Service, the error is recorded in the Journey Manager database error log.
Templates
Service
import com.avoka.core.groovy.GroovyLogger as logger
import com.avoka.tm.vo.*
import javax.servlet.http.*
class FluentGroovyService {
/*
* Perform a groovy service invocation
*
* return: the result object
*/
Object invoke(SvcDef svcDef, HttpServletRequest request, User user, Map params) {
// TODO: perform your logic
def result = 'groovy result - ' + params.formId
return result
}
}
Unit Test
import com.avoka.core.groovy.GroovyLogger as logger
import com.avoka.tm.svc.*
import com.avoka.tm.vo.*
import org.junit.Test
class UnitTest extends AbstractJUnitTest {
/*
* Perform service unit test
*
* throws exception if unit test fails
*/
@Test
void test() throws Exception {
Map args = [
"formId": 23
]
Map params = [
"svcDef": svcDef,
"request": null,
"user": null,
"params": args
]
def result = new ServiceInvoker(svcDef).invoke(params)
// Check result
logger.info result
assert "groovy result - 23" == result
}
}