org.flowable.task.api.Task Java Examples

The following examples show how to use org.flowable.task.api.Task. 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: UserEventListenerTest.java    From flowable-engine with Apache License 2.0 6 votes vote down vote up
@Test
@CmmnDeployment
public void testUserEventInstanceDeletedWhenNotReferencedByExitSentry() {

    cmmnRuntimeService.createCaseInstanceBuilder().caseDefinitionKey("testUserEvent").start();
    assertThat(cmmnRuntimeService.createUserEventListenerInstanceQuery().singleResult()).isNotNull();

    // Completing task A and B completes Stage A.
    // This should also remove the user event listener, as nothing is referencing it anymore

    List<Task> tasks = cmmnTaskService.createTaskQuery().list();
    assertThat(tasks).hasSize(2);
    tasks.forEach(t -> cmmnTaskService.complete(t.getId()));

    assertThat(cmmnRuntimeService.createPlanItemInstanceQuery().planItemInstanceName("Stage A").singleResult()).isNull();
    assertThat(cmmnRuntimeService.createPlanItemInstanceQuery().planItemInstanceName("Stage A").includeEnded().singleResult()).isNotNull();
    assertThat(cmmnRuntimeService.createUserEventListenerInstanceQuery().singleResult()).isNull();
}
 
Example #2
Source File: TerminateEndEventTest.java    From flowable-engine with Apache License 2.0 6 votes vote down vote up
@Test
@Deployment(resources = {
        "org/flowable/engine/test/bpmn/event/end/TerminateEndEventTest.testTerminateWithCallActivityTerminateAll.bpmn20.xml",
        "org/flowable/engine/test/bpmn/event/end/TerminateEndEventTest.subProcessNoTerminate.bpmn" })
public void testTerminateWithCallActivityTerminateAll() throws Exception {
    ProcessInstance pi = runtimeService.startProcessInstanceByKey("terminateEndEventExample");

    ProcessInstance subProcessInstance = runtimeService.createProcessInstanceQuery().superProcessInstanceId(pi.getId()).singleResult();
    assertThat(subProcessInstance).isNotNull();

    org.flowable.task.api.Task task = taskService.createTaskQuery().processInstanceId(pi.getId())
            .taskDefinitionKey("preTerminateEnd").singleResult();
    taskService.complete(task.getId());

    assertProcessEnded(pi.getId());
    assertHistoricProcessInstanceDetails(pi);

    assertHistoricProcessInstanceDeleteReason(pi, DeleteReason.TERMINATE_END_EVENT);
    assertHistoricTasksDeleteReason(pi, null, "check before termination");
    assertHistoricTasksDeleteReason(subProcessInstance, DeleteReason.TERMINATE_END_EVENT, "Perform Sample");
    assertHistoricActivitiesDeleteReason(pi, null, "preTerminateEnd");
    assertHistoricActivitiesDeleteReason(subProcessInstance, DeleteReason.TERMINATE_END_EVENT, "task");
}
 
Example #3
Source File: AsyncHistoryTest.java    From flowable-engine with Apache License 2.0 6 votes vote down vote up
@Test
@Deployment
public void testInclusiveGatewayEndTimeSet() {
    ProcessInstance processInstance = runtimeService.startProcessInstanceByKey("testInclusiveGateway");
    List<Task> tasks = taskService.createTaskQuery().processInstanceId(processInstance.getId()).orderByTaskName().asc().list();
    assertThat(tasks).extracting(Task::getName).containsExactly("Always", "Always");

    for (Task task : tasks) {
        taskService.complete(task.getId());
    }

    waitForHistoryJobExecutorToProcessAllJobs(10000, 200);

    HistoricProcessInstance historicProcessInstance = historyService.createHistoricProcessInstanceQuery().processInstanceId(processInstance.getId())
            .singleResult();
    assertThat(historicProcessInstance.getEndTime()).isNotNull();

}
 
Example #4
Source File: ErrorEventSubProcessTest.java    From flowable-engine with Apache License 2.0 6 votes vote down vote up
@Test
@Deployment
// an event subprocess with errorCode takes precedence over a catch-all handler
public void testErrorCodeTakesPrecedence() {
    String procId = runtimeService.startProcessInstanceByKey("CatchErrorInEmbeddedSubProcess").getId();

    // The process will throw an error event, which is caught and escalated by a User org.flowable.task.service.Task
    assertThat(taskService.createTaskQuery().taskDefinitionKey("taskAfterErrorCatch2").count()).isEqualTo(1);
    org.flowable.task.api.Task task = taskService.createTaskQuery().singleResult();
    assertThat(task.getName()).isEqualTo("Escalated Task");

    // Completing the task will end the process instance
    taskService.complete(task.getId());
    assertProcessEnded(procId);

}
 
Example #5
Source File: TaskResource.java    From flowable-engine with Apache License 2.0 6 votes vote down vote up
@ApiOperation(value = "Get a task form", tags = { "Tasks" })
@ApiResponses(value = {
        @ApiResponse(code = 200, message = "Indicates request was successful and the task form is returned"),
        @ApiResponse(code = 404, message = "Indicates the requested task was not found.")
})
@GetMapping(value = "/cmmn-runtime/tasks/{taskId}/form", produces = "application/json")
public String getTaskForm(@ApiParam(name = "taskId") @PathVariable String taskId, HttpServletRequest request) {
    Task task = getTaskFromRequest(taskId);
    if (StringUtils.isEmpty(task.getFormKey())) {
        throw new FlowableIllegalArgumentException("Task has no form defined");
    }
    
    FormInfo formInfo = taskService.getTaskFormModel(task.getId());
    if (formHandlerRestApiInterceptor != null) {
        return formHandlerRestApiInterceptor.convertTaskFormInfo(formInfo, task);
    } else {
        SimpleFormModel formModel = (SimpleFormModel) formInfo.getFormModel();
        return restResponseFactory.getFormModelString(new FormModelResponse(formInfo, formModel));
    }
}
 
Example #6
Source File: TransactionDependentExecutionListenerSpringTest.java    From flowable-engine with Apache License 2.0 6 votes vote down vote up
@Test
@Deployment
public void testCustomPropertiesMapDelegateExpression() {
    runtimeService.startProcessInstanceByKey("transactionDependentExecutionListenerProcess");

    // Completing first task will trigger the first closed listener (expression custom properties resolver)
    Task task = taskService.createTaskQuery().singleResult();
    taskService.complete(task.getId());

    assertThat(listener.getCurrentActivities().get(0).getActivityId()).isEqualTo("task3");
    assertThat(listener.getCurrentActivities().get(0).getCustomPropertiesMap().get("customProp1")).isEqualTo("task3");

    // Completing second task will trigger the second closed listener (delegate expression custom properties resolver)
    task = taskService.createTaskQuery().singleResult();
    taskService.complete(task.getId());

    assertThat(listener.getCurrentActivities().get(1).getActivityId()).isEqualTo("task4");
    assertThat(listener.getCurrentActivities().get(1).getCustomPropertiesMap().get("customProp1")).isEqualTo("task4");
}
 
Example #7
Source File: DefaultTaskLocalizationManager.java    From flowable-engine with Apache License 2.0 6 votes vote down vote up
@Override
public void localize(Task task, String locale, boolean withLocalizationFallback) {
    task.setLocalizedName(null);
    task.setLocalizedDescription(null);

    if (locale != null) {
        String processDefinitionId = task.getProcessDefinitionId();
        if (processDefinitionId != null) {
            ObjectNode languageNode = BpmnOverrideContext.getLocalizationElementProperties(locale, task.getTaskDefinitionKey(), processDefinitionId, withLocalizationFallback);
            if (languageNode != null) {
                JsonNode languageNameNode = languageNode.get(DynamicBpmnConstants.LOCALIZATION_NAME);
                if (languageNameNode != null && !languageNameNode.isNull()) {
                    task.setLocalizedName(languageNameNode.asText());
                }

                JsonNode languageDescriptionNode = languageNode.get(DynamicBpmnConstants.LOCALIZATION_DESCRIPTION);
                if (languageDescriptionNode != null && !languageDescriptionNode.isNull()) {
                    task.setLocalizedDescription(languageDescriptionNode.asText());
                }
            }
        }
    }
}
 
Example #8
Source File: ProcessTaskTest.java    From flowable-engine with Apache License 2.0 6 votes vote down vote up
@Test
@CmmnDeployment
public void testExitCaseInstanceOnProcessInstanceComplete() {
    cmmnRuntimeService.createCaseInstanceBuilder()
            .caseDefinitionKey("testExitCaseInstanceOnProcessInstanceComplete")
            .start();

    assertThat(processEngineRuntimeService.createProcessInstanceQuery().count()).isZero();
    assertThat(cmmnTaskService.createTaskQuery().count()).isEqualTo(1);

    // Process task is manually activated
    cmmnRuntimeService.startPlanItemInstance(cmmnRuntimeService.createPlanItemInstanceQuery().planItemInstanceStateEnabled().singleResult().getId());
    assertThat(processEngineRuntimeService.createProcessInstanceQuery().count()).isEqualTo(1);
    assertThat(cmmnTaskService.createTaskQuery().count()).isEqualTo(2);

    // Completing the task from the process should terminate the case
    Task userTaskFromProcess = processEngineTaskService.createTaskQuery()
            .processInstanceId(processEngineRuntimeService.createProcessInstanceQuery().singleResult().getId())
            .singleResult();
    processEngineTaskService.complete(userTaskFromProcess.getId());

    assertThat(cmmnRuntimeService.createCaseInstanceQuery().count()).isZero();
}
 
Example #9
Source File: TaskQueryTest.java    From flowable-engine with Apache License 2.0 6 votes vote down vote up
@Test
public void testQueryByInvolvedGroupOrAssignee() {
    try {
        org.flowable.task.api.Task adhocTask = taskService.newTask();
        taskService.saveTask(adhocTask);
        org.flowable.task.api.Task adhocTask2 = taskService.newTask();
        adhocTask2.setAssignee("kermit");
        taskService.saveTask(adhocTask2);
        org.flowable.task.api.Task adhocTask3 = taskService.newTask();
        taskService.saveTask(adhocTask3);
        taskService.addGroupIdentityLink(adhocTask.getId(), "testGroup", "customType");

        assertThat(taskService.getIdentityLinksForTask(adhocTask.getId())).hasSize(1);

        assertThat(taskService.createTaskQuery().or().taskAssignee("kermit").taskInvolvedGroups(Collections.singleton("testGroup")).endOr().count())
                .isEqualTo(2);

        if (HistoryTestHelper.isHistoryLevelAtLeast(HistoryLevel.AUDIT, processEngineConfiguration)) {
            assertThat(historyService.createHistoricTaskInstanceQuery().
                    or().taskAssignee("kermit").taskInvolvedGroups(Collections.singleton("testGroup")).endOr().count()).isEqualTo(2);
        }

    } finally {
        deleteAllTasks();
    }
}
 
Example #10
Source File: GetTaskVariableCmd.java    From flowable-engine with Apache License 2.0 6 votes vote down vote up
@Override
public Object execute(CommandContext commandContext) {
    if (taskId == null) {
        throw new FlowableIllegalArgumentException("taskId is null");
    }
    if (variableName == null) {
        throw new FlowableIllegalArgumentException("variableName is null");
    }

    TaskEntity task = CommandContextUtil.getTaskService().getTask(taskId);

    if (task == null) {
        throw new FlowableObjectNotFoundException("task " + taskId + " doesn't exist", Task.class);
    }

    Object value;

    if (isLocal) {
        value = task.getVariableLocal(variableName, false);
    } else {
        value = task.getVariable(variableName, false);
    }

    return value;
}
 
Example #11
Source File: MultiInstanceTest.java    From flowable-engine with Apache License 2.0 6 votes vote down vote up
@Test
@Deployment
public void testSequentialSubProcessEndEvent() {
    // ACT-1185: end-event in subprocess causes inactivated execution
    String procId = runtimeService.startProcessInstanceByKey("miSequentialSubprocess").getId();

    TaskQuery query = taskService.createTaskQuery().orderByTaskName().asc();
    for (int i = 0; i < 4; i++) {
        List<org.flowable.task.api.Task> tasks = query.list();
        assertEquals(1, tasks.size());

        assertEquals("task one", tasks.get(0).getName());

        taskService.complete(tasks.get(0).getId());

        // Last run, the execution no longer exists
        if (i != 3) {
            List<String> activities = runtimeService.getActiveActivityIds(procId);
            assertNotNull(activities);
            assertEquals(2, activities.size());
        }
    }

    assertProcessEnded(procId);
}
 
Example #12
Source File: TaskAttachmentResource.java    From flowable-engine with Apache License 2.0 6 votes vote down vote up
@ApiOperation(value = "Delete an attachment on a task", tags = { "Task Attachments"})
@ApiResponses(value = {
        @ApiResponse(code = 204, message = "Indicates the task and attachment were found and the attachment is deleted. Response body is left empty intentionally."),
        @ApiResponse(code = 404, message = "Indicates the requested task was not found or the tasks does not have a attachment with the given ID.")
})
@DeleteMapping(value = "/runtime/tasks/{taskId}/attachments/{attachmentId}")
public void deleteAttachment(@ApiParam(name = "taskId") @PathVariable("taskId") String taskId, @ApiParam(name = "attachmentId") @PathVariable("attachmentId") String attachmentId, HttpServletResponse response) {

    Task task = getTaskFromRequest(taskId);

    Attachment attachment = taskService.getAttachment(attachmentId);
    if (attachment == null || !task.getId().equals(attachment.getTaskId())) {
        throw new FlowableObjectNotFoundException("Task '" + task.getId() + "' does not have an attachment with id '" + attachmentId + "'.", Comment.class);
    }

    taskService.deleteAttachment(attachmentId);
    response.setStatus(HttpStatus.NO_CONTENT.value());
}
 
Example #13
Source File: CmmnHistoryServiceTaskLogTest.java    From flowable-engine with Apache License 2.0 6 votes vote down vote up
@Test
public void logAddCandidateUser() {
    deployOneHumanTaskCaseModel();
    CaseInstance oneTaskCase = cmmnRuntimeService.createCaseInstanceBuilder().caseDefinitionKey("oneTaskCase").start();
    assertThat(oneTaskCase).isNotNull();
    Task task = cmmnTaskService.createTaskQuery().caseInstanceId(oneTaskCase.getId()).singleResult();

    try {
        assertThat(oneTaskCase).isNotNull();
        assertThat(task).isNotNull();

        cmmnTaskService.addUserIdentityLink(task.getId(), "newCandidateUser", IdentityLinkType.CANDIDATE);

        List<HistoricTaskLogEntry> logEntries = cmmnHistoryService.createHistoricTaskLogEntryQuery().taskId(task.getId()).list();
        assertThat(logEntries).hasSize(2);
        assertThat(logEntries.get(1))
                .extracting(HistoricTaskLogEntry::getType)
                .isEqualTo("USER_TASK_IDENTITY_LINK_ADDED");
        assertThat(logEntries.get(1))
                .extracting(HistoricTaskLogEntry::getData)
                .isEqualToComparingOnlyGivenFields("{\"type\":\"candidate\", \"userId\":\"newCandidateUser\"}");
    } finally {
        cmmnTaskService.complete(task.getId());
        deleteTaskWithLogEntries(task.getId());
    }
}
 
Example #14
Source File: DecisionTaskTest.java    From flowable-engine with Apache License 2.0 6 votes vote down vote up
@Test
@CmmnDeployment(
    resources = {
        "org/flowable/cmmn/test/runtime/DecisionTaskTest.testUseDmnOutputInEntryCriteria.cmmn",
        "org/flowable/cmmn/test/runtime/DecisionTaskTest.testUseDmnOutputInEntryCriteria.dmn"
    }
)
public void testUseDmnOutputInEntryCriteria() {
    CaseInstance caseInstance = cmmnRule.getCmmnRuntimeService().createCaseInstanceBuilder()
            .caseDefinitionKey("testRules")
            .variable("first", "11")
            .variable("second", "11")
            .start();

    // The entry sentry on the first stage uses the output of the DMN table
    List<Task> tasks = cmmnRule.getCmmnTaskService().createTaskQuery().caseInstanceId(caseInstance.getId()).orderByTaskName().asc().list();
    assertThat(tasks.get(0).getName()).isEqualTo("Human task");
    assertThat(tasks.get(1).getName()).isEqualTo("Task One");
}
 
Example #15
Source File: StandaloneTaskTest.java    From flowable-engine with Apache License 2.0 6 votes vote down vote up
@Test
public void testRevisionUpdatedOnSaveWhenFetchedUsingQuery() {
    org.flowable.task.api.Task task = taskService.newTask();
    taskService.saveTask(task);
    assertThat(((TaskEntity) task).getRevision()).isEqualTo(1);

    task.setAssignee("kermit");
    taskService.saveTask(task);
    assertThat(((TaskEntity) task).getRevision()).isEqualTo(2);

    // Now fetch the task through the query api
    task = taskService.createTaskQuery().singleResult();
    assertThat(((TaskEntity) task).getRevision()).isEqualTo(2);
    task.setPriority(1);
    taskService.saveTask(task);

    assertThat(((TaskEntity) task).getRevision()).isEqualTo(3);

    taskService.deleteTask(task.getId(), true);
}
 
Example #16
Source File: CallActivityAdvancedTest.java    From flowable-engine with Apache License 2.0 6 votes vote down vote up
@Test
@Deployment(resources = {
    "org/flowable/engine/test/bpmn/callactivity/CallActivity.testIdVariableNameExpression.bpmn20.xml",
    "org/flowable/engine/test/bpmn/callactivity/simpleSubProcess.bpmn20.xml"
})
public void testIdVariableNameExpression() {
    ProcessInstance processInstance = runtimeService.createProcessInstanceBuilder()
        .processDefinitionKey("testIdVariableName")
        .variable("counter", 123)
        .start();

    Task task = taskService.createTaskQuery().singleResult();
    assertThat(task.getName()).isEqualTo("Task in subprocess");

    assertThat(runtimeService.getVariables(processInstance.getId())).hasSize(2);
    assertThat(runtimeService.getVariables(task.getProcessInstanceId())).isEmpty();

    assertThat(runtimeService.getVariable(processInstance.getId(), "myVariable-123")).isEqualTo(task.getProcessInstanceId());
}
 
Example #17
Source File: RepetitionRuleTest.java    From flowable-engine with Apache License 2.0 6 votes vote down vote up
@Test
@CmmnDeployment
public void testRepetitionRuleWithExitCriteria() {
    //Completion of taskB will transition taskA to "exit", skipping the evaluation of the repetition rule (Table 8.8 of CMM 1.1 Spec)
    CaseInstance caseInstance = cmmnRuntimeService.createCaseInstanceBuilder()
            .caseDefinitionKey("testRepetitionRuleWithExitCriteria")
            .variable("whileTrue", "true")
            .start();

    assertThat(caseInstance).isNotNull();

    for (int i = 0; i < 3; i++) {
        Task taskA = cmmnTaskService.createTaskQuery().active().taskDefinitionKey("taskA").singleResult();
        cmmnTaskService.complete(taskA.getId());
        assertCaseInstanceNotEnded(caseInstance);
    }

    Task taskB = cmmnTaskService.createTaskQuery().active().taskDefinitionKey("taskB").singleResult();
    cmmnTaskService.complete(taskB.getId());
    assertCaseInstanceEnded(caseInstance);
}
 
Example #18
Source File: TaskCollectionResource.java    From flowable-engine with Apache License 2.0 6 votes vote down vote up
@ApiOperation(value = "Create Task", tags = { "Tasks" })
@ApiResponses(value = {
        @ApiResponse(code = 201, message = "Indicates request was successful and the tasks are returned"),
        @ApiResponse(code = 400, message = "Indicates a parameter was passed in the wrong format or that delegationState has an invalid value (other than pending and resolved). The status-message contains additional information.")
})
@PostMapping(value = "/runtime/tasks", produces = "application/json")
public TaskResponse createTask(@RequestBody TaskRequest taskRequest, HttpServletRequest request, HttpServletResponse response) {

    Task task = taskService.newTask();

    // Populate the task properties based on the request
    populateTaskFromRequest(task, taskRequest);
    if (taskRequest.isTenantIdSet()) {
        ((TaskEntity) task).setTenantId(taskRequest.getTenantId());
    }
    
    if (restApiInterceptor != null) {
        restApiInterceptor.createTask(task, taskRequest);
    }
    
    taskService.saveTask(task);

    response.setStatus(HttpStatus.CREATED.value());
    return restResponseFactory.createTaskResponse(task);
}
 
Example #19
Source File: SecureScriptingTest.java    From flowable-engine with Apache License 2.0 6 votes vote down vote up
@Test
public void testUseExecutionAndVariables() {
    deployProcessDefinition("test-secure-script-use-variableScope-and-vars.bpmn20.xml");

    addWhiteListedClass("java.lang.Integer");
    addWhiteListedClass("org.flowable.engine.impl.persistence.entity.ExecutionEntityImpl");

    Map<String, Object> vars = new HashMap<>();
    vars.put("a", 123);
    vars.put("b", 456);
    ProcessInstance processInstance = runtimeService.startProcessInstanceByKey("useExecutionAndVars", vars);

    Object c = runtimeService.getVariable(processInstance.getId(), "c");
    assertThat(c).isInstanceOf(Number.class);
    Number cNumber = (Number) c;
    assertThat(cNumber.intValue()).isEqualTo(579);

    List<Task> tasks = taskService.createTaskQuery().processInstanceId(processInstance.getId()).list();
    assertThat(tasks).hasSize(1);
}
 
Example #20
Source File: AsyncHistoryUpgradeTest.java    From flowable-engine with Apache License 2.0 6 votes vote down vote up
@Test
public void testSetTaskCategory() {
    Task task = startOneTaskprocess();
    assertThat(task.getCategory()).isNull();

    waitForHistoryJobExecutorToProcessAllJobs(7000L, 100L);
    HistoricTaskInstance historicTaskInstance = historyService.createHistoricTaskInstanceQuery().singleResult();
    assertThat(historicTaskInstance.getCategory()).isNull();

    removeRuntimeActivityInstances(task.getProcessInstanceId());

    task.setCategory("test category");
    taskService.saveTask(task);

    downgradeHistoryJobConfigurations();

    waitForHistoryJobExecutorToProcessAllJobs(7000L, 100L);
    historicTaskInstance = historyService.createHistoricTaskInstanceQuery().singleResult();
    assertThat(historicTaskInstance.getCategory()).isEqualTo("test category");

    finishOneTaskProcess(task);
}
 
Example #21
Source File: FlowableTaskActionService.java    From flowable-engine with Apache License 2.0 6 votes vote down vote up
public void completeTask(String taskId) {
    User currentUser = SecurityUtils.getCurrentUserObject();
    Task task = taskService.createTaskQuery().taskId(taskId).singleResult();

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

    if (!permissionService.isTaskOwnerOrAssignee(currentUser, task)) {
        if (StringUtils.isEmpty(task.getScopeType()) && !permissionService.validateIfUserIsInitiatorAndCanCompleteTask(currentUser, task)) {
            throw new NotPermittedException();
        }
    }

    try {
        if (StringUtils.isEmpty(task.getScopeType())) {
            taskService.complete(task.getId());
        } else {
            cmmnTaskService.complete(task.getId());
        }
        
    } catch (FlowableException e) {
        LOGGER.error("Error completing task {}", taskId, e);
        throw new BadRequestException("Task " + taskId + " can't be completed", e);
    }
}
 
Example #22
Source File: GetTaskVariableCmd.java    From flowable-engine with Apache License 2.0 6 votes vote down vote up
@Override
public Object execute(CommandContext commandContext) {
    if (taskId == null) {
        throw new FlowableIllegalArgumentException("taskId is null");
    }
    if (variableName == null) {
        throw new FlowableIllegalArgumentException("variableName is null");
    }

    TaskEntity task = CommandContextUtil.getTaskService().getTask(taskId);

    if (task == null) {
        throw new FlowableObjectNotFoundException("task " + taskId + " doesn't exist", Task.class);
    }

    Object value;

    if (isLocal) {
        value = task.getVariableLocal(variableName, false);
    } else {
        value = task.getVariable(variableName, false);
    }

    return value;
}
 
Example #23
Source File: TaskQueryTest.java    From flowable-engine with Apache License 2.0 6 votes vote down vote up
@Test
public void testQueryByFormKey() {
    Task task = taskService.newTask();
    task.setFormKey("testFormKey");
    taskService.saveTask(task);
    taskIds.add(task.getId());

    List<Task> tasks = taskService.createTaskQuery().taskFormKey("testFormKey").list();
    assertThat(tasks)
            .extracting(Task::getFormKey)
            .containsExactly("testFormKey");

    if (HistoryTestHelper.isHistoryLevelAtLeast(HistoryLevel.AUDIT, processEngineConfiguration)) {
        List<HistoricTaskInstance> historicTasks = historyService.createHistoricTaskInstanceQuery()
                .taskFormKey("testFormKey")
                .list();
        assertThat(historicTasks)
                .extracting(HistoricTaskInstance::getFormKey)
                .containsExactly("testFormKey");
    }
}
 
Example #24
Source File: HistoricTaskInstanceQueryResourceTest.java    From flowable-engine with Apache License 2.0 6 votes vote down vote up
@Test
@Deployment
public void testQueryTaskInstancesWithCandidateGroup() throws Exception {
    ProcessInstance processInstance = runtimeService.startProcessInstanceByKey("oneTaskProcess");
    Task task = taskService.createTaskQuery().processInstanceId(processInstance.getId()).singleResult();

    String url = RestUrls.createRelativeResourceUrl(RestUrls.URL_HISTORIC_TASK_INSTANCE_QUERY);

    ObjectNode requestNode = objectMapper.createObjectNode();
    requestNode.put("taskCandidateGroup", "sales");
    assertResultsPresentInPostDataResponse(url, requestNode, task.getId());

    taskService.claim(task.getId(), "johnDoe");
    requestNode.put("taskCandidateGroup", "sales");
    requestNode.put("ignoreTaskAssignee", true);
    assertResultsPresentInPostDataResponse(url, requestNode, task.getId());
}
 
Example #25
Source File: ConditionalEventSubprocessTest.java    From flowable-engine with Apache License 2.0 6 votes vote down vote up
@Test
@Deployment
public void testInterruptingNestedSubProcess() {
    ProcessInstance processInstance = runtimeService.startProcessInstanceByKey("process");
    assertThat(runtimeService.createExecutionQuery().processInstanceId(processInstance.getId()).count()).isEqualTo(3);

    runtimeService.evaluateConditionalEvents(processInstance.getId(), Collections.singletonMap("myVar", "test"));
    assertThat(runtimeService.createExecutionQuery().processInstanceId(processInstance.getId()).count()).isEqualTo(5);

    assertThat(taskService.createTaskQuery().count()).isEqualTo(1);

    // now let's complete the task in the event subprocess
    Task task = taskService.createTaskQuery().taskDefinitionKey("eventSubProcessTask").singleResult();
    taskService.complete(task.getId());

    // done!
    assertThat(runtimeService.createExecutionQuery().processInstanceId(processInstance.getId()).count()).isZero();
}
 
Example #26
Source File: SerializableVariablesDiabledTest.java    From flowable-engine with Apache License 2.0 5 votes vote down vote up
@Test
public void testCreateSingleSerializableTaskVariable() throws Exception {
    repositoryService.createDeployment()
            .addClasspathResource("org/flowable/rest/service/api/runtime/ProcessInstanceVariablesCollectionResourceTest.testProcess.bpmn20.xml")
            .deploy();

    ProcessInstance processInstance = runtimeService.startProcessInstanceByKey("oneTaskProcess");

    Task task = taskService.createTaskQuery().processInstanceId(processInstance.getId()).singleResult();

    TestSerializableVariable serializable = new TestSerializableVariable();
    serializable.setSomeField("some value");

    // Serialize object to readable stream for representation
    ByteArrayOutputStream buffer = new ByteArrayOutputStream();
    ObjectOutputStream output = new ObjectOutputStream(buffer);
    output.writeObject(serializable);
    output.close();

    InputStream binaryContent = new ByteArrayInputStream(buffer.toByteArray());

    // Add name, type and scope
    Map<String, String> additionalFields = new HashMap<>();
    additionalFields.put("name", "serializableVariable");
    additionalFields.put("type", "serializable");

    HttpPost httpPost = new HttpPost(serverUrlPrefix +
            RestUrls.createRelativeResourceUrl(RestUrls.URL_TASK_VARIABLES_COLLECTION, task.getId()));
    httpPost.setEntity(HttpMultipartHelper.getMultiPartEntity("value", "application/x-java-serialized-object", binaryContent, additionalFields));

    // We have serializeable object disabled, we should get a 415.
    assertResponseStatus(httpPost, HttpStatus.SC_UNSUPPORTED_MEDIA_TYPE);
}
 
Example #27
Source File: TerminateEndEventTest.java    From flowable-engine with Apache License 2.0 5 votes vote down vote up
@Test
@Deployment
public void testTerminateInSubProcessMultiInstance() throws Exception {
    ProcessInstance pi = runtimeService.startProcessInstanceByKey("terminateEndEventExample");

    long executionEntities = runtimeService.createExecutionQuery().count();
    assertThat(executionEntities).isGreaterThan(0);

    org.flowable.task.api.Task task = taskService.createTaskQuery().processInstanceId(pi.getId()).taskDefinitionKey("preNormalEnd").singleResult();
    taskService.complete(task.getId());

    assertProcessEnded(pi.getId());
    assertHistoricProcessInstanceDetails(pi);
}
 
Example #28
Source File: ReplayRunTest.java    From flowable-engine with Apache License 2.0 5 votes vote down vote up
@Test
public void testProcessInstanceStartEvents() throws Exception {
    ProcessEngineImpl processEngine = initProcessEngine();

    TaskService taskService = processEngine.getTaskService();
    RuntimeService runtimeService = processEngine.getRuntimeService();

    Map<String, Object> variables = new HashMap<>();
    variables.put(TEST_VARIABLE, TEST_VALUE);
    ProcessInstance processInstance = runtimeService.startProcessInstanceByKey(USERTASK_PROCESS, BUSINESS_KEY, variables);

    Task task = taskService.createTaskQuery().taskDefinitionKey("userTask").singleResult();
    TimeUnit.MILLISECONDS.sleep(50);
    taskService.complete(task.getId());

    final SimulationDebugger simRun = new ReplaySimulationRun(processEngine, getReplayHandlers(processInstance.getId()));

    simRun.init(new NoExecutionVariableScope());

    // original process is finished - there should not be any running process instance/task
    assertEquals(0, runtimeService.createProcessInstanceQuery().processDefinitionKey(USERTASK_PROCESS).count());
    assertEquals(0, taskService.createTaskQuery().taskDefinitionKey("userTask").count());

    simRun.step();

    // replay process was started
    assertEquals(1, runtimeService.createProcessInstanceQuery().processDefinitionKey(USERTASK_PROCESS).count());
    // there should be one task
    assertEquals(1, taskService.createTaskQuery().taskDefinitionKey("userTask").count());

    simRun.step();

    // userTask was completed - replay process was finished
    assertEquals(0, runtimeService.createProcessInstanceQuery().processDefinitionKey(USERTASK_PROCESS).count());
    assertEquals(0, taskService.createTaskQuery().taskDefinitionKey("userTask").count());

    simRun.close();
    processEngine.close();
    ProcessEngines.destroy();
}
 
Example #29
Source File: MultiInstanceTest.java    From flowable-engine with Apache License 2.0 5 votes vote down vote up
@Test
@Deployment
public void testChangingCollection() {
    Map<String, Object> vars = new HashMap<>();
    vars.put("multi_users", Collections.singletonList("testuser"));
    ProcessInstance instance = runtimeService.startProcessInstanceByKey("test_multi", vars);
    assertNotNull(instance);
    org.flowable.task.api.Task task = taskService.createTaskQuery().singleResult();
    assertEquals("multi", task.getTaskDefinitionKey());
    vars.put("multi_users", new ArrayList<String>()); // <-- Problem here.
    taskService.complete(task.getId(), vars);
    List<ProcessInstance> instances = runtimeService.createProcessInstanceQuery().list();
    assertEquals(0, instances.size());
}
 
Example #30
Source File: CmmnRestResponseFactory.java    From flowable-engine with Apache License 2.0 5 votes vote down vote up
public List<TaskResponse> createTaskResponseList(List<Task> tasks) {
    RestUrlBuilder urlBuilder = createUrlBuilder();
    List<TaskResponse> responseList = new ArrayList<>(tasks.size());
    for (Task instance : tasks) {
        responseList.add(createTaskResponse(instance, urlBuilder));
    }
    return responseList;
}