`

Human Task API 用法

阅读更多

Creaet Human Task API:

 

<!-- 
"This sample program is provided AS IS and may be used, executed, copied and modified without
royalty payment by customer (a) for its own instruction and study, (b) in order to develop 
applications designed to run with an IBM WebSphere product, either for customer's own 
internal use or for redistribution by customer, as part of such an application, in customer's own products."

Product 5655-FLW,  (C) COPYRIGHT International Business Machines Corp., 2005, 2007
All Rights Reserved * Licensed Materials - Property of IBM
-->
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<%@ page language="java" contentType="text/html; charset=ISO-8859-1" pageEncoding="ISO-8859-1"%>
<title>Invocation Task Sample</title>
</head>
<body>
<div align="center">
<h1>Invocation Task Sample</h1>
<%@ page import="com.ibm.task.api.LocalHumanTaskManagerHome"%>
<%@ page import="com.ibm.task.api.LocalHumanTaskManager"%>
<%@ page import="com.ibm.task.api.*"%> <%@ page import="commonj.sdo.*"%>
<%@ page import="javax.naming.Context"%> <%
		try {

			//Obtain the default initial context
			Context context = new javax.naming.InitialContext();

			//Lookup the Local Home Interface
			LocalHumanTaskManagerHome taskHome = (LocalHumanTaskManagerHome) context.lookup("java:comp/env/ejb/LocalHumanTaskManagerHome");
			System.out.println("Lookup...success");

			//Access the local interface
			LocalHumanTaskManager taskManager = taskHome.create();
			System.out.println("Accessing local interface...success");

			String taskTemplateName = "ProcessStarter";
			String taskNamespace    = "http://InvocationTask/bpc/samples";

			//Create a new task instance
			TKIID pTaskID = taskManager.createTask(taskTemplateName, taskNamespace);
			System.out.println("task with instance ID = " + pTaskID.toString() + " created.");

			//get the task instance
			Task task = taskManager.getTask(pTaskID);
			
			//get wait parameter
			int wait = 1;//minutes
			try
			{
			   wait = Integer.parseInt(request.getParameter("minutesToWait"));
			}
			catch(NumberFormatException nfe)
			{
			}

			//create input message
			ClientObjectWrapper cow = taskManager.createInputMessage(pTaskID);
			DataObject dataObject = (DataObject) cow.getObject();
			dataObject.setString("in", request.getParameter("in"));
			dataObject.setInt("minutes", wait);

			//set an arbitrary task identifier
			task.setName(request.getParameter("task_name"));

			//start and update task instance
			taskManager.startTask(pTaskID, cow, null);
			taskManager.update(task);

			out.print("<BR>Task created succesfully!");

		} catch (Exception e) {
			e.printStackTrace(System.out);
			System.out.println(e.getClass());
			%>Exception occured. Check System.out.log for Details.<%
		}

	%>
<br>
<br>
<input type="button" onclick="document.location.href='index.html'" value="  Home  ">
<input type="button" onclick="document.location.href='create.html'" value="    New    ">
<input type="button" onclick="document.location.href='list.jsp'"   value="    List    ">
</div>
</body>
</html>

 

 

List Human Task API:

 

List Human Task API:

<!-- 
"This sample program is provided AS IS and may be used, executed, copied and modified without
royalty payment by customer (a) for its own instruction and study, (b) in order to develop 
applications designed to run with an IBM WebSphere product, either for customer's own 
internal use or for redistribution by customer, as part of such an application, in customer's own products."

Product 5655-FLW,  (C) COPYRIGHT International Business Machines Corp., 2005, 2007
All Rights Reserved * Licensed Materials - Property of IBM
-->
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<%@ page language="java" contentType="text/html; charset=ISO-8859-1" pageEncoding="ISO-8859-1"%>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>Invocation Task Sample</title>
</head>
<body>
<div align = center>
<h1 align="center">Invocation Task Sample</h1>
<br>

<%@ page import="com.ibm.task.api.LocalHumanTaskManagerHome"%>
<%@ page import="com.ibm.task.api.LocalHumanTaskManager"%>
<%@ page import="com.ibm.task.api.*"%>
<%@ page import="commonj.sdo.*"%>
<%@ page import="javax.naming.Context"%>
<%@ page import="bpc.samples.StateTranslator"%>

<!-- BEGINN General Code Section -->
<%
		LocalHumanTaskManager taskManager = null;
		int numOfInstances = 0;
		String name = null;
		QueryResultSet instances = null;

		try {

			//Obtain the defaukt initial context
			Context context = new javax.naming.InitialContext();

			//Lookup the Local Home Interface
			LocalHumanTaskManagerHome taskHome =
			   (LocalHumanTaskManagerHome) context.lookup("java:comp/env/ejb/LocalHumanTaskManagerHome");
			System.out.println("Lookup...success");

			//Access the local interface
			taskManager = taskHome.create();
			System.out.println("Accessing local interface...success");

			String taskTemplateName = "ProcessStarter";
			String taskNamespace    = "http://InvocationTask/bpc/samples";
			
			//query task instances
            String whereClause = "TASK_TEMPL.NAME='" + taskTemplateName + "' AND TASK_TEMPL.NAMESPACE='" + taskNamespace + "'";
			instances = taskManager.query("DISTINCT TASK.TKIID", whereClause, null,null, null, null);

			numOfInstances = instances.size();
			System.out.println(numOfInstances + " instances found");
		}

		catch (Exception e) {
			e.printStackTrace();
			System.out.println(e.getClass());
		}

		if (numOfInstances > 0) {
			//print the table

			%>
<table align="center" border="1" style="border-style:solid;" cellspacing="0">
    <thead>
        <tr>
            <th width="150" align="center" valign="middle" style="padding:5px;">Task identifier</th>
            <th width="200" align="center" valign="middle" style="padding:5px;">Input data</th>
            <th width="200" align="center" valign="middle" style="padding:5px;">Output data</th>
            <th width="80" align="center" valign="middle" style="padding:5px;">State</th>
        </tr>
    </thead>
    <tbody>
        <%
			try {

					instances.first();

					for (int i = 0; i < numOfInstances; i++) {
						TKIID temp = (TKIID) instances.getOID(1);
						Task task = taskManager.getTask(temp);
						name = task.getName();
						if (name.equals("")) {
							name = " ";
						}
						String input  = "not available";
						String output = "not available";

						//get the input message of instance i.
                        try
                        {
                            ClientObjectWrapper req = taskManager.getInputMessage(temp);
                            DataObject inputDO = (DataObject) req.getObject();
                            if(inputDO != null)
                            {
                                String in = inputDO.getString("in");
                                int minutes = inputDO.getInt("minutes");
                                input = "minutes: " + minutes + "<br>in: " + in;
                            }
                        }
                        catch(Exception e1)
                        {
                            System.out.println(e1);
                        }

						//get the output message of instance i, if possible
                        try
                        {
                            if (taskManager.getOutputMessage(temp).getObject() != null) {
                                //get the output message
                                ClientObjectWrapper resp = taskManager.getOutputMessage(temp);
                                DataObject outputDO = (DataObject) resp.getObject();
                                if(outputDO != null)
                                {
                                    output = outputDO.getString("out");
                                    if (output.equals("")) {
                                        output = " ";
                                    }
                                }
                            }
                        }
                        catch(Exception e2)
                        {
                            System.out.println(e2);
                        }

						//print table row for instance i
						out.print("<tr><td align=\"center\" style=\"padding:5px;\">"
										+ name
										+ "</td><td align=\"center\" style=\"padding:5px;\">"
										+ input
										+ "</td><td align=\"center\" style=\"padding:5px;\">"
										+ output
										+ "</td><td align=\"center\" style=\"padding:5px;\">"
										+ StateTranslator.translate(task.getState())
										+ "</td></tr>");

						instances.next();
					}
			}

			catch (Exception e)
			{
				e.printStackTrace();
				System.out.println(e.getClass());
				%>Exception occured. Check System.out.log for Details.<%
				
			}

		%>
        <!-- END List Code Section -->
    </tbody>
</table>
<br>
<br>

<input type="button" value="  Home   " onclick="document.location.href='index.html'">
<input type="button" value="   New   " onclick="document.location.href='create.html'">
<input type="button" value="Delete all" onclick="document.location.href='clearAll.jsp'">
<input type="button" value="Delete finished" onclick="document.location.href='clearFinished.jsp'">
<input type="button" value="Refresh table" onclick="document.location.href='list.jsp'">
<br>
<%} else {
			//print return button

		%>
<p>No instances of type ProcessStarter found.</p>
<br>
<br>
<input type="button" value="  Home   " onclick="document.location.href='index.html'">
<input type="button" value="   New   " onclick="document.location.href='create.html'">
<%}%>
</div>
</body>
</html>

 

 

Delete:

<!-- 
"This sample program is provided AS IS and may be used, executed, copied and modified without
royalty payment by customer (a) for its own instruction and study, (b) in order to develop 
applications designed to run with an IBM WebSphere product, either for customer's own 
internal use or for redistribution by customer, as part of such an application, in customer's own products."

Product 5655-FLW,  (C) COPYRIGHT International Business Machines Corp., 2005, 2007
All Rights Reserved * Licensed Materials - Property of IBM
-->
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<%@ page language="java" contentType="text/html; charset=ISO-8859-1" pageEncoding="ISO-8859-1"%>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>Originating Task Sample</title>
</head>
<body>
<%@ page import="com.ibm.task.api.LocalHumanTaskManagerHome"%>
<%@ page import="com.ibm.task.api.LocalHumanTaskManager"%>
<%@ page import="com.ibm.task.api.*"%>
<%@ page import="javax.naming.Context"%>
<div align="center">
<h1>Invocation Task Sample</h1>
<%

		try {

			//Obtain the defaukt initial context
			Context context = new javax.naming.InitialContext();

			//Lookup the Local Home Interface
			LocalHumanTaskManagerHome taskHome = (LocalHumanTaskManagerHome) context
					.lookup("java:comp/env/ejb/LocalHumanTaskManagerHome");
			System.out.println("Lookup...success");

			//Access the local interface
			LocalHumanTaskManager taskManager = taskHome.create();
			System.out.println("Accessing local interface...success");

			String taskTemplateName = "ProcessStarter";
			String taskNamespace    = "http://InvocationTask/bpc/samples";
			
			//query task instances
            String whereClause = "TASK_TEMPL.NAME='" + taskTemplateName + "' AND TASK_TEMPL.NAMESPACE='" + taskNamespace + "'";
			QueryResultSet instances = taskManager.query("DISTINCT TASK.TKIID",whereClause, null, null, null, null);
			System.out.println(instances.size() + " instances found");
			
			out.println("<p align=\"center\">"
							+ instances.size()
							+ " instances found.<br>Deleting all finished instances...<br></p>");

			//delete the instances
			instances.first();
			boolean noInstanceFound = true;
			for (int i = 0; i < instances.size(); i++) {
				TKIID temp = (TKIID) instances.getOID(1);
				Task task = taskManager.getTask(temp);
				int state = task.getState();
				if (state == 5) {
					taskManager.delete(temp);
					System.out.println("instance (" + temp + ") ...deleted");
					out.println("<p> --> instance \"" + task.getName() + "\" ... deleted.</p>");
					noInstanceFound = false;
				}
				instances.next();
			}
			if (noInstanceFound) {
				out.println("<p>No finished instances found.<p>");
			}
			QueryResultSet instances_left = taskManager.query("DISTINCT TASK.TKIID", whereClause, null, null, null, null);
			System.out.println(instances_left.size() + " instances left");
		}
		catch (Exception e) {
			e.printStackTrace();
			System.out.println(e.getClass());
			%>Exception occured. Check System.out.log for Details.<%
		}

	%> <br>
<input type="button" onclick="document.location.href='list.jsp'" value="    OK    "></div>
</body>
</html>

 

分享到:
评论
1 楼 littlelear 2009-02-13  
这篇文章还是很不错的。
不过还有很多常用的human task api
网上资料不是很好找

相关推荐

    4流实战_工作流中的概念与JBPM相关API调用

    8. **Human Task Service**:JBPM的人力任务服务允许与人交互的部分,如任务分配、通知和审批。 9. **Persistence**:JBPM使用JPA(Java Persistence API)持久化工作流数据,确保在系统重启后可以恢复工作流状态。...

    BPS工作流使用说明及安装指南

    本指南将详细介绍BPS 6.1版本的工作流使用方法、安装步骤以及相关API和文档,帮助用户更好地理解和操作这一系统。 首先,我们来看一下BPS的核心概念: 1. **工作流(Workflow)**:工作流是一系列相互关联的任务,...

    FireWorkflow工作原理,设计与应用

    C)审批环节之后,创建一个需要人工介入的“审批”环节,可以选择“Human Task Activity”,命名为"ApproveActivity",并在活动中添加一个Task,名为"ApproveTask"。D)结束环节最后,添加一个结束节点,通过工具栏...

    JBPM JAR包1

    **JBPM JAR包1详解** JBPM,全称Java Business Process Management,是一...总的来说,"JBPM JAR包1"是构建基于JBPM的工作流应用的基础,通过理解和掌握其组件及使用方法,开发者能够轻松实现业务流程的自动化和优化。

    JBPM5权威指南

    14.1.1 使用Helper方法创建你的session 92 14.1.2 断言 92 14.1.3测试与外部服务的结合 93 14.1.4 配置持久化 94 14.2 调试 94 14.2.1 流程实例视图 95 14.2.2 人工任务视图 96 14.2.3 核查视图 96 第十五章 流程...

    jbpm 接口,表结构说明

    2. **Human Task Service API**:专为人类参与的任务交互设计,提供任务查询、领取、完成等操作。 - `TaskQuery`:任务查询接口,可按多种条件(如任务名、负责人等)查询任务。 - `Task`:表示一个待办任务,包含...

    一个简单的jbpm 请假流程

    同时,人工作流(Human Task)是流程中不可或缺的部分,例如请假申请需要经理审批,这就涉及到任务的分配、领取和完成。 5. **jbpm事件和监听器**:jbpm允许设置事件监听器来响应流程中的特定事件,比如任务完成、...

    jbpm4.3官方例子及文档

    每个示例通常包含流程定义文件、启动代码以及解释文档,通过阅读和运行这些示例,你可以深入理解jbpm4.3的使用方法。 最后,文档部分提供了详尽的指南和API参考,帮助开发者了解jbpm4.3的各个组件和接口。这些文档...

    JBPM源码包,包含JBPM的源代码

    - **jbpm-human-task**: 实现了对人类任务的管理,包括任务的创建、分配、执行和完成等操作,支持多种任务服务实现,如JMS、EJB等。 - **jbpm-services**: 提供了服务层接口,如RESTful API,便于应用程序与JBPM...

    当你的应用程序有新版本可用时,通知用户并提示他们升级.zip

    创建一个URL对象,指向你的服务器上提供版本信息的API,然后使用URLSession的数据任务来获取响应。例如: ```swift let url = URL(string: "https://yourserver.com/updates")! let task = URLSession.shared.data...

    jbpm5_用户指南

    - **元素与属性**:详细介绍各元素的特性和使用方法。 #### 十、设计器 - **安装步骤**:提供了安装设计器的具体指导。 - **使用教程**:教授如何利用设计器进行流程设计。 #### 十一、控制台 - **安装与配置**:...

    kie-drools-wb安装所需jar包

    3. **jBPM**: 如果kie-drools-wb包含了jBPM组件,那么会有jBPM相关的jar包,如jbpm-flow、jbpm-persistence、jbpm-human-task等,用于工作流程的定义和执行。 4. **Guvnor**: Guvnor(现在称为KIE Workbench)是kie...

    swift-Flamingo-简约的HackerNews阅读器

    在Flamingo-master这个压缩包中,包含了整个项目的源代码、资源文件以及项目配置,开发者可以通过研究这个项目来学习如何使用Swift构建实际的应用程序,同时了解Hacker News API的使用方法。这对于想要提升Swift开发...

    Laravel开发-laraturksoap

    对于更复杂的操作,如创建 HIT(Human Intelligence Task)或批准已完成的任务,你可以查阅 `laraturksoap` 的文档,了解如何调用对应的方法。 **4. 创建 MTurk 请求** `laraturksoap` 包封装了 MTurk SOAP API,...

    swift-两行代码加入启动广告页Swift3.0异步加载

    首先,我们需要在`application(_:didFinishLaunchingWithOptions:)`方法中创建`LaunchADView`实例,并将其添加到窗口的根视图控制器上: ```swift func application(_ application: UIApplication, ...

    人脸识别在Android平台下的研究与实现 (2).pdf

    3.1 图像获取:使用Android的Camera API或SurfaceView捕获视频流,实时处理每一帧图像。 3.2 人脸检测:将捕获的图像输入到选定的人脸检测算法,获取人脸框位置。 3.3 特征提取与匹配:对检测到的人脸进行特征提取...

    keychain-touchid-prompt:如何在您的应用中使用 iOS8 Touch ID 提示(手指或大头针)的示例

    本文将深入探讨如何在C#环境中利用iOS8及更高版本的Keychain Services API来实现Touch ID提示,让用户可以选择使用指纹或传统密码(PIN码)进行身份验证。 首先,理解Keychain Services API是至关重要的。Keychain...

    dx修复工具

    This design is to provide an easy operation for some labour sensitive users, and this style is easy to be integrated in other games or software to achieve the goal of human-involved free repairing....

Global site tag (gtag.js) - Google Analytics