use of org.jbpm.services.task.impl.model.xml.JaxbTask in project jbpm by kiegroup.
the class AddTaskCommand method execute.
public Long execute(Context cntxt) {
Long taskId = null;
TaskContext context = (TaskContext) cntxt;
if (task == null) {
task = jaxbTask;
}
Task taskImpl = null;
if (task instanceof JaxbTask) {
taskImpl = ((JaxbTask) task).getTask();
} else {
taskImpl = task;
}
initializeTask(taskImpl);
context.getTaskRuleService().executeRules(taskImpl, userId, data != null ? data : params, TaskRuleService.ADD_TASK_SCOPE);
// use assignment service to directly assign actual owner if enabled
AssignmentService assignmentService = AssignmentServiceProvider.get();
if (assignmentService.isEnabled()) {
assignmentService.assignTask(taskImpl, context);
}
doCallbackOperationForPeopleAssignments((InternalPeopleAssignments) taskImpl.getPeopleAssignments(), context);
doCallbackOperationForTaskData((InternalTaskData) taskImpl.getTaskData(), context);
doCallbackOperationForTaskDeadlines(((InternalTask) taskImpl).getDeadlines(), context);
if (data != null) {
taskId = context.getTaskInstanceService().addTask(taskImpl, data);
} else {
((InternalTaskData) taskImpl.getTaskData()).setTaskInputVariables(params);
taskId = context.getTaskInstanceService().addTask(taskImpl, params);
}
scheduleDeadlinesForTask((InternalTask) taskImpl, context.getTaskDeadlinesService());
return taskId;
}
use of org.jbpm.services.task.impl.model.xml.JaxbTask 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");
}
Aggregations