org.activiti.engine.impl.cmd.GetBpmnModelCmd Java Examples

The following examples show how to use org.activiti.engine.impl.cmd.GetBpmnModelCmd. 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: DynamicBpmnServiceImpl.java    From flowable-engine with Apache License 2.0 6 votes vote down vote up
@Override
public DynamicProcessDefinitionSummary getDynamicProcessDefinitionSummary(String processDefinitionId) {
    ObjectNode infoNode = getProcessDefinitionInfo(processDefinitionId);
    ObjectMapper objectMapper = processEngineConfiguration.getObjectMapper();
    BpmnModel bpmnModel = commandExecutor.execute(new GetBpmnModelCmd(processDefinitionId));

    // aggressive exception. this method should not be called if the process definition does not exists.
    if (bpmnModel == null) {
        throw new ActivitiException("ProcessDefinition " + processDefinitionId + " does not exists");
    }

    // to avoid redundant null checks we create an new node
    if (infoNode == null) {
        infoNode = processEngineConfiguration.getObjectMapper().createObjectNode();
        createOrGetBpmnNode(infoNode);
    }

    return new DynamicProcessDefinitionSummary(bpmnModel, infoNode, objectMapper);
}
 
Example #2
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 #3
Source File: UpdateProcessCmd.java    From lemon with Apache License 2.0 5 votes vote down vote up
public Void execute(CommandContext commandContext) {
    ProcessDefinitionEntity processDefinitionEntity = commandContext
            .getProcessDefinitionEntityManager().findProcessDefinitionById(
                    processDefinitionId);
    String resourceName = processDefinitionEntity.getResourceName();
    String deploymentId = processDefinitionEntity.getDeploymentId();
    JdbcTemplate jdbcTemplate = new JdbcTemplate(Context
            .getProcessEngineConfiguration().getDataSource());
    jdbcTemplate
            .update("update ACT_GE_BYTEARRAY set BYTES_=? where NAME_=? and DEPLOYMENT_ID_=?",
                    bytes, resourceName, deploymentId);

    Context.getProcessEngineConfiguration().getProcessDefinitionCache()
            .remove(processDefinitionId);

    try {
        // update png
        GetBpmnModelCmd getBpmnModelCmd = new GetBpmnModelCmd(
                processDefinitionId);
        BpmnModel bpmnModel = getBpmnModelCmd.execute(commandContext);
        ProcessEngineConfiguration processEngineConfiguration = Context
                .getProcessEngineConfiguration();
        ProcessDefinitionDiagramCmd processDefinitionDiagramCmd = new ProcessDefinitionDiagramCmd(
                processDefinitionEntity.getId());
        InputStream is = processDefinitionDiagramCmd
                .execute(commandContext);
        byte[] pngBytes = IOUtils.toByteArray(is);
        String diagramResourceName = processDefinitionEntity
                .getDiagramResourceName();
        jdbcTemplate
                .update("update ACT_GE_BYTEARRAY set BYTES_=? where NAME_=? and DEPLOYMENT_ID_=?",
                        pngBytes, diagramResourceName, deploymentId);
    } catch (Exception ex) {
        logger.error(ex.getMessage(), ex);
    }

    return null;
}
 
Example #4
Source File: ProcessDefinitionDiagramCmd.java    From lemon with Apache License 2.0 5 votes vote down vote up
public InputStream execute(CommandContext commandContext) {
    ProcessDefinitionEntity processDefinition = new GetDeploymentProcessDefinitionCmd(
            processDefinitionId).execute(commandContext);
    String diagramResourceName = processDefinition.getDiagramResourceName();
    String deploymentId = processDefinition.getDeploymentId();

    if (deploymentId != null) {
        byte[] bytes = commandContext
                .getResourceEntityManager()
                .findResourceByDeploymentIdAndResourceName(deploymentId,
                        diagramResourceName).getBytes();
        InputStream inputStream = new ByteArrayInputStream(bytes);

        return inputStream;
    }

    GetBpmnModelCmd getBpmnModelCmd = new GetBpmnModelCmd(
            processDefinitionId);
    BpmnModel bpmnModel = getBpmnModelCmd.execute(commandContext);
    ProcessEngineConfiguration processEngineConfiguration = Context
            .getProcessEngineConfiguration();
    InputStream is = new DefaultProcessDiagramGenerator().generateDiagram(
            bpmnModel, "png",
            processEngineConfiguration.getActivityFontName(),
            processEngineConfiguration.getLabelFontName(), null);

    return is;
}
 
Example #5
Source File: RepositoryServiceImpl.java    From activiti6-boot2 with Apache License 2.0 4 votes vote down vote up
public BpmnModel getBpmnModel(String processDefinitionId) {
  return commandExecutor.execute(new GetBpmnModelCmd(processDefinitionId));
}
 
Example #6
Source File: RepositoryServiceImpl.java    From flowable-engine with Apache License 2.0 4 votes vote down vote up
@Override
public BpmnModel getBpmnModel(String processDefinitionId) {
    return commandExecutor.execute(new GetBpmnModelCmd(processDefinitionId));
}
 
Example #7
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());
}
 
Example #8
Source File: SyncProcessCmd.java    From lemon with Apache License 2.0 4 votes vote down vote up
public Void execute(CommandContext commandContext) {
    ProcessDefinitionEntity processDefinitionEntity = new GetDeploymentProcessDefinitionCmd(
            processDefinitionId).execute(commandContext);
    String processDefinitionKey = processDefinitionEntity.getKey();
    int processDefinitionVersion = processDefinitionEntity.getVersion();
    BpmConfBaseManager bpmConfBaseManager = getBpmConfBaseManager();
    BpmConfBase bpmConfBase = bpmConfBaseManager
            .findUnique(
                    "from BpmConfBase where processDefinitionKey=? and processDefinitionVersion=?",
                    processDefinitionKey, processDefinitionVersion);

    if (bpmConfBase == null) {
        bpmConfBase = new BpmConfBase();
        bpmConfBase.setProcessDefinitionId(processDefinitionId);
        bpmConfBase.setProcessDefinitionKey(processDefinitionKey);
        bpmConfBase.setProcessDefinitionVersion(processDefinitionVersion);
        bpmConfBaseManager.save(bpmConfBase);
    } else if (bpmConfBase.getProcessDefinitionId() == null) {
        bpmConfBase.setProcessDefinitionId(processDefinitionId);
        bpmConfBaseManager.save(bpmConfBase);
    }

    BpmnModel bpmnModel = new GetBpmnModelCmd(processDefinitionId)
            .execute(commandContext);
    Graph graph = new FindGraphCmd(processDefinitionId)
            .execute(commandContext);
    this.processGlobal(bpmnModel, 1, bpmConfBase);

    int priority = 2;

    for (Node node : graph.getNodes()) {
        if ("exclusiveGateway".equals(node.getType())) {
            continue;
        } else if ("userTask".equals(node.getType())) {
            this.processUserTask(node, bpmnModel, priority++, bpmConfBase);
        } else if ("startEvent".equals(node.getType())) {
            this.processStartEvent(node, bpmnModel, priority++, bpmConfBase);
        } else if ("endEvent".equals(node.getType())) {
            this.processEndEvent(node, bpmnModel, priority++, bpmConfBase);
        }
    }

    return null;
}