이 문서의 예에서는 Activiti 흐름도 보기의 구현 방법을 보여줍니다. 구체적인 단계는 다음과 같습니다.
1. 테스트 케이스 보기 픽처 코드는 다음과 같습니다.
public void viewImage() throws Exception { // 웨어하우스 서비스 객체 생성 RepositoryService reporter Service = processEngine.getRepositoryService(); // 웨어하우스에서 표시해야 하는 파일 찾기 String developmentId = "701" names = repositoryService.getDeploymentResourceNames(deploymentId); String imageName = null for(문자열 이름: 이름); if(name.indexOf(".png")>=0){ imageName = name; } } if(imageName!=null){// System.out.println(imageName); /"+ imageName); // 배포 ID 및 파일 이름을 통해 파일의 입력 스트림을 가져옵니다. FileUtils.copyInputStreamToFile(in, f) }
설명하다:
1) 배포Id는 프로세스 배포 ID입니다.
2) ResourceName은 act_ge_bytearray 테이블의 NAME_ 열 값입니다.
3) 지정된 배포에 있는 모든 파일의 이름을 얻으려면 저장소 서비스의 getDeploymentResourceNames 메소드를 사용하십시오.
4) 저장소 서비스의 getResourceAsStream 메소드를 사용하여 배포 ID와 파일 이름을 전달하여 배포에서 지정된 이름을 가진 파일의 입력 스트림을 얻습니다.
5) 최종 IO 스트림 작업의 경우 FileUtils 도구의 copyInputStreamToFile 메서드를 사용하여 파일에 대한 프로세스 흐름 복사를 완료합니다.
2. 웹 프로젝트의 프로세스 정의 페이지에서 그림을 봅니다.
public String viewImage(){InputStream in = reporterService.getResourceAsStream.getImageStream(deploymentId,imageName);//여기서 메소드의 실제 프로젝트는 HttpServletResponse 서비스에 배치되어야 합니다. resp = ServletActionContext.getResponse();try { OutputStream out = resp .getOutputStream( ); // 이미지 입력 프로세스를 resp 출력 스트림에 씁니다. byte[] b = new byte[1024]; for (int len = -1; (len= in.read(b))!=-1; ) { out.write(b, 0, len) } // 스트림을 닫습니다. .close( ); in.close();} catch(IOException e) { e.printStackTrace();}return null;}
설명하다:
1) 배포Id는 프로세스 배포 ID이고, imageName은 이미지 이름입니다.
2) 프로세스 정의 목록 페이지에서 이미지를 보기 때문에 프로세스 정의(ProcessDefinition)에서 id와 imageName을 얻을 수 있다. (String getDeploymentId(); and String getDiagramResourceName();)
3) 웹페이지 태그 <a target="_blank" href="viewImage?deploymentId=1&imageName=imageName.png" rel="external nofollow" >흐름도 보기</a>
3. 웹 프로젝트의 현재 흐름도 보기
public String viewCurrentImage(){ProcessDefinition pd = service.getProcessDefinitionByTaskId(taskId);// 1. 프로세스 배포 ID 가져오기 putContext("deploymentId", pd.getDeploymentId());// 2. 프로세스 이미지 이름 가져오기 putContext ("imageName" , pd.getDiagramResourceName());// 3. 현재 활동의 좌표를 가져옵니다. Map<String,Object> currentActivityCoordinates =service.getCurrentActivityCoordinates(taskId);putContext("acs", currentActivityCoordinates);return "image";}
service.getProcessDefinitionByTaskId(taskId)의 코드 구현은 다음과 같습니다.
public ProcessDefinition getProcessDefinitionByTaskId(String taskId) {// 1. taskTask 가져오기 task = taskService.createTaskQuery().taskId(taskId).singleResult();// 2. 작업 개체의 pdid를 통해 프로세스 정의 개체 ProcessDefinition 가져오기 pd = 저장소서비스.getProcessDefinition(task.getProcessDefinitionId());반환 PD;}
service.getCurrentActivityCoordinates(taskId)의 코드 구현은 다음과 같습니다.
public Map<String, Object> getCurrentActivityCoordinates(String taskId) {Map<String, Object> Coordinates = new HashMap<String, Object>(); // 1. 현재 활성화된 IDTask 가져오기 task = taskService.createTaskQuery().taskId ( taskId).singleResult();ProcessInstance pi = RuntimeService.createProcessInstanceQuery().processInstanceId(task.getProcessInstanceId()).singleResult();String currentActivitiId = pi.getActivityId();// 2. 프로세스 정의 가져오기 ProcessDefinitionEntity pd = (ProcessDefinitionEntity) reporterService.getProcessDefinition(task.getProcessDefinitionId( ));// 3. 프로세스 정의를 사용하여 currentActivitiId Activity = pd.findActivity(currentActivitiId);//를 통해 활동 개체 ActivityImpl을 가져옵니다. 4. 활동 좌표를 가져옵니다. put("y" , Activity.getY());coordinates.put("너비", Activity.getWidth());coordinates.put("높이", Activity.getHeight());좌표 반환;}
이미지 페이지 부분:
개인 작업 목록 페이지에서 <a target="_blank" href="/viewCurrentImage?taskId=1" rel="external nofollow" >현재 흐름 차트 보기</a>를 클릭하여 다음 페이지로 이동하세요.
<body><!-- 1. 규칙 흐름도를 얻습니다. 여기서는 strust2 태그를 사용하여 위의 값 스택에 값을 넣습니다.--><img style="position:absolute;top: 0px;left: 0px ; " src="viewImage?deploymentId=<s:property value='#deploymentId'/>&imageName=<s:property value='#imageName'/>"><!-- 2. 현재 활동의 좌표에 따라 DIV를 동적으로 그립니다. --><div style="position:absolute;border:1px solid red;top:<s: 속성 값 ='#acs.y'/>px;왼쪽: <s:property value='#acs.x'/>px;너비: <s:property value='#acs.width'/>px;height:<s:property value='#acs.height'/>px "></div></body>