use of org.akaza.openclinica.control.form.Validator in project OpenClinica by OpenClinica.
the class TriggerService method validateImportJobForm.
public HashMap validateImportJobForm(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);
if (!"".equals(fp.getString(EMAIL))) {
v.addValidation(EMAIL, Validator.IS_A_EMAIL);
}
// << tbh we are now allowing email to be optional
// v.addValidation(PERIOD, Validator.NO_BLANKS);
// v.addValidation(DIRECTORY, Validator.NO_BLANKS);
// v.addValidation(DATE_START_JOB + "Date", Validator.IS_A_DATE);
// TODO job names will have to be unique, tbh
String hours = fp.getString("hours");
String minutes = fp.getString("minutes");
HashMap errors = v.validate();
if ((hours.equals("0")) && (minutes.equals("0"))) {
// System.out.println("got in the ERROR LOOP");
// throw an error here, at least one should be greater than zero
// errors.put(TAB, "Error Message - Pick one of the below");
v.addError(errors, "hours", "At least one of the following should be greater than zero.");
}
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.");
}
}
return errors;
}
use of org.akaza.openclinica.control.form.Validator in project OpenClinica by OpenClinica.
the class TriggerService method validateImportForm.
public HashMap validateImportForm(HttpServletRequest request) {
Validator v = new Validator(request);
HashMap errors = v.validate();
return errors;
}
use of org.akaza.openclinica.control.form.Validator in project OpenClinica by OpenClinica.
the class CreateUserAccountServlet method processRequest.
@Override
protected void processRequest() throws Exception {
FormProcessor fp = new FormProcessor(request);
StudyDAO sdao = new StudyDAO(sm.getDataSource());
// YW 11-28-2007 << list sites under their studies
ArrayList<StudyBean> all = (ArrayList<StudyBean>) sdao.findAll();
ArrayList<StudyBean> finalList = new ArrayList<StudyBean>();
for (StudyBean sb : all) {
if (!(sb.getParentStudyId() > 0)) {
finalList.add(sb);
finalList.addAll(sdao.findAllByParent(sb.getId()));
}
}
addEntityList("studies", finalList, respage.getString("a_user_cannot_be_created_no_study_as_active"), Page.ADMIN_SYSTEM);
// YW >>
Map roleMap = new LinkedHashMap();
for (Iterator it = getRoles().iterator(); it.hasNext(); ) {
Role role = (Role) it.next();
// I added the below if statement , to exclude displaying on study level the newly added 'ReseachAssisstant2' role by default.
if (role.getId() != 7)
roleMap.put(role.getId(), role.getDescription());
// roleMap.put(role.getId(), role.getDescription());
}
// addEntityList("roles", getRoles(), respage.getString("a_user_cannot_be_created_no_roles_as_role"), Page.ADMIN_SYSTEM);
request.setAttribute("roles", roleMap);
ArrayList types = UserType.toArrayList();
types.remove(UserType.INVALID);
if (!ub.isTechAdmin()) {
types.remove(UserType.TECHADMIN);
}
addEntityList("types", types, respage.getString("a_user_cannot_be_created_no_user_types_for"), Page.ADMIN_SYSTEM);
Boolean changeRoles = request.getParameter("changeRoles") == null ? false : Boolean.parseBoolean(request.getParameter("changeRoles"));
int activeStudy = fp.getInt(INPUT_STUDY);
if (changeRoles) {
StudyBean study = (StudyBean) sdao.findByPK(activeStudy);
roleMap = new LinkedHashMap();
ResourceBundle resterm = org.akaza.openclinica.i18n.util.ResourceBundleProvider.getTermsBundle();
if (study.getParentStudyId() > 0) {
for (Iterator it = getRoles().iterator(); it.hasNext(); ) {
Role role = (Role) it.next();
switch(role.getId()) {
// break;
case 4:
roleMap.put(role.getId(), resterm.getString("site_investigator").trim());
break;
case 5:
roleMap.put(role.getId(), resterm.getString("site_Data_Entry_Person").trim());
break;
case 6:
roleMap.put(role.getId(), resterm.getString("site_monitor").trim());
break;
case 7:
roleMap.put(role.getId(), resterm.getString("site_Data_Entry_Person2").trim());
break;
default:
}
}
} else {
for (Iterator it = getRoles().iterator(); it.hasNext(); ) {
Role role = (Role) it.next();
switch(role.getId()) {
case 2:
roleMap.put(role.getId(), resterm.getString("Study_Coordinator").trim());
break;
case 3:
roleMap.put(role.getId(), resterm.getString("Study_Director").trim());
break;
case 4:
roleMap.put(role.getId(), resterm.getString("Investigator").trim());
break;
case 5:
roleMap.put(role.getId(), resterm.getString("Data_Entry_Person").trim());
break;
case 6:
roleMap.put(role.getId(), resterm.getString("Monitor").trim());
break;
default:
}
}
}
request.setAttribute("roles", roleMap);
}
request.setAttribute("ldapEnabled", isLdapEnabled());
request.setAttribute("activeStudy", activeStudy);
if (!fp.isSubmitted() || changeRoles) {
String[] textFields = { INPUT_USER_SOURCE, INPUT_USERNAME, INPUT_FIRST_NAME, INPUT_LAST_NAME, INPUT_EMAIL, INPUT_INSTITUTION, INPUT_DISPLAY_PWD };
fp.setCurrentStringValuesAsPreset(textFields);
String[] ddlbFields = { INPUT_STUDY, INPUT_ROLE, INPUT_TYPE, INPUT_RUN_WEBSERVICES };
fp.setCurrentIntValuesAsPreset(ddlbFields);
HashMap presetValues = fp.getPresetValues();
// Mantis Issue 6058.
String sendPwd = SQLInitServlet.getField("user_account_notification");
fp.addPresetValue(USER_ACCOUNT_NOTIFICATION, sendPwd);
//
setPresetValues(presetValues);
forwardPage(Page.CREATE_ACCOUNT);
} else {
UserAccountDAO udao = new UserAccountDAO(sm.getDataSource());
Validator v = new Validator(request);
// username must not be blank,
// must be in the format specified by Validator.USERNAME,
// and must be unique
v.addValidation(INPUT_USERNAME, Validator.NO_BLANKS);
v.addValidation(INPUT_USERNAME, Validator.LENGTH_NUMERIC_COMPARISON, NumericComparisonOperator.LESS_THAN_OR_EQUAL_TO, 64);
v.addValidation(INPUT_USERNAME, Validator.IS_A_USERNAME);
v.addValidation(INPUT_USERNAME, Validator.USERNAME_UNIQUE, udao);
v.addValidation(INPUT_FIRST_NAME, Validator.NO_BLANKS);
v.addValidation(INPUT_LAST_NAME, Validator.NO_BLANKS);
v.addValidation(INPUT_FIRST_NAME, Validator.LENGTH_NUMERIC_COMPARISON, NumericComparisonOperator.LESS_THAN_OR_EQUAL_TO, 50);
v.addValidation(INPUT_LAST_NAME, Validator.LENGTH_NUMERIC_COMPARISON, NumericComparisonOperator.LESS_THAN_OR_EQUAL_TO, 50);
v.addValidation(INPUT_EMAIL, Validator.NO_BLANKS);
v.addValidation(INPUT_EMAIL, Validator.LENGTH_NUMERIC_COMPARISON, NumericComparisonOperator.LESS_THAN_OR_EQUAL_TO, 120);
v.addValidation(INPUT_EMAIL, Validator.IS_A_EMAIL);
v.addValidation(INPUT_INSTITUTION, Validator.NO_BLANKS);
v.addValidation(INPUT_INSTITUTION, Validator.LENGTH_NUMERIC_COMPARISON, NumericComparisonOperator.LESS_THAN_OR_EQUAL_TO, 255);
v.addValidation(INPUT_STUDY, Validator.ENTITY_EXISTS, sdao);
v.addValidation(INPUT_ROLE, Validator.IS_VALID_TERM, TermType.ROLE);
HashMap errors = v.validate();
if (errors.isEmpty()) {
UserAccountBean createdUserAccountBean = new UserAccountBean();
createdUserAccountBean.setName(fp.getString(INPUT_USERNAME));
createdUserAccountBean.setFirstName(fp.getString(INPUT_FIRST_NAME));
createdUserAccountBean.setLastName(fp.getString(INPUT_LAST_NAME));
createdUserAccountBean.setEmail(fp.getString(INPUT_EMAIL));
createdUserAccountBean.setInstitutionalAffiliation(fp.getString(INPUT_INSTITUTION));
boolean isLdap = fp.getString(INPUT_USER_SOURCE).equals("ldap");
String password = null;
String passwordHash = UserAccountBean.LDAP_PASSWORD;
if (!isLdap) {
SecurityManager secm = (SecurityManager) SpringServletAccess.getApplicationContext(context).getBean("securityManager");
password = secm.genPassword();
passwordHash = secm.encrytPassword(password, getUserDetails());
}
createdUserAccountBean.setPasswd(passwordHash);
createdUserAccountBean.setPasswdTimestamp(null);
createdUserAccountBean.setLastVisitDate(null);
createdUserAccountBean.setStatus(Status.AVAILABLE);
createdUserAccountBean.setPasswdChallengeQuestion("");
createdUserAccountBean.setPasswdChallengeAnswer("");
createdUserAccountBean.setPhone("");
createdUserAccountBean.setOwner(ub);
createdUserAccountBean.setRunWebservices(fp.getBoolean(INPUT_RUN_WEBSERVICES));
createdUserAccountBean.setAccessCode("null");
createdUserAccountBean.setEnableApiKey(true);
String apiKey = null;
do {
apiKey = getRandom32ChApiKey();
} while (isApiKeyExist(apiKey));
createdUserAccountBean.setApiKey(apiKey);
int studyId = fp.getInt(INPUT_STUDY);
Role r = Role.get(fp.getInt(INPUT_ROLE));
createdUserAccountBean = addActiveStudyRole(createdUserAccountBean, studyId, r);
UserType type = UserType.get(fp.getInt("type"));
logger.debug("*** found type: " + fp.getInt("type"));
logger.debug("*** setting type: " + type.getDescription());
createdUserAccountBean.addUserType(type);
createdUserAccountBean = (UserAccountBean) udao.create(createdUserAccountBean);
AuthoritiesDao authoritiesDao = (AuthoritiesDao) SpringServletAccess.getApplicationContext(context).getBean("authoritiesDao");
authoritiesDao.saveOrUpdate(new AuthoritiesBean(createdUserAccountBean.getName()));
String displayPwd = fp.getString(INPUT_DISPLAY_PWD);
if (createdUserAccountBean.isActive()) {
addPageMessage(respage.getString("the_user_account") + "\"" + createdUserAccountBean.getName() + "\"" + respage.getString("was_created_succesfully"));
if (!isLdap) {
if ("no".equalsIgnoreCase(displayPwd)) {
try {
sendNewAccountEmail(createdUserAccountBean, password);
} catch (Exception e) {
addPageMessage(respage.getString("there_was_an_error_sending_account_creating_mail"));
}
} else {
addPageMessage(respage.getString("user_password") + ":<br/>" + password + "<br/> " + respage.getString("please_write_down_the_password_and_provide"));
}
}
} else {
addPageMessage(respage.getString("the_user_account") + "\"" + createdUserAccountBean.getName() + "\"" + respage.getString("could_not_created_due_database_error"));
}
if (createdUserAccountBean.isActive()) {
request.setAttribute(ViewUserAccountServlet.ARG_USER_ID, new Integer(createdUserAccountBean.getId()).toString());
forwardPage(Page.VIEW_USER_ACCOUNT_SERVLET);
} else {
forwardPage(Page.LIST_USER_ACCOUNTS_SERVLET);
}
} else {
String[] textFields = { INPUT_USERNAME, INPUT_FIRST_NAME, INPUT_LAST_NAME, INPUT_EMAIL, INPUT_INSTITUTION, INPUT_DISPLAY_PWD, INPUT_USER_SOURCE };
fp.setCurrentStringValuesAsPreset(textFields);
String[] ddlbFields = { INPUT_STUDY, INPUT_ROLE, INPUT_TYPE, INPUT_RUN_WEBSERVICES };
fp.setCurrentIntValuesAsPreset(ddlbFields);
HashMap presetValues = fp.getPresetValues();
setPresetValues(presetValues);
setInputMessages(errors);
addPageMessage(respage.getString("there_were_some_errors_submission") + respage.getString("see_below_for_details"));
forwardPage(Page.CREATE_ACCOUNT);
}
}
}
use of org.akaza.openclinica.control.form.Validator in project OpenClinica by OpenClinica.
the class CreateCRFServlet method processRequest.
@Override
public void processRequest() throws Exception {
CRFDAO cdao = new CRFDAO(sm.getDataSource());
String action = request.getParameter("action");
FormProcessor fp = new FormProcessor(request);
// checks which module the requests are from
String module = fp.getString(MODULE);
request.setAttribute(MODULE, module);
request.setAttribute("xformEnabled", CoreResources.getField("xform.enabled"));
// add the list here so that users can tell about crf creation
// process together with workflow, tbh
resetPanel();
panel.setStudyInfoShown(false);
panel.setOrderedData(true);
setToPanel(resword.getString("create_CRF"), respage.getString("br_create_new_CRF_entering"));
setToPanel(resword.getString("create_CRF_version"), respage.getString("br_create_new_CRF_uploading"));
setToPanel(resword.getString("revise_CRF_version"), respage.getString("br_if_you_owner_CRF_version"));
setToPanel(resword.getString("CRF_spreadsheet_template"), respage.getString("br_download_blank_CRF_spreadsheet_from"));
setToPanel(resword.getString("example_CRF_br_spreadsheets"), respage.getString("br_download_example_CRF_instructions_from"));
if (StringUtil.isBlank(action)) {
session.setAttribute("crf", new CRFBean());
forwardPage(Page.CREATE_CRF);
} else {
if ("confirm".equalsIgnoreCase(action)) {
Validator v = new Validator(request);
v.addValidation("name", Validator.NO_BLANKS);
String name = fp.getString("name");
String description = fp.getString("description");
CRFBean crf = new CRFBean();
crf.setName(name.trim());
crf.setDescription(description.trim());
session.setAttribute("crf", crf);
errors = v.validate();
if (fp.getString("name").trim().length() > 255) {
Validator.addError(errors, "name", resexception.getString("maximum_length_name_255"));
}
if (fp.getString("description").trim().length() > 2048) {
Validator.addError(errors, "description", resexception.getString("maximum_length_description_255"));
}
if (!errors.isEmpty()) {
logger.info("has validation errors in the first section");
request.setAttribute("formMessages", errors);
forwardPage(Page.CREATE_CRF);
} else {
CRFBean crf1 = (CRFBean) cdao.findByName(name.trim());
if (crf1.getId() > 0) {
Validator.addError(errors, "name", resexception.getString("CRF_name_used_choose_unique_name"));
request.setAttribute("formMessages", errors);
forwardPage(Page.CREATE_CRF);
} else {
crf = (CRFBean) session.getAttribute("crf");
logger.info("The crf to be saved:" + crf.getName());
crf.setOwner(ub);
crf.setCreatedDate(new Date());
crf.setStatus(Status.AVAILABLE);
crf.setStudyId(currentStudy.getId());
cdao.create(crf);
crf = (CRFBean) cdao.findByName(crf.getName());
CRFVersionBean version = new CRFVersionBean();
version.setCrfId(crf.getId());
session.setAttribute("version", version);
session.setAttribute("crfName", crf.getName());
session.removeAttribute("crf");
forwardPage(Page.CREATE_CRF_VERSION);
}
}
}
}
}
use of org.akaza.openclinica.control.form.Validator in project OpenClinica by OpenClinica.
the class ViewStudyEventsServlet method processRequest.
@Override
public void processRequest() throws Exception {
FormProcessor fp = new FormProcessor(request);
// checks which module requests are from
String module = fp.getString(MODULE);
request.setAttribute(MODULE, module);
int sedId = fp.getInt("sedId");
int statusId = fp.getInt(INPUT_STATUS_ID);
int definitionId = fp.getInt(INPUT_DEF_ID);
Date startDate = fp.getDate(INPUT_STARTDATE);
Date endDate = fp.getDate(INPUT_ENDDATE);
Calendar cal = Calendar.getInstance();
cal.setTime(new Date());
int month = cal.get(Calendar.MONTH) + 1;
int year = cal.get(Calendar.YEAR);
String defaultStartDateString = month + "/01/" + year;
Date defaultStartDate = new Date();
defaultStartDate = new SimpleDateFormat("MM/dd/yy").parse(defaultStartDateString);
DateFormat dateFormatter = DateFormat.getDateInstance(DateFormat.DEFAULT, locale);
defaultStartDateString = dateFormatter.format(defaultStartDate);
cal.setTime(defaultStartDate);
cal.add(Calendar.DATE, 30);
Date defaultEndDate = cal.getTime();
if (!fp.isSubmitted()) {
logger.info("not submitted");
HashMap presetValues = new HashMap();
presetValues.put(INPUT_STARTDATE, local_df.format(defaultStartDate));
presetValues.put(INPUT_ENDDATE, local_df.format(defaultEndDate));
startDate = defaultStartDate;
endDate = defaultEndDate;
setPresetValues(presetValues);
} else {
Validator v = new Validator(request);
v.addValidation(INPUT_STARTDATE, Validator.IS_A_DATE);
v.addValidation(INPUT_ENDDATE, Validator.IS_A_DATE);
errors = v.validate();
if (!errors.isEmpty()) {
setInputMessages(errors);
startDate = defaultStartDate;
endDate = defaultEndDate;
}
fp.addPresetValue(INPUT_STARTDATE, fp.getString(INPUT_STARTDATE));
fp.addPresetValue(INPUT_ENDDATE, fp.getString(INPUT_ENDDATE));
fp.addPresetValue(INPUT_DEF_ID, fp.getInt(INPUT_DEF_ID));
fp.addPresetValue(INPUT_STATUS_ID, fp.getInt(INPUT_STATUS_ID));
setPresetValues(fp.getPresetValues());
}
request.setAttribute(STATUS_MAP, SubjectEventStatus.toArrayList());
StudyEventDefinitionDAO seddao = new StudyEventDefinitionDAO(sm.getDataSource());
ArrayList definitions = seddao.findAllByStudy(currentStudy);
request.setAttribute(DEFINITION_MAP, definitions);
ArrayList allEvents = new ArrayList();
allEvents = genTables(fp, definitions, startDate, endDate, sedId, definitionId, statusId);
request.setAttribute("allEvents", allEvents);
// for print version
String queryUrl = INPUT_STARTDATE + "=" + local_df.format(startDate) + "&" + INPUT_ENDDATE + "=" + local_df.format(endDate) + "&" + INPUT_DEF_ID + "=" + definitionId + "&" + INPUT_STATUS_ID + "=" + statusId + "&" + "sedId=" + sedId + "&submitted=" + fp.getInt("submitted");
request.setAttribute("queryUrl", queryUrl);
if ("yes".equalsIgnoreCase(fp.getString(PRINT))) {
allEvents = genEventsForPrint(fp, definitions, startDate, endDate, sedId, definitionId, statusId);
request.setAttribute("allEvents", allEvents);
forwardPage(Page.VIEW_STUDY_EVENTS_PRINT);
} else {
forwardPage(Page.VIEW_STUDY_EVENTS);
}
}
Aggregations