@Test public void testCreate() { final Set<Person> people = new HashSet<Person>(); final List<UserActionRequest> list = new ArrayList<UserActionRequest>(); people.add(person1); people.add(person2); people.add(person3); context.checking(new Expectations() { { allowing(source).getPeople(); will(returnValue(people)); allowing(personIdsByLockedStatusDAO).execute(false); will(returnValue(new ArrayList<String>())); allowing(personIdsByLockedStatusDAO).execute(true); will(returnValue(new ArrayList<String>())); allowing(settingsMapper).execute(null); will(returnValue(settings)); allowing(settings).getSendWelcomeEmails(); will(returnValue(false)); allowing(person3).getAccountId(); will(returnValue("p3")); allowing(person2).getAccountId(); will(returnValue("p2")); allowing(person1).getAccountId(); will(returnValue("p1")); allowing(person3).getDisplayName(); will(returnValue("p3")); allowing(person2).getDisplayName(); will(returnValue("p2")); allowing(person1).getDisplayName(); will(returnValue("p1")); allowing(actionContext).getUserActionRequests(); will(returnValue(list)); } }); sut.execute(actionContext); assertEquals(3, list.size()); assertEquals("create", list.get(0).getActionKey()); context.assertIsSatisfied(); }
@Override public Serializable execute(final TaskHandlerActionContext<ActionContext> inActionContext) { log.info("Getting users from PersonSource ids..."); Long start = System.currentTimeMillis(); Set<Person> people = source.getPeople(); Long time = System.currentTimeMillis() - start; log.info("Found " + people.size() + " users to refresh (" + time + "ms)."); log.info("Getting all unlocked user ids..."); Set<String> unLockedUserAccountIds = new HashSet<String>(personIdsByLockedStatusDAO.execute(false)); log.info("Found " + unLockedUserAccountIds.size() + " currently unlocked user accounts."); log.info("Getting all locked user ids..."); Set<String> lockedUserAccountIds = new HashSet<String>(personIdsByLockedStatusDAO.execute(true)); log.info("Found " + lockedUserAccountIds.size() + " currently locked user accounts."); boolean queueCreatePerson = createPersonActionKey != null && !createPersonActionKey.isEmpty(); boolean queueLockAccounts = lockPersonActionKey != null && !lockPersonActionKey.isEmpty(); SystemSettings settings = settingsMapper.execute(null); boolean shouldSendEmail = settings.getSendWelcomeEmails(); int toLock = 0; int toUnlock = 0; int toCreate = 0; for (Person p : people) { String acctId = p.getAccountId(); if (lockedUserAccountIds.contains(acctId)) { if (log.isInfoEnabled()) { log.info("Found user AcctId: " + acctId + " (" + p.getDisplayName() + ") to be unlocked."); } inActionContext.getUserActionRequests().add(new UserActionRequest(refreshPersonActionKey, null, p)); if (queueLockAccounts) { inActionContext.getUserActionRequests().add( new UserActionRequest(lockPersonActionKey, null, new SetPersonLockedStatusRequest(acctId, false))); } toUnlock++; } else if (unLockedUserAccountIds.contains(acctId)) { log.debug("Queuing up a refresh of person: " + acctId); inActionContext.getUserActionRequests().add(new UserActionRequest(refreshPersonActionKey, null, p)); unLockedUserAccountIds.remove(acctId); } else { if (log.isInfoEnabled()) { log.info("Found user id: " + acctId + " (" + p.getDisplayName() + ") to be created."); } if (queueCreatePerson) { inActionContext.getUserActionRequests().add( new UserActionRequest(createPersonActionKey, null, new CreatePersonRequest(p, shouldSendEmail))); } toCreate++; } } toLock = unLockedUserAccountIds.size(); log.info("Determined there are " + unLockedUserAccountIds.size() + " user accounts to lock."); for (String id : unLockedUserAccountIds) { if (log.isInfoEnabled()) { log.info("Found user AcctId: " + id + " to be locked."); } if (queueLockAccounts) { inActionContext.getUserActionRequests().add( new UserActionRequest(lockPersonActionKey, null, new SetPersonLockedStatusRequest(id, true))); } } log.info("Summary: Lock: " + toLock + " unlock: " + toUnlock + " Create: " + toCreate + ". LOCK-UNLOCK ENABLED: " + queueLockAccounts + " CREATE ENABLED: " + queueCreatePerson); return null; }
RefreshPeopleExecution implements TaskHandlerExecutionStrategy<ActionContext> { @Override public Serializable execute(final TaskHandlerActionContext<ActionContext> inActionContext) { log.info("Getting users from PersonSource ids..."); Long start = System.currentTimeMillis(); Set<Person> people = source.getPeople(); Long time = System.currentTimeMillis() - start; log.info("Found " + people.size() + " users to refresh (" + time + "ms)."); log.info("Getting all unlocked user ids..."); Set<String> unLockedUserAccountIds = new HashSet<String>(personIdsByLockedStatusDAO.execute(false)); log.info("Found " + unLockedUserAccountIds.size() + " currently unlocked user accounts."); log.info("Getting all locked user ids..."); Set<String> lockedUserAccountIds = new HashSet<String>(personIdsByLockedStatusDAO.execute(true)); log.info("Found " + lockedUserAccountIds.size() + " currently locked user accounts."); boolean queueCreatePerson = createPersonActionKey != null && !createPersonActionKey.isEmpty(); boolean queueLockAccounts = lockPersonActionKey != null && !lockPersonActionKey.isEmpty(); SystemSettings settings = settingsMapper.execute(null); boolean shouldSendEmail = settings.getSendWelcomeEmails(); int toLock = 0; int toUnlock = 0; int toCreate = 0; for (Person p : people) { String acctId = p.getAccountId(); if (lockedUserAccountIds.contains(acctId)) { if (log.isInfoEnabled()) { log.info("Found user AcctId: " + acctId + " (" + p.getDisplayName() + ") to be unlocked."); } inActionContext.getUserActionRequests().add(new UserActionRequest(refreshPersonActionKey, null, p)); if (queueLockAccounts) { inActionContext.getUserActionRequests().add( new UserActionRequest(lockPersonActionKey, null, new SetPersonLockedStatusRequest(acctId, false))); } toUnlock++; } else if (unLockedUserAccountIds.contains(acctId)) { log.debug("Queuing up a refresh of person: " + acctId); inActionContext.getUserActionRequests().add(new UserActionRequest(refreshPersonActionKey, null, p)); unLockedUserAccountIds.remove(acctId); } else { if (log.isInfoEnabled()) { log.info("Found user id: " + acctId + " (" + p.getDisplayName() + ") to be created."); } if (queueCreatePerson) { inActionContext.getUserActionRequests().add( new UserActionRequest(createPersonActionKey, null, new CreatePersonRequest(p, shouldSendEmail))); } toCreate++; } } toLock = unLockedUserAccountIds.size(); log.info("Determined there are " + unLockedUserAccountIds.size() + " user accounts to lock."); for (String id : unLockedUserAccountIds) { if (log.isInfoEnabled()) { log.info("Found user AcctId: " + id + " to be locked."); } if (queueLockAccounts) { inActionContext.getUserActionRequests().add( new UserActionRequest(lockPersonActionKey, null, new SetPersonLockedStatusRequest(id, true))); } } log.info("Summary: Lock: " + toLock + " unlock: " + toUnlock + " Create: " + toCreate + ". LOCK-UNLOCK ENABLED: " + queueLockAccounts + " CREATE ENABLED: " + queueCreatePerson); return null; } }
RefreshPeopleExecution implements TaskHandlerExecutionStrategy<ActionContext> { @Override public Serializable execute(final TaskHandlerActionContext<ActionContext> inActionContext) { log.info("Getting users from PersonSource ids..."); Long start = System.currentTimeMillis(); Set<Person> people = source.getPeople(); Long time = System.currentTimeMillis() - start; log.info("Found " + people.size() + " users to refresh (" + time + "ms)."); log.info("Getting all unlocked user ids..."); Set<String> unLockedUserAccountIds = new HashSet<String>(personIdsByLockedStatusDAO.execute(false)); log.info("Found " + unLockedUserAccountIds.size() + " currently unlocked user accounts."); log.info("Getting all locked user ids..."); Set<String> lockedUserAccountIds = new HashSet<String>(personIdsByLockedStatusDAO.execute(true)); log.info("Found " + lockedUserAccountIds.size() + " currently locked user accounts."); boolean queueCreatePerson = createPersonActionKey != null && !createPersonActionKey.isEmpty(); boolean queueLockAccounts = lockPersonActionKey != null && !lockPersonActionKey.isEmpty(); SystemSettings settings = settingsMapper.execute(null); boolean shouldSendEmail = settings.getSendWelcomeEmails(); int toLock = 0; int toUnlock = 0; int toCreate = 0; for (Person p : people) { String acctId = p.getAccountId(); if (lockedUserAccountIds.contains(acctId)) { if (log.isInfoEnabled()) { log.info("Found user AcctId: " + acctId + " (" + p.getDisplayName() + ") to be unlocked."); } inActionContext.getUserActionRequests().add(new UserActionRequest(refreshPersonActionKey, null, p)); if (queueLockAccounts) { inActionContext.getUserActionRequests().add( new UserActionRequest(lockPersonActionKey, null, new SetPersonLockedStatusRequest(acctId, false))); } toUnlock++; } else if (unLockedUserAccountIds.contains(acctId)) { log.debug("Queuing up a refresh of person: " + acctId); inActionContext.getUserActionRequests().add(new UserActionRequest(refreshPersonActionKey, null, p)); unLockedUserAccountIds.remove(acctId); } else { if (log.isInfoEnabled()) { log.info("Found user id: " + acctId + " (" + p.getDisplayName() + ") to be created."); } if (queueCreatePerson) { inActionContext.getUserActionRequests().add( new UserActionRequest(createPersonActionKey, null, new CreatePersonRequest(p, shouldSendEmail))); } toCreate++; } } toLock = unLockedUserAccountIds.size(); log.info("Determined there are " + unLockedUserAccountIds.size() + " user accounts to lock."); for (String id : unLockedUserAccountIds) { if (log.isInfoEnabled()) { log.info("Found user AcctId: " + id + " to be locked."); } if (queueLockAccounts) { inActionContext.getUserActionRequests().add( new UserActionRequest(lockPersonActionKey, null, new SetPersonLockedStatusRequest(id, true))); } } log.info("Summary: Lock: " + toLock + " unlock: " + toUnlock + " Create: " + toCreate + ". LOCK-UNLOCK ENABLED: " + queueLockAccounts + " CREATE ENABLED: " + queueCreatePerson); return null; } RefreshPeopleExecution(final PersonSource inSource, final String inCreatePersonActionKey,
            final String inLockPersonAccountActionKey, final String inRefreshPersonActionKey,
            final DomainMapper<Boolean, List<String>> inGetPersonIdsByLockedStatus,
            final DomainMapper<MapperRequest, SystemSettings> inSettingsMapper); }
RefreshPeopleExecution implements TaskHandlerExecutionStrategy<ActionContext> { @Override public Serializable execute(final TaskHandlerActionContext<ActionContext> inActionContext) { log.info("Getting users from PersonSource ids..."); Long start = System.currentTimeMillis(); Set<Person> people = source.getPeople(); Long time = System.currentTimeMillis() - start; log.info("Found " + people.size() + " users to refresh (" + time + "ms)."); log.info("Getting all unlocked user ids..."); Set<String> unLockedUserAccountIds = new HashSet<String>(personIdsByLockedStatusDAO.execute(false)); log.info("Found " + unLockedUserAccountIds.size() + " currently unlocked user accounts."); log.info("Getting all locked user ids..."); Set<String> lockedUserAccountIds = new HashSet<String>(personIdsByLockedStatusDAO.execute(true)); log.info("Found " + lockedUserAccountIds.size() + " currently locked user accounts."); boolean queueCreatePerson = createPersonActionKey != null && !createPersonActionKey.isEmpty(); boolean queueLockAccounts = lockPersonActionKey != null && !lockPersonActionKey.isEmpty(); SystemSettings settings = settingsMapper.execute(null); boolean shouldSendEmail = settings.getSendWelcomeEmails(); int toLock = 0; int toUnlock = 0; int toCreate = 0; for (Person p : people) { String acctId = p.getAccountId(); if (lockedUserAccountIds.contains(acctId)) { if (log.isInfoEnabled()) { log.info("Found user AcctId: " + acctId + " (" + p.getDisplayName() + ") to be unlocked."); } inActionContext.getUserActionRequests().add(new UserActionRequest(refreshPersonActionKey, null, p)); if (queueLockAccounts) { inActionContext.getUserActionRequests().add( new UserActionRequest(lockPersonActionKey, null, new SetPersonLockedStatusRequest(acctId, false))); } toUnlock++; } else if (unLockedUserAccountIds.contains(acctId)) { log.debug("Queuing up a refresh of person: " + acctId); inActionContext.getUserActionRequests().add(new UserActionRequest(refreshPersonActionKey, null, p)); unLockedUserAccountIds.remove(acctId); } else { if (log.isInfoEnabled()) { log.info("Found user id: " + acctId + " (" + p.getDisplayName() + ") to be created."); } if (queueCreatePerson) { inActionContext.getUserActionRequests().add( new UserActionRequest(createPersonActionKey, null, new CreatePersonRequest(p, shouldSendEmail))); } toCreate++; } } toLock = unLockedUserAccountIds.size(); log.info("Determined there are " + unLockedUserAccountIds.size() + " user accounts to lock."); for (String id : unLockedUserAccountIds) { if (log.isInfoEnabled()) { log.info("Found user AcctId: " + id + " to be locked."); } if (queueLockAccounts) { inActionContext.getUserActionRequests().add( new UserActionRequest(lockPersonActionKey, null, new SetPersonLockedStatusRequest(id, true))); } } log.info("Summary: Lock: " + toLock + " unlock: " + toUnlock + " Create: " + toCreate + ". LOCK-UNLOCK ENABLED: " + queueLockAccounts + " CREATE ENABLED: " + queueCreatePerson); return null; } RefreshPeopleExecution(final PersonSource inSource, final String inCreatePersonActionKey,
            final String inLockPersonAccountActionKey, final String inRefreshPersonActionKey,
            final DomainMapper<Boolean, List<String>> inGetPersonIdsByLockedStatus,
            final DomainMapper<MapperRequest, SystemSettings> inSettingsMapper); @Override Serializable execute(final TaskHandlerActionContext<ActionContext> inActionContext); }
RefreshPeopleExecution implements TaskHandlerExecutionStrategy<ActionContext> { @Override public Serializable execute(final TaskHandlerActionContext<ActionContext> inActionContext) { log.info("Getting users from PersonSource ids..."); Long start = System.currentTimeMillis(); Set<Person> people = source.getPeople(); Long time = System.currentTimeMillis() - start; log.info("Found " + people.size() + " users to refresh (" + time + "ms)."); log.info("Getting all unlocked user ids..."); Set<String> unLockedUserAccountIds = new HashSet<String>(personIdsByLockedStatusDAO.execute(false)); log.info("Found " + unLockedUserAccountIds.size() + " currently unlocked user accounts."); log.info("Getting all locked user ids..."); Set<String> lockedUserAccountIds = new HashSet<String>(personIdsByLockedStatusDAO.execute(true)); log.info("Found " + lockedUserAccountIds.size() + " currently locked user accounts."); boolean queueCreatePerson = createPersonActionKey != null && !createPersonActionKey.isEmpty(); boolean queueLockAccounts = lockPersonActionKey != null && !lockPersonActionKey.isEmpty(); SystemSettings settings = settingsMapper.execute(null); boolean shouldSendEmail = settings.getSendWelcomeEmails(); int toLock = 0; int toUnlock = 0; int toCreate = 0; for (Person p : people) { String acctId = p.getAccountId(); if (lockedUserAccountIds.contains(acctId)) { if (log.isInfoEnabled()) { log.info("Found user AcctId: " + acctId + " (" + p.getDisplayName() + ") to be unlocked."); } inActionContext.getUserActionRequests().add(new UserActionRequest(refreshPersonActionKey, null, p)); if (queueLockAccounts) { inActionContext.getUserActionRequests().add( new UserActionRequest(lockPersonActionKey, null, new SetPersonLockedStatusRequest(acctId, false))); } toUnlock++; } else if (unLockedUserAccountIds.contains(acctId)) { log.debug("Queuing up a refresh of person: " + acctId); inActionContext.getUserActionRequests().add(new UserActionRequest(refreshPersonActionKey, null, p)); unLockedUserAccountIds.remove(acctId); } else { if (log.isInfoEnabled()) { log.info("Found user id: " + acctId + " (" + p.getDisplayName() + ") to be created."); } if (queueCreatePerson) { inActionContext.getUserActionRequests().add( new UserActionRequest(createPersonActionKey, null, new CreatePersonRequest(p, shouldSendEmail))); } toCreate++; } } toLock = unLockedUserAccountIds.size(); log.info("Determined there are " + unLockedUserAccountIds.size() + " user accounts to lock."); for (String id : unLockedUserAccountIds) { if (log.isInfoEnabled()) { log.info("Found user AcctId: " + id + " to be locked."); } if (queueLockAccounts) { inActionContext.getUserActionRequests().add( new UserActionRequest(lockPersonActionKey, null, new SetPersonLockedStatusRequest(id, true))); } } log.info("Summary: Lock: " + toLock + " unlock: " + toUnlock + " Create: " + toCreate + ". LOCK-UNLOCK ENABLED: " + queueLockAccounts + " CREATE ENABLED: " + queueCreatePerson); return null; } RefreshPeopleExecution(final PersonSource inSource, final String inCreatePersonActionKey,
            final String inLockPersonAccountActionKey, final String inRefreshPersonActionKey,
            final DomainMapper<Boolean, List<String>> inGetPersonIdsByLockedStatus,
            final DomainMapper<MapperRequest, SystemSettings> inSettingsMapper); @Override Serializable execute(final TaskHandlerActionContext<ActionContext> inActionContext);  }