[jBPM] - Evaluation sample help
by Derek Pang
Derek Pang [http://community.jboss.org/people/delbacca] created the discussion
"Evaluation sample help"
To view the discussion, visit: http://community.jboss.org/message/635655#635655
--------------------------------------------------------------
Hi,
I want to ask the difference between the 2 versions of the Evaluation sample project I currently have. One came default with the Eclipse installation and the other I downloaded (from http://sourceforge.net/projects/jbpm/files/jBPM%205/jbpm-5.1.0.Final/ http://sourceforge.net/projects/jbpm/files/jBPM%205/jbpm-5.1.0.Final/)
The downloaded one doesnt seem to do anything whereas the default one creates the tasks for you to execute in the console.
In the User task components, there scripts in the entry value field whereas theres nothing in the downloaded one. Having said that theres alot more code in the Java class file in the downloaded one, so I thought its all scripted there. But it doesnt generate the task, the code is below.
Does the top version execute the task automatically through code?
downloaded version. - nothign in the user task component
----------------------------------------------
package org.jbpm.examples.evaluation;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import org.drools.KnowledgeBase;
import org.drools.SystemEventListenerFactory;
import org.drools.builder.KnowledgeBuilder;
import org.drools.builder.KnowledgeBuilderFactory;
import org.drools.builder.ResourceType;
import org.drools.io.ResourceFactory;
import org.drools.logger.KnowledgeRuntimeLogger;
import org.drools.logger.KnowledgeRuntimeLoggerFactory;
import org.drools.runtime.StatefulKnowledgeSession;
import org.jbpm.process.workitem.wsht.WSHumanTaskHandler;
import org.jbpm.task.query.TaskSummary;
import org.jbpm.task.service.TaskClient;
import org.jbpm.task.service.mina.MinaTaskClientConnector;
import org.jbpm.task.service.mina.MinaTaskClientHandler;
import org.jbpm.task.service.responsehandlers.BlockingTaskOperationResponseHandler;
import org.jbpm.task.service.responsehandlers.BlockingTaskSummaryResponseHandler;
/**
* This is a sample file to launch a process.
*/
public class EvaluationExample2 {
public static final void main(String[] args) {
try {
// load up the knowledge base
KnowledgeBase kbase = readKnowledgeBase();
StatefulKnowledgeSession ksession = kbase.newStatefulKnowledgeSession();
KnowledgeRuntimeLogger logger = KnowledgeRuntimeLoggerFactory.newThreadedFileLogger(ksession, "test", 1000);
ksession.getWorkItemManager().registerWorkItemHandler("Human Task", new WSHumanTaskHandler());
// start a new process instance
Map<String, Object> params = new HashMap<String, Object>();
params.put("employee", "krisv");
params.put("reason", "Yearly performance evaluation");
ksession.startProcess("com.sample.evaluation", params);
SystemEventListenerFactory.setSystemEventListener(new SystemEventListener());
TaskClient taskClient = new TaskClient(new MinaTaskClientConnector("MinaConnector",
new MinaTaskClientHandler(SystemEventListenerFactory.getSystemEventListener())));
taskClient.connect("127.0.0.1", 9123);
Thread.sleep(1000);
// "krisv" executes his own performance evaluation
BlockingTaskSummaryResponseHandler taskSummaryHandler = new BlockingTaskSummaryResponseHandler();
taskClient.getTasksAssignedAsPotentialOwner("krisv", "en-UK", taskSummaryHandler);
TaskSummary task1 = taskSummaryHandler.getResults().get(0);
System.out.println("Krisv executing task " + task1.getName() + "(" + task1.getId() + ": " + task1.getDescription() + ")");
BlockingTaskOperationResponseHandler taskOperationHandler = new BlockingTaskOperationResponseHandler();
taskClient.start(task1.getId(), "krisv", taskOperationHandler);
taskOperationHandler.waitTillDone(1000);
taskOperationHandler = new BlockingTaskOperationResponseHandler();
taskClient.complete(task1.getId(), "krisv", null, taskOperationHandler);
taskOperationHandler.waitTillDone(1000);
Thread.sleep(1000);
// "john", part of the "PM" group, executes a performance evaluation
taskSummaryHandler = new BlockingTaskSummaryResponseHandler();
List<String> groups = new ArrayList<String>();
groups.add("PM");
taskClient.getTasksAssignedAsPotentialOwner("john", groups, "en-UK", taskSummaryHandler);
TaskSummary task2 = taskSummaryHandler.getResults().get(0);
System.out.println("John executing task " + task2.getName() + "(" + task2.getId() + ": " + task2.getDescription() + ")");
taskOperationHandler = new BlockingTaskOperationResponseHandler();
taskClient.claim(task2.getId(), "john", groups, taskOperationHandler);
taskOperationHandler.waitTillDone(1000);
taskOperationHandler = new BlockingTaskOperationResponseHandler();
taskClient.start(task2.getId(), "john", taskOperationHandler);
taskOperationHandler.waitTillDone(1000);
taskOperationHandler = new BlockingTaskOperationResponseHandler();
taskClient.complete(task2.getId(), "john", null, taskOperationHandler);
taskOperationHandler.waitTillDone(1000);
Thread.sleep(1000);
// "mary", part of the "HR" group, delegates a performance evaluation
taskSummaryHandler = new BlockingTaskSummaryResponseHandler();
groups = new ArrayList<String>();
groups.add("HR");
taskClient.getTasksAssignedAsPotentialOwner("mary", groups, "en-UK", taskSummaryHandler);
TaskSummary task3 = taskSummaryHandler.getResults().get(0);
System.out.println("Mary delegating task " + task3.getName() + "(" + task3.getId() + ": " + task3.getDescription() + ") to krisv");
taskOperationHandler = new BlockingTaskOperationResponseHandler();
taskClient.claim(task3.getId(), "mary", groups, taskOperationHandler);
taskOperationHandler.waitTillDone(1000);
taskOperationHandler = new BlockingTaskOperationResponseHandler();
taskClient.delegate(task3.getId(), "mary", "krisv", taskOperationHandler);
taskOperationHandler.waitTillDone(1000);
// "administrator" delegates the task back to mary
System.out.println("Administrator delegating task back to mary");
taskOperationHandler = new BlockingTaskOperationResponseHandler();
taskClient.delegate(task3.getId(), "Administrator", "mary", taskOperationHandler);
taskOperationHandler.waitTillDone(1000);
// mary executing the task
taskSummaryHandler = new BlockingTaskSummaryResponseHandler();
taskClient.getTasksAssignedAsPotentialOwner("mary", "en-UK", taskSummaryHandler);
TaskSummary task3b = taskSummaryHandler.getResults().get(0);
System.out.println("Mary executing task " + task3b.getName() + "(" + task3b.getId() + ": " + task3b.getDescription() + ")");
taskOperationHandler = new BlockingTaskOperationResponseHandler();
taskClient.start(task3b.getId(), "mary", taskOperationHandler);
taskOperationHandler.waitTillDone(1000);
taskOperationHandler = new BlockingTaskOperationResponseHandler();
taskClient.complete(task3b.getId(), "mary", null, taskOperationHandler);
taskOperationHandler.waitTillDone(1000);
Thread.sleep(1000);
logger.close();
System.exit(0);
} catch (Throwable t) {
t.printStackTrace();
}
}
private static KnowledgeBase readKnowledgeBase() throws Exception {
KnowledgeBuilder kbuilder = KnowledgeBuilderFactory.newKnowledgeBuilder();
kbuilder.add(ResourceFactory.newClassPathResource("evaluation/Evaluation2.bpmn"), ResourceType.BPMN2);
return kbuilder.newKnowledgeBase();
}
private static class SystemEventListener implements org.drools.SystemEventListener {
public void debug(String arg0) {
}
public void debug(String arg0, Object arg1) {
}
public void exception(Throwable arg0) {
}
public void exception(String arg0, Throwable arg1) {
}
public void info(String arg0) {
}
public void info(String arg0, Object arg1) {
}
public void warning(String arg0) {
}
public void warning(String arg0, Object arg1) {
}
}
}
the default version - less code with scripts in the user task component.
---------------------------------------
package org.jbpm.examples.evaluation;
import java.util.HashMap;
import java.util.Map;
import org.drools.KnowledgeBase;
import org.drools.builder.KnowledgeBuilder;
import org.drools.builder.KnowledgeBuilderFactory;
import org.drools.builder.ResourceType;
import org.drools.io.ResourceFactory;
import org.drools.logger.KnowledgeRuntimeLogger;
import org.drools.logger.KnowledgeRuntimeLoggerFactory;
import org.drools.runtime.StatefulKnowledgeSession;
import org.jbpm.process.workitem.wsht.WSHumanTaskHandler;
public class EvaluationExample {
public static final void main(String[] args) {
try {
// load up the knowledge base
KnowledgeBase kbase = readKnowledgeBase();
StatefulKnowledgeSession ksession = kbase.newStatefulKnowledgeSession();
KnowledgeRuntimeLogger logger = KnowledgeRuntimeLoggerFactory.newThreadedFileLogger(ksession, "test", 1000);
ksession.getWorkItemManager().registerWorkItemHandler("Human Task", new WSHumanTaskHandler());
// start a new process instance
Map<String, Object> params = new HashMap<String, Object>();
params.put("employee", "krisv");
params.put("reason", "Yearly performance evaluation");
ksession.startProcess("com.sample.evaluation", params);
logger.close();
} catch (Throwable t) {
t.printStackTrace();
}
}
private static KnowledgeBase readKnowledgeBase() throws Exception {
KnowledgeBuilder kbuilder = KnowledgeBuilderFactory.newKnowledgeBuilder();
kbuilder.add(ResourceFactory.newClassPathResource("evaluation/Evaluation.bpmn"), ResourceType.BPMN2);
return kbuilder.newKnowledgeBase();
}
}
--------------------------------------------------------------
Reply to this message by going to Community
[http://community.jboss.org/message/635655#635655]
Start a new discussion in jBPM at Community
[http://community.jboss.org/choose-container!input.jspa?contentType=1&cont...]
13 years
[jBPM] - Re: How to access process variable in ftl file?
by Muthuraman Panneerselvam
Muthuraman Panneerselvam [http://community.jboss.org/people/pmuthuraman] created the discussion
"Re: How to access process variable in ftl file?"
To view the discussion, visit: http://community.jboss.org/message/636166#636166
--------------------------------------------------------------
Thanks Tihomir for the reply.
My java code to start the process has the below.
|
|
|
| Map<String, Object> params = new HashMap<String, Object>(); |
|
|
|
| params.put("policyId", "testingpolicyId"); |
|
|
|
|
|
|
|
|
| ksession.startProcess("voluntaryProcess", params); |
I have added the variable "policyId" in the variable definition property of my process.
http://community.jboss.org/servlet/JiveServlet/showImage/2-636166-17292/p... http://community.jboss.org/servlet/JiveServlet/downloadImage/2-636166-172...
I am using guvnor 5.1 and the designer version is 1.0.0.55.
When I tried to access my variable in the ftl file as ${policyId}, I am getting the below error.
freemarker.core.InvalidReferenceException: Expression policyId is undefined on line 19, column 18 in ApprovedTask.
freemarker.core.TemplateObject.assertNonNull(TemplateObject.java:124)
freemarker.core.Expression.getStringValue(Expression.java:118)
freemarker.core.Expression.getStringValue(Expression.java:93)
freemarker.core.DollarVariable.accept(DollarVariable.java:76)
freemarker.core.Environment.visit(Environment.java:209)
freemarker.core.MixedContent.accept(MixedContent.java:92)
freemarker.core.Environment.visit(Environment.java:209)
freemarker.core.Environment.process(Environment.java:189)
freemarker.template.Template.process(Template.java:237)
org.jbpm.integration.console.forms.AbstractFormDispatcher.processTemplate(AbstractFormDispatcher.java:116)
org.jbpm.integration.console.forms.TaskFormDispatcher.provideForm(TaskFormDispatcher.java:119)
org.jbpm.integration.console.forms.FormDispatcherComposite.provideForm(FormDispatcherComposite.java:50)
org.jboss.bpm.console.server.FormProcessingFacade.provideForm(FormProcessingFacade.java:203)
org.jboss.bpm.console.server.FormProcessingFacade.renderTaskUI(FormProcessingFacade.java:125)
sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
java.lang.reflect.Method.invoke(Method.java:597)
org.jboss.resteasy.core.MethodInjectorImpl.invoke(MethodInjectorImpl.java:117)
org.jboss.resteasy.core.ResourceMethod.invokeOnTarget(ResourceMethod.java:260)
org.jboss.resteasy.core.ResourceMethod.invoke(ResourceMethod.java:232)
org.jboss.resteasy.core.ResourceMethod.invoke(ResourceMethod.java:166)
org.jboss.resteasy.core.DispatcherUtilities.getJaxrsResponse(DispatcherUtilities.java:142)
org.jboss.resteasy.core.SynchronousDispatcher.invoke(SynchronousDispatcher.java:356)
org.jboss.resteasy.core.SynchronousDispatcher.invoke(SynchronousDispatcher.java:173)
org.jboss.resteasy.plugins.server.servlet.HttpServletDispatcher.service(HttpServletDispatcher.java:93)
org.jboss.resteasy.plugins.server.servlet.HttpServletDispatcher.service(HttpServletDispatcher.java:68)
javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
org.jboss.bpm.console.server.util.GWTJsonFilter.doFilter(GWTJsonFilter.java:59)
org.jboss.web.tomcat.filters.ReplyHeaderFilter.doFilter(ReplyHeaderFilter.java:96)
Can you please let me know what is wrong? Please let me know if you need any other information.
--------------------------------------------------------------
Reply to this message by going to Community
[http://community.jboss.org/message/636166#636166]
Start a new discussion in jBPM at Community
[http://community.jboss.org/choose-container!input.jspa?contentType=1&cont...]
13 years