Global library
A shared workflow library that provides common utility classes available to any workflow in the system. Deploy it once per OpenKM instance; other workflows load its nodes via a Library node and invoke its methods directly in their scripts. It contains two library nodes: library_global_base (general utilities) and library_global_document (document operations).
Overview
Download Global library.okmflow
Diagram
Library nodes
library_global_base
Defines the BaseLibrary class. Bind this node to the name BaseLibrary in your Library node configuration. Provides logging, context access, OpenKM web services, JSON serialisation and duration checking.
| Method | Return value | Description |
|---|---|---|
logInfo(String component, String message) |
void |
Writes an INFO entry to the workflow log file via |
|
component: Label that identifies the caller (e.g. message: Text to log. |
||
logError(String component, String message, Exception e) |
void |
Writes an ERROR entry including the full stack trace via |
|
component: Label that identifies the caller. message: Error description. e: Exception to include in the log entry. Pass |
||
getWebservices() |
OKMWebservices |
Returns the shared |
getContextValue(Map<String,Object> context, String key) |
Object |
Returns the value stored under |
|
context: The workflow context map (the key: Context variable name. |
||
setContextValue(Map<String,Object> context, String key, Object value) |
void |
Stores |
|
context: The workflow context map. key: Context variable name. value: Value to store. |
||
getInitiatorId(Map<String,Object> context) |
String |
Returns the user ID of the person who started the workflow process (reads the |
|
context: The workflow context map. |
||
getProcessInstanceId(Map<String,Object> context) |
long |
Returns the numeric ID of the current process instance (reads the |
|
context: The workflow context map. |
||
convertToJson(Object obj) |
String |
Serialises |
|
obj: Any Java/Groovy object to serialise. |
||
convertFromJson(String jsonString, Class targetClass) |
Object |
Deserialises a JSON string into an instance of |
|
jsonString: JSON string to deserialise. targetClass: Target Java class (e.g. |
||
hasDurationElapsed(String durationString, LocalDateTime startTime) |
boolean |
Returns |
|
durationString: ISO 8601 duration string (e.g. startTime: Reference |
||
library_global_document
Provides document-specific operations. Bind this node to the name docLib in your Library node configuration. Depends on BaseLibrary ? the Library node for library_global_base must be configured in the same workflow.
| Method | Return value | Description |
|---|---|---|
rename(Map<String,Object> context, String newName) |
void |
Renames the workflow document following the convention |
|
context: The workflow context map. Must contain the key newName: The new suffix to place after the prefix separator (e.g. |
||
How to use
Add one Library node per library node you want to consume. In each node, configure:
- Library workflow name:
Global library - Library node name: the node to load (
library_global_baseorlibrary_global_document) - Binding variable: the name used to call its methods in scripts (e.g.
BaseLibrary,docLib)
Example ? Action node script that uses both library nodes:
// Library node 1 configured as: Global library / library_global_base ? BaseLibrary
// Library node 2 configured as: Global library / library_global_document ? docLib
BaseLibrary.logInfo("MyWorkflow", "Starting document processing")
long piId = BaseLibrary.getProcessInstanceId(context)
String initiator = BaseLibrary.getInitiatorId(context)
BaseLibrary.logInfo("MyWorkflow", "Process ${piId} started by ${initiator}")
// Rename document: prefix-approved.pdf
docLib.rename(context, "approved")
Example ? Scheduled node using hasDurationElapsed to poll every cycle:
import java.time.LocalDateTime
// On first pass, store the start time
if (context.get("taskStarted") == null) {
context.put("taskStarted", LocalDateTime.now())
}
LocalDateTime taskStarted = context.get("taskStarted")
// Move to "timeout" transition after 4 minutes
if (BaseLibrary.hasDurationElapsed("PT4M", taskStarted)) {
return "timeout"
}
return "wait"