|
Disclaimer:
These pages about different languages / apis / best practices were mostly jotted down quckily and rarely corrected afterwards. The languages / apis / best practices may have changed over time (e.g. the facebook api being a prime example), so what was documented as a good way to do something at the time might be outdated when you read it (some pages here are over 15 years old). Just as a reminder. jBPM developer notes; creating business processes in javaBusiness Process Management using jBPM in Java
jBOSS (separate page)using jBPM with regular jBoss server (not starter kit)InstallingYou need to copy the follwing libs:using jBPM starter kit 3.1(this stuff might or might not apply to earlier/later versions)Installing(using Eclipse 3.1.1)Note that the jBPM designer will complain with "An error occurred. See error log for details", if you already have jBPM 3.0 projects in your workspace (even if you try to create a new project I created a new workspace and then it worked fine. missing hibernate/hbm2ddlSeems like one must add the hibernate.jar as external library to the project in eclipseAssign a task node to a userSimpleProcessTest.java:package com.sample; processdefinition.xml: <?xml version="1.0" encoding="UTF-8"?> Get User taskspublic ArrayList getUserTasks(String uid){ List myTasks =null; JbpmContext jbpmContext = jbpmConfiguration.createJbpmContext(); try{ TaskMgmtSession taskMgmtSession = jbpmContext.getTaskMgmtSession(); myTasks = taskMgmtSession.findTaskInstances("donald"); } finally { jbpmContext.close(); } //create an ArrayList ArrayList returnList = new ArrayList(); //build up something we can return over a remote interface for (Iterator iter = myTasks.iterator(); iter.hasNext();) { TaskInstance myTmp = (TaskInstance) iter.next(); TaskTO myTask = new TaskTO(); myTask.name = myTmp.getName(); myTask.description = myTmp.getDescription(); myTask.id = myTmp.getId(); myTask.dueDate = myTmp.getDueDate(); myTask.startDate = myTmp.getStart(); returnList.add( myTask ); } //note that the List could not be transferred via a remote interface (due to connection to hibernate), //so you havo create a transfer object with the data you want to return return returnList; } SwimlanesUseful thread on Swimlanes, assignment of actorshttp://www.jboss.com/index.html?module=bb&op=viewtopic&t=74156 How to instantiate the swimlanes: //This ensures that all swimlanes are initialized and available for reporting and reassignment immediately. //If we don't initialize them up front, they won't be created until a task calls for them. Map swimlanes = processDefinition.getTaskMgmtDefinition().getSwimlanes(); Iterator itr = swimlanes.keySet().iterator(); log.debug(logPrefix + ".instantiateProcess: Start looping over Swimlanes..."); while(itr.hasNext()) { String sSwimlaneName = (String) itr.next(); log.debug(logPrefix + ".instantiateProcess: found: " + sSwimlaneName); Swimlane swimlane = (Swimlane)swimlanes.get( sSwimlaneName ); SwimlaneInstance swi = processInstance.getTaskMgmtInstance().getInitializedSwimlaneInstance( new ExecutionContext(processInstance.getRootToken()), swimlane); } log.debug(logPrefix + ".instantiateProcess: ....end looping over Swimlanes"); Start/end a taskInteger taskinstanceid = new Integer(23432); try{ TaskMgmtSession taskMgmtSession = jbpmContext.getTaskMgmtSession(); TaskInstance myTask = taskMgmtSession.loadTaskInstance( taskinstanceid.longValue() ); myTask.start(uid); } catch(Exception e) { log.error(logPrefix + "processTask exception thrown : " + e); } finally { jbpmContext.close(); } Setting and getting variables//start the task try{ TaskMgmtSession taskMgmtSession = jbpmContext.getTaskMgmtSession(); TaskInstance myTask = taskMgmtSession.loadTaskInstance( taskinstanceid.longValue() ); //pass on any arguments to the Actions Token token = myTask.getToken(); ProcessInstance processInstance = token.getProcessInstance(); ContextInstance contextInstance = processInstance.getContextInstance(); contextInstance.setVariable("inputdataActivity", data); myTask.start(userid); } catch(Exception e) { log.error(logPrefix + "processTask exception thrown : " + e); } finally { jbpmContext.close(); }in for example action handler we fetch the data: public void execute(ExecutionContext executionContext) throws Exception { //fetch any input data (see WorkManagerBean for more info) String varName="inputdataActivity"; ContextInstance contextInstance = executionContext.getContextInstance(); Activity myActivity = (Activity) contextInstance.getVariable(varName); if(myActivity != null) log.debug(">>>>Tried fetching variable \""+ varName2 + "\", value="+ myActivity.approved); //do stuff } Decision handler - example<decision name="Someone approved?"> <handler class='somewhere.workflows.CommonHandlers$DecisionOnEnd'> <leaveReject>applicant rejected</leaveReject> <leaveOk>applicant approved</leaveOk> </handler> <transition name="applicant approved" to="HP approve"></transition> <transition name="applicant rejected" to="rejected"></transition> </decision> public static class DecisionOnEnd implements org.jbpm.graph.node.DecisionHandler { //hmm? must this always be implemented private static final long serialVersionUID = 1L; //will be set with the name of the transition to go if user rejects private String leaveReject; //will be set with the name of the transition to go if user approves private String leaveOk; public String decide(ExecutionContext executionContext) throws Exception { log.debug(logPrefix +"DecisionOnEnd: leaveReject: "+ leaveReject); log.debug(logPrefix +"DecisionOnEnd: leaveOk: "+ leaveOk); //which way to go, as default we reject String exitTransition = leaveReject; try { //fetch input data from the processInstance variables (see WorkManagerBean for more info) String varName="inputdataActivity"; ContextInstance contextInstance = executionContext.getContextInstance(); Activity myActivity = (Activity) contextInstance.getVariable(varName); if(myActivity != null) { log.debug(logPrefix +"DecisionOnEnd: Reading processInstance variable to determine if approved or not. \""+ varName + "\", value="+ myActivity.bApproved); //if approved we go to the transition defined in leaveOk if(myActivity.bApproved) exitTransition = leaveOk; }else{ log.error(logPrefix +"DecisionOnEnd: there data regarding if the task was approved or rejected is null! (i.e. "+ varName + "=null). The task is rejected since we have to do something"); } } catch (Exception e) { log.error(logPrefix +"DecisionOnEnd: Catched exception when trying to read variable, " + "the task is rejected since we have to do something e="+e); } log.debug(logPrefix +"DecisionOnEnd: Attempt to leave on the transition: " + exitTransition ); return exitTransition; } } Action handler - example<task-node name="Someone approve"> <task swimlane="applicant"> <controller> <variable name="approved"/> </controller> <event type='task-end'> <action class='somewhere.workflows.Process$ApplicantOnEnd'> </action> </event> </task> <transition name="applicant finished" to="Applicant approved?"></transition> </task-node> /** * Process data after someone has verified if the data is correct or not */ public static class ApplicantOnEnd implements ActionHandler { private static final long serialVersionUID = 1L; public void execute(ExecutionContext executionContext) throws Exception { //fetch any input data try { String varName="inputdataActivity"; ContextInstance contextInstance = executionContext.getContextInstance(); Activity myActivity = (Activity) contextInstance.getVariable(varName); if(myActivity != null) log.debug(">>>>Tried fetching variable \""+ varName + "\", value="+ myActivity.bApproved); } catch (Exception e) { log.error(logPrefix +"ApplicantOnEnd: Could not read variable. e="+e); } //do stuff //executionContext.leaveNode(leaveReject); } } using jBPM starter kit 3.0.1(this stuff might or might not apply to earlier/later versions)When starting jBPM: Unsupported major.minor version 49The version of jBPM probably compiled with java 5 and your JAVA_HOME points to 1.4.Set JAVA_HOME to point to the jdk for java 5 (note: it should not point to the jre, have to be jdk) errors about "socket creation error"http://www.jboss.com/index.html?module=bb&op=viewtopic&t=74234:...Alright, here it goes: you're looking in the right place. In hsqldb-ds.xml, near the start, comment the section that reads "for in-process persistent db" and uncomment "for tco connection". Also, near the end, comment the section "this mbean can be used when using in-process persistent db" and uncomment "this mbean should be used only when using tcp connection". Please note that this opens a security hole so you shouldn't deploy such a data source in production. In addition, you shouldn't need to do this if you are accessing the database from within JBoss. errors about mchange c3p0 etcIt uses that for the jdbc connections, you can disable it by comment out the following lines in hibernate.properties#hibernate.c3p0.min_size=1 #hibernate.c3p0.max_size=3or download the jar and put it in your classpath. Starting hsqldb guijava -cp hsqldb.jar org.hsqldb.util.DatabaseManager or go to http://localhost:8080/jmx-console/HtmlAdaptor?action=inspectMBean&name=jboss%3Aservice%3DHypersonic and invoke startDatabaseManager() Configuring mysql for the basic sample processtodo Getting a task list for a user(not tested)//open a new persistence session JbpmSession jbpmSession = jbpmSessionFactory.openJbpmSession(); TaskMgmtSession taskMgmtSession = null; taskMgmtSession = new TaskMgmtSession(jbpmSession); List myTasks = taskMgmtSession.findTaskInstances("someuser"); More programming related pages |
|