org.activiti.engine.impl.persistence.entity.HistoricProcessInstanceEntity Java Examples

The following examples show how to use org.activiti.engine.impl.persistence.entity.HistoricProcessInstanceEntity. 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: SkipTaskListener.java    From lemon with Apache License 2.0 6 votes vote down vote up
public void processPosition(DelegateTask delegateTask, String value) {
    String processInstanceId = delegateTask.getProcessInstanceId();
    HistoricProcessInstanceEntity historicProcessInstanceEntity = Context
            .getCommandContext().getHistoricProcessInstanceEntityManager()
            .findHistoricProcessInstance(processInstanceId);
    String initiator = historicProcessInstanceEntity.getStartUserId();
    OrgConnector orgConnector = (OrgConnector) ApplicationContextHelper
            .getBean(OrgConnector.class);

    // 获得发起人的职位
    int initiatorLevel = orgConnector.getJobLevelByUserId(initiator);

    // 获得审批人的职位
    int assigneeLevel = orgConnector.getJobLevelByUserId(delegateTask
            .getAssignee());

    // 比较
    if (initiatorLevel >= assigneeLevel) {
        logger.info("skip task : {}", delegateTask.getId());
        logger.info("initiatorLevel : {}, assigneeLevel : {}",
                initiatorLevel, assigneeLevel);
        new CompleteTaskWithCommentCmd(delegateTask.getId(),
                Collections.<String, Object> emptyMap(), "高级职位自动跳过")
                .execute(Context.getCommandContext());
    }
}
 
Example #2
Source File: DefaultHistoryManager.java    From activiti6-boot2 with Apache License 2.0 6 votes vote down vote up
@Override
public void recordProcessInstanceEnd(String processInstanceId, String deleteReason, String activityId) {

  if (isHistoryLevelAtLeast(HistoryLevel.ACTIVITY)) {
    HistoricProcessInstanceEntity historicProcessInstance = getHistoricProcessInstanceEntityManager().findById(processInstanceId);

    if (historicProcessInstance != null) {
      historicProcessInstance.markEnded(deleteReason);
      historicProcessInstance.setEndActivityId(activityId);
      
      // Fire event
      ActivitiEventDispatcher activitiEventDispatcher = getEventDispatcher();
      if (activitiEventDispatcher != null && activitiEventDispatcher.isEnabled()) {
        activitiEventDispatcher.dispatchEvent(
            ActivitiEventBuilder.createEntityEvent(ActivitiEventType.HISTORIC_PROCESS_INSTANCE_ENDED, historicProcessInstance));
      }
      
    }
  }
}
 
Example #3
Source File: DefaultHistoryManager.java    From activiti6-boot2 with Apache License 2.0 6 votes vote down vote up
@Override
public void recordProcessInstanceStart(ExecutionEntity processInstance, FlowElement startElement) {
  if (isHistoryLevelAtLeast(HistoryLevel.ACTIVITY)) {
    HistoricProcessInstanceEntity historicProcessInstance = getHistoricProcessInstanceEntityManager().create(processInstance); 
    historicProcessInstance.setStartActivityId(startElement.getId());

    // Insert historic process-instance
    getHistoricProcessInstanceEntityManager().insert(historicProcessInstance, false);
    
    // Fire event
    ActivitiEventDispatcher activitiEventDispatcher = getEventDispatcher();
    if (activitiEventDispatcher != null && activitiEventDispatcher.isEnabled()) {
      activitiEventDispatcher.dispatchEvent(
          ActivitiEventBuilder.createEntityEvent(ActivitiEventType.HISTORIC_PROCESS_INSTANCE_CREATED, historicProcessInstance));
    }

  }
}
 
Example #4
Source File: DefaultHistoryManager.java    From activiti6-boot2 with Apache License 2.0 6 votes vote down vote up
@Override
public void recordSubProcessInstanceStart(ExecutionEntity parentExecution, ExecutionEntity subProcessInstance, FlowElement initialElement) {
  if (isHistoryLevelAtLeast(HistoryLevel.ACTIVITY)) {

    HistoricProcessInstanceEntity historicProcessInstance = getHistoricProcessInstanceEntityManager().create(subProcessInstance); 

    // Fix for ACT-1728: startActivityId not initialized with subprocess instance
    if (historicProcessInstance.getStartActivityId() == null) {
      historicProcessInstance.setStartActivityId(initialElement.getId());
    }
    getHistoricProcessInstanceEntityManager().insert(historicProcessInstance, false);
    
    // Fire event
    ActivitiEventDispatcher activitiEventDispatcher = getEventDispatcher();
    if (activitiEventDispatcher != null && activitiEventDispatcher.isEnabled()) {
      activitiEventDispatcher.dispatchEvent(
          ActivitiEventBuilder.createEntityEvent(ActivitiEventType.HISTORIC_PROCESS_INSTANCE_CREATED, historicProcessInstance));
    }

    HistoricActivityInstanceEntity activitiyInstance = findActivityInstance(parentExecution, false, true);
    if (activitiyInstance != null) {
      activitiyInstance.setCalledProcessInstanceId(subProcessInstance.getProcessInstanceId());
    }

  }
}
 
Example #5
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 #6
Source File: HistoricProcessInstanceVariableDataResource.java    From activiti6-boot2 with Apache License 2.0 6 votes vote down vote up
public RestVariable getVariableFromRequest(boolean includeBinary, String processInstanceId, String variableName, HttpServletRequest request) {

    HistoricProcessInstance processObject = historyService.createHistoricProcessInstanceQuery().processInstanceId(processInstanceId).includeProcessVariables().singleResult();

    if (processObject == null) {
      throw new ActivitiObjectNotFoundException("Historic process instance '" + processInstanceId + "' couldn't be found.", HistoricProcessInstanceEntity.class);
    }

    Object value = processObject.getProcessVariables().get(variableName);

    if (value == null) {
      throw new ActivitiObjectNotFoundException("Historic process instance '" + processInstanceId + "' variable value for " + variableName + " couldn't be found.", VariableInstanceEntity.class);
    } else {
      return restResponseFactory.createRestVariable(variableName, value, null, processInstanceId, RestResponseFactory.VARIABLE_HISTORY_PROCESS, includeBinary);
    }
  }
 
Example #7
Source File: DefaultHistoryManager.java    From flowable-engine with Apache License 2.0 6 votes vote down vote up
@Override
public void recordProcessInstanceEnd(String processInstanceId, String deleteReason, String activityId) {

    if (isHistoryLevelAtLeast(HistoryLevel.ACTIVITY)) {
        HistoricProcessInstanceEntity historicProcessInstance = getHistoricProcessInstanceManager()
                .findHistoricProcessInstance(processInstanceId);

        if (historicProcessInstance != null) {
            historicProcessInstance.markEnded(deleteReason);
            historicProcessInstance.setEndActivityId(activityId);

            // Fire event
            ProcessEngineConfigurationImpl config = Context.getProcessEngineConfiguration();
            if (config != null && config.getEventDispatcher().isEnabled()) {
                config.getEventDispatcher().dispatchEvent(
                        ActivitiEventBuilder.createEntityEvent(FlowableEngineEventType.HISTORIC_PROCESS_INSTANCE_ENDED, historicProcessInstance));
            }
        }
    }
}
 
Example #8
Source File: DefaultHistoryManager.java    From flowable-engine with Apache License 2.0 5 votes vote down vote up
@Override
public void recordProcessInstanceNameChange(String processInstanceId, String newName) {
    if (isHistoryLevelAtLeast(HistoryLevel.ACTIVITY)) {
        HistoricProcessInstanceEntity historicProcessInstance = getHistoricProcessInstanceManager()
                .findHistoricProcessInstance(processInstanceId);

        if (historicProcessInstance != null) {
            historicProcessInstance.setName(newName);
        }
    }
}
 
Example #9
Source File: ReOpenProcessCmd.java    From lemon with Apache License 2.0 5 votes vote down vote up
public Void execute(CommandContext commandContext) {
    HistoricProcessInstanceEntity historicProcessInstanceEntity = commandContext
            .getHistoricProcessInstanceEntityManager()
            .findHistoricProcessInstance(historicProcessInstanceId);

    if (historicProcessInstanceEntity.getEndTime() == null) {
        logger.info("historicProcessInstanceId is running");

        return null;
    }

    historicProcessInstanceEntity.setEndActivityId(null);
    historicProcessInstanceEntity.setEndTime(null);

    String processDefinitionId = historicProcessInstanceEntity
            .getProcessDefinitionId();
    String initiator = historicProcessInstanceEntity.getStartUserId();
    String businessKey = historicProcessInstanceEntity.getBusinessKey();

    ProcessDefinitionEntity processDefinition = new GetDeploymentProcessDefinitionCmd(
            processDefinitionId).execute(commandContext);

    // ExecutionEntity processInstance = processDefinition
    // .createProcessInstance(businessKey);
    ExecutionEntity processInstance = this.createProcessInstance(
            historicProcessInstanceEntity.getId(), businessKey, initiator,
            processDefinition);

    try {
        Authentication.setAuthenticatedUserId(initiator);
        // start
        processInstance.start();
    } finally {
        Authentication.setAuthenticatedUserId(null);
    }

    return null;
}
 
Example #10
Source File: SkipEventListener.java    From lemon with Apache License 2.0 5 votes vote down vote up
public void processExpression(DelegateTask delegateTask, String value) {
    UserConnector userConnector = ApplicationContextHelper
            .getBean(UserConnector.class);
    ExpressionManager expressionManager = Context
            .getProcessEngineConfiguration().getExpressionManager();
    String processInstanceId = delegateTask.getProcessInstanceId();
    HistoricProcessInstanceEntity historicProcessInstanceEntity = Context
            .getCommandContext().getHistoricProcessInstanceEntityManager()
            .findHistoricProcessInstance(processInstanceId);
    String initiator = historicProcessInstanceEntity.getStartUserId();
    MapVariableScope mapVariableScope = new MapVariableScope();
    mapVariableScope.setVariable("initiator",
            userConnector.findById(initiator));

    Object objectResult = expressionManager.createExpression(value)
            .getValue(mapVariableScope);

    if ((objectResult == null) || (!(objectResult instanceof Boolean))) {
        logger.error("{} is not Boolean, just return", objectResult);

        return;
    }

    Boolean result = (Boolean) objectResult;

    logger.info("value : {}, result : {}", value, result);

    if (result) {
        logger.info("skip task : {}", delegateTask.getId());
        // new CompleteTaskWithCommentCmd(delegateTask.getId(),
        // Collections.<String, Object> emptyMap(), "跳过")
        // .execute(Context.getCommandContext());
        this.doSkip(delegateTask);
    }
}
 
Example #11
Source File: SkipEventListener.java    From lemon with Apache License 2.0 5 votes vote down vote up
public void processPosition(DelegateTask delegateTask, String value) {
    String processInstanceId = delegateTask.getProcessInstanceId();
    HistoricProcessInstanceEntity historicProcessInstanceEntity = Context
            .getCommandContext().getHistoricProcessInstanceEntityManager()
            .findHistoricProcessInstance(processInstanceId);
    String initiator = historicProcessInstanceEntity.getStartUserId();
    OrgConnector orgConnector = (OrgConnector) ApplicationContextHelper
            .getBean(OrgConnector.class);

    // 获得发起人的职位
    int initiatorLevel = orgConnector.getJobLevelByUserId(initiator);

    // 获得审批人的职位
    int assigneeLevel = orgConnector.getJobLevelByUserId(delegateTask
            .getAssignee());

    // 比较
    if (initiatorLevel >= assigneeLevel) {
        logger.info("skip task : {}", delegateTask.getId());
        logger.info("initiatorLevel : {}, assigneeLevel : {}",
                initiatorLevel, assigneeLevel);
        // new CompleteTaskWithCommentCmd(delegateTask.getId(),
        // Collections.<String, Object> emptyMap(), "高级职位自动跳过")
        // .execute(Context.getCommandContext());
        this.doSkip(delegateTask);
    }
}
 
Example #12
Source File: SkipEventListener.java    From lemon with Apache License 2.0 5 votes vote down vote up
public void onCreate(DelegateTask delegateTask) throws Exception {
    String taskDefinitionKey = delegateTask.getTaskDefinitionKey();
    String processDefinitionId = delegateTask.getProcessDefinitionId();
    String processInstanceId = delegateTask.getProcessInstanceId();
    HistoricProcessInstanceEntity historicProcessInstanceEntity = Context
            .getCommandContext().getHistoricProcessInstanceEntityManager()
            .findHistoricProcessInstance(processInstanceId);

    List<BpmConfRule> bpmConfRules = ApplicationContextHelper
            .getBean(BpmConfRuleManager.class)
            .find("from BpmConfRule where bpmConfNode.bpmConfBase.processDefinitionId=? and bpmConfNode.code=?",
                    processDefinitionId, taskDefinitionKey);
    logger.debug("delegateTask.getId : {}", delegateTask.getId());
    logger.debug("taskDefinitionKey : {}", taskDefinitionKey);
    logger.debug("processDefinitionId : {}", processDefinitionId);
    logger.debug("processInstanceId : {}", processInstanceId);
    logger.debug("bpmConfRules : {}", bpmConfRules);

    for (BpmConfRule bpmConfRule : bpmConfRules) {
        String value = bpmConfRule.getValue();

        if ("职位".equals(value) || "高级职位自动跳过".equals(value)) {
            this.processPosition(delegateTask, value);
        } else if ("相邻相同人员自动跳过".equals(value)) {
            this.processNeighbor(delegateTask, value);
        } else {
            this.processExpression(delegateTask, value);
        }
    }
}
 
Example #13
Source File: SkipTaskListener.java    From lemon with Apache License 2.0 5 votes vote down vote up
public void processExpression(DelegateTask delegateTask, String value) {
    UserConnector userConnector = ApplicationContextHelper
            .getBean(UserConnector.class);
    ExpressionManager expressionManager = Context
            .getProcessEngineConfiguration().getExpressionManager();
    String processInstanceId = delegateTask.getProcessInstanceId();
    HistoricProcessInstanceEntity historicProcessInstanceEntity = Context
            .getCommandContext().getHistoricProcessInstanceEntityManager()
            .findHistoricProcessInstance(processInstanceId);
    String initiator = historicProcessInstanceEntity.getStartUserId();
    MapVariableScope mapVariableScope = new MapVariableScope();
    mapVariableScope.setVariable("initiator",
            userConnector.findById(initiator));

    Object objectResult = expressionManager.createExpression(value)
            .getValue(mapVariableScope);

    if ((objectResult == null) || (!(objectResult instanceof Boolean))) {
        logger.error("{} is not Boolean, just return", objectResult);

        return;
    }

    Boolean result = (Boolean) objectResult;

    logger.info("value : {}, result : {}", value, result);

    if (result) {
        logger.info("skip task : {}", delegateTask.getId());
        new CompleteTaskWithCommentCmd(delegateTask.getId(),
                Collections.<String, Object> emptyMap(), "跳过")
                .execute(Context.getCommandContext());
    }
}
 
Example #14
Source File: SkipTaskListener.java    From lemon with Apache License 2.0 5 votes vote down vote up
@Override
public void onCreate(DelegateTask delegateTask) throws Exception {
    String taskDefinitionKey = delegateTask.getTaskDefinitionKey();
    String processDefinitionId = delegateTask.getProcessDefinitionId();
    String processInstanceId = delegateTask.getProcessInstanceId();
    HistoricProcessInstanceEntity historicProcessInstanceEntity = Context
            .getCommandContext().getHistoricProcessInstanceEntityManager()
            .findHistoricProcessInstance(processInstanceId);

    List<BpmConfRule> bpmConfRules = ApplicationContextHelper
            .getBean(BpmConfRuleManager.class)
            .find("from BpmConfRule where bpmConfNode.bpmConfBase.processDefinitionId=? and bpmConfNode.code=?",
                    processDefinitionId, taskDefinitionKey);
    logger.debug("delegateTask.getId : {}", delegateTask.getId());
    logger.debug("taskDefinitionKey : {}", taskDefinitionKey);
    logger.debug("processDefinitionId : {}", processDefinitionId);
    logger.debug("processInstanceId : {}", processInstanceId);
    logger.debug("bpmConfRules : {}", bpmConfRules);

    for (BpmConfRule bpmConfRule : bpmConfRules) {
        String value = bpmConfRule.getValue();

        if ("职位".equals(value) || "高级职位自动跳过".equals(value)) {
            this.processPosition(delegateTask, value);
        } else if ("相邻相同人员自动跳过".equals(value)) {
            this.processNeighbor(delegateTask, value);
        } else {
            this.processExpression(delegateTask, value);
        }
    }
}
 
Example #15
Source File: DefaultHistoryManager.java    From flowable-engine with Apache License 2.0 5 votes vote down vote up
@Override
public void updateProcessBusinessKeyInHistory(ExecutionEntity processInstance) {
    if (isHistoryEnabled()) {
        if (LOGGER.isDebugEnabled()) {
            LOGGER.debug("updateProcessBusinessKeyInHistory : {}", processInstance.getId());
        }
        if (processInstance != null) {
            HistoricProcessInstanceEntity historicProcessInstance = getDbSqlSession().selectById(HistoricProcessInstanceEntity.class, processInstance.getId());
            if (historicProcessInstance != null) {
                historicProcessInstance.setBusinessKey(processInstance.getProcessBusinessKey());
                getDbSqlSession().update(historicProcessInstance);
            }
        }
    }
}
 
Example #16
Source File: DefaultHistoryManager.java    From flowable-engine with Apache License 2.0 5 votes vote down vote up
@Override
public void recordProcessDefinitionChange(String processInstanceId, String processDefinitionId) {
    if (isHistoryLevelAtLeast(HistoryLevel.ACTIVITY)) {
        HistoricProcessInstanceEntity historicProcessInstance = getHistoricProcessInstanceManager().findHistoricProcessInstance(processInstanceId);
        if (historicProcessInstance != null) {
            historicProcessInstance.setProcessDefinitionId(processDefinitionId);
        }
    }
}
 
Example #17
Source File: DefaultHistoryManager.java    From activiti6-boot2 with Apache License 2.0 5 votes vote down vote up
@Override
public void updateProcessBusinessKeyInHistory(ExecutionEntity processInstance) {
  if (isHistoryEnabled()) {
    if (log.isDebugEnabled()) {
      log.debug("updateProcessBusinessKeyInHistory : {}", processInstance.getId());
    }
    if (processInstance != null) {
      HistoricProcessInstanceEntity historicProcessInstance = getHistoricProcessInstanceEntityManager().findById(processInstance.getId());
      if (historicProcessInstance != null) {
        historicProcessInstance.setBusinessKey(processInstance.getProcessInstanceBusinessKey());
        getHistoricProcessInstanceEntityManager().update(historicProcessInstance, false);
      }
    }
  }
}
 
Example #18
Source File: DefaultHistoryManager.java    From activiti6-boot2 with Apache License 2.0 5 votes vote down vote up
@Override
public void recordProcessDefinitionChange(String processInstanceId, String processDefinitionId) {
  if (isHistoryLevelAtLeast(HistoryLevel.ACTIVITY)) {
    HistoricProcessInstanceEntity historicProcessInstance = getHistoricProcessInstanceEntityManager().findById(processInstanceId);
    if (historicProcessInstance != null) {
      historicProcessInstance.setProcessDefinitionId(processDefinitionId);
    }
  }
}
 
Example #19
Source File: DefaultHistoryManager.java    From activiti6-boot2 with Apache License 2.0 5 votes vote down vote up
@Override
public void recordProcessInstanceNameChange(String processInstanceId, String newName) {
  if (isHistoryLevelAtLeast(HistoryLevel.ACTIVITY)) {
    HistoricProcessInstanceEntity historicProcessInstance = getHistoricProcessInstanceEntityManager().findById(processInstanceId);

    if (historicProcessInstance != null) {
      historicProcessInstance.setName(newName);
    }
  }
}
 
Example #20
Source File: MybatisHistoricProcessInstanceDataManager.java    From activiti6-boot2 with Apache License 2.0 4 votes vote down vote up
@Override
@SuppressWarnings("unchecked")
public List<HistoricProcessInstanceEntity> findHistoricProcessInstancesBySuperProcessInstanceId(String superProcessInstanceId) {
  return getDbSqlSession().selectList("selectHistoricProcessInstanceIdsBySuperProcessInstanceId", superProcessInstanceId);
}
 
Example #21
Source File: TimeoutNotice.java    From lemon with Apache License 2.0 4 votes vote down vote up
public void processTimeout(DelegateTask delegateTask,
        BpmConfNotice bpmConfNotice) {
    try {
        Date dueDate = delegateTask.getDueDate();
        Calendar calendar = Calendar.getInstance();
        calendar.setTime(dueDate);

        DatatypeFactory datatypeFactory = DatatypeFactory.newInstance();
        Duration duration = datatypeFactory.newDuration("-"
                + bpmConfNotice.getDueDate());
        duration.addTo(calendar);

        Date noticeDate = calendar.getTime();
        Date now = new Date();

        if ((now.getTime() < noticeDate.getTime())
                && ((noticeDate.getTime() - now.getTime()) < (60 * 1000))) {
            UserConnector userConnector = ApplicationContextHelper
                    .getBean(UserConnector.class);
            NotificationConnector notificationConnector = ApplicationContextHelper
                    .getBean(NotificationConnector.class);

            //
            Map<String, Object> data = new HashMap<String, Object>();
            TaskEntity taskEntity = new TaskEntity();
            taskEntity.setId(delegateTask.getId());
            taskEntity.setName(delegateTask.getName());
            taskEntity.setAssigneeWithoutCascade(userConnector.findById(
                    delegateTask.getAssignee()).getDisplayName());
            taskEntity.setVariableLocal("initiator",
                    getInitiator(userConnector, delegateTask));
            //
            data.put("task", taskEntity);
            data.put("initiator",
                    this.getInitiator(userConnector, delegateTask));

            String receiver = bpmConfNotice.getReceiver();

            /*
             * BpmMailTemplate bpmMailTemplate = bpmConfNotice .getBpmMailTemplate(); ExpressionManager
             * expressionManager = Context .getProcessEngineConfiguration().getExpressionManager();
             */
            UserDTO userDto = null;

            if ("任务接收人".equals(receiver)) {
                userDto = userConnector
                        .findById(delegateTask.getAssignee());
            } else if ("流程发起人".equals(receiver)) {
                userDto = userConnector.findById((String) delegateTask
                        .getVariables().get("initiator"));
            } else {
                HistoricProcessInstanceEntity historicProcessInstanceEntity = Context
                        .getCommandContext()
                        .getHistoricProcessInstanceEntityManager()
                        .findHistoricProcessInstance(
                                delegateTask.getProcessInstanceId());
                userDto = userConnector
                        .findById(historicProcessInstanceEntity
                                .getStartUserId());
            }

            /*
             * String subject = expressionManager .createExpression(bpmMailTemplate.getSubject())
             * .getValue(taskEntity).toString();
             * 
             * String content = expressionManager .createExpression(bpmMailTemplate.getContent())
             * .getValue(taskEntity).toString();
             * 
             * this.sendMail(userDto, subject, content); this.sendSiteMessage(userDto, subject, content);
             */
            NotificationDTO notificationDto = new NotificationDTO();
            notificationDto.setReceiver(userDto.getId());
            notificationDto.setReceiverType("userid");
            notificationDto.setTypes(Arrays.asList(bpmConfNotice
                    .getNotificationType().split(",")));
            notificationDto.setData(data);
            notificationDto.setTemplate(bpmConfNotice.getTemplateCode());

            notificationConnector.send(notificationDto,
                    delegateTask.getTenantId());
        }
    } catch (Exception ex) {
        logger.error(ex.getMessage(), ex);
    }
}
 
Example #22
Source File: ArrivalNotice.java    From lemon with Apache License 2.0 4 votes vote down vote up
public void processArrival(DelegateTask delegateTask,
        BpmConfNotice bpmConfNotice) {
    UserConnector userConnector = ApplicationContextHelper
            .getBean(UserConnector.class);
    NotificationConnector notificationConnector = ApplicationContextHelper
            .getBean(NotificationConnector.class);

    //
    Map<String, Object> data = new HashMap<String, Object>();

    TaskEntity taskEntity = new TaskEntity();
    taskEntity.setId(delegateTask.getId());
    taskEntity.setName(delegateTask.getName());
    taskEntity.setAssigneeWithoutCascade(userConnector.findById(
            delegateTask.getAssignee()).getDisplayName());
    taskEntity.setVariableLocal("initiator",
            getInitiator(userConnector, delegateTask));
    logger.debug("initiator : {}", delegateTask.getVariable("initator"));
    logger.debug("variables : {}", delegateTask.getVariables());
    //
    data.put("task", taskEntity);
    data.put("initiator", this.getInitiator(userConnector, delegateTask));

    String receiver = bpmConfNotice.getReceiver();

    /*
     * BpmMailTemplate bpmMailTemplate = bpmConfNotice.getBpmMailTemplate(); ExpressionManager expressionManager =
     * Context .getProcessEngineConfiguration().getExpressionManager();
     */
    UserDTO userDto = null;

    /*
     * String subject = expressionManager .createExpression(bpmMailTemplate.getSubject())
     * .getValue(taskEntity).toString();
     * 
     * String content = expressionManager .createExpression(bpmMailTemplate.getContent())
     * .getValue(taskEntity).toString();
     */
    if ("任务接收人".equals(receiver)) {
        userDto = userConnector.findById(delegateTask.getAssignee());
    } else if ("流程发起人".equals(receiver)) {
        userDto = userConnector.findById((String) delegateTask
                .getVariables().get("initiator"));
    } else {
        HistoricProcessInstanceEntity historicProcessInstanceEntity = Context
                .getCommandContext()
                .getHistoricProcessInstanceEntityManager()
                .findHistoricProcessInstance(
                        delegateTask.getProcessInstanceId());
        userDto = userConnector.findById(historicProcessInstanceEntity
                .getStartUserId());
    }

    // this.sendMail(userDto, subject, content);
    // this.sendSiteMessage(userDto, subject, content);
    NotificationDTO notificationDto = new NotificationDTO();
    notificationDto.setReceiver(userDto.getId());
    notificationDto.setReceiverType("userid");
    notificationDto.setTypes(Arrays.asList(bpmConfNotice
            .getNotificationType().split(",")));
    notificationDto.setData(data);
    notificationDto.setTemplate(bpmConfNotice.getTemplateCode());
    notificationConnector.send(notificationDto, delegateTask.getTenantId());
}
 
Example #23
Source File: CompleteNotice.java    From lemon with Apache License 2.0 4 votes vote down vote up
public void processComplete(DelegateTask delegateTask,
        BpmConfNotice bpmConfNotice) {
    UserConnector userConnector = ApplicationContextHelper
            .getBean(UserConnector.class);
    NotificationConnector notificationConnector = ApplicationContextHelper
            .getBean(NotificationConnector.class);

    //
    Map<String, Object> data = new HashMap<String, Object>();
    TaskEntity taskEntity = new TaskEntity();
    taskEntity.setId(delegateTask.getId());
    taskEntity.setName(delegateTask.getName());
    taskEntity.setAssigneeWithoutCascade(userConnector.findById(
            delegateTask.getAssignee()).getDisplayName());
    taskEntity.setVariableLocal("initiator",
            getInitiator(userConnector, delegateTask));

    //
    data.put("task", taskEntity);
    data.put("initiator", this.getInitiator(userConnector, delegateTask));

    String receiver = bpmConfNotice.getReceiver();

    /*
     * BpmMailTemplate bpmMailTemplate = bpmConfNotice.getBpmMailTemplate(); ExpressionManager expressionManager =
     * Context .getProcessEngineConfiguration().getExpressionManager();
     */
    UserDTO userDto = null;

    if ("任务接收人".equals(receiver)) {
        userDto = userConnector.findById(delegateTask.getAssignee());
    } else if ("流程发起人".equals(receiver)) {
        userDto = userConnector.findById((String) delegateTask
                .getVariables().get("initiator"));
    } else {
        HistoricProcessInstanceEntity historicProcessInstanceEntity = Context
                .getCommandContext()
                .getHistoricProcessInstanceEntityManager()
                .findHistoricProcessInstance(
                        delegateTask.getProcessInstanceId());
        userDto = userConnector.findById(historicProcessInstanceEntity
                .getStartUserId());
    }

    /*
     * String subject = expressionManager .createExpression(bpmMailTemplate.getSubject())
     * .getValue(taskEntity).toString();
     * 
     * String content = expressionManager .createExpression(bpmMailTemplate.getContent())
     * .getValue(taskEntity).toString(); this.sendMail(userDto, subject, content); this.sendSiteMessage(userDto,
     * subject, content);
     */
    NotificationDTO notificationDto = new NotificationDTO();
    notificationDto.setReceiver(userDto.getId());
    notificationDto.setReceiverType("userid");
    notificationDto.setTypes(Arrays.asList(bpmConfNotice
            .getNotificationType().split(",")));
    notificationDto.setData(data);
    notificationDto.setTemplate(bpmConfNotice.getTemplateCode());
    notificationConnector.send(notificationDto, delegateTask.getTenantId());
}
 
Example #24
Source File: UpdateProcessInstanceNameEventListener.java    From lemon with Apache License 2.0 4 votes vote down vote up
protected void onInitialized(ActivitiEvent event) {
    if (!(event instanceof ActivitiEntityEventImpl)) {
        return;
    }

    ActivitiEntityEventImpl activitiEntityEventImpl = (ActivitiEntityEventImpl) event;
    Object entity = activitiEntityEventImpl.getEntity();

    if (!(entity instanceof ExecutionEntity)) {
        return;
    }

    ActivitiEventType activitiEventType = activitiEntityEventImpl.getType();

    if (activitiEventType != ActivitiEventType.ENTITY_INITIALIZED) {
        return;
    }

    ExecutionEntity executionEntity = (ExecutionEntity) entity;

    if (!executionEntity.isProcessInstanceType()) {
        return;
    }

    String processInstanceId = executionEntity.getId();
    String processDefinitionId = executionEntity.getProcessDefinitionId();
    CommandContext commandContext = Context.getCommandContext();
    ProcessDefinitionEntity processDefinition = new GetDeploymentProcessDefinitionCmd(
            processDefinitionId).execute(commandContext);

    // {流程标题:title}-{发起人:startUser}-{发起时间:startTime}
    String processDefinitionName = processDefinition.getName();

    if (processDefinitionName == null) {
        processDefinitionName = processDefinition.getKey();
    }

    String userId = Authentication.getAuthenticatedUserId();
    String displayName = userConnector.findById(userId).getDisplayName();
    String processInstanceName = processDefinitionName + "-" + displayName
            + "-"
            + new SimpleDateFormat("yyyy-MM-dd HH:mm").format(new Date());
    // runtime
    executionEntity.setName(processInstanceName);

    // history
    HistoricProcessInstanceEntity historicProcessInstanceEntity = commandContext
            .getHistoricProcessInstanceEntityManager()
            .findHistoricProcessInstance(processInstanceId);
    historicProcessInstanceEntity.setName(processInstanceName);
}
 
Example #25
Source File: MybatisHistoricProcessInstanceDataManager.java    From activiti6-boot2 with Apache License 2.0 4 votes vote down vote up
@Override
public Class<? extends HistoricProcessInstanceEntity> getManagedEntityClass() {
  return HistoricProcessInstanceEntityImpl.class;
}
 
Example #26
Source File: MybatisHistoricProcessInstanceDataManager.java    From activiti6-boot2 with Apache License 2.0 4 votes vote down vote up
@Override
public HistoricProcessInstanceEntity create() {
  return new HistoricProcessInstanceEntityImpl();
}
 
Example #27
Source File: MybatisHistoricProcessInstanceDataManager.java    From activiti6-boot2 with Apache License 2.0 4 votes vote down vote up
@Override
public HistoricProcessInstanceEntity create(ExecutionEntity processInstanceExecutionEntity) {
  return new HistoricProcessInstanceEntityImpl(processInstanceExecutionEntity);
}
 
Example #28
Source File: ProcessInstanceHistoryLogQueryImpl.java    From flowable-engine with Apache License 2.0 4 votes vote down vote up
@Override
public ProcessInstanceHistoryLog execute(CommandContext commandContext) {

    // Fetch historic process instance
    HistoricProcessInstanceEntity historicProcessInstance = commandContext
            .getHistoricProcessInstanceEntityManager().findHistoricProcessInstance(processInstanceId);

    if (historicProcessInstance == null) {
        return null;
    }

    // Create a log using this historic process instance
    ProcessInstanceHistoryLogImpl processInstanceHistoryLog = new ProcessInstanceHistoryLogImpl(historicProcessInstance);

    // Add events, based on query settings

    // Tasks
    if (includeTasks) {
        List<? extends HistoricData> tasks = commandContext.getHistoricTaskInstanceEntityManager()
                .findHistoricTaskInstancesByQueryCriteria(
                        new HistoricTaskInstanceQueryImpl(commandExecutor).processInstanceId(processInstanceId));
        processInstanceHistoryLog.addHistoricData(tasks);
    }

    // Activities
    if (includeActivities) {
        List<HistoricActivityInstance> activities = commandContext.getHistoricActivityInstanceEntityManager()
                .findHistoricActivityInstancesByQueryCriteria(
                        new HistoricActivityInstanceQueryImpl(commandExecutor).processInstanceId(processInstanceId), null);
        processInstanceHistoryLog.addHistoricData(activities);
    }

    // Variables
    if (includeVariables) {
        List<HistoricVariableInstance> variables = commandContext.getHistoricVariableInstanceEntityManager()
                .findHistoricVariableInstancesByQueryCriteria(
                        new HistoricVariableInstanceQueryImpl(commandExecutor).processInstanceId(processInstanceId), null);

        // Make sure all variables values are fetched (similar to the HistoricVariableInstance query)
        for (HistoricVariableInstance historicVariableInstance : variables) {
            historicVariableInstance.getValue();

            // make sure JPA entities are cached for later retrieval
            HistoricVariableInstanceEntity variableEntity = (HistoricVariableInstanceEntity) historicVariableInstance;
            if (JPAEntityVariableType.TYPE_NAME.equals(variableEntity.getVariableType().getTypeName()) || JPAEntityListVariableType.TYPE_NAME.equals(variableEntity.getVariableType().getTypeName())) {
                ((CacheableVariable) variableEntity.getVariableType()).setForceCacheable(true);
            }
        }

        processInstanceHistoryLog.addHistoricData(variables);
    }

    // Comment
    if (includeComments) {
        List<? extends HistoricData> comments = commandContext.getCommentEntityManager().findCommentsByProcessInstanceId(processInstanceId);
        processInstanceHistoryLog.addHistoricData(comments);
    }

    // Details: variables
    if (includeVariableUpdates) {
        List<? extends HistoricData> variableUpdates = commandContext.getHistoricDetailEntityManager()
                .findHistoricDetailsByQueryCriteria(new HistoricDetailQueryImpl(commandExecutor).variableUpdates(), null);

        // Make sure all variables values are fetched (similar to the HistoricVariableInstance query)
        for (HistoricData historicData : variableUpdates) {
            HistoricVariableUpdate variableUpdate = (HistoricVariableUpdate) historicData;
            variableUpdate.getValue();
        }

        processInstanceHistoryLog.addHistoricData(variableUpdates);
    }

    // Details: form properties
    if (includeFormProperties) {
        List<? extends HistoricData> formProperties = commandContext.getHistoricDetailEntityManager()
                .findHistoricDetailsByQueryCriteria(new HistoricDetailQueryImpl(commandExecutor).formProperties(), null);
        processInstanceHistoryLog.addHistoricData(formProperties);
    }

    // All events collected. Sort them by date.
    processInstanceHistoryLog.orderHistoricData();

    return processInstanceHistoryLog;
}
 
Example #29
Source File: ProcessInstanceHistoryLogQueryImpl.java    From activiti6-boot2 with Apache License 2.0 4 votes vote down vote up
@Override
public ProcessInstanceHistoryLog execute(CommandContext commandContext) {

  // Fetch historic process instance
  HistoricProcessInstanceEntity historicProcessInstance = commandContext.getHistoricProcessInstanceEntityManager().findById(processInstanceId);

  if (historicProcessInstance == null) {
    return null;
  }

  // Create a log using this historic process instance
  ProcessInstanceHistoryLogImpl processInstanceHistoryLog = new ProcessInstanceHistoryLogImpl(historicProcessInstance);

  // Add events, based on query settings

  // Tasks
  if (includeTasks) {
    List<? extends HistoricData> tasks = commandContext.getHistoricTaskInstanceEntityManager().findHistoricTaskInstancesByQueryCriteria(
        new HistoricTaskInstanceQueryImpl(commandExecutor).processInstanceId(processInstanceId));
    processInstanceHistoryLog.addHistoricData(tasks);
  }

  // Activities
  if (includeActivities) {
    List<HistoricActivityInstance> activities = commandContext.getHistoricActivityInstanceEntityManager().findHistoricActivityInstancesByQueryCriteria(
        new HistoricActivityInstanceQueryImpl(commandExecutor).processInstanceId(processInstanceId), null);
    processInstanceHistoryLog.addHistoricData(activities);
  }

  // Variables
  if (includeVariables) {
    List<HistoricVariableInstance> variables = commandContext.getHistoricVariableInstanceEntityManager().findHistoricVariableInstancesByQueryCriteria(
        new HistoricVariableInstanceQueryImpl(commandExecutor).processInstanceId(processInstanceId), null);
    
    // Make sure all variables values are fetched (similar to the HistoricVariableInstance query)
    for (HistoricVariableInstance historicVariableInstance : variables) {
      historicVariableInstance.getValue();
      
      // make sure JPA entities are cached for later retrieval
      HistoricVariableInstanceEntity variableEntity = (HistoricVariableInstanceEntity) historicVariableInstance;
      if (JPAEntityVariableType.TYPE_NAME.equals(variableEntity.getVariableType().getTypeName()) || JPAEntityListVariableType.TYPE_NAME.equals(variableEntity.getVariableType().getTypeName())) {
        ((CacheableVariable) variableEntity.getVariableType()).setForceCacheable(true);
      }
    }
    
    processInstanceHistoryLog.addHistoricData(variables);
  }

  // Comment
  if (includeComments) {
    List<? extends HistoricData> comments = commandContext.getCommentEntityManager().findCommentsByProcessInstanceId(processInstanceId);
    processInstanceHistoryLog.addHistoricData(comments);
  }

  // Details: variables
  if (includeVariableUpdates) {
    List<? extends HistoricData> variableUpdates = commandContext.getHistoricDetailEntityManager().findHistoricDetailsByQueryCriteria(
        new HistoricDetailQueryImpl(commandExecutor).variableUpdates(), null);
    
    // Make sure all variables values are fetched (similar to the HistoricVariableInstance query)
    for (HistoricData historicData : variableUpdates) {
      HistoricVariableUpdate variableUpdate = (HistoricVariableUpdate) historicData;
      variableUpdate.getValue();
    }
    
    processInstanceHistoryLog.addHistoricData(variableUpdates);
  }

  // Details: form properties
  if (includeFormProperties) {
    List<? extends HistoricData> formProperties = commandContext.getHistoricDetailEntityManager().findHistoricDetailsByQueryCriteria(
        new HistoricDetailQueryImpl(commandExecutor).formProperties(), null);
    processInstanceHistoryLog.addHistoricData(formProperties);
  }

  // All events collected. Sort them by date.
  processInstanceHistoryLog.orderHistoricData();

  return processInstanceHistoryLog;
}
 
Example #30
Source File: JobServiceGetJobsTest.java    From herd with Apache License 2.0 4 votes vote down vote up
@SuppressWarnings("unchecked")
@Test
public void testGetJobsGivenOneRunningJobAssertReturnCompletedJob() throws Exception
{
    String namespace = "namespace";
    String jobName = "jobName";
    JobStatusEnum jobStatus = JobStatusEnum.RUNNING;
    long expectedNumberOfExceptions = 1234l;

    Set<String> authorizedNamespaces = new HashSet<>(Arrays.asList(namespace));
    when(namespaceSecurityHelper.getAuthorizedNamespaces(any())).thenReturn(authorizedNamespaces);

    NamespaceEntity namespaceEntity = new NamespaceEntity();
    namespaceEntity.setCode(namespace);
    when(namespaceDao.getNamespaceByCd(any())).thenReturn(namespaceEntity);

    List<JobDefinitionEntity> jobDefinitionEntities = new ArrayList<>();
    JobDefinitionEntity jobDefinitionEntity1 = new JobDefinitionEntity();
    jobDefinitionEntity1.setActivitiId(namespace + "." + jobName + ":1" + ":1");
    jobDefinitionEntities.add(jobDefinitionEntity1);
    when(jobDefinitionDao.getJobDefinitionsByFilter(any(Collection.class), any())).thenReturn(jobDefinitionEntities);

    ProcessDefinition processDefinition = mock(ProcessDefinition.class);
    when(processDefinition.getId()).thenReturn("a.b:1:1");
    when(processDefinition.getKey()).thenReturn("a.b");
    when(activitiService.getProcessDefinitionsByIds(any())).thenReturn(asList(processDefinition));

    when(activitiService.getHistoricProcessInstancesCountByStatusAndProcessDefinitionKeys(any(), any(), any(), any())).thenReturn(1l);
    List<HistoricProcessInstance> historicProcessInstances = new ArrayList<>();
    HistoricProcessInstanceEntity historicProcessInstanceEntity1 = new HistoricProcessInstanceEntity();
    historicProcessInstanceEntity1.setId("historicProcessInstanceEntity1.id");
    historicProcessInstanceEntity1.setProcessDefinitionId("a.b:1:1");
    historicProcessInstanceEntity1.setStartTime(new Date(1234));
    historicProcessInstances.add(historicProcessInstanceEntity1);
    when(activitiService.getHistoricProcessInstancesByStatusAndProcessDefinitionKeys(any(), any(), any(), any())).thenReturn(historicProcessInstances);

    when(activitiService.getJobsWithExceptionCountByProcessInstanceId(any())).thenReturn(expectedNumberOfExceptions);

    JobSummaries getJobsResult = jobServiceImpl.getJobs(namespace, jobName, jobStatus, NO_START_TIME, NO_END_TIME);

    List<JobSummary> jobSummaries = getJobsResult.getJobSummaries();
    assertEquals(1, jobSummaries.size());
    JobSummary jobSummary = jobSummaries.get(0);
    assertEquals(historicProcessInstanceEntity1.getId(), jobSummary.getId());
    assertEquals("a", jobSummary.getNamespace());
    assertEquals("b", jobSummary.getJobName());
    assertEquals(JobStatusEnum.RUNNING, jobSummary.getStatus());
    assertEquals(historicProcessInstanceEntity1.getStartTime().getTime(), jobSummary.getStartTime().toGregorianCalendar().getTimeInMillis());
    assertNull(jobSummary.getEndTime());
    assertEquals(expectedNumberOfExceptions, jobSummary.getTotalExceptions());

    verify(activitiService).getJobsWithExceptionCountByProcessInstanceId(historicProcessInstanceEntity1.getId());
    verify(activitiService).getHistoricProcessInstancesCountByStatusAndProcessDefinitionKeys(eq(JobStatusEnum.RUNNING), any(), any(), any());
    verify(activitiService).getHistoricProcessInstancesByStatusAndProcessDefinitionKeys(eq(JobStatusEnum.RUNNING), any(), any(), any());
}