{
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);