@SuppressWarnings({ "unchecked", "serial" }) @Test public void testExecute() { loadAndVerifyInitialActivity(); List<ActivityDTO> activityList = activityByIdDAO.execute(Arrays.asList(activityId)); assertEquals(1, activityList.size()); ActivityDTO activity = activityList.get(0); assertNotNull(activity); List<Long> commentIds = new ArrayList<Long>(3); commentIds.add(1L); commentIds.add(2L); commentIds.add(3L); List<Long> personIdsWithStarredActivity = new ArrayList<Long>(1); personIdsWithStarredActivity.add(mrburnsId); assertNotNull(sut.execute(new DeleteActivityCacheUpdateRequest(activity, commentIds, personIdsWithStarredActivity))); List<Long> starredActivityIds = cache.getList(CacheKeys.STARRED_BY_PERSON_ID + mrburnsId); assertEquals(0, starredActivityIds.size()); List<Long> commentIdsList = cache.getList(CacheKeys.COMMENT_IDS_BY_ACTIVITY_ID + activityId); assertNull(commentIdsList); assertNull(cache.get(CacheKeys.ACTIVITY_BY_ID + activityId)); assertNull(cache.get(CacheKeys.COMMENT_BY_ID + 1)); assertNull(cache.get(CacheKeys.COMMENT_BY_ID + 2)); assertNull(cache.get(CacheKeys.COMMENT_BY_ID + 3)); }
@Override public Boolean execute(final DeleteActivityCacheUpdateRequest inRequest) { ActivityDTO activity = inRequest.getActivity(); long activityId = activity.getId(); log.info("Cleaning up cache for deleted activity #" + activity.getId()); EntityType streamType = activity.getDestinationStream().getType(); switch (streamType) { case GROUP: DomainGroupModelView group = groupByShortNameDAO.execute( Arrays.asList(activity.getDestinationStream().getUniqueIdentifier())).get(0); log.info("Removing activity #" + activityId + " from group stream + " + group.getStreamId()); getCache().removeFromList(CacheKeys.ENTITY_STREAM_BY_SCOPE_ID + group.getStreamId(), activityId); break; case PERSON: PersonModelView person = getPersonModelViewByAccountIdMapper.execute(activity.getDestinationStream() .getUniqueIdentifier()); log.info("Removing activity #" + activityId + " from person stream + " + person.getStreamId()); getCache().removeFromList(CacheKeys.ENTITY_STREAM_BY_SCOPE_ID + person.getStreamId(), activityId); break; default: break; } for (Long personId : inRequest.getPersonIdsWithActivityStarred()) { log.info("Removing activity #" + activityId + " from starred list for person #" + personId); getCache().removeFromList(CacheKeys.STARRED_BY_PERSON_ID + personId, activityId); } List<List<Long>> likers = getLikersForActivity.execute(Arrays.asList(activityId)); if (likers.size() > 0) { for (Long liker : likers.get(0)) { log.info("Removing activity #" + activityId + " from liked list for person #" + liker); getCache().removeFromList(CacheKeys.LIKED_BY_PERSON_ID + liker, activityId); } } getCache().delete(CacheKeys.LIKERS_BY_ACTIVITY_ID + activityId); getCache().delete(CacheKeys.COMMENT_IDS_BY_ACTIVITY_ID + activityId); List<Long> followingUserIds = getIdsForUsersFollowingDestinationStream(inRequest.getActivity()); for (Long followerId : followingUserIds) { log.info("Removing activity #" + activityId + " from followed list for person #" + followerId); getCache().removeFromList(CacheKeys.ACTIVITIES_BY_FOLLOWING + followerId, activityId); } for (Long commentId : inRequest.getCommentIds()) { log.info("Removing comment id #" + commentId + " from cache for activity #" + activityId); getCache().delete(CacheKeys.COMMENT_BY_ID + commentId); } log.info("Removing activity with id #" + activityId + " from cache."); getCache().delete(CacheKeys.ACTIVITY_BY_ID + activityId); log.info("Removing activity security dto with activity id #" + activityId + " from cache."); getCache().delete(CacheKeys.ACTIVITY_SECURITY_BY_ID + activityId); return true; }
DeleteActivityCacheUpdate extends BaseArgCachedDomainMapper<DeleteActivityCacheUpdateRequest, Boolean> { @Override public Boolean execute(final DeleteActivityCacheUpdateRequest inRequest) { ActivityDTO activity = inRequest.getActivity(); long activityId = activity.getId(); log.info("Cleaning up cache for deleted activity #" + activity.getId()); EntityType streamType = activity.getDestinationStream().getType(); switch (streamType) { case GROUP: DomainGroupModelView group = groupByShortNameDAO.execute( Arrays.asList(activity.getDestinationStream().getUniqueIdentifier())).get(0); log.info("Removing activity #" + activityId + " from group stream + " + group.getStreamId()); getCache().removeFromList(CacheKeys.ENTITY_STREAM_BY_SCOPE_ID + group.getStreamId(), activityId); break; case PERSON: PersonModelView person = getPersonModelViewByAccountIdMapper.execute(activity.getDestinationStream() .getUniqueIdentifier()); log.info("Removing activity #" + activityId + " from person stream + " + person.getStreamId()); getCache().removeFromList(CacheKeys.ENTITY_STREAM_BY_SCOPE_ID + person.getStreamId(), activityId); break; default: break; } for (Long personId : inRequest.getPersonIdsWithActivityStarred()) { log.info("Removing activity #" + activityId + " from starred list for person #" + personId); getCache().removeFromList(CacheKeys.STARRED_BY_PERSON_ID + personId, activityId); } List<List<Long>> likers = getLikersForActivity.execute(Arrays.asList(activityId)); if (likers.size() > 0) { for (Long liker : likers.get(0)) { log.info("Removing activity #" + activityId + " from liked list for person #" + liker); getCache().removeFromList(CacheKeys.LIKED_BY_PERSON_ID + liker, activityId); } } getCache().delete(CacheKeys.LIKERS_BY_ACTIVITY_ID + activityId); getCache().delete(CacheKeys.COMMENT_IDS_BY_ACTIVITY_ID + activityId); List<Long> followingUserIds = getIdsForUsersFollowingDestinationStream(inRequest.getActivity()); for (Long followerId : followingUserIds) { log.info("Removing activity #" + activityId + " from followed list for person #" + followerId); getCache().removeFromList(CacheKeys.ACTIVITIES_BY_FOLLOWING + followerId, activityId); } for (Long commentId : inRequest.getCommentIds()) { log.info("Removing comment id #" + commentId + " from cache for activity #" + activityId); getCache().delete(CacheKeys.COMMENT_BY_ID + commentId); } log.info("Removing activity with id #" + activityId + " from cache."); getCache().delete(CacheKeys.ACTIVITY_BY_ID + activityId); log.info("Removing activity security dto with activity id #" + activityId + " from cache."); getCache().delete(CacheKeys.ACTIVITY_SECURITY_BY_ID + activityId); return true; } }
DeleteActivityCacheUpdate extends BaseArgCachedDomainMapper<DeleteActivityCacheUpdateRequest, Boolean> { @Override public Boolean execute(final DeleteActivityCacheUpdateRequest inRequest) { ActivityDTO activity = inRequest.getActivity(); long activityId = activity.getId(); log.info("Cleaning up cache for deleted activity #" + activity.getId()); EntityType streamType = activity.getDestinationStream().getType(); switch (streamType) { case GROUP: DomainGroupModelView group = groupByShortNameDAO.execute( Arrays.asList(activity.getDestinationStream().getUniqueIdentifier())).get(0); log.info("Removing activity #" + activityId + " from group stream + " + group.getStreamId()); getCache().removeFromList(CacheKeys.ENTITY_STREAM_BY_SCOPE_ID + group.getStreamId(), activityId); break; case PERSON: PersonModelView person = getPersonModelViewByAccountIdMapper.execute(activity.getDestinationStream() .getUniqueIdentifier()); log.info("Removing activity #" + activityId + " from person stream + " + person.getStreamId()); getCache().removeFromList(CacheKeys.ENTITY_STREAM_BY_SCOPE_ID + person.getStreamId(), activityId); break; default: break; } for (Long personId : inRequest.getPersonIdsWithActivityStarred()) { log.info("Removing activity #" + activityId + " from starred list for person #" + personId); getCache().removeFromList(CacheKeys.STARRED_BY_PERSON_ID + personId, activityId); } List<List<Long>> likers = getLikersForActivity.execute(Arrays.asList(activityId)); if (likers.size() > 0) { for (Long liker : likers.get(0)) { log.info("Removing activity #" + activityId + " from liked list for person #" + liker); getCache().removeFromList(CacheKeys.LIKED_BY_PERSON_ID + liker, activityId); } } getCache().delete(CacheKeys.LIKERS_BY_ACTIVITY_ID + activityId); getCache().delete(CacheKeys.COMMENT_IDS_BY_ACTIVITY_ID + activityId); List<Long> followingUserIds = getIdsForUsersFollowingDestinationStream(inRequest.getActivity()); for (Long followerId : followingUserIds) { log.info("Removing activity #" + activityId + " from followed list for person #" + followerId); getCache().removeFromList(CacheKeys.ACTIVITIES_BY_FOLLOWING + followerId, activityId); } for (Long commentId : inRequest.getCommentIds()) { log.info("Removing comment id #" + commentId + " from cache for activity #" + activityId); getCache().delete(CacheKeys.COMMENT_BY_ID + commentId); } log.info("Removing activity with id #" + activityId + " from cache."); getCache().delete(CacheKeys.ACTIVITY_BY_ID + activityId); log.info("Removing activity security dto with activity id #" + activityId + " from cache."); getCache().delete(CacheKeys.ACTIVITY_SECURITY_BY_ID + activityId); return true; } DeleteActivityCacheUpdate(final DomainMapper<Long, List<Long>> inUserIdsFollowingPersonDAO,
            final DomainMapper<Long, List<Long>> inUserIdsFollowingGroupDAO,
            final DomainMapper<String, PersonModelView> inGetPersonModelViewByAccountIdMapper,
            final DomainMapper<String, Long> inGetPersonIdByAccountIdMapper,
            final GetDomainGroupsByShortNames inGroupByShortNameDAO,
            final DomainMapper<List<Long>, List<List<Long>>> inGetLikersForActivity); }
DeleteActivityCacheUpdate extends BaseArgCachedDomainMapper<DeleteActivityCacheUpdateRequest, Boolean> { @Override public Boolean execute(final DeleteActivityCacheUpdateRequest inRequest) { ActivityDTO activity = inRequest.getActivity(); long activityId = activity.getId(); log.info("Cleaning up cache for deleted activity #" + activity.getId()); EntityType streamType = activity.getDestinationStream().getType(); switch (streamType) { case GROUP: DomainGroupModelView group = groupByShortNameDAO.execute( Arrays.asList(activity.getDestinationStream().getUniqueIdentifier())).get(0); log.info("Removing activity #" + activityId + " from group stream + " + group.getStreamId()); getCache().removeFromList(CacheKeys.ENTITY_STREAM_BY_SCOPE_ID + group.getStreamId(), activityId); break; case PERSON: PersonModelView person = getPersonModelViewByAccountIdMapper.execute(activity.getDestinationStream() .getUniqueIdentifier()); log.info("Removing activity #" + activityId + " from person stream + " + person.getStreamId()); getCache().removeFromList(CacheKeys.ENTITY_STREAM_BY_SCOPE_ID + person.getStreamId(), activityId); break; default: break; } for (Long personId : inRequest.getPersonIdsWithActivityStarred()) { log.info("Removing activity #" + activityId + " from starred list for person #" + personId); getCache().removeFromList(CacheKeys.STARRED_BY_PERSON_ID + personId, activityId); } List<List<Long>> likers = getLikersForActivity.execute(Arrays.asList(activityId)); if (likers.size() > 0) { for (Long liker : likers.get(0)) { log.info("Removing activity #" + activityId + " from liked list for person #" + liker); getCache().removeFromList(CacheKeys.LIKED_BY_PERSON_ID + liker, activityId); } } getCache().delete(CacheKeys.LIKERS_BY_ACTIVITY_ID + activityId); getCache().delete(CacheKeys.COMMENT_IDS_BY_ACTIVITY_ID + activityId); List<Long> followingUserIds = getIdsForUsersFollowingDestinationStream(inRequest.getActivity()); for (Long followerId : followingUserIds) { log.info("Removing activity #" + activityId + " from followed list for person #" + followerId); getCache().removeFromList(CacheKeys.ACTIVITIES_BY_FOLLOWING + followerId, activityId); } for (Long commentId : inRequest.getCommentIds()) { log.info("Removing comment id #" + commentId + " from cache for activity #" + activityId); getCache().delete(CacheKeys.COMMENT_BY_ID + commentId); } log.info("Removing activity with id #" + activityId + " from cache."); getCache().delete(CacheKeys.ACTIVITY_BY_ID + activityId); log.info("Removing activity security dto with activity id #" + activityId + " from cache."); getCache().delete(CacheKeys.ACTIVITY_SECURITY_BY_ID + activityId); return true; } DeleteActivityCacheUpdate(final DomainMapper<Long, List<Long>> inUserIdsFollowingPersonDAO,
            final DomainMapper<Long, List<Long>> inUserIdsFollowingGroupDAO,
            final DomainMapper<String, PersonModelView> inGetPersonModelViewByAccountIdMapper,
            final DomainMapper<String, Long> inGetPersonIdByAccountIdMapper,
            final GetDomainGroupsByShortNames inGroupByShortNameDAO,
            final DomainMapper<List<Long>, List<List<Long>>> inGetLikersForActivity); @Override Boolean execute(final DeleteActivityCacheUpdateRequest inRequest); }
DeleteActivityCacheUpdate extends BaseArgCachedDomainMapper<DeleteActivityCacheUpdateRequest, Boolean> { @Override public Boolean execute(final DeleteActivityCacheUpdateRequest inRequest) { ActivityDTO activity = inRequest.getActivity(); long activityId = activity.getId(); log.info("Cleaning up cache for deleted activity #" + activity.getId()); EntityType streamType = activity.getDestinationStream().getType(); switch (streamType) { case GROUP: DomainGroupModelView group = groupByShortNameDAO.execute( Arrays.asList(activity.getDestinationStream().getUniqueIdentifier())).get(0); log.info("Removing activity #" + activityId + " from group stream + " + group.getStreamId()); getCache().removeFromList(CacheKeys.ENTITY_STREAM_BY_SCOPE_ID + group.getStreamId(), activityId); break; case PERSON: PersonModelView person = getPersonModelViewByAccountIdMapper.execute(activity.getDestinationStream() .getUniqueIdentifier()); log.info("Removing activity #" + activityId + " from person stream + " + person.getStreamId()); getCache().removeFromList(CacheKeys.ENTITY_STREAM_BY_SCOPE_ID + person.getStreamId(), activityId); break; default: break; } for (Long personId : inRequest.getPersonIdsWithActivityStarred()) { log.info("Removing activity #" + activityId + " from starred list for person #" + personId); getCache().removeFromList(CacheKeys.STARRED_BY_PERSON_ID + personId, activityId); } List<List<Long>> likers = getLikersForActivity.execute(Arrays.asList(activityId)); if (likers.size() > 0) { for (Long liker : likers.get(0)) { log.info("Removing activity #" + activityId + " from liked list for person #" + liker); getCache().removeFromList(CacheKeys.LIKED_BY_PERSON_ID + liker, activityId); } } getCache().delete(CacheKeys.LIKERS_BY_ACTIVITY_ID + activityId); getCache().delete(CacheKeys.COMMENT_IDS_BY_ACTIVITY_ID + activityId); List<Long> followingUserIds = getIdsForUsersFollowingDestinationStream(inRequest.getActivity()); for (Long followerId : followingUserIds) { log.info("Removing activity #" + activityId + " from followed list for person #" + followerId); getCache().removeFromList(CacheKeys.ACTIVITIES_BY_FOLLOWING + followerId, activityId); } for (Long commentId : inRequest.getCommentIds()) { log.info("Removing comment id #" + commentId + " from cache for activity #" + activityId); getCache().delete(CacheKeys.COMMENT_BY_ID + commentId); } log.info("Removing activity with id #" + activityId + " from cache."); getCache().delete(CacheKeys.ACTIVITY_BY_ID + activityId); log.info("Removing activity security dto with activity id #" + activityId + " from cache."); getCache().delete(CacheKeys.ACTIVITY_SECURITY_BY_ID + activityId); return true; } DeleteActivityCacheUpdate(final DomainMapper<Long, List<Long>> inUserIdsFollowingPersonDAO,
            final DomainMapper<Long, List<Long>> inUserIdsFollowingGroupDAO,
            final DomainMapper<String, PersonModelView> inGetPersonModelViewByAccountIdMapper,
            final DomainMapper<String, Long> inGetPersonIdByAccountIdMapper,
            final GetDomainGroupsByShortNames inGroupByShortNameDAO,
            final DomainMapper<List<Long>, List<List<Long>>> inGetLikersForActivity); @Override Boolean execute(final DeleteActivityCacheUpdateRequest inRequest);  }