public HashMap validateImportJobForm( FormProcessor fp, HttpServletRequest request, String[] triggerNames, String properName) { Validator v = new Validator(request); v.addValidation(JOB_NAME, Validator.NO_BLANKS); // 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; }
public HashMap validateForm( FormProcessor fp, HttpServletRequest request, String[] triggerNames, String properName) { Validator v = new Validator(request); v.addValidation(JOB_NAME, Validator.NO_BLANKS); // 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 String tab = fp.getString(TAB); String cdisc = fp.getString(CDISC); String cdisc12 = fp.getString(ExampleSpringJob.CDISC12); String cdisc13 = fp.getString(ExampleSpringJob.CDISC13); String cdisc13oc = fp.getString(ExampleSpringJob.CDISC13OC); String spss = fp.getString(SPSS); Date jobDate = fp.getDateTime(DATE_START_JOB); HashMap errors = v.validate(); if ((tab == "") && (cdisc == "") && (spss == "") && (cdisc12 == "") && (cdisc13 == "") && (cdisc13oc == "")) { // throw an error here, at least one should work // errors.put(TAB, "Error Message - Pick one of the below"); v.addError(errors, TAB, "Please pick at least one of the below."); } 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; }
/** * Validates the forth section of study and save it into study bean * * @param request * @param response * @throws Exception */ private void confirmStudy4() throws Exception { FormProcessor fp = new FormProcessor(request); Validator v = new Validator(request); v.addValidation( "conditions", Validator.LENGTH_NUMERIC_COMPARISON, NumericComparisonOperator.LESS_THAN_OR_EQUAL_TO, 500); v.addValidation( "keywords", Validator.LENGTH_NUMERIC_COMPARISON, NumericComparisonOperator.LESS_THAN_OR_EQUAL_TO, 255); v.addValidation( "eligibility", Validator.LENGTH_NUMERIC_COMPARISON, NumericComparisonOperator.LESS_THAN_OR_EQUAL_TO, 500); errors = v.validate(); if (fp.getInt("expectedTotalEnrollment") <= 0) { Validator.addError( errors, "expectedTotalEnrollment", respage.getString("expected_total_enrollment_must_be_a_positive_number")); } StudyBean newStudy = (StudyBean) session.getAttribute("newStudy"); newStudy.setConditions(fp.getString("conditions")); newStudy.setKeywords(fp.getString("keywords")); newStudy.setEligibility(fp.getString("eligibility")); newStudy.setGender(fp.getString("gender")); newStudy.setAgeMax(fp.getString("ageMax")); newStudy.setAgeMin(fp.getString("ageMin")); newStudy.setHealthyVolunteerAccepted(fp.getBoolean("healthyVolunteerAccepted")); newStudy.setExpectedTotalEnrollment(fp.getInt("expectedTotalEnrollment")); session.setAttribute("newStudy", newStudy); request.setAttribute("facRecruitStatusMap", CreateStudyServlet.facRecruitStatusMap); if (errors.isEmpty()) { forwardPage(Page.UPDATE_STUDY6); } else { request.setAttribute("formMessages", errors); forwardPage(Page.UPDATE_STUDY5); } }
/** * Validates the first section of study and save it into study bean * * @param request * @param response * @throws Exception */ private void confirmStudy1() throws Exception { Validator v = new Validator(request); FormProcessor fp = new FormProcessor(request); v.addValidation("name", Validator.NO_BLANKS); v.addValidation("uniqueProId", Validator.NO_BLANKS); v.addValidation("description", Validator.NO_BLANKS); v.addValidation("prinInvestigator", Validator.NO_BLANKS); v.addValidation("sponsor", Validator.NO_BLANKS); v.addValidation( "secondProId", Validator.LENGTH_NUMERIC_COMPARISON, NumericComparisonOperator.LESS_THAN_OR_EQUAL_TO, 255); v.addValidation( "collaborators", Validator.LENGTH_NUMERIC_COMPARISON, NumericComparisonOperator.LESS_THAN_OR_EQUAL_TO, 1000); v.addValidation( "protocolDescription", Validator.LENGTH_NUMERIC_COMPARISON, NumericComparisonOperator.LESS_THAN_OR_EQUAL_TO, 1000); errors = v.validate(); if (fp.getString("name").trim().length() > 100) { Validator.addError(errors, "name", resexception.getString("maximum_lenght_name_100")); } if (fp.getString("uniqueProId").trim().length() > 30) { Validator.addError( errors, "uniqueProId", resexception.getString("maximum_lenght_unique_protocol_30")); } if (fp.getString("description").trim().length() > 255) { Validator.addError( errors, "description", resexception.getString("maximum_lenght_brief_summary_255")); } if (fp.getString("prinInvestigator").trim().length() > 255) { Validator.addError( errors, "prinInvestigator", resexception.getString("maximum_lenght_principal_investigator_255")); } if (fp.getString("sponsor").trim().length() > 255) { Validator.addError(errors, "sponsor", resexception.getString("maximum_lenght_sponsor_255")); } if (fp.getString("officialTitle").trim().length() > 255) { Validator.addError( errors, "officialTitle", resexception.getString("maximum_lenght_official_title_255")); } session.setAttribute("newStudy", createStudyBean()); if (errors.isEmpty()) { logger.info("no errors in the first section"); request.setAttribute("studyPhaseMap", CreateStudyServlet.studyPhaseMap); request.setAttribute("statuses", Status.toActiveArrayList()); StudyBean newStudy = (StudyBean) session.getAttribute("newStudy"); fp.addPresetValue(INPUT_START_DATE, local_df.format(newStudy.getDatePlannedStart())); if (newStudy.getDatePlannedEnd() != null) { fp.addPresetValue(INPUT_END_DATE, local_df.format(newStudy.getDatePlannedEnd())); } fp.addPresetValue(INPUT_VER_DATE, local_df.format(newStudy.getProtocolDateVerification())); setPresetValues(fp.getPresetValues()); forwardPage(Page.UPDATE_STUDY2); } else { logger.info("has validation errors in the first section"); request.setAttribute("formMessages", errors); forwardPage(Page.UPDATE_STUDY1); } }