public String getCommentById(String containerId, Number taskId, Number commentId, String marshallingType) { containerId = context.getContainerId(containerId, new ByTaskIdContainerLocator(taskId.longValue())); Comment comment = userTaskService.getCommentById(containerId, taskId.longValue(), commentId.longValue()); if (comment == null) { throw new IllegalStateException("No comment found with id " + commentId + " on task " + taskId); } TaskComment taskComment = TaskComment.builder() .id(comment.getId()) .text(comment.getText()) .addedBy(comment.getAddedBy().getId()) .addedAt(comment.getAddedAt()) .build(); logger.debug("About to marshal task '{}' comment {}", taskId, taskComment); String response = marshallerHelper.marshal(containerId, marshallingType, taskComment); return response; }
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; }
@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(); }