package org.mpc.final_activiti; import java.util.List; import org.activiti.engine.IdentityService; import org.activiti.engine.ProcessEngine; import org.activiti.engine.ProcessEngineConfiguration; import org.activiti.engine.RepositoryService; import org.activiti.engine.repository.DeploymentBuilder; import org.junit.Test; public class RepositoryServiceTest { @Test public void test() throws Exception { /** * * 获得DeploymentBuilder对象 * * */ ProcessEngine engine = ProcessEngineConfiguration .createProcessEngineConfigurationFromResourceDefault() .buildProcessEngine(); RepositoryService repositoryService = engine.getRepositoryService(); IdentityService identityService = engine.getIdentityService(); // 创建DeploymentBuilder对象 DeploymentBuilder builder = repositoryService.createDeployment(); /** * * 添加输入流资源 * * */ // InputStream in = new FileInputStream(new File( // "C:/Users/mpc/Desktop/小新/1.jpg")); // builder.addInputStream("testInput", in); // builder.deploy(); /** * * 添加classpath资源 * * */ // builder.addClasspathResource("2.jpg"); // builder.deploy(); /** * * 添加字符串资源 * * */ // builder.addString("test_txt", "aaabbbcccddddddcccbbbaaa"); // builder.deploy(); /** * * 添加压缩包资源 * * */ // 获取zip文件的输入流 // FileInputStream fileInputStream = new FileInputStream(new File( // "C:/Users/mpc/Desktop/小新/test.zip")); // ZipInputStream zin = new ZipInputStream(fileInputStream); // builder.addZipInputStream(zin); // builder.deploy(); /** * * 修改部署名称 * * */ // builder.name("test"); // builder.deploy(); /** * * 过滤重复部署 * * 想要使用过滤重复部署,一定要给部署实体一个名称 * */ // InputStream in = new FileInputStream(new File( // "C:/Users/mpc/Desktop/小新/1.jpg")); // builder.name("d1"); // builder.addInputStream("testInput", in).deploy(); // DeploymentBuilder builder2 = repositoryService.createDeployment(); // InputStream in1 = new FileInputStream(new File( // "C:/Users/mpc/Desktop/小新/1.jpg")); // builder2.name("d1"); // builder2.enableDuplicateFiltering(); // builder2.addInputStream("testInput", in1).deploy(); // DeploymentBuilder builder3 = repositoryService.createDeployment(); // builder3.name("d1"); // builder3.enableDuplicateFiltering(); // InputStream in2 = new FileInputStream(new File( // "C:/Users/mpc/Desktop/小新/2.jpg")); // builder3.addInputStream("testInput", in2).deploy(); /** * * 流程部署,也就是部署.bpmn文件 * * */ // builder.addClasspathResource("final_activiti/progress/test.bpmn") // .deploy(); /** * * 终止与激活流程定义 * * */ // Deployment deployment = builder.addClasspathResource( // "final_activiti/progress/test.bpmn").deploy(); // // ProcessDefinition definition = repositoryService // .createProcessDefinitionQuery() // .deploymentId(deployment.getId()).singleResult(); // repositoryService.suspendProcessDefinitionById(definition.getId()); // repositoryService.activateProcessDefinitionById(definition.getId()); // repositoryService.suspendProcessDefinitionByKey(definition.getKey()); // repositoryService.activateProcessDefinitionByKey(definition.getKey()); /** * * 设置流程定义的权限 * * */ // repositoryService.addCandidateStarterUser("ptest:3:77504", "37501"); // repositoryService.addCandidateStarterGroup("ptest:3:77504", "32501"); /** * * 使用我们设置的权限 * * */ // 根据用户的信息来获得用户有权开启的流程定义 // List<ProcessDefinition> defs = repositoryService // .createProcessDefinitionQuery().startableByUser("37501").list(); // Assert.assertEquals("ptest:3:77504", defs.get(0).getId()); // 根据流程定义来获取有权开启流程的用户 // User user = identityService.createUserQuery() // .potentialStarter("ptest:3:77504").singleResult(); // Assert.assertEquals("37501", user.getId()); // 根据流程定义获取有权开启流程的用户组 // Group group // =identityService.createGroupQuery().potentialStarter("ptest:3:77504").singleResult(); // Assert.assertEquals("32501", group.getId()); /** * * 查询部署资源 * * */ // InputStream in = repositoryService.getResourceAsStream("55001", // "test_txt"); // int count = in.available(); // byte[] byes = new byte[count]; // in.read(byes); // String result = new String(byes); // System.out.println(result); /** * * 查询流程文件 * * */ // 查询流程定义实体 // ProcessDefinition pef = repositoryService // .createProcessDefinitionQuery().deploymentId("77501") // .singleResult(); // 查询资源文件 // InputStream in = repositoryService.getProcessModel(pef.getId()); // 读取输入流 // int count = in.available(); // byte[] b = new byte[count]; // in.read(b); // System.out.println(new String(b)); /** * * 查询流程图 * * */ // ProcessDefinition processDefinition = repositoryService // .createProcessDefinitionQuery().deploymentId("77501") // .singleResult(); // InputStream in = // repositoryService.getProcessDiagram(processDefinition // .getId()); // BufferedImage img = ImageIO.read(in); // File file = new File("d:/result.png"); // if (!file.exists()) // file.createNewFile(); // FileOutputStream out = new FileOutputStream(file); // ImageIO.write(img, "png", out); // in.close(); // out.close(); /** * * 查询部署资源名称 * * */ // List<String> names = repositoryService // .getDeploymentResourceNames("77501"); // for (String s : names) { // System.out.println(s); // } /** * * 删除部署资源 * * */ // repositoryService.deleteDeployment("77501"); } }
时间: 2024-10-02 04:36:21