Execution event is a semantic event which indicates that a Java delegation action occurred in the process flow. This high-level event is generated when a business logic either needs to be executed or evaluated via Spring Bean. The class that implements the com.adeptia.indigo.api.custom.ScriptExecutor interface gets this ExecutionEvent object whenever a Java delegation occurs in the process flow.
You create a Custom plugin activity using Spring Bean approach and develop a class that provides a business logic as a part of implementation of pre-defined functional interface com.adeptia.indigo.api.custom.ScriptExecutor. This implementation is executed during process execution. The ScriptExecutor interface has a execute method that accepts executionEvent object as a argument.
The definition of ScriptExecutor interface is given below.
package com.adeptia.indigo.api.custom; @FunctionalInterface public interface ScriptExecutor { public void execute(ExecutionEvent executionEvent); }
The definition of ExecutionEvent class is given below
package com.adeptia.indigo.api.custom; import java.io.InputStream; import java.io.OutputStream; import com.adeptia.indigo.logging.Logger; import com.adeptia.indigo.services.Service; import com.adeptia.indigo.services.transform.ScriptedService; import com.adeptia.indigo.system.Context; import com.adeptia.indigo.transaction.Transaction; public class ExecutionEvent { private Service service; private Transaction transaction; private InputStream inputStream; private OutputStream outputStream; private Logger logger; private Exception exception; private Context context; public Service getService() { return service; } public ExecutionEvent setService(Service service) { this.service = service; return this; } public Transaction getTransaction() { return transaction; } public ExecutionEvent setTransaction(Transaction transaction) { this.transaction = transaction; return this; } public InputStream getInputStream() { return inputStream; } public ExecutionEvent setInputStream(InputStream inputStream) { this.inputStream = inputStream; return this; } public OutputStream getOutputStream() { return outputStream; } public ExecutionEvent setOutputStream(OutputStream outputStream) { this.outputStream = outputStream; return this; } public Logger getLogger() { return logger; } public ExecutionEvent setLogger(Logger logger) { this.logger = logger; return this; } public Exception getException() { return exception; } public ExecutionEvent setException(Exception exception) { this.exception = exception; return this; } public Context getContext() { return context; } public ExecutionEvent setContext(Context context) { this.context = context; return this; } }
ExecutionEvent Class Description
The execution event class contains below fields:
Field Name | Field Description | |
---|---|---|
1 | service | The service field is the instance of Custom Plugin Service. Internally Custom Plugin Service is called as ScriptedService so this object can be casted to ScriptedService object as below. import com.adeptia.indigo.services.transform.ScriptedService; ScriptedService service = (ScriptedService) executionEvent.getService(); |
2 | transaction | Denotes the Transaction/Process Flow instance currently being executed |
3 | inputStream | A java.io.InputStream object; the data stream received from previous activity (if "Consume Stream" property is enabled) |
4 | logger | The service logger object for logging; any statement logged with this object can be viewed under Process Flow Diagnostics logs |
5 | exception | A java.lang.Exception object; available only in case of exception handler scripts |
6 | context | The process flow context |
Methods of ExecutionEvent class
The class contains the getter and setter methods for each field. The implementer classes has to deal with getter methods only to get the required objects and has nothing to do with setter methods. The anything set through setter methods will not reflect outside of execute method scope.
The below table lists the behavior of getter methods in case of different delegation situations.
Method | When delegation action occurred through a Service. Ex: Custom Plugin Service (Scripted Service) | When delegation action occurred through an Action. Ex: Gateway Condition | When delegation action occurred through an Exception Script. Ex: Service Exception Script | |
---|---|---|---|---|
1 | getService | returns the Service Object | returns null | returns the Service Object |
2 | getTransaction | returns null | returns the underlying Transaction Object | returns null |
3 | getInputStream | returns the inputStream object, the output generated by previously executed activity | returns null | returns null |
4 | getOutputStream | returns null | returns null | returns null |
5 | getLogger | returns the service logger object. | returns the service logger object. | returns the service logger object. |
6 | getException | returns null | returns null | returns the exception object. The exception object that triggered the exception script execution. |
7 | getContext | return the underlying Process flow Context | return the underlying Process flow Context | return the underlying Process flow Context |
Usage Examples when delegation action occurred through a Service. Example:- Custom Plugin Service (Scripted Service)
Usage | Example | |
---|---|---|
1 | Get Default Input Stream | InputStream inputStream = executionEvent.getInputStream(); |
2 | Get Default Output stream | ScriptedService service = (ScriptedService) executionEvent.getService(); OutputStream defaultOutputStream = service.getOutputStream(); |
3 | Get Named Input Stream | InputStream stream = service.getSourceStream(inputStreamName); |
4 | Get Named Output Stream | ScriptedService service = (ScriptedService) executionEvent.getService(); OutputStream outputStream = service.getOutputStream(outputStreamName) |
5 | Get Name of activity as defined in Process flow | ScriptedService scriptedService = (ScriptedService) executionEvent.getService(); String name = scriptedService .getName(); |
6 | Get Name of activity as defined in Custom Plugin definition | ScriptedService scriptedService = (ScriptedService) executionEvent.getService(); String entityName = scriptedService .getEntityName(); |
7 | Get Service Logger & log messages | ScriptedService scriptedService = (ScriptedService) executionEvent.getService(); Logger logger = service.getLogger(); logger.debug("Debug Statement"); logger.info("Info Statement"); logger.error("Error Statement"); |
8 | Get Character set encoding | String encoding = service.getCharacterSetEncoding(); |
9 | Get Context and Context variables | Context context = executionEvent.getContext(); |