Search in sources :

Example 6 with InternalOrganizationalEntity

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

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

the class TaskCommentTest method testTaskComment.

@Test
public void testTaskComment() throws Exception {
    String str = "(with (new Task()) { priority = 55, taskData = (with( new TaskData()) { } ), ";
    str += "peopleAssignments = (with ( new PeopleAssignments() ) { businessAdministrators = [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>());
    List<TaskSummary> tasks = taskService.getTasksAssignedAsBusinessAdministrator("Bobba Fet", "en-UK");
    String txt = "brainwashArmitageRecruitCaseGetPasswordFromLady3JaneAscentToStraylightIcebreakerUniteWithNeuromancer";
    assertEquals(1, tasks.size());
    TaskSummary taskSum = tasks.get(0);
    Comment comment = TaskModelProvider.getFactory().newComment();
    ((InternalComment) comment).setAddedAt(TODAY);
    User user = TaskModelProvider.getFactory().newUser();
    ((InternalOrganizationalEntity) user).setId("Troll");
    ((InternalComment) comment).setAddedBy(user);
    ((InternalComment) comment).setText(txt);
    Long commentId = taskService.addComment(taskSum.getId().longValue(), comment);
    assertNotNull(commentId);
    assertTrue(commentId.longValue() > 0l);
    Comment commentById = taskService.getCommentById(commentId.longValue());
    assertNotNull(commentById);
    assertEquals(commentId, commentById.getId());
    Assertions.assertThat(commentById.getAddedAt()).isCloseTo(TODAY, 1000);
    assertEquals(user, commentById.getAddedBy());
    assertEquals(txt, commentById.getText());
    Comment comment2 = TaskModelProvider.getFactory().newComment();
    ((InternalComment) comment2).setAddedAt(new Date());
    User user2 = TaskModelProvider.getFactory().newUser();
    ((InternalOrganizationalEntity) user2).setId("Master");
    ((InternalComment) comment2).setAddedBy(user2);
    ((InternalComment) comment2).setText(txt + "asdf");
    Long commentId2 = taskService.addComment(taskSum.getId(), comment2);
    assertNotNull(commentId2);
    assertTrue(commentId2.longValue() > 0l);
    assertNotEquals(commentId, commentId2);
    Comment commentById2 = taskService.getCommentById(commentId2.longValue());
    assertNotNull(commentById2);
    assertNotEquals(commentById, commentById2);
    List<Comment> allCommentList = taskService.getAllCommentsByTaskId(taskSum.getId());
    assertEquals(2, allCommentList.size());
    // check id
    assertEquals(commentId, allCommentList.get(0).getId());
    assertEquals(commentId2, allCommentList.get(1).getId());
    taskService.deleteComment(taskSum.getId(), commentId2);
    assertFalse(taskService.getAllCommentsByTaskId(taskSum.getId()).isEmpty());
    // one item
    allCommentList = taskService.getAllCommentsByTaskId(taskSum.getId());
    assertEquals(1, allCommentList.size());
    taskService.deleteComment(taskSum.getId(), commentId);
    assertTrue(taskService.getAllCommentsByTaskId(taskSum.getId()).isEmpty());
}
Also used : InternalComment(org.kie.internal.task.api.model.InternalComment) Comment(org.kie.api.task.model.Comment) Task(org.kie.api.task.model.Task) User(org.kie.api.task.model.User) InternalComment(org.kie.internal.task.api.model.InternalComment) InternalOrganizationalEntity(org.kie.internal.task.api.model.InternalOrganizationalEntity) Date(java.util.Date) StringReader(java.io.StringReader) TaskSummary(org.kie.api.task.model.TaskSummary) Test(org.junit.Test)

Example 8 with InternalOrganizationalEntity

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

the class TaskCommentTest method testTaskCommentsOrder.

@Test
public void testTaskCommentsOrder() {
    int commentsCount = 50;
    String str = "(with (new Task()) { priority = 55, taskData = (with( new TaskData()) { } ), ";
    str += "peopleAssignments = (with ( new PeopleAssignments() ) { businessAdministrators = [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>());
    List<TaskSummary> tasks = taskService.getTasksAssignedAsBusinessAdministrator("Bobba Fet", "en-UK");
    TaskSummary taskSum = tasks.get(0);
    final Map<Long, Comment> savedComments = new HashMap<>();
    for (int i = 0; i < commentsCount; i++) {
        Comment comment = TaskModelProvider.getFactory().newComment();
        ((InternalComment) comment).setAddedAt(TODAY);
        User user = TaskModelProvider.getFactory().newUser();
        ((InternalOrganizationalEntity) user).setId("Troll");
        ((InternalComment) comment).setAddedBy(user);
        ((InternalComment) comment).setText("Comment " + i + ".");
        final Long commentId = taskService.addComment(taskSum.getId(), comment);
        assertNotNull(commentId);
        savedComments.put(commentId, comment);
    }
    List<Comment> allCommentList = taskService.getAllCommentsByTaskId(taskSum.getId());
    assertEquals(commentsCount, allCommentList.size());
    Long lastId = 0L;
    for (Comment comment : allCommentList) {
        assertNotNull(comment);
        assertNotNull(comment.getId());
        assertTrue(comment.getId() > lastId);
        Comment savedComment = savedComments.get(comment.getId());
        assertNotNull(savedComment);
        assertNotNull(comment.getAddedAt());
        Assertions.assertThat(comment.getAddedAt()).isCloseTo(TODAY, 1000);
        assertEquals(savedComment.getText(), comment.getText());
        assertEquals("Troll", comment.getAddedBy().getId());
        lastId = comment.getId();
    }
}
Also used : InternalComment(org.kie.internal.task.api.model.InternalComment) Comment(org.kie.api.task.model.Comment) Task(org.kie.api.task.model.Task) User(org.kie.api.task.model.User) HashMap(java.util.HashMap) InternalComment(org.kie.internal.task.api.model.InternalComment) InternalOrganizationalEntity(org.kie.internal.task.api.model.InternalOrganizationalEntity) StringReader(java.io.StringReader) TaskSummary(org.kie.api.task.model.TaskSummary) Test(org.junit.Test)

Example 9 with InternalOrganizationalEntity

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

the class AssignmentService method assignTask.

public void assignTask(Task task) {
    List<OrganizationalEntity> potentialOwners = task.getPeopleAssignments().getPotentialOwners();
    potentialOwners.clear();
    Group group = TaskModelProvider.getFactory().newGroup();
    ((InternalOrganizationalEntity) group).setId("Crusaders");
    potentialOwners.add(group);
}
Also used : Group(org.kie.api.task.model.Group) OrganizationalEntity(org.kie.api.task.model.OrganizationalEntity) InternalOrganizationalEntity(org.kie.internal.task.api.model.InternalOrganizationalEntity) InternalOrganizationalEntity(org.kie.internal.task.api.model.InternalOrganizationalEntity)

Example 10 with InternalOrganizationalEntity

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

the class DefaultUserInfo method buildRegistry.

protected void buildRegistry(Properties registryProps) {
    if (registryProps != null) {
        Iterator<Object> propertyKeys = registryProps.keySet().iterator();
        while (propertyKeys.hasNext()) {
            String propertyKey = (String) propertyKeys.next();
            // following is the string for every organizational entity
            // email:locale:displayname:[member,member]
            // members are optional and should be given for group entities
            String propertyValue = registryProps.getProperty(propertyKey);
            String[] elems = propertyValue.split(":");
            Map<String, Object> entityInfo = new HashMap<String, Object>();
            entityInfo.put("email", elems[0]);
            entityInfo.put("locale", elems[1]);
            entityInfo.put("name", elems[2]);
            if (elems.length == 4 && elems[3] != null) {
                String memberList = elems[3];
                if (memberList.startsWith("[")) {
                    memberList = memberList.substring(1);
                }
                if (memberList.endsWith("]")) {
                    memberList = memberList.substring(0, memberList.length() - 1);
                }
                String[] members = memberList.split(",");
                List<OrganizationalEntity> membersList = new ArrayList<OrganizationalEntity>();
                for (String member : members) {
                    User user = TaskModelProvider.getFactory().newUser();
                    ((InternalOrganizationalEntity) user).setId(member);
                    membersList.add(user);
                }
                entityInfo.put("members", membersList);
            }
            registry.put(propertyKey, entityInfo);
        }
    }
}
Also used : User(org.kie.api.task.model.User) InternalOrganizationalEntity(org.kie.internal.task.api.model.InternalOrganizationalEntity) OrganizationalEntity(org.kie.api.task.model.OrganizationalEntity) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) InternalOrganizationalEntity(org.kie.internal.task.api.model.InternalOrganizationalEntity)

Aggregations

InternalOrganizationalEntity (org.kie.internal.task.api.model.InternalOrganizationalEntity)31 User (org.kie.api.task.model.User)25 OrganizationalEntity (org.kie.api.task.model.OrganizationalEntity)21 Test (org.junit.Test)16 ArrayList (java.util.ArrayList)14 InternalTask (org.kie.internal.task.api.model.InternalTask)14 InternalTaskData (org.kie.internal.task.api.model.InternalTaskData)14 InternalPeopleAssignments (org.kie.internal.task.api.model.InternalPeopleAssignments)12 InputStreamReader (java.io.InputStreamReader)11 Reader (java.io.Reader)11 Group (org.kie.api.task.model.Group)11 ContentData (org.kie.internal.task.api.model.ContentData)11 HashMap (java.util.HashMap)10 CountDownTaskEventListener (org.jbpm.services.task.util.CountDownTaskEventListener)10 InternalContent (org.kie.internal.task.api.model.InternalContent)10 Date (java.util.Date)9 Task (org.kie.api.task.model.Task)5 I18NText (org.kie.api.task.model.I18NText)4 InternalI18NText (org.kie.internal.task.api.model.InternalI18NText)4 StringReader (java.io.StringReader)3