Skip to main content

Implementing Tasks

After defining a TaskElement, 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);
Other elements

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 Layer, not the {DataElement}LocalAgent.

Custom Implementation in Ext

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.

Options

Option
noDelegation TaskElement

When added, no dedicated {TaskElement}Impl implementation class will be generated. Customization can still be added to the {TaskElement}Bean. Using the implementation class is preferred as it is decoupled from EJB.

<options>
<noDelegation/>
</options>
Option
includeRemoteAccess TaskElement

Creates an Agent class for this TaskElement, which exposes the Task to the Control Layer and other Components. Also provides a struts-endpoint from which the task can be executed.

<options>
<includeRemoteAccess/>
</options>