Search in sources :

Example 1 with Status

use of org.kie.api.task.model.Status in project jbpm by kiegroup.

the class BAMTaskEventListener method createTask.

/**
 * Creates or updates a bam task summary instance.
 *
 * @param ti The source task
 * @param newStatus The new state for the task.
 * @param worker Perform additional operations to the bam task summary instance.
 * @return The created or updated bam task summary instance.
 */
protected BAMTaskSummaryImpl createTask(TaskEvent event, Status newStatus, BAMTaskWorker worker) {
    BAMTaskSummaryImpl result = null;
    Task ti = event.getTask();
    TaskPersistenceContext persistenceContext = getPersistenceContext(((TaskContext) event.getTaskContext()).getPersistenceContext());
    try {
        if (ti == null) {
            logger.error("The task instance does not exist.");
            return result;
        }
        Status status = newStatus != null ? newStatus : ti.getTaskData().getStatus();
        String actualOwner = "";
        if (ti.getTaskData().getActualOwner() != null) {
            actualOwner = ti.getTaskData().getActualOwner().getId();
        }
        result = new BAMTaskSummaryImpl(ti.getId(), ti.getName(), status.toString(), event.getEventDate(), actualOwner, ti.getTaskData().getProcessInstanceId());
        if (worker != null)
            worker.createTask(result, ti);
        persistenceContext.persist(result);
        return result;
    } finally {
        cleanup(persistenceContext);
    }
}
Also used : Status(org.kie.api.task.model.Status) Task(org.kie.api.task.model.Task) BAMTaskSummaryImpl(org.jbpm.services.task.audit.impl.model.BAMTaskSummaryImpl) TaskPersistenceContext(org.kie.internal.task.api.TaskPersistenceContext)

Example 2 with Status

use of org.kie.api.task.model.Status in project jbpm by kiegroup.

the class GetTasksByVariableNameAndValueCommand method execute.

public List<TaskSummary> execute(Context cntxt) {
    TaskContext context = (TaskContext) cntxt;
    doCallbackUserOperation(userId, context);
    if (statuses == null) {
        statuses = new ArrayList<Status>();
        statuses.add(Status.Ready);
        statuses.add(Status.InProgress);
        statuses.add(Status.Reserved);
    }
    if (groupIds == null) {
        groupIds = doUserGroupCallbackOperation(userId, null, context);
        if (groupIds == null) {
            groupIds = new ArrayList<String>();
        }
    }
    TaskPersistenceContext persistenceContext = context.getPersistenceContext();
    List<TaskSummary> tasks = (List<TaskSummary>) persistenceContext.queryWithParametersInTransaction("TasksByStatusByVariableNameAndValue", persistenceContext.addParametersToMap("userId", userId, "groupIds", groupIds, "variableName", variableName, "variableValue", variableValue, "status", statuses), ClassUtil.<List<TaskSummary>>castClass(List.class));
    return tasks;
}
Also used : Status(org.kie.api.task.model.Status) TaskContext(org.jbpm.services.task.commands.TaskContext) TaskSummary(org.kie.api.task.model.TaskSummary) ArrayList(java.util.ArrayList) List(java.util.List) TaskPersistenceContext(org.kie.internal.task.api.TaskPersistenceContext)

Example 3 with Status

use of org.kie.api.task.model.Status in project jbpm by kiegroup.

the class CaseRuntimeDataServiceImpl method internalGetCaseStages.

/*
     * Helper methods to parse process and extract case related information
     */
public List<CaseStageInstance> internalGetCaseStages(CaseDefinition caseDef, String caseId, boolean activeOnly, QueryContext queryContext) {
    CorrelationKey correlationKey = correlationKeyFactory.newCorrelationKey(caseId);
    Collection<org.jbpm.services.api.model.NodeInstanceDesc> nodes = runtimeDataService.getNodeInstancesByCorrelationKeyNodeType(correlationKey, Arrays.asList(ProcessInstance.STATE_ACTIVE), Arrays.asList("DynamicNode"), queryContext);
    Collection<Long> completedNodes = nodes.stream().filter(n -> ((NodeInstanceDesc) n).getType() == 1).map(n -> n.getId()).collect(toList());
    Map<String, CaseStage> stagesByName = caseDef.getCaseStages().stream().collect(toMap(CaseStage::getId, c -> c));
    Predicate<org.jbpm.services.api.model.NodeInstanceDesc> filterNodes = null;
    if (activeOnly) {
        filterNodes = n -> ((NodeInstanceDesc) n).getType() == 0 && !completedNodes.contains(((NodeInstanceDesc) n).getId());
    } else {
        filterNodes = n -> ((NodeInstanceDesc) n).getType() == 0;
    }
    List<String> triggeredStages = new ArrayList<>();
    List<CaseStageInstance> stages = new ArrayList<>();
    nodes.stream().filter(filterNodes).map(n -> {
        StageStatus status = StageStatus.Active;
        if (completedNodes.contains(((NodeInstanceDesc) n).getId())) {
            status = StageStatus.Completed;
        }
        Collection<org.jbpm.services.api.model.NodeInstanceDesc> activeNodes = getActiveNodesForCaseAndStage(caseId, n.getNodeId(), new QueryContext(0, 100));
        return new CaseStageInstanceImpl(n.getNodeId(), n.getName(), stagesByName.get(n.getNodeId()).getAdHocFragments(), activeNodes, status);
    }).forEach(csi -> {
        stages.add(csi);
        triggeredStages.add(csi.getName());
    });
    if (!activeOnly) {
        // add other stages that are present in the definition
        caseDef.getCaseStages().stream().filter(cs -> !triggeredStages.contains(cs.getName())).map(cs -> new CaseStageInstanceImpl(cs.getId(), cs.getName(), cs.getAdHocFragments(), Collections.emptyList(), StageStatus.Available)).forEach(csi -> stages.add(csi));
    }
    return stages;
}
Also used : TaskSummary(org.kie.api.task.model.TaskSummary) Arrays(java.util.Arrays) CaseDefinition(org.jbpm.casemgmt.api.model.CaseDefinition) WorkflowProcess(org.jbpm.workflow.core.WorkflowProcess) ProcessDefinition(org.jbpm.services.api.model.ProcessDefinition) BoundaryEventNode(org.jbpm.workflow.core.node.BoundaryEventNode) DynamicNode(org.jbpm.workflow.core.node.DynamicNode) StartNode(org.jbpm.workflow.core.node.StartNode) CaseRuntimeDataService(org.jbpm.casemgmt.api.CaseRuntimeDataService) CaseDefinitionComparator(org.jbpm.casemgmt.impl.model.CaseDefinitionComparator) Collectors.toMap(java.util.stream.Collectors.toMap) NodeInstanceDesc(org.jbpm.kie.services.impl.model.NodeInstanceDesc) Map(java.util.Map) ProcessInstanceDesc(org.jbpm.services.api.model.ProcessInstanceDesc) KieInternalServices(org.kie.internal.KieInternalServices) AuthorizationManager(org.jbpm.casemgmt.api.auth.AuthorizationManager) CaseMilestoneInstance(org.jbpm.casemgmt.api.model.instance.CaseMilestoneInstance) CaseMilestone(org.jbpm.casemgmt.api.model.CaseMilestone) Predicate(java.util.function.Predicate) Collection(java.util.Collection) Process(org.kie.api.definition.process.Process) FILTER(org.kie.internal.query.QueryParameterIdentifiers.FILTER) Set(java.util.Set) DeploymentRolesManager(org.jbpm.kie.services.impl.security.DeploymentRolesManager) QueryContext(org.kie.api.runtime.query.QueryContext) Collectors(java.util.stream.Collectors) CaseMilestoneInstanceImpl(org.jbpm.casemgmt.impl.model.instance.CaseMilestoneInstanceImpl) AbstractRuntimeManager(org.jbpm.runtime.manager.impl.AbstractRuntimeManager) ProcessAssetDesc(org.jbpm.kie.services.impl.model.ProcessAssetDesc) CaseFileItem(org.jbpm.casemgmt.api.model.CaseFileItem) List(java.util.List) DeployedAsset(org.jbpm.services.api.model.DeployedAsset) MilestoneNode(org.jbpm.workflow.core.node.MilestoneNode) AdHocFragment(org.jbpm.casemgmt.api.model.AdHocFragment) ServiceRegistry(org.jbpm.services.api.service.ServiceRegistry) CorrelationKeyFactory(org.kie.internal.process.CorrelationKeyFactory) Status(org.kie.api.task.model.Status) NodeContainer(org.kie.api.definition.process.NodeContainer) AdHocFragmentImpl(org.jbpm.casemgmt.impl.model.AdHocFragmentImpl) CaseDefinitionImpl(org.jbpm.casemgmt.impl.model.CaseDefinitionImpl) CaseRole(org.jbpm.casemgmt.api.model.CaseRole) CaseRoleImpl(org.jbpm.casemgmt.impl.model.CaseRoleImpl) CaseStageInstanceImpl(org.jbpm.casemgmt.impl.model.instance.CaseStageInstanceImpl) CaseNotFoundException(org.jbpm.casemgmt.api.CaseNotFoundException) HashMap(java.util.HashMap) DeploymentEventListener(org.jbpm.services.api.DeploymentEventListener) TransactionalCommandService(org.jbpm.shared.services.impl.TransactionalCommandService) ArrayList(java.util.ArrayList) ProcessDefinitionComparator(org.jbpm.casemgmt.impl.model.ProcessDefinitionComparator) HashSet(java.util.HashSet) CaseStageInstance(org.jbpm.casemgmt.api.model.instance.CaseStageInstance) ProcessInstance(org.kie.api.runtime.process.ProcessInstance) DeploymentEvent(org.jbpm.services.api.DeploymentEvent) CaseInstance(org.jbpm.casemgmt.api.model.instance.CaseInstance) StageStatus(org.jbpm.casemgmt.api.model.instance.StageStatus) CaseStage(org.jbpm.casemgmt.api.model.CaseStage) CaseStageImpl(org.jbpm.casemgmt.impl.model.CaseStageImpl) KieBase(org.kie.api.KieBase) IdentityProvider(org.kie.internal.identity.IdentityProvider) QueryManager(org.jbpm.shared.services.impl.QueryManager) CorrelationKey(org.kie.internal.process.CorrelationKey) QueryNameCommand(org.jbpm.shared.services.impl.commands.QueryNameCommand) CaseIdGenerator(org.jbpm.casemgmt.api.generator.CaseIdGenerator) Collectors.toList(java.util.stream.Collectors.toList) Node(org.kie.api.definition.process.Node) RuntimeDataService(org.jbpm.services.api.RuntimeDataService) CaseStatus(org.jbpm.casemgmt.api.model.CaseStatus) CaseMilestoneImpl(org.jbpm.casemgmt.impl.model.CaseMilestoneImpl) CommonUtils.getAuthenticatedUserRoles(org.jbpm.kie.services.impl.CommonUtils.getAuthenticatedUserRoles) Collections(java.util.Collections) CaseStage(org.jbpm.casemgmt.api.model.CaseStage) ArrayList(java.util.ArrayList) CaseStageInstance(org.jbpm.casemgmt.api.model.instance.CaseStageInstance) QueryContext(org.kie.api.runtime.query.QueryContext) StageStatus(org.jbpm.casemgmt.api.model.instance.StageStatus) CorrelationKey(org.kie.internal.process.CorrelationKey) Collection(java.util.Collection) NodeInstanceDesc(org.jbpm.kie.services.impl.model.NodeInstanceDesc) CaseStageInstanceImpl(org.jbpm.casemgmt.impl.model.instance.CaseStageInstanceImpl)

Example 4 with Status

use of org.kie.api.task.model.Status in project jbpm by kiegroup.

the class AbstractTaskSerializationTest method statusInCommandSerialization.

@Test
public void statusInCommandSerialization() throws Exception {
    Assume.assumeTrue(getType().equals(TestType.JAXB));
    addClassesToSerializationContext(GetTaskAssignedAsPotentialOwnerCommand.class);
    List<Status> statuses = new ArrayList<Status>();
    statuses.add(Status.Completed);
    statuses.add(Status.Exited);
    List<String> groupIds = new ArrayList<String>();
    groupIds.add("team");
    groupIds.add("region");
    QueryFilter filter = new QueryFilter(0, 0, "order", false);
    GetTaskAssignedAsPotentialOwnerCommand cmd = new GetTaskAssignedAsPotentialOwnerCommand("user", groupIds, statuses, filter);
    GetTaskAssignedAsPotentialOwnerCommand copyCmd = testRoundTrip(cmd);
    Assertions.assertThat(cmd).isEqualToComparingFieldByFieldRecursively(copyCmd);
}
Also used : Status(org.kie.api.task.model.Status) QueryFilter(org.kie.internal.query.QueryFilter) ArrayList(java.util.ArrayList) GetTaskAssignedAsPotentialOwnerCommand(org.jbpm.services.task.commands.GetTaskAssignedAsPotentialOwnerCommand) Test(org.junit.Test)

Example 5 with Status

use of org.kie.api.task.model.Status in project jbpm by kiegroup.

the class TaskQueryBuilderLocalTest method testGetTasksByVariousFields.

@Test
public void testGetTasksByVariousFields() {
    Task[] tasks = new Task[12];
    List<Long> workItemIds = new ArrayList<Long>();
    List<Long> procInstIds = new ArrayList<Long>();
    List<Long> taskIds = new ArrayList<Long>();
    List<String> busAdmins = new ArrayList<String>();
    List<String> potOwners = new ArrayList<String>();
    List<Status> statuses = new ArrayList<Status>();
    statuses.add(Status.Reserved);
    TaskImpl taskImpl;
    Long firstTaskId;
    {
        long workItemId = 23;
        long procInstId = 101;
        String busAdmin = "Wintermute";
        String potOwner = "Maelcum";
        taskImpl = addTask(workItemId, procInstId, busAdmin, potOwner, "This is my task name", null);
        firstTaskId = taskImpl.getId();
        taskIds.add(firstTaskId);
        assertEquals(potOwner, taskImpl.getTaskData().getActualOwner().getId());
        tasks[0] = taskImpl;
        procInstIds.add(procInstId);
        workItemIds.add(workItemId);
        busAdmins.add(busAdmin);
        potOwners.add(potOwner);
    }
    List<TaskSummary> results = taskService.taskSummaryQuery(stakeHolder).build().getResultList();
    assertFalse("No tasks retrieved!", results.isEmpty());
    results = taskService.taskSummaryQuery(stakeHolder).workItemId(getUnboxedArray(workItemIds)).build().getResultList();
    assertEquals("List of tasks: work item id", 1, results.size());
    {
        long workItemId = 25;
        long procInstId = 103;
        String busAdmin = "Neuromancer";
        String potOwner = "Hideo";
        taskImpl = addTask(workItemId, procInstId, busAdmin, potOwner, "This is my task name", null);
        taskIds.add(taskImpl.getId());
        assertEquals(potOwner, taskImpl.getTaskData().getActualOwner().getId());
        // start task
        taskService.start(taskImpl.getId(), potOwner);
        tasks[1] = (Task) taskService.getTaskById(taskImpl.getId());
        statuses.add(tasks[1].getTaskData().getStatus());
        procInstIds.add(procInstId);
        workItemIds.add(workItemId);
        busAdmins.add(busAdmin);
        potOwners.add(potOwner);
    }
    {
        // Add one more task, just to make sure things are working well
        long workItemId = 57;
        long procInstId = 111;
        String busAdmin = "reviewer";
        String potOwner = "translator";
        String deploymentId = "armitage";
        String name = "Koude Bevel";
        taskImpl = addTask(workItemId, procInstId, busAdmin, potOwner, name, deploymentId);
        assertEquals(potOwner, taskImpl.getTaskData().getActualOwner().getId());
        taskService.start(taskImpl.getId(), potOwner);
        taskService.fail(taskImpl.getId(), busAdmin, null);
    }
    // everything
    results = taskService.taskSummaryQuery(stakeHolder).build().getResultList();
    assertEquals("List of tasks: everything", 3, results.size());
    testOrderByTaskIdAscending(results);
    // max results
    results = taskService.taskSummaryQuery(stakeHolder).maxResults(2).build().getResultList();
    assertEquals("List of tasks: max results", 2, results.size());
    testOrderByTaskIdAscending(results);
    assertEquals("Did not order when returning tasks (first task id: " + results.get(0).getId(), firstTaskId.longValue(), results.get(0).getId().longValue());
    // single param tests
    results = taskService.taskSummaryQuery(stakeHolder).workItemId(getUnboxedArray(workItemIds)).build().getResultList();
    assertEquals("List of tasks: work item ids", 2, results.size());
    testOrderByTaskIdAscending(results);
    results = taskService.taskSummaryQuery(stakeHolder).taskId(getUnboxedArray(taskIds)).build().getResultList();
    assertEquals("List of tasks: task ids", 2, results.size());
    testOrderByTaskIdAscending(results);
    results = taskService.taskSummaryQuery(stakeHolder).processInstanceId(getUnboxedArray(procInstIds)).build().getResultList();
    assertEquals("List of tasks: process instance ids", 2, results.size());
    testOrderByTaskIdAscending(results);
    results = taskService.taskSummaryQuery(stakeHolder).businessAdmin(busAdmins.toArray(new String[0])).build().getResultList();
    assertEquals("List of tasks: bus admins", 2, results.size());
    testOrderByTaskIdAscending(results);
    results = taskService.taskSummaryQuery(stakeHolder).potentialOwner(potOwners.toArray(new String[0])).build().getResultList();
    assertEquals("List of tasks: pot owners", 2, results.size());
    testOrderByTaskIdAscending(results);
    results = taskService.taskSummaryQuery(stakeHolder).actualOwner(potOwners.toArray(new String[0])).build().getResultList();
    assertEquals("List of tasks: task owners", 2, results.size());
    testOrderByTaskIdAscending(results);
    results = taskService.taskSummaryQuery(stakeHolder).status(statuses.toArray(new Status[0])).build().getResultList();
    assertEquals("List of tasks: status", 2, results.size());
    testOrderByTaskIdAscending(results);
    // work item id and/or task id
    List<Long> testLongList = new ArrayList<Long>();
    testLongList.add(workItemIds.get(0));
    List<Long> testLongListTwo = new ArrayList<Long>();
    testLongListTwo.add(taskIds.get(1));
    results = taskService.taskSummaryQuery(stakeHolder).and().workItemId(getUnboxedArray(testLongList)).taskId(getUnboxedArray(testLongListTwo)).build().getResultList();
    assertEquals("List of tasks", 0, results.size());
    results = taskService.taskSummaryQuery(stakeHolder).or().workItemId(getUnboxedArray(testLongList)).taskId(getUnboxedArray(testLongListTwo)).build().getResultList();
    assertEquals("List of tasks", 2, results.size());
    testOrderByTaskIdAscending(results);
    // task id and/or process instance id
    testLongList.clear();
    testLongList.add(procInstIds.get(1));
    results = taskService.taskSummaryQuery(stakeHolder).or().taskId(getUnboxedArray(testLongListTwo)).processInstanceId(getUnboxedArray(testLongList)).build().getResultList();
    assertEquals("List of tasks", 1, results.size());
    testOrderByTaskIdAscending(results);
    results = taskService.taskSummaryQuery(stakeHolder).and().taskId(getUnboxedArray(testLongListTwo)).processInstanceId(getUnboxedArray(testLongList)).build().getResultList();
    assertEquals("List of tasks", 1, results.size());
    testOrderByTaskIdAscending(results);
    // process instance id and/or bus admin
    List<String> testStringList = new ArrayList<String>();
    testStringList.add(busAdmins.get(0));
    results = taskService.taskSummaryQuery(stakeHolder).and().processInstanceId(getUnboxedArray(testLongList)).businessAdmin(testStringList.toArray(new String[0])).build().getResultList();
    assertEquals("List of tasks", 0, results.size());
    results = taskService.taskSummaryQuery(stakeHolder).or().processInstanceId(getUnboxedArray(testLongList)).businessAdmin(testStringList.toArray(new String[0])).build().getResultList();
    assertEquals("List of tasks", 2, results.size());
    testOrderByTaskIdAscending(results);
    // bus admin and/or pot owner
    testStringList.clear();
    testStringList.add(busAdmins.get(1));
    List<String> testStringListTwo = new ArrayList<String>();
    testStringListTwo.add(potOwners.get(0));
    results = taskService.taskSummaryQuery(stakeHolder).and().businessAdmin(testStringList.toArray(new String[0])).potentialOwner(testStringListTwo.toArray(new String[0])).build().getResultList();
    assertEquals("List of tasks", 0, results.size());
    results = taskService.taskSummaryQuery(stakeHolder).or().businessAdmin(testStringList.toArray(new String[0])).potentialOwner(testStringListTwo.toArray(new String[0])).build().getResultList();
    assertEquals("List of tasks", 2, results.size());
    testOrderByTaskIdAscending(results);
    // pot owner and/or task owner
    testStringList.clear();
    testStringList.add(tasks[1].getTaskData().getActualOwner().getId());
    results = taskService.taskSummaryQuery(stakeHolder).and().potentialOwner(testStringListTwo.toArray(new String[0])).actualOwner(testStringList.toArray(new String[0])).build().getResultList();
    assertEquals("List of tasks", 0, results.size());
    results = taskService.taskSummaryQuery(stakeHolder).or().potentialOwner(testStringListTwo.toArray(new String[0])).actualOwner(testStringList.toArray(new String[0])).build().getResultList();
    assertEquals("List of tasks", 2, results.size());
    testOrderByTaskIdAscending(results);
    // task owner and/or status
    List<Status> testStatusList = new ArrayList<Status>();
    testStatusList.add(statuses.get(0));
    results = taskService.taskSummaryQuery(stakeHolder).and().actualOwner(testStringList.toArray(new String[0])).status(testStatusList.toArray(new Status[0])).build().getResultList();
    assertEquals("List of tasks", 0, results.size());
    results = taskService.taskSummaryQuery(stakeHolder).or().actualOwner(testStringList.toArray(new String[0])).status(testStatusList.toArray(new Status[0])).build().getResultList();
    assertEquals("List of tasks", 2, results.size());
    testOrderByTaskIdAscending(results);
}
Also used : Status(org.kie.api.task.model.Status) Task(org.kie.api.task.model.Task) TaskImpl(org.jbpm.services.task.impl.model.TaskImpl) ArrayList(java.util.ArrayList) TaskSummary(org.kie.api.task.model.TaskSummary) HumanTaskServicesBaseTest(org.jbpm.services.task.HumanTaskServicesBaseTest) Test(org.junit.Test)

Aggregations

Status (org.kie.api.task.model.Status)60 ArrayList (java.util.ArrayList)50 TaskSummary (org.kie.api.task.model.TaskSummary)49 Test (org.junit.Test)44 Task (org.kie.api.task.model.Task)19 HashMap (java.util.HashMap)16 ProcessInstance (org.kie.api.runtime.process.ProcessInstance)16 InternalTask (org.kie.internal.task.api.model.InternalTask)16 StringReader (java.io.StringReader)15 KieSession (org.kie.api.runtime.KieSession)14 QueryFilter (org.kie.internal.query.QueryFilter)14 RuntimeEngine (org.kie.api.runtime.manager.RuntimeEngine)10 QueryContext (org.kie.api.runtime.query.QueryContext)10 AbstractKieServicesBaseTest (org.jbpm.kie.test.util.AbstractKieServicesBaseTest)9 Date (java.util.Date)8 ProcessInstanceDesc (org.jbpm.services.api.model.ProcessInstanceDesc)8 TaskService (org.kie.api.task.TaskService)7 List (java.util.List)5 Properties (java.util.Properties)4 JBossUserGroupCallbackImpl (org.jbpm.services.task.identity.JBossUserGroupCallbackImpl)4