@Test public void testTranslatePersonalStreamPost() { context.checking(new Expectations() { { allowing(followersDAO).execute(STREAM_OWNER_ID); will(returnValue(new ArrayList<Long>(Arrays.asList(ACTOR_ID, STREAM_OWNER_ID, 5L, 6L, 7L)))); } }); NotificationBatch results = sut.translate(new ActivityNotificationsRequest(null, ACTOR_ID, STREAM_OWNER_ID, ACTIVITY_ID)); assertEquals(2, results.getRecipients().size()); TranslatorTestHelper.assertRecipients(results, NotificationType.POST_TO_PERSONAL_STREAM, STREAM_OWNER_ID); TranslatorTestHelper.assertRecipients(results, NotificationType.POST_TO_FOLLOWED_STREAM, 5L, 6L, 7L); PropertyMap<Object> props = results.getProperties(); assertEquals(5, props.size()); PropertyMapTestHelper.assertPlaceholder(props, "actor", PersonModelView.class, ACTOR_ID); PropertyMapTestHelper.assertPlaceholder(props, "stream", PersonModelView.class, STREAM_OWNER_ID); PropertyMapTestHelper.assertPlaceholder(props, "activity", ActivityDTO.class, ACTIVITY_ID); PropertyMapTestHelper.assertAlias(props, "source", "stream"); PropertyMapTestHelper.assertValue(props, NotificationPropertyKeys.URL, "#activity/" + ACTIVITY_ID); }
@Override public NotificationBatch translate(final ActivityNotificationsRequest inRequest) { List<Long> followerIdsToNotify = followersDAO.execute(inRequest.getTargetEntityId()); followerIdsToNotify.remove(inRequest.getActorId()); followerIdsToNotify.remove(inRequest.getTargetEntityId()); NotificationBatch batch = new NotificationBatch(); if (inRequest.getActorId() != inRequest.getTargetEntityId()) { batch.setRecipient(NotificationType.POST_TO_PERSONAL_STREAM, inRequest.getTargetEntityId()); } if (!followerIdsToNotify.isEmpty()) { batch.getRecipients().put(NotificationType.POST_TO_FOLLOWED_STREAM, followerIdsToNotify); } if (batch.getRecipients().isEmpty()) { return null; } batch.setProperty(NotificationPropertyKeys.ACTOR, PersonModelView.class, inRequest.getActorId()); batch.setProperty("stream", PersonModelView.class, inRequest.getTargetEntityId()); batch.setProperty("activity", ActivityDTO.class, inRequest.getActivityId()); batch.setPropertyAlias(NotificationPropertyKeys.SOURCE, "stream"); batch.setProperty(NotificationPropertyKeys.URL, UiUrlBuilder.relativeUrlForActivity(inRequest.getActivityId())); return batch; }
PostPersonStreamTranslator implements NotificationTranslator<ActivityNotificationsRequest> { @Override public NotificationBatch translate(final ActivityNotificationsRequest inRequest) { List<Long> followerIdsToNotify = followersDAO.execute(inRequest.getTargetEntityId()); followerIdsToNotify.remove(inRequest.getActorId()); followerIdsToNotify.remove(inRequest.getTargetEntityId()); NotificationBatch batch = new NotificationBatch(); if (inRequest.getActorId() != inRequest.getTargetEntityId()) { batch.setRecipient(NotificationType.POST_TO_PERSONAL_STREAM, inRequest.getTargetEntityId()); } if (!followerIdsToNotify.isEmpty()) { batch.getRecipients().put(NotificationType.POST_TO_FOLLOWED_STREAM, followerIdsToNotify); } if (batch.getRecipients().isEmpty()) { return null; } batch.setProperty(NotificationPropertyKeys.ACTOR, PersonModelView.class, inRequest.getActorId()); batch.setProperty("stream", PersonModelView.class, inRequest.getTargetEntityId()); batch.setProperty("activity", ActivityDTO.class, inRequest.getActivityId()); batch.setPropertyAlias(NotificationPropertyKeys.SOURCE, "stream"); batch.setProperty(NotificationPropertyKeys.URL, UiUrlBuilder.relativeUrlForActivity(inRequest.getActivityId())); return batch; } }
PostPersonStreamTranslator implements NotificationTranslator<ActivityNotificationsRequest> { @Override public NotificationBatch translate(final ActivityNotificationsRequest inRequest) { List<Long> followerIdsToNotify = followersDAO.execute(inRequest.getTargetEntityId()); followerIdsToNotify.remove(inRequest.getActorId()); followerIdsToNotify.remove(inRequest.getTargetEntityId()); NotificationBatch batch = new NotificationBatch(); if (inRequest.getActorId() != inRequest.getTargetEntityId()) { batch.setRecipient(NotificationType.POST_TO_PERSONAL_STREAM, inRequest.getTargetEntityId()); } if (!followerIdsToNotify.isEmpty()) { batch.getRecipients().put(NotificationType.POST_TO_FOLLOWED_STREAM, followerIdsToNotify); } if (batch.getRecipients().isEmpty()) { return null; } batch.setProperty(NotificationPropertyKeys.ACTOR, PersonModelView.class, inRequest.getActorId()); batch.setProperty("stream", PersonModelView.class, inRequest.getTargetEntityId()); batch.setProperty("activity", ActivityDTO.class, inRequest.getActivityId()); batch.setPropertyAlias(NotificationPropertyKeys.SOURCE, "stream"); batch.setProperty(NotificationPropertyKeys.URL, UiUrlBuilder.relativeUrlForActivity(inRequest.getActivityId())); return batch; } PostPersonStreamTranslator(final DomainMapper<Long, List<Long>> inFollowersDAO); }
PostPersonStreamTranslator implements NotificationTranslator<ActivityNotificationsRequest> { @Override public NotificationBatch translate(final ActivityNotificationsRequest inRequest) { List<Long> followerIdsToNotify = followersDAO.execute(inRequest.getTargetEntityId()); followerIdsToNotify.remove(inRequest.getActorId()); followerIdsToNotify.remove(inRequest.getTargetEntityId()); NotificationBatch batch = new NotificationBatch(); if (inRequest.getActorId() != inRequest.getTargetEntityId()) { batch.setRecipient(NotificationType.POST_TO_PERSONAL_STREAM, inRequest.getTargetEntityId()); } if (!followerIdsToNotify.isEmpty()) { batch.getRecipients().put(NotificationType.POST_TO_FOLLOWED_STREAM, followerIdsToNotify); } if (batch.getRecipients().isEmpty()) { return null; } batch.setProperty(NotificationPropertyKeys.ACTOR, PersonModelView.class, inRequest.getActorId()); batch.setProperty("stream", PersonModelView.class, inRequest.getTargetEntityId()); batch.setProperty("activity", ActivityDTO.class, inRequest.getActivityId()); batch.setPropertyAlias(NotificationPropertyKeys.SOURCE, "stream"); batch.setProperty(NotificationPropertyKeys.URL, UiUrlBuilder.relativeUrlForActivity(inRequest.getActivityId())); return batch; } PostPersonStreamTranslator(final DomainMapper<Long, List<Long>> inFollowersDAO); @Override NotificationBatch translate(final ActivityNotificationsRequest inRequest); }
PostPersonStreamTranslator implements NotificationTranslator<ActivityNotificationsRequest> { @Override public NotificationBatch translate(final ActivityNotificationsRequest inRequest) { List<Long> followerIdsToNotify = followersDAO.execute(inRequest.getTargetEntityId()); followerIdsToNotify.remove(inRequest.getActorId()); followerIdsToNotify.remove(inRequest.getTargetEntityId()); NotificationBatch batch = new NotificationBatch(); if (inRequest.getActorId() != inRequest.getTargetEntityId()) { batch.setRecipient(NotificationType.POST_TO_PERSONAL_STREAM, inRequest.getTargetEntityId()); } if (!followerIdsToNotify.isEmpty()) { batch.getRecipients().put(NotificationType.POST_TO_FOLLOWED_STREAM, followerIdsToNotify); } if (batch.getRecipients().isEmpty()) { return null; } batch.setProperty(NotificationPropertyKeys.ACTOR, PersonModelView.class, inRequest.getActorId()); batch.setProperty("stream", PersonModelView.class, inRequest.getTargetEntityId()); batch.setProperty("activity", ActivityDTO.class, inRequest.getActivityId()); batch.setPropertyAlias(NotificationPropertyKeys.SOURCE, "stream"); batch.setProperty(NotificationPropertyKeys.URL, UiUrlBuilder.relativeUrlForActivity(inRequest.getActivityId())); return batch; } PostPersonStreamTranslator(final DomainMapper<Long, List<Long>> inFollowersDAO); @Override NotificationBatch translate(final ActivityNotificationsRequest inRequest);  }