use of org.kie.internal.task.api.model.ContentData in project jbpm by kiegroup.
the class LifeCycleBaseTest method testNewTaskWithMapContent.
@Test
public void testNewTaskWithMapContent() {
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 content = taskService.getContentById(contentId);
Object unmarshalledObject = ContentMarshallerHelper.unmarshall(content.getContent(), null);
if (!(unmarshalledObject instanceof Map)) {
fail("The variables should be a Map");
}
Map<String, Object> unmarshalledvars = (Map<String, Object>) unmarshalledObject;
JaxbContent jaxbContent = xmlRoundTripContent(content);
assertNotNull("Jaxb Content map not filled", jaxbContent.getContentMap());
assertEquals("value1", unmarshalledvars.get("key1"));
assertNull(unmarshalledvars.get("key2"));
assertEquals("value3", unmarshalledvars.get("key3"));
}
use of org.kie.internal.task.api.model.ContentData in project jbpm by kiegroup.
the class LifeCycleBaseTest method testNewTaskWithLargeContent.
@Test
public void testNewTaskWithLargeContent() {
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' })";
String largeContent = "";
for (int i = 0; i < 1000; i++) {
largeContent += i + "xxxxxxxxx";
}
ContentData data = ContentMarshallerHelper.marshal(null, largeContent, 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(largeContent, unmarshalledObject.toString());
xmlRoundTripContent(content);
}
use of org.kie.internal.task.api.model.ContentData in project jbpm by kiegroup.
the class LifeCycleLocalWithRuleServiceTest method testCreateTaskWithDisallowedCreationBasedOnContentByRuleWithContentData.
@Test
public void testCreateTaskWithDisallowedCreationBasedOnContentByRuleWithContentData() {
// One potential owner, should go straight to state Reserved
String str = "(with (new Task()) { priority = 55, taskData = (with( new TaskData()) { workItemId = 1 } ), ";
str += "peopleAssignments = (with ( new PeopleAssignments() ) { potentialOwners = [new User('john')],businessAdministrators = [ new User('Administrator') ], }),";
str += "descriptions = [ new I18NText( 'en-UK', 'This is my description')], ";
str += "subjects = [ new I18NText( 'en-UK', 'This is my subject')], ";
str += "names = [ new I18NText( 'en-UK', 'This is my task name')] })";
Task task = (Task) TaskFactory.evalTask(new StringReader(str));
Map<String, Object> params = new HashMap<String, Object>();
params.put("manager", "John");
ContentData data = ContentMarshallerHelper.marshal(task, params, null);
try {
taskService.addTask(task, data);
fail("Task should not be created due to rule violation");
} catch (CannotAddTaskException e) {
assertTrue(e.getMessage().indexOf("John (manager) does not work here any more") != -1);
}
}
use of org.kie.internal.task.api.model.ContentData in project jbpm by kiegroup.
the class TaskInstanceServiceImpl method setOutput.
public void setOutput(long taskId, String userId, Object outputContentData) {
Task task = persistenceContext.findTask(taskId);
ContentData contentData = ContentMarshallerHelper.marshal(task, outputContentData, environment);
Content content = TaskModelProvider.getFactory().newContent();
((InternalContent) content).setContent(contentData.getContent());
persistenceContext.persistContent(content);
persistenceContext.setOutputToTask(content, contentData, task);
}
use of org.kie.internal.task.api.model.ContentData in project jbpm by kiegroup.
the class TaskInstanceServiceImpl method deleteOutput.
public void deleteOutput(long taskId, String userId) {
Task task = persistenceContext.findTask(taskId);
long contentId = task.getTaskData().getOutputContentId();
Content content = persistenceContext.findContent(contentId);
Map<String, Object> initialContent = new HashMap<>();
ContentMarshallerContext context = TaskContentRegistry.get().getMarshallerContext(task);
Object unmarshalledObject = ContentMarshallerHelper.unmarshall(content.getContent(), context.getEnvironment(), context.getClassloader());
if (unmarshalledObject != null && unmarshalledObject instanceof Map) {
// set initial content before updating with this params
initialContent.putAll((Map<String, Object>) unmarshalledObject);
}
taskEventSupport.fireBeforeTaskOutputVariablesChanged(task, this.context, initialContent);
ContentData data = TaskModelProvider.getFactory().newContentData();
persistenceContext.removeContent(content);
persistenceContext.setOutputToTask(null, data, task);
taskEventSupport.fireAfterTaskOutputVariablesChanged(task, this.context, null);
}
Aggregations