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

The following examples show how to use org.activiti.engine.history.HistoricProcessInstance#getEndTime() . 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: AbstractProcessInstanceResource.java    From activiti6-boot2 with Apache License 2.0 6 votes vote down vote up
public void deleteProcessInstance(String processInstanceId) {

    User currentUser = SecurityUtils.getCurrentUserObject();

    HistoricProcessInstance processInstance = historyService.createHistoricProcessInstanceQuery()
        .processInstanceId(processInstanceId)
        .startedBy(String.valueOf(currentUser.getId())) // Permission
        .singleResult();

    if (processInstance == null) {
      throw new NotFoundException("Process with id: " + processInstanceId + " does not exist or is not started by this user");
    }

    if (processInstance.getEndTime() != null) {
      // Check if a hard delete of process instance is allowed
      if (!permissionService.canDeleteProcessInstance(currentUser, processInstance)) {
        throw new NotFoundException("Process with id: " + processInstanceId + " is already completed and can't be deleted");
      }

      // Delete cascade behavior in separate service to share a single transaction for all nested service-calls
      processInstanceService.deleteProcessInstance(processInstanceId);

    } else {
      runtimeService.deleteProcessInstance(processInstanceId, "Cancelled by " + SecurityUtils.getCurrentUserId());
    }
  }
 
Example 2
Source File: DeleteHistoricProcessInstanceCmd.java    From activiti6-boot2 with Apache License 2.0 6 votes vote down vote up
public Object execute(CommandContext commandContext) {
  if (processInstanceId == null) {
    throw new ActivitiIllegalArgumentException("processInstanceId is null");
  }
  // Check if process instance is still running
  HistoricProcessInstance instance = commandContext.getHistoricProcessInstanceEntityManager().findById(processInstanceId);

  if (instance == null) {
    throw new ActivitiObjectNotFoundException("No historic process instance found with id: " + processInstanceId, HistoricProcessInstance.class);
  }
  if (instance.getEndTime() == null) {
    throw new ActivitiException("Process instance is still running, cannot delete historic process instance: " + processInstanceId);
  }

  if (Activiti5Util.isActiviti5ProcessDefinitionId(commandContext, instance.getProcessDefinitionId())) {
    Activiti5CompatibilityHandler activiti5CompatibilityHandler = Activiti5Util.getActiviti5CompatibilityHandler(); 
    activiti5CompatibilityHandler.deleteHistoricProcessInstance(processInstanceId);
    return null;
  }
  
  commandContext.getHistoricProcessInstanceEntityManager().delete(processInstanceId);

  return null;
}
 
Example 3
Source File: ActivitiTypeConverter.java    From alfresco-repository with GNU Lesser General Public License v3.0 6 votes vote down vote up
public WorkflowInstance convertToInstanceAndSetVariables(HistoricProcessInstance historicProcessInstance, Map<String, Object> collectedVariables)
{
    String processInstanceId = historicProcessInstance.getId();
    String id = processInstanceId;
    ProcessDefinition procDef = activitiUtil.getProcessDefinition(historicProcessInstance.getProcessDefinitionId());
    WorkflowDefinition definition = convert(procDef);
    
    // Set process variables based on historic detail query
    Map<String, Object> variables = propertyConverter.getHistoricProcessVariables(processInstanceId);
    
    Date startDate = historicProcessInstance.getStartTime();
    Date endDate = historicProcessInstance.getEndTime();

    // Copy all variables to map, if not null
    if(collectedVariables != null)
    {
    	collectedVariables.putAll(variables);
    }
    boolean isActive = endDate == null;
    return factory.createInstance(id, definition, variables, isActive, startDate, endDate);
}
 
Example 4
Source File: DeleteHistoricProcessInstanceCmd.java    From flowable-engine with Apache License 2.0 6 votes vote down vote up
@Override
public Object execute(CommandContext commandContext) {
    if (processInstanceId == null) {
        throw new ActivitiIllegalArgumentException("processInstanceId is null");
    }
    // Check if process instance is still running
    HistoricProcessInstance instance = commandContext
            .getHistoricProcessInstanceEntityManager()
            .findHistoricProcessInstance(processInstanceId);

    if (instance == null) {
        throw new ActivitiObjectNotFoundException("No historic process instance found with id: " + processInstanceId, HistoricProcessInstance.class);
    }
    if (instance.getEndTime() == null) {
        throw new ActivitiException("Process instance is still running, cannot delete historic process instance: " + processInstanceId);
    }

    commandContext
            .getHistoricProcessInstanceEntityManager()
            .deleteHistoricProcessInstanceById(processInstanceId);

    return null;
}
 
Example 5
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 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: ProcessInstanceHighlightsResource.java    From hsweb-framework with Apache License 2.0 5 votes vote down vote up
@GetMapping(value = "/process-instance/{processInstanceId}/highlights", produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
public Object getHighlighted(@PathVariable String processInstanceId) {

    JSONObject responseJSON = new JSONObject();

    responseJSON.put("processInstanceId", processInstanceId);

    JSONArray activitiesArray = new JSONArray();
    JSONArray flowsArray = new JSONArray();

    HistoricProcessInstance processInstance = historyService.createHistoricProcessInstanceQuery()
            .processInstanceId(processInstanceId)
            .singleResult();
    ProcessDefinitionEntity processDefinition = (ProcessDefinitionEntity) repositoryService
            .getProcessDefinition(processInstance.getProcessDefinitionId());

    responseJSON.put("processDefinitionId", processInstance.getProcessDefinitionId());
    List<String> highLightedActivities;
    if (processInstance.getEndTime() != null) {
        highLightedActivities = historyService
                .createHistoricActivityInstanceQuery()
                .processInstanceId(processInstanceId)
                .activityType("endEvent")
                .list().stream().map(HistoricActivityInstance::getActivityId)
                .collect(Collectors.toList());
    } else {
        highLightedActivities = runtimeService.getActiveActivityIds(processInstanceId);
    }
    List<String> highLightedFlows = getHighLightedFlows(processDefinition, processInstanceId);

    activitiesArray.addAll(highLightedActivities);

    flowsArray.addAll(highLightedFlows);


    responseJSON.put("activities", activitiesArray);
    responseJSON.put("flows", flowsArray);

    return responseJSON;
}
 
Example 8
Source File: ActivitiTypeConverter.java    From alfresco-repository with GNU Lesser General Public License v3.0 4 votes vote down vote up
private WorkflowTask getVirtualStartTask(HistoricProcessInstance historicProcessInstance)
{
    if(historicProcessInstance == null)
    {
        return null;
    }
    String processInstanceId = historicProcessInstance.getId();

    if (!activitiUtil.isMultiTenantWorkflowDeploymentEnabled() && false == isCorrectTenantHistoric(processInstanceId))
    {
        return null;
    }
    
    String id = ActivitiConstants.START_TASK_PREFIX + processInstanceId;
    
    // Since the process instance is complete the Start Task must be complete!
    WorkflowTaskState state = WorkflowTaskState.COMPLETED;

    // We use the process-instance ID as execution-id. It's ended anyway
    WorkflowPath path  = buildCompletedPath(processInstanceId, processInstanceId);
    if(path == null)
    {
        return null;
    }
    
    // Convert start-event to start-task Node
    ReadOnlyProcessDefinition procDef = activitiUtil.getDeployedProcessDefinition(historicProcessInstance.getProcessDefinitionId());
    WorkflowNode startNode = convert(procDef.getInitial(), true);
    
    String taskDefId = activitiUtil.getStartFormKey(historicProcessInstance.getProcessDefinitionId());
    WorkflowTaskDefinition taskDef = factory.createTaskDefinition(taskDefId, startNode, taskDefId, true);
    
    boolean completed = historicProcessInstance.getEndTime() != null;
    Map<QName, Serializable> properties = propertyConverter.getStartTaskProperties(historicProcessInstance, taskDefId, completed);
    
    // TODO: Figure out what name/description should be used for the start-task, start event's name?
    String defaultTitle = null;
    String defaultDescription = null;
    
    return factory.createTask(id,
                taskDef, taskDef.getId(), defaultTitle, defaultDescription, state, path, properties);
}
 
Example 9
Source File: WorkspaceController.java    From lemon with Apache License 2.0 4 votes vote down vote up
/**
 * 查看历史【包含流程跟踪、任务列表(完成和未完成)、流程变量】.
 */
@RequestMapping("workspace-viewHistory")
public String viewHistory(
        @RequestParam("processInstanceId") String processInstanceId,
        Model model) {
    String userId = currentUserHolder.getUserId();
    HistoryService historyService = processEngine.getHistoryService();
    HistoricProcessInstance historicProcessInstance = historyService
            .createHistoricProcessInstanceQuery()
            .processInstanceId(processInstanceId).singleResult();

    if (userId.equals(historicProcessInstance.getStartUserId())) {
        // startForm
    }

    List<HistoricTaskInstance> historicTasks = historyService
            .createHistoricTaskInstanceQuery()
            .processInstanceId(processInstanceId).list();
    // List<HistoricVariableInstance> historicVariableInstances = historyService
    // .createHistoricVariableInstanceQuery()
    // .processInstanceId(processInstanceId).list();
    model.addAttribute("historicTasks", historicTasks);

    // 获取流程对应的所有人工任务(目前还没有区分历史)
    List<HumanTaskDTO> humanTasks = humanTaskConnector
            .findHumanTasksByProcessInstanceId(processInstanceId);
    List<HumanTaskDTO> humanTaskDtos = new ArrayList<HumanTaskDTO>();

    for (HumanTaskDTO humanTaskDto : humanTasks) {
        if (humanTaskDto.getParentId() != null) {
            continue;
        }

        humanTaskDtos.add(humanTaskDto);
    }

    model.addAttribute("humanTasks", humanTaskDtos);
    // model.addAttribute("historicVariableInstances",
    // historicVariableInstances);
    model.addAttribute("nodeDtos",
            traceService.traceProcessInstance(processInstanceId));
    model.addAttribute("historyActivities", processEngine
            .getHistoryService().createHistoricActivityInstanceQuery()
            .processInstanceId(processInstanceId).list());

    if (historicProcessInstance.getEndTime() == null) {
        model.addAttribute("currentActivities", processEngine
                .getRuntimeService()
                .getActiveActivityIds(processInstanceId));
    } else {
        model.addAttribute("currentActivities", Collections
                .singletonList(historicProcessInstance.getEndActivityId()));
    }

    Graph graph = processEngine.getManagementService().executeCommand(
            new FindHistoryGraphCmd(processInstanceId));
    model.addAttribute("graph", graph);
    model.addAttribute("historicProcessInstance", historicProcessInstance);

    return "bpm/workspace-viewHistory";
}
 
Example 10
Source File: ViewService.java    From lemon with Apache License 2.0 4 votes vote down vote up
public ProcessBaseInfo findProcess(String processInstanceId) {
    HistoryService historyService = processEngine.getHistoryService();
    HistoricProcessInstance historicProcessInstance = historyService
            .createHistoricProcessInstanceQuery()
            .processInstanceId(processInstanceId).singleResult();
    ProcessDefinition processDefinition = processEngine
            .getRepositoryService()
            .createProcessDefinitionQuery()
            .processDefinitionId(
                    historicProcessInstance.getProcessDefinitionId())
            .singleResult();

    ProcessBaseInfo processBaseInfo = new ProcessBaseInfo();
    processBaseInfo
            .setBusinessKey(historicProcessInstance.getBusinessKey());
    processBaseInfo.setId(processInstanceId);
    processBaseInfo.setCode(processDefinition.getKey());
    processBaseInfo.setName(processDefinition.getName());
    processBaseInfo.setUserId(historicProcessInstance.getStartUserId());
    processBaseInfo.setStartTime(historicProcessInstance.getStartTime());

    if (historicProcessInstance.getEndTime() == null) {
        processBaseInfo.setStatus("active");
    } else {
        processBaseInfo.setStatus("end");
    }

    List<String> userIds = new ArrayList<String>();
    List<String> activityNames = new ArrayList<String>();
    List<Task> tasks = processEngine.getTaskService().createTaskQuery()
            .processInstanceId(processInstanceId).list();

    for (Task task : tasks) {
        userIds.add(task.getAssignee());
        activityNames.add(task.getName());
    }

    processBaseInfo.setAssignee(StringUtils.join(userIds, ","));
    processBaseInfo.setActivityName(StringUtils.join(activityNames, ","));

    return processBaseInfo;
}
 
Example 11
Source File: ViewService.java    From lemon with Apache License 2.0 4 votes vote down vote up
public List<Map<String, String>> findProcessToolbar(String processInstanceId) {
    HistoryService historyService = processEngine.getHistoryService();
    HistoricProcessInstance historicProcessInstance = historyService
            .createHistoricProcessInstanceQuery()
            .processInstanceId(processInstanceId).singleResult();
    boolean isEnd = historicProcessInstance.getEndTime() != null;
    List<Map<String, String>> buttons = new ArrayList<Map<String, String>>();

    if (isEnd) {
        // this.addButton(buttons, "复制",
        // "/workspace-copyProcessInstance.do?processInstanceId="
        // + processInstanceId);
        // this.addButton(buttons, "转发", "javascript:void(0);doTransfer('"
        // + processInstanceId + "')");
        this.addButton(buttons, "复制", "taskOperation.copyProcess()");
        this.addButton(buttons, "转发", "taskOperation.transferProcess()");
    } else {
        // this.addButton(buttons, "终止",
        // "/bpm/workspace-endProcessInstance.do?processInstanceId="
        // + processInstanceId + "&userId=&comment=");
        // this.addButton(buttons, "催办",
        // "/bpm/workspace-remind.do?processInstanceId="
        // + processInstanceId + "&userId=&comment=");
        // 跳过风险太高了,想明白了再加
        // this.addButton(buttons, "跳过",
        // "/bpm/workspace-skip.do?processInstanceId="
        // + processInstanceId + "&userId=&comment=");
        // if (couldProcessWithdraw(processInstanceId)) {
        // this.addButton(buttons, "撤销",
        // "/bpm/workspace-withdraw.do?processInstanceId="
        // + processInstanceId + "&userId=&comment=");
        // }
        this.addButton(buttons, "终止", "taskOperation.endProcess()");
        this.addButton(buttons, "催办", "taskOperation.remind()");
        this.addButton(buttons, "跳过", "taskOperation.skip()");

        if (couldProcessWithdraw(processInstanceId)) {
            this.addButton(buttons, "撤销", "taskOperation.withdrawProcess()");
        }
    }

    return buttons;
}