我正在使用activiti BPM,并且想在没有Activiti浏览的情况下运行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());
        }



}

}

最佳答案

好的,这是一个简单过程的示例。在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);


希望能帮助到你

09-11 17:25