@Test public void testSuccessfulExecute() { final ActivityDTO currentActivity = PostActivityTestHelpers.buildActivityDTO( PostActivityTestHelpers.DestinationStreamTestState.VALID, false, testComment, DESTINATION_ID); final List<ActivityDTO> activityResults = new ArrayList<ActivityDTO>(); activityResults.add(currentActivity); final PostActivityRequest request = new PostActivityRequest(currentActivity); final Principal currentPrincipal = new DefaultPrincipal(ACCOUNT_ID, OPENSOCIAL_ID, USER_ID); context.checking(new Expectations() { { oneOf(recipientRetrieverMock).getStreamScope(currentActivity); oneOf(recipientRetrieverMock).isDestinationStreamPublic(currentActivity); oneOf(activityInsertMapperMock).execute(with(any(PersistenceRequest.class))); oneOf(activityInsertMapperMock).flush(); oneOf(activitiesMapperMock).execute(with(any(List.class))); will(returnValue(activityResults)); oneOf(getPersonModelViewByAccountIdMapper).execute(ACCOUNT_ID); will(returnValue(person)); oneOf(filter).filter(with(any(List.class)), with(person)); oneOf(updateStreamsByActorMapperMock).execute(currentActivity); } }); sut.execute(TestContextCreator.createTaskHandlerContextWithPrincipal(request, currentPrincipal)); context.assertIsSatisfied(); }
@Override public Serializable execute(final TaskHandlerActionContext<PrincipalActionContext> inActionContext) { ActivityDTO inActivityDTO = ((PostActivityRequest) inActionContext.getActionContext().getParams()) .getActivityDTO(); ActivityDTO persistedActivityDTO; Activity newActivity = convertDTOToActivity(inActivityDTO, inActionContext.getUserActionRequests()); List<UserActionRequest> queueRequests = new ArrayList<UserActionRequest>(); String actorAccountName = inActionContext.getActionContext().getPrincipal().getAccountId(); newActivity.setPostedTime(new Date()); newActivity.setActorId(actorAccountName); newActivity.setActorType(EntityType.PERSON); long actorId = 0; long destinationId = 0; EntityType destinationType; insertMapper.execute(new PersistenceRequest<Activity>(newActivity)); insertMapper.flush(); List<ActivityDTO> activityResults = activitiesMapper.execute(Arrays.asList(newActivity.getId())); persistedActivityDTO = activityResults.get(0); actorId = persistedActivityDTO.getActor().getId(); destinationId = persistedActivityDTO.getDestinationStream().getDestinationEntityId(); destinationType = persistedActivityDTO.getDestinationStream().getType(); updateStreamsByActorMapper.execute(persistedActivityDTO); if (inActivityDTO.getFirstComment() != null && inActivityDTO.getVerb().equals(ActivityVerb.SHARE)) { insertCommentDAO.execute(new InsertActivityCommentRequest(actorId, persistedActivityDTO.getId(), inActivityDTO.getFirstComment().getBody())); } RequestType requestType = null; if (destinationType == EntityType.PERSON) { requestType = RequestType.POST_PERSON_STREAM; } else if (destinationType == EntityType.GROUP) { requestType = RequestType.POST_GROUP_STREAM; } if (requestType != null) { CreateNotificationsRequest notificationRequest = new ActivityNotificationsRequest(requestType, actorId, destinationId, persistedActivityDTO.getEntityId()); queueRequests .add(new UserActionRequest(CreateNotificationsRequest.ACTION_NAME, null, notificationRequest)); } queueRequests.add(new UserActionRequest("postActivityAsyncAction", null, new PostActivityRequest( persistedActivityDTO))); inActionContext.getUserActionRequests().addAll(queueRequests); PersonModelView person = getPersonModelViewByAccountIdMapper.execute(actorAccountName); for (ActivityFilter filter : filters) { filter.filter(Collections.singletonList(persistedActivityDTO), person); } return persistedActivityDTO; }
PostActivityExecutionStrategy implements TaskHandlerExecutionStrategy<PrincipalActionContext> { @Override public Serializable execute(final TaskHandlerActionContext<PrincipalActionContext> inActionContext) { ActivityDTO inActivityDTO = ((PostActivityRequest) inActionContext.getActionContext().getParams()) .getActivityDTO(); ActivityDTO persistedActivityDTO; Activity newActivity = convertDTOToActivity(inActivityDTO, inActionContext.getUserActionRequests()); List<UserActionRequest> queueRequests = new ArrayList<UserActionRequest>(); String actorAccountName = inActionContext.getActionContext().getPrincipal().getAccountId(); newActivity.setPostedTime(new Date()); newActivity.setActorId(actorAccountName); newActivity.setActorType(EntityType.PERSON); long actorId = 0; long destinationId = 0; EntityType destinationType; insertMapper.execute(new PersistenceRequest<Activity>(newActivity)); insertMapper.flush(); List<ActivityDTO> activityResults = activitiesMapper.execute(Arrays.asList(newActivity.getId())); persistedActivityDTO = activityResults.get(0); actorId = persistedActivityDTO.getActor().getId(); destinationId = persistedActivityDTO.getDestinationStream().getDestinationEntityId(); destinationType = persistedActivityDTO.getDestinationStream().getType(); updateStreamsByActorMapper.execute(persistedActivityDTO); if (inActivityDTO.getFirstComment() != null && inActivityDTO.getVerb().equals(ActivityVerb.SHARE)) { insertCommentDAO.execute(new InsertActivityCommentRequest(actorId, persistedActivityDTO.getId(), inActivityDTO.getFirstComment().getBody())); } RequestType requestType = null; if (destinationType == EntityType.PERSON) { requestType = RequestType.POST_PERSON_STREAM; } else if (destinationType == EntityType.GROUP) { requestType = RequestType.POST_GROUP_STREAM; } if (requestType != null) { CreateNotificationsRequest notificationRequest = new ActivityNotificationsRequest(requestType, actorId, destinationId, persistedActivityDTO.getEntityId()); queueRequests .add(new UserActionRequest(CreateNotificationsRequest.ACTION_NAME, null, notificationRequest)); } queueRequests.add(new UserActionRequest("postActivityAsyncAction", null, new PostActivityRequest( persistedActivityDTO))); inActionContext.getUserActionRequests().addAll(queueRequests); PersonModelView person = getPersonModelViewByAccountIdMapper.execute(actorAccountName); for (ActivityFilter filter : filters) { filter.filter(Collections.singletonList(persistedActivityDTO), person); } return persistedActivityDTO; } }
PostActivityExecutionStrategy implements TaskHandlerExecutionStrategy<PrincipalActionContext> { @Override public Serializable execute(final TaskHandlerActionContext<PrincipalActionContext> inActionContext) { ActivityDTO inActivityDTO = ((PostActivityRequest) inActionContext.getActionContext().getParams()) .getActivityDTO(); ActivityDTO persistedActivityDTO; Activity newActivity = convertDTOToActivity(inActivityDTO, inActionContext.getUserActionRequests()); List<UserActionRequest> queueRequests = new ArrayList<UserActionRequest>(); String actorAccountName = inActionContext.getActionContext().getPrincipal().getAccountId(); newActivity.setPostedTime(new Date()); newActivity.setActorId(actorAccountName); newActivity.setActorType(EntityType.PERSON); long actorId = 0; long destinationId = 0; EntityType destinationType; insertMapper.execute(new PersistenceRequest<Activity>(newActivity)); insertMapper.flush(); List<ActivityDTO> activityResults = activitiesMapper.execute(Arrays.asList(newActivity.getId())); persistedActivityDTO = activityResults.get(0); actorId = persistedActivityDTO.getActor().getId(); destinationId = persistedActivityDTO.getDestinationStream().getDestinationEntityId(); destinationType = persistedActivityDTO.getDestinationStream().getType(); updateStreamsByActorMapper.execute(persistedActivityDTO); if (inActivityDTO.getFirstComment() != null && inActivityDTO.getVerb().equals(ActivityVerb.SHARE)) { insertCommentDAO.execute(new InsertActivityCommentRequest(actorId, persistedActivityDTO.getId(), inActivityDTO.getFirstComment().getBody())); } RequestType requestType = null; if (destinationType == EntityType.PERSON) { requestType = RequestType.POST_PERSON_STREAM; } else if (destinationType == EntityType.GROUP) { requestType = RequestType.POST_GROUP_STREAM; } if (requestType != null) { CreateNotificationsRequest notificationRequest = new ActivityNotificationsRequest(requestType, actorId, destinationId, persistedActivityDTO.getEntityId()); queueRequests .add(new UserActionRequest(CreateNotificationsRequest.ACTION_NAME, null, notificationRequest)); } queueRequests.add(new UserActionRequest("postActivityAsyncAction", null, new PostActivityRequest( persistedActivityDTO))); inActionContext.getUserActionRequests().addAll(queueRequests); PersonModelView person = getPersonModelViewByAccountIdMapper.execute(actorAccountName); for (ActivityFilter filter : filters) { filter.filter(Collections.singletonList(persistedActivityDTO), person); } return persistedActivityDTO; } PostActivityExecutionStrategy(final InsertMapper<Activity> inInsertMapper,
            final InsertActivityComment inInsertCommentDAO,
            final DomainMapper<List<Long>, List<ActivityDTO>> inActivitiesMapper,
            final RecipientRetriever inRecipientRetriever,
            final PostActivityUpdateStreamsByActorMapper inUpdateStreamsByActorMapper,
            final DomainMapper<SharedResourceRequest, SharedResource> inFindOrInsertSharedResourceMapper,
            final Cache inCache, final DomainMapper<String, PersonModelView> inGetPersonModelViewByAccountIdMapper,
            final List<ActivityFilter> inFilters,
            final Transformer<String, String> inSharedResourceCacheKeySuffixTransformer); }
PostActivityExecutionStrategy implements TaskHandlerExecutionStrategy<PrincipalActionContext> { @Override public Serializable execute(final TaskHandlerActionContext<PrincipalActionContext> inActionContext) { ActivityDTO inActivityDTO = ((PostActivityRequest) inActionContext.getActionContext().getParams()) .getActivityDTO(); ActivityDTO persistedActivityDTO; Activity newActivity = convertDTOToActivity(inActivityDTO, inActionContext.getUserActionRequests()); List<UserActionRequest> queueRequests = new ArrayList<UserActionRequest>(); String actorAccountName = inActionContext.getActionContext().getPrincipal().getAccountId(); newActivity.setPostedTime(new Date()); newActivity.setActorId(actorAccountName); newActivity.setActorType(EntityType.PERSON); long actorId = 0; long destinationId = 0; EntityType destinationType; insertMapper.execute(new PersistenceRequest<Activity>(newActivity)); insertMapper.flush(); List<ActivityDTO> activityResults = activitiesMapper.execute(Arrays.asList(newActivity.getId())); persistedActivityDTO = activityResults.get(0); actorId = persistedActivityDTO.getActor().getId(); destinationId = persistedActivityDTO.getDestinationStream().getDestinationEntityId(); destinationType = persistedActivityDTO.getDestinationStream().getType(); updateStreamsByActorMapper.execute(persistedActivityDTO); if (inActivityDTO.getFirstComment() != null && inActivityDTO.getVerb().equals(ActivityVerb.SHARE)) { insertCommentDAO.execute(new InsertActivityCommentRequest(actorId, persistedActivityDTO.getId(), inActivityDTO.getFirstComment().getBody())); } RequestType requestType = null; if (destinationType == EntityType.PERSON) { requestType = RequestType.POST_PERSON_STREAM; } else if (destinationType == EntityType.GROUP) { requestType = RequestType.POST_GROUP_STREAM; } if (requestType != null) { CreateNotificationsRequest notificationRequest = new ActivityNotificationsRequest(requestType, actorId, destinationId, persistedActivityDTO.getEntityId()); queueRequests .add(new UserActionRequest(CreateNotificationsRequest.ACTION_NAME, null, notificationRequest)); } queueRequests.add(new UserActionRequest("postActivityAsyncAction", null, new PostActivityRequest( persistedActivityDTO))); inActionContext.getUserActionRequests().addAll(queueRequests); PersonModelView person = getPersonModelViewByAccountIdMapper.execute(actorAccountName); for (ActivityFilter filter : filters) { filter.filter(Collections.singletonList(persistedActivityDTO), person); } return persistedActivityDTO; } PostActivityExecutionStrategy(final InsertMapper<Activity> inInsertMapper,
            final InsertActivityComment inInsertCommentDAO,
            final DomainMapper<List<Long>, List<ActivityDTO>> inActivitiesMapper,
            final RecipientRetriever inRecipientRetriever,
            final PostActivityUpdateStreamsByActorMapper inUpdateStreamsByActorMapper,
            final DomainMapper<SharedResourceRequest, SharedResource> inFindOrInsertSharedResourceMapper,
            final Cache inCache, final DomainMapper<String, PersonModelView> inGetPersonModelViewByAccountIdMapper,
            final List<ActivityFilter> inFilters,
            final Transformer<String, String> inSharedResourceCacheKeySuffixTransformer); @Override Serializable execute(final TaskHandlerActionContext<PrincipalActionContext> inActionContext); }
PostActivityExecutionStrategy implements TaskHandlerExecutionStrategy<PrincipalActionContext> { @Override public Serializable execute(final TaskHandlerActionContext<PrincipalActionContext> inActionContext) { ActivityDTO inActivityDTO = ((PostActivityRequest) inActionContext.getActionContext().getParams()) .getActivityDTO(); ActivityDTO persistedActivityDTO; Activity newActivity = convertDTOToActivity(inActivityDTO, inActionContext.getUserActionRequests()); List<UserActionRequest> queueRequests = new ArrayList<UserActionRequest>(); String actorAccountName = inActionContext.getActionContext().getPrincipal().getAccountId(); newActivity.setPostedTime(new Date()); newActivity.setActorId(actorAccountName); newActivity.setActorType(EntityType.PERSON); long actorId = 0; long destinationId = 0; EntityType destinationType; insertMapper.execute(new PersistenceRequest<Activity>(newActivity)); insertMapper.flush(); List<ActivityDTO> activityResults = activitiesMapper.execute(Arrays.asList(newActivity.getId())); persistedActivityDTO = activityResults.get(0); actorId = persistedActivityDTO.getActor().getId(); destinationId = persistedActivityDTO.getDestinationStream().getDestinationEntityId(); destinationType = persistedActivityDTO.getDestinationStream().getType(); updateStreamsByActorMapper.execute(persistedActivityDTO); if (inActivityDTO.getFirstComment() != null && inActivityDTO.getVerb().equals(ActivityVerb.SHARE)) { insertCommentDAO.execute(new InsertActivityCommentRequest(actorId, persistedActivityDTO.getId(), inActivityDTO.getFirstComment().getBody())); } RequestType requestType = null; if (destinationType == EntityType.PERSON) { requestType = RequestType.POST_PERSON_STREAM; } else if (destinationType == EntityType.GROUP) { requestType = RequestType.POST_GROUP_STREAM; } if (requestType != null) { CreateNotificationsRequest notificationRequest = new ActivityNotificationsRequest(requestType, actorId, destinationId, persistedActivityDTO.getEntityId()); queueRequests .add(new UserActionRequest(CreateNotificationsRequest.ACTION_NAME, null, notificationRequest)); } queueRequests.add(new UserActionRequest("postActivityAsyncAction", null, new PostActivityRequest( persistedActivityDTO))); inActionContext.getUserActionRequests().addAll(queueRequests); PersonModelView person = getPersonModelViewByAccountIdMapper.execute(actorAccountName); for (ActivityFilter filter : filters) { filter.filter(Collections.singletonList(persistedActivityDTO), person); } return persistedActivityDTO; } PostActivityExecutionStrategy(final InsertMapper<Activity> inInsertMapper,
            final InsertActivityComment inInsertCommentDAO,
            final DomainMapper<List<Long>, List<ActivityDTO>> inActivitiesMapper,
            final RecipientRetriever inRecipientRetriever,
            final PostActivityUpdateStreamsByActorMapper inUpdateStreamsByActorMapper,
            final DomainMapper<SharedResourceRequest, SharedResource> inFindOrInsertSharedResourceMapper,
            final Cache inCache, final DomainMapper<String, PersonModelView> inGetPersonModelViewByAccountIdMapper,
            final List<ActivityFilter> inFilters,
            final Transformer<String, String> inSharedResourceCacheKeySuffixTransformer); @Override Serializable execute(final TaskHandlerActionContext<PrincipalActionContext> inActionContext);  }