@Test public void testExecute() { final List<Long> existingSystemAdmins = new ArrayList<Long>(); existingSystemAdmins.add(5L); final HashSet<Person> admins = new HashSet<Person>(); admins.add(admin1); final List<Long> newAdminIds = new ArrayList<Long>(); newAdminIds.add(7L); final ArrayList<String> adminAccountIds = new ArrayList<String>(); adminAccountIds.add("admin1"); final HashMap<String, Serializable> formData = new HashMap<String, Serializable>(); formData.put("admins", admins); context.checking(new Expectations() { { oneOf(admin1).getAccountId(); will(returnValue("admin1")); oneOf(peopleIdsByAccountIdsMapper).execute(with(IsEqualInternally.equalInternally(adminAccountIds))); will(returnValue(newAdminIds)); allowing(finder).execute(null); will(returnValue(systemSettings)); oneOf(updaterStrategy).setProperties(systemSettings, formData); allowing(updateMapper).execute(null); oneOf(setSystemAdministratorsMapper).execute(with(IsEqualInternally.equalInternally(adminAccountIds))); oneOf(getSystemAdministratorIdsMapper).execute(null); will(returnValue(existingSystemAdmins)); oneOf(cache).delete(CacheKeys.PERSON_BY_ID + 5); oneOf(cache).delete(CacheKeys.PERSON_BY_ID + 7); oneOf(cache).delete(CacheKeys.SYSTEM_ADMINISTRATOR_IDS); } }); final TaskHandlerActionContext<PrincipalActionContext> actionContext = TestContextCreator .createTaskHandlerContextWithPrincipal(formData, null); List<UserActionRequest> userActionRequests = actionContext.getUserActionRequests(); Assert.assertEquals(systemSettings, sut.execute(actionContext)); context.assertIsSatisfied(); Assert.assertEquals(1, userActionRequests.size()); Assert.assertEquals("deleteCacheKeysAction", userActionRequests.get(0).getActionKey()); final Serializable asyncParams = userActionRequests.get(0).getParams(); Assert.assertSame(3, ((HashSet<String>) asyncParams).size()); Assert.assertTrue(((HashSet<String>) asyncParams).contains(CacheKeys.PERSON_BY_ID + 5)); Assert.assertTrue(((HashSet<String>) asyncParams).contains(CacheKeys.PERSON_BY_ID + 7)); Assert.assertTrue(((HashSet<String>) asyncParams).contains(CacheKeys.SYSTEM_ADMINISTRATOR_IDS)); }
@SuppressWarnings("unchecked") @Override public SystemSettings execute(final TaskHandlerActionContext<PrincipalActionContext> inActionContext) { log.info("updating system settings"); Set<String> cacheKeysToClear = new HashSet<String>(); Map<String, Serializable> fields = (Map<String, Serializable>) inActionContext.getActionContext().getParams(); HashSet<Person> admins = (HashSet<Person>) fields.get("admins"); fields.remove("ldapGroups"); fields.remove("admins"); SystemSettings systemSettings = finder.execute(null); updater.setProperties(systemSettings, fields); updateMapper.execute(null); for (Long personId : getSystemAdministratorIdsMapper.execute(null)) { cacheKeysToClear.add(CacheKeys.PERSON_BY_ID + personId); log.debug("Deleting existing system administrator with person id " + personId + " from cache before updating admin settings"); cache.delete(CacheKeys.PERSON_BY_ID + personId); } ArrayList<String> adminAccountIds = new ArrayList<String>(); for (Person person : admins) { adminAccountIds.add(person.getAccountId()); } List<Long> peopleIds = peopleIdsByAccountIdsMapper.execute(adminAccountIds); log.info("Setting system administrators to " + adminAccountIds); setSystemAdministratorsMapper.execute(adminAccountIds); for (Long personId : peopleIds) { log.debug("Deleting new system administrator with person id " + personId + " from cache before updating admin settings"); cacheKeysToClear.add(CacheKeys.PERSON_BY_ID + personId); cache.delete(CacheKeys.PERSON_BY_ID + personId); } log.debug("Deleting the system administrator ids from cache, now that they've changed."); cache.delete(CacheKeys.SYSTEM_ADMINISTRATOR_IDS); cacheKeysToClear.add(CacheKeys.SYSTEM_ADMINISTRATOR_IDS); inActionContext.getUserActionRequests().add( new UserActionRequest("deleteCacheKeysAction", null, (Serializable) cacheKeysToClear)); return systemSettings; }
UpdateSystemSettingsExecution implements TaskHandlerExecutionStrategy<PrincipalActionContext> { @SuppressWarnings("unchecked") @Override public SystemSettings execute(final TaskHandlerActionContext<PrincipalActionContext> inActionContext) { log.info("updating system settings"); Set<String> cacheKeysToClear = new HashSet<String>(); Map<String, Serializable> fields = (Map<String, Serializable>) inActionContext.getActionContext().getParams(); HashSet<Person> admins = (HashSet<Person>) fields.get("admins"); fields.remove("ldapGroups"); fields.remove("admins"); SystemSettings systemSettings = finder.execute(null); updater.setProperties(systemSettings, fields); updateMapper.execute(null); for (Long personId : getSystemAdministratorIdsMapper.execute(null)) { cacheKeysToClear.add(CacheKeys.PERSON_BY_ID + personId); log.debug("Deleting existing system administrator with person id " + personId + " from cache before updating admin settings"); cache.delete(CacheKeys.PERSON_BY_ID + personId); } ArrayList<String> adminAccountIds = new ArrayList<String>(); for (Person person : admins) { adminAccountIds.add(person.getAccountId()); } List<Long> peopleIds = peopleIdsByAccountIdsMapper.execute(adminAccountIds); log.info("Setting system administrators to " + adminAccountIds); setSystemAdministratorsMapper.execute(adminAccountIds); for (Long personId : peopleIds) { log.debug("Deleting new system administrator with person id " + personId + " from cache before updating admin settings"); cacheKeysToClear.add(CacheKeys.PERSON_BY_ID + personId); cache.delete(CacheKeys.PERSON_BY_ID + personId); } log.debug("Deleting the system administrator ids from cache, now that they've changed."); cache.delete(CacheKeys.SYSTEM_ADMINISTRATOR_IDS); cacheKeysToClear.add(CacheKeys.SYSTEM_ADMINISTRATOR_IDS); inActionContext.getUserActionRequests().add( new UserActionRequest("deleteCacheKeysAction", null, (Serializable) cacheKeysToClear)); return systemSettings; } }
UpdateSystemSettingsExecution implements TaskHandlerExecutionStrategy<PrincipalActionContext> { @SuppressWarnings("unchecked") @Override public SystemSettings execute(final TaskHandlerActionContext<PrincipalActionContext> inActionContext) { log.info("updating system settings"); Set<String> cacheKeysToClear = new HashSet<String>(); Map<String, Serializable> fields = (Map<String, Serializable>) inActionContext.getActionContext().getParams(); HashSet<Person> admins = (HashSet<Person>) fields.get("admins"); fields.remove("ldapGroups"); fields.remove("admins"); SystemSettings systemSettings = finder.execute(null); updater.setProperties(systemSettings, fields); updateMapper.execute(null); for (Long personId : getSystemAdministratorIdsMapper.execute(null)) { cacheKeysToClear.add(CacheKeys.PERSON_BY_ID + personId); log.debug("Deleting existing system administrator with person id " + personId + " from cache before updating admin settings"); cache.delete(CacheKeys.PERSON_BY_ID + personId); } ArrayList<String> adminAccountIds = new ArrayList<String>(); for (Person person : admins) { adminAccountIds.add(person.getAccountId()); } List<Long> peopleIds = peopleIdsByAccountIdsMapper.execute(adminAccountIds); log.info("Setting system administrators to " + adminAccountIds); setSystemAdministratorsMapper.execute(adminAccountIds); for (Long personId : peopleIds) { log.debug("Deleting new system administrator with person id " + personId + " from cache before updating admin settings"); cacheKeysToClear.add(CacheKeys.PERSON_BY_ID + personId); cache.delete(CacheKeys.PERSON_BY_ID + personId); } log.debug("Deleting the system administrator ids from cache, now that they've changed."); cache.delete(CacheKeys.SYSTEM_ADMINISTRATOR_IDS); cacheKeysToClear.add(CacheKeys.SYSTEM_ADMINISTRATOR_IDS); inActionContext.getUserActionRequests().add( new UserActionRequest("deleteCacheKeysAction", null, (Serializable) cacheKeysToClear)); return systemSettings; } UpdateSystemSettingsExecution(final DomainMapper<MapperRequest, SystemSettings> inFinder,
            final UpdaterStrategy inUpdater, final UpdateMapper<SystemSettings> inupdateMapper,
            final DomainMapper<List<String>, Boolean> inSetSystemAdministratorsMapper,
            final DomainMapper<Serializable, List<Long>> inGetSystemAdministratorIdsMapper,
            final DomainMapper<List<String>, List<Long>> inPeopleIdsByAccountIdsMapper, final Cache inCache); }
UpdateSystemSettingsExecution implements TaskHandlerExecutionStrategy<PrincipalActionContext> { @SuppressWarnings("unchecked") @Override public SystemSettings execute(final TaskHandlerActionContext<PrincipalActionContext> inActionContext) { log.info("updating system settings"); Set<String> cacheKeysToClear = new HashSet<String>(); Map<String, Serializable> fields = (Map<String, Serializable>) inActionContext.getActionContext().getParams(); HashSet<Person> admins = (HashSet<Person>) fields.get("admins"); fields.remove("ldapGroups"); fields.remove("admins"); SystemSettings systemSettings = finder.execute(null); updater.setProperties(systemSettings, fields); updateMapper.execute(null); for (Long personId : getSystemAdministratorIdsMapper.execute(null)) { cacheKeysToClear.add(CacheKeys.PERSON_BY_ID + personId); log.debug("Deleting existing system administrator with person id " + personId + " from cache before updating admin settings"); cache.delete(CacheKeys.PERSON_BY_ID + personId); } ArrayList<String> adminAccountIds = new ArrayList<String>(); for (Person person : admins) { adminAccountIds.add(person.getAccountId()); } List<Long> peopleIds = peopleIdsByAccountIdsMapper.execute(adminAccountIds); log.info("Setting system administrators to " + adminAccountIds); setSystemAdministratorsMapper.execute(adminAccountIds); for (Long personId : peopleIds) { log.debug("Deleting new system administrator with person id " + personId + " from cache before updating admin settings"); cacheKeysToClear.add(CacheKeys.PERSON_BY_ID + personId); cache.delete(CacheKeys.PERSON_BY_ID + personId); } log.debug("Deleting the system administrator ids from cache, now that they've changed."); cache.delete(CacheKeys.SYSTEM_ADMINISTRATOR_IDS); cacheKeysToClear.add(CacheKeys.SYSTEM_ADMINISTRATOR_IDS); inActionContext.getUserActionRequests().add( new UserActionRequest("deleteCacheKeysAction", null, (Serializable) cacheKeysToClear)); return systemSettings; } UpdateSystemSettingsExecution(final DomainMapper<MapperRequest, SystemSettings> inFinder,
            final UpdaterStrategy inUpdater, final UpdateMapper<SystemSettings> inupdateMapper,
            final DomainMapper<List<String>, Boolean> inSetSystemAdministratorsMapper,
            final DomainMapper<Serializable, List<Long>> inGetSystemAdministratorIdsMapper,
            final DomainMapper<List<String>, List<Long>> inPeopleIdsByAccountIdsMapper, final Cache inCache); @SuppressWarnings("unchecked") @Override SystemSettings execute(final TaskHandlerActionContext<PrincipalActionContext> inActionContext); }
UpdateSystemSettingsExecution implements TaskHandlerExecutionStrategy<PrincipalActionContext> { @SuppressWarnings("unchecked") @Override public SystemSettings execute(final TaskHandlerActionContext<PrincipalActionContext> inActionContext) { log.info("updating system settings"); Set<String> cacheKeysToClear = new HashSet<String>(); Map<String, Serializable> fields = (Map<String, Serializable>) inActionContext.getActionContext().getParams(); HashSet<Person> admins = (HashSet<Person>) fields.get("admins"); fields.remove("ldapGroups"); fields.remove("admins"); SystemSettings systemSettings = finder.execute(null); updater.setProperties(systemSettings, fields); updateMapper.execute(null); for (Long personId : getSystemAdministratorIdsMapper.execute(null)) { cacheKeysToClear.add(CacheKeys.PERSON_BY_ID + personId); log.debug("Deleting existing system administrator with person id " + personId + " from cache before updating admin settings"); cache.delete(CacheKeys.PERSON_BY_ID + personId); } ArrayList<String> adminAccountIds = new ArrayList<String>(); for (Person person : admins) { adminAccountIds.add(person.getAccountId()); } List<Long> peopleIds = peopleIdsByAccountIdsMapper.execute(adminAccountIds); log.info("Setting system administrators to " + adminAccountIds); setSystemAdministratorsMapper.execute(adminAccountIds); for (Long personId : peopleIds) { log.debug("Deleting new system administrator with person id " + personId + " from cache before updating admin settings"); cacheKeysToClear.add(CacheKeys.PERSON_BY_ID + personId); cache.delete(CacheKeys.PERSON_BY_ID + personId); } log.debug("Deleting the system administrator ids from cache, now that they've changed."); cache.delete(CacheKeys.SYSTEM_ADMINISTRATOR_IDS); cacheKeysToClear.add(CacheKeys.SYSTEM_ADMINISTRATOR_IDS); inActionContext.getUserActionRequests().add( new UserActionRequest("deleteCacheKeysAction", null, (Serializable) cacheKeysToClear)); return systemSettings; } UpdateSystemSettingsExecution(final DomainMapper<MapperRequest, SystemSettings> inFinder,
            final UpdaterStrategy inUpdater, final UpdateMapper<SystemSettings> inupdateMapper,
            final DomainMapper<List<String>, Boolean> inSetSystemAdministratorsMapper,
            final DomainMapper<Serializable, List<Long>> inGetSystemAdministratorIdsMapper,
            final DomainMapper<List<String>, List<Long>> inPeopleIdsByAccountIdsMapper, final Cache inCache); @SuppressWarnings("unchecked") @Override SystemSettings execute(final TaskHandlerActionContext<PrincipalActionContext> inActionContext);  }