use of org.kie.api.task.model.Task in project jbpm by kiegroup.
the class LifeCycleBaseTest method testClaimWithGroupAssignee.
@Test
public void testClaimWithGroupAssignee() throws Exception {
// One potential owner, should go straight to state Reserved
String str = "(with (new Task()) { priority = 55, taskData = (with( new TaskData()) { } ), ";
str += "peopleAssignments = (with ( new PeopleAssignments() ) { potentialOwners = [new Group('Knights Templer' )], businessAdministrators = [ new User('Administrator') ], }),";
str += "name = 'This is my task name' })";
Task task = TaskFactory.evalTask(new StringReader(str));
taskService.addTask(task, new HashMap<String, Object>());
long taskId = task.getId();
// A Task with multiple potential owners moves to "Ready" state until someone claims it.
Task task1 = taskService.getTaskById(taskId);
assertEquals(Status.Ready, task1.getTaskData().getStatus());
taskService.claim(taskId, "Darth Vader");
Task task2 = taskService.getTaskById(taskId);
assertEquals(Status.Reserved, task2.getTaskData().getStatus());
assertEquals("Darth Vader", task2.getTaskData().getActualOwner().getId());
}
use of org.kie.api.task.model.Task in project jbpm by kiegroup.
the class LifeCycleBaseTest method testNewTaskWithMapContentAndOutput.
/*
* This test shows how to work with a task and save severeal intermediate steps of the content that the
* task is handling.
* The input parameters for this task are: (key1,value1) (key3,value3).
*
* (key2, null) is a variable that is input/output, this means that is a variable that comes defined, but it value can be changed
* by the user
*
* The expected outputs for the task are: (key2, value2), (key4, value4) (key5, value5) (key6, value6)
*/
@Test
public void testNewTaskWithMapContentAndOutput() {
String str = "(with (new Task()) { priority = 55, taskData = (with( new TaskData()) { } ), ";
str += "peopleAssignments = (with ( new PeopleAssignments() ) { potentialOwners = [new User('Bobba Fet') ],businessAdministrators = [ new User('Administrator') ], }),";
str += "name = 'This is my task name' })";
Map<String, Object> variablesMap = new HashMap<String, Object>();
variablesMap.put("key1", "value1");
variablesMap.put("key2", null);
variablesMap.put("key3", "value3");
ContentData data = ContentMarshallerHelper.marshal(null, variablesMap, null);
Task task = TaskFactory.evalTask(new StringReader(str));
taskService.addTask(task, data);
long taskId = task.getId();
// Task should be assigned to the single potential owner and state set to Reserved
Task task1 = taskService.getTaskById(taskId);
assertEquals(AccessType.Inline, ((InternalTaskData) task1.getTaskData()).getDocumentAccessType());
assertEquals("java.util.HashMap", task1.getTaskData().getDocumentType());
long contentId = task1.getTaskData().getDocumentContentId();
assertTrue(contentId != -1);
Content content = taskService.getContentById(contentId);
Object unmarshalledObject = ContentMarshallerHelper.unmarshall(content.getContent(), null);
if (!(unmarshalledObject instanceof Map)) {
fail("The variables should be a Map");
}
xmlRoundTripContent(content);
Map<String, Object> unmarshalledvars = (Map<String, Object>) unmarshalledObject;
assertEquals("value1", unmarshalledvars.get("key1"));
assertNull(unmarshalledvars.get("key2"));
assertEquals("value3", unmarshalledvars.get("key3"));
taskService.start(taskId, "Bobba Fet");
task1 = taskService.getTaskById(taskId);
assertEquals(Status.InProgress, task1.getTaskData().getStatus());
// Once the task has being started the user decide to start working on it.
Map<String, Object> intermediateOutputContentMap = new HashMap<String, Object>();
intermediateOutputContentMap.put("key2", "value2");
intermediateOutputContentMap.put("key4", "value4");
taskService.addContent(taskId, intermediateOutputContentMap);
Map<String, Object> finalOutputContentMap = new HashMap<String, Object>();
finalOutputContentMap.put("key5", "value5");
finalOutputContentMap.put("key6", "value6");
taskService.complete(taskId, "Bobba Fet", finalOutputContentMap);
task1 = taskService.getTaskById(taskId);
assertEquals(Status.Completed, task1.getTaskData().getStatus());
long outputContentId = task1.getTaskData().getOutputContentId();
Content contentById = taskService.getContentById(outputContentId);
unmarshalledObject = ContentMarshallerHelper.unmarshall(contentById.getContent(), null);
assertNotNull(unmarshalledObject);
if (!(unmarshalledObject instanceof Map)) {
fail("The variables should be a Map");
}
assertTrue(((Map<String, Object>) unmarshalledObject).containsKey("key2"));
assertTrue(((Map<String, Object>) unmarshalledObject).containsKey("key4"));
assertTrue(((Map<String, Object>) unmarshalledObject).containsKey("key5"));
assertTrue(((Map<String, Object>) unmarshalledObject).containsKey("key6"));
xmlRoundTripContent(contentById);
}
use of org.kie.api.task.model.Task in project jbpm by kiegroup.
the class LifeCycleBaseTest method testNewTaskWithContent.
@Test
public void testNewTaskWithContent() {
String str = "(with (new Task()) { priority = 55, taskData = (with( new TaskData()) { } ), ";
str += "peopleAssignments = (with ( new PeopleAssignments() ) { potentialOwners = [new User('Bobba Fet') ],businessAdministrators = [ new User('Administrator') ], }),";
str += "name = 'This is my task name' })";
ContentData data = ContentMarshallerHelper.marshal(null, "content", null);
Task task = TaskFactory.evalTask(new StringReader(str));
taskService.addTask(task, data);
long taskId = task.getId();
// Task should be assigned to the single potential owner and state set to Reserved
Task task1 = taskService.getTaskById(taskId);
assertEquals(AccessType.Inline, ((InternalTaskData) task1.getTaskData()).getDocumentAccessType());
assertEquals("java.lang.String", task1.getTaskData().getDocumentType());
long contentId = task1.getTaskData().getDocumentContentId();
assertTrue(contentId != -1);
Content content = taskService.getContentById(contentId);
Object unmarshalledObject = ContentMarshallerHelper.unmarshall(content.getContent(), null);
assertEquals("content", unmarshalledObject.toString());
xmlRoundTripContent(content);
}
use of org.kie.api.task.model.Task in project jbpm by kiegroup.
the class LifeCycleBaseTest method testReleaseFromReserved.
public void testReleaseFromReserved() {
// One potential owner, should go straight to state Reserved
String str = "(with (new Task()) { priority = 55, taskData = (with( new TaskData()) { } ), ";
str += "peopleAssignments = (with ( new PeopleAssignments() ) { potentialOwners = [new User('Bobba Fet'), new User('Darth Vader') ],businessAdministrators = [ new User('Administrator') ], }),";
str += "name = 'This is my task name'})";
Task task = TaskFactory.evalTask(new StringReader(str));
taskService.addTask(task, new HashMap<String, Object>());
long taskId = task.getId();
// Go straight from Ready to Inprogress
taskService.claim(taskId, "Darth Vader");
Task task1 = taskService.getTaskById(taskId);
assertEquals(Status.Reserved, task1.getTaskData().getStatus());
assertEquals("Darth Vader", task1.getTaskData().getActualOwner().getId());
// Check is Released
taskService.release(taskId, "Darth Vader");
Task task2 = taskService.getTaskById(taskId);
assertEquals(Status.Ready, task2.getTaskData().getStatus());
assertNull(task2.getTaskData().getActualOwner());
}
use of org.kie.api.task.model.Task in project jbpm by kiegroup.
the class LifeCycleBaseTest method testDelegateFromReservedWithIncorrectUser.
@Test
public void testDelegateFromReservedWithIncorrectUser() throws Exception {
// One potential owner, should go straight to state Reserved
String str = "(with (new Task()) { priority = 55, taskData = (with( new TaskData()) { } ), ";
str += "peopleAssignments = (with ( new PeopleAssignments() ) { potentialOwners = [new User('Bobba Fet'), new User('Darth Vader') ],businessAdministrators = [ new User('Administrator') ], }),";
str += "name = 'This is my task name' })";
Task task = TaskFactory.evalTask(new StringReader(str));
taskService.addTask(task, new HashMap<String, Object>());
long taskId = task.getId();
// Claim and Reserved
taskService.claim(taskId, "Darth Vader");
Task task1 = taskService.getTaskById(taskId);
assertEquals(Status.Reserved, task1.getTaskData().getStatus());
assertEquals("Darth Vader", task1.getTaskData().getActualOwner().getId());
// Check was not delegated
PermissionDeniedException denied = null;
try {
taskService.delegate(taskId, "Bobba Fet", "Tony Stark");
} catch (PermissionDeniedException e) {
denied = e;
}
assertNotNull("Should get permissed denied exception", denied);
Task task2 = taskService.getTaskById(taskId);
User user = createUser("Darth Vader");
assertTrue(task2.getPeopleAssignments().getPotentialOwners().contains(user));
user = createUser("Tony Stark");
assertFalse(task2.getPeopleAssignments().getPotentialOwners().contains(user));
assertEquals("Darth Vader", task2.getTaskData().getActualOwner().getId());
assertEquals(Status.Reserved, task2.getTaskData().getStatus());
}
Aggregations