@Test public void testExecuteWhenFoundAndNoSharersOrLikersWithNullDtoIdLists() { final SharedResourceDTO dto = new SharedResourceDTO(); dto.setLikerPersonIds(null); dto.setSharerPersonIds(null); context.checking(new Expectations() { { oneOf(mapper).execute(request); will(returnValue(dto)); } }); sut.execute(actionContext); Assert.assertEquals(0, dto.getLikerPersonIds().size()); Assert.assertEquals(0, dto.getSharerPersonIds().size()); Assert.assertEquals(0, dto.getSharersSample().size()); Assert.assertEquals(0, dto.getSharersSample().size()); Assert.assertFalse(dto.isLiked()); Assert.assertEquals(0, dto.getLikeCount()); Assert.assertEquals(0, dto.getShareCount()); context.assertIsSatisfied(); }
@Override public Serializable execute(final PrincipalActionContext inActionContext) throws ExecutionException { SharedResourceRequest request = (SharedResourceRequest) inActionContext.getParams(); Long currentUserPersonId = inActionContext.getPrincipal().getId(); log.info("Searching for the cacheable component of the SharedResourceDTO"); SharedResourceDTO dto = mapper.execute(request); if (dto.getLikerPersonIds() == null) { dto.setLikerPersonIds(new ArrayList<Long>()); } if (dto.getSharerPersonIds() == null) { dto.setSharerPersonIds(new ArrayList<Long>()); } dto.setSharersSample(new ArrayList<PersonModelView>()); dto.setLikersSample(new ArrayList<PersonModelView>()); log.info("Now customizing the SharedResourceDTO with info about the current user, and include avatar info"); dto.setIsLiked(dto.getLikerPersonIds().contains(currentUserPersonId)); List<Long> sharedPersonIds = dto.getSharerPersonIds(); List<Long> likedPersonIds = dto.getLikerPersonIds(); if (sharedPersonIds.size() > 4) { sharedPersonIds = sharedPersonIds.subList(0, 4); } if (likedPersonIds.size() > 4) { likedPersonIds = likedPersonIds.subList(0, 4); } List<Long> personIds = new ArrayList<Long>(); personIds.addAll(sharedPersonIds); for (long id : likedPersonIds) { if (!personIds.contains(id)) { personIds.add(id); } } if (personIds.size() > 0) { List<PersonModelView> people = getPeopleModelViewsByIdsMapper.execute(personIds); PersonModelView foundPerson; for (long personId : personIds) { foundPerson = findPersonInList(people, personId); if (foundPerson != null) { if (likedPersonIds.contains(personId)) { dto.getLikersSample().add(foundPerson); } if (sharedPersonIds.contains(personId)) { dto.getSharersSample().add(foundPerson); } } } } return dto; }
GetSharedResourcePropertiesExecution implements ExecutionStrategy<PrincipalActionContext> { @Override public Serializable execute(final PrincipalActionContext inActionContext) throws ExecutionException { SharedResourceRequest request = (SharedResourceRequest) inActionContext.getParams(); Long currentUserPersonId = inActionContext.getPrincipal().getId(); log.info("Searching for the cacheable component of the SharedResourceDTO"); SharedResourceDTO dto = mapper.execute(request); if (dto.getLikerPersonIds() == null) { dto.setLikerPersonIds(new ArrayList<Long>()); } if (dto.getSharerPersonIds() == null) { dto.setSharerPersonIds(new ArrayList<Long>()); } dto.setSharersSample(new ArrayList<PersonModelView>()); dto.setLikersSample(new ArrayList<PersonModelView>()); log.info("Now customizing the SharedResourceDTO with info about the current user, and include avatar info"); dto.setIsLiked(dto.getLikerPersonIds().contains(currentUserPersonId)); List<Long> sharedPersonIds = dto.getSharerPersonIds(); List<Long> likedPersonIds = dto.getLikerPersonIds(); if (sharedPersonIds.size() > 4) { sharedPersonIds = sharedPersonIds.subList(0, 4); } if (likedPersonIds.size() > 4) { likedPersonIds = likedPersonIds.subList(0, 4); } List<Long> personIds = new ArrayList<Long>(); personIds.addAll(sharedPersonIds); for (long id : likedPersonIds) { if (!personIds.contains(id)) { personIds.add(id); } } if (personIds.size() > 0) { List<PersonModelView> people = getPeopleModelViewsByIdsMapper.execute(personIds); PersonModelView foundPerson; for (long personId : personIds) { foundPerson = findPersonInList(people, personId); if (foundPerson != null) { if (likedPersonIds.contains(personId)) { dto.getLikersSample().add(foundPerson); } if (sharedPersonIds.contains(personId)) { dto.getSharersSample().add(foundPerson); } } } } return dto; } }
GetSharedResourcePropertiesExecution implements ExecutionStrategy<PrincipalActionContext> { @Override public Serializable execute(final PrincipalActionContext inActionContext) throws ExecutionException { SharedResourceRequest request = (SharedResourceRequest) inActionContext.getParams(); Long currentUserPersonId = inActionContext.getPrincipal().getId(); log.info("Searching for the cacheable component of the SharedResourceDTO"); SharedResourceDTO dto = mapper.execute(request); if (dto.getLikerPersonIds() == null) { dto.setLikerPersonIds(new ArrayList<Long>()); } if (dto.getSharerPersonIds() == null) { dto.setSharerPersonIds(new ArrayList<Long>()); } dto.setSharersSample(new ArrayList<PersonModelView>()); dto.setLikersSample(new ArrayList<PersonModelView>()); log.info("Now customizing the SharedResourceDTO with info about the current user, and include avatar info"); dto.setIsLiked(dto.getLikerPersonIds().contains(currentUserPersonId)); List<Long> sharedPersonIds = dto.getSharerPersonIds(); List<Long> likedPersonIds = dto.getLikerPersonIds(); if (sharedPersonIds.size() > 4) { sharedPersonIds = sharedPersonIds.subList(0, 4); } if (likedPersonIds.size() > 4) { likedPersonIds = likedPersonIds.subList(0, 4); } List<Long> personIds = new ArrayList<Long>(); personIds.addAll(sharedPersonIds); for (long id : likedPersonIds) { if (!personIds.contains(id)) { personIds.add(id); } } if (personIds.size() > 0) { List<PersonModelView> people = getPeopleModelViewsByIdsMapper.execute(personIds); PersonModelView foundPerson; for (long personId : personIds) { foundPerson = findPersonInList(people, personId); if (foundPerson != null) { if (likedPersonIds.contains(personId)) { dto.getLikersSample().add(foundPerson); } if (sharedPersonIds.contains(personId)) { dto.getSharersSample().add(foundPerson); } } } } return dto; } GetSharedResourcePropertiesExecution(final DomainMapper<SharedResourceRequest, SharedResourceDTO> inMapper,
            final DomainMapper<List<Long>, List<PersonModelView>> inGetPeopleModelViewsByIdsMapper); }
GetSharedResourcePropertiesExecution implements ExecutionStrategy<PrincipalActionContext> { @Override public Serializable execute(final PrincipalActionContext inActionContext) throws ExecutionException { SharedResourceRequest request = (SharedResourceRequest) inActionContext.getParams(); Long currentUserPersonId = inActionContext.getPrincipal().getId(); log.info("Searching for the cacheable component of the SharedResourceDTO"); SharedResourceDTO dto = mapper.execute(request); if (dto.getLikerPersonIds() == null) { dto.setLikerPersonIds(new ArrayList<Long>()); } if (dto.getSharerPersonIds() == null) { dto.setSharerPersonIds(new ArrayList<Long>()); } dto.setSharersSample(new ArrayList<PersonModelView>()); dto.setLikersSample(new ArrayList<PersonModelView>()); log.info("Now customizing the SharedResourceDTO with info about the current user, and include avatar info"); dto.setIsLiked(dto.getLikerPersonIds().contains(currentUserPersonId)); List<Long> sharedPersonIds = dto.getSharerPersonIds(); List<Long> likedPersonIds = dto.getLikerPersonIds(); if (sharedPersonIds.size() > 4) { sharedPersonIds = sharedPersonIds.subList(0, 4); } if (likedPersonIds.size() > 4) { likedPersonIds = likedPersonIds.subList(0, 4); } List<Long> personIds = new ArrayList<Long>(); personIds.addAll(sharedPersonIds); for (long id : likedPersonIds) { if (!personIds.contains(id)) { personIds.add(id); } } if (personIds.size() > 0) { List<PersonModelView> people = getPeopleModelViewsByIdsMapper.execute(personIds); PersonModelView foundPerson; for (long personId : personIds) { foundPerson = findPersonInList(people, personId); if (foundPerson != null) { if (likedPersonIds.contains(personId)) { dto.getLikersSample().add(foundPerson); } if (sharedPersonIds.contains(personId)) { dto.getSharersSample().add(foundPerson); } } } } return dto; } GetSharedResourcePropertiesExecution(final DomainMapper<SharedResourceRequest, SharedResourceDTO> inMapper,
            final DomainMapper<List<Long>, List<PersonModelView>> inGetPeopleModelViewsByIdsMapper); @Override Serializable execute(final PrincipalActionContext inActionContext); }
GetSharedResourcePropertiesExecution implements ExecutionStrategy<PrincipalActionContext> { @Override public Serializable execute(final PrincipalActionContext inActionContext) throws ExecutionException { SharedResourceRequest request = (SharedResourceRequest) inActionContext.getParams(); Long currentUserPersonId = inActionContext.getPrincipal().getId(); log.info("Searching for the cacheable component of the SharedResourceDTO"); SharedResourceDTO dto = mapper.execute(request); if (dto.getLikerPersonIds() == null) { dto.setLikerPersonIds(new ArrayList<Long>()); } if (dto.getSharerPersonIds() == null) { dto.setSharerPersonIds(new ArrayList<Long>()); } dto.setSharersSample(new ArrayList<PersonModelView>()); dto.setLikersSample(new ArrayList<PersonModelView>()); log.info("Now customizing the SharedResourceDTO with info about the current user, and include avatar info"); dto.setIsLiked(dto.getLikerPersonIds().contains(currentUserPersonId)); List<Long> sharedPersonIds = dto.getSharerPersonIds(); List<Long> likedPersonIds = dto.getLikerPersonIds(); if (sharedPersonIds.size() > 4) { sharedPersonIds = sharedPersonIds.subList(0, 4); } if (likedPersonIds.size() > 4) { likedPersonIds = likedPersonIds.subList(0, 4); } List<Long> personIds = new ArrayList<Long>(); personIds.addAll(sharedPersonIds); for (long id : likedPersonIds) { if (!personIds.contains(id)) { personIds.add(id); } } if (personIds.size() > 0) { List<PersonModelView> people = getPeopleModelViewsByIdsMapper.execute(personIds); PersonModelView foundPerson; for (long personId : personIds) { foundPerson = findPersonInList(people, personId); if (foundPerson != null) { if (likedPersonIds.contains(personId)) { dto.getLikersSample().add(foundPerson); } if (sharedPersonIds.contains(personId)) { dto.getSharersSample().add(foundPerson); } } } } return dto; } GetSharedResourcePropertiesExecution(final DomainMapper<SharedResourceRequest, SharedResourceDTO> inMapper,
            final DomainMapper<List<Long>, List<PersonModelView>> inGetPeopleModelViewsByIdsMapper); @Override Serializable execute(final PrincipalActionContext inActionContext);  }