Search in sources :

Example 36 with InternalTask

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

the class EmailDeadlinesBaseTest method testDelayedEmailNotificationOnDeadlineTaskCompleted.

@Test(timeout = 10000)
public void testDelayedEmailNotificationOnDeadlineTaskCompleted() 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.complete(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.Completed, 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 37 with InternalTask

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

the class EmailDeadlinesBaseTest method testDelayedEmailNotificationOnDeadlineTaskExited.

@Test(timeout = 10000)
public void testDelayedEmailNotificationOnDeadlineTaskExited() 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.exit(taskId, "Administrator");
    // 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.Exited, 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 38 with InternalTask

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

the class EmailDeadlinesBaseTest method testDelayedEmailNotificationOnDeadlineTaskSkipped.

@Test(timeout = 10000)
public void testDelayedEmailNotificationOnDeadlineTaskSkipped() 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.skip(taskId, "Administrator");
    // 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.Obsolete, 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 39 with InternalTask

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

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

the class TaskReminderBaseTest method testTaskReminderWithNotificationByTaskNoCompleted.

@Test(timeout = 10000)
public void testTaskReminderWithNotificationByTaskNoCompleted() 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.ReminderWithNotificationInProgress));
    InternalTask task = (InternalTask) TaskFactory.evalTask(reader, vars);
    System.out.println("testTaskReminderWithNotificationByTaskNoCompleted " + 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());
    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("ReminderWithNotificationInProgress:you have new task to be completed", msg.getSubject());
    assertEquals("task is not completed", msg.getContent());
    msg = ((WiserMessage) wiser.getMessages().get(1)).getMimeMessage();
    assertEquals("ReminderWithNotificationInProgress:you have new task to be completed", msg.getSubject());
    assertEquals("task is not completed", 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