Search in sources :

Example 1 with TaskInstanceService

use of org.kie.internal.task.api.TaskInstanceService in project jbpm by kiegroup.

the class CompleteTaskCommand method execute.

public Void execute(Context cntxt) {
    TaskContext context = (TaskContext) cntxt;
    doCallbackUserOperation(userId, context, true);
    groupIds = doUserGroupCallbackOperation(userId, null, context);
    context.set("local:groups", groupIds);
    Task task = context.getTaskQueryService().getTaskInstanceById(taskId);
    if (task == null) {
        throw new PermissionDeniedException("Task '" + taskId + "' not found");
    }
    context.loadTaskVariables(task);
    Map<String, Object> outputdata = task.getTaskData().getTaskOutputVariables();
    if (outputdata != null) {
        // if there are data given with completion, merged them into existing outputs
        if (data != null) {
            outputdata.putAll(data);
        }
        // since output data was non null make it the actual data
        data = outputdata;
    }
    context.getTaskRuleService().executeRules(task, userId, data, TaskRuleService.COMPLETE_TASK_SCOPE);
    ((InternalTaskData) task.getTaskData()).setTaskOutputVariables(data);
    TaskInstanceService instanceService = context.getTaskInstanceService();
    instanceService.complete(taskId, userId, data);
    return null;
}
Also used : Task(org.kie.api.task.model.Task) TaskInstanceService(org.kie.internal.task.api.TaskInstanceService) InternalTaskData(org.kie.internal.task.api.model.InternalTaskData) PermissionDeniedException(org.jbpm.services.task.exception.PermissionDeniedException)

Example 2 with TaskInstanceService

use of org.kie.internal.task.api.TaskInstanceService in project jbpm by kiegroup.

the class ProcessSubTaskCommand method execute.

@Override
public Void execute(Context cntxt) {
    TaskContext context = (TaskContext) cntxt;
    TaskInstanceService instanceService = context.getTaskInstanceService();
    TaskQueryService queryService = context.getTaskQueryService();
    Task task = queryService.getTaskInstanceById(taskId);
    if (task == null) {
        return null;
    }
    Task parentTask = null;
    if (task.getTaskData().getParentId() != -1) {
        parentTask = queryService.getTaskInstanceById(task.getTaskData().getParentId());
    }
    if (parentTask != null) {
        if (((InternalTask) parentTask).getSubTaskStrategy() != null && ((InternalTask) parentTask).getSubTaskStrategy().equals(SubTasksStrategy.EndParentOnAllSubTasksEnd)) {
            List<TaskSummary> subTasks = queryService.getSubTasksByParent(parentTask.getId());
            // If there are no more sub tasks or if the last sub task is the one that we are completing now
            if (subTasks.isEmpty() || (subTasks.size() == 1 && subTasks.get(0).getId().equals(taskId))) {
                // Completing parent task if all the sub task has being completed, including the one that we are completing now
                instanceService.complete(parentTask.getId(), "Administrator", data);
            }
        }
    }
    if (((InternalTask) task).getSubTaskStrategy() != null && ((InternalTask) task).getSubTaskStrategy().equals(SubTasksStrategy.SkipAllSubTasksOnParentSkip)) {
        List<TaskSummary> subTasks = queryService.getSubTasksByParent(task.getId());
        for (TaskSummary taskSummary : subTasks) {
            Task subTask = queryService.getTaskInstanceById(taskSummary.getId());
            // Exit each sub task because the parent task was aborted
            instanceService.skip(subTask.getId(), "Administrator");
        }
    }
    return null;
}
Also used : Task(org.kie.api.task.model.Task) InternalTask(org.kie.internal.task.api.model.InternalTask) TaskInstanceService(org.kie.internal.task.api.TaskInstanceService) InternalTask(org.kie.internal.task.api.model.InternalTask) TaskSummary(org.kie.api.task.model.TaskSummary) TaskQueryService(org.kie.internal.task.api.TaskQueryService)

Example 3 with TaskInstanceService

use of org.kie.internal.task.api.TaskInstanceService in project jbpm by kiegroup.

the class SetTaskPropertyCommand method execute.

public Void execute(Context cntxt) {
    TaskContext context = (TaskContext) cntxt;
    TaskInstanceService service = context.getTaskInstanceService();
    switch(property) {
        case FAULT_PROPERTY:
            doCallbackUserOperation(userId, context, true);
            service.setFault(taskId, userId, faultData);
            break;
        case OUTPUT_PROPERTY:
            doCallbackUserOperation(userId, context, true);
            service.setOutput(taskId, userId, output);
            break;
        case PRIORITY_PROPERTY:
            service.setPriority(taskId, priority);
            break;
        case TASK_NAMES_PROPERTY:
            List<I18NText> names = null;
            if (namesOrDescriptions != null) {
                names = JaxbI18NText.convertListFromJaxbImplToInterface(namesOrDescriptions);
            }
            service.setTaskNames(taskId, names);
            break;
        case EXPIRATION_DATE_PROPERTY:
            service.setExpirationDate(taskId, expirationDate);
            break;
        case DESCRIPTION_PROPERTY:
            List<I18NText> descriptions = null;
            if (namesOrDescriptions != null) {
                descriptions = JaxbI18NText.convertListFromJaxbImplToInterface(namesOrDescriptions);
            }
            service.setDescriptions(taskId, descriptions);
            break;
        case SKIPPABLE_PROPERTY:
            service.setSkipable(taskId, skippable);
            break;
        case SUB_TASK_STRATEGY_PROPERTY:
            service.setSubTaskStrategy(taskId, subTasksStrategy);
            break;
        default:
            throw new IllegalStateException("Unknown property in " + this.getClass().getSimpleName() + " execute: " + property);
    }
    return null;
}
Also used : I18NText(org.kie.api.task.model.I18NText) JaxbI18NText(org.jbpm.services.task.impl.model.xml.JaxbI18NText) TaskInstanceService(org.kie.internal.task.api.TaskInstanceService)

Example 4 with TaskInstanceService

use of org.kie.internal.task.api.TaskInstanceService in project jbpm by kiegroup.

the class GetTaskPropertyCommand method execute.

public Object execute(Context cntxt) {
    TaskContext context = (TaskContext) cntxt;
    TaskInstanceService service = context.getTaskInstanceService();
    Object result = null;
    switch(property) {
        case SetTaskPropertyCommand.PRIORITY_PROPERTY:
            result = service.getPriority(taskId);
            break;
        case SetTaskPropertyCommand.EXPIRATION_DATE_PROPERTY:
            result = service.getExpirationDate(taskId);
            break;
        case SetTaskPropertyCommand.DESCRIPTION_PROPERTY:
            result = service.getDescriptions(taskId);
            break;
        case SetTaskPropertyCommand.SKIPPABLE_PROPERTY:
            result = service.isSkipable(taskId);
            break;
        case SetTaskPropertyCommand.SUB_TASK_STRATEGY_PROPERTY:
            result = service.getSubTaskStrategy(taskId);
            break;
        default:
            break;
    }
    return result;
}
Also used : TaskInstanceService(org.kie.internal.task.api.TaskInstanceService)

Example 5 with TaskInstanceService

use of org.kie.internal.task.api.TaskInstanceService in project jbpm by kiegroup.

the class JaxbTaskSerializationTest method setTaskPropertyCommandTest.

@Test
public void setTaskPropertyCommandTest() throws Exception {
    SetTaskPropertyCommand cmd;
    int taskId = 1;
    String userId = "user";
    FaultDataImpl faultData = new FaultDataImpl();
    faultData.setAccessType(AccessType.Inline);
    faultData.setContent("skinned shins".getBytes());
    faultData.setFaultName("Whoops!");
    faultData.setType("skates");
    List<I18NText> textList = new ArrayList<I18NText>();
    I18NText text = new I18NTextImpl("nl-NL", "Stroopwafel!");
    textList.add(text);
    Object[][] testData = { { FAULT_PROPERTY, faultData }, { OUTPUT_PROPERTY, new Object() }, { PRIORITY_PROPERTY, 23 }, { TASK_NAMES_PROPERTY, textList }, { EXPIRATION_DATE_PROPERTY, new Date() }, { DESCRIPTION_PROPERTY, new ArrayList<I18NText>() }, { SKIPPABLE_PROPERTY, false }, { SUB_TASK_STRATEGY_PROPERTY, SubTasksStrategy.EndParentOnAllSubTasksEnd } };
    TaskContext mockContext = mock(TaskContext.class);
    TaskInstanceService mockTaskService = mock(TaskInstanceService.class);
    UserGroupCallback mockUserGroupCallback = mock(UserGroupCallback.class);
    when(mockContext.getTaskInstanceService()).thenReturn(mockTaskService);
    when(mockContext.getUserGroupCallback()).thenReturn(mockUserGroupCallback);
    when(mockUserGroupCallback.existsUser(anyString())).thenReturn(false);
    for (Object[] data : testData) {
        int property = (Integer) data[0];
        cmd = new SetTaskPropertyCommand(taskId, userId, property, data[1]);
        try {
            cmd.execute(mockContext);
        } catch (IllegalArgumentException e) {
            // expected for fault and output
            assertTrue(e.getMessage().startsWith("User user was not found in callback "));
        }
    }
}
Also used : I18NText(org.kie.api.task.model.I18NText) TaskContext(org.jbpm.services.task.commands.TaskContext) ArrayList(java.util.ArrayList) Matchers.anyString(org.mockito.Matchers.anyString) UserGroupCallback(org.kie.internal.task.api.UserGroupCallback) Date(java.util.Date) FaultDataImpl(org.jbpm.services.task.impl.model.FaultDataImpl) TaskInstanceService(org.kie.internal.task.api.TaskInstanceService) SetTaskPropertyCommand(org.jbpm.services.task.commands.SetTaskPropertyCommand) I18NTextImpl(org.jbpm.services.task.impl.model.I18NTextImpl) Test(org.junit.Test)

Aggregations

TaskInstanceService (org.kie.internal.task.api.TaskInstanceService)5 I18NText (org.kie.api.task.model.I18NText)2 Task (org.kie.api.task.model.Task)2 ArrayList (java.util.ArrayList)1 Date (java.util.Date)1 SetTaskPropertyCommand (org.jbpm.services.task.commands.SetTaskPropertyCommand)1 TaskContext (org.jbpm.services.task.commands.TaskContext)1 PermissionDeniedException (org.jbpm.services.task.exception.PermissionDeniedException)1 FaultDataImpl (org.jbpm.services.task.impl.model.FaultDataImpl)1 I18NTextImpl (org.jbpm.services.task.impl.model.I18NTextImpl)1 JaxbI18NText (org.jbpm.services.task.impl.model.xml.JaxbI18NText)1 Test (org.junit.Test)1 TaskSummary (org.kie.api.task.model.TaskSummary)1 TaskQueryService (org.kie.internal.task.api.TaskQueryService)1 UserGroupCallback (org.kie.internal.task.api.UserGroupCallback)1 InternalTask (org.kie.internal.task.api.model.InternalTask)1 InternalTaskData (org.kie.internal.task.api.model.InternalTaskData)1 Matchers.anyString (org.mockito.Matchers.anyString)1