// this switching here is a hold over until the GroupCreator can be refactored to call this strategy
// and not fail because of additional mapper calls on the DomainGroupModelView and PersonModelView objects.
if (params instanceof SetFollowingStatusRequest)
{
SetFollowingStatusRequest currentRequest = (SetFollowingStatusRequest) params;
followerStatus = currentRequest.getFollowerStatus();
followerAccountId = currentRequest.getFollowerUniqueId();
// gets the current user if no follower id was passed in.
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 = // \n
(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:
// Update the db and cache for list of followers and following.
domainGroupMapper.addFollower(followerId, targetId);
// Update the cache list of followers
addCachedGroupFollowerMapper.execute(followerId, targetId);
// Queue async action to remove the newly followed group from cache (to sync follower counts)
asyncRequests.add(new UserActionRequest("deleteCacheKeysAction", null, (Serializable) Collections
.singleton(CacheKeys.GROUP_BY_ID + targetId)));
// remove any requests from the user for group membership
if (deleteRequestForGroupMembershipMapper
.execute(new RequestForGroupMembershipRequest(targetId, followerId)))
{
// if any requests were present, then user was just approved for access
asyncRequests.add(new UserActionRequest(CreateNotificationsRequest.ACTION_NAME, null,
new GroupMembershipResponseNotificationsRequest(RequestType.REQUEST_GROUP_ACCESS_APPROVED,
inActionContext.getActionContext().getPrincipal().getId(), targetId, followerId)));
}
// remove person modelview from cache as groupstreamhiddenlineindex will be changed.
deleteCacheKeyMapper.execute(Collections.singleton(CacheKeys.PERSON_BY_ID + followerId));
// Sends new follower notifications.
asyncRequests.add(new UserActionRequest(CreateNotificationsRequest.ACTION_NAME, null,
new TargetEntityNotificationsRequest(RequestType.FOLLOW_GROUP, followerId, targetId)));
// Posts a message to the user's personal stream unless this is a new pending group
if (!isPending)
{
String targetStream = "";
if (params instanceof SetFollowingStatusRequest)
{
SetFollowingStatusRequest currentRequest = (SetFollowingStatusRequest) params;
targetStream = currentRequest.getTargetUniqueId();
}
else if (params instanceof SetFollowingStatusByGroupCreatorRequest)
{
SetFollowingStatusByGroupCreatorRequest currentRequest = // \n
(SetFollowingStatusByGroupCreatorRequest) params;
targetStream = currentRequest.getTargetUniqueId();
}
StreamEntityDTO destination = new StreamEntityDTO();
destination.setUniqueIdentifier(followerAccountId);
destination.setType(EntityType.PERSON);