Search in sources :

Example 46 with InternalTask

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

the class UserTaskServiceImplTest method testGetTask.

@Test
public void testGetTask() {
    processInstanceId = processService.startProcess(deploymentUnit.getIdentifier(), "org.jbpm.writedocument.noform");
    assertNotNull(processInstanceId);
    List<Long> taskIds = runtimeDataService.getTasksByProcessInstanceId(processInstanceId);
    assertNotNull(taskIds);
    assertEquals(1, taskIds.size());
    Long taskId = taskIds.get(0);
    Task taskInstance = userTaskService.getTask(taskId);
    assertNotNull(taskInstance);
    assertEquals(Status.Reserved, taskInstance.getTaskData().getStatus());
    assertEquals("Write a Document", taskInstance.getName());
    assertTrue(StringUtils.isEmpty(((InternalTask) taskInstance).getFormName()));
}
Also used : Task(org.kie.api.task.model.Task) InternalTask(org.kie.internal.task.api.model.InternalTask) InternalTask(org.kie.internal.task.api.model.InternalTask) AbstractKieServicesBaseTest(org.jbpm.kie.test.util.AbstractKieServicesBaseTest) Test(org.junit.Test)

Example 47 with InternalTask

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

the class MVELLifeCycleManagerTest method testClaimIsAllowedExcludedOwner.

/**
 * Tests that a user who is in the ExcludedOwners list of the {@link Task task's) {@link PeopleAssignments peopleAssignment's) object is
 * not allowed to execute operations on the given task. We expect to get a {@link PermissionDeniedException}.
 */
@Test(expected = PermissionDeniedException.class)
public void testClaimIsAllowedExcludedOwner() {
    User testUser = new UserImpl("BB8");
    List<String> testGroupIds = new ArrayList<>();
    testGroupIds.add("testGroup1");
    // Create the task.
    String str = "(with (new Task()) { priority = 55, taskData = (with( new TaskData()) { status = Status.Created } ), ";
    str += "peopleAssignments = (with ( new PeopleAssignments() ) { excludedOwners = [new User('BB8')], potentialOwners = [new Group('testGroup1')]}),";
    str += "name =  'This is my task name' })";
    InternalTask task = (InternalTask) TaskFactory.evalTask(new StringReader(str));
    // Test whether we can claim the task. This should not be possible.
    Operation operation = Operation.Claim;
    List<OperationCommand> operationCommands = new ArrayList<>();
    OperationCommand operationCommand = new OperationCommand();
    // Set the list of user-types (e.g. PotentialOwners, BusinessAdministrators, etc.) that are allowed to execute this operation.
    List<Allowed> allowed = new ArrayList<>();
    // We should only allow PotentialOwner in this test (we're claiming a task).
    allowed.add(Allowed.PotentialOwner);
    operationCommand.setAllowed(allowed);
    // Set the status that is required to be able to execute this operation.
    List<Status> status = new ArrayList<>();
    // Before we claim a task, the status is "Created".
    status.add(Status.Created);
    operationCommand.setStatus(status);
    operationCommands.add(operationCommand);
    // We don't need "targetEntity" and "entities" for this test.
    MVELLifeCycleManager taskLcManager = new MVELLifeCycleManager();
    taskLcManager.evalCommand(operation, operationCommands, task, testUser, null, testGroupIds, null);
}
Also used : Status(org.kie.api.task.model.Status) User(org.kie.api.task.model.User) InternalTask(org.kie.internal.task.api.model.InternalTask) ArrayList(java.util.ArrayList) Operation(org.kie.internal.task.api.model.Operation) UserImpl(org.jbpm.services.task.impl.model.UserImpl) StringReader(java.io.StringReader) Test(org.junit.Test)

Example 48 with InternalTask

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

the class MVELLifeCycleManagerTest method testDelegateIsAllowedExcludedOwnerBusinessAdministrator.

/**
 * Tests that a user who is in the ExcludedOwners list of the {@link Task task's) {@link PeopleAssignments peopleAssignment's) object IS
 * allowed to execute operations on the given task IF the person is also a Business Administrator.
 */
@Test
public void testDelegateIsAllowedExcludedOwnerBusinessAdministrator() {
    User testUser = new UserImpl("BB8");
    List<String> testGroupIds = new ArrayList<>();
    testGroupIds.add("testGroup1");
    // Create the task.
    String str = "(with (new Task()) { priority = 55, taskData = (with( new TaskData()) { status = Status.Ready } ), ";
    str += "peopleAssignments = (with ( new PeopleAssignments() ) { excludedOwners = [new User('BB8')], potentialOwners = [new Group('testGroup1')], businessAdministrators = [new User('BB8')]}),";
    str += "name =  'This is my task name' })";
    InternalTask task = (InternalTask) TaskFactory.evalTask(new StringReader(str));
    /*
		 * Test whether we can delegate the task. Because the user is a BusinessAdministrator, this should be possible, even if the owner is
		 * in the ExcludedOwners list.
		 */
    Operation operation = Operation.Delegate;
    List<OperationCommand> operationCommands = new ArrayList<>();
    OperationCommand operationCommand = new OperationCommand();
    // Set the list of user-types (e.g. PotentialOwners, BusinessAdministrators, etc.) that are allowed to execute this operation.
    List<Allowed> allowed = new ArrayList<>();
    // We should only allow PotentialOwner in this test (we're claiming a task).
    allowed.add(Allowed.PotentialOwner);
    allowed.add(Allowed.BusinessAdministrator);
    operationCommand.setAllowed(allowed);
    // Set the status that is required to be able to execute this operation.
    List<Status> status = new ArrayList<>();
    // Before we claim a task, the status is "Created".
    status.add(Status.Ready);
    operationCommand.setStatus(status);
    operationCommands.add(operationCommand);
    // We don't need "targetEntity" and "entities" for this test.
    MVELLifeCycleManager taskLcManager = new MVELLifeCycleManager();
    taskLcManager.evalCommand(operation, operationCommands, task, testUser, null, testGroupIds, null);
}
Also used : Status(org.kie.api.task.model.Status) User(org.kie.api.task.model.User) InternalTask(org.kie.internal.task.api.model.InternalTask) ArrayList(java.util.ArrayList) Operation(org.kie.internal.task.api.model.Operation) UserImpl(org.jbpm.services.task.impl.model.UserImpl) StringReader(java.io.StringReader) Test(org.junit.Test)

Example 49 with InternalTask

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

the class AbstractTaskSerializationTest method jaxbTaskTest.

// TESTS ----------------------------------------------------------------------------------------------------------------------
@Test
public void jaxbTaskTest() throws Exception {
    // Yaml serialization requires major changes in order to be supported.. :/
    Assume.assumeTrue(!getType().equals(TestType.YAML));
    Map<String, Object> vars = new HashMap<String, Object>();
    vars.put("now", new Date());
    InputStream stream = getClass().getResourceAsStream(MvelFilePath.FullTask);
    assertNotNull("Could not load file: " + MvelFilePath.FullTask, stream);
    Reader reader = new InputStreamReader(stream);
    InternalTask task = (InternalTask) TaskFactory.evalTask(reader, vars);
    // fill task
    task.setFormName("Bruno's Form");
    task.setId(23L);
    task.setSubTaskStrategy(SubTasksStrategy.EndParentOnAllSubTasksEnd);
    for (I18NText text : task.getNames()) {
        ((InternalI18NText) text).setId((long) random.nextInt(1000));
    }
    for (I18NText text : task.getSubjects()) {
        ((InternalI18NText) text).setId((long) random.nextInt(1000));
    }
    for (I18NText text : task.getDescriptions()) {
        ((InternalI18NText) text).setId((long) random.nextInt(1000));
    }
    // fill task -> task data
    InternalTaskData taskData = (InternalTaskData) task.getTaskData();
    taskData.setOutputAccessType(AccessType.Inline);
    taskData.setFaultAccessType(AccessType.Unknown);
    taskData.setTaskInputVariables(new HashMap<String, Object>());
    taskData.setTaskOutputVariables(new HashMap<String, Object>());
    // fill task -> task data -> comment
    String payload = "brainwashArmitageRecruitCaseGetPasswordFromLady3JaneAscentToStraylightIcebreakerUniteWithNeuromancer";
    InternalComment comment = (InternalComment) TaskModelProvider.getFactory().newComment();
    comment.setId(42);
    comment.setText(payload);
    comment.setAddedAt(new Date());
    User user = TaskModelProvider.getFactory().newUser();
    ((InternalOrganizationalEntity) user).setId("Case");
    comment.setAddedBy(user);
    taskData.addComment(comment);
    // fill task -> task data -> attachment
    InternalAttachment attach = (InternalAttachment) TaskModelProvider.getFactory().newAttachment();
    attach.setId(10);
    attach.setName("virus");
    attach.setContentType("ROM");
    attach.setAttachedAt(new Date());
    user = TaskModelProvider.getFactory().newUser();
    ((InternalOrganizationalEntity) user).setId("Wintermute");
    attach.setAttachedBy(user);
    attach.setSize(payload.getBytes().length);
    attach.setAttachmentContentId(comment.getId());
    taskData.addAttachment(attach);
    JaxbTask xmlTask = new JaxbTask(task);
    verifyThatAllFieldsAreFilledOrUnsupported(xmlTask, InternalTask.class);
    verifyThatAllFieldsAreFilledOrUnsupported(xmlTask.getTaskData(), TaskData.class);
    verifyThatAllFieldsAreFilledOrUnsupported(xmlTask.getTaskData().getAttachments().get(0), Attachment.class);
    verifyThatAllFieldsAreFilledOrUnsupported(xmlTask.getTaskData().getComments().get(0), Comment.class);
    assertNotNull(xmlTask.getNames());
    assertTrue(xmlTask.getNames().size() > 0);
    JaxbTask bornAgainTask = testRoundTrip(xmlTask);
    assertNotNull(bornAgainTask.getNames());
    assertTrue("Round-tripped task has empty 'names' list!", !bornAgainTask.getNames().isEmpty());
    Assertions.assertThat(xmlTask).isEqualToComparingFieldByFieldRecursively(bornAgainTask);
    assertNotNull(((InternalTask) xmlTask).getFormName());
    assertEquals(((InternalTask) xmlTask).getFormName(), ((InternalTask) bornAgainTask).getFormName());
    Task realTask = xmlTask.getTask();
    verifyThatXmlFieldsAreFilled(realTask, xmlTask, InternalTask.class, "deadlines");
    verifyThatXmlFieldsAreFilled(realTask.getTaskData(), xmlTask.getTaskData(), TaskData.class, "taskInputVariables", "taskOutputVariables");
}
Also used : I18NText(org.kie.api.task.model.I18NText) JaxbI18NText(org.jbpm.services.task.impl.model.xml.JaxbI18NText) InternalI18NText(org.kie.internal.task.api.model.InternalI18NText) Task(org.kie.api.task.model.Task) InternalTask(org.kie.internal.task.api.model.InternalTask) JaxbTask(org.jbpm.services.task.impl.model.xml.JaxbTask) User(org.kie.api.task.model.User) JaxbTask(org.jbpm.services.task.impl.model.xml.JaxbTask) InputStreamReader(java.io.InputStreamReader) HashMap(java.util.HashMap) InternalTask(org.kie.internal.task.api.model.InternalTask) InternalI18NText(org.kie.internal.task.api.model.InternalI18NText) InternalAttachment(org.kie.internal.task.api.model.InternalAttachment) InputStream(java.io.InputStream) InternalComment(org.kie.internal.task.api.model.InternalComment) InternalTaskData(org.kie.internal.task.api.model.InternalTaskData) Reader(java.io.Reader) InputStreamReader(java.io.InputStreamReader) InternalOrganizationalEntity(org.kie.internal.task.api.model.InternalOrganizationalEntity) Date(java.util.Date) Test(org.junit.Test)

Example 50 with InternalTask

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

the class TaskTransactionInterceptor method postInit.

private void postInit(Object result) {
    if (result instanceof Task) {
        Task task = (Task) result;
        if (task != null && !eagerDisabled) {
            task.getNames().size();
            task.getDescriptions().size();
            task.getSubjects().size();
            task.getPeopleAssignments().getBusinessAdministrators().size();
            task.getPeopleAssignments().getPotentialOwners().size();
            ((InternalPeopleAssignments) task.getPeopleAssignments()).getRecipients().size();
            ((InternalPeopleAssignments) task.getPeopleAssignments()).getExcludedOwners().size();
            ((InternalPeopleAssignments) task.getPeopleAssignments()).getTaskStakeholders().size();
            task.getTaskData().getAttachments().size();
            task.getTaskData().getComments().size();
            ((InternalTask) task).getDeadlines().getStartDeadlines().size();
            ((InternalTask) task).getDeadlines().getEndDeadlines().size();
            if (((InternalTask) task).getDelegation() != null) {
                ((InternalTask) task).getDelegation().getDelegates().size();
            }
        }
    } else if (result instanceof Collection<?>) {
        ((Collection<?>) result).size();
    }
}
Also used : Task(org.kie.api.task.model.Task) InternalTask(org.kie.internal.task.api.model.InternalTask) InternalTask(org.kie.internal.task.api.model.InternalTask)

Aggregations

InternalTask (org.kie.internal.task.api.model.InternalTask)50 Task (org.kie.api.task.model.Task)29 Test (org.junit.Test)27 ArrayList (java.util.ArrayList)21 InternalTaskData (org.kie.internal.task.api.model.InternalTaskData)18 OrganizationalEntity (org.kie.api.task.model.OrganizationalEntity)17 InputStreamReader (java.io.InputStreamReader)16 Reader (java.io.Reader)16 User (org.kie.api.task.model.User)16 CountDownTaskEventListener (org.jbpm.services.task.util.CountDownTaskEventListener)15 InternalPeopleAssignments (org.kie.internal.task.api.model.InternalPeopleAssignments)15 InternalOrganizationalEntity (org.kie.internal.task.api.model.InternalOrganizationalEntity)14 Date (java.util.Date)12 HashMap (java.util.HashMap)11 ContentData (org.kie.internal.task.api.model.ContentData)11 InternalContent (org.kie.internal.task.api.model.InternalContent)11 I18NText (org.kie.api.task.model.I18NText)10 InternalI18NText (org.kie.internal.task.api.model.InternalI18NText)8 TaskSummary (org.kie.api.task.model.TaskSummary)6 StringReader (java.io.StringReader)5