@Override public Comment persistComment(Comment comment) { check(); this.em.persist( comment ); if( this.pessimisticLocking ) { this.em.flush(); return this.em.find(CommentImpl.class, comment.getId(), LockModeType.PESSIMISTIC_WRITE ); } return comment; }
/** * Removes the Comment specified by the commentId. * * @param commentId id of Comment to remove * @return removed Comment or null if one was not found with the id */ public Comment removeComment(final long commentId) { Comment removedComment = null; if (comments != null) { for (int index = comments.size() - 1; index >= 0; --index) { Comment currentComment = comments.get(index); if (currentComment.getId() == commentId) { removedComment = comments.remove(index); break; } } } return removedComment; }
protected void initialize(Comment comment) { if( comment != null ) { this.id = comment.getId(); this.text = comment.getText(); User addedByUser = comment.getAddedBy(); if( addedByUser != null ) { this.addedBy = addedByUser.getId(); } this.addedAt = comment.getAddedAt(); } }
@Override public Comment removeCommentFromTask(Comment comment, Task task) { ((InternalTaskData) task.getTaskData()).removeComment(comment.getId()); EventManagerProvider.getInstance().get().update(new TaskInstanceView(task)); return comment; }
public long addComment(long taskId, Comment comment) { Task task = persistenceContext.findTask(taskId); if (persistenceContext.findUser(comment.getAddedBy().getId()) == null) { persistenceContext.persistUser(comment.getAddedBy()); } persistenceContext.persistComment(comment); persistenceContext.addCommentToTask(comment, task); return comment.getId(); }
for (Comment comment : allCommentList) { assertNotNull(comment); assertNotNull(comment.getId()); assertTrue(comment.getId() > lastId); Comment savedComment = savedComments.get(comment.getId()); assertNotNull(savedComment); assertNotNull(comment.getAddedAt()); assertEquals(savedComment.getText(), comment.getText()); assertEquals("Troll", comment.getAddedBy().getId()); lastId = comment.getId();
public boolean containsComment(int commentId) { for(Comment comment : getComments()){ if(comment.getId() == commentId){ return true; } } return false; }
/** * Removes the Comment specified by the commentId. * * @param commentId id of Comment to remove * @return removed Comment or null if one was not found with the id */ public Comment removeComment(final long commentId) { Comment removedComment = null; if (comments != null) { for (int index = comments.size() - 1; index >= 0; --index) { Comment currentComment = comments.get(index); if (currentComment.getId() == commentId) { removedComment = comments.remove(index); break; } } } return removedComment; }
Iterator<Comment> commentIter = relevant.iterator(); Iterator<GitItem> itemIter = tree.iterator(); while (commentIter.hasNext() && itemIter.hasNext()) { Comment mc = commentIter.next(); GitItem gi = itemIter.next(); bb.buildBody(gi.getHash(), mc.getBody()); MutableComment mutable = commentManager.getMutableComment(mc.getId()); mutable.setBody(bb.sb.toString()); commentManager.update(mutable, true); }
@Override public Comment persistComment(Comment comment) { check(); this.em.persist( comment ); if( this.pessimisticLocking ) { this.em.flush(); return this.em.find(CommentImpl.class, comment.getId(), LockModeType.PESSIMISTIC_WRITE ); } return comment; }
public static List<CommentSummary> adaptCollection(List<Comment> comments) { List<CommentSummary> commentsSummaries = new ArrayList<CommentSummary>(comments.size()); for (Comment comment : comments) { commentsSummaries.add(new CommentSummary(comment.getId(), comment.getText(), comment.getAddedBy().toString(), comment.getAddedAt())); } return commentsSummaries; }
/*Serializer*/ import org.springframework.stereotype.Component; import com.fasterxml.jackson.core.JsonGenerator; import com.fasterxml.jackson.core.JsonProcessingException; import com.fasterxml.jackson.databind.JsonSerializer; import com.fasterxml.jackson.databind.SerializerProvider; @Component @Slf4j public class CommentSerializer extends JsonSerializer<Comment> { @Override public void serialize(Comment comment, JsonGenerator jgen, SerializerProvider provider) throws IOException, JsonProcessingException { jgen.writeStartObject(); jgen.writeStringField("id", comment.getId()); jgen.writeStringField("userId", comment.getUserId()); jgen.writeStringField("firstName", redisRepo.getName(comment.getUserId(), false)); jgen.writeStringField("discussionId", comment.getDiscussionId()); jgen.writeStringField("createdTime", String.valueOf(comment.getCreatedTime().getTime())); jgen.writeStringField("comment", comment.getComment()); jgen.writeEndObject(); } }
static CommentSummary adapt(Comment comment) { return new CommentSummary(comment.getId(), comment.getText(), comment.getAddedBy().toString(), comment.getAddedAt()); }
private void setCommentFields(Comment comment) { this.addedAt = ConversionUtil.convertDateToXmlGregorianCalendar(comment.getAddedAt()); User addedByUser = comment.getAddedBy(); if( addedByUser != null ) { this.addedBy = addedByUser.getId(); } this.id = comment.getId(); this.text = comment.getText(); }
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; }
@Override public Comment removeCommentFromTask(Comment comment, Task task) { ((InternalTaskData) task.getTaskData()).removeComment(comment.getId()); EventManagerProvider.getInstance().get().update(new TaskInstanceView(task)); return comment; }
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 addComment(long taskId, Comment comment) { // fill jaxbComment org.kie.remote.jaxb.gen.Comment jaxbComment = new org.kie.remote.jaxb.gen.Comment(); Date addedAt = comment.getAddedAt(); if( addedAt != null ) { XMLGregorianCalendar jaxbAddedAt = convertDateToXmlGregorianCalendar(addedAt); jaxbComment.setAddedAt(jaxbAddedAt); } User addedBy = comment.getAddedBy(); if( addedBy != null ) { jaxbComment.setAddedBy(addedBy.getId()); } jaxbComment.setText(comment.getText()); jaxbComment.setId(comment.getId()); // create command AddCommentCommand cmd = new AddCommentCommand(); cmd.setTaskId(taskId); cmd.setJaxbComment(jaxbComment); return executeCommand(cmd); }