@Test public void test() { Long personId = 392L; String personDisplayName = "personDisplayName"; String personAvatarId = "personAvatarId"; Long groupId = 989L; String groupDisplayName = "groupDisplayName"; String groupAvatarId = "groupAvatarId"; FeaturedStreamDTO personStream = new FeaturedStreamDTO(); FeaturedStreamDTO groupStream = new FeaturedStreamDTO(); personStream.setStreamType(ScopeType.PERSON); personStream.setStreamEntityId(personId); personStream.setStreamUniqueKey("personA"); groupStream.setStreamType(ScopeType.GROUP); groupStream.setStreamEntityId(groupId); groupStream.setStreamUniqueKey("groupA"); final PersonModelView p = new PersonModelView(); p.setEntityId(personId); p.setDisplayName(personDisplayName); p.setAvatarId("personAvatarId"); p.setAccountId("personA"); final DomainGroupModelView g = new DomainGroupModelView(); g.setEntityId(groupId); g.setName(groupDisplayName); g.setAvatarId(groupAvatarId); g.setShortName("groupA"); final List<DisplayInfoSettable> fsList = new ArrayList<DisplayInfoSettable>(Arrays.asList(personStream, groupStream)); context.checking(new Expectations() { { oneOf(getPersonModelViewsByIdsMapper).execute(with(any(List.class))); will(returnValue(new ArrayList<PersonModelView>(Arrays.asList(p)))); oneOf(getGroupModelViewsByIdsMapper).execute(with(any(List.class))); will(returnValue(new ArrayList<DomainGroupModelView>(Arrays.asList(g)))); } }); List<DisplayInfoSettable> results = sut.execute(fsList); assertEquals(2, results.size()); assertEquals(personDisplayName, results.get(0).getDisplayName()); assertEquals(personAvatarId, ((FeaturedStreamDTO) results.get(0)).getAvatarId()); assertEquals(groupDisplayName, results.get(1).getDisplayName()); assertEquals(groupAvatarId, ((FeaturedStreamDTO) results.get(1)).getAvatarId()); context.assertIsSatisfied(); }
public List<DisplayInfoSettable> execute(final List<DisplayInfoSettable> inDisplaySettables) { List<Long> personIds = new ArrayList<Long>(); List<Long> groupIds = new ArrayList<Long>(); Long id; for (DisplayInfoSettable ds : inDisplaySettables) { id = ds.getEntityId(); switch (ds.getEntityType()) { case PERSON: if (!personIds.contains(id)) { personIds.add(id); } break; case GROUP: if (!groupIds.contains(id)) { groupIds.add(id); } break; default: break; } } List<PersonModelView> personDTOs = getPersonModelViewsByIdsMapper.execute(personIds); List<DomainGroupModelView> groupDTOs = getGroupModelViewsByIdsMapper.execute(groupIds); Map<String, PersonModelView> peopleByAccountIdsMap = new HashMap<String, PersonModelView>(); Map<String, DomainGroupModelView> domainGroupsByShortNamesMap = new HashMap<String, DomainGroupModelView>(); for (PersonModelView person : personDTOs) { peopleByAccountIdsMap.put(person.getAccountId(), person); } for (DomainGroupModelView domainGroup : groupDTOs) { domainGroupsByShortNamesMap.put(domainGroup.getShortName(), domainGroup); } PersonModelView pmv; DomainGroupModelView gmv; for (DisplayInfoSettable ds : inDisplaySettables) { if (ds.getEntityType() == EntityType.PERSON) { pmv = peopleByAccountIdsMap.get(ds.getStreamUniqueKey()); if (pmv != null) { ds.setAvatarId(pmv.getAvatarId()); ds.setDisplayName(pmv.getDisplayName()); } } else if (ds.getEntityType() == EntityType.GROUP) { gmv = domainGroupsByShortNamesMap.get(ds.getStreamUniqueKey()); if (gmv != null) { ds.setAvatarId(gmv.getAvatarId()); ds.setDisplayName(gmv.getDisplayName()); } } } return inDisplaySettables; }
DisplayInfoSettableDataPopulator implements
        DomainMapper<List<DisplayInfoSettable>, List<DisplayInfoSettable>> { public List<DisplayInfoSettable> execute(final List<DisplayInfoSettable> inDisplaySettables) { List<Long> personIds = new ArrayList<Long>(); List<Long> groupIds = new ArrayList<Long>(); Long id; for (DisplayInfoSettable ds : inDisplaySettables) { id = ds.getEntityId(); switch (ds.getEntityType()) { case PERSON: if (!personIds.contains(id)) { personIds.add(id); } break; case GROUP: if (!groupIds.contains(id)) { groupIds.add(id); } break; default: break; } } List<PersonModelView> personDTOs = getPersonModelViewsByIdsMapper.execute(personIds); List<DomainGroupModelView> groupDTOs = getGroupModelViewsByIdsMapper.execute(groupIds); Map<String, PersonModelView> peopleByAccountIdsMap = new HashMap<String, PersonModelView>(); Map<String, DomainGroupModelView> domainGroupsByShortNamesMap = new HashMap<String, DomainGroupModelView>(); for (PersonModelView person : personDTOs) { peopleByAccountIdsMap.put(person.getAccountId(), person); } for (DomainGroupModelView domainGroup : groupDTOs) { domainGroupsByShortNamesMap.put(domainGroup.getShortName(), domainGroup); } PersonModelView pmv; DomainGroupModelView gmv; for (DisplayInfoSettable ds : inDisplaySettables) { if (ds.getEntityType() == EntityType.PERSON) { pmv = peopleByAccountIdsMap.get(ds.getStreamUniqueKey()); if (pmv != null) { ds.setAvatarId(pmv.getAvatarId()); ds.setDisplayName(pmv.getDisplayName()); } } else if (ds.getEntityType() == EntityType.GROUP) { gmv = domainGroupsByShortNamesMap.get(ds.getStreamUniqueKey()); if (gmv != null) { ds.setAvatarId(gmv.getAvatarId()); ds.setDisplayName(gmv.getDisplayName()); } } } return inDisplaySettables; } }
DisplayInfoSettableDataPopulator implements
        DomainMapper<List<DisplayInfoSettable>, List<DisplayInfoSettable>> { public List<DisplayInfoSettable> execute(final List<DisplayInfoSettable> inDisplaySettables) { List<Long> personIds = new ArrayList<Long>(); List<Long> groupIds = new ArrayList<Long>(); Long id; for (DisplayInfoSettable ds : inDisplaySettables) { id = ds.getEntityId(); switch (ds.getEntityType()) { case PERSON: if (!personIds.contains(id)) { personIds.add(id); } break; case GROUP: if (!groupIds.contains(id)) { groupIds.add(id); } break; default: break; } } List<PersonModelView> personDTOs = getPersonModelViewsByIdsMapper.execute(personIds); List<DomainGroupModelView> groupDTOs = getGroupModelViewsByIdsMapper.execute(groupIds); Map<String, PersonModelView> peopleByAccountIdsMap = new HashMap<String, PersonModelView>(); Map<String, DomainGroupModelView> domainGroupsByShortNamesMap = new HashMap<String, DomainGroupModelView>(); for (PersonModelView person : personDTOs) { peopleByAccountIdsMap.put(person.getAccountId(), person); } for (DomainGroupModelView domainGroup : groupDTOs) { domainGroupsByShortNamesMap.put(domainGroup.getShortName(), domainGroup); } PersonModelView pmv; DomainGroupModelView gmv; for (DisplayInfoSettable ds : inDisplaySettables) { if (ds.getEntityType() == EntityType.PERSON) { pmv = peopleByAccountIdsMap.get(ds.getStreamUniqueKey()); if (pmv != null) { ds.setAvatarId(pmv.getAvatarId()); ds.setDisplayName(pmv.getDisplayName()); } } else if (ds.getEntityType() == EntityType.GROUP) { gmv = domainGroupsByShortNamesMap.get(ds.getStreamUniqueKey()); if (gmv != null) { ds.setAvatarId(gmv.getAvatarId()); ds.setDisplayName(gmv.getDisplayName()); } } } return inDisplaySettables; } DisplayInfoSettableDataPopulator(
            final DomainMapper<List<Long>, List<PersonModelView>> inGetPersonModelViewsByIdsMapper,
            final DomainMapper<List<Long>, List<DomainGroupModelView>> inGetGroupModelViewsByIdsMapper); }
DisplayInfoSettableDataPopulator implements
        DomainMapper<List<DisplayInfoSettable>, List<DisplayInfoSettable>> { public List<DisplayInfoSettable> execute(final List<DisplayInfoSettable> inDisplaySettables) { List<Long> personIds = new ArrayList<Long>(); List<Long> groupIds = new ArrayList<Long>(); Long id; for (DisplayInfoSettable ds : inDisplaySettables) { id = ds.getEntityId(); switch (ds.getEntityType()) { case PERSON: if (!personIds.contains(id)) { personIds.add(id); } break; case GROUP: if (!groupIds.contains(id)) { groupIds.add(id); } break; default: break; } } List<PersonModelView> personDTOs = getPersonModelViewsByIdsMapper.execute(personIds); List<DomainGroupModelView> groupDTOs = getGroupModelViewsByIdsMapper.execute(groupIds); Map<String, PersonModelView> peopleByAccountIdsMap = new HashMap<String, PersonModelView>(); Map<String, DomainGroupModelView> domainGroupsByShortNamesMap = new HashMap<String, DomainGroupModelView>(); for (PersonModelView person : personDTOs) { peopleByAccountIdsMap.put(person.getAccountId(), person); } for (DomainGroupModelView domainGroup : groupDTOs) { domainGroupsByShortNamesMap.put(domainGroup.getShortName(), domainGroup); } PersonModelView pmv; DomainGroupModelView gmv; for (DisplayInfoSettable ds : inDisplaySettables) { if (ds.getEntityType() == EntityType.PERSON) { pmv = peopleByAccountIdsMap.get(ds.getStreamUniqueKey()); if (pmv != null) { ds.setAvatarId(pmv.getAvatarId()); ds.setDisplayName(pmv.getDisplayName()); } } else if (ds.getEntityType() == EntityType.GROUP) { gmv = domainGroupsByShortNamesMap.get(ds.getStreamUniqueKey()); if (gmv != null) { ds.setAvatarId(gmv.getAvatarId()); ds.setDisplayName(gmv.getDisplayName()); } } } return inDisplaySettables; } DisplayInfoSettableDataPopulator(
            final DomainMapper<List<Long>, List<PersonModelView>> inGetPersonModelViewsByIdsMapper,
            final DomainMapper<List<Long>, List<DomainGroupModelView>> inGetGroupModelViewsByIdsMapper); List<DisplayInfoSettable> execute(final List<DisplayInfoSettable> inDisplaySettables); }
DisplayInfoSettableDataPopulator implements
        DomainMapper<List<DisplayInfoSettable>, List<DisplayInfoSettable>> { public List<DisplayInfoSettable> execute(final List<DisplayInfoSettable> inDisplaySettables) { List<Long> personIds = new ArrayList<Long>(); List<Long> groupIds = new ArrayList<Long>(); Long id; for (DisplayInfoSettable ds : inDisplaySettables) { id = ds.getEntityId(); switch (ds.getEntityType()) { case PERSON: if (!personIds.contains(id)) { personIds.add(id); } break; case GROUP: if (!groupIds.contains(id)) { groupIds.add(id); } break; default: break; } } List<PersonModelView> personDTOs = getPersonModelViewsByIdsMapper.execute(personIds); List<DomainGroupModelView> groupDTOs = getGroupModelViewsByIdsMapper.execute(groupIds); Map<String, PersonModelView> peopleByAccountIdsMap = new HashMap<String, PersonModelView>(); Map<String, DomainGroupModelView> domainGroupsByShortNamesMap = new HashMap<String, DomainGroupModelView>(); for (PersonModelView person : personDTOs) { peopleByAccountIdsMap.put(person.getAccountId(), person); } for (DomainGroupModelView domainGroup : groupDTOs) { domainGroupsByShortNamesMap.put(domainGroup.getShortName(), domainGroup); } PersonModelView pmv; DomainGroupModelView gmv; for (DisplayInfoSettable ds : inDisplaySettables) { if (ds.getEntityType() == EntityType.PERSON) { pmv = peopleByAccountIdsMap.get(ds.getStreamUniqueKey()); if (pmv != null) { ds.setAvatarId(pmv.getAvatarId()); ds.setDisplayName(pmv.getDisplayName()); } } else if (ds.getEntityType() == EntityType.GROUP) { gmv = domainGroupsByShortNamesMap.get(ds.getStreamUniqueKey()); if (gmv != null) { ds.setAvatarId(gmv.getAvatarId()); ds.setDisplayName(gmv.getDisplayName()); } } } return inDisplaySettables; } DisplayInfoSettableDataPopulator(
            final DomainMapper<List<Long>, List<PersonModelView>> inGetPersonModelViewsByIdsMapper,
            final DomainMapper<List<Long>, List<DomainGroupModelView>> inGetGroupModelViewsByIdsMapper); List<DisplayInfoSettable> execute(final List<DisplayInfoSettable> inDisplaySettables);  }