AnsweredAssumed Answered

How to grab & enhance the script code prior to executing a groovy script task?

Question asked by darpanthanki on May 1, 2014
Latest reply on May 2, 2014 by martin.grofcik
We use script tasks quite extensively in the BPM workflows. However, given the nature of our application i.e. it being a SaaS application the workflows are designed by end-users (business users) which could typically includes script tasks as well. We need to build in mechanisms which can be used for securing the groovy code that gets executed. For example, to address issues relating to very long running scripts due to let's say an infinite loop we would like to ensure that prior to executing the script task do the following:

During workflow execution, when the script task is encountered we would like to enhance it by prepending 2 lines of code at the beginning of groovy script. The below code allows safe timed executions of scripts by adding elapsed time checks into loops (for, while) and at the start of closures and methods and throwing an exception if a timeout occurs. This can be achieved by implementing the logic to prepend the code using Activiti’s step listener hook.

import groovy.transform.TimedInterrupt
@TimedInterrupt(value = 300L, unit = java.util.concurrent.TimeUnit.SECONDS)
… original groovy script code follows …

This means we need the ability to grab the script code, enhance it, and then submit it to Activiti for execution.

Can someone provide a hint on how this could be accomplished?