@Test public void testExecute() { final InAppNotificationDTO notif1 = new InAppNotificationDTO(); notif1.setAvatarOwnerType(EntityType.PERSON); notif1.setAvatarOwnerUniqueId("knownperson"); notif1.setNotificationType(NotificationType.COMMENT_TO_PERSONAL_POST); final InAppNotificationDTO notif2 = new InAppNotificationDTO(); notif2.setAvatarOwnerType(EntityType.GROUP); notif2.setAvatarOwnerUniqueId("knowngroup"); notif2.setNotificationType(NotificationType.REQUEST_GROUP_ACCESS); final InAppNotificationDTO notif3 = new InAppNotificationDTO(); notif3.setAvatarOwnerType(EntityType.NOTSET); notif3.setNotificationType(NotificationType.FOLLOW_GROUP); final InAppNotificationDTO notif4 = new InAppNotificationDTO(); notif4.setAvatarOwnerType(EntityType.PERSON); notif4.setAvatarOwnerUniqueId("unknownperson"); notif4.setNotificationType(NotificationType.PASS_THROUGH); final InAppNotificationDTO notif5 = new InAppNotificationDTO(); notif5.setAvatarOwnerType(EntityType.GROUP); notif5.setAvatarOwnerUniqueId("avatarlessgroup"); notif5.setNotificationType(NotificationType.COMMENT_TO_COMMENTED_POST); final PersonModelView person = new PersonModelView(); person.setAccountId("knownperson"); person.setAvatarId("avatar1"); final DomainGroupModelView group = new DomainGroupModelView(); group.setShortName("knowngroup"); group.setAvatarId("avatar2"); final DomainGroupModelView group2 = new DomainGroupModelView(); group2.setShortName("avatarlessgroup"); group2.setAvatarId(null); context.checking(new Expectations() { { oneOf(alertMapper).execute(USER_ID); will(returnValue(Arrays.asList(notif1, notif2, notif3, notif4, notif5))); oneOf(personsMapper).execute((List<String>) with(Matchers.hasItems("knownperson", "unknownperson"))); will(returnValue(Collections.singletonList(person))); oneOf(groupsMapper).execute((List<String>) with(Matchers.hasItems("knowngroup", "avatarlessgroup"))); will(returnValue(Arrays.asList(group, group2))); } }); PrincipalActionContext ctx = TestContextCreator.createPrincipalActionContext(null, "whomever", USER_ID); List<InAppNotificationDTO> result = (List<InAppNotificationDTO>) sut.execute(ctx); context.assertIsSatisfied(); assertEquals(5, result.size()); assertEquals("COMMENT", result.get(0).getFilterCategory()); assertNull(result.get(1).getFilterCategory()); assertEquals("FOLLOW", result.get(2).getFilterCategory()); assertNull(result.get(3).getFilterCategory()); assertEquals("COMMENT", result.get(4).getFilterCategory()); assertEquals("avatar1", result.get(0).getAvatarId()); assertEquals("avatar2", result.get(1).getAvatarId()); assertNull(result.get(2).getAvatarId()); assertNull(result.get(3).getAvatarId()); assertNull(result.get(4).getAvatarId()); }
@Override @SuppressWarnings("unchecked") public Serializable execute(final PrincipalActionContext inActionContext) { long userId = inActionContext.getPrincipal().getId(); List<InAppNotificationDTO> results = alertMapper.execute(userId); if (results.isEmpty()) { return (Serializable) Collections.EMPTY_LIST; } for (InAppNotificationDTO item : results) { item.setFilterCategory(notificationTypeToCategory.get(item.getNotificationType())); } Map<String, PersonModelView> personLookup = new HashMap<String, PersonModelView>(); Map<String, DomainGroupModelView> groupLookup = new HashMap<String, DomainGroupModelView>(); for (InAppNotificationDTO notif : results) { switch (notif.getAvatarOwnerType()) { case PERSON: personLookup.put(notif.getAvatarOwnerUniqueId(), null); break; case GROUP: groupLookup.put(notif.getAvatarOwnerUniqueId(), null); break; default: int makeCheckstyleShutUpBecauseTheresNothingToDoHere = 1; } } for (PersonModelView person : personsMapper.execute(new ArrayList(personLookup.keySet()))) { personLookup.put(person.getAccountId(), person); } for (DomainGroupModelView group : groupsMapper.execute(new ArrayList(groupLookup.keySet()))) { groupLookup.put(group.getUniqueId(), group); } for (InAppNotificationDTO notif : results) { AvatarEntity entity = null; switch (notif.getAvatarOwnerType()) { case PERSON: entity = personLookup.get(notif.getAvatarOwnerUniqueId()); break; case GROUP: entity = groupLookup.get(notif.getAvatarOwnerUniqueId()); break; default: int makeCheckstyleShutUpBecauseTheresNothingToDoHere = 1; } if (entity != null && entity.getAvatarId() != null) { notif.setAvatarId(entity.getAvatarId()); } } log.trace("Found {} notifications for user {}", results.size(), userId); return new ArrayList(results); }
GetInAppNotificationsExecution implements ExecutionStrategy<PrincipalActionContext> { @Override @SuppressWarnings("unchecked") public Serializable execute(final PrincipalActionContext inActionContext) { long userId = inActionContext.getPrincipal().getId(); List<InAppNotificationDTO> results = alertMapper.execute(userId); if (results.isEmpty()) { return (Serializable) Collections.EMPTY_LIST; } for (InAppNotificationDTO item : results) { item.setFilterCategory(notificationTypeToCategory.get(item.getNotificationType())); } Map<String, PersonModelView> personLookup = new HashMap<String, PersonModelView>(); Map<String, DomainGroupModelView> groupLookup = new HashMap<String, DomainGroupModelView>(); for (InAppNotificationDTO notif : results) { switch (notif.getAvatarOwnerType()) { case PERSON: personLookup.put(notif.getAvatarOwnerUniqueId(), null); break; case GROUP: groupLookup.put(notif.getAvatarOwnerUniqueId(), null); break; default: int makeCheckstyleShutUpBecauseTheresNothingToDoHere = 1; } } for (PersonModelView person : personsMapper.execute(new ArrayList(personLookup.keySet()))) { personLookup.put(person.getAccountId(), person); } for (DomainGroupModelView group : groupsMapper.execute(new ArrayList(groupLookup.keySet()))) { groupLookup.put(group.getUniqueId(), group); } for (InAppNotificationDTO notif : results) { AvatarEntity entity = null; switch (notif.getAvatarOwnerType()) { case PERSON: entity = personLookup.get(notif.getAvatarOwnerUniqueId()); break; case GROUP: entity = groupLookup.get(notif.getAvatarOwnerUniqueId()); break; default: int makeCheckstyleShutUpBecauseTheresNothingToDoHere = 1; } if (entity != null && entity.getAvatarId() != null) { notif.setAvatarId(entity.getAvatarId()); } } log.trace("Found {} notifications for user {}", results.size(), userId); return new ArrayList(results); } }
GetInAppNotificationsExecution implements ExecutionStrategy<PrincipalActionContext> { @Override @SuppressWarnings("unchecked") public Serializable execute(final PrincipalActionContext inActionContext) { long userId = inActionContext.getPrincipal().getId(); List<InAppNotificationDTO> results = alertMapper.execute(userId); if (results.isEmpty()) { return (Serializable) Collections.EMPTY_LIST; } for (InAppNotificationDTO item : results) { item.setFilterCategory(notificationTypeToCategory.get(item.getNotificationType())); } Map<String, PersonModelView> personLookup = new HashMap<String, PersonModelView>(); Map<String, DomainGroupModelView> groupLookup = new HashMap<String, DomainGroupModelView>(); for (InAppNotificationDTO notif : results) { switch (notif.getAvatarOwnerType()) { case PERSON: personLookup.put(notif.getAvatarOwnerUniqueId(), null); break; case GROUP: groupLookup.put(notif.getAvatarOwnerUniqueId(), null); break; default: int makeCheckstyleShutUpBecauseTheresNothingToDoHere = 1; } } for (PersonModelView person : personsMapper.execute(new ArrayList(personLookup.keySet()))) { personLookup.put(person.getAccountId(), person); } for (DomainGroupModelView group : groupsMapper.execute(new ArrayList(groupLookup.keySet()))) { groupLookup.put(group.getUniqueId(), group); } for (InAppNotificationDTO notif : results) { AvatarEntity entity = null; switch (notif.getAvatarOwnerType()) { case PERSON: entity = personLookup.get(notif.getAvatarOwnerUniqueId()); break; case GROUP: entity = groupLookup.get(notif.getAvatarOwnerUniqueId()); break; default: int makeCheckstyleShutUpBecauseTheresNothingToDoHere = 1; } if (entity != null && entity.getAvatarId() != null) { notif.setAvatarId(entity.getAvatarId()); } } log.trace("Found {} notifications for user {}", results.size(), userId); return new ArrayList(results); } GetInAppNotificationsExecution(final BaseArgDomainMapper<Long, List<InAppNotificationDTO>> inAlertMapper,
            final GetItemsByPointerIdsMapper<String, PersonModelView> inPersonsMapper,
            final GetItemsByPointerIds<DomainGroupModelView> inGroupsMapper,
            final Map<NotificationType, String> inNotificationTypeCategories); }
GetInAppNotificationsExecution implements ExecutionStrategy<PrincipalActionContext> { @Override @SuppressWarnings("unchecked") public Serializable execute(final PrincipalActionContext inActionContext) { long userId = inActionContext.getPrincipal().getId(); List<InAppNotificationDTO> results = alertMapper.execute(userId); if (results.isEmpty()) { return (Serializable) Collections.EMPTY_LIST; } for (InAppNotificationDTO item : results) { item.setFilterCategory(notificationTypeToCategory.get(item.getNotificationType())); } Map<String, PersonModelView> personLookup = new HashMap<String, PersonModelView>(); Map<String, DomainGroupModelView> groupLookup = new HashMap<String, DomainGroupModelView>(); for (InAppNotificationDTO notif : results) { switch (notif.getAvatarOwnerType()) { case PERSON: personLookup.put(notif.getAvatarOwnerUniqueId(), null); break; case GROUP: groupLookup.put(notif.getAvatarOwnerUniqueId(), null); break; default: int makeCheckstyleShutUpBecauseTheresNothingToDoHere = 1; } } for (PersonModelView person : personsMapper.execute(new ArrayList(personLookup.keySet()))) { personLookup.put(person.getAccountId(), person); } for (DomainGroupModelView group : groupsMapper.execute(new ArrayList(groupLookup.keySet()))) { groupLookup.put(group.getUniqueId(), group); } for (InAppNotificationDTO notif : results) { AvatarEntity entity = null; switch (notif.getAvatarOwnerType()) { case PERSON: entity = personLookup.get(notif.getAvatarOwnerUniqueId()); break; case GROUP: entity = groupLookup.get(notif.getAvatarOwnerUniqueId()); break; default: int makeCheckstyleShutUpBecauseTheresNothingToDoHere = 1; } if (entity != null && entity.getAvatarId() != null) { notif.setAvatarId(entity.getAvatarId()); } } log.trace("Found {} notifications for user {}", results.size(), userId); return new ArrayList(results); } GetInAppNotificationsExecution(final BaseArgDomainMapper<Long, List<InAppNotificationDTO>> inAlertMapper,
            final GetItemsByPointerIdsMapper<String, PersonModelView> inPersonsMapper,
            final GetItemsByPointerIds<DomainGroupModelView> inGroupsMapper,
            final Map<NotificationType, String> inNotificationTypeCategories); @Override @SuppressWarnings("unchecked") Serializable execute(final PrincipalActionContext inActionContext); }
GetInAppNotificationsExecution implements ExecutionStrategy<PrincipalActionContext> { @Override @SuppressWarnings("unchecked") public Serializable execute(final PrincipalActionContext inActionContext) { long userId = inActionContext.getPrincipal().getId(); List<InAppNotificationDTO> results = alertMapper.execute(userId); if (results.isEmpty()) { return (Serializable) Collections.EMPTY_LIST; } for (InAppNotificationDTO item : results) { item.setFilterCategory(notificationTypeToCategory.get(item.getNotificationType())); } Map<String, PersonModelView> personLookup = new HashMap<String, PersonModelView>(); Map<String, DomainGroupModelView> groupLookup = new HashMap<String, DomainGroupModelView>(); for (InAppNotificationDTO notif : results) { switch (notif.getAvatarOwnerType()) { case PERSON: personLookup.put(notif.getAvatarOwnerUniqueId(), null); break; case GROUP: groupLookup.put(notif.getAvatarOwnerUniqueId(), null); break; default: int makeCheckstyleShutUpBecauseTheresNothingToDoHere = 1; } } for (PersonModelView person : personsMapper.execute(new ArrayList(personLookup.keySet()))) { personLookup.put(person.getAccountId(), person); } for (DomainGroupModelView group : groupsMapper.execute(new ArrayList(groupLookup.keySet()))) { groupLookup.put(group.getUniqueId(), group); } for (InAppNotificationDTO notif : results) { AvatarEntity entity = null; switch (notif.getAvatarOwnerType()) { case PERSON: entity = personLookup.get(notif.getAvatarOwnerUniqueId()); break; case GROUP: entity = groupLookup.get(notif.getAvatarOwnerUniqueId()); break; default: int makeCheckstyleShutUpBecauseTheresNothingToDoHere = 1; } if (entity != null && entity.getAvatarId() != null) { notif.setAvatarId(entity.getAvatarId()); } } log.trace("Found {} notifications for user {}", results.size(), userId); return new ArrayList(results); } GetInAppNotificationsExecution(final BaseArgDomainMapper<Long, List<InAppNotificationDTO>> inAlertMapper,
            final GetItemsByPointerIdsMapper<String, PersonModelView> inPersonsMapper,
            final GetItemsByPointerIds<DomainGroupModelView> inGroupsMapper,
            final Map<NotificationType, String> inNotificationTypeCategories); @Override @SuppressWarnings("unchecked") Serializable execute(final PrincipalActionContext inActionContext);  }