@SuppressWarnings("unchecked") @Test(expected = InvalidStateException.class) public void testExecuteCommentT0oBig() { final long activityId = 6790L; final long smithersId = 98L; Person smithers = (Person) getEntityManager().createQuery("FROM Person where id = :smithersId").setParameter( "smithersId", smithersId).getSingleResult(); assertEquals(smithersId, smithers.getId()); List<Long> activityIds = new ArrayList<Long>(1); activityIds.add(activityId); ActivityDTO activityDTO = activityMapper.execute(activityIds).get(0); assertEquals(activityId, activityDTO.getId()); assertEquals(3, activityDTO.getCommentCount()); assertEquals(5L, activityDTO.getFirstComment().getId()); assertEquals(7, activityDTO.getLastComment().getId()); InsertActivityCommentRequest insertRequest = new InsertActivityCommentRequest(smithersId, activityId, over1000); sut.execute(insertRequest); }
@SuppressWarnings("unchecked") @Override public CommentDTO execute(final InsertActivityCommentRequest inRequest) { final Activity activity = (Activity) getHibernateSession().load(Activity.class, inRequest.getActivityId()); Comment comment = new Comment((Person) getHibernateSession().load(Person.class, inRequest.getUserId()), 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()); commentDTOPopulator.execute(commentDTO, getCache()); 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); } 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; }
InsertActivityComment extends BaseArgCachedDomainMapper<InsertActivityCommentRequest, CommentDTO> { @SuppressWarnings("unchecked") @Override public CommentDTO execute(final InsertActivityCommentRequest inRequest) { final Activity activity = (Activity) getHibernateSession().load(Activity.class, inRequest.getActivityId()); Comment comment = new Comment((Person) getHibernateSession().load(Person.class, inRequest.getUserId()), 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()); commentDTOPopulator.execute(commentDTO, getCache()); 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); } 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; } }
InsertActivityComment extends BaseArgCachedDomainMapper<InsertActivityCommentRequest, CommentDTO> { @SuppressWarnings("unchecked") @Override public CommentDTO execute(final InsertActivityCommentRequest inRequest) { final Activity activity = (Activity) getHibernateSession().load(Activity.class, inRequest.getActivityId()); Comment comment = new Comment((Person) getHibernateSession().load(Person.class, inRequest.getUserId()), 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()); commentDTOPopulator.execute(commentDTO, getCache()); 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); } 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; } InsertActivityComment(final CommentDTOPopulator inCommentDTOPopulator); }
InsertActivityComment extends BaseArgCachedDomainMapper<InsertActivityCommentRequest, CommentDTO> { @SuppressWarnings("unchecked") @Override public CommentDTO execute(final InsertActivityCommentRequest inRequest) { final Activity activity = (Activity) getHibernateSession().load(Activity.class, inRequest.getActivityId()); Comment comment = new Comment((Person) getHibernateSession().load(Person.class, inRequest.getUserId()), 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()); commentDTOPopulator.execute(commentDTO, getCache()); 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); } 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; } InsertActivityComment(final CommentDTOPopulator inCommentDTOPopulator); @SuppressWarnings("unchecked") @Override CommentDTO execute(final InsertActivityCommentRequest inRequest); }
InsertActivityComment extends BaseArgCachedDomainMapper<InsertActivityCommentRequest, CommentDTO> { @SuppressWarnings("unchecked") @Override public CommentDTO execute(final InsertActivityCommentRequest inRequest) { final Activity activity = (Activity) getHibernateSession().load(Activity.class, inRequest.getActivityId()); Comment comment = new Comment((Person) getHibernateSession().load(Person.class, inRequest.getUserId()), 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()); commentDTOPopulator.execute(commentDTO, getCache()); 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); } 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; } InsertActivityComment(final CommentDTOPopulator inCommentDTOPopulator); @SuppressWarnings("unchecked") @Override CommentDTO execute(final InsertActivityCommentRequest inRequest);  }