Search in sources :

Example 6 with InternalTask

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

the class EmailDeadlinesBaseTest method testDelayedEmailNotificationStartDeadlineStatusDoesNotMatch.

@Test(timeout = 10000)
public void testDelayedEmailNotificationStartDeadlineStatusDoesNotMatch() throws Exception {
    CountDownTaskEventListener countDownListener = new CountDownTaskEventListener(2, false, true);
    addCountDownListner(countDownListener);
    Map<String, Object> vars = new HashMap<String, Object>();
    vars.put("now", new Date());
    Reader reader = new InputStreamReader(getClass().getResourceAsStream(MvelFilePath.DeadlineWithNotification));
    InternalTask task = (InternalTask) TaskFactory.evalTask(reader, vars);
    ((InternalTaskData) task.getTaskData()).setSkipable(true);
    InternalPeopleAssignments assignments = (InternalPeopleAssignments) TaskModelProvider.getFactory().newPeopleAssignments();
    List<OrganizationalEntity> ba = new ArrayList<OrganizationalEntity>();
    User user = TaskModelProvider.getFactory().newUser();
    ((InternalOrganizationalEntity) user).setId("Administrator");
    ba.add(user);
    assignments.setBusinessAdministrators(ba);
    List<OrganizationalEntity> po = new ArrayList<OrganizationalEntity>();
    User user2 = TaskModelProvider.getFactory().newUser();
    ((InternalOrganizationalEntity) user2).setId("Administrator");
    po.add(user2);
    assignments.setPotentialOwners(po);
    task.setPeopleAssignments(assignments);
    taskService.addTask(task, new HashMap<String, Object>());
    long taskId = task.getId();
    InternalContent content = (InternalContent) TaskModelProvider.getFactory().newContent();
    Map<String, String> params = fillMarshalSubjectAndBodyParams();
    ContentData marshalledObject = ContentMarshallerHelper.marshal(task, params, null);
    content.setContent(marshalledObject.getContent());
    taskService.addContent(taskId, content);
    long contentId = content.getId();
    content = (InternalContent) taskService.getContentById(contentId);
    Object unmarshallObject = ContentMarshallerHelper.unmarshall(content.getContent(), null);
    checkContentSubjectAndBody(unmarshallObject);
    taskService.start(taskId, "Administrator");
    // emails should not be set yet
    assertEquals(0, getWiser().getMessages().size());
    // since we don't want the notification to be invoked we need to rely on timeout
    countDownListener.waitTillCompleted(3000);
    // no email should ne sent as task was completed before deadline was triggered
    assertEquals(0, getWiser().getMessages().size());
    task = (InternalTask) taskService.getTaskById(taskId);
    assertEquals(Status.InProgress, task.getTaskData().getStatus());
    assertEquals(0, task.getDeadlines().getStartDeadlines().size());
    assertEquals(0, task.getDeadlines().getEndDeadlines().size());
}
Also used : User(org.kie.api.task.model.User) CountDownTaskEventListener(org.jbpm.services.task.util.CountDownTaskEventListener) InputStreamReader(java.io.InputStreamReader) OrganizationalEntity(org.kie.api.task.model.OrganizationalEntity) InternalOrganizationalEntity(org.kie.internal.task.api.model.InternalOrganizationalEntity) HashMap(java.util.HashMap) InternalTask(org.kie.internal.task.api.model.InternalTask) InternalTaskData(org.kie.internal.task.api.model.InternalTaskData) ArrayList(java.util.ArrayList) Reader(java.io.Reader) InputStreamReader(java.io.InputStreamReader) InternalContent(org.kie.internal.task.api.model.InternalContent) InternalOrganizationalEntity(org.kie.internal.task.api.model.InternalOrganizationalEntity) Date(java.util.Date) InternalPeopleAssignments(org.kie.internal.task.api.model.InternalPeopleAssignments) ContentData(org.kie.internal.task.api.model.ContentData) Test(org.junit.Test)

Example 7 with InternalTask

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

the class EmailDeadlinesBaseTest method testDelayedEmailNotificationOnDeadlineTaskFailed.

@Test(timeout = 10000)
public void testDelayedEmailNotificationOnDeadlineTaskFailed() throws Exception {
    CountDownTaskEventListener countDownListener = new CountDownTaskEventListener(1, false, true);
    addCountDownListner(countDownListener);
    Map<String, Object> vars = new HashMap<String, Object>();
    vars.put("now", new Date());
    Reader reader = new InputStreamReader(getClass().getResourceAsStream(MvelFilePath.DeadlineWithNotification));
    InternalTask task = (InternalTask) TaskFactory.evalTask(reader, vars);
    ((InternalTaskData) task.getTaskData()).setSkipable(true);
    InternalPeopleAssignments assignments = (InternalPeopleAssignments) TaskModelProvider.getFactory().newPeopleAssignments();
    List<OrganizationalEntity> ba = new ArrayList<OrganizationalEntity>();
    User user = TaskModelProvider.getFactory().newUser();
    ((InternalOrganizationalEntity) user).setId("Administrator");
    ba.add(user);
    assignments.setBusinessAdministrators(ba);
    List<OrganizationalEntity> po = new ArrayList<OrganizationalEntity>();
    User user2 = TaskModelProvider.getFactory().newUser();
    ((InternalOrganizationalEntity) user2).setId("Administrator");
    po.add(user2);
    assignments.setPotentialOwners(po);
    task.setPeopleAssignments(assignments);
    taskService.addTask(task, new HashMap<String, Object>());
    long taskId = task.getId();
    InternalContent content = (InternalContent) TaskModelProvider.getFactory().newContent();
    Map<String, String> params = fillMarshalSubjectAndBodyParams();
    ContentData marshalledObject = ContentMarshallerHelper.marshal(task, params, null);
    content.setContent(marshalledObject.getContent());
    taskService.addContent(taskId, content);
    long contentId = content.getId();
    content = (InternalContent) taskService.getContentById(contentId);
    Object unmarshallObject = ContentMarshallerHelper.unmarshall(content.getContent(), null);
    checkContentSubjectAndBody(unmarshallObject);
    taskService.start(taskId, "Administrator");
    taskService.fail(taskId, "Administrator", null);
    // emails should not be set yet
    assertEquals(0, getWiser().getMessages().size());
    countDownListener.waitTillCompleted();
    // no email should ne sent as task was completed before deadline was triggered
    assertEquals(0, getWiser().getMessages().size());
    task = (InternalTask) taskService.getTaskById(taskId);
    assertEquals(Status.Failed, task.getTaskData().getStatus());
    assertEquals(0, task.getDeadlines().getStartDeadlines().size());
    assertEquals(0, task.getDeadlines().getEndDeadlines().size());
}
Also used : User(org.kie.api.task.model.User) CountDownTaskEventListener(org.jbpm.services.task.util.CountDownTaskEventListener) InputStreamReader(java.io.InputStreamReader) OrganizationalEntity(org.kie.api.task.model.OrganizationalEntity) InternalOrganizationalEntity(org.kie.internal.task.api.model.InternalOrganizationalEntity) HashMap(java.util.HashMap) InternalTask(org.kie.internal.task.api.model.InternalTask) InternalTaskData(org.kie.internal.task.api.model.InternalTaskData) ArrayList(java.util.ArrayList) Reader(java.io.Reader) InputStreamReader(java.io.InputStreamReader) InternalContent(org.kie.internal.task.api.model.InternalContent) InternalOrganizationalEntity(org.kie.internal.task.api.model.InternalOrganizationalEntity) Date(java.util.Date) InternalPeopleAssignments(org.kie.internal.task.api.model.InternalPeopleAssignments) ContentData(org.kie.internal.task.api.model.ContentData) Test(org.junit.Test)

Example 8 with InternalTask

use of org.kie.internal.task.api.model.InternalTask 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 9 with InternalTask

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

the class TaskReminderBaseTest method testTaskReminderWithoutNotification.

@Test(timeout = 10000)
public void testTaskReminderWithoutNotification() throws Exception {
    CountDownTaskEventListener countDownListener = new CountDownTaskEventListener(1, false, true);
    addCountDownListner(countDownListener);
    Map<String, Object> vars = new HashMap<String, Object>();
    vars.put("now", new Date());
    Reader reader = new InputStreamReader(getClass().getResourceAsStream(MvelFilePath.ReminderWithoutNotification));
    InternalTask task = (InternalTask) TaskFactory.evalTask(reader, vars);
    System.out.println("testTaskReminderWithoutNotification " + task.getTaskData().getStatus());
    assertNull(task.getDeadlines());
    long taskId = taskService.addTask(task, new HashMap<String, Object>());
    taskService.executeReminderForTask(taskId, "Luke Cage");
    countDownListener.waitTillCompleted();
    assertEquals(1, wiser.getMessages().size());
    String receiver = wiser.getMessages().get(0).getEnvelopeReceiver();
    assertEquals("tony@domain.com", receiver);
    MimeMessage msg = ((WiserMessage) wiser.getMessages().get(0)).getMimeMessage();
    assertEquals("You have a task ( Simple Test Task ) of process ( taskReminder )", msg.getSubject());
}
Also used : CountDownTaskEventListener(org.jbpm.services.task.util.CountDownTaskEventListener) InputStreamReader(java.io.InputStreamReader) HashMap(java.util.HashMap) InternalTask(org.kie.internal.task.api.model.InternalTask) Reader(java.io.Reader) InputStreamReader(java.io.InputStreamReader) WiserMessage(org.subethamail.wiser.WiserMessage) Date(java.util.Date) MimeMessage(javax.mail.internet.MimeMessage) Test(org.junit.Test)

Example 10 with InternalTask

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

the class TaskReminderBaseTest method testTaskReminderWithNotificationByTaskNostarted.

@Test(timeout = 10000)
public void testTaskReminderWithNotificationByTaskNostarted() throws Exception {
    CountDownTaskEventListener countDownListener = new CountDownTaskEventListener(1, false, true);
    addCountDownListner(countDownListener);
    Map<String, Object> vars = new HashMap<String, Object>();
    vars.put("now", new Date());
    Reader reader = new InputStreamReader(getClass().getResourceAsStream(MvelFilePath.ReminderWithNotificationReserved));
    InternalTask task = (InternalTask) TaskFactory.evalTask(reader, vars);
    System.out.println("testTaskReminderWithNotificationByTaskNostarted " + task.getTaskData().getStatus());
    assertEquals(1, task.getDeadlines().getEndDeadlines().size());
    assertEquals(1, task.getDeadlines().getStartDeadlines().size());
    long taskId = taskService.addTask(task, new HashMap<String, Object>());
    taskService.executeReminderForTask(taskId, "Luke Cage");
    countDownListener.waitTillCompleted();
    assertEquals(2, wiser.getMessages().size());
    final List<String> list = new ArrayList<String>(2);
    list.add(wiser.getMessages().get(0).getEnvelopeReceiver());
    list.add(wiser.getMessages().get(1).getEnvelopeReceiver());
    assertTrue(list.contains("tony@domain.com"));
    assertTrue(list.contains("darth@domain.com"));
    MimeMessage msg = ((WiserMessage) wiser.getMessages().get(0)).getMimeMessage();
    assertEquals("ReminderWithNotificationReserved:you have new task to be started", msg.getSubject());
    assertEquals("task is not started", msg.getContent());
    msg = ((WiserMessage) wiser.getMessages().get(1)).getMimeMessage();
    assertEquals("ReminderWithNotificationReserved:you have new task to be started", msg.getSubject());
    assertEquals("task is not started", msg.getContent());
}
Also used : CountDownTaskEventListener(org.jbpm.services.task.util.CountDownTaskEventListener) InputStreamReader(java.io.InputStreamReader) HashMap(java.util.HashMap) InternalTask(org.kie.internal.task.api.model.InternalTask) ArrayList(java.util.ArrayList) Reader(java.io.Reader) InputStreamReader(java.io.InputStreamReader) WiserMessage(org.subethamail.wiser.WiserMessage) Date(java.util.Date) MimeMessage(javax.mail.internet.MimeMessage) Test(org.junit.Test)

Aggregations

InternalTask (org.kie.internal.task.api.model.InternalTask)50 Task (org.kie.api.task.model.Task)29 Test (org.junit.Test)27 ArrayList (java.util.ArrayList)21 InternalTaskData (org.kie.internal.task.api.model.InternalTaskData)18 OrganizationalEntity (org.kie.api.task.model.OrganizationalEntity)17 InputStreamReader (java.io.InputStreamReader)16 Reader (java.io.Reader)16 User (org.kie.api.task.model.User)16 CountDownTaskEventListener (org.jbpm.services.task.util.CountDownTaskEventListener)15 InternalPeopleAssignments (org.kie.internal.task.api.model.InternalPeopleAssignments)15 InternalOrganizationalEntity (org.kie.internal.task.api.model.InternalOrganizationalEntity)14 Date (java.util.Date)12 HashMap (java.util.HashMap)11 ContentData (org.kie.internal.task.api.model.ContentData)11 InternalContent (org.kie.internal.task.api.model.InternalContent)11 I18NText (org.kie.api.task.model.I18NText)10 InternalI18NText (org.kie.internal.task.api.model.InternalI18NText)8 TaskSummary (org.kie.api.task.model.TaskSummary)6 StringReader (java.io.StringReader)5