@Test public void testFilter() { final StreamEntityDTO e1 = context.mock(StreamEntityDTO.class, "e1"); final StreamEntityDTO e2 = context.mock(StreamEntityDTO.class, "e2"); final StreamEntityDTO e3 = context.mock(StreamEntityDTO.class, "e3"); final StreamEntityDTO e1o = context.mock(StreamEntityDTO.class, "e1o"); final StreamEntityDTO e3o = context.mock(StreamEntityDTO.class, "e3o"); final ActivityDTO a1 = context.mock(ActivityDTO.class, "a1"); final ActivityDTO a2 = context.mock(ActivityDTO.class, "a2"); final ActivityDTO a3 = context.mock(ActivityDTO.class, "a3"); final PersonModelView p7 = context.mock(PersonModelView.class, "p7"); final PersonModelView p8 = context.mock(PersonModelView.class, "p8"); final PersonModelView p9 = context.mock(PersonModelView.class, "p9"); context.checking(new Expectations() { { allowing(a1).getActor(); will(returnValue(e1)); allowing(a1).getOriginalActor(); will(returnValue(e1o)); allowing(e1).getId(); will(returnValue(7L)); allowing(e1).getType(); will(returnValue(EntityType.PERSON)); allowing(e1o).getType(); will(returnValue(EntityType.GROUP)); allowing(a2).getActor(); will(returnValue(e2)); allowing(a2).getOriginalActor(); will(returnValue(null)); allowing(e2).getType(); will(returnValue(EntityType.GROUP)); allowing(a3).getActor(); will(returnValue(e3)); allowing(a3).getOriginalActor(); will(returnValue(e3o)); allowing(e3).getId(); will(returnValue(8L)); allowing(e3).getType(); will(returnValue(EntityType.PERSON)); allowing(e3o).getId(); will(returnValue(9L)); allowing(e3o).getType(); will(returnValue(EntityType.PERSON)); allowing(p7).getId(); will(returnValue(7L)); allowing(p7).isAccountLocked(); will(returnValue(true)); allowing(p8).getId(); will(returnValue(8L)); allowing(p8).isAccountLocked(); will(returnValue(false)); allowing(p9).getId(); will(returnValue(9L)); allowing(p9).isAccountLocked(); will(returnValue(false)); oneOf(personMapper).execute(with(new EasyMatcher<List<Long>>() { @Override protected boolean isMatch(final List<Long> inTestObject) { return inTestObject.size() == 3 && inTestObject.contains(7L) && inTestObject.contains(8L) && inTestObject.contains(9L); } })); will(returnValue(Arrays.asList(p7, p8, p9))); oneOf(e1).setActive(false); oneOf(e3).setActive(true); oneOf(e3o).setActive(true); } }); sut.filter(Arrays.asList(a1, a2, a3), null); context.assertIsSatisfied(); }
@Override public void filter(final List<ActivityDTO> inActivities, final PersonModelView inCurrentUserAccount) { if (inActivities.isEmpty()) { return; } Set<Long> ids = new HashSet<Long>(); for (ActivityDTO activity : inActivities) { if (activity.getActor().getType() == EntityType.PERSON) { ids.add(activity.getActor().getId()); } if (activity.getOriginalActor() != null && activity.getOriginalActor().getType() == EntityType.PERSON) { ids.add(activity.getOriginalActor().getId()); } } List<PersonModelView> peopleList = getPeopleMapper.execute(new ArrayList<Long>(ids)); HashMap<Long, Boolean> peopleIndex = new HashMap<Long, Boolean>(); for (PersonModelView person : peopleList) { peopleIndex.put(person.getId(), person.isAccountLocked()); } for (ActivityDTO activity : inActivities) { if (activity.getActor().getType() == EntityType.PERSON) { activity.getActor().setActive(!peopleIndex.get(activity.getActor().getId())); } if (activity.getOriginalActor() != null && activity.getOriginalActor().getType() == EntityType.PERSON) { activity.getOriginalActor().setActive(!peopleIndex.get(activity.getOriginalActor().getId())); } } }
IsAuthorLockedFilter implements ActivityFilter { @Override public void filter(final List<ActivityDTO> inActivities, final PersonModelView inCurrentUserAccount) { if (inActivities.isEmpty()) { return; } Set<Long> ids = new HashSet<Long>(); for (ActivityDTO activity : inActivities) { if (activity.getActor().getType() == EntityType.PERSON) { ids.add(activity.getActor().getId()); } if (activity.getOriginalActor() != null && activity.getOriginalActor().getType() == EntityType.PERSON) { ids.add(activity.getOriginalActor().getId()); } } List<PersonModelView> peopleList = getPeopleMapper.execute(new ArrayList<Long>(ids)); HashMap<Long, Boolean> peopleIndex = new HashMap<Long, Boolean>(); for (PersonModelView person : peopleList) { peopleIndex.put(person.getId(), person.isAccountLocked()); } for (ActivityDTO activity : inActivities) { if (activity.getActor().getType() == EntityType.PERSON) { activity.getActor().setActive(!peopleIndex.get(activity.getActor().getId())); } if (activity.getOriginalActor() != null && activity.getOriginalActor().getType() == EntityType.PERSON) { activity.getOriginalActor().setActive(!peopleIndex.get(activity.getOriginalActor().getId())); } } } }
IsAuthorLockedFilter implements ActivityFilter { @Override public void filter(final List<ActivityDTO> inActivities, final PersonModelView inCurrentUserAccount) { if (inActivities.isEmpty()) { return; } Set<Long> ids = new HashSet<Long>(); for (ActivityDTO activity : inActivities) { if (activity.getActor().getType() == EntityType.PERSON) { ids.add(activity.getActor().getId()); } if (activity.getOriginalActor() != null && activity.getOriginalActor().getType() == EntityType.PERSON) { ids.add(activity.getOriginalActor().getId()); } } List<PersonModelView> peopleList = getPeopleMapper.execute(new ArrayList<Long>(ids)); HashMap<Long, Boolean> peopleIndex = new HashMap<Long, Boolean>(); for (PersonModelView person : peopleList) { peopleIndex.put(person.getId(), person.isAccountLocked()); } for (ActivityDTO activity : inActivities) { if (activity.getActor().getType() == EntityType.PERSON) { activity.getActor().setActive(!peopleIndex.get(activity.getActor().getId())); } if (activity.getOriginalActor() != null && activity.getOriginalActor().getType() == EntityType.PERSON) { activity.getOriginalActor().setActive(!peopleIndex.get(activity.getOriginalActor().getId())); } } } IsAuthorLockedFilter(final DomainMapper<List<Long>, List<PersonModelView>> inGetPeopleMapper); }
IsAuthorLockedFilter implements ActivityFilter { @Override public void filter(final List<ActivityDTO> inActivities, final PersonModelView inCurrentUserAccount) { if (inActivities.isEmpty()) { return; } Set<Long> ids = new HashSet<Long>(); for (ActivityDTO activity : inActivities) { if (activity.getActor().getType() == EntityType.PERSON) { ids.add(activity.getActor().getId()); } if (activity.getOriginalActor() != null && activity.getOriginalActor().getType() == EntityType.PERSON) { ids.add(activity.getOriginalActor().getId()); } } List<PersonModelView> peopleList = getPeopleMapper.execute(new ArrayList<Long>(ids)); HashMap<Long, Boolean> peopleIndex = new HashMap<Long, Boolean>(); for (PersonModelView person : peopleList) { peopleIndex.put(person.getId(), person.isAccountLocked()); } for (ActivityDTO activity : inActivities) { if (activity.getActor().getType() == EntityType.PERSON) { activity.getActor().setActive(!peopleIndex.get(activity.getActor().getId())); } if (activity.getOriginalActor() != null && activity.getOriginalActor().getType() == EntityType.PERSON) { activity.getOriginalActor().setActive(!peopleIndex.get(activity.getOriginalActor().getId())); } } } IsAuthorLockedFilter(final DomainMapper<List<Long>, List<PersonModelView>> inGetPeopleMapper); @Override void filter(final List<ActivityDTO> inActivities, final PersonModelView inCurrentUserAccount); }
IsAuthorLockedFilter implements ActivityFilter { @Override public void filter(final List<ActivityDTO> inActivities, final PersonModelView inCurrentUserAccount) { if (inActivities.isEmpty()) { return; } Set<Long> ids = new HashSet<Long>(); for (ActivityDTO activity : inActivities) { if (activity.getActor().getType() == EntityType.PERSON) { ids.add(activity.getActor().getId()); } if (activity.getOriginalActor() != null && activity.getOriginalActor().getType() == EntityType.PERSON) { ids.add(activity.getOriginalActor().getId()); } } List<PersonModelView> peopleList = getPeopleMapper.execute(new ArrayList<Long>(ids)); HashMap<Long, Boolean> peopleIndex = new HashMap<Long, Boolean>(); for (PersonModelView person : peopleList) { peopleIndex.put(person.getId(), person.isAccountLocked()); } for (ActivityDTO activity : inActivities) { if (activity.getActor().getType() == EntityType.PERSON) { activity.getActor().setActive(!peopleIndex.get(activity.getActor().getId())); } if (activity.getOriginalActor() != null && activity.getOriginalActor().getType() == EntityType.PERSON) { activity.getOriginalActor().setActive(!peopleIndex.get(activity.getOriginalActor().getId())); } } } IsAuthorLockedFilter(final DomainMapper<List<Long>, List<PersonModelView>> inGetPeopleMapper); @Override void filter(final List<ActivityDTO> inActivities, final PersonModelView inCurrentUserAccount);  }