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