Search in sources :

Example 6 with InternalI18NText

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

the class TaskQueryServiceBaseTest method testModifyTaskName.

@Test
public void testModifyTaskName() {
    // 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());
    Task newTask = taskService.getTaskById(tasks.get(0).getId());
    List<I18NText> updatedNames = new ArrayList<I18NText>();
    I18NText updatedName = TaskModelProvider.getFactory().newI18NText();
    ((InternalI18NText) updatedName).setLanguage(newTask.getNames().get(0).getLanguage());
    ((InternalI18NText) updatedName).setText("New task name");
    updatedNames.add(updatedName);
    taskService.setTaskNames(newTask.getId(), updatedNames);
    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 : 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) StringReader(java.io.StringReader) ArrayList(java.util.ArrayList) TaskSummary(org.kie.api.task.model.TaskSummary) Test(org.junit.Test)

Example 7 with InternalI18NText

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

the class TaskInstanceServiceImpl method setTaskNames.

public void setTaskNames(long taskId, List<I18NText> inputTaskNames) {
    Task task = persistenceContext.findTask(taskId);
    taskEventSupport.fireBeforeTaskUpdated(task, context);
    List<I18NText> taskNames = new ArrayList<I18NText>(inputTaskNames.size());
    for (I18NText inputText : inputTaskNames) {
        I18NText text = TaskModelProvider.getFactory().newI18NText();
        ((InternalI18NText) text).setLanguage(inputText.getLanguage());
        ((InternalI18NText) text).setText(inputText.getText());
        taskNames.add(text);
    }
    ((InternalTask) task).setNames(taskNames);
    ((InternalTask) task).setName(taskNames.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 8 with InternalI18NText

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

the class TestPersistenceContext method createSomeTask.

public void createSomeTask() {
    testIsInitialized();
    TaskImpl task = new TaskImpl();
    InternalI18NText name = (InternalI18NText) TaskModelProvider.getFactory().newI18NText();
    name.setText("Some Task");
    List<I18NText> names = new ArrayList<I18NText>();
    names.add(name);
    task.setNames(names);
    InternalTaskData taskData = (InternalTaskData) TaskModelProvider.getFactory().newTaskData();
    taskData.setWorkItemId(12);
    taskData.setProcessInstanceId(1);
    taskData.setProcessId("someprocess");
    taskData.setDeploymentId("org.jbpm.test:someprocess:1.0");
    taskData.setProcessSessionId(1);
    task.setTaskData(taskData);
    InternalPeopleAssignments peopleAssignments = (InternalPeopleAssignments) TaskModelProvider.getFactory().newPeopleAssignments();
    peopleAssignments.setPotentialOwners(new ArrayList<OrganizationalEntity>());
    peopleAssignments.setBusinessAdministrators(new ArrayList<OrganizationalEntity>());
    peopleAssignments.setExcludedOwners(new ArrayList<OrganizationalEntity>());
    peopleAssignments.setRecipients(new ArrayList<OrganizationalEntity>());
    peopleAssignments.setTaskStakeholders(new ArrayList<OrganizationalEntity>());
    InternalOrganizationalEntity jdoe = (InternalOrganizationalEntity) TaskModelProvider.getFactory().newUser();
    jdoe.setId("jdoe");
    peopleAssignments.getPotentialOwners().add(jdoe);
    peopleAssignments.getBusinessAdministrators().add(jdoe);
    task.setPeopleAssignments(peopleAssignments);
    final boolean txOwner = transactionManager.begin();
    try {
        EntityManager em = entityManagerFactory.createEntityManager();
        em.persist(jdoe);
        em.persist(task);
        transactionManager.commit(txOwner);
    } catch (Exception ex) {
        ex.printStackTrace();
        transactionManager.rollback(txOwner);
        throw new RuntimeException(ex.getMessage(), ex);
    }
}
Also used : I18NText(org.kie.api.task.model.I18NText) InternalI18NText(org.kie.internal.task.api.model.InternalI18NText) OrganizationalEntity(org.kie.api.task.model.OrganizationalEntity) InternalOrganizationalEntity(org.kie.internal.task.api.model.InternalOrganizationalEntity) InternalI18NText(org.kie.internal.task.api.model.InternalI18NText) TaskImpl(org.jbpm.persistence.scripts.oldentities.TaskImpl) ArrayList(java.util.ArrayList) InternalTaskData(org.kie.internal.task.api.model.InternalTaskData) InternalOrganizationalEntity(org.kie.internal.task.api.model.InternalOrganizationalEntity) SQLException(java.sql.SQLException) ParseException(java.text.ParseException) IOException(java.io.IOException) InternalPeopleAssignments(org.kie.internal.task.api.model.InternalPeopleAssignments) EntityManager(javax.persistence.EntityManager)

Example 9 with InternalI18NText

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

the class AbstractHTWorkItemHandler method createTaskBasedOnWorkItemParams.

protected Task createTaskBasedOnWorkItemParams(KieSession session, WorkItem workItem) {
    InternalTask task = (InternalTask) TaskModelProvider.getFactory().newTask();
    String taskName = (String) workItem.getParameter("NodeName");
    CaseData caseFile = null;
    String locale = (String) workItem.getParameter("Locale");
    if (locale == null) {
        locale = "en-UK";
    }
    if (taskName != null) {
        List<I18NText> names = new ArrayList<I18NText>();
        I18NText text = TaskModelProvider.getFactory().newI18NText();
        ((InternalI18NText) text).setLanguage(locale);
        ((InternalI18NText) text).setText(taskName);
        names.add(text);
        task.setNames(names);
    }
    task.setName(taskName);
    // this should be replaced by FormName filled by designer
    // TaskName shouldn't be trimmed if we are planning to use that for the task lists
    String formName = (String) workItem.getParameter("TaskName");
    if (formName != null) {
        task.setFormName(formName);
    }
    String comment = (String) workItem.getParameter("Comment");
    if (comment == null) {
        comment = "";
    }
    String description = (String) workItem.getParameter("Description");
    if (description == null) {
        description = comment;
    }
    List<I18NText> descriptions = new ArrayList<I18NText>();
    I18NText descText = TaskModelProvider.getFactory().newI18NText();
    ((InternalI18NText) descText).setLanguage(locale);
    ((InternalI18NText) descText).setText(description);
    descriptions.add(descText);
    task.setDescriptions(descriptions);
    task.setDescription(description);
    List<I18NText> subjects = new ArrayList<I18NText>();
    I18NText subjectText = TaskModelProvider.getFactory().newI18NText();
    ((InternalI18NText) subjectText).setLanguage(locale);
    ((InternalI18NText) subjectText).setText(comment);
    subjects.add(subjectText);
    task.setSubjects(subjects);
    task.setSubject(comment);
    String priorityString = (String) workItem.getParameter("Priority");
    int priority = 0;
    if (priorityString != null) {
        try {
            priority = new Integer(priorityString);
        } catch (NumberFormatException e) {
        // do nothing
        }
    }
    task.setPriority(priority);
    InternalTaskData taskData = (InternalTaskData) TaskModelProvider.getFactory().newTaskData();
    taskData.setWorkItemId(workItem.getId());
    taskData.setProcessInstanceId(workItem.getProcessInstanceId());
    if (session != null) {
        if (session.getProcessInstance(workItem.getProcessInstanceId()) != null) {
            taskData.setProcessId(session.getProcessInstance(workItem.getProcessInstanceId()).getProcess().getId());
            String deploymentId = ((WorkItemImpl) workItem).getDeploymentId();
            taskData.setDeploymentId(deploymentId);
        }
        if (session instanceof KieSession) {
            taskData.setProcessSessionId(((KieSession) session).getIdentifier());
        }
        @SuppressWarnings("unchecked") Collection<CaseData> caseFiles = (Collection<CaseData>) session.getObjects(new ClassObjectFilter(CaseData.class));
        if (caseFiles != null && caseFiles.size() == 1) {
            caseFile = caseFiles.iterator().next();
        }
    }
    taskData.setSkipable(!"false".equals(workItem.getParameter("Skippable")));
    // Sub Task Data
    Long parentId = (Long) workItem.getParameter("ParentId");
    if (parentId != null) {
        taskData.setParentId(parentId);
    }
    String createdBy = (String) workItem.getParameter("CreatedBy");
    if (createdBy != null && createdBy.trim().length() > 0) {
        User user = TaskModelProvider.getFactory().newUser();
        ((InternalOrganizationalEntity) user).setId(createdBy);
        taskData.setCreatedBy(user);
    }
    String dueDateString = (String) workItem.getParameter("DueDate");
    Date date = null;
    if (dueDateString != null && !dueDateString.isEmpty()) {
        if (DateTimeUtils.isPeriod(dueDateString)) {
            Long longDateValue = DateTimeUtils.parseDateAsDuration(dueDateString.substring(1));
            date = new Date(System.currentTimeMillis() + longDateValue);
        } else {
            date = new Date(DateTimeUtils.parseDateTime(dueDateString));
        }
    }
    if (date != null) {
        taskData.setExpirationTime(date);
    }
    PeopleAssignmentHelper peopleAssignmentHelper = new PeopleAssignmentHelper(caseFile);
    peopleAssignmentHelper.handlePeopleAssignments(workItem, task, taskData);
    PeopleAssignments peopleAssignments = task.getPeopleAssignments();
    List<OrganizationalEntity> businessAdministrators = peopleAssignments.getBusinessAdministrators();
    taskData.initialize();
    task.setTaskData(taskData);
    task.setDeadlines(HumanTaskHandlerHelper.setDeadlines(workItem, businessAdministrators, session.getEnvironment()));
    return task;
}
Also used : CaseData(org.kie.api.runtime.process.CaseData) User(org.kie.api.task.model.User) InternalTask(org.kie.internal.task.api.model.InternalTask) ArrayList(java.util.ArrayList) InternalTaskData(org.kie.internal.task.api.model.InternalTaskData) InternalOrganizationalEntity(org.kie.internal.task.api.model.InternalOrganizationalEntity) PeopleAssignments(org.kie.api.task.model.PeopleAssignments) KieSession(org.kie.api.runtime.KieSession) I18NText(org.kie.api.task.model.I18NText) InternalI18NText(org.kie.internal.task.api.model.InternalI18NText) OrganizationalEntity(org.kie.api.task.model.OrganizationalEntity) InternalOrganizationalEntity(org.kie.internal.task.api.model.InternalOrganizationalEntity) InternalI18NText(org.kie.internal.task.api.model.InternalI18NText) Date(java.util.Date) PeopleAssignmentHelper(org.jbpm.services.task.wih.util.PeopleAssignmentHelper) ClassObjectFilter(org.drools.core.ClassObjectFilter) WorkItemImpl(org.drools.core.process.instance.impl.WorkItemImpl) Collection(java.util.Collection)

Example 10 with InternalI18NText

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

the class DefaultChecklistManager method setTaskDescription.

private void setTaskDescription(InternalTask task, String description) {
    List<I18NText> descriptions = new ArrayList<I18NText>();
    I18NText text = TaskModelProvider.getFactory().newI18NText();
    ((InternalI18NText) text).setLanguage("en-UK");
    ((InternalI18NText) text).setText(description);
    descriptions.add(text);
    task.setDescriptions(descriptions);
}
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)

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