@SuppressWarnings("unchecked") @Test public void testPerformAction() throws Exception { context.checking(new Expectations() { { final int expireDays = 20; SystemSettings settings = new SystemSettings(); settings.setContentExpiration(expireDays); allowing(settingsMapper).execute(null); will(returnValue(settings)); List<Long> activities = new ArrayList<Long>(); activities.add(1L); activities.add(2L); activities.add(3L); allowing(expiredActivitiesMapper).execute(with(any(Date.class))); will(returnValue(activities)); allowing(listsMapper).execute(with(any(List.class))); will(returnValue(Arrays.asList("cacheKey1", "cacheKey2"))); allowing(deleteMapper).execute(with(any(List.class))); List<UserActionRequest> requests = new ArrayList<UserActionRequest>(); oneOf(actionContext).getUserActionRequests(); will(returnValue(requests)); allowing(indexDeleteMapper).execute(with(any(DeleteFromSearchIndexRequest.class))); allowing(listsMapper).execute(with(any(List.class))); will(returnValue(Arrays.asList("cacheKey3"))); allowing(deleteMapper).execute(with(any(List.class))); requests = new ArrayList<UserActionRequest>(); oneOf(actionContext).getUserActionRequests(); will(returnValue(requests)); allowing(indexDeleteMapper).execute(with(any(DeleteFromSearchIndexRequest.class))); } }); Boolean result = sut.execute(actionContext); context.assertIsSatisfied(); assertTrue(result); }
@Override public Boolean execute(final TaskHandlerActionContext<PrincipalActionContext> inActionContext) { SystemSettings settings = settingsMapper.execute(null); int expirationDays = settings.getContentExpiration(); if (expirationDays > 0) { Calendar calendar = Calendar.getInstance(); calendar.add(Calendar.DATE, expirationDays * -1); List<Long> expired = expiredActivitiesMapper.execute(calendar.getTime()); if (log.isTraceEnabled()) { log.trace("Expired activity ids to delete: " + expired); } while (expired.size() > 0) { int count = expired.size() > chunkSize ? chunkSize : expired.size(); ArrayList<Long> chunkActivityIds = new ArrayList<Long>(expired.subList(0, count)); if (log.isTraceEnabled()) { log.trace("Pushing UserActionRequest to queue for deleteActivitiesByIds with " + chunkActivityIds.size() + " activities"); } inActionContext.getUserActionRequests().add( new UserActionRequest("deleteActivitiesByIds", null, chunkActivityIds)); expired.subList(0, count).clear(); } } return Boolean.TRUE; }
DeleteExpiredActivitiesExecution implements TaskHandlerExecutionStrategy<PrincipalActionContext> { @Override public Boolean execute(final TaskHandlerActionContext<PrincipalActionContext> inActionContext) { SystemSettings settings = settingsMapper.execute(null); int expirationDays = settings.getContentExpiration(); if (expirationDays > 0) { Calendar calendar = Calendar.getInstance(); calendar.add(Calendar.DATE, expirationDays * -1); List<Long> expired = expiredActivitiesMapper.execute(calendar.getTime()); if (log.isTraceEnabled()) { log.trace("Expired activity ids to delete: " + expired); } while (expired.size() > 0) { int count = expired.size() > chunkSize ? chunkSize : expired.size(); ArrayList<Long> chunkActivityIds = new ArrayList<Long>(expired.subList(0, count)); if (log.isTraceEnabled()) { log.trace("Pushing UserActionRequest to queue for deleteActivitiesByIds with " + chunkActivityIds.size() + " activities"); } inActionContext.getUserActionRequests().add( new UserActionRequest("deleteActivitiesByIds", null, chunkActivityIds)); expired.subList(0, count).clear(); } } return Boolean.TRUE; } }
DeleteExpiredActivitiesExecution implements TaskHandlerExecutionStrategy<PrincipalActionContext> { @Override public Boolean execute(final TaskHandlerActionContext<PrincipalActionContext> inActionContext) { SystemSettings settings = settingsMapper.execute(null); int expirationDays = settings.getContentExpiration(); if (expirationDays > 0) { Calendar calendar = Calendar.getInstance(); calendar.add(Calendar.DATE, expirationDays * -1); List<Long> expired = expiredActivitiesMapper.execute(calendar.getTime()); if (log.isTraceEnabled()) { log.trace("Expired activity ids to delete: " + expired); } while (expired.size() > 0) { int count = expired.size() > chunkSize ? chunkSize : expired.size(); ArrayList<Long> chunkActivityIds = new ArrayList<Long>(expired.subList(0, count)); if (log.isTraceEnabled()) { log.trace("Pushing UserActionRequest to queue for deleteActivitiesByIds with " + chunkActivityIds.size() + " activities"); } inActionContext.getUserActionRequests().add( new UserActionRequest("deleteActivitiesByIds", null, chunkActivityIds)); expired.subList(0, count).clear(); } } return Boolean.TRUE; } DeleteExpiredActivitiesExecution(final DomainMapper<MapperRequest, SystemSettings> inSettingsMapper,
            final GetExpiredActivities inExpiredActivitiesMapper, final int inChunkSize); }
DeleteExpiredActivitiesExecution implements TaskHandlerExecutionStrategy<PrincipalActionContext> { @Override public Boolean execute(final TaskHandlerActionContext<PrincipalActionContext> inActionContext) { SystemSettings settings = settingsMapper.execute(null); int expirationDays = settings.getContentExpiration(); if (expirationDays > 0) { Calendar calendar = Calendar.getInstance(); calendar.add(Calendar.DATE, expirationDays * -1); List<Long> expired = expiredActivitiesMapper.execute(calendar.getTime()); if (log.isTraceEnabled()) { log.trace("Expired activity ids to delete: " + expired); } while (expired.size() > 0) { int count = expired.size() > chunkSize ? chunkSize : expired.size(); ArrayList<Long> chunkActivityIds = new ArrayList<Long>(expired.subList(0, count)); if (log.isTraceEnabled()) { log.trace("Pushing UserActionRequest to queue for deleteActivitiesByIds with " + chunkActivityIds.size() + " activities"); } inActionContext.getUserActionRequests().add( new UserActionRequest("deleteActivitiesByIds", null, chunkActivityIds)); expired.subList(0, count).clear(); } } return Boolean.TRUE; } DeleteExpiredActivitiesExecution(final DomainMapper<MapperRequest, SystemSettings> inSettingsMapper,
            final GetExpiredActivities inExpiredActivitiesMapper, final int inChunkSize); @Override Boolean execute(final TaskHandlerActionContext<PrincipalActionContext> inActionContext); }
DeleteExpiredActivitiesExecution implements TaskHandlerExecutionStrategy<PrincipalActionContext> { @Override public Boolean execute(final TaskHandlerActionContext<PrincipalActionContext> inActionContext) { SystemSettings settings = settingsMapper.execute(null); int expirationDays = settings.getContentExpiration(); if (expirationDays > 0) { Calendar calendar = Calendar.getInstance(); calendar.add(Calendar.DATE, expirationDays * -1); List<Long> expired = expiredActivitiesMapper.execute(calendar.getTime()); if (log.isTraceEnabled()) { log.trace("Expired activity ids to delete: " + expired); } while (expired.size() > 0) { int count = expired.size() > chunkSize ? chunkSize : expired.size(); ArrayList<Long> chunkActivityIds = new ArrayList<Long>(expired.subList(0, count)); if (log.isTraceEnabled()) { log.trace("Pushing UserActionRequest to queue for deleteActivitiesByIds with " + chunkActivityIds.size() + " activities"); } inActionContext.getUserActionRequests().add( new UserActionRequest("deleteActivitiesByIds", null, chunkActivityIds)); expired.subList(0, count).clear(); } } return Boolean.TRUE; } DeleteExpiredActivitiesExecution(final DomainMapper<MapperRequest, SystemSettings> inSettingsMapper,
            final GetExpiredActivities inExpiredActivitiesMapper, final int inChunkSize); @Override Boolean execute(final TaskHandlerActionContext<PrincipalActionContext> inActionContext);  }