public class HelloWorld {
ProcessEngine processEngine = ProcessEngines.getDefaultProcessEngine();
//部署流程定义
@Test
public void deplementProcessDefination(){
//创建一个部署构建器对象
DeploymentBuilder deploymentBuilder = processEngine.getRepositoryService().createDeployment();
deploymentBuilder.name("请假");
//加载流程定义文件(bpmn、png)
deploymentBuilder.addClasspathResource("qjlc.bpmn");
deploymentBuilder.addClasspathResource("qjlc.png");
Deployment deployment = deploymentBuilder.deploy();
System.out.println(deployment.getId());
System.out.println(deployment.getName());
}
//部署流程定义(zip)
/*@Test
public void deplementProcessDefination_zip(){
InputStream inputStream = this.getClass().getClassLoader().getResourceAsStream("qjlc.zip");
ZipInputStream zipInputStream=new ZipInputStream(inputStream);
DeploymentBuilder deploymentBuilder = processEngine.getRepositoryService().createDeployment();
deploymentBuilder.addZipInputStream(zipInputStream);
deploymentBuilder.name("zip请假");
Deployment deploy = deploymentBuilder.deploy();
System.out.println(deploy.getId());
System.out.println(deploy.getName());
}*/
//查询流程定义
@Test
public void queryProcessDefination(){
ProcessDefinitionQuery query = processEngine.getRepositoryService().createProcessDefinitionQuery();
query.processDefinitionName("请假");
query.orderByProcessDefinitionVersion().asc();
List<ProcessDefinition> list = query.listPage(0, 10);
for (ProcessDefinition processDefinition : list) {
System.out.println(processDefinition.getName());
}
}
//删除流程定义
/*@Test
public void deleteProcessDefination(){
processEngine.getRepositoryService().deleteDeployment("101", true);
System.out.println("删除成功");
}*/
//启动流程实例
@Test
public void startProcessInstance(){
String processDefinationId="qjlc:3:1404";
Map<String, Object> map=new HashMap<String, Object>();
map.put("qjts", 5);
ProcessInstance pi = processEngine.getRuntimeService().startProcessInstanceById(processDefinationId, map);
System.out.println(pi.getId());
System.out.println(pi.getProcessDefinitionId());
}
//查询流程实例
@Test
public void queryProcessInstance(){
ProcessInstanceQuery query = processEngine.getRuntimeService().createProcessInstanceQuery();
List<ProcessInstance> list = query.list();
for (ProcessInstance processInstance : list) {
System.out.println(processInstance.getId());
}
}
//创建组
@Test
public void createGroup(){
Group group=new GroupEntity();
group.setId("主管");
processEngine.getIdentityService().saveGroup(group);
}
//创建用户
@Test
public void createUser(){
User user=new UserEntity();
user.setId("001");
processEngine.getIdentityService().saveUser(user);
}
//建立用户与候选组之间的关系
@Test
public void createMembership(){
String userid="001";
String groupid="主管";
processEngine.getIdentityService().createMembership(userid, groupid);
}
//查询组任务
@Test
public void queryGroupTask(){
TaskQuery query = processEngine.getTaskService().createTaskQuery();
query.taskCandidateUser("001");
List<Task> list = query.list();
for (Task task : list) {
System.out.println(task.getId());
}
}
//拾取组任务
@Test
public void getGroupTask(){
String taskid="1602";
String userid="001";
processEngine.getTaskService().claim(taskid, userid);
}
//查询个人任务
@Test
public void queryTask(){
TaskQuery query = processEngine.getTaskService().createTaskQuery();
query.taskAssignee("001");
List<Task> list = query.list();
for (Task task : list) {
System.out.println(task.getId());
}
}
//办理个人任务
@Test
public void task(){
String taskid="1902";
processEngine.getTaskService().complete(taskid);
}
//查询办理到了哪一个节点
@Test
public void TaskDefinition(){
String processInstanceId="1902";
RuntimeService runtimeService = processEngine.getRuntimeService();
ProcessInstance processInstance = runtimeService.createProcessInstanceQuery().processInstanceId(processInstanceId).singleResult();
String processDefinitionId= processInstance.getProcessDefinitionId();
RepositoryService repositoryService = processEngine.getRepositoryService();
ProcessDefinitionEntity entity = (ProcessDefinitionEntity) repositoryService.createProcessDefinitionQuery().processDefinitionId(processDefinitionId).singleResult();
String activityId = processInstance.getActivityId();
System.out.println(activityId);
/*//获得当前任务的所有节点
List<ActivityImpl> activities = entity.getActivities();
String id = null;
for(ActivityImpl activityImpl:activities){
id = activityImpl.getId();
if(activityId.equals(id)){
System.out.println("当前任务:"+activityImpl.getProperty("name"));
}
} */
}
}
ProcessEngine processEngine = ProcessEngines.getDefaultProcessEngine();
//部署流程定义
@Test
public void deplementProcessDefination(){
//创建一个部署构建器对象
DeploymentBuilder deploymentBuilder = processEngine.getRepositoryService().createDeployment();
deploymentBuilder.name("请假");
//加载流程定义文件(bpmn、png)
deploymentBuilder.addClasspathResource("qjlc.bpmn");
deploymentBuilder.addClasspathResource("qjlc.png");
Deployment deployment = deploymentBuilder.deploy();
System.out.println(deployment.getId());
System.out.println(deployment.getName());
}
//部署流程定义(zip)
/*@Test
public void deplementProcessDefination_zip(){
InputStream inputStream = this.getClass().getClassLoader().getResourceAsStream("qjlc.zip");
ZipInputStream zipInputStream=new ZipInputStream(inputStream);
DeploymentBuilder deploymentBuilder = processEngine.getRepositoryService().createDeployment();
deploymentBuilder.addZipInputStream(zipInputStream);
deploymentBuilder.name("zip请假");
Deployment deploy = deploymentBuilder.deploy();
System.out.println(deploy.getId());
System.out.println(deploy.getName());
}*/
//查询流程定义
@Test
public void queryProcessDefination(){
ProcessDefinitionQuery query = processEngine.getRepositoryService().createProcessDefinitionQuery();
query.processDefinitionName("请假");
query.orderByProcessDefinitionVersion().asc();
List<ProcessDefinition> list = query.listPage(0, 10);
for (ProcessDefinition processDefinition : list) {
System.out.println(processDefinition.getName());
}
}
//删除流程定义
/*@Test
public void deleteProcessDefination(){
processEngine.getRepositoryService().deleteDeployment("101", true);
System.out.println("删除成功");
}*/
//启动流程实例
@Test
public void startProcessInstance(){
String processDefinationId="qjlc:3:1404";
Map<String, Object> map=new HashMap<String, Object>();
map.put("qjts", 5);
ProcessInstance pi = processEngine.getRuntimeService().startProcessInstanceById(processDefinationId, map);
System.out.println(pi.getId());
System.out.println(pi.getProcessDefinitionId());
}
//查询流程实例
@Test
public void queryProcessInstance(){
ProcessInstanceQuery query = processEngine.getRuntimeService().createProcessInstanceQuery();
List<ProcessInstance> list = query.list();
for (ProcessInstance processInstance : list) {
System.out.println(processInstance.getId());
}
}
//创建组
@Test
public void createGroup(){
Group group=new GroupEntity();
group.setId("主管");
processEngine.getIdentityService().saveGroup(group);
}
//创建用户
@Test
public void createUser(){
User user=new UserEntity();
user.setId("001");
processEngine.getIdentityService().saveUser(user);
}
//建立用户与候选组之间的关系
@Test
public void createMembership(){
String userid="001";
String groupid="主管";
processEngine.getIdentityService().createMembership(userid, groupid);
}
//查询组任务
@Test
public void queryGroupTask(){
TaskQuery query = processEngine.getTaskService().createTaskQuery();
query.taskCandidateUser("001");
List<Task> list = query.list();
for (Task task : list) {
System.out.println(task.getId());
}
}
//拾取组任务
@Test
public void getGroupTask(){
String taskid="1602";
String userid="001";
processEngine.getTaskService().claim(taskid, userid);
}
//查询个人任务
@Test
public void queryTask(){
TaskQuery query = processEngine.getTaskService().createTaskQuery();
query.taskAssignee("001");
List<Task> list = query.list();
for (Task task : list) {
System.out.println(task.getId());
}
}
//办理个人任务
@Test
public void task(){
String taskid="1902";
processEngine.getTaskService().complete(taskid);
}
//查询办理到了哪一个节点
@Test
public void TaskDefinition(){
String processInstanceId="1902";
RuntimeService runtimeService = processEngine.getRuntimeService();
ProcessInstance processInstance = runtimeService.createProcessInstanceQuery().processInstanceId(processInstanceId).singleResult();
String processDefinitionId= processInstance.getProcessDefinitionId();
RepositoryService repositoryService = processEngine.getRepositoryService();
ProcessDefinitionEntity entity = (ProcessDefinitionEntity) repositoryService.createProcessDefinitionQuery().processDefinitionId(processDefinitionId).singleResult();
String activityId = processInstance.getActivityId();
System.out.println(activityId);
/*//获得当前任务的所有节点
List<ActivityImpl> activities = entity.getActivities();
String id = null;
for(ActivityImpl activityImpl:activities){
id = activityImpl.getId();
if(activityId.equals(id)){
System.out.println("当前任务:"+activityImpl.getProperty("name"));
}
} */
}
}