Lingaiah Sundari [
https://community.jboss.org/people/lingaiah.sundari] created the
discussion
"Re: How to integrate a Web Application with JBPM?"
To view the discussion, visit:
https://community.jboss.org/message/752576#752576
--------------------------------------------------------------
Hi Srikanthan,
I have done the web application interaction with JBPM. In our example It was covered
around 70% of your requirement.
We can have the helper class to call the JBPM process or with in the servlet we can
have the call to JBPM process. And also covered Human tasks and actions .
sample code (Servlet) :
***protected
**
* **void** processRequest(HttpServletRequest request, HttpServletResponse response)
**throws** ServletException, IOException {
response.setContentType(
"text/html;charset=UTF-8");PrintWriter out = response.getWriter();
**try** {String action = request.getParameter(
"action");
**if** (action.equals("CreateProcess")) {
UserTransaction ut = (UserTransaction)
**new** InitialContext().lookup( "java:comp/UserTransaction" );ut.begin();
//StatefulKnowledgeSession ksession = JbpmAPIUtil.getSession();
// JPAWorkingMemoryDbLogger logger =
**new** JPAWorkingMemoryDbLogger (ksession);
/*Map<String, Object> params = new HashMap<String,
Object>();params.put("priority", "High");
params.put("modelNumber", "123");
params.put("quantity", "66"); */
KnowledgeRuntimeLoggerFactory.+newConsoleLogger+(
ksession);
ksession.getWorkItemManager().registerWorkItemHandler("Log", **new**
SystemOutWorkItemHandler());
ksession.getWorkItemManager().registerWorkItemHandler(
"Email", **new**
EmailWorkItemHandler("20.139.68.11","86400","lsundari","Shiva@2012"));
//ksession.getWorkItemManager().registerWorkItemHandler("Human Task", new
WSHumanTaskHandler());
CustomerProfile customerProfile =
**new**
CustomerProfile(request.getParameter("fName"),request.getParameter("lName"),Integer.+parseInt+(request.getParameter("age")),Integer.+parseInt+(request.getParameter("aLimit")),Integer.+parseInt+(request.getParameter("mSalary")),request.getParameter("eMail"),"TODO","TODO");Map<String,
Object> params =
**new** HashMap<String, Object>();params.put(
"customerProfile", customerProfile);params.put(
"employee", "lingaiah");params.put(
"reason", "CC Review Process");
ksession.startProcess("com.sample.bpmn.creditcardissueprocess",params);Thread.+sleep+(200);
ksession.fireAllRules();Thread.+sleep+(200);
ut.commit();
//logger.dispose();
request.setAttribute(
"processVariable", processInstanceVarible());request.setAttribute(
"message", "Process Created!");request.setAttribute(
"processList", processInstances());
RequestDispatcher rD = request.getRequestDispatcher(
"adminuser.jsp");rD.forward(request, response);
}
**else** **if**(action.equals("listtasks")) {String user =
request.getParameter(
"user");
//UserTransaction ut = (UserTransaction) new InitialContext().lookup(
"java:comp/UserTransaction" );
/** Get all the task assigned to 'user'
*/
java.util.List<TaskSummary> tasks = JbpmAPIUtil.+getAssignedTasks+(user);
TaskSummary task =
**null**;
BlockingTaskOperationResponseHandler responseHandler =
**null**;ContentData contentData =
**null**;Map data =
**new** HashMap();
**for** (TaskSummary taskSummary : tasks) { System.
++out++.println(taskSummary.getId() + " : " + taskSummary.getActualOwner());}
request.setAttribute(
"tasks",tasks);request.setAttribute(
"user",user);
request.setAttribute(
"processList", processInstances());request.setAttribute(
"processVariable", processInstanceVarible());RequestDispatcher rD =
request.getRequestDispatcher(
"taskrequest.jsp");rD.forward(request, response);
}
**else** **if**(action.equals("Submit")) {
UserTransaction ut = (UserTransaction)
**new** InitialContext().lookup( "java:comp/UserTransaction" );ut.begin();
String user = request.getParameter(
"user");
/** Get all the task assigned to 'user'
*/
CustomerProfile data =
**new** CustomerProfile();
/*data.put("priority",request.getParameter("priority"));data.put("modelNumber",request.getParameter("modelNumber"));
data.put("quantity",request.getParameter("quantity"));*/
data.setfName(request.getParameter(
"fName"));data.setlName(request.getParameter(
"lName"));data.setAppliedLimit(Integer.+parseInt+(request.getParameter(
"aLimit")));data.setMonthlySalary(Integer.+parseInt+(request.getParameter(
"mSalary")));data.seteMail(request.getParameter(
"eMail"));System.
++out++.println("lingarao :
"+request.getParameter("reviewStatus"));data.setReviewStatus(request.getParameter(
"reviewStatus"));
Long processId =
**new** Long((String)request.getParameter("processId"));
// StatefulKnowledgeSession ksession = JbpmAPIUtil.getSession();
// JPAWorkingMemoryDbLogger logger = new JPAWorkingMemoryDbLogger (ksession);
// processInstaceLogger = new JPAProcessInstanceDbLog (ksession.getEnvironment());
WorkflowProcessInstance process = (WorkflowProcessInstance)
ksession.getProcessInstance(processId);((CustomerProfile)process.getVariable(
"customerProfile")).setReviewStatus(request.getParameter("reviewStatus"));;
**if**((request.getParameter("reviewStatus").equalsIgnoreCase("Accepted"))){
((CustomerProfile)process.getVariable(
"customerProfile")).setCardIssueStatus(" Accepted by manual process ,
submitted to CC fulfillment process.");}
**else** {((CustomerProfile)process.getVariable(
"customerProfile")).setCardIssueStatus(" Rejeected by manual process , sent
status email");}
**long** taskId = **new**
Long(request.getParameter("taskId")).longValue();String taskStatus =
request.getParameter(
"taskStatus");
**if** (!taskStatus.equals("Completed"))JbpmAPIUtil.+completeTask+(taskId, data,
user);
// request.setAttribute("processList", processInstances());
ut.commit();
//logger.dispose();
//processInstaceLogger.dispose();
//request.setAttribute("tasks",tasks);
request.setAttribute(
"processVariable", processInstanceVarible());RequestDispatcher rD =
request.getRequestDispatcher(
"index.jsp");rD.forward(request, response);
}
**else** **if**(action.equals("taskinit")){
request.setAttribute(
"taskId",request.getParameter("taskId"));request.setAttribute(
"taskStatus",request.getParameter("taskStatus"));request.setAttribute(
"user",request.getParameter("user"));request.setAttribute(
"processId",request.getParameter("processId"));
request.setAttribute(
"processVariable", processInstanceVarible());
// request.setAttribute("processList", processInstances());
RequestDispatcher rD = request.getRequestDispatcher(
"initialrequest.jsp");rD.forward(request, response);
}
}
**catch**(Exception e){out.println(
"Error:"+ e.getMessage().toString());}
**finally** {out.close();
}
-Regards,
Lingaiah.S
--------------------------------------------------------------
Reply to this message by going to Community
[
https://community.jboss.org/message/752576#752576]
Start a new discussion in jBPM Development at Community
[
https://community.jboss.org/choose-container!input.jspa?contentType=1&...]