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>