Search in sources :

Example 16 with InternalI18NText

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;
}
Also used : Group(org.kie.api.task.model.Group) I18NText(org.kie.api.task.model.I18NText) InternalI18NText(org.kie.internal.task.api.model.InternalI18NText) User(org.kie.api.task.model.User) EmailNotificationHeader(org.kie.internal.task.api.model.EmailNotificationHeader) OrganizationalEntity(org.kie.api.task.model.OrganizationalEntity) InternalOrganizationalEntity(org.kie.internal.task.api.model.InternalOrganizationalEntity) HashMap(java.util.HashMap) InternalI18NText(org.kie.internal.task.api.model.InternalI18NText) ArrayList(java.util.ArrayList) EmailNotification(org.kie.internal.task.api.model.EmailNotification) InternalOrganizationalEntity(org.kie.internal.task.api.model.InternalOrganizationalEntity) Notification(org.kie.internal.task.api.model.Notification) EmailNotification(org.kie.internal.task.api.model.EmailNotification) Language(org.kie.internal.task.api.model.Language)

Example 17 with InternalI18NText

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);
    }
}
Also used : RuntimeEngine(org.kie.api.runtime.manager.RuntimeEngine) I18NText(org.kie.api.task.model.I18NText) InternalI18NText(org.kie.internal.task.api.model.InternalI18NText) InternalI18NText(org.kie.internal.task.api.model.InternalI18NText) InternalTaskService(org.kie.internal.task.api.InternalTaskService) UserTaskService(org.jbpm.services.api.UserTaskService) TaskService(org.kie.api.task.TaskService) RuntimeManager(org.kie.api.runtime.manager.RuntimeManager) InternalRuntimeManager(org.kie.internal.runtime.manager.InternalRuntimeManager) ArrayList(java.util.ArrayList) InternalTaskService(org.kie.internal.task.api.InternalTaskService) UserTaskInstanceDesc(org.jbpm.services.api.model.UserTaskInstanceDesc)

Example 18 with InternalI18NText

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");
}
Also used : I18NText(org.kie.api.task.model.I18NText) JaxbI18NText(org.jbpm.services.task.impl.model.xml.JaxbI18NText) InternalI18NText(org.kie.internal.task.api.model.InternalI18NText) Task(org.kie.api.task.model.Task) InternalTask(org.kie.internal.task.api.model.InternalTask) JaxbTask(org.jbpm.services.task.impl.model.xml.JaxbTask) User(org.kie.api.task.model.User) JaxbTask(org.jbpm.services.task.impl.model.xml.JaxbTask) InputStreamReader(java.io.InputStreamReader) HashMap(java.util.HashMap) InternalTask(org.kie.internal.task.api.model.InternalTask) InternalI18NText(org.kie.internal.task.api.model.InternalI18NText) InternalAttachment(org.kie.internal.task.api.model.InternalAttachment) InputStream(java.io.InputStream) InternalComment(org.kie.internal.task.api.model.InternalComment) InternalTaskData(org.kie.internal.task.api.model.InternalTaskData) Reader(java.io.Reader) InputStreamReader(java.io.InputStreamReader) InternalOrganizationalEntity(org.kie.internal.task.api.model.InternalOrganizationalEntity) Date(java.util.Date) Test(org.junit.Test)

Aggregations

I18NText (org.kie.api.task.model.I18NText)18 InternalI18NText (org.kie.internal.task.api.model.InternalI18NText)18 ArrayList (java.util.ArrayList)17 InternalTask (org.kie.internal.task.api.model.InternalTask)8 Task (org.kie.api.task.model.Task)6 Test (org.junit.Test)4 RuntimeEngine (org.kie.api.runtime.manager.RuntimeEngine)4 OrganizationalEntity (org.kie.api.task.model.OrganizationalEntity)4 User (org.kie.api.task.model.User)4 InternalTaskService (org.kie.internal.task.api.InternalTaskService)4 InternalOrganizationalEntity (org.kie.internal.task.api.model.InternalOrganizationalEntity)4 InternalTaskData (org.kie.internal.task.api.model.InternalTaskData)4 StringReader (java.io.StringReader)3 HashMap (java.util.HashMap)3 Date (java.util.Date)2 UserTaskService (org.jbpm.services.api.UserTaskService)2 UserTaskInstanceDesc (org.jbpm.services.api.model.UserTaskInstanceDesc)2 RuntimeManager (org.kie.api.runtime.manager.RuntimeManager)2 TaskService (org.kie.api.task.TaskService)2 TaskSummary (org.kie.api.task.model.TaskSummary)2