Implementing Tasks
After defining a Task Element, you will need to implement the actual functionality as a customization.
By default, an implementation class {TaskElement}Impl is provided. This class contains a anchor:custom-perform where
the custom implementation can be added.
public class InvoiceSenderImpl implements InvoiceSender {
public TaskResult<Void> perform(ParameterContext<InvoiceDetails> targetParameter) {
UserContext userContext = targetParameter.getUserContext();
Context context = targetParameter.getContext();
TaskResult<Void> taskResult = TaskResult.success();
if (logger.isDebugEnabled()) {
logger.debug(
"Performing the InvoiceSenderImpl implementation"
);
}
try {
// @anchor:perform:start
// @anchor:perform:end
// anchor:custom-perform:start
// anchor:custom-perform:end
// @anchor:post-perform:start
// @anchor:post-perform:end
} catch (Exception e) {
// @anchor:perform-error:start
// @anchor:perform-error:end
// anchor:custom-perform-error:start
// anchor:custom-perform-error:end
taskResult = TaskResult.error();
if (logger.isErrorEnabled()) {
logger.error(
"Exception in InvoiceSenderImpl implementation", e
);
}
}
return taskResult;
}
}
The target DataElement instance can be accessed from the ParameterContext:
InvoiceDetails invoice = targetParameter.getValue();
To make changes to the database, you can use the LocalAgent class:
InvoiceLocalAgent agent = InvoiceLocalAgent.getInvoiceAgent();
agent.modify(invoice);
You can also access agents from other DataElements. When using the agent from a DataElement from another Component,
you should use the {DataElement}Agent from the Proxy LayerLayerLogical separation of functionality within a single system/application, focused on code organization., not the {DataElement}LocalAgent.
It it also possible to implement the Task in a custom class in the ext directory.
This has some benefits:
- You don't need to worry about missing import statements.
- You can give it a concrete name to set it apart from other implementations.
- It can be more concise.
Ext implementations will need to be added to the switch in the {TaskElement}Bean.
Receiving transition parameters
ProcessAutomation allows transitions to define an additional parameter class. To use the provided value, the task needs
to receive it. This can be done through the ValueParameterContext api. See also transition parameters.
Optional<MyParameters> params = ValueParameterContext.retrieve(context, MyParameters.class);
// check/unpack/use params
Options
TaskElementCreates an Agent class for this TaskElement, which exposes the Task to the Control LayerLayerLogical separation of functionality within a single system/application, focused on code organization. and other Components.
Also provides a struts-endpoint from which the task can be executed.
<options>
<includeRemoteAccess/>
</options>