2014-07-04 59 views
0

此前獲得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 :(
請人幫助我。

回答

1

的區別可能與事務分界的不同有關,更具體地說,只要流程實例在事務中處於活動狀態,它就與流程引擎「連接」並始終保持最新幷包含所有內部信息。事務完成,流程實例s是「斷開」的並且包含信息的快照,因爲它在交易結束時(充當DTO)。

看來在這裏,你正從中獲取「projectFormData」變量的流程實例現在已斷開連接,並且不包含該變量(可能是因爲它已過時?)。

該解決方案可以爲下列之一: - 確保你的地方刷新斷開的進程實例(使用ksession.getProcessInstance(..),以確保您有 最新版本的呼叫前右 - 請確保調用的getVariable( ..)在你從中獲得流程實例的同一個事務中,所以它仍然連接。

+0

我試過在單個事務中使用它,但仍然發現'projectFormData'沒有在數據庫中保存。 'processData' MAP中的所有值都保存在processInstanceInfo中,除了'projectFormData'和'rejectStatus'。 這是在web面板中使用的相同代碼。 – Raja

1

您正在獲取此NPE,因爲您正在嘗試獲取的某些流程變量在processinstanceinfo表中不可用。 process .getVariable(「projectFormData」); 現在這返回NULL,因爲它沒有得到保存在過程變量可能是因爲其他一些方法想要這個是某種填充對象而不是僅僅是新實例化的對象。

相關問題