Search in sources :

Example 16 with I18NText

use of org.kie.api.task.model.I18NText in project jbpm by kiegroup.

the class TaskInstanceServiceImpl method setDescriptions.

public void setDescriptions(long taskId, List<I18NText> inputDescriptions) {
    Task task = persistenceContext.findTask(taskId);
    taskEventSupport.fireBeforeTaskUpdated(task, context);
    List<I18NText> descriptions = new ArrayList<I18NText>(inputDescriptions.size());
    for (I18NText inputText : inputDescriptions) {
        I18NText text = TaskModelProvider.getFactory().newI18NText();
        ((InternalI18NText) text).setLanguage(inputText.getLanguage());
        ((InternalI18NText) text).setText(inputText.getText());
        descriptions.add(text);
    }
    ((InternalTask) task).setDescriptions(descriptions);
    ((InternalTask) task).setDescription(descriptions.get(0).getText());
    taskEventSupport.fireAfterTaskUpdated(task, context);
}
Also used : Task(org.kie.api.task.model.Task) InternalTask(org.kie.internal.task.api.model.InternalTask) I18NText(org.kie.api.task.model.I18NText) InternalI18NText(org.kie.internal.task.api.model.InternalI18NText) InternalI18NText(org.kie.internal.task.api.model.InternalI18NText) InternalTask(org.kie.internal.task.api.model.InternalTask) ArrayList(java.util.ArrayList)

Example 17 with I18NText

use of org.kie.api.task.model.I18NText in project jbpm by kiegroup.

the class TaskQueryServiceBaseTest method testModifyTaskNameWithinTX.

@Test
public void testModifyTaskNameWithinTX() throws Exception {
    // JBPM-4148
    String taskName = "This is my task name";
    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 = '" + taskName + "' })";
    Task task = TaskFactory.evalTask(new StringReader(str));
    List<I18NText> names = new ArrayList<I18NText>();
    I18NText text = TaskModelProvider.getFactory().newI18NText();
    ((InternalI18NText) text).setLanguage("en-UK");
    ((InternalI18NText) text).setText(taskName);
    names.add(text);
    ((InternalTask) task).setNames(names);
    taskService.addTask(task, new HashMap<String, Object>());
    List<TaskSummary> tasks = taskService.getTasksAssignedAsPotentialOwner("Bobba Fet", "en-UK");
    assertEquals(1, tasks.size());
    assertEquals(taskName, tasks.get(0).getName());
    UserTransaction ut = InitialContext.doLookup("java:comp/UserTransaction");
    ut.begin();
    Task newTask = taskService.getTaskById(tasks.get(0).getId());
    ((InternalI18NText) newTask.getNames().get(0)).setText("New task name");
    ut.commit();
    List<TaskSummary> newTasks = taskService.getTasksAssignedAsPotentialOwner("Bobba Fet", "en-UK");
    assertEquals(1, newTasks.size());
    newTask = taskService.getTaskById(newTasks.get(0).getId());
    assertEquals("New task name", newTask.getNames().get(0).getText());
}
Also used : UserTransaction(javax.transaction.UserTransaction) Task(org.kie.api.task.model.Task) InternalTask(org.kie.internal.task.api.model.InternalTask) I18NText(org.kie.api.task.model.I18NText) InternalI18NText(org.kie.internal.task.api.model.InternalI18NText) InternalI18NText(org.kie.internal.task.api.model.InternalI18NText) InternalTask(org.kie.internal.task.api.model.InternalTask) ArrayList(java.util.ArrayList) StringReader(java.io.StringReader) TaskSummary(org.kie.api.task.model.TaskSummary) Test(org.junit.Test)

Example 18 with I18NText

use of org.kie.api.task.model.I18NText in project jbpm by kiegroup.

the class JaxbTask method getTask.

/**
 * This is a convienence method that retrieves a TaskImpl instance. It's used
 * internally in the {@link AddTaskCommand#execute(org.kie.internal.command.Context)} method
 * because that command requires a persistable task representation.
 * </p>
 * Users who are looking for information from the task should <i>not</i> use this method:
 * all of the task information is already available via the normal methods
 * defined by the {@link Task} or {@link InternalTask} interfaces, both of which this class
 * implements: for example: {@link JaxbTask#getId()}, {@link JaxbTask#getTaskData()}
 * or {@link JaxbTask#getPeopleAssignments()}.
 * @return a TaskImpl instance
 */
public Task getTask() {
    InternalTask taskImpl = (InternalTask) TaskModelProvider.getFactory().newTask();
    if (this.getId() != null) {
        taskImpl.setId(this.getId());
    }
    if (this.priority != null) {
        taskImpl.setPriority(this.getPriority());
    }
    JaxbPeopleAssignments jaxbPeopleAssignments = this.peopleAssignments;
    InternalPeopleAssignments peopleAssignments = (InternalPeopleAssignments) TaskModelProvider.getFactory().newPeopleAssignments();
    if (jaxbPeopleAssignments.getTaskInitiator() != null) {
        User user = createUser(this.getPeopleAssignments().getTaskInitiator().getId());
        peopleAssignments.setTaskInitiator(user);
    }
    List<OrganizationalEntity> potentialOwners = copyOrganizationalEntityList(jaxbPeopleAssignments.getPotentialOwners());
    peopleAssignments.setPotentialOwners(potentialOwners);
    List<OrganizationalEntity> businessAdmins = copyOrganizationalEntityList(jaxbPeopleAssignments.getBusinessAdministrators());
    peopleAssignments.setBusinessAdministrators(businessAdmins);
    List<OrganizationalEntity> exclOwners = copyOrganizationalEntityList(jaxbPeopleAssignments.getExcludedOwners());
    peopleAssignments.setExcludedOwners(exclOwners);
    List<OrganizationalEntity> taskStake = copyOrganizationalEntityList(jaxbPeopleAssignments.getTaskStakeholders());
    peopleAssignments.setTaskStakeholders(taskStake);
    List<OrganizationalEntity> recipients = copyOrganizationalEntityList(jaxbPeopleAssignments.getRecipients());
    peopleAssignments.setRecipients(recipients);
    taskImpl.setPeopleAssignments(peopleAssignments);
    taskImpl.setSubTaskStrategy(this.getSubTaskStrategy());
    {
        List<I18NText> names = new ArrayList<I18NText>();
        for (I18NText n : this.getNames()) {
            I18NText text = TaskModelProvider.getFactory().newI18NText();
            ((InternalI18NText) text).setId(n.getId());
            ((InternalI18NText) text).setLanguage(n.getLanguage());
            ((InternalI18NText) text).setText(n.getText());
            names.add(text);
        }
        taskImpl.setNames(names);
    }
    if (this.getName() != null) {
        taskImpl.setName(this.getName());
    } else if (!this.getNames().isEmpty()) {
        taskImpl.setName(this.getNames().get(0).getText());
    }
    {
        List<I18NText> subjects = new ArrayList<I18NText>();
        for (I18NText s : this.getSubjects()) {
            I18NText text = TaskModelProvider.getFactory().newI18NText();
            ((InternalI18NText) text).setId(s.getId());
            ((InternalI18NText) text).setLanguage(s.getLanguage());
            ((InternalI18NText) text).setText(s.getText());
            subjects.add(text);
        }
        taskImpl.setSubjects(subjects);
    }
    if (this.getSubject() != null) {
        taskImpl.setSubject(this.getSubject());
    } else if (!this.getSubjects().isEmpty()) {
        taskImpl.setSubject(this.getSubjects().get(0).getText());
    }
    {
        List<I18NText> descriptions = new ArrayList<I18NText>();
        for (I18NText d : this.getDescriptions()) {
            I18NText text = TaskModelProvider.getFactory().newI18NText();
            ((InternalI18NText) text).setId(d.getId());
            ((InternalI18NText) text).setLanguage(d.getLanguage());
            ((InternalI18NText) text).setText(d.getText());
            descriptions.add(text);
        }
        taskImpl.setDescriptions(descriptions);
    }
    if (this.getDescription() != null) {
        taskImpl.setDescription(this.getDescription());
    } else if (!this.getDescriptions().isEmpty()) {
        taskImpl.setDescription(this.getDescriptions().get(0).getText());
    }
    taskImpl.setTaskType(this.getTaskType());
    taskImpl.setFormName(this.getFormName());
    // task data
    InternalTaskData taskData = (InternalTaskData) TaskModelProvider.getFactory().newTaskData();
    JaxbTaskData jaxbTaskData = (JaxbTaskData) this.getTaskData();
    taskData.setStatus(jaxbTaskData.getStatus());
    taskData.setPreviousStatus(jaxbTaskData.getPreviousStatus());
    taskData.setActualOwner(createUser(jaxbTaskData.getActualOwnerId()));
    taskData.setCreatedBy(createUser(jaxbTaskData.getCreatedById()));
    taskData.setCreatedOn(jaxbTaskData.getCreatedOn());
    taskData.setActivationTime(jaxbTaskData.getActivationTime());
    taskData.setExpirationTime(jaxbTaskData.getExpirationTime());
    taskData.setSkipable(jaxbTaskData.isSkipable());
    taskData.setWorkItemId(jaxbTaskData.getWorkItemId());
    taskData.setProcessInstanceId(jaxbTaskData.getProcessInstanceId());
    taskData.setDocumentContentId(jaxbTaskData.getDocumentContentId());
    taskData.setDocumentAccessType(jaxbTaskData.getDocumentAccessType());
    taskData.setDocumentType(jaxbTaskData.getDocumentType());
    taskData.setOutputAccessType(jaxbTaskData.getOutputAccessType());
    taskData.setOutputType(jaxbTaskData.getOutputType());
    taskData.setOutputContentId(jaxbTaskData.getOutputContentId());
    taskData.setFaultName(jaxbTaskData.getFaultName());
    taskData.setFaultAccessType(jaxbTaskData.getFaultAccessType());
    taskData.setFaultType(jaxbTaskData.getFaultType());
    taskData.setFaultContentId(jaxbTaskData.getFaultContentId());
    taskData.setParentId(jaxbTaskData.getParentId());
    taskData.setProcessId(jaxbTaskData.getProcessId());
    taskData.setProcessSessionId(jaxbTaskData.getProcessSessionId());
    List<Comment> jaxbComments = jaxbTaskData.getComments();
    if (jaxbComments != null) {
        List<Comment> comments = new ArrayList<Comment>(jaxbComments.size());
        for (Comment jaxbComment : jaxbComments) {
            InternalComment comment = (InternalComment) TaskModelProvider.getFactory().newComment();
            if (jaxbComment.getId() != null) {
                comment.setId(jaxbComment.getId());
            }
            comment.setAddedAt(jaxbComment.getAddedAt());
            comment.setAddedBy(createUser(((JaxbComment) jaxbComment).getAddedById()));
            comment.setText(jaxbComment.getText());
            comments.add(comment);
        }
        taskData.setComments(comments);
    }
    List<Attachment> jaxbAttachments = jaxbTaskData.getAttachments();
    if (jaxbAttachments != null) {
        List<Attachment> attachments = new ArrayList<Attachment>(jaxbAttachments.size());
        for (Attachment jaxbAttach : jaxbAttachments) {
            InternalAttachment attach = (InternalAttachment) TaskModelProvider.getFactory().newAttachment();
            if (jaxbAttach.getId() != null) {
                attach.setId(jaxbAttach.getId());
            }
            attach.setName(jaxbAttach.getName());
            attach.setContentType(jaxbAttach.getContentType());
            attach.setAttachedAt(jaxbAttach.getAttachedAt());
            attach.setAttachedBy(createUser(((JaxbAttachment) jaxbAttach).getAttachedById()));
            attach.setSize(jaxbAttach.getSize());
            attach.setAttachmentContentId(jaxbAttach.getAttachmentContentId());
            attachments.add(attach);
        }
        taskData.setAttachments(attachments);
    }
    taskData.setDeploymentId(jaxbTaskData.getDeploymentId());
    ((InternalTask) taskImpl).setTaskData(taskData);
    return taskImpl;
}
Also used : InternalComment(org.kie.internal.task.api.model.InternalComment) Comment(org.kie.api.task.model.Comment) I18NText(org.kie.api.task.model.I18NText) InternalI18NText(org.kie.internal.task.api.model.InternalI18NText) User(org.kie.api.task.model.User) OrganizationalEntity(org.kie.api.task.model.OrganizationalEntity) InternalTask(org.kie.internal.task.api.model.InternalTask) InternalAttachment(org.kie.internal.task.api.model.InternalAttachment) InternalComment(org.kie.internal.task.api.model.InternalComment) InternalTaskData(org.kie.internal.task.api.model.InternalTaskData) ArrayList(java.util.ArrayList) Attachment(org.kie.api.task.model.Attachment) InternalAttachment(org.kie.internal.task.api.model.InternalAttachment) InternalPeopleAssignments(org.kie.internal.task.api.model.InternalPeopleAssignments) ArrayList(java.util.ArrayList) List(java.util.List)

Example 19 with I18NText

use of org.kie.api.task.model.I18NText in project jbpm by kiegroup.

the class AdHocUserTaskServiceImpl method updateTask.

@Override
public void updateTask(long taskId, int priority, String taskDescription, Date dueDate) {
    nonProcessScopedTaskService.setPriority(taskId, priority);
    if (taskDescription != null) {
        InternalI18NText text = (InternalI18NText) TaskModelProvider.getFactory().newI18NText();
        text.setLanguage("en-UK");
        text.setText(taskDescription);
        List<I18NText> names = new ArrayList<I18NText>();
        names.add(text);
        nonProcessScopedTaskService.setDescriptions(taskId, names);
    }
    if (dueDate != null) {
        nonProcessScopedTaskService.setExpirationDate(taskId, dueDate);
    }
}
Also used : I18NText(org.kie.api.task.model.I18NText) InternalI18NText(org.kie.internal.task.api.model.InternalI18NText) InternalI18NText(org.kie.internal.task.api.model.InternalI18NText) ArrayList(java.util.ArrayList)

Example 20 with I18NText

use of org.kie.api.task.model.I18NText 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)

Aggregations

I18NText (org.kie.api.task.model.I18NText)24 ArrayList (java.util.ArrayList)22 InternalI18NText (org.kie.internal.task.api.model.InternalI18NText)19 Task (org.kie.api.task.model.Task)8 InternalTask (org.kie.internal.task.api.model.InternalTask)8 Test (org.junit.Test)6 I18NTextImpl (org.jbpm.services.task.impl.model.I18NTextImpl)5 RuntimeEngine (org.kie.api.runtime.manager.RuntimeEngine)4 OrganizationalEntity (org.kie.api.task.model.OrganizationalEntity)4 User (org.kie.api.task.model.User)4 InternalOrganizationalEntity (org.kie.internal.task.api.model.InternalOrganizationalEntity)4 InternalTaskData (org.kie.internal.task.api.model.InternalTaskData)4 StringReader (java.io.StringReader)3 Date (java.util.Date)3 HashMap (java.util.HashMap)3 JaxbI18NText (org.jbpm.services.task.impl.model.xml.JaxbI18NText)3 InternalTaskService (org.kie.internal.task.api.InternalTaskService)3 UserTaskService (org.jbpm.services.api.UserTaskService)2 UserTaskInstanceDesc (org.jbpm.services.api.model.UserTaskInstanceDesc)2 TaskFluent (org.jbpm.services.task.utils.TaskFluent)2