Search in sources :

Example 31 with InternalTaskData

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

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

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

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

the class PeopleAssignmentHelperTest method testAssignActors.

@Test
public void testAssignActors() {
    String actorId = "espiegelberg";
    Task task = TaskModelProvider.getFactory().newTask();
    InternalTaskData taskData = (InternalTaskData) TaskModelProvider.getFactory().newTaskData();
    PeopleAssignments peopleAssignments = peopleAssignmentHelper.getNullSafePeopleAssignments(task);
    WorkItem workItem = new WorkItemImpl();
    workItem.setParameter(PeopleAssignmentHelper.ACTOR_ID, actorId);
    peopleAssignmentHelper.assignActors(workItem, peopleAssignments, taskData);
    OrganizationalEntity organizationalEntity1 = peopleAssignments.getPotentialOwners().get(0);
    assertTrue(organizationalEntity1 instanceof User);
    assertEquals(actorId, organizationalEntity1.getId());
    assertEquals(actorId, taskData.getCreatedBy().getId());
    workItem = new WorkItemImpl();
    peopleAssignments = peopleAssignmentHelper.getNullSafePeopleAssignments(task);
    workItem.setParameter(PeopleAssignmentHelper.ACTOR_ID, actorId + ", drbug  ");
    peopleAssignmentHelper.assignActors(workItem, peopleAssignments, taskData);
    assertEquals(2, peopleAssignments.getPotentialOwners().size());
    organizationalEntity1 = peopleAssignments.getPotentialOwners().get(0);
    assertEquals(actorId, organizationalEntity1.getId());
    assertEquals(actorId, taskData.getCreatedBy().getId());
    OrganizationalEntity organizationalEntity2 = peopleAssignments.getPotentialOwners().get(1);
    assertEquals("drbug", organizationalEntity2.getId());
    workItem = new WorkItemImpl();
    peopleAssignments = peopleAssignmentHelper.getNullSafePeopleAssignments(task);
    workItem.setParameter(PeopleAssignmentHelper.ACTOR_ID, "");
    peopleAssignmentHelper.assignActors(workItem, peopleAssignments, taskData);
    assertEquals(0, peopleAssignments.getPotentialOwners().size());
}
Also used : Task(org.kie.api.task.model.Task) InternalTask(org.kie.internal.task.api.model.InternalTask) User(org.kie.api.task.model.User) OrganizationalEntity(org.kie.api.task.model.OrganizationalEntity) InternalTaskData(org.kie.internal.task.api.model.InternalTaskData) WorkItemImpl(org.drools.core.process.instance.impl.WorkItemImpl) WorkItem(org.drools.core.process.instance.WorkItem) PeopleAssignments(org.kie.api.task.model.PeopleAssignments) InternalPeopleAssignments(org.kie.internal.task.api.model.InternalPeopleAssignments) Test(org.junit.Test) AbstractBaseTest(org.jbpm.test.util.AbstractBaseTest)

Example 35 with InternalTaskData

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

the class PeopleAssignmentHelperTest method testHandlePeopleAssignments.

@Test
public void testHandlePeopleAssignments() {
    InternalTask task = (InternalTask) TaskModelProvider.getFactory().newTask();
    InternalTaskData taskData = (InternalTaskData) TaskModelProvider.getFactory().newTaskData();
    InternalPeopleAssignments peopleAssignment = peopleAssignmentHelper.getNullSafePeopleAssignments(task);
    assertNotNull(peopleAssignment);
    assertEquals(0, peopleAssignment.getPotentialOwners().size());
    assertEquals(0, peopleAssignment.getBusinessAdministrators().size());
    assertEquals(0, peopleAssignment.getTaskStakeholders().size());
    String actorId = "espiegelberg";
    String taskStakeholderId = "drmary";
    String businessAdministratorId = "drbug";
    String businessAdministratorGroupId = "Super users";
    String excludedOwnerId = "john";
    String recipientId = "mary";
    WorkItem workItem = new WorkItemImpl();
    workItem.setParameter(PeopleAssignmentHelper.ACTOR_ID, actorId);
    workItem.setParameter(PeopleAssignmentHelper.TASKSTAKEHOLDER_ID, taskStakeholderId);
    workItem.setParameter(PeopleAssignmentHelper.BUSINESSADMINISTRATOR_ID, businessAdministratorId);
    workItem.setParameter(PeopleAssignmentHelper.BUSINESSADMINISTRATOR_GROUP_ID, businessAdministratorGroupId);
    workItem.setParameter(PeopleAssignmentHelper.EXCLUDED_OWNER_ID, excludedOwnerId);
    workItem.setParameter(PeopleAssignmentHelper.RECIPIENT_ID, recipientId);
    peopleAssignmentHelper.handlePeopleAssignments(workItem, task, taskData);
    List<OrganizationalEntity> potentialOwners = task.getPeopleAssignments().getPotentialOwners();
    assertEquals(1, potentialOwners.size());
    assertEquals(actorId, potentialOwners.get(0).getId());
    List<OrganizationalEntity> businessAdministrators = task.getPeopleAssignments().getBusinessAdministrators();
    assertEquals(4, businessAdministrators.size());
    assertEquals("Administrator", businessAdministrators.get(0).getId());
    // Admin group
    assertEquals("Administrators", businessAdministrators.get(1).getId());
    assertEquals(businessAdministratorId, businessAdministrators.get(2).getId());
    assertEquals(businessAdministratorGroupId, businessAdministrators.get(3).getId());
    List<OrganizationalEntity> taskStakehoders = ((InternalPeopleAssignments) task.getPeopleAssignments()).getTaskStakeholders();
    assertEquals(1, taskStakehoders.size());
    assertEquals(taskStakeholderId, taskStakehoders.get(0).getId());
    List<OrganizationalEntity> excludedOwners = ((InternalPeopleAssignments) task.getPeopleAssignments()).getExcludedOwners();
    assertEquals(1, excludedOwners.size());
    assertEquals(excludedOwnerId, excludedOwners.get(0).getId());
    List<OrganizationalEntity> recipients = ((InternalPeopleAssignments) task.getPeopleAssignments()).getRecipients();
    assertEquals(1, recipients.size());
    assertEquals(recipientId, recipients.get(0).getId());
}
Also used : InternalPeopleAssignments(org.kie.internal.task.api.model.InternalPeopleAssignments) OrganizationalEntity(org.kie.api.task.model.OrganizationalEntity) InternalTask(org.kie.internal.task.api.model.InternalTask) InternalTaskData(org.kie.internal.task.api.model.InternalTaskData) WorkItemImpl(org.drools.core.process.instance.impl.WorkItemImpl) WorkItem(org.drools.core.process.instance.WorkItem) Test(org.junit.Test) AbstractBaseTest(org.jbpm.test.util.AbstractBaseTest)

Aggregations

InternalTaskData (org.kie.internal.task.api.model.InternalTaskData)45 InternalTask (org.kie.internal.task.api.model.InternalTask)23 OrganizationalEntity (org.kie.api.task.model.OrganizationalEntity)22 Task (org.kie.api.task.model.Task)22 Test (org.junit.Test)21 User (org.kie.api.task.model.User)20 InternalPeopleAssignments (org.kie.internal.task.api.model.InternalPeopleAssignments)20 InternalContent (org.kie.internal.task.api.model.InternalContent)15 ContentData (org.kie.internal.task.api.model.ContentData)14 InternalOrganizationalEntity (org.kie.internal.task.api.model.InternalOrganizationalEntity)14 ArrayList (java.util.ArrayList)13 InputStreamReader (java.io.InputStreamReader)11 Reader (java.io.Reader)11 HashMap (java.util.HashMap)10 CountDownTaskEventListener (org.jbpm.services.task.util.CountDownTaskEventListener)10 Date (java.util.Date)7 StringReader (java.io.StringReader)6 WorkItemImpl (org.drools.core.process.instance.impl.WorkItemImpl)6 Content (org.kie.api.task.model.Content)6 Map (java.util.Map)5