此前獲得Workflowinstance可變我已經問的jBPM的ProcessInstanceInfo和WorkItemInfo這裏
Need to know Class of a Byte Array saved in MySQL Database
我現在已經集成jBPM的庫到我的代碼,一切似乎除了創建工作正常一個新的ProcessInstance。
當我從已經建好的網站創建一個新的processInstance時,如果我從我的代碼完成一個任務,工作流程正常工作。但是當我從我的代碼中創建一個新的流程實例時,它在我身邊正常工作,但在Web上拋出一個NullPointer。
我使用下面這段代碼來創建新的流程實例
的jBPM流程實例拋出NPE而從數據庫
public Long startProject(ProjectDTO projectDto, UserDTO userInfo) {
ApplicationContext context = new FileSystemXmlApplicationContext(
ServletContextHolder.getContext().getRealPath("/WEB-INF")
+ "/dispatcher-servlet.xml");
SessionFactory sessionFactory = (SessionFactory) context
.getBean("sessionFactory");
UserinfoHBM userinfoHBM = new UserinfoHBM(sessionFactory);
WorkflowHBM workflowHBM = new WorkflowHBM(sessionFactory);
TemplateHBM templateHBM = new TemplateHBM(sessionFactory);
Template template = templateHBM.getTemplateById(Integer
.parseInt(projectDto.getTemplateId()));
Map<String, Object> processData = new HashMap<String, Object>();
processData.put("Initiator", userInfo.getUsername());
UserInfo userInfoReq = userinfoHBM.getUserById(Integer
.parseInt(userInfo.getRequester()));
processData.put("Requester", userInfoReq.getFirst_name());
List<String> requesterEmail = new ArrayList<String>();
requesterEmail.add(userInfoReq.getEmail());
processData.put("RequesterEmail", requesterEmail);
UserInfo userInfoSup = userinfoHBM.getUserById(Integer
.parseInt(userInfo.getSupplier()));
processData.put("Supplier", userInfoSup.getFirst_name());
List<String> supplierEmail = new ArrayList<String>();
supplierEmail.add(userInfoSup.getEmail());
processData.put("SupplierEmail", supplierEmail);
UserInfo userInfoMan = userinfoHBM.getUserById(Integer
.parseInt(userInfo.getManager()));
processData.put("Manager", userInfoMan.getFirst_name());
List<String> managerEmail = new ArrayList<String>();
managerEmail.add(userInfoMan.getEmail());
processData.put("ManagerEmail", managerEmail);
List<String> initiatorEmail = new ArrayList<String>();
initiatorEmail.add(userInfo.getEmail());
processData.put("initiatorEmail", initiatorEmail);
Workflow workflow = workflowHBM.getWorkflow(template.getWorkflow()
.getWorkflow_id());
Long processId = startProcess(workflow, processData,
userInfo.getUsername(), projectDto.getName(),
projectDto.getUniqueProjectRefId());
return processId;
}
和
public Long startProcess(Workflow workflow,
Map<String, Object> processData, String userName,
String project_name, String uniqueProRefNo) {
// TODO Auto-generated method stub
Long processId = new Long(0);
try {
Boolean status = false;
Map<String, String> taskTypeMap = new HashMap<String, String>();
Map<String, ProcessTaskData> processTaskDataMap = new HashMap<String, ProcessTaskData>();
Map<String, WorkflowTask> workflowTaskMap = new HashMap<String, WorkflowTask>();
for (WorkflowTask workflowTask : workflow.getWorkflow_taskList()) {
ProcessTaskData processTaskData = new ProcessTaskData();
processTaskData.setProjectName(project_name);
processTaskData.setProjectUniNumber(uniqueProRefNo);
processTaskData.setTaskType(workflowTask.getTask_type());
processTaskData.setTaskId(workflowTask.getTask_id());
// processTaskData.setAssign(" User/Group Name");
processTaskData.setSubassign(workflowTask
.getDianamicAssimentGroup());
taskTypeMap.put(workflowTask.getTask_name(),
workflowTask.getTask_type());
if (workflowTask.getTask_type().equalsIgnoreCase("survey")) {
List<String> email = new ArrayList<String>();
email.add(workflowTask.getSendSurveyToemail());
processTaskData.setSurveyEmail(email);
}
processTaskDataMap.put(workflowTask.getTask_name(),
processTaskData);
if ("parallel".equalsIgnoreCase(workflowTask.getTask_Mode())) {
workflowTaskMap.put(workflowTask.getTask_name(),
workflowTask);
}
if (workflowTask.getTask_type().equalsIgnoreCase("approve")) {
status = true;
}
if (workflowTask.getTask_type().equalsIgnoreCase("survey")) {
List<String> email = new ArrayList<String>();
email.add(workflowTask.getSendSurveyToemail());
processTaskData.setSurveyId(workflowTask.getSurveyForm()
.getSurve_from_Id());
processTaskData.setSurveyEmail(email);
}
if (workflowTask.getTask_type().equalsIgnoreCase("email")) {
List<String> email = new ArrayList<String>();
// email.add();
List<EmailListsItems> items = workflowTask
.getEmailListsItems();
for (EmailListsItems e : items) {
email.add(e.getName());
}
processTaskData.setEmailList_EmailTask(email);
}
// workflowTaskMap
}
UserTransaction ut = (UserTransaction) new InitialContext()
.lookup("java:comp/UserTransaction");
ut.begin();
StatefulKnowledgeSession ksession = JbpmAPIUtil.getSession();
processData.put("workflowTaskMap", workflowTaskMap);
processData.put("taskTypeMap", taskTypeMap);
processData.put("formComments", new ArrayList<String>());
processData.put("processTaskDataMap", processTaskDataMap);
processData.put("rejectStatus", true);
ProjectFormData projectFormData = new ProjectFormData();
projectFormData.setProjectFormDataMap(new HashMap());
projectFormData.setProjectFormTableMap(new HashMap());
projectFormData.setProjectSurveyFormMap(new HashMap());
processData.put("projectFormData", projectFormData);
CommandBasedWSHumanTaskHandler taskHandler = new CommandBasedWSHumanTaskHandler(
ksession);
ksession.getWorkItemManager().registerWorkItemHandler("Human Task",
taskHandler);
/*
* JPAWorkingMemoryDbLogger logger2 = new
* JPAWorkingMemoryDbLogger(ksession);
*/
ProcessInstance instance = ksession.startProcess(workflow
.getWorkflow_name().replaceAll(" ", ""), processData);
processId = instance.getId();
/* logger2.dispose(); */
ut.commit();
// Thread.sleep(2000);
while (status) {
List<TaskSummary> taskSummaryList = JbpmAPIUtil
.getAssignedTasks(userName);
for (TaskSummary taskSummary : taskSummaryList) {
if (taskSummary.getName() == null) {
continue;
}
if (taskSummary.getName().equalsIgnoreCase("InitiatorTask")
&& taskSummary.getProcessInstanceId() == processId) {
try {
JbpmAPIUtil
.completeTask(taskSummary.getId(),
(Map) processData
.get("projectFormDataMap"),
userName);
status = false;
} catch (InterruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
break;
}
}
}
} catch (Exception e) {
e.printStackTrace();
} finally {
}
return processId;
}
當我執行這個代碼,它工作正常,我的結束,所有的數據被插入放入表格中。 但是,當創建的進程被訪問到的網絡板它在
ProjectFormData projectFormData=(ProjectFormData) process.getVariable("projectFormData");
System.out.println(projectFormData.getProjectFormDataMap()); <- NullPointer
我停留在這個地方從幾天給NPE :(
請人幫助我。
我試過在單個事務中使用它,但仍然發現'projectFormData'沒有在數據庫中保存。 'processData' MAP中的所有值都保存在processInstanceInfo中,除了'projectFormData'和'rejectStatus'。 這是在web面板中使用的相同代碼。 – Raja