Search in sources :

Example 1 with TaskComment

use of org.kie.server.api.model.instance.TaskComment in project droolsjbpm-integration by kiegroup.

the class UserTaskServicesClientImpl method getTaskCommentById.

@Override
public TaskComment getTaskCommentById(String containerId, Long taskId, Long commentId) {
    TaskComment taskComment = null;
    if (config.isRest()) {
        Map<String, Object> valuesMap = new HashMap<String, Object>();
        valuesMap.put(CONTAINER_ID, containerId);
        valuesMap.put(TASK_INSTANCE_ID, taskId);
        valuesMap.put(COMMENT_ID, commentId);
        taskComment = makeHttpGetRequestAndCreateCustomResponse(build(loadBalancer.getUrl(), TASK_URI + "/" + TASK_INSTANCE_COMMENT_GET_URI, valuesMap), TaskComment.class);
    } else {
        CommandScript script = new CommandScript(Collections.singletonList((KieServerCommand) new DescriptorCommand("UserTaskService", "getCommentById", marshaller.getFormat().getType(), new Object[] { containerId, taskId, commentId })));
        ServiceResponse<String> response = (ServiceResponse<String>) executeJmsCommand(script, DescriptorCommand.class.getName(), "BPM", containerId).getResponses().get(0);
        throwExceptionOnFailure(response);
        if (shouldReturnWithNullResponse(response)) {
            return null;
        }
        taskComment = deserialize(response.getResult(), TaskComment.class);
    }
    return taskComment;
}
Also used : DescriptorCommand(org.kie.server.api.commands.DescriptorCommand) TaskComment(org.kie.server.api.model.instance.TaskComment) ServiceResponse(org.kie.server.api.model.ServiceResponse) KieServerCommand(org.kie.server.api.model.KieServerCommand) HashMap(java.util.HashMap) CommandScript(org.kie.server.api.commands.CommandScript)

Example 2 with TaskComment

use of org.kie.server.api.model.instance.TaskComment in project droolsjbpm-integration by kiegroup.

the class UserTaskServicesClientImpl method addTaskComment.

@Override
public Long addTaskComment(String containerId, Long taskId, String text, String addedBy, Date addedOn) {
    Object commentId = null;
    TaskComment taskComment = TaskComment.builder().text(text).addedBy(addedBy).addedAt(addedOn).build();
    if (config.isRest()) {
        Map<String, Object> valuesMap = new HashMap<String, Object>();
        valuesMap.put(CONTAINER_ID, containerId);
        valuesMap.put(TASK_INSTANCE_ID, taskId);
        commentId = makeHttpPostRequestAndCreateCustomResponse(build(loadBalancer.getUrl(), TASK_URI + "/" + TASK_INSTANCE_COMMENT_ADD_POST_URI, valuesMap), taskComment, Object.class, getHeaders(taskComment));
    } else {
        CommandScript script = new CommandScript(Collections.singletonList((KieServerCommand) new DescriptorCommand("UserTaskService", "addComment", serialize(taskComment), marshaller.getFormat().getType(), new Object[] { containerId, taskId })));
        ServiceResponse<String> response = (ServiceResponse<String>) executeJmsCommand(script, DescriptorCommand.class.getName(), "BPM", containerId).getResponses().get(0);
        throwExceptionOnFailure(response);
        if (shouldReturnWithNullResponse(response)) {
            return null;
        }
        commentId = deserialize(response.getResult(), Object.class);
    }
    if (commentId instanceof Wrapped) {
        return (Long) ((Wrapped) commentId).unwrap();
    }
    return ((Number) commentId).longValue();
}
Also used : DescriptorCommand(org.kie.server.api.commands.DescriptorCommand) TaskComment(org.kie.server.api.model.instance.TaskComment) KieServerCommand(org.kie.server.api.model.KieServerCommand) HashMap(java.util.HashMap) CommandScript(org.kie.server.api.commands.CommandScript) ServiceResponse(org.kie.server.api.model.ServiceResponse) Wrapped(org.kie.server.api.model.Wrapped)

Example 3 with TaskComment

use of org.kie.server.api.model.instance.TaskComment in project droolsjbpm-integration by kiegroup.

the class UserTaskServiceIntegrationTest method testUserTaskComments.

@Test
public void testUserTaskComments() throws Exception {
    Long processInstanceId = processClient.startProcess(CONTAINER_ID, PROCESS_ID_USERTASK);
    assertNotNull(processInstanceId);
    assertTrue(processInstanceId.longValue() > 0);
    try {
        List<TaskSummary> taskList = taskClient.findTasksAssignedAsPotentialOwner(USER_YODA, 0, 10);
        assertNotNull(taskList);
        assertEquals(1, taskList.size());
        TaskSummary taskSummary = taskList.get(0);
        // Adding comment to user task as yoda.
        String firstComment = "First comment.";
        Calendar firstCommentTime = Calendar.getInstance();
        Long firstCommentId = taskClient.addTaskComment(CONTAINER_ID, taskSummary.getId(), firstComment, USER_YODA, firstCommentTime.getTime());
        // Adding second comment to user task as john.
        String secondComment = "Second comment.";
        Calendar secondCommentTime = Calendar.getInstance();
        secondCommentTime.add(Calendar.MINUTE, 5);
        Long secondCommentId = taskClient.addTaskComment(CONTAINER_ID, taskSummary.getId(), secondComment, USER_JOHN, secondCommentTime.getTime());
        // start task
        taskClient.startTask(CONTAINER_ID, taskSummary.getId(), USER_YODA);
        // Verifying first comment returned by getTaskCommentById().
        TaskComment firstTaskComment = taskClient.getTaskCommentById(CONTAINER_ID, taskSummary.getId(), firstCommentId);
        assertNotNull(firstTaskComment.getAddedAt());
        assertEquals(USER_YODA, firstTaskComment.getAddedBy());
        assertEquals(firstCommentId, firstTaskComment.getId());
        assertEquals(firstComment, firstTaskComment.getText());
        // Verifying second comment returned by getTaskCommentsByTaskId().
        List<TaskComment> taskComments = taskClient.getTaskCommentsByTaskId(CONTAINER_ID, taskSummary.getId());
        assertEquals(2, taskComments.size());
        TaskComment secondTaskComment = null;
        if (secondCommentId.equals(taskComments.get(0).getId())) {
            secondTaskComment = taskComments.get(0);
        } else {
            secondTaskComment = taskComments.get(1);
        }
        assertNotNull(secondTaskComment.getAddedAt());
        assertEquals(USER_JOHN, secondTaskComment.getAddedBy());
        assertEquals(secondCommentId, secondTaskComment.getId());
        assertEquals(secondComment, secondTaskComment.getText());
        // Delete task comment.
        taskClient.deleteTaskComment(CONTAINER_ID, taskSummary.getId(), secondCommentId);
        // Now there is just one comment left.
        taskComments = taskClient.getTaskCommentsByTaskId(CONTAINER_ID, taskSummary.getId());
        assertEquals(1, taskComments.size());
        assertEquals(firstCommentId, taskComments.get(0).getId());
    } finally {
        processClient.abortProcessInstance(CONTAINER_ID, processInstanceId);
    }
}
Also used : TaskComment(org.kie.server.api.model.instance.TaskComment) Calendar(java.util.Calendar) TaskSummary(org.kie.server.api.model.instance.TaskSummary) Test(org.junit.Test)

Example 4 with TaskComment

use of org.kie.server.api.model.instance.TaskComment in project droolsjbpm-integration by kiegroup.

the class RollingUpdateUserTaskServiceIntegrationTest method testTaskCommentsWithAlias.

@Test
public void testTaskCommentsWithAlias() throws Exception {
    Long pid = processClient.startProcess(CONTAINER_ALIAS, PROCESS_ID_EVALUATION);
    assertThat(pid).isNotNull().isGreaterThan(0);
    ProcessInstance processInstance = processClient.getProcessInstance(CONTAINER_ALIAS, pid);
    assertThat(processInstance).isNotNull();
    List<TaskSummary> taskList = taskClient.findTasksAssignedAsPotentialOwner(USER_YODA, 0, 10);
    assertThat(taskList).hasSize(1);
    TaskSummary taskSummary = taskList.get(0);
    List<TaskComment> taskComments = taskClient.getTaskCommentsByTaskId(CONTAINER_ALIAS, taskSummary.getId());
    assertThat(taskComments).isNotNull().hasSize(0);
    Date commentDate = new SimpleDateFormat("dd-MM-yyyy hh:mm").parse("18-03-1992 08:06");
    taskClient.addTaskComment(CONTAINER_ALIAS, taskSummary.getId(), "May the force be with you!", USER_YODA, commentDate);
    taskComments = taskClient.getTaskCommentsByTaskId(CONTAINER_ALIAS, taskSummary.getId());
    assertThat(taskComments).isNotNull().hasSize(1);
    TaskComment taskComment = taskComments.get(0);
    assertThat(taskComment.getText()).isEqualTo("May the force be with you!");
    assertThat(taskComment.getAddedBy()).isEqualTo(USER_YODA);
    assertThat(taskComment.getAddedAt()).isEqualTo(commentDate);
    taskComment = taskClient.getTaskCommentById(CONTAINER_ALIAS, taskSummary.getId(), taskComments.get(0).getId());
    assertThat(taskComment.getId()).isEqualTo(taskComments.get(0).getId());
    assertThat(taskComment.getText()).isEqualTo("May the force be with you!");
    assertThat(taskComment.getAddedBy()).isEqualTo(USER_YODA);
    assertThat(taskComment.getAddedAt()).isEqualTo(commentDate);
}
Also used : TaskComment(org.kie.server.api.model.instance.TaskComment) TaskSummary(org.kie.server.api.model.instance.TaskSummary) ProcessInstance(org.kie.server.api.model.instance.ProcessInstance) SimpleDateFormat(java.text.SimpleDateFormat) Date(java.util.Date) Test(org.junit.Test)

Example 5 with TaskComment

use of org.kie.server.api.model.instance.TaskComment in project droolsjbpm-integration by kiegroup.

the class UserTaskServiceBase method getCommentsByTaskId.

public String getCommentsByTaskId(String containerId, Number taskId, String marshallingType) {
    containerId = context.getContainerId(containerId, new ByTaskIdContainerLocator(taskId.longValue()));
    List<Comment> comments = userTaskService.getCommentsByTaskId(containerId, taskId.longValue());
    TaskComment[] taskComments = new TaskComment[comments.size()];
    int counter = 0;
    for (Comment comment : comments) {
        TaskComment taskComment = TaskComment.builder().id(comment.getId()).text(comment.getText()).addedBy(comment.getAddedBy().getId()).addedAt(comment.getAddedAt()).build();
        taskComments[counter] = taskComment;
        counter++;
    }
    TaskCommentList result = new TaskCommentList(taskComments);
    logger.debug("About to marshal task '{}' comments {}", taskId, result);
    String response = marshallerHelper.marshal(containerId, marshallingType, result);
    return response;
}
Also used : TaskComment(org.kie.server.api.model.instance.TaskComment) Comment(org.kie.api.task.model.Comment) ByTaskIdContainerLocator(org.kie.server.services.jbpm.locator.ByTaskIdContainerLocator) TaskComment(org.kie.server.api.model.instance.TaskComment) TaskCommentList(org.kie.server.api.model.instance.TaskCommentList)

Aggregations

TaskComment (org.kie.server.api.model.instance.TaskComment)7 ByTaskIdContainerLocator (org.kie.server.services.jbpm.locator.ByTaskIdContainerLocator)3 HashMap (java.util.HashMap)2 Test (org.junit.Test)2 Comment (org.kie.api.task.model.Comment)2 CommandScript (org.kie.server.api.commands.CommandScript)2 DescriptorCommand (org.kie.server.api.commands.DescriptorCommand)2 KieServerCommand (org.kie.server.api.model.KieServerCommand)2 ServiceResponse (org.kie.server.api.model.ServiceResponse)2 TaskSummary (org.kie.server.api.model.instance.TaskSummary)2 SimpleDateFormat (java.text.SimpleDateFormat)1 Calendar (java.util.Calendar)1 Date (java.util.Date)1 Wrapped (org.kie.server.api.model.Wrapped)1 ProcessInstance (org.kie.server.api.model.instance.ProcessInstance)1 TaskCommentList (org.kie.server.api.model.instance.TaskCommentList)1