Startseite / Plugin-Entwicklung / ContentCreator-Erweiterungen / Administrative Erweiterungen / Workflow Executables / Codebeispiel

Workflow Executable: Code Example

Using Java classes as workflow executables requires a multi-step process that involves both workflow and script definitions in a project's Template Store. This code example documents the configuration of a simple example workflow that calls a script; that script is configured to trigger the Java workflow executable.

The Workflow Executable

Workflow executables implement the interface Executable provided by the FirstSpirit Access API. This interface specifies two methods named execute(), of which one is called with a map of context information as a parameter, while the other method receives the same context map as well as two writer objects for logging as parameters.

Example: Executable class for use with workflow scripts

public class ExampleExecutable implements Executable {

public Object execute(Map<String,Object> executionContext) {
// Call the other execute method using System.out and System.err for logging.
return execute(executionContext, new PrintWriter(System.out, true), new PrintWriter(System.err, true));
}

public Object execute(Map<String,Object> executionContext, final Writer out, final Writer err) {
final Object scriptContext = executionContext.get("context");

// Acquire the editorial language used to display element information in the current execution instance.
final WebeditUiAgent webeditUiAgent = scriptContext.requireSpecialist(WebeditUiAgent.TYPE);
final Language displayLanguage = webeditUiAgent.getDisplayLanguage();

// Check if scriptContext is actually a WorkflowScriptContext object.
if (scriptContext instanceof WorkflowScriptContext) {
// Acquire the store element.
final StoreElement elementInWorkflow = scriptContext.getElement();

// Identify the transition's source and target vertices in the workflow model.
final Transition transition = scriptContext.getTransition();
final WorkflowElement transitionSource = transition.getSource();
final WorkflowElement transitionTarget = transition.getTarget();

// Log a sentence about the current workflow transition to System.out.
out.append("Performing workflow transition ");
out.append(transition.getDisplayName(displayLanguage));
out.append(" on store element \"");
out.append(elementInWorkflow.getDisplayName(displayLanguage));
out.append("\" from \"");
out.append(transitionSource.getDisplayName(displayLanguage));
out.append("\" to \"");
out.append(transitionTarget.getDisplayName(displayLanguage));
out.append("\".");
out.flush();
}
}
}

Calling the Executable From a Script

A simple script, placed in the Template Store, is required to call the workflow executable class. Context information available in the script's context will be passed along to the Java class as its methods are called.

The script may be of any type ("Template", "Menu" or "Context Menu") and consists of a shebang in the first line, followed by the fully-qualified class name (i.e., including package path) of the workflow executable on the second line. This code should be entered in the output channel that matches the first template set listed in the project's configuration in ServerManager.

Example: BeanShell script calling an Executable class

#! executable-class
de.espirit.firstspirit.opt.example.webedit.workflow.ExampleWorkflowExecutable

Configuring a Workflow Activity

A workflow activity configured to call a script.

Lastly, the workflow activity that is to trigger the workflow executable must be configured to run the script described above. This script may be selected in the "Script" drop-down list in the activity's settings window.

If the "Execution" option "Automatic" is selected, the script will automatically be run as a store element in this workflow is transitioned towards this activity. If the option "Manual" is selected, the user transitioning the store element towards this activity will see the workflow activity dialog and may optionally set or modify information such as revisers for the next workflow state, deadlines, etc.; once the user selects an outgoing transition towards another workflow state, the dialog will close, and the script is run.

© 2005 - 2024 Crownpeak Technology GmbH | Alle Rechte vorbehalten. | FirstSpirit 2024.13 | Datenschutz