@Test public void testTranslate() { final StreamEntityDTO actor = new StreamEntityDTO(); actor.setId(AUTHOR_ID); final ActivityDTO activity = new ActivityDTO(); activity.setActor(actor); context.checking(new Expectations() { { oneOf(activityDAO).execute(ACTIVITY_ID); will(returnValue(activity)); oneOf(commentorsMapper).execute(ACTIVITY_ID); will(returnValue(Arrays.asList(ACTOR_ID, AUTHOR_ID, STREAM_OWNER_ID, COMMENTOR1, COMMENTOR2))); } }); CommentNotificationsRequest request = new CommentNotificationsRequest(null, ACTOR_ID, DESTINATION_ID, ACTIVITY_ID, COMMENT_ID); NotificationBatch results = sut.translate(request); context.assertIsSatisfied(); assertEquals(2, results.getRecipients().size()); TranslatorTestHelper.assertRecipients(results, NotificationType.COMMENT_TO_PERSONAL_POST, AUTHOR_ID); TranslatorTestHelper.assertRecipients(results, NotificationType.COMMENT_TO_COMMENTED_POST, STREAM_OWNER_ID, COMMENTOR1, COMMENTOR2); PropertyMap<Object> props = results.getProperties(); assertEquals(6, props.size()); PropertyMapTestHelper.assertPlaceholder(props, "actor", PersonModelView.class, ACTOR_ID); PropertyMapTestHelper.assertValue(props, "stream", activity.getDestinationStream()); PropertyMapTestHelper.assertAlias(props, "source", "stream"); PropertyMapTestHelper.assertValue(props, "activity", activity); PropertyMapTestHelper.assertPlaceholder(props, "comment", CommentDTO.class, COMMENT_ID); PropertyMapTestHelper.assertValue(props, NotificationPropertyKeys.URL, "#activity/" + ACTIVITY_ID); }
@Override public NotificationBatch translate(final CommentNotificationsRequest inRequest) { final long activityId = inRequest.getActivityId(); ActivityDTO activity = activityDAO.execute(activityId); if (activity == null) { return null; } final long actorId = inRequest.getActorId(); NotificationBatch batch = new NotificationBatch(); long postAuthor = activity.getActor().getId(); if (postAuthor != actorId) { batch.setRecipient(NotificationType.COMMENT_TO_PERSONAL_POST, postAuthor); } List<Long> commentToCommentedRecipients = new ArrayList<Long>(); for (long commentorId : commentorsDAO.execute(activityId)) { if (commentorId != postAuthor && commentorId != actorId) { commentToCommentedRecipients.add(commentorId); batch.getRecipients().put(NotificationType.COMMENT_TO_COMMENTED_POST, commentToCommentedRecipients); } } batch.setProperty(NotificationPropertyKeys.ACTOR, PersonModelView.class, actorId); batch.setProperty("stream", activity.getDestinationStream()); batch.setPropertyAlias(NotificationPropertyKeys.SOURCE, "stream"); batch.setProperty("activity", activity); batch.setProperty("comment", CommentDTO.class, inRequest.getCommentId()); batch.setProperty(NotificationPropertyKeys.URL, UiUrlBuilder.relativeUrlForActivity(activityId)); return batch; }
CommentTranslator implements NotificationTranslator<CommentNotificationsRequest> { @Override public NotificationBatch translate(final CommentNotificationsRequest inRequest) { final long activityId = inRequest.getActivityId(); ActivityDTO activity = activityDAO.execute(activityId); if (activity == null) { return null; } final long actorId = inRequest.getActorId(); NotificationBatch batch = new NotificationBatch(); long postAuthor = activity.getActor().getId(); if (postAuthor != actorId) { batch.setRecipient(NotificationType.COMMENT_TO_PERSONAL_POST, postAuthor); } List<Long> commentToCommentedRecipients = new ArrayList<Long>(); for (long commentorId : commentorsDAO.execute(activityId)) { if (commentorId != postAuthor && commentorId != actorId) { commentToCommentedRecipients.add(commentorId); batch.getRecipients().put(NotificationType.COMMENT_TO_COMMENTED_POST, commentToCommentedRecipients); } } batch.setProperty(NotificationPropertyKeys.ACTOR, PersonModelView.class, actorId); batch.setProperty("stream", activity.getDestinationStream()); batch.setPropertyAlias(NotificationPropertyKeys.SOURCE, "stream"); batch.setProperty("activity", activity); batch.setProperty("comment", CommentDTO.class, inRequest.getCommentId()); batch.setProperty(NotificationPropertyKeys.URL, UiUrlBuilder.relativeUrlForActivity(activityId)); return batch; } }
CommentTranslator implements NotificationTranslator<CommentNotificationsRequest> { @Override public NotificationBatch translate(final CommentNotificationsRequest inRequest) { final long activityId = inRequest.getActivityId(); ActivityDTO activity = activityDAO.execute(activityId); if (activity == null) { return null; } final long actorId = inRequest.getActorId(); NotificationBatch batch = new NotificationBatch(); long postAuthor = activity.getActor().getId(); if (postAuthor != actorId) { batch.setRecipient(NotificationType.COMMENT_TO_PERSONAL_POST, postAuthor); } List<Long> commentToCommentedRecipients = new ArrayList<Long>(); for (long commentorId : commentorsDAO.execute(activityId)) { if (commentorId != postAuthor && commentorId != actorId) { commentToCommentedRecipients.add(commentorId); batch.getRecipients().put(NotificationType.COMMENT_TO_COMMENTED_POST, commentToCommentedRecipients); } } batch.setProperty(NotificationPropertyKeys.ACTOR, PersonModelView.class, actorId); batch.setProperty("stream", activity.getDestinationStream()); batch.setPropertyAlias(NotificationPropertyKeys.SOURCE, "stream"); batch.setProperty("activity", activity); batch.setProperty("comment", CommentDTO.class, inRequest.getCommentId()); batch.setProperty(NotificationPropertyKeys.URL, UiUrlBuilder.relativeUrlForActivity(activityId)); return batch; } CommentTranslator(final DomainMapper<Long, List<Long>> inCommentorsDAO,
            final DomainMapper<Long, ActivityDTO> inActivityDAO); }
CommentTranslator implements NotificationTranslator<CommentNotificationsRequest> { @Override public NotificationBatch translate(final CommentNotificationsRequest inRequest) { final long activityId = inRequest.getActivityId(); ActivityDTO activity = activityDAO.execute(activityId); if (activity == null) { return null; } final long actorId = inRequest.getActorId(); NotificationBatch batch = new NotificationBatch(); long postAuthor = activity.getActor().getId(); if (postAuthor != actorId) { batch.setRecipient(NotificationType.COMMENT_TO_PERSONAL_POST, postAuthor); } List<Long> commentToCommentedRecipients = new ArrayList<Long>(); for (long commentorId : commentorsDAO.execute(activityId)) { if (commentorId != postAuthor && commentorId != actorId) { commentToCommentedRecipients.add(commentorId); batch.getRecipients().put(NotificationType.COMMENT_TO_COMMENTED_POST, commentToCommentedRecipients); } } batch.setProperty(NotificationPropertyKeys.ACTOR, PersonModelView.class, actorId); batch.setProperty("stream", activity.getDestinationStream()); batch.setPropertyAlias(NotificationPropertyKeys.SOURCE, "stream"); batch.setProperty("activity", activity); batch.setProperty("comment", CommentDTO.class, inRequest.getCommentId()); batch.setProperty(NotificationPropertyKeys.URL, UiUrlBuilder.relativeUrlForActivity(activityId)); return batch; } CommentTranslator(final DomainMapper<Long, List<Long>> inCommentorsDAO,
            final DomainMapper<Long, ActivityDTO> inActivityDAO); @Override NotificationBatch translate(final CommentNotificationsRequest inRequest); }
CommentTranslator implements NotificationTranslator<CommentNotificationsRequest> { @Override public NotificationBatch translate(final CommentNotificationsRequest inRequest) { final long activityId = inRequest.getActivityId(); ActivityDTO activity = activityDAO.execute(activityId); if (activity == null) { return null; } final long actorId = inRequest.getActorId(); NotificationBatch batch = new NotificationBatch(); long postAuthor = activity.getActor().getId(); if (postAuthor != actorId) { batch.setRecipient(NotificationType.COMMENT_TO_PERSONAL_POST, postAuthor); } List<Long> commentToCommentedRecipients = new ArrayList<Long>(); for (long commentorId : commentorsDAO.execute(activityId)) { if (commentorId != postAuthor && commentorId != actorId) { commentToCommentedRecipients.add(commentorId); batch.getRecipients().put(NotificationType.COMMENT_TO_COMMENTED_POST, commentToCommentedRecipients); } } batch.setProperty(NotificationPropertyKeys.ACTOR, PersonModelView.class, actorId); batch.setProperty("stream", activity.getDestinationStream()); batch.setPropertyAlias(NotificationPropertyKeys.SOURCE, "stream"); batch.setProperty("activity", activity); batch.setProperty("comment", CommentDTO.class, inRequest.getCommentId()); batch.setProperty(NotificationPropertyKeys.URL, UiUrlBuilder.relativeUrlForActivity(activityId)); return batch; } CommentTranslator(final DomainMapper<Long, List<Long>> inCommentorsDAO,
            final DomainMapper<Long, ActivityDTO> inActivityDAO); @Override NotificationBatch translate(final CommentNotificationsRequest inRequest);  }