use of org.kie.api.task.model.Content in project jbpm by kiegroup.
the class UserTaskServiceImpl method getTaskOutputContentByTaskId.
@SuppressWarnings("unchecked")
@Override
public Map<String, Object> getTaskOutputContentByTaskId(String deploymentId, Long taskId) {
UserTaskInstanceDesc task = dataService.getTaskById(taskId);
validateTask(deploymentId, taskId, task);
RuntimeManager manager = getRuntimeManager(task);
if (manager == null) {
logger.warn("Cannot find runtime manager for task {}", taskId);
return null;
}
RuntimeEngine engine = manager.getRuntimeEngine(ProcessInstanceIdContext.get(task.getProcessInstanceId()));
try {
TaskService taskService = engine.getTaskService();
// perform actual operation
Task taskInstanceById = taskService.getTaskById(taskId);
long documentContentId = taskInstanceById.getTaskData().getOutputContentId();
if (documentContentId > 0) {
Content contentById = taskService.getContentById(documentContentId);
if (contentById == null) {
return new HashMap<String, Object>();
}
ContentMarshallerContext ctx = TaskContentRegistry.get().getMarshallerContext(task.getDeploymentId());
Object unmarshall = ContentMarshallerHelper.unmarshall(contentById.getContent(), ctx.getEnvironment(), ctx.getClassloader());
Map<String, Object> data = (Map<String, Object>) unmarshall;
for (Object variable : data.values()) {
if (variable instanceof LazyLoaded<?>) {
((LazyLoaded<?>) variable).load();
}
}
return data;
}
return new HashMap<String, Object>();
} finally {
disposeRuntimeEngine(manager, engine);
}
}
use of org.kie.api.task.model.Content in project jbpm by kiegroup.
the class LifeCycleBaseTest method testCompleteWithResults.
@Test
public void testCompleteWithResults() {
// 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.start(taskId, "Darth Vader");
Task task1 = taskService.getTaskById(taskId);
assertEquals(Status.InProgress, task1.getTaskData().getStatus());
assertEquals("Darth Vader", task1.getTaskData().getActualOwner().getId());
Map<String, Object> params = new HashMap<String, Object>();
params.put("content", "content");
taskService.complete(taskId, "Darth Vader", params);
Task task2 = taskService.getTaskById(taskId);
assertEquals(AccessType.Inline, ((InternalTaskData) task2.getTaskData()).getOutputAccessType());
assertEquals("java.util.HashMap", task2.getTaskData().getOutputType());
long contentId = task2.getTaskData().getOutputContentId();
assertTrue(contentId != -1);
Content content = taskService.getContentById(contentId);
Map<String, Object> unmarshalledObject = (Map<String, Object>) ContentMarshallerHelper.unmarshall(content.getContent(), null);
assertEquals("content", unmarshalledObject.get("content"));
}
use of org.kie.api.task.model.Content in project jbpm by kiegroup.
the class LifeCycleBaseTest method testFailWithContent.
@Test
public void testFailWithContent() {
// 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.start(taskId, "Darth Vader");
taskService.getTaskById(taskId);
Task task1 = taskService.getTaskById(taskId);
assertEquals(Status.InProgress, task1.getTaskData().getStatus());
assertEquals("Darth Vader", task1.getTaskData().getActualOwner().getId());
Map<String, Object> faultData = new HashMap<String, Object>();
faultData.put("faultType", "type");
faultData.put("faultName", "faultName");
faultData.put("content", "content");
taskService.fail(taskId, "Darth Vader", faultData);
List<Content> allContent = taskService.getAllContentByTaskId(taskId);
assertNotNull(allContent);
assertEquals(3, allContent.size());
// only input(0) and fault(2) is present
assertNotNull(allContent.get(0));
assertNull(allContent.get(1));
assertNotNull(allContent.get(2));
Task task2 = taskService.getTaskById(taskId);
assertEquals(Status.Failed, task2.getTaskData().getStatus());
assertEquals(AccessType.Inline, ((InternalTaskData) task2.getTaskData()).getFaultAccessType());
assertEquals("type", task2.getTaskData().getFaultType());
assertEquals("faultName", task2.getTaskData().getFaultName());
long contentId = task2.getTaskData().getFaultContentId();
assertTrue(contentId != -1);
Content content = taskService.getContentById(contentId);
Map<String, Object> unmarshalledContent = (Map<String, Object>) ContentMarshallerHelper.unmarshall(content.getContent(), null);
assertEquals("content", unmarshalledContent.get("content"));
xmlRoundTripContent(content);
// update fault
FaultData data = TaskModelProvider.getFactory().newFaultData();
data.setAccessType(AccessType.Inline);
data.setType("type");
data.setFaultName("faultName");
data.setContent("updated content".getBytes());
taskService.setFault(taskId, "Darth Vader", data);
task = taskService.getTaskById(taskId);
contentId = task.getTaskData().getFaultContentId();
content = taskService.getContentById(contentId);
String updated = new String(content.getContent());
assertEquals("updated content", updated);
// delete fault
taskService.deleteFault(taskId, "Darth Vader");
content = taskService.getContentById(contentId);
assertNull(content);
}
use of org.kie.api.task.model.Content 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.Content 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);
}
Aggregations