@Test public void testRemoveFollowing() throws Exception { final String followerAccountId = "ntAccount"; final String followedAccountId = "followingntaccount"; final Long followerId = 1L; final Long followedId = 2L; final List<Long> targetFollowerIds = new ArrayList<Long>(5); context.checking(new Expectations() { { oneOf(getPersonIdByAccountIdMapper).execute(followerAccountId); will(returnValue(followerId)); oneOf(getPersonIdByAccountIdMapper).execute(followedAccountId); will(returnValue(followedId)); oneOf(personMapperMock).removeFollower(1L, 2L); oneOf(followerIdsMapperMock).execute(2L); will(returnValue(targetFollowerIds)); } }); SetFollowingStatusRequest currentRequest = new SetFollowingStatusRequest(followerAccountId, followedAccountId, EntityType.PERSON, false, Follower.FollowerStatus.NOTFOLLOWING); sut.execute(TestContextCreator.createTaskHandlerContextWithPrincipal(currentRequest, principalMock)); context.assertIsSatisfied(); }
@Override public Serializable execute(final TaskHandlerActionContext<PrincipalActionContext> inActionContext) throws ExecutionException { SetFollowingStatusRequest request = (SetFollowingStatusRequest) inActionContext.getActionContext().getParams(); if (logger.isTraceEnabled()) { logger.trace("Entering follow person strategy with followerid: " + request.getFollowerUniqueId() + " targetid: " + request.getTargetUniqueId() + " and status " + request.getFollowerStatus()); } List<UserActionRequest> asyncRequests = inActionContext.getUserActionRequests(); int followingCount; Long followerPersonId; Long followedPersonId = getPersonIdByAccountIdMapper.execute(request.getTargetUniqueId()); if (request.getFollowerUniqueId() == null || request.getFollowerUniqueId() == "") { followerPersonId = inActionContext.getActionContext().getPrincipal().getId(); } else { followerPersonId = getPersonIdByAccountIdMapper.execute(request.getFollowerUniqueId()); } switch (request.getFollowerStatus()) { case FOLLOWING: logger.trace("Add new following to the list of following."); mapper.addFollower(followerPersonId, followedPersonId); addCachedFollowerMapper.execute(followerPersonId, followedPersonId); asyncRequests.add(new UserActionRequest("deleteCacheKeysAction", null, (Serializable) Collections .singleton(CacheKeys.PERSON_BY_ID + followedPersonId))); logger.trace("Submit async action to update all cached activities."); asyncRequests.add(new UserActionRequest("refreshFollowedByActivities", null, followerPersonId)); asyncRequests .add(new UserActionRequest(CreateNotificationsRequest.ACTION_NAME, null, new TargetEntityNotificationsRequest(RequestType.FOLLOW_PERSON, followerPersonId, followedPersonId))); break; case NOTFOLLOWING: logger.trace("Remove new following from the list of following."); mapper.removeFollower(followerPersonId, followedPersonId); asyncRequests.add(new UserActionRequest("deleteCacheKeysAction", null, (Serializable) Collections .singleton(CacheKeys.PERSON_BY_ID + followedPersonId))); asyncRequests.add(new UserActionRequest("deleteIdsFromLists", null, new DeleteIdsFromListsRequest( Collections.singletonList(CacheKeys.FOLLOWERS_BY_PERSON + followedPersonId), Collections .singletonList(followerPersonId)))); asyncRequests.add(new UserActionRequest("deleteIdsFromLists", null, new DeleteIdsFromListsRequest( Collections.singletonList(CacheKeys.PEOPLE_FOLLOWED_BY_PERSON + followerPersonId), Collections .singletonList(followedPersonId)))); asyncRequests.add(new UserActionRequest("refreshFollowedByActivities", null, followerPersonId)); break; default: } followingCount = followerIdsMapper.execute(followedPersonId).size(); return new Integer(followingCount); }
SetFollowingPersonStatusExecution implements TaskHandlerExecutionStrategy<PrincipalActionContext> { @Override public Serializable execute(final TaskHandlerActionContext<PrincipalActionContext> inActionContext) throws ExecutionException { SetFollowingStatusRequest request = (SetFollowingStatusRequest) inActionContext.getActionContext().getParams(); if (logger.isTraceEnabled()) { logger.trace("Entering follow person strategy with followerid: " + request.getFollowerUniqueId() + " targetid: " + request.getTargetUniqueId() + " and status " + request.getFollowerStatus()); } List<UserActionRequest> asyncRequests = inActionContext.getUserActionRequests(); int followingCount; Long followerPersonId; Long followedPersonId = getPersonIdByAccountIdMapper.execute(request.getTargetUniqueId()); if (request.getFollowerUniqueId() == null || request.getFollowerUniqueId() == "") { followerPersonId = inActionContext.getActionContext().getPrincipal().getId(); } else { followerPersonId = getPersonIdByAccountIdMapper.execute(request.getFollowerUniqueId()); } switch (request.getFollowerStatus()) { case FOLLOWING: logger.trace("Add new following to the list of following."); mapper.addFollower(followerPersonId, followedPersonId); addCachedFollowerMapper.execute(followerPersonId, followedPersonId); asyncRequests.add(new UserActionRequest("deleteCacheKeysAction", null, (Serializable) Collections .singleton(CacheKeys.PERSON_BY_ID + followedPersonId))); logger.trace("Submit async action to update all cached activities."); asyncRequests.add(new UserActionRequest("refreshFollowedByActivities", null, followerPersonId)); asyncRequests .add(new UserActionRequest(CreateNotificationsRequest.ACTION_NAME, null, new TargetEntityNotificationsRequest(RequestType.FOLLOW_PERSON, followerPersonId, followedPersonId))); break; case NOTFOLLOWING: logger.trace("Remove new following from the list of following."); mapper.removeFollower(followerPersonId, followedPersonId); asyncRequests.add(new UserActionRequest("deleteCacheKeysAction", null, (Serializable) Collections .singleton(CacheKeys.PERSON_BY_ID + followedPersonId))); asyncRequests.add(new UserActionRequest("deleteIdsFromLists", null, new DeleteIdsFromListsRequest( Collections.singletonList(CacheKeys.FOLLOWERS_BY_PERSON + followedPersonId), Collections .singletonList(followerPersonId)))); asyncRequests.add(new UserActionRequest("deleteIdsFromLists", null, new DeleteIdsFromListsRequest( Collections.singletonList(CacheKeys.PEOPLE_FOLLOWED_BY_PERSON + followerPersonId), Collections .singletonList(followedPersonId)))); asyncRequests.add(new UserActionRequest("refreshFollowedByActivities", null, followerPersonId)); break; default: } followingCount = followerIdsMapper.execute(followedPersonId).size(); return new Integer(followingCount); } }
SetFollowingPersonStatusExecution implements TaskHandlerExecutionStrategy<PrincipalActionContext> { @Override public Serializable execute(final TaskHandlerActionContext<PrincipalActionContext> inActionContext) throws ExecutionException { SetFollowingStatusRequest request = (SetFollowingStatusRequest) inActionContext.getActionContext().getParams(); if (logger.isTraceEnabled()) { logger.trace("Entering follow person strategy with followerid: " + request.getFollowerUniqueId() + " targetid: " + request.getTargetUniqueId() + " and status " + request.getFollowerStatus()); } List<UserActionRequest> asyncRequests = inActionContext.getUserActionRequests(); int followingCount; Long followerPersonId; Long followedPersonId = getPersonIdByAccountIdMapper.execute(request.getTargetUniqueId()); if (request.getFollowerUniqueId() == null || request.getFollowerUniqueId() == "") { followerPersonId = inActionContext.getActionContext().getPrincipal().getId(); } else { followerPersonId = getPersonIdByAccountIdMapper.execute(request.getFollowerUniqueId()); } switch (request.getFollowerStatus()) { case FOLLOWING: logger.trace("Add new following to the list of following."); mapper.addFollower(followerPersonId, followedPersonId); addCachedFollowerMapper.execute(followerPersonId, followedPersonId); asyncRequests.add(new UserActionRequest("deleteCacheKeysAction", null, (Serializable) Collections .singleton(CacheKeys.PERSON_BY_ID + followedPersonId))); logger.trace("Submit async action to update all cached activities."); asyncRequests.add(new UserActionRequest("refreshFollowedByActivities", null, followerPersonId)); asyncRequests .add(new UserActionRequest(CreateNotificationsRequest.ACTION_NAME, null, new TargetEntityNotificationsRequest(RequestType.FOLLOW_PERSON, followerPersonId, followedPersonId))); break; case NOTFOLLOWING: logger.trace("Remove new following from the list of following."); mapper.removeFollower(followerPersonId, followedPersonId); asyncRequests.add(new UserActionRequest("deleteCacheKeysAction", null, (Serializable) Collections .singleton(CacheKeys.PERSON_BY_ID + followedPersonId))); asyncRequests.add(new UserActionRequest("deleteIdsFromLists", null, new DeleteIdsFromListsRequest( Collections.singletonList(CacheKeys.FOLLOWERS_BY_PERSON + followedPersonId), Collections .singletonList(followerPersonId)))); asyncRequests.add(new UserActionRequest("deleteIdsFromLists", null, new DeleteIdsFromListsRequest( Collections.singletonList(CacheKeys.PEOPLE_FOLLOWED_BY_PERSON + followerPersonId), Collections .singletonList(followedPersonId)))); asyncRequests.add(new UserActionRequest("refreshFollowedByActivities", null, followerPersonId)); break; default: } followingCount = followerIdsMapper.execute(followedPersonId).size(); return new Integer(followingCount); } SetFollowingPersonStatusExecution(final PersonMapper inMapper,
            final DomainMapper<String, Long> inGetPersonIdByAccountIdMapper,
            final AddCachedPersonFollower inAddCachedFollowerMapper,
            final DomainMapper<Long, List<Long>> inFollowerIdsMapper); }
SetFollowingPersonStatusExecution implements TaskHandlerExecutionStrategy<PrincipalActionContext> { @Override public Serializable execute(final TaskHandlerActionContext<PrincipalActionContext> inActionContext) throws ExecutionException { SetFollowingStatusRequest request = (SetFollowingStatusRequest) inActionContext.getActionContext().getParams(); if (logger.isTraceEnabled()) { logger.trace("Entering follow person strategy with followerid: " + request.getFollowerUniqueId() + " targetid: " + request.getTargetUniqueId() + " and status " + request.getFollowerStatus()); } List<UserActionRequest> asyncRequests = inActionContext.getUserActionRequests(); int followingCount; Long followerPersonId; Long followedPersonId = getPersonIdByAccountIdMapper.execute(request.getTargetUniqueId()); if (request.getFollowerUniqueId() == null || request.getFollowerUniqueId() == "") { followerPersonId = inActionContext.getActionContext().getPrincipal().getId(); } else { followerPersonId = getPersonIdByAccountIdMapper.execute(request.getFollowerUniqueId()); } switch (request.getFollowerStatus()) { case FOLLOWING: logger.trace("Add new following to the list of following."); mapper.addFollower(followerPersonId, followedPersonId); addCachedFollowerMapper.execute(followerPersonId, followedPersonId); asyncRequests.add(new UserActionRequest("deleteCacheKeysAction", null, (Serializable) Collections .singleton(CacheKeys.PERSON_BY_ID + followedPersonId))); logger.trace("Submit async action to update all cached activities."); asyncRequests.add(new UserActionRequest("refreshFollowedByActivities", null, followerPersonId)); asyncRequests .add(new UserActionRequest(CreateNotificationsRequest.ACTION_NAME, null, new TargetEntityNotificationsRequest(RequestType.FOLLOW_PERSON, followerPersonId, followedPersonId))); break; case NOTFOLLOWING: logger.trace("Remove new following from the list of following."); mapper.removeFollower(followerPersonId, followedPersonId); asyncRequests.add(new UserActionRequest("deleteCacheKeysAction", null, (Serializable) Collections .singleton(CacheKeys.PERSON_BY_ID + followedPersonId))); asyncRequests.add(new UserActionRequest("deleteIdsFromLists", null, new DeleteIdsFromListsRequest( Collections.singletonList(CacheKeys.FOLLOWERS_BY_PERSON + followedPersonId), Collections .singletonList(followerPersonId)))); asyncRequests.add(new UserActionRequest("deleteIdsFromLists", null, new DeleteIdsFromListsRequest( Collections.singletonList(CacheKeys.PEOPLE_FOLLOWED_BY_PERSON + followerPersonId), Collections .singletonList(followedPersonId)))); asyncRequests.add(new UserActionRequest("refreshFollowedByActivities", null, followerPersonId)); break; default: } followingCount = followerIdsMapper.execute(followedPersonId).size(); return new Integer(followingCount); } SetFollowingPersonStatusExecution(final PersonMapper inMapper,
            final DomainMapper<String, Long> inGetPersonIdByAccountIdMapper,
            final AddCachedPersonFollower inAddCachedFollowerMapper,
            final DomainMapper<Long, List<Long>> inFollowerIdsMapper); @Override Serializable execute(final TaskHandlerActionContext<PrincipalActionContext> inActionContext); }
SetFollowingPersonStatusExecution implements TaskHandlerExecutionStrategy<PrincipalActionContext> { @Override public Serializable execute(final TaskHandlerActionContext<PrincipalActionContext> inActionContext) throws ExecutionException { SetFollowingStatusRequest request = (SetFollowingStatusRequest) inActionContext.getActionContext().getParams(); if (logger.isTraceEnabled()) { logger.trace("Entering follow person strategy with followerid: " + request.getFollowerUniqueId() + " targetid: " + request.getTargetUniqueId() + " and status " + request.getFollowerStatus()); } List<UserActionRequest> asyncRequests = inActionContext.getUserActionRequests(); int followingCount; Long followerPersonId; Long followedPersonId = getPersonIdByAccountIdMapper.execute(request.getTargetUniqueId()); if (request.getFollowerUniqueId() == null || request.getFollowerUniqueId() == "") { followerPersonId = inActionContext.getActionContext().getPrincipal().getId(); } else { followerPersonId = getPersonIdByAccountIdMapper.execute(request.getFollowerUniqueId()); } switch (request.getFollowerStatus()) { case FOLLOWING: logger.trace("Add new following to the list of following."); mapper.addFollower(followerPersonId, followedPersonId); addCachedFollowerMapper.execute(followerPersonId, followedPersonId); asyncRequests.add(new UserActionRequest("deleteCacheKeysAction", null, (Serializable) Collections .singleton(CacheKeys.PERSON_BY_ID + followedPersonId))); logger.trace("Submit async action to update all cached activities."); asyncRequests.add(new UserActionRequest("refreshFollowedByActivities", null, followerPersonId)); asyncRequests .add(new UserActionRequest(CreateNotificationsRequest.ACTION_NAME, null, new TargetEntityNotificationsRequest(RequestType.FOLLOW_PERSON, followerPersonId, followedPersonId))); break; case NOTFOLLOWING: logger.trace("Remove new following from the list of following."); mapper.removeFollower(followerPersonId, followedPersonId); asyncRequests.add(new UserActionRequest("deleteCacheKeysAction", null, (Serializable) Collections .singleton(CacheKeys.PERSON_BY_ID + followedPersonId))); asyncRequests.add(new UserActionRequest("deleteIdsFromLists", null, new DeleteIdsFromListsRequest( Collections.singletonList(CacheKeys.FOLLOWERS_BY_PERSON + followedPersonId), Collections .singletonList(followerPersonId)))); asyncRequests.add(new UserActionRequest("deleteIdsFromLists", null, new DeleteIdsFromListsRequest( Collections.singletonList(CacheKeys.PEOPLE_FOLLOWED_BY_PERSON + followerPersonId), Collections .singletonList(followedPersonId)))); asyncRequests.add(new UserActionRequest("refreshFollowedByActivities", null, followerPersonId)); break; default: } followingCount = followerIdsMapper.execute(followedPersonId).size(); return new Integer(followingCount); } SetFollowingPersonStatusExecution(final PersonMapper inMapper,
            final DomainMapper<String, Long> inGetPersonIdByAccountIdMapper,
            final AddCachedPersonFollower inAddCachedFollowerMapper,
            final DomainMapper<Long, List<Long>> inFollowerIdsMapper); @Override Serializable execute(final TaskHandlerActionContext<PrincipalActionContext> inActionContext);  }