Search in sources :

Example 51 with UserImpl

use of org.jbpm.services.task.impl.model.UserImpl in project jbpm by kiegroup.

the class SubCaseServiceImplTest method testStartCaseWithSubCaseAbortProcessInstanceOfSubCase.

@Test
public void testStartCaseWithSubCaseAbortProcessInstanceOfSubCase() {
    Map<String, OrganizationalEntity> roleAssignments = new HashMap<>();
    roleAssignments.put("owner", new UserImpl("john"));
    roleAssignments.put("manager", new UserImpl("mary"));
    Map<String, Object> data = new HashMap<>();
    data.put("name", "John Doe");
    CaseFileInstance caseFile = caseService.newCaseFileInstance(deploymentUnit.getIdentifier(), BASIC_SUB_CASE_P_ID, data, roleAssignments);
    String caseId = caseService.startCase(deploymentUnit.getIdentifier(), BASIC_SUB_CASE_P_ID, caseFile);
    assertNotNull(caseId);
    assertEquals(SUB_CASE_ID, caseId);
    try {
        CaseInstance cInstance = caseService.getCaseInstance(caseId);
        assertNotNull(cInstance);
        assertEquals(deploymentUnit.getIdentifier(), cInstance.getDeploymentId());
        caseService.triggerAdHocFragment(caseId, "Sub Case", null);
        Collection<CaseInstance> caseInstances = caseRuntimeDataService.getCaseInstances(new QueryContext());
        assertNotNull(caseInstances);
        assertEquals(2, caseInstances.size());
        Map<String, CaseInstance> byCaseId = caseInstances.stream().collect(toMap(CaseInstance::getCaseId, c -> c));
        assertTrue(byCaseId.containsKey(SUB_CASE_ID));
        assertTrue(byCaseId.containsKey(HR_CASE_ID));
        List<TaskSummary> tasks = caseRuntimeDataService.getCaseTasksAssignedAsPotentialOwner(HR_CASE_ID, "john", null, new QueryContext());
        assertNotNull(tasks);
        assertEquals(1, tasks.size());
        assertEquals("Hello1", tasks.get(0).getName());
        CaseFileInstance mainCaseFile = caseService.getCaseFileInstance(caseId);
        assertNotNull(mainCaseFile);
        assertNull(mainCaseFile.getData("subCaseId"));
        processService.abortProcessInstance(tasks.get(0).getProcessInstanceId());
        mainCaseFile = caseService.getCaseFileInstance(caseId);
        assertNotNull(mainCaseFile);
        assertEquals(HR_CASE_ID, mainCaseFile.getData("subCaseId"));
        assertEquals("John Doe", mainCaseFile.getData("outcome"));
    } catch (Exception e) {
        logger.error("Unexpected error {}", e.getMessage(), e);
        fail("Unexpected exception " + e.getMessage());
    } finally {
        if (caseId != null) {
            caseService.cancelCase(caseId);
        }
    }
}
Also used : TaskSummary(org.kie.api.task.model.TaskSummary) Arrays(java.util.Arrays) UserImpl(org.jbpm.services.task.impl.model.UserImpl) CaseFileInstance(org.jbpm.casemgmt.api.model.instance.CaseFileInstance) LoggerFactory(org.slf4j.LoggerFactory) HashMap(java.util.HashMap) QueryFilter(org.kie.internal.query.QueryFilter) ArrayList(java.util.ArrayList) OrganizationalEntity(org.kie.api.task.model.OrganizationalEntity) Collectors.toMap(java.util.stream.Collectors.toMap) ProcessInstance(org.jbpm.process.instance.ProcessInstance) CaseInstance(org.jbpm.casemgmt.api.model.instance.CaseInstance) Map(java.util.Map) ProcessInstanceDesc(org.jbpm.services.api.model.ProcessInstanceDesc) TaskSpecification(org.jbpm.casemgmt.api.dynamic.TaskSpecification) Logger(org.slf4j.Logger) Assert.assertNotNull(org.junit.Assert.assertNotNull) Collection(java.util.Collection) AbstractCaseServicesBaseTest(org.jbpm.casemgmt.impl.util.AbstractCaseServicesBaseTest) Assert.assertTrue(org.junit.Assert.assertTrue) Test(org.junit.Test) QueryContext(org.kie.api.runtime.query.QueryContext) Consumer(java.util.function.Consumer) List(java.util.List) Assertions.fail(org.assertj.core.api.Assertions.fail) Assert.assertNull(org.junit.Assert.assertNull) CaseStatus(org.jbpm.casemgmt.api.model.CaseStatus) Assert.assertEquals(org.junit.Assert.assertEquals) OrganizationalEntity(org.kie.api.task.model.OrganizationalEntity) HashMap(java.util.HashMap) QueryContext(org.kie.api.runtime.query.QueryContext) CaseFileInstance(org.jbpm.casemgmt.api.model.instance.CaseFileInstance) CaseInstance(org.jbpm.casemgmt.api.model.instance.CaseInstance) UserImpl(org.jbpm.services.task.impl.model.UserImpl) TaskSummary(org.kie.api.task.model.TaskSummary) AbstractCaseServicesBaseTest(org.jbpm.casemgmt.impl.util.AbstractCaseServicesBaseTest) Test(org.junit.Test)

Example 52 with UserImpl

use of org.jbpm.services.task.impl.model.UserImpl 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 53 with UserImpl

use of org.jbpm.services.task.impl.model.UserImpl 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 54 with UserImpl

use of org.jbpm.services.task.impl.model.UserImpl in project jbpm by kiegroup.

the class AbstractTaskSerializationTest method jaxbCommentTest.

@Test
public void jaxbCommentTest() throws Exception {
    Assume.assumeFalse(getType().equals(TestType.YAML));
    CommentImpl comment = new CommentImpl();
    comment.setAddedAt(new Date());
    comment.setAddedBy(new UserImpl("user"));
    comment.setId(23l);
    comment.setText("ILLUMINATI!");
    JaxbComment jaxbComment = new JaxbComment(comment);
    assertEquals("added at", comment.getAddedAt(), jaxbComment.getAddedAt());
    assertEquals("added by", comment.getAddedBy().getId(), jaxbComment.getAddedById());
    assertEquals("added by", comment.getAddedBy().getId(), jaxbComment.getAddedBy().getId());
    assertEquals("id", comment.getId(), jaxbComment.getId());
    assertEquals("text", comment.getText(), jaxbComment.getText());
    JaxbComment copyJaxbComment = testRoundTrip(jaxbComment);
    Assertions.assertThat(jaxbComment).isEqualToComparingFieldByFieldRecursively(copyJaxbComment);
}
Also used : UserImpl(org.jbpm.services.task.impl.model.UserImpl) CommentImpl(org.jbpm.services.task.impl.model.CommentImpl) JaxbComment(org.jbpm.services.task.impl.model.xml.JaxbComment) Date(java.util.Date) Test(org.junit.Test)

Example 55 with UserImpl

use of org.jbpm.services.task.impl.model.UserImpl in project jbpm by kiegroup.

the class TaskSummaryQueryCriteriaUtil method taskImplSpecificGetEntityField.

@SuppressWarnings("unchecked")
public static <T> Expression taskImplSpecificGetEntityField(CriteriaQuery<T> query, Root<TaskImpl> taskRoot, Join<TaskImpl, TaskDataImpl> taskDataJoin, Join<TaskImpl, PeopleAssignmentsImpl> peopleAssignJoin, String listId, Attribute attr) {
    Expression entityField = null;
    if (attr != null) {
        if (listId.equals(TASK_DESCRIPTION_LIST) || listId.equals(TASK_NAME_LIST) || listId.equals(TASK_SUBJECT_LIST)) {
            // we can *not* query on @LOB annotated fields (and it would be inefficient for a query api to do this?)
            // so we query on the (max 255 char length) string equivalent fields
            entityField = getJoinedEntityField(taskRoot, (Attribute<TaskImpl, I18NTextImpl>) attr, I18NTextImpl_.shortText);
        } else if (listId.equals(ACTUAL_OWNER_ID_LIST) || listId.equals(CREATED_BY_LIST)) {
            if (taskDataJoin == null) {
                taskDataJoin = taskRoot.join(TaskImpl_.taskData);
            }
            // task -> taskData -> (actualOwn/createdBy) UserImpl ->  id
            entityField = getJoinedEntityField(taskDataJoin, (Attribute<TaskDataImpl, UserImpl>) attr, UserImpl_.id);
        } else if (listId.equals(BUSINESS_ADMIN_ID_LIST) || listId.equals(POTENTIAL_OWNER_ID_LIST) || listId.equals(STAKEHOLDER_ID_LIST) || listId.equals(EXCLUDED_OWNER_ID_LIST)) {
            if (peopleAssignJoin == null) {
                peopleAssignJoin = taskRoot.join(TaskImpl_.peopleAssignments);
            }
            // task -> peopleAssignments -> (bus admin/pot owner/stake holder/excl user) OrganizationalEntityImpl ->  id
            entityField = getJoinedEntityField(peopleAssignJoin, (Attribute<PeopleAssignmentsImpl, OrganizationalEntityImpl>) attr, OrganizationalEntityImpl_.id);
        } else {
            if (taskDataJoin == null) {
                taskDataJoin = taskRoot.join(TaskImpl_.taskData);
            }
            Class attrType = attr.getDeclaringType().getJavaType();
            From[] taskRoots = { taskRoot, taskDataJoin };
            for (From from : taskRoots) {
                if (from.getJavaType().equals(attrType)) {
                    if (attr != null) {
                        if (attr instanceof SingularAttribute) {
                            entityField = from.get((SingularAttribute) attr);
                        } else if (attr instanceof PluralAttribute) {
                            entityField = from.get((PluralAttribute) attr);
                        } else {
                            throw new IllegalStateException("Unexpected attribute type when processing criteria with list id " + listId + ": " + attr.getClass().getName());
                        }
                        break;
                    }
                }
            }
        }
    }
    return entityField;
}
Also used : SingularAttribute(javax.persistence.metamodel.SingularAttribute) Expression(javax.persistence.criteria.Expression) SingularAttribute(javax.persistence.metamodel.SingularAttribute) Attribute(javax.persistence.metamodel.Attribute) ListAttribute(javax.persistence.metamodel.ListAttribute) CollectionAttribute(javax.persistence.metamodel.CollectionAttribute) PluralAttribute(javax.persistence.metamodel.PluralAttribute) SetAttribute(javax.persistence.metamodel.SetAttribute) PluralAttribute(javax.persistence.metamodel.PluralAttribute) UserImpl(org.jbpm.services.task.impl.model.UserImpl) From(javax.persistence.criteria.From) TaskDataImpl(org.jbpm.services.task.impl.model.TaskDataImpl)

Aggregations

UserImpl (org.jbpm.services.task.impl.model.UserImpl)57 Test (org.junit.Test)52 OrganizationalEntity (org.kie.api.task.model.OrganizationalEntity)51 HashMap (java.util.HashMap)49 CaseFileInstance (org.jbpm.casemgmt.api.model.instance.CaseFileInstance)49 AbstractCaseServicesBaseTest (org.jbpm.casemgmt.impl.util.AbstractCaseServicesBaseTest)49 CaseInstance (org.jbpm.casemgmt.api.model.instance.CaseInstance)42 QueryContext (org.kie.api.runtime.query.QueryContext)33 AdHocFragmentNotFoundException (org.jbpm.casemgmt.api.AdHocFragmentNotFoundException)25 CaseActiveException (org.jbpm.casemgmt.api.CaseActiveException)25 CaseCommentNotFoundException (org.jbpm.casemgmt.api.CaseCommentNotFoundException)25 CaseNotFoundException (org.jbpm.casemgmt.api.CaseNotFoundException)25 TaskNotFoundException (org.jbpm.services.api.TaskNotFoundException)25 TaskSummary (org.kie.api.task.model.TaskSummary)21 QueryFilter (org.kie.internal.query.QueryFilter)10 ArrayList (java.util.ArrayList)9 GroupImpl (org.jbpm.services.task.impl.model.GroupImpl)9 CaseStageInstance (org.jbpm.casemgmt.api.model.instance.CaseStageInstance)8 ProcessInstanceDesc (org.jbpm.services.api.model.ProcessInstanceDesc)7 CaseAssignment (org.kie.api.runtime.process.CaseAssignment)7