Helix Tutorial: User Defined Content Store for Tasks
The purpose of user defined content store is to provide an easy use feature for some task dedicated meta temporary store. In this chapter, we'll learn how to implement and use content store in the user defined tasks.
Content Store Implementation
Extends abstract class UserContentStore.
private static class ContentStoreTask extends UserContentStore implements Task {
@Override public TaskResult run() {
...
}
@Override public void cancel() {
...
}
}
The default methods support 3 types of scopes:
- WORKFLOW: Define the content store in workflow level
- JOB: Define the content store in job level
- TASK: Define the content store in task level
Content Store Usage
Access content store in Task.run() method.
private static class ContentStoreTask extends UserContentStore implements Task {
@Override public TaskResult run() {
// put values into the store
putUserContent("ContentTest", "Value1", Scope.JOB);
putUserContent("ContentTest", "Value2", Scope.WORKFLOW);
putUserContent("ContentTest", "Value3", Scope.TASK);
// get the values with the same key in the different scopes
if (!getUserContent("ContentTest", Scope.JOB).equals("Value1") ||
!getUserContent("ContentTest", Scope.WORKFLOW).equals("Value2") ||
!getUserContent("ContentTest", Scope.TASK).equals("Value3")) {
return new TaskResult(TaskResult.Status.FAILED, null);
}
return new TaskResult(TaskResult.Status.COMPLETED, null);
}
}