如何向Activiti BPM流程提交数据programitacaly

时间:2016-01-13 12:30:04

标签: java activiti bpm

我使用的是activiti BPM,我希望在没有Activiti explore的情况下运行我的bpm流程。我只有一个表单变量的用户任务。我需要帮助来使用java为该任务分配值 这是我的代码:

public class Application {

public static void main(String[] args) throws FileNotFoundException {

    String filename = "E:/Activiti/STS_workspace/Test/src/main/resources/diagrams/FinancialReportProcess.bpmn";

    ActivitiRule activitiRule = new ActivitiRule();

    // Create Activiti process engine
      ProcessEngine processEngine = ProcessEngineConfiguration
        .createStandaloneProcessEngineConfiguration()
        .setDatabaseType("postgres")
        .setJdbcUrl("jdbc:postgresql://localhost:5432/testActiviti")
        .setJdbcDriver("org.postgresql.Driver")
        .setJdbcUsername("postgres")
        .setJdbcPassword("postgres")
        .setDatabaseSchemaUpdate("true")
        .buildProcessEngine();

      // Get Activiti services
      RepositoryService repositoryService = processEngine.getRepositoryService();
      RuntimeService runtimeService = processEngine.getRuntimeService();

      // Deploy the process definition
      repositoryService.createDeployment()
        .addInputStream("financialReport.bpmn20.xml", new FileInputStream(filename)).deploy();

      // Start a process instance
        String procId = runtimeService.startProcessInstanceByKey("financialReport").getId();

        FormService formService = processEngine.getFormService();

        Map<String, String> formProperties = new HashMap<String, String>();
        formProperties.put("name", "activiti rocks!");


        // Get the first task
        TaskService taskService = processEngine.getTaskService();

        List<Task> tasks = taskService.createTaskQuery().taskCandidateGroup("accountancy").list();
        for (Task task : tasks) {

          System.out.println("Following task is available for accountancy group: " + task.getName());

          TaskFormData taskFormData = formService.getTaskFormData(task.getId());

          List<FormProperty> listFormProperty = taskFormData.getFormProperties();

          for(FormProperty formProperty : listFormProperty){
                 System.out.println(task.getId()+":"+task.getName()+"id:"+formProperty.getId());
                 System.out.println(task.getId()+":"+task.getName()+"name:"+formProperty.getName());
                 System.out.println(task.getId()+":"+task.getName()+"type:"+formProperty.getType().getName());
                 System.out.println(task.getId()+":"+task.getName()+"value:"+formProperty.getValue());

              }

          System.out.println("task is "+task.getId()+":"+task.getName()+":"+task.getAssignee()+":"+task.getDescription());
        }



}

}

1 个答案:

答案 0 :(得分:1)

好的以上是一个简单过程的示例在THIS IS THE PART YOU ARE INTERESTED IN I THINK

上检查具有此评论的部分
//Create the proces variables
     Map<String, Object> variables = new HashMap<String, Object>();
         variables.put("requester", userRequestingForAbsence); //User who wants timeOff
         variables.put("dateFrom", new Date(2015, 10, 10));
         variables.put("dateTo", new Date(2015, 11, 11));
         variables.put("group", groupDto);
         variables.put("organization", orgDto.getOrganizationId());
         variables.put("candidateApprover", p.getUserId());

         //Create the process instance
//Im using org.activiti.engine.RuntimeService
         ProcessInstance pi = runtimeService.startProcessInstanceByKey("myProcess", String.valueOf(orgDto.getOrganizationId()),variables);
         //Create Process Instance
         Assert.assertNotNull(pi);

         //Check inbox for approver 
         Task task = taskService.createTaskQuery()
                 ))
                   // .taskCandidateGroup(String.valueOf(orgDto.getOrganizationId()))
                    .taskAssignee(String.valueOf(p.getUserId()))
                    .singleResult();

         Assert.assertEquals("RequestAproval", task.getName());


         //Approver Completes ApprovalRequest and we add additional values THIS IS THE PART YOU ARE INTERESTED IN I THINK

         Map<String, Object> userTaskVariables = new HashMap<String, Object>();
         userTaskVariables.put("requestAccepted", true);
         userTaskVariables.put("approver",approver);

         //Complete Task
         taskService.complete(task.getId(),userTaskVariables);

希望有所帮助