activity,
inRequest.getContent().trim());
getEntityManager().persist(comment);
CommentDTO commentDTO = new CommentDTO();
commentDTO.setActivityId(inRequest.getActivityId());
commentDTO.setAuthorId(inRequest.getUserId());
commentDTO.setId(comment.getId());
commentDTO.setTimeSent(comment.getTimeSent());
commentDTO.setBody(inRequest.getContent());
//fully popluate and cache the commentDTO
commentDTOPopulator.execute(commentDTO, getCache());
//if present update activityDTO in cache.
String activityDTOKey = CacheKeys.ACTIVITY_BY_ID + inRequest.getActivityId();
ActivityDTO activityDTO = (ActivityDTO) getCache().get(activityDTOKey);
if (activityDTO != null)
{
if (activityDTO.getCommentCount() == 0)
{
activityDTO.setFirstComment(commentDTO);
}
else
{
activityDTO.setLastComment(commentDTO);
}
activityDTO.setCommentCount(activityDTO.getCommentCount() + 1);
getCache().set(activityDTOKey, activityDTO);
}
//if present, update commentId list for activity in cache.
String commentIdListKey = CacheKeys.COMMENT_IDS_BY_ACTIVITY_ID + inRequest.getActivityId();
List<Long> commentIds = getCache().getList(commentIdListKey);
if (commentIds != null)
{
commentIds.add(commentDTO.getId());
getCache().setList(commentIdListKey, commentIds);
}
commentDTO.setDeletable(true);
Search.getFullTextSession((Session) getEntityManager().getDelegate()).index(activity);
return commentDTO;
}