org.activiti.engine.impl.HistoricActivityInstanceQueryImpl Java Examples

The following examples show how to use org.activiti.engine.impl.HistoricActivityInstanceQueryImpl. 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: ActivitiHistoryGraphBuilder.java    From lemon with Apache License 2.0 6 votes vote down vote up
public void fetchHistoricActivityInstances() {
    HistoricActivityInstanceQueryImpl historicActivityInstanceQueryImpl = new HistoricActivityInstanceQueryImpl();
    // historicActivityInstanceQueryImpl.processInstanceId(processInstanceId)
    // .orderByHistoricActivityInstanceStartTime().asc();
    // TODO: 如果用了uuid会造成这样排序出问题
    // 但是如果用startTime,可能出现因为处理速度太快,时间一样,导致次序颠倒的问题
    historicActivityInstanceQueryImpl.processInstanceId(processInstanceId)
            .orderByHistoricActivityInstanceId().asc();

    Page page = new Page(0, 100);
    historicActivityInstances = Context
            .getCommandContext()
            .getHistoricActivityInstanceEntityManager()
            .findHistoricActivityInstancesByQueryCriteria(
                    historicActivityInstanceQueryImpl, page);
}
 
Example #2
Source File: RollbackCmd.java    From lemon with Apache License 2.0 6 votes vote down vote up
public HistoricActivityInstanceEntity getHistoricActivityInstanceEntity(
        String historyTaskId) {
    logger.info("historyTaskId : {}", historyTaskId);

    JdbcTemplate jdbcTemplate = ApplicationContextHelper
            .getBean(JdbcTemplate.class);
    String historicActivityInstanceId = jdbcTemplate.queryForObject(
            "select id_ from ACT_HI_ACTINST where task_id_=?",
            String.class, historyTaskId);
    logger.info("historicActivityInstanceId : {}",
            historicActivityInstanceId);

    HistoricActivityInstanceQueryImpl historicActivityInstanceQueryImpl = new HistoricActivityInstanceQueryImpl();
    historicActivityInstanceQueryImpl
            .activityInstanceId(historicActivityInstanceId);

    HistoricActivityInstanceEntity historicActivityInstanceEntity = (HistoricActivityInstanceEntity) Context
            .getCommandContext()
            .getHistoricActivityInstanceEntityManager()
            .findHistoricActivityInstancesByQueryCriteria(
                    historicActivityInstanceQueryImpl, new Page(0, 1))
            .get(0);

    return historicActivityInstanceEntity;
}
 
Example #3
Source File: WithdrawTaskCmd.java    From lemon with Apache License 2.0 6 votes vote down vote up
public HistoricActivityInstanceEntity getHistoricActivityInstanceEntity(
        String historyTaskId) {
    logger.info("historyTaskId : {}", historyTaskId);

    JdbcTemplate jdbcTemplate = ApplicationContextHelper
            .getBean(JdbcTemplate.class);
    String historicActivityInstanceId = jdbcTemplate.queryForObject(
            "select id_ from ACT_HI_ACTINST where task_id_=?",
            String.class, historyTaskId);
    logger.info("historicActivityInstanceId : {}",
            historicActivityInstanceId);

    HistoricActivityInstanceQueryImpl historicActivityInstanceQueryImpl = new HistoricActivityInstanceQueryImpl();
    historicActivityInstanceQueryImpl
            .activityInstanceId(historicActivityInstanceId);

    HistoricActivityInstanceEntity historicActivityInstanceEntity = (HistoricActivityInstanceEntity) Context
            .getCommandContext()
            .getHistoricActivityInstanceEntityManager()
            .findHistoricActivityInstancesByQueryCriteria(
                    historicActivityInstanceQueryImpl, new Page(0, 1))
            .get(0);

    return historicActivityInstanceEntity;
}
 
Example #4
Source File: CheckWithdrawTaskCmd.java    From lemon with Apache License 2.0 6 votes vote down vote up
public HistoricActivityInstanceEntity getHistoricActivityInstanceEntity(
        String historyTaskId) {
    logger.info("historyTaskId : {}", historyTaskId);

    JdbcTemplate jdbcTemplate = ApplicationContextHelper
            .getBean(JdbcTemplate.class);
    String historicActivityInstanceId = jdbcTemplate.queryForObject(
            "select id_ from ACT_HI_ACTINST where task_id_=?",
            String.class, historyTaskId);
    logger.info("historicActivityInstanceId : {}",
            historicActivityInstanceId);

    HistoricActivityInstanceQueryImpl historicActivityInstanceQueryImpl = new HistoricActivityInstanceQueryImpl();
    historicActivityInstanceQueryImpl
            .activityInstanceId(historicActivityInstanceId);

    HistoricActivityInstanceEntity historicActivityInstanceEntity = (HistoricActivityInstanceEntity) Context
            .getCommandContext()
            .getHistoricActivityInstanceEntityManager()
            .findHistoricActivityInstancesByQueryCriteria(
                    historicActivityInstanceQueryImpl, new Page(0, 1))
            .get(0);

    return historicActivityInstanceEntity;
}
 
Example #5
Source File: RollbackTaskCmd.java    From lemon with Apache License 2.0 6 votes vote down vote up
/**
 * 查询历史节点.
 */
public HistoricActivityInstanceEntity getHistoricActivityInstanceEntity(
        String historyTaskId) {
    logger.info("historyTaskId : {}", historyTaskId);

    JdbcTemplate jdbcTemplate = ApplicationContextHelper
            .getBean(JdbcTemplate.class);
    String historicActivityInstanceId = jdbcTemplate.queryForObject(
            "SELECT ID_ FROM ACT_HI_ACTINST WHERE TASK_ID_=?",
            String.class, historyTaskId);
    logger.info("historicActivityInstanceId : {}",
            historicActivityInstanceId);

    HistoricActivityInstanceQueryImpl historicActivityInstanceQueryImpl = new HistoricActivityInstanceQueryImpl();
    historicActivityInstanceQueryImpl
            .activityInstanceId(historicActivityInstanceId);

    HistoricActivityInstanceEntity historicActivityInstanceEntity = (HistoricActivityInstanceEntity) Context
            .getCommandContext()
            .getHistoricActivityInstanceEntityManager()
            .findHistoricActivityInstancesByQueryCriteria(
                    historicActivityInstanceQueryImpl, new Page(0, 1))
            .get(0);

    return historicActivityInstanceEntity;
}
 
Example #6
Source File: RollbackTaskCmd.java    From lemon with Apache License 2.0 6 votes vote down vote up
/**
 * 找到想要回退对应的节点历史.
 */
public HistoricActivityInstanceEntity findTargetHistoricActivity(
        CommandContext commandContext, TaskEntity taskEntity,
        ActivityImpl activityImpl) {
    HistoricActivityInstanceQueryImpl historicActivityInstanceQueryImpl = new HistoricActivityInstanceQueryImpl();
    historicActivityInstanceQueryImpl.activityId(activityImpl.getId());
    historicActivityInstanceQueryImpl.processInstanceId(taskEntity
            .getProcessInstanceId());
    historicActivityInstanceQueryImpl
            .orderByHistoricActivityInstanceEndTime().desc();

    HistoricActivityInstanceEntity historicActivityInstanceEntity = (HistoricActivityInstanceEntity) commandContext
            .getHistoricActivityInstanceEntityManager()
            .findHistoricActivityInstancesByQueryCriteria(
                    historicActivityInstanceQueryImpl, new Page(0, 1))
            .get(0);

    return historicActivityInstanceEntity;
}
 
Example #7
Source File: DefaultHistoryManager.java    From flowable-engine with Apache License 2.0 6 votes vote down vote up
@Override
@SuppressWarnings({ "unchecked", "rawtypes" })
public void recordExecutionReplacedBy(ExecutionEntity execution, InterpretableExecution replacedBy) {
    if (isHistoryLevelAtLeast(HistoryLevel.ACTIVITY)) {

        // Update the cached historic activity instances that are open
        List<HistoricActivityInstanceEntity> cachedHistoricActivityInstances = getDbSqlSession().findInCache(HistoricActivityInstanceEntity.class);
        for (HistoricActivityInstanceEntity cachedHistoricActivityInstance : cachedHistoricActivityInstances) {
            if ((cachedHistoricActivityInstance.getEndTime() == null)
                    && (execution.getId().equals(cachedHistoricActivityInstance.getExecutionId()))) {
                cachedHistoricActivityInstance.setExecutionId(replacedBy.getId());
            }
        }

        // Update the persisted historic activity instances that are open
        List<HistoricActivityInstanceEntity> historicActivityInstances = (List) new HistoricActivityInstanceQueryImpl(Context.getCommandContext())
                .executionId(execution.getId())
                .unfinished()
                .list();
        for (HistoricActivityInstanceEntity historicActivityInstance : historicActivityInstances) {
            historicActivityInstance.setExecutionId(replacedBy.getId());
        }
    }
}
 
Example #8
Source File: DefaultHistoryManager.java    From flowable-engine with Apache License 2.0 5 votes vote down vote up
protected HistoricActivityInstanceEntity findActivityInstance(ExecutionEntity execution, String activityId, boolean checkPersistentStore) {

        String executionId = execution.getId();

        // search for the historic activity instance in the dbsqlsession cache
        List<HistoricActivityInstanceEntity> cachedHistoricActivityInstances = getDbSqlSession()
                .findInCache(HistoricActivityInstanceEntity.class);
        for (HistoricActivityInstanceEntity cachedHistoricActivityInstance : cachedHistoricActivityInstances) {
            if (executionId.equals(cachedHistoricActivityInstance.getExecutionId())
                    && activityId != null
                    && (activityId.equals(cachedHistoricActivityInstance.getActivityId()))
                    && (cachedHistoricActivityInstance.getEndTime() == null)) {
                return cachedHistoricActivityInstance;
            }
        }

        List<HistoricActivityInstance> historicActivityInstances = null;
        if (checkPersistentStore) {
            historicActivityInstances = new HistoricActivityInstanceQueryImpl(Context.getCommandContext())
                    .executionId(executionId)
                    .activityId(activityId)
                    .unfinished()
                    .listPage(0, 1);
        }

        if (historicActivityInstances != null && !historicActivityInstances.isEmpty()) {
            return (HistoricActivityInstanceEntity) historicActivityInstances.get(0);
        }

        if (execution.getParentId() != null) {
            return findActivityInstance(execution.getParent(), activityId, checkPersistentStore);
        }

        return null;
    }
 
Example #9
Source File: HistoricActivityInstanceEntityManager.java    From flowable-engine with Apache License 2.0 4 votes vote down vote up
@SuppressWarnings("unchecked")
public List<HistoricActivityInstance> findHistoricActivityInstancesByQueryCriteria(HistoricActivityInstanceQueryImpl historicActivityInstanceQuery, Page page) {
    return getDbSqlSession().selectList("selectHistoricActivityInstancesByQueryCriteria", historicActivityInstanceQuery, page);
}
 
Example #10
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 #11
Source File: DbSqlSession.java    From flowable-engine with Apache License 2.0 4 votes vote down vote up
public HistoricActivityInstanceQueryImpl createHistoricActivityInstanceQuery() {
    return new HistoricActivityInstanceQueryImpl();
}
 
Example #12
Source File: HistoricActivityInstanceEntityManager.java    From flowable-engine with Apache License 2.0 4 votes vote down vote up
public long findHistoricActivityInstanceCountByQueryCriteria(HistoricActivityInstanceQueryImpl historicActivityInstanceQuery) {
    return (Long) getDbSqlSession().selectOne("selectHistoricActivityInstanceCountByQueryCriteria", historicActivityInstanceQuery);
}
 
Example #13
Source File: DbSqlSession.java    From activiti6-boot2 with Apache License 2.0 4 votes vote down vote up
public HistoricActivityInstanceQueryImpl createHistoricActivityInstanceQuery() {
  return new HistoricActivityInstanceQueryImpl();
}
 
Example #14
Source File: HistoricActivityInstanceEntityManagerImpl.java    From activiti6-boot2 with Apache License 2.0 4 votes vote down vote up
@Override
public List<HistoricActivityInstance> findHistoricActivityInstancesByQueryCriteria(HistoricActivityInstanceQueryImpl historicActivityInstanceQuery, Page page) {
  return historicActivityInstanceDataManager.findHistoricActivityInstancesByQueryCriteria(historicActivityInstanceQuery, page);
}
 
Example #15
Source File: HistoricActivityInstanceEntityManagerImpl.java    From activiti6-boot2 with Apache License 2.0 4 votes vote down vote up
@Override
public long findHistoricActivityInstanceCountByQueryCriteria(HistoricActivityInstanceQueryImpl historicActivityInstanceQuery) {
  return historicActivityInstanceDataManager.findHistoricActivityInstanceCountByQueryCriteria(historicActivityInstanceQuery);
}
 
Example #16
Source File: MybatisHistoricActivityInstanceDataManager.java    From activiti6-boot2 with Apache License 2.0 4 votes vote down vote up
@Override
@SuppressWarnings("unchecked")
public List<HistoricActivityInstance> findHistoricActivityInstancesByQueryCriteria(HistoricActivityInstanceQueryImpl historicActivityInstanceQuery, Page page) {
  return getDbSqlSession().selectList("selectHistoricActivityInstancesByQueryCriteria", historicActivityInstanceQuery, page);
}
 
Example #17
Source File: MybatisHistoricActivityInstanceDataManager.java    From activiti6-boot2 with Apache License 2.0 4 votes vote down vote up
@Override
public long findHistoricActivityInstanceCountByQueryCriteria(HistoricActivityInstanceQueryImpl historicActivityInstanceQuery) {
  return (Long) getDbSqlSession().selectOne("selectHistoricActivityInstanceCountByQueryCriteria", historicActivityInstanceQuery);
}
 
Example #18
Source File: HistoricActivityInstanceDataManager.java    From activiti6-boot2 with Apache License 2.0 votes vote down vote up
long findHistoricActivityInstanceCountByQueryCriteria(HistoricActivityInstanceQueryImpl historicActivityInstanceQuery); 
Example #19
Source File: HistoricActivityInstanceEntityManager.java    From activiti6-boot2 with Apache License 2.0 votes vote down vote up
List<HistoricActivityInstance> findHistoricActivityInstancesByQueryCriteria(HistoricActivityInstanceQueryImpl historicActivityInstanceQuery, Page page); 
Example #20
Source File: HistoricActivityInstanceEntityManager.java    From activiti6-boot2 with Apache License 2.0 votes vote down vote up
long findHistoricActivityInstanceCountByQueryCriteria(HistoricActivityInstanceQueryImpl historicActivityInstanceQuery); 
Example #21
Source File: HistoricActivityInstanceDataManager.java    From activiti6-boot2 with Apache License 2.0 votes vote down vote up
List<HistoricActivityInstance> findHistoricActivityInstancesByQueryCriteria(HistoricActivityInstanceQueryImpl historicActivityInstanceQuery, Page page);