@Test(expected = ValidationException.class) public void persistFailedCoordinators() throws Exception { final DomainGroup dupGroup = context.mock(DomainGroup.class, "dupGroup"); final Set<Person> coordinators = new HashSet<Person>(); final long id = 1L; String newName = "NEW org name here"; final HashMap<String, Serializable> formData = new HashMap<String, Serializable>(); formData.put("id", Long.toString(id)); formData.put("name", newName); formData.put("shortName", "group1"); final SystemSettings settings = new SystemSettings(); settings.setAllUsersCanCreateGroups(false); context.checking(new Expectations() { { oneOf(getSystemSettingsMapper).execute(null); will(returnValue(settings)); allowing(groupMock).getShortName(); will(returnValue("group1")); oneOf(groupMock).getCoordinators(); will(returnValue(coordinators)); oneOf(groupMapperMock).findByShortName("group1"); will(returnValue(dupGroup)); } }); assertEquals(0, userActionRequests.size()); GroupCreator sut = new GroupCreator(groupMapperMock, personMapperMock, getSystemAdminIdsMapper, followStrategyMock, getSystemSettingsMapper); sut.persist(taskHandlerActionContext, formData, groupMock); assertEquals(0, userActionRequests.size()); }
@Override public void persist(final TaskHandlerActionContext<PrincipalActionContext> inActionContext, final Map<String, Serializable> inFields, final DomainGroup inGroup) throws Exception { final Principal principal = inActionContext.getActionContext().getPrincipal(); ValidationException ve = new ValidationException(); String creatorUserName = principal.getAccountId(); final Long creatorPersonId = principal.getId(); SystemSettings settings = getSystemSettingsMapper.execute(null); if (getGroupMapper().findByShortName(inGroup.getShortName()) != null) { ve.addError(SHORTNAME_KEY, DUP_SHORTNAME_MSG); } if (inGroup.getCoordinators().isEmpty()) { ve.addError("coordinators", "Group must have at least one coordinator"); } if (!ve.getErrors().isEmpty()) { throw ve; } boolean isPending = true; if (settings.getAllUsersCanCreateGroups() || getSystemAdministratorIdsMapper.execute(null).contains(creatorPersonId)) { isPending = false; } inGroup.setPending(isPending); inGroup.setCreatedBy(personMapper.findByAccountId(creatorUserName)); getGroupMapper().insert(inGroup); inGroup.getStreamScope().setDestinationEntityId(inGroup.getId()); queueAsyncAction(inActionContext, inGroup, false); for (Person coordinator : inGroup.getCoordinators()) { SetFollowingStatusByGroupCreatorRequest currentRequest = new SetFollowingStatusByGroupCreatorRequest( coordinator.getId(), inGroup.getId(), Follower.FollowerStatus.FOLLOWING, inGroup.getName(), inGroup.getShortName(), isPending); new InlineExecutionStrategyExecutor().execute(followStrategy, currentRequest, new DefaultPrincipal( creatorUserName, principal.getOpenSocialId(), creatorPersonId), inActionContext .getUserActionRequests()); } if (isPending) { inActionContext.getUserActionRequests().add( new UserActionRequest(CreateNotificationsRequest.ACTION_NAME, null, new TargetEntityNotificationsRequest(RequestType.REQUEST_NEW_GROUP, creatorPersonId, inGroup.getId()))); } }
GroupCreator extends GroupPersister { @Override public void persist(final TaskHandlerActionContext<PrincipalActionContext> inActionContext, final Map<String, Serializable> inFields, final DomainGroup inGroup) throws Exception { final Principal principal = inActionContext.getActionContext().getPrincipal(); ValidationException ve = new ValidationException(); String creatorUserName = principal.getAccountId(); final Long creatorPersonId = principal.getId(); SystemSettings settings = getSystemSettingsMapper.execute(null); if (getGroupMapper().findByShortName(inGroup.getShortName()) != null) { ve.addError(SHORTNAME_KEY, DUP_SHORTNAME_MSG); } if (inGroup.getCoordinators().isEmpty()) { ve.addError("coordinators", "Group must have at least one coordinator"); } if (!ve.getErrors().isEmpty()) { throw ve; } boolean isPending = true; if (settings.getAllUsersCanCreateGroups() || getSystemAdministratorIdsMapper.execute(null).contains(creatorPersonId)) { isPending = false; } inGroup.setPending(isPending); inGroup.setCreatedBy(personMapper.findByAccountId(creatorUserName)); getGroupMapper().insert(inGroup); inGroup.getStreamScope().setDestinationEntityId(inGroup.getId()); queueAsyncAction(inActionContext, inGroup, false); for (Person coordinator : inGroup.getCoordinators()) { SetFollowingStatusByGroupCreatorRequest currentRequest = new SetFollowingStatusByGroupCreatorRequest( coordinator.getId(), inGroup.getId(), Follower.FollowerStatus.FOLLOWING, inGroup.getName(), inGroup.getShortName(), isPending); new InlineExecutionStrategyExecutor().execute(followStrategy, currentRequest, new DefaultPrincipal( creatorUserName, principal.getOpenSocialId(), creatorPersonId), inActionContext .getUserActionRequests()); } if (isPending) { inActionContext.getUserActionRequests().add( new UserActionRequest(CreateNotificationsRequest.ACTION_NAME, null, new TargetEntityNotificationsRequest(RequestType.REQUEST_NEW_GROUP, creatorPersonId, inGroup.getId()))); } } }
GroupCreator extends GroupPersister { @Override public void persist(final TaskHandlerActionContext<PrincipalActionContext> inActionContext, final Map<String, Serializable> inFields, final DomainGroup inGroup) throws Exception { final Principal principal = inActionContext.getActionContext().getPrincipal(); ValidationException ve = new ValidationException(); String creatorUserName = principal.getAccountId(); final Long creatorPersonId = principal.getId(); SystemSettings settings = getSystemSettingsMapper.execute(null); if (getGroupMapper().findByShortName(inGroup.getShortName()) != null) { ve.addError(SHORTNAME_KEY, DUP_SHORTNAME_MSG); } if (inGroup.getCoordinators().isEmpty()) { ve.addError("coordinators", "Group must have at least one coordinator"); } if (!ve.getErrors().isEmpty()) { throw ve; } boolean isPending = true; if (settings.getAllUsersCanCreateGroups() || getSystemAdministratorIdsMapper.execute(null).contains(creatorPersonId)) { isPending = false; } inGroup.setPending(isPending); inGroup.setCreatedBy(personMapper.findByAccountId(creatorUserName)); getGroupMapper().insert(inGroup); inGroup.getStreamScope().setDestinationEntityId(inGroup.getId()); queueAsyncAction(inActionContext, inGroup, false); for (Person coordinator : inGroup.getCoordinators()) { SetFollowingStatusByGroupCreatorRequest currentRequest = new SetFollowingStatusByGroupCreatorRequest( coordinator.getId(), inGroup.getId(), Follower.FollowerStatus.FOLLOWING, inGroup.getName(), inGroup.getShortName(), isPending); new InlineExecutionStrategyExecutor().execute(followStrategy, currentRequest, new DefaultPrincipal( creatorUserName, principal.getOpenSocialId(), creatorPersonId), inActionContext .getUserActionRequests()); } if (isPending) { inActionContext.getUserActionRequests().add( new UserActionRequest(CreateNotificationsRequest.ACTION_NAME, null, new TargetEntityNotificationsRequest(RequestType.REQUEST_NEW_GROUP, creatorPersonId, inGroup.getId()))); } } GroupCreator(final DomainGroupMapper inGroupMapper, final PersonMapper inPersonMapper,
            final DomainMapper<Serializable, List<Long>> inGetSystemAdministratorIdsMapper,
            final TaskHandlerExecutionStrategy inFollowStrategy,
            final DomainMapper<MapperRequest, SystemSettings> inGetSystemSettingsMapper); }
GroupCreator extends GroupPersister { @Override public void persist(final TaskHandlerActionContext<PrincipalActionContext> inActionContext, final Map<String, Serializable> inFields, final DomainGroup inGroup) throws Exception { final Principal principal = inActionContext.getActionContext().getPrincipal(); ValidationException ve = new ValidationException(); String creatorUserName = principal.getAccountId(); final Long creatorPersonId = principal.getId(); SystemSettings settings = getSystemSettingsMapper.execute(null); if (getGroupMapper().findByShortName(inGroup.getShortName()) != null) { ve.addError(SHORTNAME_KEY, DUP_SHORTNAME_MSG); } if (inGroup.getCoordinators().isEmpty()) { ve.addError("coordinators", "Group must have at least one coordinator"); } if (!ve.getErrors().isEmpty()) { throw ve; } boolean isPending = true; if (settings.getAllUsersCanCreateGroups() || getSystemAdministratorIdsMapper.execute(null).contains(creatorPersonId)) { isPending = false; } inGroup.setPending(isPending); inGroup.setCreatedBy(personMapper.findByAccountId(creatorUserName)); getGroupMapper().insert(inGroup); inGroup.getStreamScope().setDestinationEntityId(inGroup.getId()); queueAsyncAction(inActionContext, inGroup, false); for (Person coordinator : inGroup.getCoordinators()) { SetFollowingStatusByGroupCreatorRequest currentRequest = new SetFollowingStatusByGroupCreatorRequest( coordinator.getId(), inGroup.getId(), Follower.FollowerStatus.FOLLOWING, inGroup.getName(), inGroup.getShortName(), isPending); new InlineExecutionStrategyExecutor().execute(followStrategy, currentRequest, new DefaultPrincipal( creatorUserName, principal.getOpenSocialId(), creatorPersonId), inActionContext .getUserActionRequests()); } if (isPending) { inActionContext.getUserActionRequests().add( new UserActionRequest(CreateNotificationsRequest.ACTION_NAME, null, new TargetEntityNotificationsRequest(RequestType.REQUEST_NEW_GROUP, creatorPersonId, inGroup.getId()))); } } GroupCreator(final DomainGroupMapper inGroupMapper, final PersonMapper inPersonMapper,
            final DomainMapper<Serializable, List<Long>> inGetSystemAdministratorIdsMapper,
            final TaskHandlerExecutionStrategy inFollowStrategy,
            final DomainMapper<MapperRequest, SystemSettings> inGetSystemSettingsMapper); @Override DomainGroup get(final TaskHandlerActionContext<PrincipalActionContext> inActionContext,
            final Map<String, Serializable> inFields); @Override void persist(final TaskHandlerActionContext<PrincipalActionContext> inActionContext,
            final Map<String, Serializable> inFields, final DomainGroup inGroup); }
GroupCreator extends GroupPersister { @Override public void persist(final TaskHandlerActionContext<PrincipalActionContext> inActionContext, final Map<String, Serializable> inFields, final DomainGroup inGroup) throws Exception { final Principal principal = inActionContext.getActionContext().getPrincipal(); ValidationException ve = new ValidationException(); String creatorUserName = principal.getAccountId(); final Long creatorPersonId = principal.getId(); SystemSettings settings = getSystemSettingsMapper.execute(null); if (getGroupMapper().findByShortName(inGroup.getShortName()) != null) { ve.addError(SHORTNAME_KEY, DUP_SHORTNAME_MSG); } if (inGroup.getCoordinators().isEmpty()) { ve.addError("coordinators", "Group must have at least one coordinator"); } if (!ve.getErrors().isEmpty()) { throw ve; } boolean isPending = true; if (settings.getAllUsersCanCreateGroups() || getSystemAdministratorIdsMapper.execute(null).contains(creatorPersonId)) { isPending = false; } inGroup.setPending(isPending); inGroup.setCreatedBy(personMapper.findByAccountId(creatorUserName)); getGroupMapper().insert(inGroup); inGroup.getStreamScope().setDestinationEntityId(inGroup.getId()); queueAsyncAction(inActionContext, inGroup, false); for (Person coordinator : inGroup.getCoordinators()) { SetFollowingStatusByGroupCreatorRequest currentRequest = new SetFollowingStatusByGroupCreatorRequest( coordinator.getId(), inGroup.getId(), Follower.FollowerStatus.FOLLOWING, inGroup.getName(), inGroup.getShortName(), isPending); new InlineExecutionStrategyExecutor().execute(followStrategy, currentRequest, new DefaultPrincipal( creatorUserName, principal.getOpenSocialId(), creatorPersonId), inActionContext .getUserActionRequests()); } if (isPending) { inActionContext.getUserActionRequests().add( new UserActionRequest(CreateNotificationsRequest.ACTION_NAME, null, new TargetEntityNotificationsRequest(RequestType.REQUEST_NEW_GROUP, creatorPersonId, inGroup.getId()))); } } GroupCreator(final DomainGroupMapper inGroupMapper, final PersonMapper inPersonMapper,
            final DomainMapper<Serializable, List<Long>> inGetSystemAdministratorIdsMapper,
            final TaskHandlerExecutionStrategy inFollowStrategy,
            final DomainMapper<MapperRequest, SystemSettings> inGetSystemSettingsMapper); @Override DomainGroup get(final TaskHandlerActionContext<PrincipalActionContext> inActionContext,
            final Map<String, Serializable> inFields); @Override void persist(final TaskHandlerActionContext<PrincipalActionContext> inActionContext,
            final Map<String, Serializable> inFields, final DomainGroup inGroup);  }