use of org.kie.api.task.model.I18NText in project jbpm by kiegroup.
the class UserTaskServiceImpl method setDescription.
@Override
public void setDescription(String deploymentId, Long taskId, String description) {
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;
}
RuntimeEngine engine = manager.getRuntimeEngine(ProcessInstanceIdContext.get(task.getProcessInstanceId()));
try {
InternalI18NText text = (InternalI18NText) TaskModelProvider.getFactory().newI18NText();
text.setLanguage("en-UK");
text.setText(description);
List<I18NText> names = new ArrayList<I18NText>();
names.add(text);
TaskService taskService = engine.getTaskService();
// perform actual operation
((InternalTaskService) taskService).setDescriptions(taskId, names);
} finally {
disposeRuntimeEngine(manager, engine);
}
}
use of org.kie.api.task.model.I18NText 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");
}
use of org.kie.api.task.model.I18NText in project jbpm by kiegroup.
the class JaxbTaskSerializationTest method setTaskPropertyCommandTest.
@Test
public void setTaskPropertyCommandTest() throws Exception {
SetTaskPropertyCommand cmd;
int taskId = 1;
String userId = "user";
FaultDataImpl faultData = new FaultDataImpl();
faultData.setAccessType(AccessType.Inline);
faultData.setContent("skinned shins".getBytes());
faultData.setFaultName("Whoops!");
faultData.setType("skates");
List<I18NText> textList = new ArrayList<I18NText>();
I18NText text = new I18NTextImpl("nl-NL", "Stroopwafel!");
textList.add(text);
Object[][] testData = { { FAULT_PROPERTY, faultData }, { OUTPUT_PROPERTY, new Object() }, { PRIORITY_PROPERTY, 23 }, { TASK_NAMES_PROPERTY, textList }, { EXPIRATION_DATE_PROPERTY, new Date() }, { DESCRIPTION_PROPERTY, new ArrayList<I18NText>() }, { SKIPPABLE_PROPERTY, false }, { SUB_TASK_STRATEGY_PROPERTY, SubTasksStrategy.EndParentOnAllSubTasksEnd } };
TaskContext mockContext = mock(TaskContext.class);
TaskInstanceService mockTaskService = mock(TaskInstanceService.class);
UserGroupCallback mockUserGroupCallback = mock(UserGroupCallback.class);
when(mockContext.getTaskInstanceService()).thenReturn(mockTaskService);
when(mockContext.getUserGroupCallback()).thenReturn(mockUserGroupCallback);
when(mockUserGroupCallback.existsUser(anyString())).thenReturn(false);
for (Object[] data : testData) {
int property = (Integer) data[0];
cmd = new SetTaskPropertyCommand(taskId, userId, property, data[1]);
try {
cmd.execute(mockContext);
} catch (IllegalArgumentException e) {
// expected for fault and output
assertTrue(e.getMessage().startsWith("User user was not found in callback "));
}
}
}
use of org.kie.api.task.model.I18NText in project jbpm by kiegroup.
the class CollectionUtils method readI18NTextList.
public static List<I18NText> readI18NTextList(ObjectInput in) throws IOException, ClassNotFoundException {
int size = in.readInt();
List<I18NText> list = new ArrayList<I18NText>(size);
for (int i = 0; i < size; i++) {
I18NText item = new I18NTextImpl();
item.readExternal(in);
list.add(item);
}
return list;
}
Aggregations