use of org.akaza.openclinica.control.form.Validator in project OpenClinica by OpenClinica.
the class ConfigurePasswordRequirementsServlet method processRequest.
@Override
protected void processRequest() throws Exception {
FormProcessor fp = new FormProcessor(request);
ConfigurationDao configurationDao = SpringServletAccess.getApplicationContext(context).getBean(ConfigurationDao.class);
PasswordRequirementsDao passwordRequirementsDao = new PasswordRequirementsDao(configurationDao);
if (!fp.isSubmitted()) {
setPresetValues(new HashMap<String, Object>(passwordRequirementsDao.configs()));
forwardPage(Page.CONFIGURATION_PASSWORD_REQUIREMENTS);
} else {
Validator v = new Validator(request);
for (String key : passwordRequirementsDao.intConfigKeys()) {
v.addValidation(key, Validator.IS_AN_INTEGER);
}
HashMap<?, ?> errors = v.validate();
int minChars = fp.getInt("pwd.chars.min");
int maxChars = fp.getInt("pwd.chars.max");
if (minChars > 0 && maxChars > 0 && maxChars < minChars) {
Validator.addError(errors, "pwd.chars.min", resexception.getString("pwd_min_greater_than_max"));
}
if (errors.isEmpty()) {
passwordRequirementsDao.setHasLower(Boolean.valueOf(fp.getString("pwd.chars.case.lower")));
passwordRequirementsDao.setHasUpper(Boolean.valueOf(fp.getString("pwd.chars.case.upper")));
passwordRequirementsDao.setHasDigits(Boolean.valueOf(fp.getString("pwd.chars.digits")));
passwordRequirementsDao.setHasSpecials(Boolean.valueOf(fp.getString("pwd.chars.specials")));
passwordRequirementsDao.setMinLength(fp.getInt("pwd.chars.min"));
passwordRequirementsDao.setMaxLength(fp.getInt("pwd.chars.max"));
passwordRequirementsDao.setExpirationDays(fp.getInt("pwd.expiration.days"));
passwordRequirementsDao.setChangeRequired(fp.getInt("pwd.change.required"));
addPageMessage(respage.getString("password_req_changes_have_been_saved"));
forwardPage(Page.LIST_USER_ACCOUNTS_SERVLET);
} else {
setPresetValues(submittedValues(passwordRequirementsDao, fp));
setInputMessages(errors);
forwardPage(Page.CONFIGURATION_PASSWORD_REQUIREMENTS);
}
}
}
use of org.akaza.openclinica.control.form.Validator in project OpenClinica by OpenClinica.
the class ConfigureServlet method processRequest.
@SuppressWarnings("unchecked")
@Override
protected void processRequest() throws Exception {
FormProcessor fp = new FormProcessor(request);
if (!fp.isSubmitted()) {
loadPresetValuesFromBean(fp);
setPresetValues(fp.getPresetValues());
forwardPage(Page.CONFIGURATION);
} else {
Validator v = new Validator(request);
v.addValidation("lockcount", Validator.IS_AN_INTEGER);
v.addValidation("lockcount", Validator.NO_BLANKS);
v.addValidation("lockcount", Validator.IS_IN_RANGE, 1, 25);
HashMap errors = v.validate();
if (!errors.isEmpty()) {
loadPresetValuesFromForm(fp);
setPresetValues(fp.getPresetValues());
setInputMessages(errors);
forwardPage(Page.CONFIGURATION);
} else {
ConfigurationBean userLockSwitch = getConfigurationDao().findByKey("user.lock.switch");
ConfigurationBean userLockAllowedFailedConsecutiveLoginAttempts = getConfigurationDao().findByKey("user.lock.allowedFailedConsecutiveLoginAttempts");
userLockSwitch.setValue(fp.getString("lockswitch"));
userLockAllowedFailedConsecutiveLoginAttempts.setValue(fp.getString("lockcount"));
getConfigurationDao().saveOrUpdate(userLockSwitch);
getConfigurationDao().saveOrUpdate(userLockAllowedFailedConsecutiveLoginAttempts);
addPageMessage(respage.getString("lockout_changes_have_been_saved"));
forwardPage(Page.LIST_USER_ACCOUNTS_SERVLET);
}
}
}
use of org.akaza.openclinica.control.form.Validator in project OpenClinica by OpenClinica.
the class CreateJobExportServlet method validateForm.
public HashMap validateForm(FormProcessor fp, HttpServletRequest request, String[] triggerNames, String properName) {
Validator v = new Validator(request);
v.addValidation(JOB_NAME, Validator.NO_BLANKS);
v.addValidation(JOB_NAME, Validator.NO_LEADING_OR_TRAILING_SPACES);
// need to be unique too
v.addValidation(JOB_DESC, Validator.NO_BLANKS);
v.addValidation(EMAIL, Validator.IS_A_EMAIL);
v.addValidation(PERIOD, Validator.NO_BLANKS);
v.addValidation(DATE_START_JOB + "Date", Validator.IS_A_DATE);
// v.addValidation(DATE_START_JOB + "Date", new Date(), Validator.DATE_IS_AFTER_OR_EQUAL);
// TODO job names will have to be unique, tbh
int formatId = fp.getInt(FORMAT_ID);
Date jobDate = fp.getDateTime(DATE_START_JOB);
HashMap errors = v.validate();
if (formatId == 0) {
// throw an error here, at least one should work
// errors.put(TAB, "Error Message - Pick one of the below");
v.addError(errors, FORMAT_ID, "Please pick at least one.");
}
for (String triggerName : triggerNames) {
if (triggerName.equals(fp.getString(JOB_NAME)) && !triggerName.equals(properName)) {
v.addError(errors, JOB_NAME, "A job with that name already exists. Please pick another name.");
}
}
if (jobDate.before(new Date())) {
v.addError(errors, DATE_START_JOB + "Date", "This date needs to be later than the present time.");
}
// @pgawade 20-April-2011 Limit the job description to 250 characters
String jobDesc = fp.getString(JOB_DESC);
if (null != jobDesc && !jobDesc.equals("")) {
if (jobDesc.length() > 250) {
v.addError(errors, JOB_DESC, "A job description cannot be more than 250 characters.");
}
}
return errors;
}
use of org.akaza.openclinica.control.form.Validator in project OpenClinica by OpenClinica.
the class UpdateCRFServlet method confirmCRF.
/**
*
* @throws Exception
*/
private void confirmCRF() throws Exception {
Validator v = new Validator(request);
FormProcessor fp = new FormProcessor(request);
v.addValidation("name", Validator.NO_BLANKS);
v.addValidation("name", Validator.LENGTH_NUMERIC_COMPARISON, NumericComparisonOperator.LESS_THAN_OR_EQUAL_TO, 255);
// v.addValidation("description", Validator.NO_BLANKS);
v.addValidation("description", Validator.LENGTH_NUMERIC_COMPARISON, NumericComparisonOperator.LESS_THAN_OR_EQUAL_TO, 2048);
errors = v.validate();
if (!StringUtil.isBlank(fp.getString("name"))) {
CRFDAO cdao = new CRFDAO(sm.getDataSource());
CRFBean crf = (CRFBean) session.getAttribute(CRF);
CRFBean crf1 = (CRFBean) cdao.findAnotherByName(fp.getString("name").trim(), crf.getId());
logger.info("crf:" + crf.getName() + crf.getId());
logger.info("crf1:" + crf1.getName() + crf1.getId());
if (crf1.getId() > 0) {
Validator.addError(errors, "name", resexception.getString("CRF_name_used_by_another_CRF_choose_unique"));
}
}
if (!errors.isEmpty()) {
logger.info("has errors");
request.setAttribute("formMessages", errors);
forwardPage(Page.UPDATE_CRF);
} else {
logger.info("no errors");
CRFBean crf = (CRFBean) session.getAttribute(CRF);
crf.setName(fp.getString("name"));
crf.setDescription(fp.getString("description"));
session.setAttribute(CRF, crf);
forwardPage(Page.UPDATE_CRF_CONFIRM);
}
}
use of org.akaza.openclinica.control.form.Validator in project OpenClinica by OpenClinica.
the class UpdateJobExportServlet method validateForm.
public HashMap validateForm(FormProcessor fp, HttpServletRequest request, String[] triggerNames, String properName) {
Validator v = new Validator(request);
v.addValidation(JOB_NAME, Validator.NO_BLANKS);
v.addValidation(JOB_NAME, Validator.NO_LEADING_OR_TRAILING_SPACES);
// need to be unique too
v.addValidation(JOB_DESC, Validator.NO_BLANKS);
v.addValidation(EMAIL, Validator.IS_A_EMAIL);
v.addValidation(PERIOD, Validator.NO_BLANKS);
v.addValidation(DATE_START_JOB + "Date", Validator.IS_A_DATE);
// v.addValidation(DATE_START_JOB + "Date", new Date(), Validator.DATE_IS_AFTER_OR_EQUAL);
// TODO job names will have to be unique, tbh
int formatId = fp.getInt(FORMAT_ID);
Date jobDate = fp.getDateTime(DATE_START_JOB);
HashMap errors = v.validate();
if (formatId == 0) {
// throw an error here, at least one should work
// errors.put(TAB, "Error Message - Pick one of the below");
v.addError(errors, FORMAT_ID, "Please pick at least one.");
}
for (String triggerName : triggerNames) {
if (triggerName.equals(fp.getString(JOB_NAME)) && !triggerName.equals(properName)) {
v.addError(errors, JOB_NAME, "A job with that name already exists. Please pick another name.");
}
}
if (jobDate.before(new Date())) {
v.addError(errors, DATE_START_JOB + "Date", "This date needs to be later than the present time.");
}
return errors;
}
Aggregations