// TODO: refactor to get better validation.
Map<String, Serializable> fields = (Map<String, Serializable>) inActionContext.getParams();
if (fields == null)
{
throw new ValidationException("UpdateSystemSettings requires Map of form data");
}
ValidationException ve = new ValidationException();
if (fields.containsKey("ldapGroups") && ((List<MembershipCriteria>) fields.get("ldapGroups")).size() == 0)
{
ve.addError("ldapGroups", "At least one entry is required in the access list");
}
if (fields.containsKey("contentWarningText") && fields.get("contentWarningText") == null)
{
ve.addError("contentWarningText", CONTENT_WARNING_REQUIRED_ERROR_MESSAGE);
}
else if (fields.containsKey("contentWarningText")
&& ((String) fields.get("contentWarningText")).length() > SystemSettings.MAX_INPUT)
{
ve.addError("contentWarningText", CONTENT_WARNING_LENGTH_ERROR_MESSAGE);
}
if (fields.containsKey("siteLabel") && fields.get("siteLabel") == null)
{
ve.addError("siteLabel", SITE_LABEL_REQUIRED_ERROR_MESSAGE);
}
else if (fields.containsKey("siteLabel")
&& ((String) fields.get("siteLabel")).length() > SystemSettings.MAX_SITELABEL_INPUT)
{
ve.addError("siteLabel", SITE_LABEL_LENGTH_ERROR_MESSAGE);
}
if (fields.containsKey("termsOfService") && fields.get("termsOfService") == null)
{
ve.addError("termsOfService", TOS_REQUIRED_ERROR_MESSAGE);
}
if (fields.containsKey("pluginWarning") && fields.get("pluginWarning") == null)
{
ve.addError("pluginWarning", PLUGIN_WARNING_REQUIRED_ERROR_MESSAGE);
}
if (fields.containsKey("contentExpiration") && fields.get("contentExpiration") == null)
{
ve.addError("contentExpiration", CONTENT_EXPIRATION_REQUIRED_ERROR_MESSAGE);
}
else if (fields.containsKey("contentExpiration") && !(fields.get("contentExpiration") instanceof Integer))
{
ve.addError("contentExpiration", CONTENT_EXPIRATION_ERROR_MESSAGE);
}
else if (fields.containsKey("contentExpiration") && fields.get("contentExpiration") != null
&& fields.get("contentExpiration") instanceof Integer
&& ((Integer) fields.get("contentExpiration") < SystemSettings.MIN_CONTENT_EXPIRATION //
|| (Integer) fields.get("contentExpiration") > SystemSettings.MAX_CONTENT_EXPIRATION))
{
ve.addError("contentExpiration", CONTENT_EXPIRATION_ERROR_MESSAGE);
}
if (fields.containsKey("tosPromptInterval") && !(fields.get("tosPromptInterval") instanceof Integer))
{
ve.addError("tosPromptInterval", TOS_PROMPT_INTERVAL_INVALID_ERROR_MESSAGE);
}
else if (fields.containsKey("tosPromptInterval")
&& (Integer) fields.get("tosPromptInterval") < SystemSettings.MIN_TOS_PROMPT_INTERVAL)
{
ve.addError("tosPromptInterval", MIN_TOS_PROMPT_INTERVAL_ERROR_MESSAGE);
}
if (!fields.containsKey("admins") || fields.get("admins") == null
|| ((HashSet<Person>) fields.get("admins")).size() == 0)
{
ve.addError("admins", SYSTEM_ADMINISTRATORS_EMPTY_ERROR_MESSAGE);
}
else
{
boolean adminErrorOccurred = false;
// see if the people exist
HashSet<Person> requestedAdmins = (HashSet<Person>) fields.get("admins");
List<Long> adminIds = new ArrayList<Long>();
// convert the list of people to people ids
for (Person person : requestedAdmins)
{
adminIds.add(person.getId());
}
// get the people from db/cache
List<PersonModelView> foundPeople = peopleByIdsMapper.execute(adminIds);
// check for locked users
String lockedUsers = "";
for (PersonModelView foundPerson : foundPeople)
{
if (foundPerson.isAccountLocked())
{
if (lockedUsers.length() > 0)
{
lockedUsers += ", ";
}
lockedUsers += foundPerson.getAccountId();
}
}
if (lockedUsers.length() > 0)
{
// some of the users are locked users
ve.addError("admins", SYSTEM_ADMINISTRATOR_LOCKED_OUT_ERROR_MESSAGE + lockedUsers);
adminErrorOccurred = true;
}
if (!adminErrorOccurred)
{
// check for missing users
String missingUsers = "";
for (Person requestedAdmin : requestedAdmins)
{
if (!isPersonIdInPersonList(foundPeople, requestedAdmin.getId()))
{
// missing person
if (missingUsers.length() > 0)
{
missingUsers += ", ";
}
missingUsers += requestedAdmin.getAccountId();
}
}
if (missingUsers.length() > 0)
{
// some of the users weren't found
ve.addError("admins", SYSTEM_ADMINISTRATOR_NOTFOUND_ERROR_MESSAGE + missingUsers);
}
}
}
if (!ve.getErrors().isEmpty())
{
throw ve;
}
}