*/
@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);
// Verify that group with given short name doesn't already exist.
if (getGroupMapper().findByShortName(inGroup.getShortName()) != null)
{
ve.addError(SHORTNAME_KEY, DUP_SHORTNAME_MSG);
}
// Verify that group has on coordinator.
if (inGroup.getCoordinators().isEmpty())
{
ve.addError("coordinators", "Group must have at least one coordinator");
}
if (!ve.getErrors().isEmpty())
{
throw ve;
}
// if the system requires approval to create groups, set the pending state to true.
boolean isPending = true;
if (settings.getAllUsersCanCreateGroups()
|| getSystemAdministratorIdsMapper.execute(null).contains(creatorPersonId))
{
isPending = false;
}
inGroup.setPending(isPending);
// Set the current user to the createdby person.
inGroup.setCreatedBy(personMapper.findByAccountId(creatorUserName));
getGroupMapper().insert(inGroup);
// sets the destination entity id for the group's stream scope
inGroup.getStreamScope().setDestinationEntityId(inGroup.getId());
queueAsyncAction(inActionContext, inGroup, false);
// Make all coordinators follow/join the new group
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());
}
// trigger notification if group will be pending approval
if (isPending)