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

The following examples show how to use org.flowable.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: ProcessInstanceResource.java    From plumdo-work with Apache License 2.0 6 votes vote down vote up
@DeleteMapping(value = "/process-instances/{processInstanceId}", name = "流程实例删除")
@ResponseStatus(value = HttpStatus.NO_CONTENT)
public void deleteProcessInstance(@PathVariable String processInstanceId, @RequestParam(value = "deleteReason", required = false) String deleteReason, @RequestParam(value = "cascade", required = false) boolean cascade) {
    HistoricProcessInstance historicProcessInstance = getHistoricProcessInstanceFromRequest(processInstanceId);
    if (historicProcessInstance.getEndTime() != null) {
        historyService.deleteHistoricProcessInstance(historicProcessInstance.getId());
        return;
    }
    ExecutionEntity executionEntity = (ExecutionEntity) getProcessInstanceFromRequest(processInstanceId);
    if (ObjectUtils.isNotEmpty(executionEntity.getSuperExecutionId())) {
        exceptionFactory.throwForbidden(ErrorConstant.INSTANCE_HAVE_PARENT, processInstanceId);
    }

    runtimeService.deleteProcessInstance(processInstanceId, deleteReason);
    if (cascade) {
        historyService.deleteHistoricProcessInstance(processInstanceId);
    }
}
 
Example 2
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 FlowableIllegalArgumentException("processInstanceId is null");
    }
    // Check if process instance is still running
    HistoricProcessInstance instance = CommandContextUtil.getHistoricProcessInstanceEntityManager(commandContext).findById(processInstanceId);

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

    if (Flowable5Util.isFlowable5ProcessDefinitionId(commandContext, instance.getProcessDefinitionId())) {
        Flowable5CompatibilityHandler compatibilityHandler = Flowable5Util.getFlowable5CompatibilityHandler();
        compatibilityHandler.deleteHistoricProcessInstance(processInstanceId);
        return null;
    }

    CommandContextUtil.getHistoryManager(commandContext).recordProcessInstanceDeleted(processInstanceId, instance.getProcessDefinitionId(), instance.getTenantId());

    return null;
}
 
Example 3
Source File: FlowableFacade.java    From multiapps-controller with Apache License 2.0 5 votes vote down vote up
private boolean isActive(String processId) {
    HistoricProcessInstance processInstance = processEngine.getHistoryService()
                                                           .createHistoricProcessInstanceQuery()
                                                           .processInstanceId(processId)
                                                           .singleResult();
    return processInstance.getEndTime() == null;
}
 
Example 4
Source File: ProcessInstanceImageResource.java    From plumdo-work with Apache License 2.0 5 votes vote down vote up
@GetMapping(value = "/process-instances/{processInstanceId}/image", name = "流程实例流程图")
public ResponseEntity<byte[]> getProcessInstanceImage(@PathVariable String processInstanceId) {
    HistoricProcessInstance processInstance = getHistoricProcessInstanceFromRequest(processInstanceId);
    ProcessDefinition pde = repositoryService.getProcessDefinition(processInstance.getProcessDefinitionId());
    if (pde == null || !pde.hasGraphicalNotation()) {
        exceptionFactory.throwObjectNotFound(ErrorConstant.INSTANCE_IMAGE_NOT_FOUND, processInstance.getId());
    }

    List<String> highLightedActivities;
    if (processInstance.getEndTime() == null) {
        highLightedActivities = runtimeService.getActiveActivityIds(processInstance.getId());
    } else {
        highLightedActivities = Collections.emptyList();
    }

    BpmnModel bpmnModel = repositoryService.getBpmnModel(pde.getId());
    ProcessDiagramGenerator diagramGenerator = processEngineConfiguration.getProcessDiagramGenerator();

    InputStream resource = diagramGenerator.generateDiagram(bpmnModel, "png", highLightedActivities,
            Collections.emptyList(),
            processEngineConfiguration.getActivityFontName(),
            processEngineConfiguration.getLabelFontName(),
            processEngineConfiguration.getAnnotationFontName(),
            processEngineConfiguration.getClassLoader(), 1.0);

    HttpHeaders responseHeaders = new HttpHeaders();
    responseHeaders.setContentType(MediaType.IMAGE_PNG);
    try {
        return new ResponseEntity<>(IOUtils.toByteArray(resource), responseHeaders, HttpStatus.OK);
    } catch (Exception e) {
        exceptionFactory.throwDefinedException(ErrorConstant.INSTANCE_IMAGE_READ_ERROR, e.getMessage());
    }

    return null;
}
 
Example 5
Source File: ProcessInstanceVariableResource.java    From plumdo-work with Apache License 2.0 5 votes vote down vote up
@GetMapping(value = "/process-instances/{processInstanceId}/variables", name = "获取流程实例变量")
public List<RestVariable> getExecutionVariables(@PathVariable String processInstanceId) {
    HistoricProcessInstance processInstance = getHistoricProcessInstanceFromRequest(processInstanceId);
    if (processInstance.getEndTime() == null) {
        Map<String, Object> variables = runtimeService.getVariables(processInstance.getId());
        return restResponseFactory.createRestVariables(variables);
    } else {
        List<HistoricVariableInstance> historicVariableInstances = historyService.createHistoricVariableInstanceQuery().processInstanceId(processInstance.getId()).list();
        return restResponseFactory.createRestVariables(historicVariableInstances);
    }
}
 
Example 6
Source File: ProcessInstanceResource.java    From plumdo-work with Apache License 2.0 5 votes vote down vote up
@GetMapping(value = "/process-instances/{processInstanceId}", name = "根据ID获取流程实例")
public ProcessInstanceDetailResponse getProcessDefinition(@PathVariable String processInstanceId) {
    ProcessInstance processInstance = null;
    HistoricProcessInstance historicProcessInstance = getHistoricProcessInstanceFromRequest(processInstanceId);
    if (historicProcessInstance.getEndTime() == null) {
        processInstance = getProcessInstanceFromRequest(processInstanceId);
    }
    return restResponseFactory.createProcessInstanceDetailResponse(historicProcessInstance, processInstance);
}
 
Example 7
Source File: ProcessInstanceRepresentation.java    From flowable-engine 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 = startedBy != null ? new UserRepresentation(startedBy) : null;
}
 
Example 8
Source File: FlowableProcessInstanceService.java    From flowable-engine with Apache License 2.0 5 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 all content related to the process instance
            contentService.deleteContentItemsByProcessInstanceId(processInstanceId);

            // Delete all comments on tasks and process instances
            commentService.deleteAllCommentsForProcessInstance(processInstanceId);

            // Finally, delete all history for this instance in the engine
            historyService.deleteHistoricProcessInstance(processInstanceId);

        } else {
            runtimeService.deleteProcessInstance(processInstanceId, "Cancelled by " + SecurityUtils.getCurrentUserId());
        }
    }
 
Example 9
Source File: ProcessTimeCalculator.java    From multiapps-controller with Apache License 2.0 4 votes vote down vote up
private Date determineProcessInstanceEndTime(HistoricProcessInstance processInstance) {
    return processInstance.getEndTime() != null ? processInstance.getEndTime() : new Date(currentTimeSupplier.get());
}
 
Example 10
Source File: AbstractFlowableTestCase.java    From flowable-engine with Apache License 2.0 4 votes vote down vote up
protected static void validateHistoryData(ProcessEngine processEngine) {
    ProcessEngineConfiguration processEngineConfiguration = processEngine.getProcessEngineConfiguration();
    HistoryService historyService = processEngine.getHistoryService();
    if (processEngineConfiguration.getHistoryLevel().isAtLeast(HistoryLevel.AUDIT)) {

        List<HistoricProcessInstance> historicProcessInstances = historyService.createHistoricProcessInstanceQuery().finished().list();

        for (HistoricProcessInstance historicProcessInstance : historicProcessInstances) {
            
            assertNotNull("Historic process instance has no process definition id", historicProcessInstance.getProcessDefinitionId());
            assertNotNull("Historic process instance has no process definition key", historicProcessInstance.getProcessDefinitionKey());
            assertNotNull("Historic process instance has no process definition version", historicProcessInstance.getProcessDefinitionVersion());
            assertNotNull("Historic process instance has no deployment id", historicProcessInstance.getDeploymentId());
            assertNotNull("Historic process instance has no start activity id", historicProcessInstance.getStartActivityId());
            assertNotNull("Historic process instance has no start time", historicProcessInstance.getStartTime());
            assertNotNull("Historic process instance has no end time", historicProcessInstance.getEndTime());

            String processInstanceId = historicProcessInstance.getId();

            // tasks
            List<HistoricTaskInstance> historicTaskInstances = historyService.createHistoricTaskInstanceQuery()
                    .processInstanceId(processInstanceId).list();
            
            if (historicTaskInstances != null && historicTaskInstances.size() > 0) {
                for (HistoricTaskInstance historicTaskInstance : historicTaskInstances) {
                    assertEquals(processInstanceId, historicTaskInstance.getProcessInstanceId());
                    if (historicTaskInstance.getClaimTime() != null) {
                        assertNotNull("Historic task " + historicTaskInstance.getTaskDefinitionKey() + " has no work time", historicTaskInstance.getWorkTimeInMillis());
                    }
                    assertNotNull("Historic task " + historicTaskInstance.getTaskDefinitionKey() + " has no id", historicTaskInstance.getId());
                    assertNotNull("Historic task " + historicTaskInstance.getTaskDefinitionKey() + " has no process instance id", historicTaskInstance.getProcessInstanceId());
                    assertNotNull("Historic task " + historicTaskInstance.getTaskDefinitionKey() + " has no execution id", historicTaskInstance.getExecutionId());
                    assertNotNull("Historic task " + historicTaskInstance.getTaskDefinitionKey() + " has no process definition id", historicTaskInstance.getProcessDefinitionId());
                    assertNotNull("Historic task " + historicTaskInstance.getTaskDefinitionKey() + " has no task definition key", historicTaskInstance.getTaskDefinitionKey());
                    assertNotNull("Historic task " + historicTaskInstance.getTaskDefinitionKey() + " has no create time", historicTaskInstance.getCreateTime());
                    assertNotNull("Historic task " + historicTaskInstance.getTaskDefinitionKey() + " has no start time", historicTaskInstance.getStartTime());
                    assertNotNull("Historic task " + historicTaskInstance.getTaskDefinitionKey() + " has no end time", historicTaskInstance.getEndTime());
                }
            }

            // activities
            List<HistoricActivityInstance> historicActivityInstances = historyService.createHistoricActivityInstanceQuery()
                    .processInstanceId(processInstanceId).list();
            if (historicActivityInstances != null && historicActivityInstances.size() > 0) {
                for (HistoricActivityInstance historicActivityInstance : historicActivityInstances) {
                    assertEquals(processInstanceId, historicActivityInstance.getProcessInstanceId());
                    assertNotNull("Historic activity instance " + historicActivityInstance.getId() + " / " + historicActivityInstance.getActivityId() + " has no activity id", historicActivityInstance.getActivityId());
                    assertNotNull("Historic activity instance " + historicActivityInstance.getId() + " / " + historicActivityInstance.getActivityId() + " has no activity type", historicActivityInstance.getActivityType());
                    assertNotNull("Historic activity instance " + historicActivityInstance.getId() + " / " + historicActivityInstance.getActivityId() + " has no process definition id", historicActivityInstance.getProcessDefinitionId());
                    assertNotNull("Historic activity instance " + historicActivityInstance.getId() + " / " + historicActivityInstance.getActivityId() + " has no process instance id", historicActivityInstance.getProcessInstanceId());
                    assertNotNull("Historic activity instance " + historicActivityInstance.getId() + " / " + historicActivityInstance.getActivityId() + " has no execution id", historicActivityInstance.getExecutionId());
                    assertNotNull("Historic activity instance " + historicActivityInstance.getId() + " / " + historicActivityInstance.getActivityId() + " has no start time", historicActivityInstance.getStartTime());
                    assertNotNull("Historic activity instance " + historicActivityInstance.getId() + " / " + historicActivityInstance.getActivityId() + " has no end time", historicActivityInstance.getEndTime());
                    if (historicProcessInstance.getEndTime() == null) {
                        assertActivityInstancesAreSame(historicActivityInstance,
                            processEngine.getRuntimeService().createActivityInstanceQuery().activityInstanceId(historicActivityInstance.getId()).singleResult()
                        );
                    }
                }
            }
        }

    }
}