Search in sources :

Example 36 with OrganizationalEntity

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

the class EmailNotificationPublisherTest method testEmailNotificationWithoutTemplateToGroup.

@Test
public void testEmailNotificationWithoutTemplateToGroup() throws Exception {
    EmailNotificationPublisher publisher = new EmailNotificationPublisher(connection, userInfo);
    Set<OrganizationalEntity> recipients = new HashSet<>(Arrays.asList(factory.newGroup("managers")));
    publisher.publish("admin@jbpm.org", "Test notification", recipients, "Test body");
    assertEquals(1, wiser.getMessages().size());
    MimeMessage msg = ((WiserMessage) wiser.getMessages().get(0)).getMimeMessage();
    // Side effect of MIME encoding (I think.. ): \r\n..
    String content = ((String) msg.getContent()).replace("\r\n", "");
    assertEquals("Test body", content);
    assertEquals("Test notification", msg.getSubject());
    assertEquals("admin@jbpm.org", ((InternetAddress) msg.getFrom()[0]).getAddress());
    assertEquals("john@domain.com", ((InternetAddress) msg.getRecipients(RecipientType.TO)[0]).getAddress());
    assertNull(msg.getRecipients(RecipientType.CC));
    assertNull(msg.getRecipients(RecipientType.BCC));
}
Also used : OrganizationalEntity(org.kie.api.task.model.OrganizationalEntity) MimeMessage(javax.mail.internet.MimeMessage) WiserMessage(org.subethamail.wiser.WiserMessage) HashSet(java.util.HashSet) LinkedHashSet(java.util.LinkedHashSet) Test(org.junit.Test)

Example 37 with OrganizationalEntity

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

the class EmailNotificationPublisherTest method testEmailNotificationWithoutTemplateToMultipleRecipients.

@Test
public void testEmailNotificationWithoutTemplateToMultipleRecipients() throws Exception {
    EmailNotificationPublisher publisher = new EmailNotificationPublisher(connection, userInfo);
    Set<OrganizationalEntity> recipients = new LinkedHashSet<>(Arrays.asList(factory.newGroup("managers"), factory.newUser("mary")));
    publisher.publish("admin@jbpm.org", "Test notification", recipients, "Test body");
    assertEquals(2, wiser.getMessages().size());
    MimeMessage msg = ((WiserMessage) wiser.getMessages().get(0)).getMimeMessage();
    // Side effect of MIME encoding (I think.. ): \r\n..
    String content = ((String) msg.getContent()).replace("\r\n", "");
    assertEquals("Test body", content);
    assertEquals("Test notification", msg.getSubject());
    assertEquals("admin@jbpm.org", ((InternetAddress) msg.getFrom()[0]).getAddress());
    assertEquals("john@domain.com", ((InternetAddress) msg.getRecipients(RecipientType.TO)[0]).getAddress());
    assertNull(msg.getRecipients(RecipientType.CC));
    assertNull(msg.getRecipients(RecipientType.BCC));
}
Also used : LinkedHashSet(java.util.LinkedHashSet) OrganizationalEntity(org.kie.api.task.model.OrganizationalEntity) MimeMessage(javax.mail.internet.MimeMessage) WiserMessage(org.subethamail.wiser.WiserMessage) Test(org.junit.Test)

Example 38 with OrganizationalEntity

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

the class LifeCycleBaseTest method testNominateToUser.

@Test
public void testNominateToUser() {
    String str = "(with (new Task()) { priority = 55, taskData = (with( new TaskData()) { } ), ";
    str += "peopleAssignments = (with ( new PeopleAssignments() ) { businessAdministrators = [ new User('Darth Vader'), new User('Bobba Fet') ] } ),";
    str += "name =  'This is my task name' })";
    Task task = TaskFactory.evalTask(new StringReader(str));
    taskService.addTask(task, new HashMap<String, Object>());
    long taskId = task.getId();
    List<OrganizationalEntity> potentialOwners = new ArrayList<OrganizationalEntity>(1);
    User user = createUser("Jabba Hutt");
    potentialOwners.add(user);
    taskService.nominate(taskId, "Darth Vader", potentialOwners);
    // shouldn't affect the assignments
    Task task1 = taskService.getTaskById(taskId);
    assertEquals(task1.getTaskData().getActualOwner().getId(), "Jabba Hutt");
    assertEquals(task1.getTaskData().getStatus(), Status.Reserved);
}
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) InternalOrganizationalEntity(org.kie.internal.task.api.model.InternalOrganizationalEntity) StringReader(java.io.StringReader) ArrayList(java.util.ArrayList) Test(org.junit.Test)

Example 39 with OrganizationalEntity

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

the class LifeCycleBaseTest method testCompleteWithRestrictedGroups.

@Test
public void testCompleteWithRestrictedGroups() {
    // One potential owner, should go straight to state Reserved
    String str = "(with (new Task()) { priority = 55, taskData = (with( new TaskData()) { } ), ";
    str += "peopleAssignments = (with ( new PeopleAssignments() ) { potentialOwners = [new Group('analyst'), new Group('Crusaders') ],businessAdministrators = [ new User('Administrator') ], }),";
    str += "name =  'This is my task name' })";
    Task task = TaskFactory.evalTask(new StringReader(str));
    taskService.addTask(task, new HashMap<String, Object>());
    long taskId = task.getId();
    List<OrganizationalEntity> potOwners = task.getPeopleAssignments().getPotentialOwners();
    assertNotNull(potOwners);
    assertEquals(1, potOwners.size());
    assertEquals("Crusaders", potOwners.get(0).getId());
    // Go straight from Ready to Inprogress
    taskService.start(taskId, "Darth Vader");
    Task task1 = taskService.getTaskById(taskId);
    assertEquals(Status.InProgress, task1.getTaskData().getStatus());
    assertEquals("Darth Vader", task1.getTaskData().getActualOwner().getId());
    // Check is Complete
    taskService.complete(taskId, "Darth Vader", null);
    Task task2 = taskService.getTaskById(taskId);
    assertEquals(Status.Completed, task2.getTaskData().getStatus());
    assertEquals("Darth Vader", task2.getTaskData().getActualOwner().getId());
}
Also used : Task(org.kie.api.task.model.Task) InternalTask(org.kie.internal.task.api.model.InternalTask) OrganizationalEntity(org.kie.api.task.model.OrganizationalEntity) InternalOrganizationalEntity(org.kie.internal.task.api.model.InternalOrganizationalEntity) StringReader(java.io.StringReader) Test(org.junit.Test)

Example 40 with OrganizationalEntity

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

the class LifeCycleBaseTest method testActivateFromIncorrectStatus.

@Test
public void testActivateFromIncorrectStatus() {
    String str = "(with (new Task()) { priority = 55, taskData = (with( new TaskData()) { status = Status.Ready } ), ";
    str += "peopleAssignments = (with ( new PeopleAssignments() ) { potentialOwners = [ new User('Darth Vader'), new User('Bobba Fet') ], ";
    str += "businessAdministrators = [ new User('Jabba Hutt') ] } ),";
    str += "name = 'This is my task name' })";
    Task task = TaskFactory.evalTask(new StringReader(str), null);
    // We need to add the Admin if we don't initialize the task
    if (task.getPeopleAssignments() != null && task.getPeopleAssignments().getBusinessAdministrators() != null) {
        List<OrganizationalEntity> businessAdmins = new ArrayList<OrganizationalEntity>();
        User user = createUser("Administrator");
        businessAdmins.add(user);
        businessAdmins.addAll(task.getPeopleAssignments().getBusinessAdministrators());
        ((InternalPeopleAssignments) task.getPeopleAssignments()).setBusinessAdministrators(businessAdmins);
    }
    taskService.addTask(task, new HashMap<String, Object>());
    long taskId = task.getId();
    try {
        taskService.activate(taskId, "Darth Vader");
        fail("Shouldn't have succeded");
    } catch (RuntimeException e) {
    // assertNotNull(activateResponseHandler.getError());
    // assertNotNull(activateResponseHandler.getError().getMessage());
    // assertTrue(activateResponseHandler.getError().getMessage().contains("Darth Vader"));
    }
}
Also used : Task(org.kie.api.task.model.Task) InternalTask(org.kie.internal.task.api.model.InternalTask) InternalPeopleAssignments(org.kie.internal.task.api.model.InternalPeopleAssignments) User(org.kie.api.task.model.User) OrganizationalEntity(org.kie.api.task.model.OrganizationalEntity) InternalOrganizationalEntity(org.kie.internal.task.api.model.InternalOrganizationalEntity) StringReader(java.io.StringReader) ArrayList(java.util.ArrayList) Test(org.junit.Test)

Aggregations

OrganizationalEntity (org.kie.api.task.model.OrganizationalEntity)146 Test (org.junit.Test)93 HashMap (java.util.HashMap)69 CaseFileInstance (org.jbpm.casemgmt.api.model.instance.CaseFileInstance)55 ArrayList (java.util.ArrayList)54 User (org.kie.api.task.model.User)52 UserImpl (org.jbpm.services.task.impl.model.UserImpl)51 AbstractCaseServicesBaseTest (org.jbpm.casemgmt.impl.util.AbstractCaseServicesBaseTest)48 CaseInstance (org.jbpm.casemgmt.api.model.instance.CaseInstance)41 InternalPeopleAssignments (org.kie.internal.task.api.model.InternalPeopleAssignments)36 InternalTask (org.kie.internal.task.api.model.InternalTask)35 InternalOrganizationalEntity (org.kie.internal.task.api.model.InternalOrganizationalEntity)34 Task (org.kie.api.task.model.Task)33 QueryContext (org.kie.api.runtime.query.QueryContext)32 Group (org.kie.api.task.model.Group)29 CaseNotFoundException (org.jbpm.casemgmt.api.CaseNotFoundException)26 TaskSummary (org.kie.api.task.model.TaskSummary)25 AdHocFragmentNotFoundException (org.jbpm.casemgmt.api.AdHocFragmentNotFoundException)24 CaseActiveException (org.jbpm.casemgmt.api.CaseActiveException)24 CaseCommentNotFoundException (org.jbpm.casemgmt.api.CaseCommentNotFoundException)24