Search in sources :

Example 1 with InternalComment

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

the class AddCommentCommand method execute.

public Long execute(Context cntxt) {
    TaskContext context = (TaskContext) cntxt;
    Comment cmdComent = comment;
    if (cmdComent == null) {
        cmdComent = jaxbComment;
    }
    InternalComment commentImpl = (InternalComment) TaskModelProvider.getFactory().newComment();
    commentImpl.setAddedAt(cmdComent.getAddedAt());
    User cmdAddedBy = cmdComent.getAddedBy();
    User addedBy = TaskModelProvider.getFactory().newUser(cmdAddedBy.getId());
    commentImpl.setAddedBy(addedBy);
    commentImpl.setText(cmdComent.getText());
    doCallbackOperationForComment(commentImpl, context);
    return context.getTaskCommentService().addComment(taskId, commentImpl);
}
Also used : JaxbComment(org.jbpm.services.task.impl.model.xml.JaxbComment) Comment(org.kie.api.task.model.Comment) InternalComment(org.kie.internal.task.api.model.InternalComment) User(org.kie.api.task.model.User) InternalComment(org.kie.internal.task.api.model.InternalComment)

Example 2 with InternalComment

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

the class UserTaskServiceImpl method addComment.

@Override
public Long addComment(String deploymentId, Long taskId, String text, String addedBy, Date addedOn) {
    UserTaskInstanceDesc task = dataService.getTaskById(taskId);
    validateTask(deploymentId, taskId, task);
    RuntimeManager manager = getRuntimeManager(task);
    if (manager == null) {
        logger.warn("Cannot find runtime manager for task {}", taskId);
        return null;
    }
    RuntimeEngine engine = manager.getRuntimeEngine(ProcessInstanceIdContext.get(task.getProcessInstanceId()));
    try {
        TaskService taskService = engine.getTaskService();
        // perform actual operation
        InternalComment comment = (InternalComment) TaskModelProvider.getFactory().newComment();
        comment.setText(text);
        comment.setAddedAt(addedOn);
        comment.setAddedBy(TaskModelProvider.getFactory().newUser(addedBy));
        return ((InternalTaskService) taskService).addComment(taskId, comment);
    } finally {
        disposeRuntimeEngine(manager, engine);
    }
}
Also used : RuntimeEngine(org.kie.api.runtime.manager.RuntimeEngine) InternalTaskService(org.kie.internal.task.api.InternalTaskService) UserTaskService(org.jbpm.services.api.UserTaskService) TaskService(org.kie.api.task.TaskService) InternalComment(org.kie.internal.task.api.model.InternalComment) RuntimeManager(org.kie.api.runtime.manager.RuntimeManager) InternalRuntimeManager(org.kie.internal.runtime.manager.InternalRuntimeManager) InternalTaskService(org.kie.internal.task.api.InternalTaskService) UserTaskInstanceDesc(org.jbpm.services.api.model.UserTaskInstanceDesc)

Example 3 with InternalComment

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

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

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

the class LifeCycleBaseTest method testCompleteWithComments.

@Test
public void testCompleteWithComments() {
    // 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 User('Bobba Fet'), new User('Darth Vader') ],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<Comment> comments = taskService.getAllCommentsByTaskId(taskId);
    assertNotNull(comments);
    assertEquals(0, comments.size());
    User user = createUser("Bobba Fet");
    Comment comment = TaskModelProvider.getFactory().newComment();
    ((InternalComment) comment).setAddedAt(new Date());
    ((InternalComment) comment).setAddedBy(user);
    ((InternalComment) comment).setText("Simple test comment");
    taskService.addComment(taskId, comment);
    comments = taskService.getAllCommentsByTaskId(taskId);
    assertNotNull(comments);
    assertEquals(1, comments.size());
    // 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 : InternalComment(org.kie.internal.task.api.model.InternalComment) Comment(org.kie.api.task.model.Comment) Task(org.kie.api.task.model.Task) InternalTask(org.kie.internal.task.api.model.InternalTask) User(org.kie.api.task.model.User) InternalComment(org.kie.internal.task.api.model.InternalComment) StringReader(java.io.StringReader) Date(java.util.Date) Test(org.junit.Test)

Aggregations

InternalComment (org.kie.internal.task.api.model.InternalComment)7 User (org.kie.api.task.model.User)6 Comment (org.kie.api.task.model.Comment)5 Test (org.junit.Test)4 Task (org.kie.api.task.model.Task)4 StringReader (java.io.StringReader)3 Date (java.util.Date)3 InternalOrganizationalEntity (org.kie.internal.task.api.model.InternalOrganizationalEntity)3 InternalTask (org.kie.internal.task.api.model.InternalTask)3 HashMap (java.util.HashMap)2 I18NText (org.kie.api.task.model.I18NText)2 TaskSummary (org.kie.api.task.model.TaskSummary)2 InternalAttachment (org.kie.internal.task.api.model.InternalAttachment)2 InternalI18NText (org.kie.internal.task.api.model.InternalI18NText)2 InternalTaskData (org.kie.internal.task.api.model.InternalTaskData)2 InputStream (java.io.InputStream)1 InputStreamReader (java.io.InputStreamReader)1 Reader (java.io.Reader)1 ArrayList (java.util.ArrayList)1 List (java.util.List)1