Java Code Examples for org.flowable.task.api.Task#getProcessInstanceId()

The following examples show how to use org.flowable.task.api.Task#getProcessInstanceId() . 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: FlowableTaskFormService.java    From flowable-engine with Apache License 2.0 6 votes vote down vote up
public void saveTaskForm(String taskId, SaveFormRepresentation saveFormRepresentation) {

        // Get the form definition
        Task task = taskService.createTaskQuery().taskId(taskId).singleResult();

        if (task == null) {
            throw new NotFoundException("Task not found with id: " + taskId);
        }

        checkCurrentUserCanModifyTask(task);
            
        FormInfo formInfo = formRepositoryService.getFormModelById(saveFormRepresentation.getFormId());
        Map<String, Object> formVariables = saveFormRepresentation.getValues();
        
        if (task.getProcessInstanceId() != null) {
            formService.saveFormInstanceByFormDefinitionId(formVariables, saveFormRepresentation.getFormId(), taskId, 
                            task.getProcessInstanceId(), task.getProcessDefinitionId(), task.getTenantId(), null);
            
        } else {
            formService.saveFormInstanceWithScopeId(formVariables, saveFormRepresentation.getFormId(), taskId, 
                            task.getScopeId(), task.getScopeType(), task.getScopeDefinitionId(), task.getTenantId(), null);
        }

    }
 
Example 2
Source File: FlowableTaskFormService.java    From flowable-engine with Apache License 2.0 6 votes vote down vote up
public void completeTaskForm(String taskId, CompleteFormRepresentation completeTaskFormRepresentation) {

        // Get the form definition
        Task task = taskService.createTaskQuery().taskId(taskId).singleResult();

        if (task == null) {
            throw new NotFoundException("Task not found with id: " + taskId);
        }

        checkCurrentUserCanModifyTask(task);

        if (task.getProcessInstanceId() != null) {
            taskService.completeTaskWithForm(taskId, completeTaskFormRepresentation.getFormId(),
                    completeTaskFormRepresentation.getOutcome(), completeTaskFormRepresentation.getValues());
        } else {
            cmmnTaskService.completeTaskWithForm(taskId, completeTaskFormRepresentation.getFormId(), completeTaskFormRepresentation.getOutcome(), 
                            completeTaskFormRepresentation.getValues());
        }
    }
 
Example 3
Source File: TaskCommentCollectionResource.java    From flowable-engine with Apache License 2.0 6 votes vote down vote up
@ApiOperation(value = "Create a new comment on a task", tags = { "Task Comments" }, nickname = "createTaskComments")
@ApiResponses(value = {
        @ApiResponse(code = 201, message = "Indicates the comment was created and the result is returned."),
        @ApiResponse(code = 400, message = "Indicates the comment is missing from the request."),
        @ApiResponse(code = 404, message = "Indicates the requested task was not found.")
})
@PostMapping(value = "/runtime/tasks/{taskId}/comments", produces = "application/json")
public CommentResponse createComment(@ApiParam(name = "taskId") @PathVariable String taskId, @RequestBody CommentRequest comment, HttpServletRequest request, HttpServletResponse response) {

    Task task = getTaskFromRequest(taskId);

    if (comment.getMessage() == null) {
        throw new FlowableIllegalArgumentException("Comment text is required.");
    }

    String processInstanceId = null;
    if (comment.isSaveProcessInstanceId()) {
        Task taskEntity = taskService.createTaskQuery().taskId(task.getId()).singleResult();
        processInstanceId = taskEntity.getProcessInstanceId();
    }
    Comment createdComment = taskService.addComment(task.getId(), processInstanceId, comment.getMessage());
    response.setStatus(HttpStatus.CREATED.value());

    return restResponseFactory.createRestComment(createdComment);
}
 
Example 4
Source File: PermissionService.java    From flowable-engine with Apache License 2.0 5 votes vote down vote up
public boolean validateIfUserIsInitiatorAndCanCompleteTask(User user, Task task) {
    boolean canCompleteTask = false;
    if (task.getProcessInstanceId() != null) {
        HistoricProcessInstance historicProcessInstance = historyService.createHistoricProcessInstanceQuery().processInstanceId(task.getProcessInstanceId()).singleResult();
        if (historicProcessInstance != null && StringUtils.isNotEmpty(historicProcessInstance.getStartUserId())) {
            String processInstanceStartUserId = historicProcessInstance.getStartUserId();
            if (String.valueOf(user.getId()).equals(processInstanceStartUserId)) {
                BpmnModel bpmnModel = repositoryService.getBpmnModel(task.getProcessDefinitionId());
                FlowElement flowElement = bpmnModel.getFlowElement(task.getTaskDefinitionKey());
                if (flowElement instanceof UserTask) {
                    UserTask userTask = (UserTask) flowElement;
                    List<ExtensionElement> extensionElements = userTask.getExtensionElements().get("initiator-can-complete");
                    if (CollectionUtils.isNotEmpty(extensionElements)) {
                        String value = extensionElements.get(0).getElementText();
                        if (StringUtils.isNotEmpty(value) && Boolean.valueOf(value)) {
                            canCompleteTask = true;
                        }
                    }
                }
            }
        }

    } else if (task.getScopeId() != null) {
        HistoricCaseInstance historicCaseInstance = cmmnHistoryService.createHistoricCaseInstanceQuery().caseInstanceId(task.getScopeId()).singleResult();
        if (historicCaseInstance != null && StringUtils.isNotEmpty(historicCaseInstance.getStartUserId())) {
            String caseInstanceStartUserId = historicCaseInstance.getStartUserId();
            if (String.valueOf(user.getId()).equals(caseInstanceStartUserId)) {
                canCompleteTask = true;
            }
        }
    }
    return canCompleteTask;
}
 
Example 5
Source File: DefaultIdentityLinkInterceptor.java    From flowable-engine with Apache License 2.0 5 votes vote down vote up
protected void addUserIdentityLinkToParent(Task task, String userId) {
    if (userId != null && task.getProcessInstanceId() != null) {
        ExecutionEntity processInstanceEntity = CommandContextUtil.getExecutionEntityManager().findById(task.getProcessInstanceId());
        for (IdentityLinkEntity identityLink : processInstanceEntity.getIdentityLinks()) {
            if (identityLink.isUser() && identityLink.getUserId().equals(userId) && IdentityLinkType.PARTICIPANT.equals(identityLink.getType())) {
                return;
            }
        }
        
        IdentityLinkUtil.createProcessInstanceIdentityLink(processInstanceEntity, userId, null, IdentityLinkType.PARTICIPANT);
    }
}
 
Example 6
Source File: AttachmentEntityManagerImpl.java    From flowable-engine with Apache License 2.0 5 votes vote down vote up
@Override
public void deleteAttachmentsByTaskId(String taskId) {
    checkHistoryEnabled();
    List<AttachmentEntity> attachments = findAttachmentsByTaskId(taskId);
    FlowableEventDispatcher eventDispatcher = getEventDispatcher();
    boolean dispatchEvents = eventDispatcher != null && eventDispatcher.isEnabled();

    String processInstanceId = null;
    String processDefinitionId = null;
    String executionId = null;

    if (dispatchEvents && attachments != null && !attachments.isEmpty()) {
        // Forced to fetch the task to get hold of the process definition
        // for event-dispatching, if available
        Task task = CommandContextUtil.getTaskService().getTask(taskId);
        if (task != null) {
            processDefinitionId = task.getProcessDefinitionId();
            processInstanceId = task.getProcessInstanceId();
            executionId = task.getExecutionId();
        }
    }

    for (Attachment attachment : attachments) {
        String contentId = attachment.getContentId();
        if (contentId != null) {
            getByteArrayEntityManager().deleteByteArrayById(contentId);
        }

        dataManager.delete((AttachmentEntity) attachment);

        if (dispatchEvents) {
            eventDispatcher.dispatchEvent(
                    FlowableEventBuilder.createEntityEvent(FlowableEngineEventType.ENTITY_DELETED, attachment, executionId, processInstanceId, processDefinitionId));
        }
    }
}
 
Example 7
Source File: InterfaceApplyController.java    From open-capacity-platform with Apache License 2.0 4 votes vote down vote up
/**
 * 生成流程图
 *http://localhost:7010/interfaceApply/processDiagram?processId=9f328c57-38ca-11e9-afb9-000ec6da9d45
 * @param processId 任务ID
 */
@RequestMapping(value = "processDiagram")
public void genProcessDiagram(HttpServletResponse httpServletResponse, String processId) throws Exception {
    ProcessInstance pi = runtimeService.createProcessInstanceQuery().processInstanceId(processId).singleResult();

    //流程走完的不显示图
    if (pi == null) {
        return;
    }
    Task task = taskService.createTaskQuery().processInstanceId(pi.getId()).singleResult();
    //使用流程实例ID,查询正在执行的执行对象表,返回流程实例对象
    String InstanceId = task.getProcessInstanceId();
    List<Execution> executions = runtimeService
            .createExecutionQuery()
            .processInstanceId(InstanceId)
            .list();

    //得到正在执行的Activity的Id
    List<String> activityIds = new ArrayList<>();
    List<String> flows = new ArrayList<>();
    for (Execution exe : executions) {
        List<String> ids = runtimeService.getActiveActivityIds(exe.getId());
        activityIds.addAll(ids);
    }

    //获取流程图
    BpmnModel bpmnModel = repositoryService.getBpmnModel(pi.getProcessDefinitionId());
    ProcessEngineConfiguration engconf = processEngine.getProcessEngineConfiguration();
    ProcessDiagramGenerator diagramGenerator = engconf.getProcessDiagramGenerator();
    InputStream in = diagramGenerator.generateDiagram(bpmnModel, "png", activityIds, flows, engconf.getActivityFontName(), engconf.getLabelFontName(), engconf.getAnnotationFontName(), engconf.getClassLoader(), 1.0);
    OutputStream out = null;
    byte[] buf = new byte[1024];
    int legth = 0;
    try {
        out = httpServletResponse.getOutputStream();
        while ((legth = in.read(buf)) != -1) {
            out.write(buf, 0, legth);
        }
    } finally {
        if (in != null) {
            in.close();
        }
        if (out != null) {
            out.close();
        }
    }
}
 
Example 8
Source File: ExpenseController.java    From flowable-springboot with MIT License 4 votes vote down vote up
/**
 * 生成流程图
 *
 * @param processId 任务ID
 */
@RequestMapping(value = "processDiagram")
public void genProcessDiagram(HttpServletResponse httpServletResponse, String processId) throws Exception {
    ProcessInstance pi = runtimeService.createProcessInstanceQuery().processInstanceId(processId).singleResult();

    //流程走完的不显示图
    if (pi == null) {
        return;
    }
    Task task = taskService.createTaskQuery().processInstanceId(pi.getId()).singleResult();
    //使用流程实例ID,查询正在执行的执行对象表,返回流程实例对象
    String InstanceId = task.getProcessInstanceId();
    List<Execution> executions = runtimeService
            .createExecutionQuery()
            .processInstanceId(InstanceId)
            .list();

    //得到正在执行的Activity的Id
    List<String> activityIds = new ArrayList<>();
    List<String> flows = new ArrayList<>();
    for (Execution exe : executions) {
        List<String> ids = runtimeService.getActiveActivityIds(exe.getId());
        activityIds.addAll(ids);
    }

    //获取流程图
    BpmnModel bpmnModel = repositoryService.getBpmnModel(pi.getProcessDefinitionId());
    ProcessEngineConfiguration engconf = processEngine.getProcessEngineConfiguration();
    ProcessDiagramGenerator diagramGenerator = engconf.getProcessDiagramGenerator();
    InputStream in = diagramGenerator.generateDiagram(bpmnModel, "png", activityIds, flows, engconf.getActivityFontName(), engconf.getLabelFontName(), engconf.getAnnotationFontName(), engconf.getClassLoader(), 1.0);
    OutputStream out = null;
    byte[] buf = new byte[1024];
    int legth = 0;
    try {
        out = httpServletResponse.getOutputStream();
        while ((legth = in.read(buf)) != -1) {
            out.write(buf, 0, legth);
        }
    } finally {
        if (in != null) {
            in.close();
        }
        if (out != null) {
            out.close();
        }
    }
}