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);
}
}
}
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);
}
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);
}
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);
}
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;
}
Aggregations