use of org.kie.internal.task.api.model.ContentData 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.internal.task.api.model.ContentData 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.internal.task.api.model.ContentData in project jbpm by kiegroup.
the class ContentMarshallerHelper method marshal.
public static ContentData marshal(Task task, Object o, Environment env) {
if (o == null) {
return null;
}
ContentData content = null;
byte[] toByteArray = marshallContent(task, o, env);
content = TaskModelProvider.getFactory().newContentData();
content.setContent(toByteArray);
content.setType(o.getClass().getCanonicalName());
content.setAccessType(AccessType.Inline);
return content;
}
use of org.kie.internal.task.api.model.ContentData in project jbpm by kiegroup.
the class DeadlinesBaseTest method testDelayedEmailNotificationOnDeadlineTaskCompleted.
@Test(timeout = 10000)
public void testDelayedEmailNotificationOnDeadlineTaskCompleted() throws Exception {
CountDownTaskEventListener countDownListener = new CountDownTaskEventListener(1, false, true);
addCountDownListner(countDownListener);
Map<String, Object> vars = new HashMap<String, Object>();
vars.put("now", new Date());
Reader reader = new InputStreamReader(getClass().getResourceAsStream(MvelFilePath.DeadlineWithNotification));
InternalTask task = (InternalTask) TaskFactory.evalTask(reader, vars);
((InternalTaskData) task.getTaskData()).setSkipable(true);
InternalPeopleAssignments assignments = (InternalPeopleAssignments) TaskModelProvider.getFactory().newPeopleAssignments();
List<OrganizationalEntity> ba = new ArrayList<OrganizationalEntity>();
User user = TaskModelProvider.getFactory().newUser();
((InternalOrganizationalEntity) user).setId("Administrator");
ba.add(user);
assignments.setBusinessAdministrators(ba);
List<OrganizationalEntity> po = new ArrayList<OrganizationalEntity>();
User user2 = TaskModelProvider.getFactory().newUser();
((InternalOrganizationalEntity) user2).setId("Administrator");
po.add(user2);
assignments.setPotentialOwners(po);
task.setPeopleAssignments(assignments);
taskService.addTask(task, new HashMap<String, Object>());
long taskId = task.getId();
InternalContent content = (InternalContent) TaskModelProvider.getFactory().newContent();
Map<String, String> params = fillMarshalSubjectAndBodyParams();
ContentData marshalledObject = ContentMarshallerHelper.marshal(task, params, null);
content.setContent(marshalledObject.getContent());
taskService.addContent(taskId, content);
long contentId = content.getId();
content = (InternalContent) taskService.getContentById(contentId);
Object unmarshallObject = ContentMarshallerHelper.unmarshall(content.getContent(), null);
checkContentSubjectAndBody(unmarshallObject);
taskService.start(taskId, "Administrator");
taskService.complete(taskId, "Administrator", null);
// emails should not be set yet
assertThat(((MockNotificationListener) notificationListener).getEventsRecieved().size()).isEqualTo(0);
countDownListener.waitTillCompleted();
// no email should ne sent as task was completed before deadline was triggered
assertThat(((MockNotificationListener) notificationListener).getEventsRecieved().size()).isEqualTo(0);
task = (InternalTask) taskService.getTaskById(taskId);
assertThat(task.getTaskData().getStatus()).isEqualTo(Status.Completed);
assertThat(((InternalTask) task).getDeadlines().getStartDeadlines().size()).isEqualTo(0);
assertThat(((InternalTask) task).getDeadlines().getEndDeadlines().size()).isEqualTo(0);
}
use of org.kie.internal.task.api.model.ContentData in project jbpm by kiegroup.
the class DeadlinesBaseTest method testDelayedEmailNotificationOnDeadline.
@Test(timeout = 10000)
public void testDelayedEmailNotificationOnDeadline() throws Exception {
CountDownTaskEventListener countDownListener = new CountDownTaskEventListener(1, false, true);
addCountDownListner(countDownListener);
Map<String, Object> vars = new HashMap<String, Object>();
vars.put("now", new Date());
Reader reader = new InputStreamReader(getClass().getResourceAsStream(MvelFilePath.DeadlineWithNotification));
Task task = (Task) TaskFactory.evalTask(reader, vars);
taskService.addTask(task, new HashMap<String, Object>());
long taskId = task.getId();
InternalContent content = (InternalContent) TaskModelProvider.getFactory().newContent();
Map<String, String> params = fillMarshalSubjectAndBodyParams();
ContentData marshalledObject = ContentMarshallerHelper.marshal(task, params, null);
content.setContent(marshalledObject.getContent());
taskService.addContent(taskId, content);
long contentId = content.getId();
content = (InternalContent) taskService.getContentById(contentId);
Object unmarshallObject = ContentMarshallerHelper.unmarshall(content.getContent(), null);
checkContentSubjectAndBody(unmarshallObject);
// emails should not be set yet
assertThat(((MockNotificationListener) notificationListener).getEventsRecieved().size()).isEqualTo(0);
countDownListener.waitTillCompleted();
// 1 email with two recipients should now exist
assertThat(((MockNotificationListener) notificationListener).getEventsRecieved().size()).isEqualTo(1);
}
Aggregations