如何以编程方式向Activiti BPM流程提交数据
How to submit data programitacaly to the Activiti BPM process
我正在使用 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());
}
}
}
好的,所以这是一个简单过程的示例检查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);
希望对您有所帮助
我正在使用 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());
}
}
}
好的,所以这是一个简单过程的示例检查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);
希望对您有所帮助