@Test public void testSetFollowingWithDifferentRequestObject() throws Exception { final PersonModelView testFollower = new PersonModelView(); testFollower.setEntityId(FOLLOWER_ID); final RequestForGroupMembershipRequest delRequest = new RequestForGroupMembershipRequest(GROUP_ID, 1L); final PersonModelView person = context.mock(PersonModelView.class); context.checking(new Expectations() { { allowing(getPersonByIdMapper).execute(FOLLOWER_ID); will(returnValue(person)); allowing(person).getAccountId(); oneOf(groupMapperMock).addFollower(FOLLOWER_ID, GROUP_ID); oneOf(addCachedGroupFollowerMapperMock).execute(1L, GROUP_ID); oneOf(deleteRequestForGroupMembershipMapper).execute(with(equalInternally(delRequest))); oneOf(deleteCacheKeyMapper).execute(Collections.singleton("Per:1")); oneOf(postActivity).execute(with(any(TaskHandlerActionContext.class))); oneOf(groupFollowerIdsMapperMock).execute(GROUP_ID); will(returnValue(followerIds)); } }); SetFollowingStatusByGroupCreatorRequest currentRequest = new SetFollowingStatusByGroupCreatorRequest( FOLLOWER_ID, GROUP_ID, Follower.FollowerStatus.FOLLOWING, "Group Name", "groupName", false); TaskHandlerActionContext<PrincipalActionContext> actionContext = TestContextCreator .createTaskHandlerContextWithPrincipal(currentRequest, principal); Serializable result = sut.execute(actionContext); context.assertIsSatisfied(); assertEquals(5, result); assertEquals(2, actionContext.getUserActionRequests().size()); }
@Override public Serializable execute(final TaskHandlerActionContext<PrincipalActionContext> inActionContext) throws ExecutionException { Long followerId; String followerAccountId = null; Long targetId; FollowerStatus followerStatus; String targetName; boolean isPending = false; List<UserActionRequest> asyncRequests = inActionContext.getUserActionRequests(); final Serializable params = inActionContext.getActionContext().getParams(); if (params instanceof SetFollowingStatusRequest) { SetFollowingStatusRequest currentRequest = (SetFollowingStatusRequest) params; followerStatus = currentRequest.getFollowerStatus(); followerAccountId = currentRequest.getFollowerUniqueId(); if (followerAccountId == null || followerAccountId == "") { followerAccountId = inActionContext.getActionContext().getPrincipal().getAccountId(); } followerId = getPersonIdFromAccountIdMapper.execute(followerAccountId); DomainGroupModelView targetResult = groupMapper.fetchUniqueResult(currentRequest.getTargetUniqueId()); targetName = targetResult.getName(); targetId = targetResult.getEntityId(); } else if (params instanceof SetFollowingStatusByGroupCreatorRequest) { SetFollowingStatusByGroupCreatorRequest currentRequest = (SetFollowingStatusByGroupCreatorRequest) params; followerId = currentRequest.getFollowerId(); targetId = currentRequest.getTargetId(); targetName = currentRequest.getTargetName(); followerStatus = currentRequest.getFollowerStatus(); isPending = currentRequest.isPending(); if (Follower.FollowerStatus.FOLLOWING.equals(followerStatus) && !isPending) { followerAccountId = getPersonByIdMapper.execute(followerId).getAccountId(); } } else { throw new IllegalArgumentException("Invalid Request type sent to SetFollowingGroupStatusExecution."); } switch (followerStatus) { case FOLLOWING: domainGroupMapper.addFollower(followerId, targetId); addCachedGroupFollowerMapper.execute(followerId, targetId); asyncRequests.add(new UserActionRequest("deleteCacheKeysAction", null, (Serializable) Collections .singleton(CacheKeys.GROUP_BY_ID + targetId))); if (deleteRequestForGroupMembershipMapper .execute(new RequestForGroupMembershipRequest(targetId, followerId))) { asyncRequests.add(new UserActionRequest(CreateNotificationsRequest.ACTION_NAME, null, new GroupMembershipResponseNotificationsRequest(RequestType.REQUEST_GROUP_ACCESS_APPROVED, inActionContext.getActionContext().getPrincipal().getId(), targetId, followerId))); } deleteCacheKeyMapper.execute(Collections.singleton(CacheKeys.PERSON_BY_ID + followerId)); asyncRequests.add(new UserActionRequest(CreateNotificationsRequest.ACTION_NAME, null, new TargetEntityNotificationsRequest(RequestType.FOLLOW_GROUP, followerId, targetId))); if (!isPending) { String targetStream = ""; if (params instanceof SetFollowingStatusRequest) { SetFollowingStatusRequest currentRequest = (SetFollowingStatusRequest) params; targetStream = currentRequest.getTargetUniqueId(); } else if (params instanceof SetFollowingStatusByGroupCreatorRequest) { SetFollowingStatusByGroupCreatorRequest currentRequest = (SetFollowingStatusByGroupCreatorRequest) params; targetStream = currentRequest.getTargetUniqueId(); } StreamEntityDTO destination = new StreamEntityDTO(); destination.setUniqueIdentifier(followerAccountId); destination.setType(EntityType.PERSON); ActivityDTO activity = new ActivityDTO(); HashMap<String, String> props = new HashMap<String, String>(); activity.setBaseObjectProperties(props); String content = ""; if (targetStream.length() > 0) { content = "%EUREKA:ACTORNAME% is now following the [" + targetName + "](#activity/group/" + targetStream + ") group"; } else { content = "%EUREKA:ACTORNAME% is now following the " + targetName + " group"; } activity.getBaseObjectProperties().put("content", content); activity.setDestinationStream(destination); activity.setBaseObjectType(BaseObjectType.NOTE); activity.setVerb(ActivityVerb.POST); new InlineExecutionStrategyExecutor().execute(postActivityExecutor, new PostActivityRequest(activity), new DefaultPrincipal(followerAccountId, null, followerId), inActionContext.getUserActionRequests()); } break; case NOTFOLLOWING: boolean isToBeRemovedUserGroupCoordinator = domainGroupMapper.isInputUserGroupCoordinator(followerId, targetId); if ((domainGroupMapper.getGroupCoordinatorCount(targetId) == 1) && isToBeRemovedUserGroupCoordinator) { log.error("Cannot remove followerId: " + followerId + " " + "from targetId:" + targetId + " since there's " + "only a single Group Coordinator remaining " + "in the Group"); throw new ExecutionException("Cannot remove followerId: " + followerId + " " + "from targetId:" + targetId + " since there's " + "only a single Group Coordinator remaining " + "in the Group"); } domainGroupMapper.removeFollower(followerId, targetId); asyncRequests.add(new UserActionRequest("deleteCacheKeysAction", null, (Serializable) Collections .singleton(CacheKeys.GROUP_BY_ID + targetId))); asyncRequests.add(new UserActionRequest("deleteIdsFromLists", null, new DeleteIdsFromListsRequest( Collections.singletonList(CacheKeys.FOLLOWERS_BY_GROUP + targetId), Collections .singletonList(followerId)))); asyncRequests.add(new UserActionRequest("deleteIdsFromLists", null, new DeleteIdsFromListsRequest( Collections.singletonList(CacheKeys.GROUPS_FOLLOWED_BY_PERSON + followerId), Collections .singletonList(targetId)))); if (isToBeRemovedUserGroupCoordinator) { domainGroupMapper.removeGroupCoordinator(followerId, targetId); asyncRequests.add(new UserActionRequest("deleteCacheKeysAction", null, (Serializable) Collections .singleton(CacheKeys.COORDINATOR_PERSON_IDS_BY_GROUP_ID + targetId))); if (domainGroupMapper.isGroupPrivate(targetId)) { asyncRequests.add(new UserActionRequest("deleteCacheKeysAction", null, (Serializable) Collections .singleton(CacheKeys.PRIVATE_GROUP_IDS_VIEWABLE_BY_PERSON_AS_COORDINATOR + followerId))); } } break; default: } return followerIdsMapper.execute(targetId).size(); }
SetFollowingGroupStatusExecution implements TaskHandlerExecutionStrategy<PrincipalActionContext> { @Override public Serializable execute(final TaskHandlerActionContext<PrincipalActionContext> inActionContext) throws ExecutionException { Long followerId; String followerAccountId = null; Long targetId; FollowerStatus followerStatus; String targetName; boolean isPending = false; List<UserActionRequest> asyncRequests = inActionContext.getUserActionRequests(); final Serializable params = inActionContext.getActionContext().getParams(); if (params instanceof SetFollowingStatusRequest) { SetFollowingStatusRequest currentRequest = (SetFollowingStatusRequest) params; followerStatus = currentRequest.getFollowerStatus(); followerAccountId = currentRequest.getFollowerUniqueId(); if (followerAccountId == null || followerAccountId == "") { followerAccountId = inActionContext.getActionContext().getPrincipal().getAccountId(); } followerId = getPersonIdFromAccountIdMapper.execute(followerAccountId); DomainGroupModelView targetResult = groupMapper.fetchUniqueResult(currentRequest.getTargetUniqueId()); targetName = targetResult.getName(); targetId = targetResult.getEntityId(); } else if (params instanceof SetFollowingStatusByGroupCreatorRequest) { SetFollowingStatusByGroupCreatorRequest currentRequest = (SetFollowingStatusByGroupCreatorRequest) params; followerId = currentRequest.getFollowerId(); targetId = currentRequest.getTargetId(); targetName = currentRequest.getTargetName(); followerStatus = currentRequest.getFollowerStatus(); isPending = currentRequest.isPending(); if (Follower.FollowerStatus.FOLLOWING.equals(followerStatus) && !isPending) { followerAccountId = getPersonByIdMapper.execute(followerId).getAccountId(); } } else { throw new IllegalArgumentException("Invalid Request type sent to SetFollowingGroupStatusExecution."); } switch (followerStatus) { case FOLLOWING: domainGroupMapper.addFollower(followerId, targetId); addCachedGroupFollowerMapper.execute(followerId, targetId); asyncRequests.add(new UserActionRequest("deleteCacheKeysAction", null, (Serializable) Collections .singleton(CacheKeys.GROUP_BY_ID + targetId))); if (deleteRequestForGroupMembershipMapper .execute(new RequestForGroupMembershipRequest(targetId, followerId))) { asyncRequests.add(new UserActionRequest(CreateNotificationsRequest.ACTION_NAME, null, new GroupMembershipResponseNotificationsRequest(RequestType.REQUEST_GROUP_ACCESS_APPROVED, inActionContext.getActionContext().getPrincipal().getId(), targetId, followerId))); } deleteCacheKeyMapper.execute(Collections.singleton(CacheKeys.PERSON_BY_ID + followerId)); asyncRequests.add(new UserActionRequest(CreateNotificationsRequest.ACTION_NAME, null, new TargetEntityNotificationsRequest(RequestType.FOLLOW_GROUP, followerId, targetId))); if (!isPending) { String targetStream = ""; if (params instanceof SetFollowingStatusRequest) { SetFollowingStatusRequest currentRequest = (SetFollowingStatusRequest) params; targetStream = currentRequest.getTargetUniqueId(); } else if (params instanceof SetFollowingStatusByGroupCreatorRequest) { SetFollowingStatusByGroupCreatorRequest currentRequest = (SetFollowingStatusByGroupCreatorRequest) params; targetStream = currentRequest.getTargetUniqueId(); } StreamEntityDTO destination = new StreamEntityDTO(); destination.setUniqueIdentifier(followerAccountId); destination.setType(EntityType.PERSON); ActivityDTO activity = new ActivityDTO(); HashMap<String, String> props = new HashMap<String, String>(); activity.setBaseObjectProperties(props); String content = ""; if (targetStream.length() > 0) { content = "%EUREKA:ACTORNAME% is now following the [" + targetName + "](#activity/group/" + targetStream + ") group"; } else { content = "%EUREKA:ACTORNAME% is now following the " + targetName + " group"; } activity.getBaseObjectProperties().put("content", content); activity.setDestinationStream(destination); activity.setBaseObjectType(BaseObjectType.NOTE); activity.setVerb(ActivityVerb.POST); new InlineExecutionStrategyExecutor().execute(postActivityExecutor, new PostActivityRequest(activity), new DefaultPrincipal(followerAccountId, null, followerId), inActionContext.getUserActionRequests()); } break; case NOTFOLLOWING: boolean isToBeRemovedUserGroupCoordinator = domainGroupMapper.isInputUserGroupCoordinator(followerId, targetId); if ((domainGroupMapper.getGroupCoordinatorCount(targetId) == 1) && isToBeRemovedUserGroupCoordinator) { log.error("Cannot remove followerId: " + followerId + " " + "from targetId:" + targetId + " since there's " + "only a single Group Coordinator remaining " + "in the Group"); throw new ExecutionException("Cannot remove followerId: " + followerId + " " + "from targetId:" + targetId + " since there's " + "only a single Group Coordinator remaining " + "in the Group"); } domainGroupMapper.removeFollower(followerId, targetId); asyncRequests.add(new UserActionRequest("deleteCacheKeysAction", null, (Serializable) Collections .singleton(CacheKeys.GROUP_BY_ID + targetId))); asyncRequests.add(new UserActionRequest("deleteIdsFromLists", null, new DeleteIdsFromListsRequest( Collections.singletonList(CacheKeys.FOLLOWERS_BY_GROUP + targetId), Collections .singletonList(followerId)))); asyncRequests.add(new UserActionRequest("deleteIdsFromLists", null, new DeleteIdsFromListsRequest( Collections.singletonList(CacheKeys.GROUPS_FOLLOWED_BY_PERSON + followerId), Collections .singletonList(targetId)))); if (isToBeRemovedUserGroupCoordinator) { domainGroupMapper.removeGroupCoordinator(followerId, targetId); asyncRequests.add(new UserActionRequest("deleteCacheKeysAction", null, (Serializable) Collections .singleton(CacheKeys.COORDINATOR_PERSON_IDS_BY_GROUP_ID + targetId))); if (domainGroupMapper.isGroupPrivate(targetId)) { asyncRequests.add(new UserActionRequest("deleteCacheKeysAction", null, (Serializable) Collections .singleton(CacheKeys.PRIVATE_GROUP_IDS_VIEWABLE_BY_PERSON_AS_COORDINATOR + followerId))); } } break; default: } return followerIdsMapper.execute(targetId).size(); } }
SetFollowingGroupStatusExecution implements TaskHandlerExecutionStrategy<PrincipalActionContext> { @Override public Serializable execute(final TaskHandlerActionContext<PrincipalActionContext> inActionContext) throws ExecutionException { Long followerId; String followerAccountId = null; Long targetId; FollowerStatus followerStatus; String targetName; boolean isPending = false; List<UserActionRequest> asyncRequests = inActionContext.getUserActionRequests(); final Serializable params = inActionContext.getActionContext().getParams(); if (params instanceof SetFollowingStatusRequest) { SetFollowingStatusRequest currentRequest = (SetFollowingStatusRequest) params; followerStatus = currentRequest.getFollowerStatus(); followerAccountId = currentRequest.getFollowerUniqueId(); if (followerAccountId == null || followerAccountId == "") { followerAccountId = inActionContext.getActionContext().getPrincipal().getAccountId(); } followerId = getPersonIdFromAccountIdMapper.execute(followerAccountId); DomainGroupModelView targetResult = groupMapper.fetchUniqueResult(currentRequest.getTargetUniqueId()); targetName = targetResult.getName(); targetId = targetResult.getEntityId(); } else if (params instanceof SetFollowingStatusByGroupCreatorRequest) { SetFollowingStatusByGroupCreatorRequest currentRequest = (SetFollowingStatusByGroupCreatorRequest) params; followerId = currentRequest.getFollowerId(); targetId = currentRequest.getTargetId(); targetName = currentRequest.getTargetName(); followerStatus = currentRequest.getFollowerStatus(); isPending = currentRequest.isPending(); if (Follower.FollowerStatus.FOLLOWING.equals(followerStatus) && !isPending) { followerAccountId = getPersonByIdMapper.execute(followerId).getAccountId(); } } else { throw new IllegalArgumentException("Invalid Request type sent to SetFollowingGroupStatusExecution."); } switch (followerStatus) { case FOLLOWING: domainGroupMapper.addFollower(followerId, targetId); addCachedGroupFollowerMapper.execute(followerId, targetId); asyncRequests.add(new UserActionRequest("deleteCacheKeysAction", null, (Serializable) Collections .singleton(CacheKeys.GROUP_BY_ID + targetId))); if (deleteRequestForGroupMembershipMapper .execute(new RequestForGroupMembershipRequest(targetId, followerId))) { asyncRequests.add(new UserActionRequest(CreateNotificationsRequest.ACTION_NAME, null, new GroupMembershipResponseNotificationsRequest(RequestType.REQUEST_GROUP_ACCESS_APPROVED, inActionContext.getActionContext().getPrincipal().getId(), targetId, followerId))); } deleteCacheKeyMapper.execute(Collections.singleton(CacheKeys.PERSON_BY_ID + followerId)); asyncRequests.add(new UserActionRequest(CreateNotificationsRequest.ACTION_NAME, null, new TargetEntityNotificationsRequest(RequestType.FOLLOW_GROUP, followerId, targetId))); if (!isPending) { String targetStream = ""; if (params instanceof SetFollowingStatusRequest) { SetFollowingStatusRequest currentRequest = (SetFollowingStatusRequest) params; targetStream = currentRequest.getTargetUniqueId(); } else if (params instanceof SetFollowingStatusByGroupCreatorRequest) { SetFollowingStatusByGroupCreatorRequest currentRequest = (SetFollowingStatusByGroupCreatorRequest) params; targetStream = currentRequest.getTargetUniqueId(); } StreamEntityDTO destination = new StreamEntityDTO(); destination.setUniqueIdentifier(followerAccountId); destination.setType(EntityType.PERSON); ActivityDTO activity = new ActivityDTO(); HashMap<String, String> props = new HashMap<String, String>(); activity.setBaseObjectProperties(props); String content = ""; if (targetStream.length() > 0) { content = "%EUREKA:ACTORNAME% is now following the [" + targetName + "](#activity/group/" + targetStream + ") group"; } else { content = "%EUREKA:ACTORNAME% is now following the " + targetName + " group"; } activity.getBaseObjectProperties().put("content", content); activity.setDestinationStream(destination); activity.setBaseObjectType(BaseObjectType.NOTE); activity.setVerb(ActivityVerb.POST); new InlineExecutionStrategyExecutor().execute(postActivityExecutor, new PostActivityRequest(activity), new DefaultPrincipal(followerAccountId, null, followerId), inActionContext.getUserActionRequests()); } break; case NOTFOLLOWING: boolean isToBeRemovedUserGroupCoordinator = domainGroupMapper.isInputUserGroupCoordinator(followerId, targetId); if ((domainGroupMapper.getGroupCoordinatorCount(targetId) == 1) && isToBeRemovedUserGroupCoordinator) { log.error("Cannot remove followerId: " + followerId + " " + "from targetId:" + targetId + " since there's " + "only a single Group Coordinator remaining " + "in the Group"); throw new ExecutionException("Cannot remove followerId: " + followerId + " " + "from targetId:" + targetId + " since there's " + "only a single Group Coordinator remaining " + "in the Group"); } domainGroupMapper.removeFollower(followerId, targetId); asyncRequests.add(new UserActionRequest("deleteCacheKeysAction", null, (Serializable) Collections .singleton(CacheKeys.GROUP_BY_ID + targetId))); asyncRequests.add(new UserActionRequest("deleteIdsFromLists", null, new DeleteIdsFromListsRequest( Collections.singletonList(CacheKeys.FOLLOWERS_BY_GROUP + targetId), Collections .singletonList(followerId)))); asyncRequests.add(new UserActionRequest("deleteIdsFromLists", null, new DeleteIdsFromListsRequest( Collections.singletonList(CacheKeys.GROUPS_FOLLOWED_BY_PERSON + followerId), Collections .singletonList(targetId)))); if (isToBeRemovedUserGroupCoordinator) { domainGroupMapper.removeGroupCoordinator(followerId, targetId); asyncRequests.add(new UserActionRequest("deleteCacheKeysAction", null, (Serializable) Collections .singleton(CacheKeys.COORDINATOR_PERSON_IDS_BY_GROUP_ID + targetId))); if (domainGroupMapper.isGroupPrivate(targetId)) { asyncRequests.add(new UserActionRequest("deleteCacheKeysAction", null, (Serializable) Collections .singleton(CacheKeys.PRIVATE_GROUP_IDS_VIEWABLE_BY_PERSON_AS_COORDINATOR + followerId))); } } break; default: } return followerIdsMapper.execute(targetId).size(); } SetFollowingGroupStatusExecution(final GetDomainGroupsByShortNames inGroupMapper,
            final DomainMapper<Long, PersonModelView> inGetPersonByIdMapper,
            final DomainMapper<String, Long> inGetPersonIdFromAccountIdMapper,
            final DomainGroupMapper inDomainGroupMapper, final AddCachedGroupFollower inAddCachedGroupFollowerMapper,
            final DomainMapper<Long, List<Long>> inFollowerIdsMapper,
            final DeleteRequestForGroupMembership inDeleteRequestForGroupMembershipMapper,
            final TaskHandlerExecutionStrategy inPostActivityExecutor,
            final DomainMapper<Set<String>, Boolean> inDeleteCacheKeyMapper); }
SetFollowingGroupStatusExecution implements TaskHandlerExecutionStrategy<PrincipalActionContext> { @Override public Serializable execute(final TaskHandlerActionContext<PrincipalActionContext> inActionContext) throws ExecutionException { Long followerId; String followerAccountId = null; Long targetId; FollowerStatus followerStatus; String targetName; boolean isPending = false; List<UserActionRequest> asyncRequests = inActionContext.getUserActionRequests(); final Serializable params = inActionContext.getActionContext().getParams(); if (params instanceof SetFollowingStatusRequest) { SetFollowingStatusRequest currentRequest = (SetFollowingStatusRequest) params; followerStatus = currentRequest.getFollowerStatus(); followerAccountId = currentRequest.getFollowerUniqueId(); if (followerAccountId == null || followerAccountId == "") { followerAccountId = inActionContext.getActionContext().getPrincipal().getAccountId(); } followerId = getPersonIdFromAccountIdMapper.execute(followerAccountId); DomainGroupModelView targetResult = groupMapper.fetchUniqueResult(currentRequest.getTargetUniqueId()); targetName = targetResult.getName(); targetId = targetResult.getEntityId(); } else if (params instanceof SetFollowingStatusByGroupCreatorRequest) { SetFollowingStatusByGroupCreatorRequest currentRequest = (SetFollowingStatusByGroupCreatorRequest) params; followerId = currentRequest.getFollowerId(); targetId = currentRequest.getTargetId(); targetName = currentRequest.getTargetName(); followerStatus = currentRequest.getFollowerStatus(); isPending = currentRequest.isPending(); if (Follower.FollowerStatus.FOLLOWING.equals(followerStatus) && !isPending) { followerAccountId = getPersonByIdMapper.execute(followerId).getAccountId(); } } else { throw new IllegalArgumentException("Invalid Request type sent to SetFollowingGroupStatusExecution."); } switch (followerStatus) { case FOLLOWING: domainGroupMapper.addFollower(followerId, targetId); addCachedGroupFollowerMapper.execute(followerId, targetId); asyncRequests.add(new UserActionRequest("deleteCacheKeysAction", null, (Serializable) Collections .singleton(CacheKeys.GROUP_BY_ID + targetId))); if (deleteRequestForGroupMembershipMapper .execute(new RequestForGroupMembershipRequest(targetId, followerId))) { asyncRequests.add(new UserActionRequest(CreateNotificationsRequest.ACTION_NAME, null, new GroupMembershipResponseNotificationsRequest(RequestType.REQUEST_GROUP_ACCESS_APPROVED, inActionContext.getActionContext().getPrincipal().getId(), targetId, followerId))); } deleteCacheKeyMapper.execute(Collections.singleton(CacheKeys.PERSON_BY_ID + followerId)); asyncRequests.add(new UserActionRequest(CreateNotificationsRequest.ACTION_NAME, null, new TargetEntityNotificationsRequest(RequestType.FOLLOW_GROUP, followerId, targetId))); if (!isPending) { String targetStream = ""; if (params instanceof SetFollowingStatusRequest) { SetFollowingStatusRequest currentRequest = (SetFollowingStatusRequest) params; targetStream = currentRequest.getTargetUniqueId(); } else if (params instanceof SetFollowingStatusByGroupCreatorRequest) { SetFollowingStatusByGroupCreatorRequest currentRequest = (SetFollowingStatusByGroupCreatorRequest) params; targetStream = currentRequest.getTargetUniqueId(); } StreamEntityDTO destination = new StreamEntityDTO(); destination.setUniqueIdentifier(followerAccountId); destination.setType(EntityType.PERSON); ActivityDTO activity = new ActivityDTO(); HashMap<String, String> props = new HashMap<String, String>(); activity.setBaseObjectProperties(props); String content = ""; if (targetStream.length() > 0) { content = "%EUREKA:ACTORNAME% is now following the [" + targetName + "](#activity/group/" + targetStream + ") group"; } else { content = "%EUREKA:ACTORNAME% is now following the " + targetName + " group"; } activity.getBaseObjectProperties().put("content", content); activity.setDestinationStream(destination); activity.setBaseObjectType(BaseObjectType.NOTE); activity.setVerb(ActivityVerb.POST); new InlineExecutionStrategyExecutor().execute(postActivityExecutor, new PostActivityRequest(activity), new DefaultPrincipal(followerAccountId, null, followerId), inActionContext.getUserActionRequests()); } break; case NOTFOLLOWING: boolean isToBeRemovedUserGroupCoordinator = domainGroupMapper.isInputUserGroupCoordinator(followerId, targetId); if ((domainGroupMapper.getGroupCoordinatorCount(targetId) == 1) && isToBeRemovedUserGroupCoordinator) { log.error("Cannot remove followerId: " + followerId + " " + "from targetId:" + targetId + " since there's " + "only a single Group Coordinator remaining " + "in the Group"); throw new ExecutionException("Cannot remove followerId: " + followerId + " " + "from targetId:" + targetId + " since there's " + "only a single Group Coordinator remaining " + "in the Group"); } domainGroupMapper.removeFollower(followerId, targetId); asyncRequests.add(new UserActionRequest("deleteCacheKeysAction", null, (Serializable) Collections .singleton(CacheKeys.GROUP_BY_ID + targetId))); asyncRequests.add(new UserActionRequest("deleteIdsFromLists", null, new DeleteIdsFromListsRequest( Collections.singletonList(CacheKeys.FOLLOWERS_BY_GROUP + targetId), Collections .singletonList(followerId)))); asyncRequests.add(new UserActionRequest("deleteIdsFromLists", null, new DeleteIdsFromListsRequest( Collections.singletonList(CacheKeys.GROUPS_FOLLOWED_BY_PERSON + followerId), Collections .singletonList(targetId)))); if (isToBeRemovedUserGroupCoordinator) { domainGroupMapper.removeGroupCoordinator(followerId, targetId); asyncRequests.add(new UserActionRequest("deleteCacheKeysAction", null, (Serializable) Collections .singleton(CacheKeys.COORDINATOR_PERSON_IDS_BY_GROUP_ID + targetId))); if (domainGroupMapper.isGroupPrivate(targetId)) { asyncRequests.add(new UserActionRequest("deleteCacheKeysAction", null, (Serializable) Collections .singleton(CacheKeys.PRIVATE_GROUP_IDS_VIEWABLE_BY_PERSON_AS_COORDINATOR + followerId))); } } break; default: } return followerIdsMapper.execute(targetId).size(); } SetFollowingGroupStatusExecution(final GetDomainGroupsByShortNames inGroupMapper,
            final DomainMapper<Long, PersonModelView> inGetPersonByIdMapper,
            final DomainMapper<String, Long> inGetPersonIdFromAccountIdMapper,
            final DomainGroupMapper inDomainGroupMapper, final AddCachedGroupFollower inAddCachedGroupFollowerMapper,
            final DomainMapper<Long, List<Long>> inFollowerIdsMapper,
            final DeleteRequestForGroupMembership inDeleteRequestForGroupMembershipMapper,
            final TaskHandlerExecutionStrategy inPostActivityExecutor,
            final DomainMapper<Set<String>, Boolean> inDeleteCacheKeyMapper); @Override Serializable execute(final TaskHandlerActionContext<PrincipalActionContext> inActionContext); }
SetFollowingGroupStatusExecution implements TaskHandlerExecutionStrategy<PrincipalActionContext> { @Override public Serializable execute(final TaskHandlerActionContext<PrincipalActionContext> inActionContext) throws ExecutionException { Long followerId; String followerAccountId = null; Long targetId; FollowerStatus followerStatus; String targetName; boolean isPending = false; List<UserActionRequest> asyncRequests = inActionContext.getUserActionRequests(); final Serializable params = inActionContext.getActionContext().getParams(); if (params instanceof SetFollowingStatusRequest) { SetFollowingStatusRequest currentRequest = (SetFollowingStatusRequest) params; followerStatus = currentRequest.getFollowerStatus(); followerAccountId = currentRequest.getFollowerUniqueId(); if (followerAccountId == null || followerAccountId == "") { followerAccountId = inActionContext.getActionContext().getPrincipal().getAccountId(); } followerId = getPersonIdFromAccountIdMapper.execute(followerAccountId); DomainGroupModelView targetResult = groupMapper.fetchUniqueResult(currentRequest.getTargetUniqueId()); targetName = targetResult.getName(); targetId = targetResult.getEntityId(); } else if (params instanceof SetFollowingStatusByGroupCreatorRequest) { SetFollowingStatusByGroupCreatorRequest currentRequest = (SetFollowingStatusByGroupCreatorRequest) params; followerId = currentRequest.getFollowerId(); targetId = currentRequest.getTargetId(); targetName = currentRequest.getTargetName(); followerStatus = currentRequest.getFollowerStatus(); isPending = currentRequest.isPending(); if (Follower.FollowerStatus.FOLLOWING.equals(followerStatus) && !isPending) { followerAccountId = getPersonByIdMapper.execute(followerId).getAccountId(); } } else { throw new IllegalArgumentException("Invalid Request type sent to SetFollowingGroupStatusExecution."); } switch (followerStatus) { case FOLLOWING: domainGroupMapper.addFollower(followerId, targetId); addCachedGroupFollowerMapper.execute(followerId, targetId); asyncRequests.add(new UserActionRequest("deleteCacheKeysAction", null, (Serializable) Collections .singleton(CacheKeys.GROUP_BY_ID + targetId))); if (deleteRequestForGroupMembershipMapper .execute(new RequestForGroupMembershipRequest(targetId, followerId))) { asyncRequests.add(new UserActionRequest(CreateNotificationsRequest.ACTION_NAME, null, new GroupMembershipResponseNotificationsRequest(RequestType.REQUEST_GROUP_ACCESS_APPROVED, inActionContext.getActionContext().getPrincipal().getId(), targetId, followerId))); } deleteCacheKeyMapper.execute(Collections.singleton(CacheKeys.PERSON_BY_ID + followerId)); asyncRequests.add(new UserActionRequest(CreateNotificationsRequest.ACTION_NAME, null, new TargetEntityNotificationsRequest(RequestType.FOLLOW_GROUP, followerId, targetId))); if (!isPending) { String targetStream = ""; if (params instanceof SetFollowingStatusRequest) { SetFollowingStatusRequest currentRequest = (SetFollowingStatusRequest) params; targetStream = currentRequest.getTargetUniqueId(); } else if (params instanceof SetFollowingStatusByGroupCreatorRequest) { SetFollowingStatusByGroupCreatorRequest currentRequest = (SetFollowingStatusByGroupCreatorRequest) params; targetStream = currentRequest.getTargetUniqueId(); } StreamEntityDTO destination = new StreamEntityDTO(); destination.setUniqueIdentifier(followerAccountId); destination.setType(EntityType.PERSON); ActivityDTO activity = new ActivityDTO(); HashMap<String, String> props = new HashMap<String, String>(); activity.setBaseObjectProperties(props); String content = ""; if (targetStream.length() > 0) { content = "%EUREKA:ACTORNAME% is now following the [" + targetName + "](#activity/group/" + targetStream + ") group"; } else { content = "%EUREKA:ACTORNAME% is now following the " + targetName + " group"; } activity.getBaseObjectProperties().put("content", content); activity.setDestinationStream(destination); activity.setBaseObjectType(BaseObjectType.NOTE); activity.setVerb(ActivityVerb.POST); new InlineExecutionStrategyExecutor().execute(postActivityExecutor, new PostActivityRequest(activity), new DefaultPrincipal(followerAccountId, null, followerId), inActionContext.getUserActionRequests()); } break; case NOTFOLLOWING: boolean isToBeRemovedUserGroupCoordinator = domainGroupMapper.isInputUserGroupCoordinator(followerId, targetId); if ((domainGroupMapper.getGroupCoordinatorCount(targetId) == 1) && isToBeRemovedUserGroupCoordinator) { log.error("Cannot remove followerId: " + followerId + " " + "from targetId:" + targetId + " since there's " + "only a single Group Coordinator remaining " + "in the Group"); throw new ExecutionException("Cannot remove followerId: " + followerId + " " + "from targetId:" + targetId + " since there's " + "only a single Group Coordinator remaining " + "in the Group"); } domainGroupMapper.removeFollower(followerId, targetId); asyncRequests.add(new UserActionRequest("deleteCacheKeysAction", null, (Serializable) Collections .singleton(CacheKeys.GROUP_BY_ID + targetId))); asyncRequests.add(new UserActionRequest("deleteIdsFromLists", null, new DeleteIdsFromListsRequest( Collections.singletonList(CacheKeys.FOLLOWERS_BY_GROUP + targetId), Collections .singletonList(followerId)))); asyncRequests.add(new UserActionRequest("deleteIdsFromLists", null, new DeleteIdsFromListsRequest( Collections.singletonList(CacheKeys.GROUPS_FOLLOWED_BY_PERSON + followerId), Collections .singletonList(targetId)))); if (isToBeRemovedUserGroupCoordinator) { domainGroupMapper.removeGroupCoordinator(followerId, targetId); asyncRequests.add(new UserActionRequest("deleteCacheKeysAction", null, (Serializable) Collections .singleton(CacheKeys.COORDINATOR_PERSON_IDS_BY_GROUP_ID + targetId))); if (domainGroupMapper.isGroupPrivate(targetId)) { asyncRequests.add(new UserActionRequest("deleteCacheKeysAction", null, (Serializable) Collections .singleton(CacheKeys.PRIVATE_GROUP_IDS_VIEWABLE_BY_PERSON_AS_COORDINATOR + followerId))); } } break; default: } return followerIdsMapper.execute(targetId).size(); } SetFollowingGroupStatusExecution(final GetDomainGroupsByShortNames inGroupMapper,
            final DomainMapper<Long, PersonModelView> inGetPersonByIdMapper,
            final DomainMapper<String, Long> inGetPersonIdFromAccountIdMapper,
            final DomainGroupMapper inDomainGroupMapper, final AddCachedGroupFollower inAddCachedGroupFollowerMapper,
            final DomainMapper<Long, List<Long>> inFollowerIdsMapper,
            final DeleteRequestForGroupMembership inDeleteRequestForGroupMembershipMapper,
            final TaskHandlerExecutionStrategy inPostActivityExecutor,
            final DomainMapper<Set<String>, Boolean> inDeleteCacheKeyMapper); @Override Serializable execute(final TaskHandlerActionContext<PrincipalActionContext> inActionContext);  }