use of org.kie.internal.task.api.model.InternalI18NText in project jbpm by kiegroup.
the class HumanTaskHandlerHelper method parseNotifications.
protected static List<Notification> parseNotifications(String notificationString, List<OrganizationalEntity> businessAdministrators) {
List<Notification> notifications = new ArrayList<Notification>();
Map<String, String> parameters = asMap(notificationString);
if (parameters.containsKey("tousers") || parameters.containsKey("togroups")) {
String locale = parameters.get("locale");
if (locale == null) {
locale = "en-UK";
}
EmailNotification emailNotification = TaskModelProvider.getFactory().newEmialNotification();
notifications.add(emailNotification);
emailNotification.setBusinessAdministrators(businessAdministrators);
Map<Language, EmailNotificationHeader> emailHeaders = new HashMap<Language, EmailNotificationHeader>();
List<I18NText> subjects = new ArrayList<I18NText>();
List<I18NText> names = new ArrayList<I18NText>();
List<OrganizationalEntity> notificationRecipients = new ArrayList<OrganizationalEntity>();
EmailNotificationHeader emailHeader = TaskModelProvider.getFactory().newEmailNotificationHeader();
emailHeader.setBody(parameters.get("body"));
emailHeader.setFrom(parameters.get("from"));
emailHeader.setReplyTo(parameters.get("replyto"));
emailHeader.setLanguage(locale);
emailHeader.setSubject(parameters.get("subject"));
Language lang = TaskModelProvider.getFactory().newLanguage();
lang.setMapkey(locale);
emailHeaders.put(lang, emailHeader);
I18NText subject = TaskModelProvider.getFactory().newI18NText();
((InternalI18NText) subject).setLanguage(locale);
((InternalI18NText) subject).setText(emailHeader.getSubject());
;
subjects.add(subject);
names.add(subject);
String recipients = parameters.get("tousers");
if (recipients != null && recipients.trim().length() > 0) {
String[] recipientsIds = recipients.split(ATTRIBUTES_ELEMENTS_SEPARATOR);
for (String id : recipientsIds) {
User user = TaskModelProvider.getFactory().newUser();
((InternalOrganizationalEntity) user).setId(id.trim());
notificationRecipients.add(user);
}
}
String groupRecipients = parameters.get("togroups");
if (groupRecipients != null && groupRecipients.trim().length() > 0) {
String[] groupRecipientsIds = groupRecipients.split(ATTRIBUTES_ELEMENTS_SEPARATOR);
for (String id : groupRecipientsIds) {
Group group = TaskModelProvider.getFactory().newGroup();
((InternalOrganizationalEntity) group).setId(id.trim());
notificationRecipients.add(group);
}
}
emailNotification.setEmailHeaders(emailHeaders);
emailNotification.setNames(names);
emailNotification.setRecipients(notificationRecipients);
emailNotification.setSubjects(subjects);
}
return notifications;
}
use of org.kie.internal.task.api.model.InternalI18NText 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.internal.task.api.model.InternalI18NText 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