Skip to main content

Migrating workflow methods including renderer calls

1. Migrating workflow methods not implementing RenderingPlugin interface

There are two ways to run old legacy workflow methods in a Camunda process without rewriting them.

1.1 Running old (legacy) workflow method in Camunda process with legacy worker

Configuring the process, we need to add a new service task and configure it to run the legacy workflow method. More details about creating new process with service tasks can be found here

We need to set a proper worker - Implementation set to: External, Topic set to Legacy Workflow Method:

legacy-topic.png

Then we can choose a type of the method:

legacy-definition01.png

and the specific method:

legacy-definition02.png

Handling method result

Legacy workflow method can finish with success, technical error or business error. Legacy worker running a method creates process variable named errorCode. If a method succeeds the error code is equal 0 if business error was raised errorCode is set to 1. It can be handled further in the process using gateway element. In case of technical error, the exception is raised. It can be handled by error boundary event element.

The sample process is shown below:

sample_process.png

1.2 Creating a new workflow method wrapping the old one

Another way to run legacy workflow method is to wrap it in the new method (later referred to as Automation Method) designed for service tasks for Camunda processes.

Inside the new method one can call the legacy method via PluginMethodUtils.execJavaPluginMethod. i.e.

public static final String LEGACY_PAGINATION_MAPPED_NAME = "com.priint.pubserver.plugins.pubplanner.Pagination"; 

//in exec method
PluginMethodUtils.execJavaPluginMethod(LEGACY_PAGINATION_MAPPED_NAME, new Object[]{params}, sessionId);

Before that, it is needed to pass parameter values required by the method from the process variables. i.e.

public static final String PUBLICATION_ID = "publicationId";
private static final String OLD_PUBLICATION_ID_PARAMETER = "<DOCUMENT_ID>";

//in exec method
String sessionId = (String)parameters.get("sessionId");
String publicationId = (String)parameters.get(PUBLICATION_ID);
Map<String, Object> params = new HashMap<>();
params.put(OLD_PUBLICATION_ID_PARAMETER,publicationId);

The legacy method can raise technical or business error or finish with success. The business error should be intercepted and change into a process variable (i.e. errorCode) to be able to react properly in the process. Technical error should be rethrown (thrown as an exception), then can be handled further in the process by boundary events. If the method completes with success the proper process variable (i.e. errorCode) should be set to 0.

The whole new wrapper method can be done as below:

public static final String LEGACY_PAGINATION_MAPPED_NAME = "com.priint.pubserver.plugins.pubplanner.Pagination";
public static final String PUBLICATION_ID = "publicationId";
private static final String OLD_PUBLICATION_ID_PARAMETER = "<DOCUMENT_ID>";
private static final String ERROR_CODE = "errorCode";
private static final String ERROR_MSG = "errorMessage";


@PubServerMethod(label = "CalculateDocumentStartPage", type = PluginMethod.MethodType.BPM_PUBLICATION_PROCESS_METHOD,
description = "plugin method called to set a document start page for documents in publication")
public Map<String, Object> exec(@PubServerMethodParameter(name = "parameters") final Map<String, Object> parameters) {

Map<String, Object> result = new HashMap<>();

String sessionId = (String)parameters.get("sessionId");
String publicationId = (String)parameters.get(PUBLICATION_ID);
Map<String, Object> params = new HashMap<>();
params.put(OLD_PUBLICATION_ID_PARAMETER,publicationId);

try {
PluginMethodUtils.execJavaPluginMethod(LEGACY_PAGINATION_MAPPED_NAME, new Object[]{params}, sessionId);
result.put(ERROR_CODE, 0);
return result;
} catch (ParameterInterpreterException e) {
Throwable cause = e.getCause();
if (e.getErrorCode() == ParameterInterpreterException.EXCEPTION_IN_INVOKED_METHOD) {
if (cause instanceof WorkflowJobBussinessException) {
result.put(ERROR_CODE, 1);
result.put(ERROR_MSG, e.getErrorMessage());
return result;
}
}
throw new ServiceRuntimeException(e.getErrorMessage(), cause);
}
}

The manual about creating new workflow java methods can be found here

2. Methods from plugin implementing RenderingPlugin interface

There is no possibility to use methods implementing rendering calls in a Camunda process. It must be done in a different way. The method should be divided into parts (tasks) of the process. The task responsible for rendering should be replaced with new rendering service. More details about rendering tasks are here