0 Replies Latest reply on Jul 4, 2014 9:23 AM by Raja Vashishtha

    jbpm process instance throws NPE while getting Workflowinstance variable from db

    Raja Vashishtha Newbie

      I have a jbpm5.3 web panel and what i am trying to do it to create web services in servlets by manipulating mysql database.

      Now i have integrated the jBPM libs into my code and everything seems to be working fine except creation of a new ProcessInstance.

      When i create a new processInstance from already built WebSite, the workflow works fine if i complete a task from my code. But when i create a new Process Instance from my code it works fine on my side but throws a NullPointer on Web.

      I am using following piece of code to create New Process Instance

       

      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;
      }
      

      When i execute this code it works fine on my end, all data is inserted into the tables. But when created process is accessed to web panel it gives NPE at

      ProjectFormData projectFormData=(ProjectFormData) process.getVariable("projectFormData");
      System.out.println(projectFormData.getProjectFormDataMap()); <- NullPointer