Java Code Examples for org.activiti.engine.history.HistoricProcessInstance#getProcessDefinitionId()

The following examples show how to use org.activiti.engine.history.HistoricProcessInstance#getProcessDefinitionId() . 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: HistoricProcessInstanceQueryImpl.java    From activiti6-boot2 with Apache License 2.0 6 votes vote down vote up
protected void localize(HistoricProcessInstance processInstance, CommandContext commandContext) {
  HistoricProcessInstanceEntity processInstanceEntity = (HistoricProcessInstanceEntity) processInstance;
  processInstanceEntity.setLocalizedName(null);
  processInstanceEntity.setLocalizedDescription(null);

  if (locale != null && processInstance.getProcessDefinitionId() != null) {
    ProcessDefinition processDefinition = commandContext.getProcessEngineConfiguration().getDeploymentManager().findDeployedProcessDefinitionById(processInstanceEntity.getProcessDefinitionId());
    ObjectNode languageNode = Context.getLocalizationElementProperties(locale, processDefinition.getKey(), 
        processInstanceEntity.getProcessDefinitionId(), withLocalizationFallback);
    
    if (languageNode != null) {
      JsonNode languageNameNode = languageNode.get(DynamicBpmnConstants.LOCALIZATION_NAME);
      if (languageNameNode != null && languageNameNode.isNull() == false) {
        processInstanceEntity.setLocalizedName(languageNameNode.asText());
      }

      JsonNode languageDescriptionNode = languageNode.get(DynamicBpmnConstants.LOCALIZATION_DESCRIPTION);
      if (languageDescriptionNode != null && languageDescriptionNode.isNull() == false) {
        processInstanceEntity.setLocalizedDescription(languageDescriptionNode.asText());
      }
    }
  }
}
 
Example 2
Source File: HistoricProcessInstanceQueryImpl.java    From flowable-engine with Apache License 2.0 6 votes vote down vote up
protected void localize(HistoricProcessInstance processInstance, CommandContext commandContext) {
    processInstance.setLocalizedName(null);
    processInstance.setLocalizedDescription(null);

    if (locale != null && processInstance.getProcessDefinitionId() != null) {
        ProcessDefinition processDefinition = commandContext.getProcessEngineConfiguration().getDeploymentManager().findDeployedProcessDefinitionById(processInstance.getProcessDefinitionId());
        ObjectNode languageNode = Context.getLocalizationElementProperties(locale, processDefinition.getKey(),
                processInstance.getProcessDefinitionId(), withLocalizationFallback);

        if (languageNode != null) {
            JsonNode languageNameNode = languageNode.get(DynamicBpmnConstants.LOCALIZATION_NAME);
            if (languageNameNode != null && !languageNameNode.isNull()) {
                processInstance.setLocalizedName(languageNameNode.asText());
            }

            JsonNode languageDescriptionNode = languageNode.get(DynamicBpmnConstants.LOCALIZATION_DESCRIPTION);
            if (languageDescriptionNode != null && !languageDescriptionNode.isNull()) {
                processInstance.setLocalizedDescription(languageDescriptionNode.asText());
            }
        }
    }
}
 
Example 3
Source File: TraceService.java    From lemon with Apache License 2.0 6 votes vote down vote up
public List<NodeDTO> traceProcessInstance(String processInstanceId) {
    HistoricProcessInstance historicProcessInstance = processEngine
            .getHistoryService().createHistoricProcessInstanceQuery()
            .processInstanceId(processInstanceId).singleResult();
    GetBpmnModelCmd getBpmnModelCmd = new GetBpmnModelCmd(
            historicProcessInstance.getProcessDefinitionId());
    BpmnModel bpmnModel = processEngine.getManagementService()
            .executeCommand(getBpmnModelCmd);

    Map<String, GraphicInfo> graphicInfoMap = bpmnModel.getLocationMap();

    List<NodeDTO> nodeDtos = new ArrayList<NodeDTO>();

    for (Map.Entry<String, GraphicInfo> entry : graphicInfoMap.entrySet()) {
        String key = entry.getKey();
        GraphicInfo graphicInfo = entry.getValue();
        nodeDtos.add(this.convertNodeDto(graphicInfo,
                bpmnModel.getFlowElement(key), key, bpmnModel));
    }

    return nodeDtos;
}
 
Example 4
Source File: ProcessInstanceRepresentation.java    From activiti6-boot2 with Apache License 2.0 5 votes vote down vote up
public ProcessInstanceRepresentation(HistoricProcessInstance processInstance, boolean graphicalNotation, User startedBy) {
    this.id = processInstance.getId();
    this.name = processInstance.getName();
    this.businessKey = processInstance.getBusinessKey();
    this.processDefinitionId = processInstance.getProcessDefinitionId();
    this.tenantId = processInstance.getTenantId();
    this.graphicalNotationDefined = graphicalNotation;
    this.started = processInstance.getStartTime();
    this.ended = processInstance.getEndTime();
    this.startedBy = new UserRepresentation(startedBy);
}
 
Example 5
Source File: RuntimeDisplayJsonClientResource.java    From activiti6-boot2 with Apache License 2.0 5 votes vote down vote up
@RequestMapping(value = "/rest/process-instances/history/{processInstanceId}/model-json", method = RequestMethod.GET, produces = "application/json")
public JsonNode getModelHistoryJSON(@PathVariable String processInstanceId) {

  User currentUser = SecurityUtils.getCurrentUserObject();
  if (!permissionService.hasReadPermissionOnProcessInstance(currentUser, processInstanceId)) {
    throw new NotPermittedException();
  }

  HistoricProcessInstance processInstance = historyService.createHistoricProcessInstanceQuery().processInstanceId(processInstanceId).singleResult();
  if (processInstance == null) {
    throw new BadRequestException("No process instance found with id " + processInstanceId);
  }

  BpmnModel pojoModel = repositoryService.getBpmnModel(processInstance.getProcessDefinitionId());

  if (pojoModel == null || pojoModel.getLocationMap().isEmpty()) {
    throw new InternalServerErrorException("Process definition could not be found with id " + processInstance.getProcessDefinitionId());
  }

  // Fetch process-instance activities
  List<HistoricActivityInstance> activityInstances = historyService.createHistoricActivityInstanceQuery().processInstanceId(processInstanceId).list();

  Set<String> completedActivityInstances = new HashSet<String>();
  Set<String> currentActivityinstances = new HashSet<String>();
  if (CollectionUtils.isNotEmpty(activityInstances)) {
    for (HistoricActivityInstance activityInstance : activityInstances) {
      if (activityInstance.getEndTime() != null) {
        completedActivityInstances.add(activityInstance.getActivityId());
      } else {
        currentActivityinstances.add(activityInstance.getActivityId());
      }
    }
  }

  ObjectNode displayNode = processProcessElements(pojoModel, completedActivityInstances, currentActivityinstances);
  return displayNode;
}
 
Example 6
Source File: ProcessInfo.java    From alfresco-remote-api with GNU Lesser General Public License v3.0 5 votes vote down vote up
public ProcessInfo(HistoricProcessInstance processInstance)
{
    this.id = processInstance.getId();
    this.processDefinitionId = processInstance.getProcessDefinitionId();
    this.startedAt = processInstance.getStartTime();
    this.endedAt = processInstance.getEndTime();
    this.durationInMs = processInstance.getDurationInMillis();
    this.deleteReason = processInstance.getDeleteReason();
    this.startUserId = processInstance.getStartUserId();
    this.startActivityId = processInstance.getStartActivityId();
    this.endActivityId = processInstance.getEndActivityId();
    this.businessKey = processInstance.getBusinessKey();
    this.superProcessInstanceId = processInstance.getSuperProcessInstanceId();
    this.completed = (processInstance.getEndTime() != null);
}
 
Example 7
Source File: CustomProcessDiagramGenerator.java    From lemon with Apache License 2.0 5 votes vote down vote up
public void drawHistoryFlow(BufferedImage image, String processInstanceId) {
    HistoricProcessInstance historicProcessInstance = Context
            .getCommandContext().getHistoricProcessInstanceEntityManager()
            .findHistoricProcessInstance(processInstanceId);
    String processDefinitionId = historicProcessInstance
            .getProcessDefinitionId();
    Graph graph = new ActivitiHistoryGraphBuilder(processInstanceId)
            .build();

    for (Edge edge : graph.getEdges()) {
        drawSequenceFlow(image, processDefinitionId, edge.getName());
    }
}
 
Example 8
Source File: ViewService.java    From lemon with Apache License 2.0 5 votes vote down vote up
public Map<String, Object> findProcessForm(String processInstanceId)
        throws Exception {
    Map<String, Object> result = new HashMap<String, Object>();

    HistoryService historyService = processEngine.getHistoryService();
    HistoricProcessInstance historicProcessInstance = historyService
            .createHistoricProcessInstanceQuery()
            .processInstanceId(processInstanceId).singleResult();
    String processDefinitionId = historicProcessInstance
            .getProcessDefinitionId();

    FormDTO formDto = this.processConnector
            .findStartForm(processDefinitionId);
    // model.addAttribute("formDto", formDto);
    result.put("formDto", formDto);

    String businessKey = processConnector
            .findBusinessKeyByProcessInstanceId(processInstanceId);
    String tenantId = tenantHolder.getTenantId();
    ModelInfoDTO modelInfoDto = modelConnector.findByCode(businessKey);
    formDto = formConnector.findForm(formDto.getCode(), tenantId);

    Xform xform = this.processModelService.processFormData(businessKey,
            formDto);
    // model.addAttribute("xform", xform);
    result.put("xform", xform);
    this.processExternalForm(result, formDto, businessKey, modelInfoDto);

    return result;
}
 
Example 9
Source File: ActivitiWorkflowImageInnerServiceSMOImpl.java    From MicroCommunity with Apache License 2.0 4 votes vote down vote up
public String getWorkflowImage(@RequestBody String taskId){
    Task task = taskService.createTaskQuery().taskId(taskId).singleResult();
    String processInstanceId = task.getProcessInstanceId();
    ProcessInstance processInstance = runtimeService.createProcessInstanceQuery()
            .processInstanceId(processInstanceId).singleResult();
    String processDefinitionId = "";
    if (processInstance == null) {
        //查询已经结束的流程实例
        HistoricProcessInstance processInstanceHistory =
                historyService.createHistoricProcessInstanceQuery()
                        .processInstanceId(processInstanceId).singleResult();
        if (processInstanceHistory == null)
            return null;
        else
            processDefinitionId = processInstanceHistory.getProcessDefinitionId();
    } else {
        processDefinitionId = processInstance.getProcessDefinitionId();
    }

    //使用宋体
    String fontName = "宋体";
    //获取BPMN模型对象
    BpmnModel model = repositoryService.getBpmnModel(processDefinitionId);
    //获取流程实例当前的节点,需要高亮显示
    List<String> currentActs = Collections.EMPTY_LIST;
    if (processInstance != null)
        currentActs = runtimeService.getActiveActivityIds(processInstance.getId());

    InputStream is = processEngine.getProcessEngineConfiguration()
            .getProcessDiagramGenerator()
            .generateDiagram(model, "png", currentActs, new ArrayList<String>(),
                    fontName, fontName, fontName, null, 1.0);
    String image = "";
    try {
        image = Base64Convert.ioToBase64(is);
    } catch (IOException e) {
        e.printStackTrace();
    }

    return image;
}
 
Example 10
Source File: ProcessesImpl.java    From alfresco-remote-api with GNU Lesser General Public License v3.0 4 votes vote down vote up
@Override
public CollectionWithPagingInfo<Variable> getVariables(String processId, Paging paging)
{
    CollectionWithPagingInfo<Variable> result = null;
    
    // Check if user is allowed to get variables
    List<HistoricVariableInstance> variableInstances = validateIfUserAllowedToWorkWithProcess(processId);
    Map<String, Object> variables = new HashMap<String, Object>();
    for (HistoricVariableInstance variable : variableInstances)
    {
        variables.put(variable.getVariableName(), variable.getValue());
    }
    
    ProcessInstance processInstance = activitiProcessEngine.getRuntimeService()
            .createProcessInstanceQuery()
            .processInstanceId(processId)
            .singleResult();
    
    String processDefinitionId = null;
    
    if (processInstance != null)
    {
        processDefinitionId = processInstance.getProcessDefinitionId();
    }
    else
    {
        // Completed process instance
        HistoricProcessInstance historicInstance = activitiProcessEngine.getHistoryService().createHistoricProcessInstanceQuery()
            .processInstanceId(processId).singleResult();
        
        if (historicInstance == null)
        {
            throw new EntityNotFoundException(processId);
        }
        
        processDefinitionId = historicInstance.getProcessDefinitionId();
    }

    // Get start-task definition for explicit typing of variables submitted at the start
    String formKey = null;
    StartFormData startFormData = activitiProcessEngine.getFormService().getStartFormData(processDefinitionId);
    if (startFormData != null)
    {
        formKey = startFormData.getFormKey();
    }
    
    TypeDefinition startTaskTypeDefinition = getWorkflowFactory().getTaskFullTypeDefinition(formKey, true);
    
    // Convert raw variables to Variable objects
    List<Variable> resultingVariables = restVariableHelper.getVariables(variables, startTaskTypeDefinition);
    result = CollectionWithPagingInfo.asPaged(paging, resultingVariables);
    return result;
}
 
Example 11
Source File: WorkspaceController.java    From lemon with Apache License 2.0 4 votes vote down vote up
@RequestMapping("workspace-copyProcessInstance")
public String copyProcessInstance(
        @RequestParam("processInstanceId") String processInstanceId)
        throws Exception {
    // 复制流程
    // 1. 从历史获取businessKey
    HistoricProcessInstance historicProcessInstance = processEngine
            .getHistoryService().createHistoricProcessInstanceQuery()
            .processInstanceId(processInstanceId).singleResult();
    String businessKey = historicProcessInstance.getBusinessKey();
    String processDefinitionId = historicProcessInstance
            .getProcessDefinitionId();

    // 2. 从businessKey获取keyvalue
    // Record original = keyValueConnector.findByCode(businessKey);
    ModelInfoDTO original = modelConnector.findByCode(businessKey);

    // 3. 找到流程的第一个form
    FormDTO formDto = this.processConnector
            .findStartForm(processDefinitionId);

    List<String> fieldNames = new ArrayList<String>();

    if (formDto.isExists()) {
        String content = formDto.getContent();
        logger.debug("content : {}", content);

        Map<String, Object> formJson = jsonMapper.fromJson(
                formDto.getContent(), Map.class);
        List<Map<String, Object>> sections = (List<Map<String, Object>>) formJson
                .get("sections");

        for (Map<String, Object> section : sections) {
            if (!"grid".equals(section.get("type"))) {
                continue;
            }

            List<Map<String, Object>> fields = (List<Map<String, Object>>) section
                    .get("fields");

            for (Map<String, Object> field : fields) {
                logger.debug("field : {}", field);

                String type = (String) field.get("type");
                String name = (String) field.get("name");
                String label = name;

                if ("label".equals(type)) {
                    continue;
                }

                // if (formField != null) {
                // continue;
                // }
                fieldNames.add(name);
            }
        }
    }

    logger.debug("fieldNames : {}", fieldNames);

    // 4. 使用第一个form复制数据,后续的审批意见数据之类的不要复制
    // Record record = keyValueConnector.copyRecord(original, fieldNames);
    ModelInfoDTO modelInfoDto = modelConnector.copyModel(original,
            fieldNames);

    // 5. 跳转到草稿箱
    return "redirect:/operation/process-operation-listDrafts.do";
}
 
Example 12
Source File: CustomProcessDiagramGenerator.java    From lemon with Apache License 2.0 4 votes vote down vote up
public InputStream generateDiagram(String processInstanceId)
        throws IOException {
    HistoricProcessInstance historicProcessInstance = Context
            .getCommandContext().getHistoricProcessInstanceEntityManager()
            .findHistoricProcessInstance(processInstanceId);
    String processDefinitionId = historicProcessInstance
            .getProcessDefinitionId();
    GetBpmnModelCmd getBpmnModelCmd = new GetBpmnModelCmd(
            processDefinitionId);
    BpmnModel bpmnModel = getBpmnModelCmd.execute(Context
            .getCommandContext());

    // Point point = getMinXAndMinY(bpmnModel);
    // this.minX = point.x;
    // this.minY = point.y;
    // this.minX = (this.minX <= 5) ? 5 : this.minX;
    // this.minY = (this.minY <= 5) ? 5 : this.minY;
    // this.minX -= 5;
    // this.minY -= 5;
    ProcessDefinitionEntity definition = new GetDeploymentProcessDefinitionCmd(
            processDefinitionId).execute(Context.getCommandContext());
    String diagramResourceName = definition.getDiagramResourceName();
    String deploymentId = definition.getDeploymentId();
    byte[] bytes = Context
            .getCommandContext()
            .getResourceEntityManager()
            .findResourceByDeploymentIdAndResourceName(deploymentId,
                    diagramResourceName).getBytes();
    InputStream originDiagram = new ByteArrayInputStream(bytes);
    BufferedImage image = ImageIO.read(originDiagram);

    HistoricActivityInstanceQueryImpl historicActivityInstanceQueryImpl = new HistoricActivityInstanceQueryImpl();
    historicActivityInstanceQueryImpl.processInstanceId(processInstanceId)
            .orderByHistoricActivityInstanceStartTime().asc();

    Page page = new Page(0, 100);
    List<HistoricActivityInstance> activityInstances = Context
            .getCommandContext()
            .getHistoricActivityInstanceEntityManager()
            .findHistoricActivityInstancesByQueryCriteria(
                    historicActivityInstanceQueryImpl, page);

    this.drawHistoryFlow(image, processInstanceId);

    for (HistoricActivityInstance historicActivityInstance : activityInstances) {
        String historicActivityId = historicActivityInstance
                .getActivityId();
        ActivityImpl activity = definition.findActivity(historicActivityId);

        if (activity != null) {
            if (historicActivityInstance.getEndTime() == null) {
                // 节点正在运行中
                signRunningNode(image, activity.getX() - this.minX,
                        activity.getY() - this.minY, activity.getWidth(),
                        activity.getHeight(),
                        historicActivityInstance.getActivityType());
            } else {
                String deleteReason = null;

                if (historicActivityInstance.getTaskId() != null) {
                    deleteReason = Context
                            .getCommandContext()
                            .getHistoricTaskInstanceEntityManager()
                            .findHistoricTaskInstanceById(
                                    historicActivityInstance.getTaskId())
                            .getDeleteReason();
                }

                // 节点已经结束
                if ("跳过".equals(deleteReason)) {
                    signSkipNode(image, activity.getX() - this.minX,
                            activity.getY() - this.minY,
                            activity.getWidth(), activity.getHeight(),
                            historicActivityInstance.getActivityType());
                } else {
                    signHistoryNode(image, activity.getX() - this.minX,
                            activity.getY() - this.minY,
                            activity.getWidth(), activity.getHeight(),
                            historicActivityInstance.getActivityType());
                }
            }
        }
    }

    ByteArrayOutputStream out = new ByteArrayOutputStream();
    String formatName = getDiagramExtension(diagramResourceName);
    ImageIO.write(image, formatName, out);

    return new ByteArrayInputStream(out.toByteArray());
}