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

The following examples show how to use org.flowable.engine.history.HistoricProcessInstance#getId() . 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: HistoricProcessInstanceCommentResource.java    From flowable-engine with Apache License 2.0 6 votes vote down vote up
@ApiOperation(value = "Get a comment on a historic process instance", tags = { "History Process" }, notes = "")
@ApiResponses(value = {
        @ApiResponse(code = 200, message = "Indicates the historic process instance and comment were found and the comment is returned."),
        @ApiResponse(code = 404, message = "Indicates the requested historic process instance was not found or the historic process instance does not have a comment with the given ID.") })
@GetMapping(value = "/history/historic-process-instances/{processInstanceId}/comments/{commentId}", produces = "application/json")
public CommentResponse getComment(@ApiParam(name = "processInstanceId") @PathVariable("processInstanceId") String processInstanceId, @ApiParam(name = "commentId") @PathVariable("commentId") String commentId, HttpServletRequest request) {

    HistoricProcessInstance instance = getHistoricProcessInstanceFromRequest(processInstanceId);

    Comment comment = taskService.getComment(commentId);
    if (comment == null || comment.getProcessInstanceId() == null || !comment.getProcessInstanceId().equals(instance.getId())) {
        throw new FlowableObjectNotFoundException("Process instance '" + instance.getId() + "' does not have a comment with id '" + commentId + "'.", Comment.class);
    }

    return restResponseFactory.createRestComment(comment);
}
 
Example 2
Source File: HistoricProcessInstanceCommentResource.java    From flowable-engine with Apache License 2.0 6 votes vote down vote up
@ApiOperation(value = "Delete a comment on a historic process instance", tags = { "History Process" }, notes = "")
@ApiResponses(value = {
        @ApiResponse(code = 204, message = "Indicates the historic process instance and comment were found and the comment is deleted. Response body is left empty intentionally."),
        @ApiResponse(code = 404, message = "Indicates the requested historic process instance was not found or the historic process instance does not have a comment with the given ID.") })
@DeleteMapping(value = "/history/historic-process-instances/{processInstanceId}/comments/{commentId}")
public void deleteComment(@ApiParam(name = "processInstanceId") @PathVariable("processInstanceId") String processInstanceId, @ApiParam(name = "commentId") @PathVariable("commentId") String commentId, HttpServletRequest request,
        HttpServletResponse response) {

    HistoricProcessInstance instance = getHistoricProcessInstanceFromRequest(processInstanceId);

    Comment comment = taskService.getComment(commentId);
    if (comment == null || comment.getProcessInstanceId() == null || !comment.getProcessInstanceId().equals(instance.getId())) {
        throw new FlowableObjectNotFoundException("Process instance '" + instance.getId() + "' does not have a comment with id '" + commentId + "'.", Comment.class);
    }

    taskService.deleteComment(commentId);
    response.setStatus(HttpStatus.NO_CONTENT.value());
}
 
Example 3
Source File: ServiceCacheTask.java    From flowable-engine with Apache License 2.0 6 votes vote down vote up
@Override
public void execute(DelegateExecution execution) {
    ProcessEngineConfigurationImpl processEngineConfiguration = CommandContextUtil.getProcessEngineConfiguration();
    RuntimeService runtimeService = processEngineConfiguration.getRuntimeService();
    ProcessInstance processInstance = runtimeService.createProcessInstanceQuery().processInstanceId(execution.getProcessInstanceId()).singleResult();
    if (processInstance != null && processInstance.getId().equals(execution.getProcessInstanceId())) {
        processInstanceId = processInstance.getId();
    }
    
    Execution queryExecution = runtimeService.createExecutionQuery().executionId(execution.getId()).singleResult();
    if (queryExecution != null && execution.getId().equals(queryExecution.getId())) {
        executionId = queryExecution.getId();
    }
    
    HistoryService historyService = processEngineConfiguration.getHistoryService();
    HistoricProcessInstance historicProcessInstance = historyService.createHistoricProcessInstanceQuery().processInstanceId(execution.getProcessInstanceId()).singleResult();
    if (historicProcessInstance != null && historicProcessInstance.getId().equals(execution.getProcessInstanceId())) {
        historicProcessInstanceId = historicProcessInstance.getId();
    }
}
 
Example 4
Source File: FlowableHistoricDataCleaner.java    From multiapps-controller with Apache License 2.0 5 votes vote down vote up
private boolean deleteProcessSafely(HistoricProcessInstance process) {
    String processId = process.getId();
    try {
        LOGGER.debug(CleanUpJob.LOG_MARKER, format(Messages.DELETING_HISTORIC_PROCESS_0, processId));
        historyService.deleteHistoricProcessInstance(processId);
        return true;
    } catch (Exception e) {
        LOGGER.warn(CleanUpJob.LOG_MARKER, format(Messages.COULD_NOT_DELETE_HISTORIC_PROCESS_0, processId), e);
        return false;
    }
}
 
Example 5
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 6
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()
                        );
                    }
                }
            }
        }

    }
}