org.activiti.engine.impl.RepositoryServiceImpl Java Examples

The following examples show how to use org.activiti.engine.impl.RepositoryServiceImpl. 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: ActivitiWorkflowEngine.java    From alfresco-repository with GNU Lesser General Public License v3.0 6 votes vote down vote up
/**
 * {@inheritDoc}
 */
public boolean hasWorkflowImage(String workflowInstanceId)
{
    boolean hasImage = false;
    
    String processInstanceId = createLocalId(workflowInstanceId);
    ExecutionEntity pi = (ExecutionEntity) runtimeService.createProcessInstanceQuery()
                .processInstanceId(processInstanceId).singleResult();

    // If the process is finished, there is no diagram available
    if (pi != null)
    {
        // Fetch the process-definition. Not using query API, since the returned
        // processdefinition isn't initialized with all activities
        ProcessDefinitionEntity processDefinition = (ProcessDefinitionEntity) ((RepositoryServiceImpl) repoService)
                    .getDeployedProcessDefinition(pi.getProcessDefinitionId());

        hasImage = (processDefinition != null && processDefinition.isGraphicalNotationDefined()); 
    }
    
    return hasImage;
}
 
Example #2
Source File: BpmnParseHandlerTest.java    From activiti-in-action-codes with Apache License 2.0 6 votes vote down vote up
@Test
@Deployment(resources = "chapter6/dynamic-form/leave.bpmn")
public void testParseHandler() throws Exception {
    ProcessDefinition processDefinition = repositoryService.createProcessDefinitionQuery().singleResult();
    assertEquals("请假流程-动态表单-被PRE解析器修改", processDefinition.getName());
    assertEquals("leave-modified-by-post-parse-handler", processDefinition.getKey());

    RepositoryServiceImpl repositoryServiceImpl = (RepositoryServiceImpl) repositoryService;
    ReadOnlyProcessDefinition deployedProcessDefinition = repositoryServiceImpl
            .getDeployedProcessDefinition(processDefinition.getId());

    ProcessDefinitionEntity processDefinitionEntity = (ProcessDefinitionEntity) deployedProcessDefinition;
    List<ActivityImpl> activitiList = processDefinitionEntity.getActivities();//获得当前任务的所有节点
    for (ActivityImpl activity : activitiList) {
        System.out.println("Activity Name: " + activity.getProperty("name") + ", async=" + activity.isAsync());
    }

    InputStream processBpmn = activitiRule.getRepositoryService()
            .getResourceAsStream(processDefinition.getDeploymentId(), processDefinition.getResourceName());
    String userHomeDir = getClass().getResource("/").getFile();
    FileUtils.copyInputStreamToFile(processBpmn,
            new File(userHomeDir + "/leave.bpmn20.xml"));
}
 
Example #3
Source File: ProcessDefinitionPersistenceTest.java    From activiti6-boot2 with Apache License 2.0 5 votes vote down vote up
public void testProcessDefinitionIntrospection() {
  String deploymentId = repositoryService.createDeployment().addClasspathResource("org/activiti/engine/test/db/processOne.bpmn20.xml").deploy().getId();

  String procDefId = repositoryService.createProcessDefinitionQuery().singleResult().getId();
  ProcessDefinition processDefinition = ((RepositoryServiceImpl) repositoryService).getDeployedProcessDefinition(procDefId);

  assertEquals(procDefId, processDefinition.getId());
  assertEquals("Process One", processDefinition.getName());
  
  Process process = repositoryService.getBpmnModel(processDefinition.getId()).getMainProcess();
  StartEvent startElement = (StartEvent) process.getFlowElement("start");
  assertNotNull(startElement);
  assertEquals("start", startElement.getId());
  assertEquals("S t a r t", startElement.getName());
  assertEquals("the start event", startElement.getDocumentation());
  List<SequenceFlow> outgoingFlows = startElement.getOutgoingFlows();
  assertEquals(1, outgoingFlows.size());
  assertEquals("${a == b}", outgoingFlows.get(0).getConditionExpression());

  EndEvent endElement = (EndEvent) process.getFlowElement("end");
  assertNotNull(endElement);
  assertEquals("end", endElement.getId());

  assertEquals("flow1", outgoingFlows.get(0).getId());
  assertEquals("Flow One", outgoingFlows.get(0).getName());
  assertEquals("The only transitions in the process", outgoingFlows.get(0).getDocumentation());
  assertSame(startElement, outgoingFlows.get(0).getSourceFlowElement());
  assertSame(endElement, outgoingFlows.get(0).getTargetFlowElement());

  repositoryService.deleteDeployment(deploymentId);
}
 
Example #4
Source File: BpmResource.java    From lemon with Apache License 2.0 5 votes vote down vote up
private void init() {
    runtimeService = processEngine.getRuntimeService();
    historyService = processEngine.getHistoryService();
    repositoryService = (RepositoryServiceImpl) processEngine
            .getRepositoryService();
    processInstance = null;
    processDefinition = null;
    highLightedFlows = new ArrayList();
    highLightedActivities = new ArrayList();
    subProcessInstanceMap = new HashMap<String, ObjectNode>();
    // ~
    historicActivityInstanceList = new ArrayList<String>();
}
 
Example #5
Source File: ProcessExtensionServiceImpl.java    From activiti-demo with Apache License 2.0 5 votes vote down vote up
/**
 * 根据任务ID获取流程定义
 * @param taskId 任务ID
 * @return
 * @throws Exception
 */
public ProcessDefinitionEntity findProcessDefinitionEntityByTaskId(String taskId)throws Exception{

     ProcessDefinitionEntity processDefinition = (ProcessDefinitionEntity)((RepositoryServiceImpl) repositoryService).getDeployedProcessDefinition(findTaskById(taskId).getProcessDefinitionId());

     if(processDefinition == null){
         throw new Exception("流程定义未找到!");
     }
     return processDefinition;
}
 
Example #6
Source File: ProcessCustomService.java    From maven-framework-project with MIT License 5 votes vote down vote up
/** 
 * 根据任务ID获取流程定义 
 *  
 * @param taskId 
 *            任务ID 
 * @return 
 * @throws Exception 
 */  
public static ProcessDefinitionEntity findProcessDefinitionEntityByTaskId(  
        String taskId) throws Exception {  
    // 取得流程定义  
    ProcessDefinitionEntity processDefinition = (ProcessDefinitionEntity) ((RepositoryServiceImpl) repositoryService)  
            .getDeployedProcessDefinition(findTaskById(taskId)  
                    .getProcessDefinitionId());  
  
    if (processDefinition == null) {  
        throw new Exception("流程定义未找到!");  
    }  
  
    return processDefinition;  
}
 
Example #7
Source File: ActivitiWorkFlowServiceImpl.java    From maven-framework-project with MIT License 5 votes vote down vote up
public ProcessDefinitionEntity findProcessDefinitionEntityByTaskId(  
        String taskId) throws Exception {  
    // 取得流程定义  
    ProcessDefinitionEntity processDefinition = (ProcessDefinitionEntity) ((RepositoryServiceImpl) repositoryService)  
            .getDeployedProcessDefinition(findTaskById(taskId)  
                    .getProcessDefinitionId());  
  
    if (processDefinition == null) {  
        throw new Exception("流程定义未找到!");  
    }  
  
    return processDefinition;  
}
 
Example #8
Source File: WorkflowTraceService.java    From maven-framework-project with MIT License 5 votes vote down vote up
/**
 * 流程跟踪图
 * @param processInstanceId		流程实例ID
 * @return	封装了各种节点信息
 */
public List<Map<String, Object>> traceProcess(String processInstanceId) throws Exception {
	//根据流程实例获取流程节点
	Execution execution = runtimeService.createExecutionQuery().executionId(processInstanceId).singleResult();//执行实例
	Object property = PropertyUtils.getProperty(execution, "activityId");
	String activityId = "";
	if (property != null) {
		activityId = property.toString();
	}
	//查询流程实例
	ProcessInstance processInstance = runtimeService.createProcessInstanceQuery().processInstanceId(processInstanceId).singleResult();
	//根据流程定义id查询流程定义
	ProcessDefinitionEntity processDefinition = (ProcessDefinitionEntity) ((RepositoryServiceImpl) repositoryService).getDeployedProcessDefinition(processInstance.getProcessDefinitionId());
	//获取该流程定义的所有节点
	List<ActivityImpl> activitiList = processDefinition.getActivities();//获得当前任务的所有节点

	List<Map<String, Object>> activityInfos = new ArrayList<Map<String, Object>>();
	for (ActivityImpl activity : activitiList) {

		boolean currentActiviti = false;
		String id = activity.getId();

		// 判断是否是当前节点
		if (id.equals(activityId)) {
			currentActiviti = true;
		}

		Map<String, Object> activityImageInfo = packageSingleActivitiInfo(activity, processInstance, currentActiviti);

		activityInfos.add(activityImageInfo);
	}

	return activityInfos;
}
 
Example #9
Source File: WorkFlowController.java    From maven-framework-project with MIT License 5 votes vote down vote up
/**
 * 输出跟踪流程信息
 * @param processInstanceId
 * @return
 * @throws Exception
 */
@RequestMapping(value = "/process/{executionId}/trace/{processInstanceId}",produces={MediaType.APPLICATION_JSON_VALUE})
public @ResponseBody Map<String,Object> traceProcess(@PathVariable("executionId") String executionId,@PathVariable("processInstanceId") String processInstanceId) throws Exception {
	
	//根据executionId查询当前执行的节点
	ExecutionEntity execution=(ExecutionEntity) runtimeService.createExecutionQuery().processInstanceId(processInstanceId).executionId(executionId).singleResult();
	
	//获取当前节点的activityId
	String activityId=execution.getActivityId();
	
	ProcessInstance processInstance = runtimeService.createProcessInstanceQuery().processInstanceId(processInstanceId).singleResult();
	
	ProcessDefinitionEntity processDefinitionEntity = (ProcessDefinitionEntity) ((RepositoryServiceImpl)repositoryService).getDeployedProcessDefinition(processInstance.getProcessDefinitionId());
	
	List<ActivityImpl> activities = processDefinitionEntity.getActivities();
	
	Map<String,Object> activityImageInfo=new HashMap<String,Object>();
	
	for (ActivityImpl activityImpl : activities) {
		String id=activityImpl.getId();
		//判断是否是当前节点
		if(id.equals(activityId)){
			activityImageInfo.put("x", activityImpl.getX());
			activityImageInfo.put("y", activityImpl.getY());
			activityImageInfo.put("width", activityImpl.getWidth());
			activityImageInfo.put("height", activityImpl.getHeight());
			break;//跳出循环
		}
	}
	return activityImageInfo;
}
 
Example #10
Source File: WorkflowService.java    From maven-framework-project with MIT License 5 votes vote down vote up
byte[] getActiveDocumentDiagram(String docId) throws IOException {
    log.debug("getting active diagram for doc: " + docId);
    //http://forums.activiti.org/content/process-diagram-highlighting-current-process
    ProcessInstance pi =
            runtimeService.createProcessInstanceQuery().processInstanceBusinessKey(docId).singleResult();

    RepositoryServiceImpl impl = (RepositoryServiceImpl)repoSrvc;
    ProcessDefinitionEntity pde = (ProcessDefinitionEntity) impl.getDeployedProcessDefinition(pi.getProcessDefinitionId());
    BpmnModel bpmnModel = repoSrvc.getBpmnModel(pde.getId());
    InputStream in = ProcessDiagramGenerator.generateDiagram(bpmnModel, "png", runtimeService.getActiveActivityIds(pi.getProcessInstanceId()));
    byte[] bytes = IOUtils.toByteArray(in);
    IOUtils.closeQuietly(in);
    log.debug("Got bytes of size: " + bytes.length);
    return bytes;
}
 
Example #11
Source File: BpmnDeploymentTest.java    From flowable-engine with Apache License 2.0 5 votes vote down vote up
@Deployment
public void testProcessDefinitionDescription() {
    String id = repositoryService.createProcessDefinitionQuery().singleResult().getId();
    org.activiti.engine.impl.cfg.ProcessEngineConfigurationImpl activiti5ProcessEngineConfig = (org.activiti.engine.impl.cfg.ProcessEngineConfigurationImpl) processEngineConfiguration.getFlowable5CompatibilityHandler()
            .getRawProcessConfiguration();
    ReadOnlyProcessDefinition processDefinition = ((RepositoryServiceImpl) activiti5ProcessEngineConfig.getRepositoryService()).getDeployedProcessDefinition(id);
    assertEquals("This is really good process documentation!", processDefinition.getDescription());
}
 
Example #12
Source File: BpmnDeploymentTest.java    From flowable-engine with Apache License 2.0 5 votes vote down vote up
@Deployment
public void testGetBpmnXmlFileThroughService() {
    String deploymentId = repositoryService.createDeploymentQuery().singleResult().getId();
    List<String> deploymentResources = repositoryService.getDeploymentResourceNames(deploymentId);

    // verify bpmn file name
    assertEquals(1, deploymentResources.size());
    String bpmnResourceName = "org/activiti/engine/test/bpmn/deployment/BpmnDeploymentTest.testGetBpmnXmlFileThroughService.bpmn20.xml";
    assertEquals(bpmnResourceName, deploymentResources.get(0));

    ProcessDefinition processDefinition = repositoryService.createProcessDefinitionQuery().singleResult();
    assertEquals(bpmnResourceName, processDefinition.getResourceName());
    assertNull(processDefinition.getDiagramResourceName());
    assertFalse(processDefinition.hasStartFormKey());

    org.activiti.engine.impl.cfg.ProcessEngineConfigurationImpl activiti5ProcessEngineConfig = (org.activiti.engine.impl.cfg.ProcessEngineConfigurationImpl) processEngineConfiguration.getFlowable5CompatibilityHandler()
            .getRawProcessConfiguration();
    ReadOnlyProcessDefinition readOnlyProcessDefinition = ((RepositoryServiceImpl) activiti5ProcessEngineConfig.getRepositoryService()).getDeployedProcessDefinition(processDefinition.getId());
    assertNull(readOnlyProcessDefinition.getDiagramResourceName());

    // verify content
    InputStream deploymentInputStream = repositoryService.getResourceAsStream(deploymentId, bpmnResourceName);
    String contentFromDeployment = readInputStreamToString(deploymentInputStream);
    assertTrue(contentFromDeployment.length() > 0);
    assertTrue(contentFromDeployment.contains("process id=\"emptyProcess\""));

    InputStream fileInputStream = ReflectUtil.getResourceAsStream("org/activiti/engine/test/bpmn/deployment/BpmnDeploymentTest.testGetBpmnXmlFileThroughService.bpmn20.xml");
    String contentFromFile = readInputStreamToString(fileInputStream);
    assertEquals(contentFromFile, contentFromDeployment);
}
 
Example #13
Source File: ProcessDefinitionPersistenceTest.java    From flowable-engine with Apache License 2.0 5 votes vote down vote up
public void testProcessDefinitionIntrospection() {
    String deploymentId = repositoryService
            .createDeployment()
            .addClasspathResource("org/activiti/engine/test/db/processOne.bpmn20.xml")
            .deploymentProperty(DeploymentProperties.DEPLOY_AS_FLOWABLE5_PROCESS_DEFINITION, Boolean.TRUE)
            .deploy()
            .getId();

    String procDefId = repositoryService.createProcessDefinitionQuery().singleResult().getId();
    ProcessEngineConfigurationImpl activiti5ProcessEngineConfig = (ProcessEngineConfigurationImpl) processEngineConfiguration.getFlowable5CompatibilityHandler().getRawProcessConfiguration();
    ReadOnlyProcessDefinition processDefinition = ((RepositoryServiceImpl) activiti5ProcessEngineConfig.getRepositoryService()).getDeployedProcessDefinition(procDefId);

    assertEquals(procDefId, processDefinition.getId());
    assertEquals("Process One", processDefinition.getName());
    assertEquals("the first process", processDefinition.getProperty("documentation"));

    PvmActivity start = processDefinition.findActivity("start");
    assertNotNull(start);
    assertEquals("start", start.getId());
    assertEquals("S t a r t", start.getProperty("name"));
    assertEquals("the start event", start.getProperty("documentation"));
    assertEquals(Collections.EMPTY_LIST, start.getActivities());
    List<PvmTransition> outgoingTransitions = start.getOutgoingTransitions();
    assertEquals(1, outgoingTransitions.size());
    assertEquals("${a == b}", outgoingTransitions.get(0).getProperty(BpmnParse.PROPERTYNAME_CONDITION_TEXT));

    PvmActivity end = processDefinition.findActivity("end");
    assertNotNull(end);
    assertEquals("end", end.getId());

    PvmTransition transition = outgoingTransitions.get(0);
    assertEquals("flow1", transition.getId());
    assertEquals("Flow One", transition.getProperty("name"));
    assertEquals("The only transitions in the process", transition.getProperty("documentation"));
    assertSame(start, transition.getSource());
    assertSame(end, transition.getDestination());

    repositoryService.deleteDeployment(deploymentId);
}
 
Example #14
Source File: BpmTaskServiceImpl.java    From hsweb-framework with Apache License 2.0 5 votes vote down vote up
@Override
public ActivityImpl selectActivityImplByTask(String taskId) {
    if (StringUtils.isNullOrEmpty(taskId)) {
        return new ActivityImpl(null, null);
    }
    Task task = taskService.createTaskQuery().taskId(taskId).singleResult();
    ProcessDefinitionEntity entity = (ProcessDefinitionEntity) ((RepositoryServiceImpl) repositoryService).getDeployedProcessDefinition(task.getProcessDefinitionId());
    List<ActivityImpl> activities = entity.getActivities();
    return activities
            .stream()
            .filter(activity -> "userTask".equals(activity.getProperty("type")) && activity.getProperty("name").equals(task.getName()))
            .findFirst()
            .orElseThrow(() -> new NotFoundException("获取节点信息失败"));
}
 
Example #15
Source File: BpmnDeploymentTest.java    From activiti6-boot2 with Apache License 2.0 5 votes vote down vote up
@Deployment
public void testGetBpmnXmlFileThroughService() {
  String deploymentId = repositoryService.createDeploymentQuery().singleResult().getId();
  List<String> deploymentResources = repositoryService.getDeploymentResourceNames(deploymentId);

  // verify bpmn file name
  assertEquals(1, deploymentResources.size());
  String bpmnResourceName = "org/activiti/engine/test/bpmn/deployment/BpmnDeploymentTest.testGetBpmnXmlFileThroughService.bpmn20.xml";
  assertEquals(bpmnResourceName, deploymentResources.get(0));

  ProcessDefinition processDefinition = repositoryService.createProcessDefinitionQuery().singleResult();
  assertEquals(bpmnResourceName, processDefinition.getResourceName());
  assertNull(processDefinition.getDiagramResourceName());
  assertFalse(processDefinition.hasStartFormKey());

  ProcessDefinition readOnlyProcessDefinition = ((RepositoryServiceImpl) repositoryService).getDeployedProcessDefinition(processDefinition.getId());
  assertNull(readOnlyProcessDefinition.getDiagramResourceName());

  // verify content
  InputStream deploymentInputStream = repositoryService.getResourceAsStream(deploymentId, bpmnResourceName);
  String contentFromDeployment = readInputStreamToString(deploymentInputStream);
  assertTrue(contentFromDeployment.length() > 0);
  assertTrue(contentFromDeployment.contains("process id=\"emptyProcess\""));

  InputStream fileInputStream = ReflectUtil.getResourceAsStream("org/activiti/engine/test/bpmn/deployment/BpmnDeploymentTest.testGetBpmnXmlFileThroughService.bpmn20.xml");
  String contentFromFile = readInputStreamToString(fileInputStream);
  assertEquals(contentFromFile, contentFromDeployment);
}
 
Example #16
Source File: ActivitiWorkflowEngine.java    From alfresco-repository with GNU Lesser General Public License v3.0 5 votes vote down vote up
/**
* {@inheritDoc}
*/
public List<WorkflowTaskDefinition> getTaskDefinitions(String workflowDefinitionId)
{
    List<WorkflowTaskDefinition> defs = new ArrayList<WorkflowTaskDefinition>();
    String processDefinitionId = createLocalId(workflowDefinitionId);
    
    // This should return all task definitions, including the start-task
    ReadOnlyProcessDefinition processDefinition =((RepositoryServiceImpl)repoService).getDeployedProcessDefinition(processDefinitionId);

    String processName = ((ProcessDefinition)processDefinition).getKey();
    factory.checkDomain(processName);
    
    // Process start task definition
    PvmActivity startEvent = processDefinition.getInitial();
    
    String startTaskName = null;
    StartFormData startFormData = formService.getStartFormData(processDefinition.getId());
    if(startFormData != null) 
    {
        startTaskName = startFormData.getFormKey();
    }
    
    // Add start task definition
    defs.add(typeConverter.getTaskDefinition(startEvent, startTaskName, processDefinition.getId(), true));
    
    // Now, continue through process, finding all user-tasks
    Collection<PvmActivity> taskActivities = typeConverter.findUserTasks(startEvent);
    for(PvmActivity act : taskActivities)
    {
        String formKey = typeConverter.getFormKey(act, processDefinition);
        defs.add(typeConverter.getTaskDefinition(act, formKey, processDefinition.getId(), false));
    }
    
   return defs;
}
 
Example #17
Source File: ActTaskService.java    From Shop-for-JavaWeb with MIT License 5 votes vote down vote up
/**
 * 流程跟踪图信息
 * @param processInstanceId		流程实例ID
 * @return	封装了各种节点信息
 */
public List<Map<String, Object>> traceProcess(String processInstanceId) throws Exception {
	Execution execution = runtimeService.createExecutionQuery().executionId(processInstanceId).singleResult();//执行实例
	Object property = PropertyUtils.getProperty(execution, "activityId");
	String activityId = "";
	if (property != null) {
		activityId = property.toString();
	}
	ProcessInstance processInstance = runtimeService.createProcessInstanceQuery().processInstanceId(processInstanceId)
			.singleResult();
	ProcessDefinitionEntity processDefinition = (ProcessDefinitionEntity) ((RepositoryServiceImpl) repositoryService)
			.getDeployedProcessDefinition(processInstance.getProcessDefinitionId());
	List<ActivityImpl> activitiList = processDefinition.getActivities();//获得当前任务的所有节点

	List<Map<String, Object>> activityInfos = new ArrayList<Map<String, Object>>();
	for (ActivityImpl activity : activitiList) {

		boolean currentActiviti = false;
		String id = activity.getId();

		// 当前节点
		if (id.equals(activityId)) {
			currentActiviti = true;
		}

		Map<String, Object> activityImageInfo = packageSingleActivitiInfo(activity, processInstance, currentActiviti);

		activityInfos.add(activityImageInfo);
	}

	return activityInfos;
}
 
Example #18
Source File: TraceProcessController.java    From activiti-in-action-codes with Apache License 2.0 4 votes vote down vote up
/**
 * 读取跟踪数据
 *
 * @param executionId
 * @return
 * @throws Exception
 */
@RequestMapping(value = "trace/data/{executionId}")
@ResponseBody
public List<Map<String, Object>> readActivityDatas(@PathVariable("executionId") String executionId) throws Exception {
    ExecutionEntity executionEntity = (ExecutionEntity) runtimeService.createExecutionQuery().executionId(executionId).singleResult();
    List<String> activeActivityIds = runtimeService.getActiveActivityIds(executionId);

    RepositoryServiceImpl repositoryServiceImpl = (RepositoryServiceImpl) repositoryService;
    ReadOnlyProcessDefinition deployedProcessDefinition = repositoryServiceImpl
            .getDeployedProcessDefinition(executionEntity.getProcessDefinitionId());

    ProcessDefinitionEntity processDefinition = (ProcessDefinitionEntity) deployedProcessDefinition;
    List<ActivityImpl> activitiList = processDefinition.getActivities();//获得当前任务的所有节点

    List<Map<String, Object>> activityInfos = new ArrayList<Map<String, Object>>();
    for (ActivityImpl activity : activitiList) {

        ActivityBehavior activityBehavior = activity.getActivityBehavior();

        boolean currentActiviti = false;
        // 当前节点
        String activityId = activity.getId();
        if (activeActivityIds.contains(activityId)) {
            currentActiviti = true;
        }
        Map<String, Object> activityImageInfo = packageSingleActivitiInfo(activity, executionEntity.getId(), currentActiviti);
        activityInfos.add(activityImageInfo);

        // 处理子流程
        if (activityBehavior instanceof SubProcessActivityBehavior) {
            List<ActivityImpl> innerActivityList = activity.getActivities();
            for (ActivityImpl innerActivity : innerActivityList) {
                String innerActivityId = innerActivity.getId();
                if (activeActivityIds.contains(innerActivityId)) {
                    currentActiviti = true;
                } else {
                    currentActiviti = false;
                }
                activityImageInfo = packageSingleActivitiInfo(innerActivity, executionEntity.getId(), currentActiviti);
                activityInfos.add(activityImageInfo);
            }
        }

    }

    return activityInfos;
}
 
Example #19
Source File: DeploymentBuilderImpl.java    From activiti6-boot2 with Apache License 2.0 4 votes vote down vote up
public DeploymentBuilderImpl(RepositoryServiceImpl repositoryService) {
  this.repositoryService = repositoryService;
  this.deployment = Context.getProcessEngineConfiguration().getDeploymentEntityManager().create();
  this.resourceEntityManager = Context.getProcessEngineConfiguration().getResourceEntityManager();
}
 
Example #20
Source File: BpmnDeploymentTest.java    From activiti6-boot2 with Apache License 2.0 4 votes vote down vote up
@Deployment
public void testProcessDefinitionDescription() {
  String id = repositoryService.createProcessDefinitionQuery().singleResult().getId();
  ProcessDefinition processDefinition = ((RepositoryServiceImpl) repositoryService).getDeployedProcessDefinition(id);
  assertEquals("This is really good process documentation!", processDefinition.getDescription());
}
 
Example #21
Source File: WorkflowInnerServiceSMOImpl.java    From MicroCommunity with Apache License 2.0 4 votes vote down vote up
public String getRunWorkflowImage(@RequestBody String businessKey) {

        String image = "";
        ProcessEngine processEngine = ProcessEngines.getDefaultProcessEngine();
        try {
            //  获取历史流程实例
            HistoricProcessInstance historicProcessInstance = historyService.createHistoricProcessInstanceQuery()
                    .processInstanceBusinessKey(businessKey).singleResult();

            if (historicProcessInstance == null) {
                //throw new BusinessException("获取流程实例ID[" + pProcessInstanceId + "]对应的历史流程实例失败!");
            } else {
                // 获取流程定义
                ProcessDefinitionEntity processDefinition = (ProcessDefinitionEntity) ((RepositoryServiceImpl) repositoryService)
                        .getDeployedProcessDefinition(historicProcessInstance.getProcessDefinitionId());

                // 获取流程历史中已执行节点,并按照节点在流程中执行先后顺序排序
                List<HistoricActivityInstance> historicActivityInstanceList = historyService.createHistoricActivityInstanceQuery()
                        .processInstanceId(historicProcessInstance.getId()).orderByHistoricActivityInstanceId().asc().list();

                // 已执行的节点ID集合
                List<String> executedActivityIdList = new ArrayList<String>();
                int index = 1;
                //logger.info("获取已经执行的节点ID");
                for (HistoricActivityInstance activityInstance : historicActivityInstanceList) {
                    executedActivityIdList.add(activityInstance.getActivityId());

                    //logger.info("第[" + index + "]个已执行节点=" + activityInstance.getActivityId() + " : " +activityInstance.getActivityName());
                    index++;
                }

                BpmnModel bpmnModel = repositoryService.getBpmnModel(historicProcessInstance.getProcessDefinitionId());

                // 已执行的线集合
                List<String> flowIds = new ArrayList<String>();
                // 获取流程走过的线 (getHighLightedFlows是下面的方法)
                flowIds = getHighLightedFlows(bpmnModel, processDefinition, historicActivityInstanceList);


                // 获取流程图图像字符流
                ProcessDiagramGenerator pec = processEngine.getProcessEngineConfiguration().getProcessDiagramGenerator();
                //配置字体
                InputStream imageStream = pec.generateDiagram(bpmnModel, "png", executedActivityIdList, flowIds, "宋体", "宋体", "宋体", null, 2.0);


                image = Base64Convert.ioToBase64(imageStream);
            }
        } catch (Exception e) {
            logger.error("读取图片失败", e);

        }
        return image;
    }
 
Example #22
Source File: ActivitiUtil.java    From alfresco-repository with GNU Lesser General Public License v3.0 4 votes vote down vote up
public ReadOnlyProcessDefinition getDeployedProcessDefinition(String processDefinitionId) 
{
    // Currently, getDeployedProcessDefinition is still experimental and not exposed on 
    // RepositoryService interface
    return ((RepositoryServiceImpl)repoService).getDeployedProcessDefinition(processDefinitionId);
}
 
Example #23
Source File: DocumentApproveSubProcessTest.java    From maven-framework-project with MIT License 4 votes vote down vote up
@Test
public void testDocApprovalFlow() throws InterruptedException, IOException {
    setSpringSecurity("kermit");
    Document doc = new Document();
    doc.setGroupId("engineering");
    doc.setCreatedDate(new Date());
    doc.setTitle("title");
    doc.setSummary("Summary");
    doc.setContent("content");
    doc.setAuthor("kermit");
    String docId;
    docId = documentService.createDocument(doc);
    log.debug("new doc id: " + docId);
    this.documentService.submitForApproval(docId);



    setSpringSecurity("fozzie");
    List<TaskForm> tasks = this.localTaskService.getTasks("fozzie");
    assertTrue(tasks.size() == 1);
    TaskForm currentTask = tasks.get(0);
    log.debug("got task: " + tasks.get(0).getName());

    //http://forums.activiti.org/content/process-diagram-highlighting-current-process
    RepositoryServiceImpl impl = (RepositoryServiceImpl)repoSrvc;
    ProcessDefinitionEntity pde = (ProcessDefinitionEntity) impl.getDeployedProcessDefinition(currentTask.getProcessDefinitionId());
    BpmnModel bpmnModel = repoSrvc.getBpmnModel(pde.getId());
    InputStream in = ProcessDiagramGenerator.generateDiagram(bpmnModel, "png", runtimeService.getActiveActivityIds(currentTask.getProcessInstanceId()));
    FileUtils.copyInputStreamToFile(in, new File("target/current-diagram.png"));

    localTaskService.approveTask(true, "task approved blah blah blah", tasks.get(0).getId());
    HistoricProcessInstance pi = historyService.createHistoricProcessInstanceQuery().
            includeProcessVariables().processInstanceBusinessKey(docId).singleResult();

    assertNotNull(pi);
    log.debug("Duration time in millis: " + pi.getDurationInMillis());
    List<HistoricTaskInstance> hTasks;
    hTasks = historyService.createHistoricTaskInstanceQuery().includeTaskLocalVariables().processInstanceBusinessKey(docId).list();
    assertTrue(hTasks.size() == 2);
    HistoricTaskInstance approval = hTasks.get(1);
    Map<String, Object> vars = approval.getTaskLocalVariables();
    List<Comment> comments = taskService.getTaskComments(approval.getId());
}
 
Example #24
Source File: BpmTaskServiceImpl.java    From hsweb-framework with Apache License 2.0 4 votes vote down vote up
@Override
@SneakyThrows
public void reject(RejectTaskRequest request) {
    request.tryValidate();
    String taskId = request.getTaskId();
    Task curTask = selectTaskByTaskId(taskId);
    if (curTask == null) {
        throw new NotFoundException("任务不存在或未激活");
    }
    ProcessInstance processInstance = runtimeService
            .createProcessInstanceQuery()
            .processInstanceId(curTask.getProcessInstanceId())
            .singleResult();

    ProcessDefinitionEntity entity = (ProcessDefinitionEntity)
            ((RepositoryServiceImpl) repositoryService)
                    .getDeployedProcessDefinition(curTask.getProcessDefinitionId());

    ActivityImpl currActivity = entity.findActivity(curTask.getTaskDefinitionKey());

    List<PvmActivity> transitions = new ArrayList<>();
    //查找上一个环节
    findActivity(currActivity,
            activity ->
                    activity.getIncomingTransitions()
                            .stream()
                            .map(PvmTransition::getSource)
                            .collect(Collectors.toList()),
            activity -> transitions.isEmpty() && "userTask".equals(activity.getProperty("type")),
            transitions::add);

    if (!transitions.isEmpty()) {
        //跳转到上一环节
        PvmActivity transition = transitions.get(transitions.size() - 1);
        doJumpTask(curTask, transition.getId(), newTask -> {
        });
    } else {
        throw new BusinessException("无法获取上一步任务");
    }

    //记录日志
    ProcessHistoryEntity history = ProcessHistoryEntity.builder()
            .businessKey(processInstance.getBusinessKey())
            .type("reject")
            .typeText("驳回")
            .creatorId(request.getRejectUserId())
            .creatorName(request.getRejectUserName())
            .processDefineId(processInstance.getProcessDefinitionId())
            .processInstanceId(processInstance.getProcessInstanceId())
            .taskId(taskId)
            .taskDefineKey(curTask.getTaskDefinitionKey())
            .taskName(curTask.getName())
            .data(request.getData())
            .build();

    processHistoryService.insert(history);
}
 
Example #25
Source File: BpmTaskServiceImpl.java    From hsweb-framework with Apache License 2.0 4 votes vote down vote up
@SneakyThrows
public void doJumpTask(Task task, String activityId, Consumer<Task> newTaskConsumer) {

    ProcessDefinitionEntity entity = (ProcessDefinitionEntity)
            ((RepositoryServiceImpl) repositoryService)
                    .getDeployedProcessDefinition(task.getProcessDefinitionId());

    String sourceId = task.getTaskDefinitionKey();

    ActivityImpl targetActivity = entity.findActivity(activityId);
    ActivityImpl sourceActivity = entity.findActivity(sourceId);

    if (logger.isDebugEnabled()) {
        logger.debug("流程[{}({})]跳转[{}]->[{}]",
                entity.getName(),
                entity.getId(),
                sourceActivity.getId(),
                targetActivity.getId());
    }

    //回退的节点
    List<PvmActivity> backActivities = new ArrayList<>();
    //如果目标节点的Outgoing中有源节点,说明是回退需要删除对应的连线
    findActivity(targetActivity,
            activity -> activity
                    .getOutgoingTransitions()
                    .stream()
                    .map(PvmTransition::getDestination)
                    .collect(Collectors.toList()),
            activity -> sourceActivity.getId().equals(activity.getId()),
            backActivities::add);

    //回退
    if (!backActivities.isEmpty()) {
        for (PvmActivity pvmTransition : backActivities) {
            if (logger.isDebugEnabled()) {
                logger.debug("流程[{}({})]回退[{}]->[{}],删除链接线:{}",
                        entity.getName(),
                        entity.getId(),
                        sourceActivity.getId(),
                        targetActivity.getId(),
                        pvmTransition.getId());
            }
            //删除连线
            List<HistoricActivityInstance> instance = historyService
                    .createHistoricActivityInstanceQuery()
                    .processInstanceId(task.getProcessInstanceId())
                    .activityId(pvmTransition.getId())
                    .list();
            for (HistoricActivityInstance historicActivityInstance : instance) {
                sqlExecutor.delete("delete from act_hi_actinst where id_= #{id}", historicActivityInstance);
            }
        }
    }
    //执行回退命令
    TaskServiceImpl taskServiceImpl = (TaskServiceImpl) taskService;
    taskServiceImpl.getCommandExecutor().execute(new JumpTaskCmd(task.getExecutionId(), activityId));
    //设置候选人并回调
    selectNowTask(task.getProcessInstanceId())
            .forEach(t -> {
                //设置候选人
                setCandidate(task.getAssignee(), t);
                newTaskConsumer.accept(t);
            });

}
 
Example #26
Source File: TraceProcessController.java    From activiti-in-action-codes with Apache License 2.0 4 votes vote down vote up
/**
 * 读取跟踪数据
 *
 * @param executionId
 * @return
 * @throws Exception
 */
@RequestMapping(value = "trace/data/{executionId}")
@ResponseBody
public List<Map<String, Object>> readActivityDatas(@PathVariable("executionId") String executionId) throws Exception {
    ExecutionEntity executionEntity = (ExecutionEntity) runtimeService.createExecutionQuery().executionId(executionId).singleResult();
    List<String> activeActivityIds = runtimeService.getActiveActivityIds(executionId);

    RepositoryServiceImpl repositoryServiceImpl = (RepositoryServiceImpl) repositoryService;
    ReadOnlyProcessDefinition deployedProcessDefinition = repositoryServiceImpl
            .getDeployedProcessDefinition(executionEntity.getProcessDefinitionId());

    ProcessDefinitionEntity processDefinition = (ProcessDefinitionEntity) deployedProcessDefinition;
    List<ActivityImpl> activitiList = processDefinition.getActivities();//获得当前任务的所有节点

    List<Map<String, Object>> activityInfos = new ArrayList<Map<String, Object>>();
    for (ActivityImpl activity : activitiList) {

        ActivityBehavior activityBehavior = activity.getActivityBehavior();

        boolean currentActiviti = false;
        // 当前节点
        String activityId = activity.getId();
        if (activeActivityIds.contains(activityId)) {
            currentActiviti = true;
        }
        Map<String, Object> activityImageInfo = packageSingleActivitiInfo(activity, executionEntity.getId(), currentActiviti);
        activityInfos.add(activityImageInfo);

        // 处理子流程
        if (activityBehavior instanceof SubProcessActivityBehavior) {
            List<ActivityImpl> innerActivityList = activity.getActivities();
            for (ActivityImpl innerActivity : innerActivityList) {
                String innerActivityId = innerActivity.getId();
                if (activeActivityIds.contains(innerActivityId)) {
                    currentActiviti = true;
                } else {
                    currentActiviti = false;
                }
                activityImageInfo = packageSingleActivitiInfo(innerActivity, executionEntity.getId(), currentActiviti);
                activityInfos.add(activityImageInfo);
            }
        }

    }

    return activityInfos;
}
 
Example #27
Source File: TraceProcessController.java    From activiti-in-action-codes with Apache License 2.0 4 votes vote down vote up
/**
 * 读取跟踪数据
 *
 * @param executionId
 * @return
 * @throws Exception
 */
@RequestMapping(value = "trace/data/{executionId}")
@ResponseBody
public List<Map<String, Object>> readActivityDatas(@PathVariable("executionId") String executionId) throws Exception {
    ExecutionEntity executionEntity = (ExecutionEntity) runtimeService.createExecutionQuery().executionId(executionId).singleResult();
    List<String> activeActivityIds = runtimeService.getActiveActivityIds(executionId);

    RepositoryServiceImpl repositoryServiceImpl = (RepositoryServiceImpl) repositoryService;
    ReadOnlyProcessDefinition deployedProcessDefinition = repositoryServiceImpl
            .getDeployedProcessDefinition(executionEntity.getProcessDefinitionId());

    ProcessDefinitionEntity processDefinition = (ProcessDefinitionEntity) deployedProcessDefinition;
    List<ActivityImpl> activitiList = processDefinition.getActivities();//获得当前任务的所有节点

    List<Map<String, Object>> activityInfos = new ArrayList<Map<String, Object>>();
    for (ActivityImpl activity : activitiList) {

        ActivityBehavior activityBehavior = activity.getActivityBehavior();

        boolean currentActiviti = false;
        // 当前节点
        String activityId = activity.getId();
        if (activeActivityIds.contains(activityId)) {
            currentActiviti = true;
        }
        Map<String, Object> activityImageInfo = packageSingleActivitiInfo(activity, executionEntity.getId(), currentActiviti);
        activityInfos.add(activityImageInfo);

        // 处理子流程
        if (activityBehavior instanceof SubProcessActivityBehavior) {
            List<ActivityImpl> innerActivityList = activity.getActivities();
            for (ActivityImpl innerActivity : innerActivityList) {
                String innerActivityId = innerActivity.getId();
                if (activeActivityIds.contains(innerActivityId)) {
                    currentActiviti = true;
                } else {
                    currentActiviti = false;
                }
                activityImageInfo = packageSingleActivitiInfo(innerActivity, executionEntity.getId(), currentActiviti);
                activityInfos.add(activityImageInfo);
            }
        }

    }

    return activityInfos;
}
 
Example #28
Source File: TraceProcessController.java    From activiti-in-action-codes with Apache License 2.0 4 votes vote down vote up
/**
 * 读取跟踪数据
 *
 * @param executionId
 * @return
 * @throws Exception
 */
@RequestMapping(value = "trace/data/{executionId}")
@ResponseBody
public List<Map<String, Object>> readActivityDatas(@PathVariable("executionId") String executionId) throws Exception {
    ExecutionEntity executionEntity = (ExecutionEntity) runtimeService.createExecutionQuery().executionId(executionId).singleResult();
    List<String> activeActivityIds = runtimeService.getActiveActivityIds(executionId);

    RepositoryServiceImpl repositoryServiceImpl = (RepositoryServiceImpl) repositoryService;
    ReadOnlyProcessDefinition deployedProcessDefinition = repositoryServiceImpl
            .getDeployedProcessDefinition(executionEntity.getProcessDefinitionId());

    ProcessDefinitionEntity processDefinition = (ProcessDefinitionEntity) deployedProcessDefinition;
    List<ActivityImpl> activitiList = processDefinition.getActivities();//获得当前任务的所有节点

    List<Map<String, Object>> activityInfos = new ArrayList<Map<String, Object>>();
    for (ActivityImpl activity : activitiList) {

        ActivityBehavior activityBehavior = activity.getActivityBehavior();

        boolean currentActiviti = false;
        // 当前节点
        String activityId = activity.getId();
        if (activeActivityIds.contains(activityId)) {
            currentActiviti = true;
        }
        Map<String, Object> activityImageInfo = packageSingleActivitiInfo(activity, executionEntity.getId(), currentActiviti);
        activityInfos.add(activityImageInfo);

        // 处理子流程
        if (activityBehavior instanceof SubProcessActivityBehavior) {
            List<ActivityImpl> innerActivityList = activity.getActivities();
            for (ActivityImpl innerActivity : innerActivityList) {
                String innerActivityId = innerActivity.getId();
                if (activeActivityIds.contains(innerActivityId)) {
                    currentActiviti = true;
                } else {
                    currentActiviti = false;
                }
                activityImageInfo = packageSingleActivitiInfo(innerActivity, executionEntity.getId(), currentActiviti);
                activityInfos.add(activityImageInfo);
            }
        }

    }

    return activityInfos;
}
 
Example #29
Source File: TraceProcessController.java    From activiti-in-action-codes with Apache License 2.0 4 votes vote down vote up
/**
 * 读取跟踪数据
 *
 * @param executionId
 * @return
 * @throws Exception
 */
@RequestMapping(value = "trace/data/{executionId}")
@ResponseBody
public List<Map<String, Object>> readActivityDatas(@PathVariable("executionId") String executionId) throws Exception {
    ExecutionEntity executionEntity = (ExecutionEntity) runtimeService.createExecutionQuery().executionId(executionId).singleResult();
    List<String> activeActivityIds = runtimeService.getActiveActivityIds(executionId);

    RepositoryServiceImpl repositoryServiceImpl = (RepositoryServiceImpl) repositoryService;
    ReadOnlyProcessDefinition deployedProcessDefinition = repositoryServiceImpl
            .getDeployedProcessDefinition(executionEntity.getProcessDefinitionId());

    ProcessDefinitionEntity processDefinition = (ProcessDefinitionEntity) deployedProcessDefinition;
    List<ActivityImpl> activitiList = processDefinition.getActivities();//获得当前任务的所有节点

    List<Map<String, Object>> activityInfos = new ArrayList<Map<String, Object>>();
    for (ActivityImpl activity : activitiList) {

        ActivityBehavior activityBehavior = activity.getActivityBehavior();

        boolean currentActiviti = false;
        // 当前节点
        String activityId = activity.getId();
        if (activeActivityIds.contains(activityId)) {
            currentActiviti = true;
        }
        Map<String, Object> activityImageInfo = packageSingleActivitiInfo(activity, executionEntity.getId(), currentActiviti);
        activityInfos.add(activityImageInfo);

        // 处理子流程
        if (activityBehavior instanceof SubProcessActivityBehavior) {
            List<ActivityImpl> innerActivityList = activity.getActivities();
            for (ActivityImpl innerActivity : innerActivityList) {
                String innerActivityId = innerActivity.getId();
                if (activeActivityIds.contains(innerActivityId)) {
                    currentActiviti = true;
                } else {
                    currentActiviti = false;
                }
                activityImageInfo = packageSingleActivitiInfo(innerActivity, executionEntity.getId(), currentActiviti);
                activityInfos.add(activityImageInfo);
            }
        }

    }

    return activityInfos;
}
 
Example #30
Source File: ProcessDefinitionUtils.java    From openwebflow with BSD 2-Clause "Simplified" License 4 votes vote down vote up
public static ProcessDefinitionEntity getProcessDefinition(ProcessEngine processEngine, String processDefId)
{
	return (ProcessDefinitionEntity) ((RepositoryServiceImpl) processEngine.getRepositoryService())
			.getDeployedProcessDefinition(processDefId);
}