以程式設計方式與工作流程互動 interacting-with-workflows-programmatically
當自訂及擴充您的工作流程時,您可以存取工作流程物件:
使用工作流程Java API using-the-workflow-java-api
工作流程Java API包含com.adobe.granite.workflow
套件和多個子套件。 API最重要的成員是com.adobe.granite.workflow.WorkflowSession
類別。 WorkflowSession
類別同時提供設計階段和執行階段工作流程物件的存取權:
- 工作流程模型
- 工作專案
- 工作流程例項
- 工作流程資料
- 收件匣專案
此類別也提供幾種方法來干預工作流程生命週期。
下表提供以程式設計方式與工作流程互動時,要使用的數個關鍵Java物件的參考檔案連結。 下列範例示範如何取得和使用程式碼中的類別物件。
在ECMA指令碼中取得工作流程物件 obtaining-workflow-objects-in-ecma-scripts
如尋找指令碼中所述,AEM (透過Apache Sling)提供執行伺服器端ECMA指令碼的ECMA指令碼引擎。 org.apache.sling.scripting.core.ScriptHelper
類別可立即供您的指令碼做為sling
變數使用。
ScriptHelper
類別可讓您存取最終用來取得WorkflowSession
物件的SlingHttpServletRequest
;例如:
var wfsession = sling.getRequest().getResource().getResourceResolver().adaptTo(Packages.com.adobe.granite.workflow.WorkflowSession);
使用工作流程REST API using-the-workflow-rest-api
「工作流程」主控台大量使用REST API,因此本頁會說明工作流程的REST API。
REST API支援下列動作:
- 啟動或停止工作流程服務
- 建立、更新或刪除工作流程模型
- 啟動、暫停、繼續或終止工作流程例項
- 完成或委派工作專案
POST
要求檢查傳送至AEM伺服器的引數和值。在此頁面中,假設AEM會在連線埠4502
的localhost上執行,而且安裝內容是" /
" (根)。 如果不是安裝,則需要相應地調整HTTP請求適用的URI。
GET
要求支援的轉譯是JSON轉譯。 GET
的URL應該有.json
副檔名,例如:
http://localhost:4502/etc/workflow.json
管理工作流程例項 managing-workflow-instances
下列HTTP要求方法適用於:
http://localhost:4502/etc/workflow/instances
依狀態管理工作流程例項 managing-a-workflow-instance-by-its-state
下列HTTP要求方法適用於:
http://localhost:4502/etc/workflow/instances.{state}
GET
RUNNING
、SUSPENDED
、ABORTED
或COMPLETED
)依其ID管理工作流程例項 managing-a-workflow-instance-by-its-id
下列HTTP要求方法適用於:
http://localhost:4502/etc/workflow/instances/{id}
管理工作流程模型 managing-workflow-models
下列HTTP要求方法適用於:
http://localhost:4502/etc/workflow/models
範例:在瀏覽器中,對http://localhost:4502/etc/workflow/models.json
的請求會產生類似以下的json回應:
[
{"uri":"/var/workflow/models/activationmodel"}
,{"uri":"/var/workflow/models/dam/adddamsize"}
,{"uri":"/var/workflow/models/cloudconfigs/dtm-reactor/library-download"}
,{"uri":"/var/workflow/models/ac-newsletter-workflow-simple"}
,{"uri":"/var/workflow/models/dam/dam-create-language-copy"}
,{"uri":"/var/workflow/models/dam/dam-create-and-translate-language-copy"}
,{"uri":"/var/workflow/models/dam-indesign-proxy"}
,{"uri":"/var/workflow/models/dam-xmp-writeback"}
,{"uri":"/var/workflow/models/dam-parse-word-documents"}
,{"uri":"/var/workflow/models/dam/process_subasset"}
,{"uri":"/var/workflow/models/dam/dam_set_last_modified"}
,{"uri":"/var/workflow/models/dam/dam-autotag-assets"}
,{"uri":"/var/workflow/models/dam/update_asset"}
,{"uri":"/var/workflow/models/dam/update_asset_offloading"}
,{"uri":"/var/workflow/models/dam/dam-update-language-copy"}
,{"uri":"/var/workflow/models/dam/update_from_lightbox"}
,{"uri":"/var/workflow/models/cloudservices/DTM_bundle_download"}
,{"uri":"/var/workflow/models/dam/dam_download_asset"}
,{"uri":"/var/workflow/models/dam/dynamic-media-encode-video"}
,{"uri":"/var/workflow/models/dam/dynamic-media-video-thumbnail-replacement"}
,{"uri":"/var/workflow/models/dam/dynamic-media-video-user-uploaded-thumbnail"}
,{"uri":"/var/workflow/models/newsletter_bounce_check"}
,{"uri":"/var/workflow/models/projects/photo_shoot_submission"}
,{"uri":"/var/workflow/models/projects/product_photo_shoot"}
,{"uri":"/var/workflow/models/projects/approval_workflow"}
,{"uri":"/var/workflow/models/prototype-01"}
,{"uri":"/var/workflow/models/publish_example"}
,{"uri":"/var/workflow/models/publish_to_campaign"}
,{"uri":"/var/workflow/models/screens/publish_to_author_bin"}
,{"uri":"/var/workflow/models/s7dam/request_to_publish_to_youtube"}
,{"uri":"/var/workflow/models/projects/request_copy"}
,{"uri":"/var/workflow/models/projects/request_email"}
,{"uri":"/var/workflow/models/projects/request_landing_page"}
,{"uri":"/var/workflow/models/projects/request_launch"}
,{"uri":"/var/workflow/models/request_for_activation"}
,{"uri":"/var/workflow/models/request_for_deactivation"}
,{"uri":"/var/workflow/models/request_for_deletion"}
,{"uri":"/var/workflow/models/request_for_deletion_without_deactivation"}
,{"uri":"/var/workflow/models/request_to_complete_move_operation"}
,{"uri":"/var/workflow/models/reverse_replication"}
,{"uri":"/var/workflow/models/salesforce-com-export"}
,{"uri":"/var/workflow/models/scene7"}
,{"uri":"/var/workflow/models/scheduled_activation"}
,{"uri":"/var/workflow/models/scheduled_deactivation"}
,{"uri":"/var/workflow/models/screens/screens-update-asset"}
,{"uri":"/var/workflow/models/translation"}
,{"uri":"/var/workflow/models/s7dam/request_to_remove_from_youtube"}
,{"uri":"/var/workflow/models/wcm-translation/create_language_copy"}
,{"uri":"/var/workflow/models/wcm-translation/prepare_translation_project"}
,{"uri":"/var/workflow/models/wcm-translation/translate-i18n-dictionary"}
,{"uri":"/var/workflow/models/wcm-translation/sync_translation_job"}
,{"uri":"/var/workflow/models/wcm-translation/translate-language-copy"}
,{"uri":"/var/workflow/models/wcm-translation/update_language_copy"}
]
管理特定工作流程模型 managing-a-specific-workflow-model
下列HTTP要求方法適用於:
http://localhost:4502*{uri}*
其中*{uri}*
是存放庫中模型節點的路徑。
範例:在瀏覽器中,對http://localhost:4502/var/workflow/models/publish_example.json
的請求傳回與下列程式碼類似的json
回應:
{
"id":"/var/workflow/models/publish_example",
"title":"Publish Example",
"version":"1.0",
"description":"This example shows a simple review and publish process.",
"metaData":
{
"multiResourceSupport":"true",
"tags":"wcm,publish"
},
"nodes":
[{
"id":"node0",
"type":"START",
"title":"Start",
"description":"The start node of the workflow.",
"metaData":
{
}
},
{
"id":"node1",
"type":"PARTICIPANT",
"title":"Validate Content",
"description":"Validate the modified content.",
"metaData":
{
"PARTICIPANT":"admin"
}
},
{
"id":"node2",
"type":"PROCESS",
"title":"Publish Content",
"description":"Publish the modified content.",
"metaData":
{
"PROCESS_AUTO_ADVANCE":"true",
"PROCESS":"com.day.cq.wcm.workflow.process.ActivatePageProcess"
}
},
{
"id":"node3",
"type":"END",
"title":"End",
"description":"The end node of the workflow.",
"metaData":
{
}
}],
"transitions":
[{
"from":"node0",
"to":"node1",
"metaData":
{
}
},
{
"from":"node1",
"to":"node2",
"metaData":
{
}
},
{
"from":"node2",
"to":"node3",
"metaData":
{
}
}
]}
依工作流程模型版本進行管理 managing-a-workflow-model-by-its-version
下列HTTP要求方法適用於:
http://localhost:4502/etc/workflow/models/{id}.{version}
GET
管理(使用者)收件匣 managing-user-inboxes
下列HTTP要求方法適用於:
http://localhost:4502/bin/workflow/inbox
依工作專案ID管理(使用者)收件匣 managing-a-user-inbox-by-the-workitem-id
下列HTTP要求方法適用於:
http://localhost:4502/bin/workflow/inbox/{id}
GET
WorkItem
的資料(定義和中繼資料)。範例 examples
如何取得所有執行中工作流程的清單及其ID how-to-get-a-list-of-all-running-workflows-with-their-ids
若要取得所有執行中的工作流程清單,請執行GET:
http://localhost:4502/etc/workflow/instances.RUNNING.json
如何使用ID取得所有執行中工作流程的清單 — REST (使用CURL) how-to-get-a-list-of-all-running-workflows-with-their-ids-rest-using-curl
使用curl的範例:
curl -u admin:admin http://localhost:4502/etc/workflow/instances.RUNNING.json
結果中顯示的uri
可以做為其他命令的執行個體id
;例如:
[
{"uri":"/etc/workflow/instances/server0/2017-03-08/request_for_activation_1"}
]
如何變更工作流程標題 how-to-change-the-workflow-title
若要變更顯示在工作流程主控台 執行個體 索引標籤中的 工作流程標題,請傳送POST
命令:
-
至:
http://localhost:4502/etc/workflow/instances/{id}
-
,並使用下列引數:
action
:它的值必須是:UPDATE
workflowTitle
:工作流程標題
如何使用curl變更工作流程標題 — REST how-to-change-the-workflow-title-rest-using-curl
使用curl的範例:
curl -u admin:admin -d "action=UPDATE&workflowTitle=myWorkflowTitle" http://localhost:4502/etc/workflow/instances/{id}
# for example
curl -u admin:admin -d "action=UPDATE&workflowTitle=myWorkflowTitle" http://localhost:4502/etc/workflow/instances/server0/2017-03-08/request_for_activation_1
如何列出所有工作流程模型 how-to-list-all-workflow-models
若要取得所有可用工作流程模型的清單,請執行GET:
http://localhost:4502/etc/workflow/models.json
如何使用CURL列出所有工作流程模型 — REST how-to-list-all-workflow-models-rest-using-curl
使用curl的範例:
curl -u admin:admin http://localhost:4502/etc/workflow/models.json
取得WorkflowSession物件 obtaining-a-workflowsession-object
com.adobe.granite.workflow.WorkflowSession
類別可從javax.jcr.Session
物件或org.apache.sling.api.resource.ResourceResolver
物件改寫。
取得WorkflowSession物件 — Java obtaining-a-workflowsession-object-java
在JSP指令碼(或Servlet類別的Java程式碼)中,使用HTTP要求物件來取得SlingHttpServletRequest
物件,以提供ResourceResolver
物件的存取權。 將ResourceResolver
物件調整為WorkflowSession
。
<%
%><%@include file="/libs/foundation/global.jsp"%><%
%><%@page session="false"
import="com.adobe.granite.workflow.WorkflowSession,
org.apache.sling.api.SlingHttpServletRequest"%><%
SlingHttpServletRequest slingReq = (SlingHttpServletRequest)request;
WorkflowSession wfSession = slingReq.getResourceResolver().adaptTo(WorkflowSession.class);
%>
取得WorkflowSession物件 — ECMA指令碼 obtaining-a-workflowsession-object-ecma-script
使用sling
變數來取得您用來取得ResourceResolver
物件的SlingHttpServletRequest
物件。 將ResourceResolver
物件調整為WorkflowSession
物件。
var wfsession = sling.getRequest().getResource().getResourceResolver().adaptTo(Packages.com.adobe.granite.workflow.WorkflowSession);
建立、讀取或刪除工作流程模型 creating-reading-or-deleting-workflow-models
下列範例顯示如何存取工作流程模型:
- Java和ECMA指令碼的程式碼使用
WorkflowSession.createNewModel
方法。 - curl指令會使用模型的URL直接存取模型。
使用的範例:
- 建立模型(識別碼為
/var/workflow/models/mymodel/jcr:content/model
)。 - 刪除模型。
metaData
子節點的deleted
屬性設定為true
。建立模型時:
-
工作流程模型編輯器要求模型使用
/var/workflow/models
下的特定節點結構。 模型的父節點必須是型別cq:Page
,具有具有下列屬性值之jcr:content
節點:sling:resourceType
:cq/workflow/components/pages/model
cq:template
:/libs/cq/workflow/templates/model
建立模型時,您必須先建立此
cq:Page
節點,並使用其jcr:content
節點作為模型節點的父節點。 -
某些用來識別模型的方法所需的
id
引數是存放庫中模型節點的絕對路徑:/var/workflow/models/<*model_name>*/jcr:content/model
note note NOTE 請參閱如何列出所有工作流程模型。
建立、讀取或刪除工作流程模型 — Java creating-reading-or-deleting-workflow-models-java
<%@include file="/libs/foundation/global.jsp"%><%
%><%@page session="false" import="com.adobe.granite.workflow.WorkflowSession,
com.adobe.granite.workflow.model.WorkflowModel,
org.apache.sling.api.SlingHttpServletRequest"%><%
SlingHttpServletRequest slingReq = (SlingHttpServletRequest)request;
WorkflowSession wfSession = slingReq.getResourceResolver().adaptTo(WorkflowSession.class);
/* Create the parent page */
String modelRepo = new String("/var/workflow/models");
String modelTemplate = new String ("/libs/cq/workflow/templates/model");
String modelName = new String("mymodel");
Page modelParent = pageManager.create(modelRepo, modelName, modelTemplate, "My workflow model");
/* create the model */
String modelId = new String(modelParent.getPath()+"/jcr:content/model")
WorkflowModel model = wfSession.createNewModel("Made using Java",modelId);
/* delete the model */
wfSession.deleteModel(modelId);
%>
建立、讀取或刪除工作流程模型 — ECMA指令碼 creating-reading-or-deleting-workflow-models-ecma-script
var resolver = sling.getRequest().getResource().getResourceResolver();
var wfSession = resolver.adaptTo(Packages.com.adobe.granite.workflow.WorkflowSession);
var pageManager = resolver.adaptTo(Packages.com.day.cq.wcm.api.PageManager);
//create the parent page node
var workflowPage = pageManager.create("/var/workflow/models", "mymodel", "/libs/cq/workflow/templates/model", "Created via ECMA Script");
var modelId = workflowPage.getPath()+ "/jcr:content/model";
//create the model
var model = wfSession.createNewModel("My Model", modelId);
//delete the model
var model = wfSession.deleteModel(modelId);
刪除工作流程模型 — 使用CURL的REST deleting-a-workflow-model-rest-using-curl
# deleting the model by its id
curl -u admin:admin -X DELETE http://localhost:4502/etc/workflow/models/{id}
檢查工作流程狀態時篩選出系統工作流程 filtering-out-system-workflows-when-checking-workflow-status
您可以使用WorkflowStatus API來擷取有關節點的工作流程狀態的資訊。
各種方法都有引數:
excludeSystemWorkflows
此引數可設為true
,以表示系統工作流程應從相關結果中排除。
您可以更新OSGi設定 AdobeGranite工作流程PayloadMapCache,該設定將工作流程Models
指定為系統工作流程。 預設(執行階段)工作流程模型為:
/var/workflow/models/scheduled_activation/jcr:content/model
/var/workflow/models/scheduled_deactivation/jcr:content/model
逾時後自動前進參與者步驟 auto-advance-participant-step-after-a-timeout
如果您需要自動推進尚未在預先定義的時間內完成的 參與者 步驟,您可以:
-
實作OSGI事件接聽程式以接聽工作的建立和修改。
-
指定逾時(期限),然後建立排程的Sling作業,於當時引發。
-
撰寫作業處理常式,在逾時過期並觸發作業時通知此處理常式。
如果工作尚未完成,此處理常式會對工作採取必要的動作
與工作流程例項互動 interacting-with-workflow-instances
以下提供如何與工作流程例項互動(程式化)的基本範例。
與工作流程例項互動 — Java interacting-with-workflow-instances-java
// starting a workflow
WorkflowModel model = wfSession.getModel(workflowId);
WorkflowData wfData = wfSession.newWorkflowData("JCR_PATH", repoPath);
wfSession.startWorkflow(model, wfData);
// querying and managing a workflow
Workflow[] workflows workflows = wfSession.getAllWorkflows();
Workflow workflow= wfSession.getWorkflow(id);
wfSession.suspendWorkflow(workflow);
wfSession.resumeWorkflow(workflow);
wfSession.terminateWorkflow(workflow);
與工作流程執行個體互動 — ECMA指令碼 interacting-with-workflow-instances-ecma-script
// starting a workflow
var model = wfSession.getModel(workflowId);
var wfData = wfSession.newWorkflowData("JCR_PATH", repoPath);
wfSession.startWorkflow(model, wfData);
// querying and managing a workflow
var workflows = wfSession.getWorkflows("RUNNING");
var workflow= wfSession.getWorkflow(id);
wfSession.suspendWorkflow(workflow);
wfSession.resumeWorkflow(workflow);
wfSession.terminateWorkflow(workflow);
與工作流程例項互動 — 使用CURL的REST interacting-with-workflow-instances-rest-using-curl
-
正在啟動工作流程
code language-shell # starting a workflow curl -d "model={id}&payloadType={type}&payload={payload}" http://localhost:4502/etc/workflow/instances # for example: curl -u admin:admin -d "model=/var/workflow/models/request_for_activation&payloadType=JCR_PATH&payload=/content/we-retail/us/en/products" http://localhost:4502/etc/workflow/instances
-
列出執行個體
code language-shell # listing the instances curl -u admin:admin http://localhost:4502/etc/workflow/instances.json
這會列出所有例項,例如:
code language-shell [ {"uri":"/var/workflow/instances/server0/2018-02-26/prototype-01_1"} ,{"uri":"/var/workflow/instances/server0/2018-02-26/prototype-01_2"} ]
note note NOTE 請參閱如何取得所有執行中工作流程的清單及其識別碼,以列出具有特定狀態的執行個體。 -
正在暫停工作流程
code language-shell # suspending a workflow curl -d "state=SUSPENDED" http://localhost:4502/etc/workflow/instances/{id} # for example: curl -u admin:admin -d "state=SUSPENDED" http://localhost:4502/etc/workflow/instances/server0/2017-03-08/request_for_activation_1
-
繼續工作流程
code language-shell # resuming a workflow curl -d "state=RUNNING" http://localhost:4502/etc/workflow/instances/{id} # for example: curl -u admin:admin -d "state=RUNNING" http://localhost:4502/etc/workflow/instances/server0/2017-03-08/request_for_activation_1
-
正在終止工作流程執行個體
code language-shell # terminating a workflow curl -d "state=ABORTED" http://localhost:4502/etc/workflow/instances/{id} # for example: curl -u admin:admin -d "state=ABORTED" http://localhost:4502/etc/workflow/instances/server0/2017-03-08/request_for_activation_1
與工作專案互動 interacting-with-work-items
以下提供如何與工作專案互動(程式化)的基本範例。
與工作專案互動 — Java interacting-with-work-items-java
// querying work items
WorkItem[] workItems = wfSession.getActiveWorkItems();
WorkItem workItem = wfSession.getWorkItem(id);
// getting routes
List<Route> routes = wfSession.getRoutes(workItem);
// delegating
Iterator<Participant> delegatees = wfSession.getDelegatees(workItem);
wfSession.delegateWorkItem(workItem, delegatees.get(0));
// completing or advancing to the next step
wfSession.complete(workItem, routes.get(0));
與工作專案互動 — ECMA指令碼 interacting-with-work-items-ecma-script
// querying work items
var workItems = wfSession.getActiveWorkItems();
var workItem = wfSession.getWorkItem(id);
// getting routes
var routes = wfSession.getRoutes(workItem);
// delegating
var delegatees = wfSession.getDelegatees(workItem);
wfSession.delegateWorkItem(workItem, delegatees.get(0));
// completing or advancing to the next step
wfSession.complete(workItem, routes.get(0));
與工作專案互動 — 使用CURL的REST interacting-with-work-items-rest-using-curl
-
從收件匣列出工作專案
code language-shell # listing the work items curl -u admin:admin http://localhost:4502/bin/workflow/inbox
將會列出目前在「收件匣」中的工作專案詳細資訊;例如:
code language-shell [{ "uri_xss": "/var/workflow/instances/server0/2018-02-26/prototype-01_2/workItems/node2_var_workflow_instances_server0_2018-02-26_prototype-01_2", "uri": "/var/workflow/instances/server0/2018-02-26/prototype-01_2/workItems/node2_var_workflow_instances_server0_2018-02-26_prototype-01_2", "currentAssignee_xss": "workflow-administrators", "currentAssignee": "workflow-administrators", "startTime": 1519656289274, "payloadType_xss": "JCR_PATH", "payloadType": "JCR_PATH", "payload_xss": "/content/we-retail/es/es", "payload": "/content/we-retail/es/es", "comment_xss": "Process resource is null", "comment": "Process resource is null", "type_xss": "WorkItem", "type": "WorkItem" },{ "uri_xss": "configuration/configure_analyticstargeting", "uri": "configuration/configure_analyticstargeting", "currentAssignee_xss": "administrators", "currentAssignee": "administrators", "type_xss": "Task", "type": "Task" },{ "uri_xss": "configuration/securitychecklist", "uri": "configuration/securitychecklist", "currentAssignee_xss": "administrators", "currentAssignee": "administrators", "type_xss": "Task", "type": "Task" },{ "uri_xss": "configuration/enable_collectionofanonymoususagedata", "uri": "configuration/enable_collectionofanonymoususagedata", "currentAssignee_xss": "administrators", "currentAssignee": "administrators", "type_xss": "Task", "type": "Task" },{ "uri_xss": "configuration/configuressl", "uri": "configuration/configuressl", "currentAssignee_xss": "administrators", "currentAssignee": "administrators", "type_xss": "Task", "type": "Task" }
-
委派工作專案
code language-xml # delegating curl -d "item={item}&delegatee={delegatee}" http://localhost:4502/bin/workflow/inbox # for example: curl -u admin:admin -d "item=/etc/workflow/instances/server0/2017-03-08/request_for_activation_1/workItems/node1_etc_workflow_instances_server0_2017-03-08_request_for_act_1&delegatee=administrators" http://localhost:4502/bin/workflow/inbox
note note NOTE delegatee
必須是工作流程步驟的有效選項。 -
完成工作專案或將工作專案推進到下一個步驟
code language-xml # retrieve the list of routes; the results will be similar to {"results":1,"routes":[{"rid":"233123169","label":"End","label_xss":"End"}]} http://localhost:4502/etc/workflow/instances/<path-to-the-workitem>.routes.json # completing or advancing to the next step; use the appropriate route ID (rid value) from the above list curl -d "item={item}&route={route}" http://localhost:4502/bin/workflow/inbox # for example: curl -u admin:admin -d "item=/etc/workflow/instances/server0/2017-03-08/request_for_activation_1/workItems/node1_etc_workflow_instances_server0_2017-03-08_request_for_activation_1&route=233123169" http://localhost:4502/bin/workflow/inbox
接聽工作流程事件 listening-for-workflow-events
使用OSGi事件架構接聽com.adobe.granite.workflow.event.WorkflowEvent
類別定義的事件。 此類別也提供幾個實用方法,用來取得有關事件主旨的資訊。 例如,getWorkItem
方法會傳回事件所涉及之工作專案的WorkItem
物件。
以下範常式式碼會定義一項服務,此服務會監聽工作流程事件並根據事件型別執行工作。
package com.adobe.example.workflow.listeners;
import org.apache.sling.event.jobs.JobProcessor;
import org.apache.sling.event.jobs.JobUtil;
import org.osgi.service.event.Event;
import org.osgi.service.event.EventHandler;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.apache.felix.scr.annotations.Component;
import org.apache.felix.scr.annotations.Property;
import org.apache.felix.scr.annotations.Service;
import com.adobe.granite.workflow.event.WorkflowEvent;
import com.adobe.granite.workflow.exec.WorkItem;
/**
* The <code>WorkflowEventCatcher</code> class listens to workflow events.
*/
@Component(metatype=false, immediate=true)
@Service(value=org.osgi.service.event.EventHandler.class)
public class WorkflowEventCatcher implements EventHandler, JobProcessor {
@Property(value=com.adobe.granite.workflow.event.WorkflowEvent.EVENT_TOPIC)
static final String EVENT_TOPICS = "event.topics";
private static final Logger logger = LoggerFactory.getLogger(WorkflowEventCatcher.class);
public void handleEvent(Event event) {
JobUtil.processJob(event, this);
}
public boolean process(Event event) {
logger.info("Received event of topic: " + event.getTopic());
String topic = event.getTopic();
try {
if (topic.equals(WorkflowEvent.EVENT_TOPIC)) {
WorkflowEvent wfevent = (WorkflowEvent)event;
String eventType = wfevent.getEventType();
String instanceId = wfevent.getWorkflowInstanceId();
if (instanceId != null) {
//workflow instance events
if (eventType.equals(WorkflowEvent.WORKFLOW_STARTED_EVENT) ||
eventType.equals(WorkflowEvent.WORKFLOW_RESUMED_EVENT) ||
eventType.equals(WorkflowEvent.WORKFLOW_SUSPENDED_EVENT)) {
// your code comes here...
} else if (
eventType.equals(WorkflowEvent.WORKFLOW_ABORTED_EVENT) ||
eventType.equals(WorkflowEvent.WORKFLOW_COMPLETED_EVENT)) {
// your code comes here...
}
// workflow node event
if (eventType.equals(WorkflowEvent.NODE_TRANSITION_EVENT)) {
WorkItem currentItem = (WorkItem) event.getProperty(WorkflowEvent.WORK_ITEM);
// your code comes here...
}
}
}
} catch(Exception e){
logger.debug(e.getMessage());
e.printStackTrace();
}
return true;
}
}