@Test @SuppressWarnings("unchecked") public void testShortNameEntityIdIsGroupNotSameIsFollowing() throws Exception { context.checking(new Expectations() { { oneOf(actionContext).getParams(); will(returnValue(getCurrentUserFollowingStatusRequest)); oneOf(actionContext).getPrincipal(); will(returnValue(principal)); oneOf(principal).getAccountId(); will(returnValue(CURRENT_USER)); oneOf(principal).getId(); will(returnValue(CURRENT_USER_ID)); oneOf(getCurrentUserFollowingStatusRequest).getFollowedEntityId(); will(returnValue(TARGET_GROUP)); oneOf(getCurrentUserFollowingStatusRequest).getEntityType(); will(returnValue(EntityType.GROUP)); DomainGroupModelView target = new DomainGroupModelView(); target.setEntityId(TARGET_GROUP_ID); oneOf(getDomainGroupsByShortNames).execute(with(any(List.class))); will(returnValue(Collections.singletonList(target))); oneOf(getGroupFollowerIds).execute(TARGET_GROUP_ID); will(returnValue(Collections.singletonList(CURRENT_USER_ID))); } }); assertEquals(sut.execute(actionContext), Follower.FollowerStatus.FOLLOWING); context.assertIsSatisfied(); }
@Override public Serializable execute(final PrincipalActionContext inActionContext) { GetCurrentUserFollowingStatusRequest inRequest = (GetCurrentUserFollowingStatusRequest) inActionContext .getParams(); final Principal principal = inActionContext.getPrincipal(); final String accountId = principal.getAccountId(); final Long userId = principal.getId(); String followedEntityId = inRequest.getFollowedEntityId(); final EntityType entityType = inRequest.getEntityType(); if (log.isTraceEnabled()) { log.trace("Checking the following status for the user " + accountId + " following " + followedEntityId + " of entity type " + entityType.toString()); } if (followedEntityId.matches(openSocialPattern) && entityType == EntityType.PERSON) { followedEntityId = getPeopleByOpenSocialIdsMapper.fetchUniqueResult(followedEntityId).getAccountId(); } if (accountId == null || (accountId.equalsIgnoreCase(followedEntityId) && entityType == EntityType.PERSON)) { return Follower.FollowerStatus.DISABLED; } Follower.FollowerStatus status = Follower.FollowerStatus.DISABLED; if (EntityType.PERSON == entityType) { status = isUserFollowingUser(userId, followedEntityId); } else if (EntityType.GROUP == entityType) { status = isUserFollowingGroup(userId, followedEntityId); } return status; }
GetCurrentUserFollowingStatusExecution implements ExecutionStrategy<PrincipalActionContext> { @Override public Serializable execute(final PrincipalActionContext inActionContext) { GetCurrentUserFollowingStatusRequest inRequest = (GetCurrentUserFollowingStatusRequest) inActionContext .getParams(); final Principal principal = inActionContext.getPrincipal(); final String accountId = principal.getAccountId(); final Long userId = principal.getId(); String followedEntityId = inRequest.getFollowedEntityId(); final EntityType entityType = inRequest.getEntityType(); if (log.isTraceEnabled()) { log.trace("Checking the following status for the user " + accountId + " following " + followedEntityId + " of entity type " + entityType.toString()); } if (followedEntityId.matches(openSocialPattern) && entityType == EntityType.PERSON) { followedEntityId = getPeopleByOpenSocialIdsMapper.fetchUniqueResult(followedEntityId).getAccountId(); } if (accountId == null || (accountId.equalsIgnoreCase(followedEntityId) && entityType == EntityType.PERSON)) { return Follower.FollowerStatus.DISABLED; } Follower.FollowerStatus status = Follower.FollowerStatus.DISABLED; if (EntityType.PERSON == entityType) { status = isUserFollowingUser(userId, followedEntityId); } else if (EntityType.GROUP == entityType) { status = isUserFollowingGroup(userId, followedEntityId); } return status; } }
GetCurrentUserFollowingStatusExecution implements ExecutionStrategy<PrincipalActionContext> { @Override public Serializable execute(final PrincipalActionContext inActionContext) { GetCurrentUserFollowingStatusRequest inRequest = (GetCurrentUserFollowingStatusRequest) inActionContext .getParams(); final Principal principal = inActionContext.getPrincipal(); final String accountId = principal.getAccountId(); final Long userId = principal.getId(); String followedEntityId = inRequest.getFollowedEntityId(); final EntityType entityType = inRequest.getEntityType(); if (log.isTraceEnabled()) { log.trace("Checking the following status for the user " + accountId + " following " + followedEntityId + " of entity type " + entityType.toString()); } if (followedEntityId.matches(openSocialPattern) && entityType == EntityType.PERSON) { followedEntityId = getPeopleByOpenSocialIdsMapper.fetchUniqueResult(followedEntityId).getAccountId(); } if (accountId == null || (accountId.equalsIgnoreCase(followedEntityId) && entityType == EntityType.PERSON)) { return Follower.FollowerStatus.DISABLED; } Follower.FollowerStatus status = Follower.FollowerStatus.DISABLED; if (EntityType.PERSON == entityType) { status = isUserFollowingUser(userId, followedEntityId); } else if (EntityType.GROUP == entityType) { status = isUserFollowingGroup(userId, followedEntityId); } return status; } GetCurrentUserFollowingStatusExecution(final GetPeopleByOpenSocialIds inGetPeopleByOpenSocialIdsMapper,
            final String inPattern, final DomainMapper<Long, List<Long>> inGroupFollowerIdsMapper,
            final DomainMapper<Long, List<Long>> inGollowerIdsMapper,
            final GetDomainGroupsByShortNames inGroupsByNameMapper,
            final DomainMapper<List<String>, List<PersonModelView>> inGetPersonModelViewsByAccountIdsMapper); }
GetCurrentUserFollowingStatusExecution implements ExecutionStrategy<PrincipalActionContext> { @Override public Serializable execute(final PrincipalActionContext inActionContext) { GetCurrentUserFollowingStatusRequest inRequest = (GetCurrentUserFollowingStatusRequest) inActionContext .getParams(); final Principal principal = inActionContext.getPrincipal(); final String accountId = principal.getAccountId(); final Long userId = principal.getId(); String followedEntityId = inRequest.getFollowedEntityId(); final EntityType entityType = inRequest.getEntityType(); if (log.isTraceEnabled()) { log.trace("Checking the following status for the user " + accountId + " following " + followedEntityId + " of entity type " + entityType.toString()); } if (followedEntityId.matches(openSocialPattern) && entityType == EntityType.PERSON) { followedEntityId = getPeopleByOpenSocialIdsMapper.fetchUniqueResult(followedEntityId).getAccountId(); } if (accountId == null || (accountId.equalsIgnoreCase(followedEntityId) && entityType == EntityType.PERSON)) { return Follower.FollowerStatus.DISABLED; } Follower.FollowerStatus status = Follower.FollowerStatus.DISABLED; if (EntityType.PERSON == entityType) { status = isUserFollowingUser(userId, followedEntityId); } else if (EntityType.GROUP == entityType) { status = isUserFollowingGroup(userId, followedEntityId); } return status; } GetCurrentUserFollowingStatusExecution(final GetPeopleByOpenSocialIds inGetPeopleByOpenSocialIdsMapper,
            final String inPattern, final DomainMapper<Long, List<Long>> inGroupFollowerIdsMapper,
            final DomainMapper<Long, List<Long>> inGollowerIdsMapper,
            final GetDomainGroupsByShortNames inGroupsByNameMapper,
            final DomainMapper<List<String>, List<PersonModelView>> inGetPersonModelViewsByAccountIdsMapper); @Override Serializable execute(final PrincipalActionContext inActionContext); }
GetCurrentUserFollowingStatusExecution implements ExecutionStrategy<PrincipalActionContext> { @Override public Serializable execute(final PrincipalActionContext inActionContext) { GetCurrentUserFollowingStatusRequest inRequest = (GetCurrentUserFollowingStatusRequest) inActionContext .getParams(); final Principal principal = inActionContext.getPrincipal(); final String accountId = principal.getAccountId(); final Long userId = principal.getId(); String followedEntityId = inRequest.getFollowedEntityId(); final EntityType entityType = inRequest.getEntityType(); if (log.isTraceEnabled()) { log.trace("Checking the following status for the user " + accountId + " following " + followedEntityId + " of entity type " + entityType.toString()); } if (followedEntityId.matches(openSocialPattern) && entityType == EntityType.PERSON) { followedEntityId = getPeopleByOpenSocialIdsMapper.fetchUniqueResult(followedEntityId).getAccountId(); } if (accountId == null || (accountId.equalsIgnoreCase(followedEntityId) && entityType == EntityType.PERSON)) { return Follower.FollowerStatus.DISABLED; } Follower.FollowerStatus status = Follower.FollowerStatus.DISABLED; if (EntityType.PERSON == entityType) { status = isUserFollowingUser(userId, followedEntityId); } else if (EntityType.GROUP == entityType) { status = isUserFollowingGroup(userId, followedEntityId); } return status; } GetCurrentUserFollowingStatusExecution(final GetPeopleByOpenSocialIds inGetPeopleByOpenSocialIdsMapper,
            final String inPattern, final DomainMapper<Long, List<Long>> inGroupFollowerIdsMapper,
            final DomainMapper<Long, List<Long>> inGollowerIdsMapper,
            final GetDomainGroupsByShortNames inGroupsByNameMapper,
            final DomainMapper<List<String>, List<PersonModelView>> inGetPersonModelViewsByAccountIdsMapper); @Override Serializable execute(final PrincipalActionContext inActionContext);  }