Java Code Examples for org.activiti.engine.repository.ProcessDefinition#getDiagramResourceName()

The following examples show how to use org.activiti.engine.repository.ProcessDefinition#getDiagramResourceName() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: GetDeploymentProcessDiagramCmd.java    From activiti6-boot2 with Apache License 2.0 6 votes vote down vote up
public InputStream execute(CommandContext commandContext) {
  ProcessDefinition processDefinition = commandContext
          .getProcessEngineConfiguration()
          .getDeploymentManager()
          .findDeployedProcessDefinitionById(processDefinitionId);
  String deploymentId = processDefinition.getDeploymentId();
  String resourceName = processDefinition.getDiagramResourceName();
  if (resourceName == null ) {
    log.info("Resource name is null! No process diagram stream exists.");
    return null;
  } else {
    InputStream processDiagramStream =
            new GetDeploymentResourceCmd(deploymentId, resourceName)
            .execute(commandContext);
    return processDiagramStream;
  }
}
 
Example 2
Source File: BpmnDeploymentTest.java    From activiti6-boot2 with Apache License 2.0 6 votes vote down vote up
@Deployment(resources = { "org/activiti/engine/test/bpmn/deployment/BpmnDeploymentTest.testProcessDiagramResource.bpmn20.xml",
    "org/activiti/engine/test/bpmn/deployment/BpmnDeploymentTest.testProcessDiagramResource.jpg" })
public void testProcessDiagramResource() {
  ProcessDefinition processDefinition = repositoryService.createProcessDefinitionQuery().singleResult();

  assertEquals("org/activiti/engine/test/bpmn/deployment/BpmnDeploymentTest.testProcessDiagramResource.bpmn20.xml", processDefinition.getResourceName());
  BpmnModel processModel = repositoryService.getBpmnModel(processDefinition.getId());
  List<StartEvent> startEvents = processModel.getMainProcess().findFlowElementsOfType(StartEvent.class);
  assertEquals(1, startEvents.size());
  assertEquals("someFormKey", startEvents.get(0).getFormKey());

  String diagramResourceName = processDefinition.getDiagramResourceName();
  assertEquals("org/activiti/engine/test/bpmn/deployment/BpmnDeploymentTest.testProcessDiagramResource.jpg", diagramResourceName);

  InputStream diagramStream = repositoryService.getResourceAsStream(deploymentIdFromDeploymentAnnotation,
      "org/activiti/engine/test/bpmn/deployment/BpmnDeploymentTest.testProcessDiagramResource.jpg");
  byte[] diagramBytes = IoUtil.readInputStream(diagramStream, "diagram stream");
  assertEquals(33343, diagramBytes.length);
}
 
Example 3
Source File: RestResponseFactory.java    From activiti6-boot2 with Apache License 2.0 6 votes vote down vote up
public ProcessDefinitionResponse createProcessDefinitionResponse(ProcessDefinition processDefinition, RestUrlBuilder urlBuilder) {
  ProcessDefinitionResponse response = new ProcessDefinitionResponse();
  response.setUrl(urlBuilder.buildUrl(RestUrls.URL_PROCESS_DEFINITION, processDefinition.getId()));
  response.setId(processDefinition.getId());
  response.setKey(processDefinition.getKey());
  response.setVersion(processDefinition.getVersion());
  response.setCategory(processDefinition.getCategory());
  response.setName(processDefinition.getName());
  response.setDescription(processDefinition.getDescription());
  response.setSuspended(processDefinition.isSuspended());
  response.setStartFormDefined(processDefinition.hasStartFormKey());
  response.setGraphicalNotationDefined(processDefinition.hasGraphicalNotation());
  response.setTenantId(processDefinition.getTenantId());

  // Links to other resources
  response.setDeploymentId(processDefinition.getDeploymentId());
  response.setDeploymentUrl(urlBuilder.buildUrl(RestUrls.URL_DEPLOYMENT, processDefinition.getDeploymentId()));
  response.setResource(urlBuilder.buildUrl(RestUrls.URL_DEPLOYMENT_RESOURCE, processDefinition.getDeploymentId(), processDefinition.getResourceName()));
  if (processDefinition.getDiagramResourceName() != null) {
    response.setDiagramResource(urlBuilder.buildUrl(RestUrls.URL_DEPLOYMENT_RESOURCE, processDefinition.getDeploymentId(), processDefinition.getDiagramResourceName()));
  }
  return response;
}
 
Example 4
Source File: BpmnDeploymentTest.java    From activiti6-boot2 with Apache License 2.0 6 votes vote down vote up
@Deployment(resources={
  "org/activiti5/engine/test/bpmn/deployment/BpmnDeploymentTest.testProcessDiagramResource.bpmn20.xml",
  "org/activiti5/engine/test/bpmn/deployment/BpmnDeploymentTest.testProcessDiagramResource.jpg"
})
public void testProcessDiagramResource() {
  ProcessDefinition processDefinition = repositoryService.createProcessDefinitionQuery().singleResult();
  
  assertEquals("org/activiti5/engine/test/bpmn/deployment/BpmnDeploymentTest.testProcessDiagramResource.bpmn20.xml", processDefinition.getResourceName());
  assertTrue(processDefinition.hasStartFormKey());

  String diagramResourceName = processDefinition.getDiagramResourceName();
  assertEquals("org/activiti5/engine/test/bpmn/deployment/BpmnDeploymentTest.testProcessDiagramResource.jpg", diagramResourceName);
  
  InputStream diagramStream = repositoryService.getResourceAsStream(deploymentIdFromDeploymentAnnotation, "org/activiti5/engine/test/bpmn/deployment/BpmnDeploymentTest.testProcessDiagramResource.jpg");
  byte[] diagramBytes = IoUtil.readInputStream(diagramStream, "diagram stream");
  assertEquals(33343, diagramBytes.length);
}
 
Example 5
Source File: ActProcessService.java    From Shop-for-JavaWeb with MIT License 6 votes vote down vote up
/**
 * 读取资源,通过部署ID
 * @param processDefinitionId  流程定义ID
 * @param processInstanceId 流程实例ID
 * @param resourceType 资源类型(xml|image)
 */
public InputStream resourceRead(String procDefId, String proInsId, String resType) throws Exception {
	
	if (StringUtils.isBlank(procDefId)){
		ProcessInstance processInstance = runtimeService.createProcessInstanceQuery().processInstanceId(proInsId).singleResult();
		procDefId = processInstance.getProcessDefinitionId();
	}
	ProcessDefinition processDefinition = repositoryService.createProcessDefinitionQuery().processDefinitionId(procDefId).singleResult();
	
	String resourceName = "";
	if (resType.equals("image")) {
		resourceName = processDefinition.getDiagramResourceName();
	} else if (resType.equals("xml")) {
		resourceName = processDefinition.getResourceName();
	}
	
	InputStream resourceAsStream = repositoryService.getResourceAsStream(processDefinition.getDeploymentId(), resourceName);
	return resourceAsStream;
}
 
Example 6
Source File: GetDeploymentProcessDiagramCmd.java    From activiti6-boot2 with Apache License 2.0 5 votes vote down vote up
public InputStream execute(CommandContext commandContext) {
  ProcessDefinition processDefinition = commandContext.getProcessEngineConfiguration().getDeploymentManager().findDeployedProcessDefinitionById(processDefinitionId);
  String deploymentId = processDefinition.getDeploymentId();
  String resourceName = processDefinition.getDiagramResourceName();
  if (resourceName == null) {
    log.info("Resource name is null! No process diagram stream exists.");
    return null;
  } else {
    InputStream processDiagramStream = new GetDeploymentResourceCmd(deploymentId, resourceName).execute(commandContext);
    return processDiagramStream;
  }
}
 
Example 7
Source File: WorkFlowController.java    From maven-framework-project with MIT License 5 votes vote down vote up
/**
 * 根据流程实例Id和资源类型加载流程资源
 * @param processInstanceId 流程实例id
 * @param resourceType 流程资源类型
 * @param request
 * @param response
 */
@RequestMapping(value="/loadResourceByProcessInstance",method={RequestMethod.GET,RequestMethod.POST})
public void loadResourceByProcessInstance(@RequestParam("processInstanceId")String processInstanceId,@RequestParam("resourceType")String resourceType,HttpServletRequest request, HttpServletResponse response){
	//根据流程实例id查询流程实例
	ProcessInstance processInstance = runtimeService.createProcessInstanceQuery().processInstanceId(processInstanceId).singleResult();
	//根据流程定义id查询流程定义
	ProcessDefinition processDefinition = repositoryService.createProcessDefinitionQuery().processDefinitionId(processInstance.getProcessDefinitionId()).singleResult();
	
	String resourceName="";
	if(resourceType.equals("xml")){
		//获取流程定义资源名称
		resourceName=processDefinition.getResourceName();
	}else if(resourceType.equals("image")){
		//获取流程图资源名称
		resourceName=processDefinition.getDiagramResourceName();
	}
	//打开流程资源流
	InputStream resourceAsStream = repositoryService.getResourceAsStream(processDefinition.getDeploymentId(), resourceName);
	//输出到浏览器
	try {
		byte[] byteArray = IOUtils.toByteArray(resourceAsStream);
		ServletOutputStream servletOutputStream = response.getOutputStream();
		servletOutputStream.write(byteArray, 0, byteArray.length);
		servletOutputStream.flush();
		servletOutputStream.close();
	} catch (IOException e) {
		e.printStackTrace();
	}
}
 
Example 8
Source File: WorkFlowController.java    From maven-framework-project with MIT License 5 votes vote down vote up
/**
 * 根据流程实例id查询流程图(跟踪流程图)
 * @param processInstanceId 流程实例id
 * @param request
 * @param response
 */
@RequestMapping(value="/view/{processInstanceId}",method={RequestMethod.GET,RequestMethod.POST})
public void viewProcessImageView(@PathVariable("processInstanceId")String processInstanceId,HttpServletRequest request, HttpServletResponse response){
	InputStream resourceAsStream = null;
	try {
		
		//根据流程实例id查询流程实例
		ProcessInstance processInstance = runtimeService.createProcessInstanceQuery().processInstanceId(processInstanceId).singleResult();
		
		//根据流程定义id查询流程定义
		ProcessDefinition processDefinition = repositoryService.createProcessDefinitionQuery().processDefinitionId(processInstance.getProcessDefinitionId()).singleResult();
		
		String resourceName=processDefinition.getDiagramResourceName();
		
		//打开流程资源流
		resourceAsStream = repositoryService.getResourceAsStream(processDefinition.getDeploymentId(), resourceName);
		
		runtimeService.getActiveActivityIds(processInstance.getId());
		
		//输出到浏览器
		byte[] byteArray = IOUtils.toByteArray(resourceAsStream);
		ServletOutputStream servletOutputStream = response.getOutputStream();
		servletOutputStream.write(byteArray, 0, byteArray.length);
		servletOutputStream.flush();
		servletOutputStream.close();
		
	} catch (Exception ex) {
		ex.printStackTrace();
	}
}
 
Example 9
Source File: BpmProcessServiceImpl.java    From hsweb-framework with Apache License 2.0 4 votes vote down vote up
@Override
public InputStream findProcessPic(String procDefId) {
    ProcessDefinition definition = getProcessDefinitionById(procDefId);
    String source = definition.getDiagramResourceName();
    return repositoryService.getResourceAsStream(definition.getDeploymentId(), source);
}
 
Example 10
Source File: ActProcessService.java    From Shop-for-JavaWeb with MIT License 4 votes vote down vote up
/**
 * 导出图片文件到硬盘
 */
public List<String> exportDiagrams(String exportDir) throws IOException {
	List<String> files = new ArrayList<String>();
	List<ProcessDefinition> list = repositoryService.createProcessDefinitionQuery().list();
	
	for (ProcessDefinition processDefinition : list) {
		String diagramResourceName = processDefinition.getDiagramResourceName();
		String key = processDefinition.getKey();
		int version = processDefinition.getVersion();
		String diagramPath = "";

		InputStream resourceAsStream = repositoryService.getResourceAsStream(
				processDefinition.getDeploymentId(), diagramResourceName);
		byte[] b = new byte[resourceAsStream.available()];

		@SuppressWarnings("unused")
		int len = -1;
		resourceAsStream.read(b, 0, b.length);

		// create file if not exist
		String diagramDir = exportDir + "/" + key + "/" + version;
		File diagramDirFile = new File(diagramDir);
		if (!diagramDirFile.exists()) {
			diagramDirFile.mkdirs();
		}
		diagramPath = diagramDir + "/" + diagramResourceName;
		File file = new File(diagramPath);

		// 文件存在退出
		if (file.exists()) {
			// 文件大小相同时直接返回否则重新创建文件(可能损坏)
			logger.debug("diagram exist, ignore... : {}", diagramPath);
			
			files.add(diagramPath);
		} else {
			file.createNewFile();
			logger.debug("export diagram to : {}", diagramPath);

			// wirte bytes to file
			FileUtils.writeByteArrayToFile(file, b, true);
			
			files.add(diagramPath);
		}
		
	}
	
	return files;
}
 
Example 11
Source File: ClasspathDeploymentTest.java    From activiti-in-action-codes with Apache License 2.0 4 votes vote down vote up
@Test
    public void testClasspathDeployment() throws Exception {

        // 定义classpath
        String bpmnClasspath = "chapter5/candidateUserInUserTask.bpmn";
        String pngClasspath = "chapter5/candidateUserInUserTask.png";

        // 创建部署构建器
        DeploymentBuilder deploymentBuilder = repositoryService.createDeployment();

        // 添加资源
        deploymentBuilder.addClasspathResource(bpmnClasspath);
        deploymentBuilder.addClasspathResource(pngClasspath);

        // 执行部署
        deploymentBuilder.deploy();

        // 验证流程定义是否部署成功
        ProcessDefinitionQuery processDefinitionQuery = repositoryService.createProcessDefinitionQuery();
        long count = processDefinitionQuery.processDefinitionKey("candidateUserInUserTask").count();
        assertEquals(1, count);

        // 读取图片文件
        ProcessDefinition processDefinition = processDefinitionQuery.singleResult();
        String diagramResourceName = processDefinition.getDiagramResourceName();
        assertEquals(pngClasspath, diagramResourceName);

        Map<String, Object> vars = new HashMap<String, Object>();
        ArrayList<Date> objs = new ArrayList<Date>();
        objs.add(new Date());
        vars.put("list", objs);
//        vars.put("aaa", "333");
        runtimeService.startProcessInstanceByKey("candidateUserInUserTask", vars);
        List<Task> list = taskService.createTaskQuery().includeProcessVariables().list();
        System.out.println(list);
        Task task = taskService.createTaskQuery().taskId(list.get(0).getId())
                .includeProcessVariables().includeTaskLocalVariables().singleResult();
        CommandContext commandContext = Context.getCommandContext();
        System.out.println(task);
        System.out.println(commandContext);

//        ProcessEngineImpl defaultProcessEngine = (ProcessEngineImpl) ProcessEngines.getDefaultProcessEngine();
//        Context.setProcessEngineConfiguration(defaultProcessEngine.getProcessEngineConfiguration());
//        Context.setCommandContext(defaultProcessEngine.getProcessEngineConfiguration().getCommandContextFactory().createCommandContext(null));
        System.out.println(Context.getCommandContext());
        System.out.println(task.getProcessVariables());
    }