Search in sources :

Example 11 with Validator

use of org.akaza.openclinica.control.form.Validator in project OpenClinica by OpenClinica.

the class CreateDatasetServlet method processRequest.

@Override
public void processRequest() throws Exception {
    FormProcessor fp = new FormProcessor(request);
    String action = fp.getString("action");
    if (StringUtil.isBlank(action)) {
        // step 1 -- instructions, and continue button
        session.setAttribute("newDataset", new DatasetBean());
        session.setAttribute("allItems", new ArrayList());
        session.setAttribute("crf", new CRFBean());
        session.setAttribute("allSelectedItems", new ArrayList());
        forwardPage(Page.CREATE_DATASET_1);
    } else {
        StudyBean studyWithEventDefs = currentStudy;
        if (currentStudy.getParentStudyId() > 0) {
            studyWithEventDefs = new StudyBean();
            studyWithEventDefs.setId(currentStudy.getParentStudyId());
        }
        if ("begin".equalsIgnoreCase(action)) {
            // step 2 -- select study events/crfs
            StudyEventDAO sedao = new StudyEventDAO(sm.getDataSource());
            StudyEventDefinitionDAO seddao = new StudyEventDefinitionDAO(sm.getDataSource());
            EventCRFDAO ecdao = new EventCRFDAO(sm.getDataSource());
            StudyBean studyWithEventDefinitions = currentStudy;
            if (currentStudy.getParentStudyId() > 0) {
                studyWithEventDefinitions = new StudyBean();
                studyWithEventDefinitions.setId(currentStudy.getParentStudyId());
            }
            ArrayList seds = seddao.findAllActiveByStudy(studyWithEventDefinitions);
            CRFDAO crfdao = new CRFDAO(sm.getDataSource());
            HashMap events = new LinkedHashMap();
            for (int i = 0; i < seds.size(); i++) {
                StudyEventDefinitionBean sed = (StudyEventDefinitionBean) seds.get(i);
                ArrayList<CRFBean> crfs = (ArrayList<CRFBean>) crfdao.findAllActiveByDefinition(sed);
                if (currentStudy.getParentStudyId() > 0) {
                    // sift through these CRFs and see which ones are hidden
                    HideCRFManager hideCRFs = HideCRFManager.createHideCRFManager();
                    crfs = hideCRFs.removeHiddenCRFBeans(studyWithEventDefinitions, sed, crfs, sm.getDataSource());
                }
                if (!crfs.isEmpty()) {
                    events.put(sed, crfs);
                }
            }
            // datasets
            if (events.isEmpty()) {
                addPageMessage(respage.getString("not_have_study_definitions_assigned"));
                forwardPage(Page.CREATE_DATASET_1);
            } else {
                crfdao = new CRFDAO(sm.getDataSource());
                ItemDAO idao = new ItemDAO(sm.getDataSource());
                ArrayList sedItemIds = CreateDatasetServlet.allSedItemIdsInStudy(events, crfdao, idao);
                session.setAttribute("numberOfStudyItems", Integer.toString(sedItemIds.size()));
                request.setAttribute("eventlist", events);
                session.setAttribute(EVENTS_FOR_CREATE_DATASET, events);
                session.setAttribute("newDataset", new DatasetBean());
                session.setAttribute("allItems", new ArrayList());
                session.setAttribute("crf", new CRFBean());
                forwardPage(Page.CREATE_DATASET_2);
            }
        } else if ("beginsubmit".equalsIgnoreCase(action)) {
            String saveItems = fp.getString(SAVE_BUTTON);
            String saveContinue = fp.getString(SAVE_CONTINUE_BUTTON);
            DatasetBean db = (DatasetBean) session.getAttribute("newDataset");
            if (db == null) {
                db = new DatasetBean();
            }
            extractIdsFromForm(db);
            extractEventIds(db);
            session.setAttribute("newDataset", db);
            // +"");
            if (!StringUtil.isBlank(saveItems)) {
                request.setAttribute("eventlist", session.getAttribute(EVENTS_FOR_CREATE_DATASET));
                // BWP 3095>>
                String summary = respage.getString("you_have_selected") + " " + db.getItemIds().size() + " " + respage.getString("items_so_far");
                summary += genAttMsg(db);
                addPageMessage(summary);
                int crfId = fp.getInt("crfId");
                if (crfId > 0) {
                    // user choose a crf and select items
                    forwardPage(Page.CREATE_DATASET_2);
                } else {
                    ArrayList sgclasses = (ArrayList) session.getAttribute("allSelectedGroups");
                    if (sgclasses == null || sgclasses.size() == 0) {
                        sgclasses = setUpStudyGroups();
                    }
                    session.setAttribute("allSelectedGroups", sgclasses);
                    request.setAttribute("allSelectedGroups", sgclasses);
                    // TODO push out list of subject groups here???
                    // form submitted from "view selected item ' or
                    // attribute page, so
                    // forward back to "view selected item " page
                    forwardPage(Page.CREATE_DATASET_VIEW_SELECTED);
                }
            } else {
                if (db.getItemIds().size() == 0) {
                    request.setAttribute("eventlist", session.getAttribute(EVENTS_FOR_CREATE_DATASET));
                    addPageMessage(respage.getString("should_select_one_item_to_create_dataset"));
                    forwardPage(Page.CREATE_DATASET_2);
                } else {
                    String summary = respage.getString("you_have_selected") + " " + db.getItemIds().size() + " " + respage.getString("items_totally_for_this_dataset");
                    summary += genAttMsg(db);
                    addPageMessage(summary);
                    // 0 means using
                    fp.addPresetValue("firstmonth", 0);
                    // default month
                    fp.addPresetValue("firstyear", 1900);
                    fp.addPresetValue("lastmonth", 0);
                    fp.addPresetValue("lastyear", 2100);
                    setPresetValues(fp.getPresetValues());
                    logger.warn("found preset values while setting date: " + fp.getPresetValues().toString());
                    request.setAttribute(BEAN_MONTHS, getMonths());
                    request.setAttribute(BEAN_YEARS, getYears());
                    forwardPage(Page.CREATE_DATASET_3);
                }
            }
        } else if ("scopesubmit".equalsIgnoreCase(action)) {
            ArrayList months = getMonths();
            ArrayList years = getYears();
            int firstMonth = fp.getInt("firstmonth");
            int firstYear = fp.getInt("firstyear");
            int lastMonth = fp.getInt("lastmonth");
            int lastYear = fp.getInt("lastyear");
            if (fp.getInt("firstmonth") == 0) {
                // default value
                firstMonth = 1;
            }
            if (fp.getInt("lastmonth") == 0) {
                // default value
                lastMonth = 12;
            }
            errors = new HashMap();
            if (fp.getInt("firstmonth") > 0 && firstYear == 1900) {
                Validator.addError(errors, "firstmonth", restext.getString("if_specify_month_also_specify_year"));
            }
            if (fp.getInt("lastmonth") > 0 && lastYear == 2100) {
                Validator.addError(errors, "lastmonth", restext.getString("if_specify_month_also_specify_year"));
            }
            Date dateStart = getFirstDayOfMonth(firstYear, firstMonth);
            Date dateEnd = getLastDayOfMonth(lastYear, lastMonth);
            if (dateEnd.compareTo(dateStart) < 0) {
                Validator.addError(errors, "firstmonth", restext.getString("the_from_should_be_come_before_to"));
            }
            if (!errors.isEmpty()) {
                String[] fieldNames = { "firstmonth", "firstyear", "lastmonth", "lastyear" };
                fp.setCurrentIntValuesAsPreset(fieldNames);
                setInputMessages(errors);
                addPageMessage(respage.getString("errors_in_submission_see_below"));
                setPresetValues(fp.getPresetValues());
                request.setAttribute(BEAN_MONTHS, getMonths());
                request.setAttribute(BEAN_YEARS, getYears());
                forwardPage(Page.CREATE_DATASET_3);
            } else {
                DatasetBean dsb = (DatasetBean) session.getAttribute("newDataset");
                dsb.setDateStart(dateStart);
                dsb.setDateEnd(dateEnd);
                session.setAttribute("newDataset", dsb);
                if (fp.getString("submit").equals(resword.getString("continue_to_apply_filter"))) {
                    // FilterDAO fdao = new FilterDAO(sm.getDataSource());
                    // Collection filters = fdao.findAll();
                    // TODO make findAllByProject
                    // request.setAttribute("filters",filters);
                    EntityBeanTable table = getFilterTable();
                    session.setAttribute("partOfCreateDataset", new Integer(1));
                    // to be used in createFiltersThree servlet, tbh
                    request.setAttribute("table", table);
                    forwardPage(Page.APPLY_FILTER);
                } else {
                    request.setAttribute("statuses", Status.toActiveArrayList());
                    // YW, 2-20-2008 <<these attributes will show on the
                    // CREATE_DATASET_4
                    String temp = dsb.getODMMetaDataVersionOid();
                    request.setAttribute("mdvOID", temp != null && temp.length() > 0 ? temp : "v1.0.0");
                    temp = dsb.getODMMetaDataVersionName();
                    request.setAttribute("mdvName", temp != null && temp.length() > 0 ? temp : "MetaDataVersion_v1.0.0");
                    request.setAttribute("mdvPrevStudy", dsb.getODMPriorStudyOid());
                    request.setAttribute("mdvPrevOID", dsb.getODMPriorMetaDataVersionOid());
                    // YW >>
                    forwardPage(Page.CREATE_DATASET_4);
                }
            }
        } else if ("specifysubmit".equalsIgnoreCase(action)) {
            Validator v = new Validator(request);
            v.addValidation("dsName", Validator.NO_BLANKS);
            v.addValidation("dsName", Validator.NO_SEMI_COLONS_OR_COLONS);
            v.addValidation("dsDesc", Validator.NO_BLANKS);
            v.addValidation("dsStatus", Validator.IS_VALID_TERM, TermType.STATUS);
            v.addValidation("dsName", Validator.LENGTH_NUMERIC_COMPARISON, NumericComparisonOperator.LESS_THAN_OR_EQUAL_TO, 255);
            v.addValidation("dsDesc", Validator.LENGTH_NUMERIC_COMPARISON, NumericComparisonOperator.LESS_THAN_OR_EQUAL_TO, 2000);
            String mdvOID = fp.getString("mdvOID");
            String mdvName = fp.getString("mdvName");
            String mdvPrevStudy = fp.getString("mdvPrevStudy");
            if (mdvPrevStudy != null && mdvPrevStudy.length() > 0) {
                v.addValidation("mdvPrevOID", Validator.NO_BLANKS);
            }
            String mdvPrevOID = fp.getString("mdvPrevOID");
            errors = v.validate();
            String dsName = fp.getString("dsName");
            if (!StringUtil.isBlank(dsName)) {
                // YW, << 3-19-2008
                if (dsName.contains("/") || dsName.contains("\\")) {
                    v.addError(errors, "dsName", restext.getString("slash_not_allowed"));
                }
                // 2-20-2008, no check for editing dataset
                if (((DatasetBean) session.getAttribute("newDataset")).getId() <= 0) {
                    // YW >>
                    // logger.info("dsName" + fp.getString("dsName"));
                    DatasetDAO dsdao = new DatasetDAO(sm.getDataSource());
                    DatasetBean dsBean = (DatasetBean) dsdao.findByNameAndStudy(fp.getString("dsName").trim(), currentStudy);
                    if (dsBean.getId() > 0) {
                        Validator.addError(errors, "dsName", restext.getString("dataset_name_used_by_another_choose_unique"));
                    }
                }
            }
            if (!errors.isEmpty()) {
                String[] fieldNames = { "dsName", "dsDesc" };
                fp.setCurrentStringValuesAsPreset(fieldNames);
                fp.addPresetValue("dsStatusId", fp.getInt("dsStatus"));
                fp.addPresetValue("mdvOID", mdvOID);
                fp.addPresetValue("mdvName", mdvName);
                fp.addPresetValue("mdvPrevStudy", mdvPrevStudy);
                fp.addPresetValue("mdvPrevOID", mdvPrevOID);
                addPageMessage(respage.getString("errors_in_submission_see_below"));
                setInputMessages(errors);
                setPresetValues(fp.getPresetValues());
                request.setAttribute("statuses", Status.toActiveArrayList());
                forwardPage(Page.CREATE_DATASET_4);
            } else {
                session.setAttribute("mdvOID", mdvOID);
                session.setAttribute("mdvName", mdvName);
                session.setAttribute("mdvPrevStudy", mdvPrevStudy);
                session.setAttribute("mdvPrevOID", mdvPrevOID);
                if (mdvPrevOID != null && mdvPrevOID.length() > 0 && (mdvPrevStudy == null || mdvPrevStudy.length() <= 0)) {
                    mdvPrevStudy = currentStudy.getId() + "";
                }
                DatasetBean dsb = (DatasetBean) session.getAttribute("newDataset");
                dsb.setSQLStatement(dsb.generateQuery());
                String dbName = SQLInitServlet.getField("dataBase");
                if ("oracle".equals(dbName)) {
                    dsb.setSQLStatement(dsb.generateOracleQuery());
                }
                // TODO set up oracle syntax for the query, grab the
                // database
                // from the session manager and feed it to the dataset bean
                // possibly done, tbh 1/4/2005
                // TODO look for the filter here, re-create the sql
                // statement
                // and put it in here
                // possibly done need to test, tbh 1/7/2005
                FilterBean fb = (FilterBean) session.getAttribute("newFilter");
                if (fb != null) {
                    // FilterDAO fDAO = new FilterDAO(sm.getDataSource());
                    dsb.setSQLStatement(dsb.getSQLStatement() + " " + fb.getSQLStatement());
                }
                // dataset if dataset name has been changed.
                if (dsb.getId() > 0 && !dsb.getName().equals(fp.getString("dsName"))) {
                    dsb.setId(0);
                }
                // YW >>
                dsb.setODMMetaDataVersionName(mdvName);
                dsb.setODMMetaDataVersionOid(mdvOID);
                dsb.setODMPriorMetaDataVersionOid(mdvPrevOID);
                dsb.setODMPriorStudyOid(mdvPrevStudy);
                dsb.setName(fp.getString("dsName"));
                dsb.setDescription(fp.getString("dsDesc"));
                dsb.setStatus(Status.get(fp.getInt("dsStatus")));
                dsb.setDatasetItemStatus(DatasetItemStatus.get(fp.getInt("itemStatus")));
                session.removeAttribute("partOfCreateDataset");
                Date ddate = new SimpleDateFormat("MM/dd/yyyy").parse("01/01/1900");
                // done to remove the set up of going to get the filter, tbh
                // set up dataset here, grab primary key???!!!???
                // added by jxu
                request.setAttribute("defaultStart", local_df.parse(local_df.format(ddate)));
                request.setAttribute("defaultEnd", getLastDayOfMonth(2100, 12));
                session.setAttribute("newDataset", dsb);
                forwardPage(Page.CONFIRM_DATASET);
            }
        } else if ("confirmall".equalsIgnoreCase(action)) {
            String submit = fp.getString("btnSubmit");
            logger.info("reached confirm all");
            if (!resword.getString("confirm_and_save").equalsIgnoreCase(submit)) {
                // we're going back, so we should not destroy the
                // data we've created, tbh
                // session.removeAttribute("newDataset");
                // session.removeAttribute("newFilter");
                forwardPage(Page.CREATE_DATASET_4);
            } else {
                DatasetDAO ddao = new DatasetDAO(sm.getDataSource());
                DatasetBean dsb = (DatasetBean) session.getAttribute("newDataset");
                dsb.setStudyId(this.currentStudy.getId());
                dsb.setOwner(ub);
                // dsb.setOwnerId(ub.getId());
                //
                // at this point, dataset itemId will still be kept
                // uniquely.
                dsb = finalUpateDatasetBean(dsb);
                if (dsb.getId() == 0) {
                    // if the bean hasn't been created already that is...
                    logger.info("*** about to create the dataset bean");
                    dsb = (DatasetBean) ddao.create(dsb);
                    logger.info("created dataset bean: " + dsb.getId() + ", name: " + dsb.getName());
                    if (!dsb.isActive()) {
                        addPageMessage(restext.getString("problem_creating_dataset_try_again"));
                        forwardPage(Page.EXTRACT_DATASETS_MAIN);
                    }
                } else // YW, 2-20-2008 << for editing existing dataset
                if (dsb.getId() > 0) {
                    dsb = (DatasetBean) ddao.updateAll(dsb);
                    if (!dsb.isActive()) {
                        addPageMessage(restext.getString("problem_creating_dataset_try_again"));
                        forwardPage(Page.EXTRACT_DATASETS_MAIN);
                    }
                    dsb = (DatasetBean) ddao.updateGroupMap(dsb);
                    if (!dsb.isActive()) {
                        addPageMessage(restext.getString("problem_updating_subject_group_class_when_updating_dataset"));
                        forwardPage(Page.EXTRACT_DATASETS_MAIN);
                    }
                }
                // YW >>
                logger.info("setting data set id here");
                // may be easier to just set the dataset bean
                // back into the session?
                request.setAttribute("dataset", dsb);
                forwardPage(Page.EXPORT_DATASETS);
            }
        } else {
            // refine this bit to catch errors, hopefully
            addPageMessage(restext.getString("creating_new_dataset_cancelled"));
            forwardPage(Page.CREATE_DATASET_1);
        }
    }
}
Also used : HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) ItemDAO(org.akaza.openclinica.dao.submit.ItemDAO) EntityBeanTable(org.akaza.openclinica.web.bean.EntityBeanTable) DatasetBean(org.akaza.openclinica.bean.extract.DatasetBean) ArrayList(java.util.ArrayList) StudyEventDefinitionBean(org.akaza.openclinica.bean.managestudy.StudyEventDefinitionBean) LinkedHashMap(java.util.LinkedHashMap) StudyEventDAO(org.akaza.openclinica.dao.managestudy.StudyEventDAO) EventCRFDAO(org.akaza.openclinica.dao.submit.EventCRFDAO) FilterBean(org.akaza.openclinica.bean.extract.FilterBean) EventCRFDAO(org.akaza.openclinica.dao.submit.EventCRFDAO) CRFDAO(org.akaza.openclinica.dao.admin.CRFDAO) FormProcessor(org.akaza.openclinica.control.form.FormProcessor) StudyBean(org.akaza.openclinica.bean.managestudy.StudyBean) HideCRFManager(org.akaza.openclinica.service.crfdata.HideCRFManager) DatasetDAO(org.akaza.openclinica.dao.extract.DatasetDAO) Date(java.util.Date) CRFBean(org.akaza.openclinica.bean.admin.CRFBean) StudyEventDefinitionDAO(org.akaza.openclinica.dao.managestudy.StudyEventDefinitionDAO) SimpleDateFormat(java.text.SimpleDateFormat) Validator(org.akaza.openclinica.control.form.Validator)

Example 12 with Validator

use of org.akaza.openclinica.control.form.Validator in project OpenClinica by OpenClinica.

the class RequestStudyServlet method confirm.

/**
     *
     * @param request
     * @param response
     */
private void confirm() throws Exception {
    Validator v = new Validator(request);
    v.addValidation("studyId", Validator.IS_AN_INTEGER);
    v.addValidation("studyRoleId", Validator.IS_VALID_TERM, TermType.ROLE);
    HashMap errors = v.validate();
    FormProcessor fp = new FormProcessor(request);
    StudyUserRoleBean newRole = new StudyUserRoleBean();
    if (fp.getInt("studyRoleId") > 0) {
        newRole.setRole(Role.get(fp.getInt("studyRoleId")));
    }
    newRole.setStudyId(fp.getInt("studyId"));
    StudyDAO sdao = new StudyDAO(sm.getDataSource());
    StudyBean studyRequested = (StudyBean) sdao.findByPK(newRole.getStudyId());
    newRole.setStudyName(studyRequested.getName());
    session.setAttribute("newRole", newRole);
    if (!errors.isEmpty()) {
        logger.info("after processing form,error is not empty");
        request.setAttribute("formMessages", errors);
        forwardPage(Page.REQUEST_STUDY);
    } else {
        logger.info("after processing form,no errors");
        forwardPage(Page.REQUEST_STUDY_CONFIRM);
    }
}
Also used : HashMap(java.util.HashMap) FormProcessor(org.akaza.openclinica.control.form.FormProcessor) StudyUserRoleBean(org.akaza.openclinica.bean.login.StudyUserRoleBean) StudyBean(org.akaza.openclinica.bean.managestudy.StudyBean) StudyDAO(org.akaza.openclinica.dao.managestudy.StudyDAO) Validator(org.akaza.openclinica.control.form.Validator)

Example 13 with Validator

use of org.akaza.openclinica.control.form.Validator in project OpenClinica by OpenClinica.

the class ResetPasswordServlet method processRequest.

/**
     * Tasks include:
     * <ol>
     * <li>Validation:
     * <ol>
     * <li>1. old password match database record
     * <li>2. new password is follows requirements
     * <li>4. two times entered passwords are same
     * <li>5. all required fields are filled
     * </ol>
     * <li>Update ub - UserAccountBean - in session and database
     * </ol>
     */
@Override
public void processRequest() throws Exception {
    logger.info("Change expired password");
    UserAccountDAO udao = new UserAccountDAO(sm.getDataSource());
    Validator v = new Validator(request);
    errors.clear();
    FormProcessor fp = new FormProcessor(request);
    String mustChangePwd = request.getParameter("mustChangePwd");
    String newPwd = fp.getString("passwd").trim();
    String passwdChallengeQ = fp.getString("passwdChallengeQ");
    String passwdChallengeA = fp.getString("passwdChallengeA");
    if ("yes".equalsIgnoreCase(mustChangePwd)) {
        addPageMessage(respage.getString("your_password_has_expired_must_change"));
    } else {
        addPageMessage(respage.getString("password_expired") + " " + respage.getString("if_you_do_not_want_change_leave_blank"));
    }
    request.setAttribute("mustChangePass", mustChangePwd);
    String oldPwd = fp.getString("oldPasswd").trim();
    // user bean from web
    UserAccountBean ubForm = new UserAccountBean();
    // form
    ubForm.setPasswd(oldPwd);
    ubForm.setPasswdChallengeQuestion(passwdChallengeQ);
    ubForm.setPasswdChallengeAnswer(passwdChallengeA);
    request.setAttribute("userBean1", ubForm);
    SecurityManager sm = ((SecurityManager) SpringServletAccess.getApplicationContext(context).getBean("securityManager"));
    if (!sm.isPasswordValid(ub.getPasswd(), oldPwd, getUserDetails())) {
        Validator.addError(errors, "oldPasswd", resexception.getString("wrong_old_password"));
        request.setAttribute("formMessages", errors);
        forwardPage(Page.RESET_PASSWORD);
    } else {
        if (mustChangePwd.equalsIgnoreCase("yes")) {
            v.addValidation("passwd", Validator.NO_BLANKS);
            v.addValidation("passwd1", Validator.NO_BLANKS);
            v.addValidation("passwdChallengeQ", Validator.NO_BLANKS);
            v.addValidation("passwdChallengeA", Validator.NO_BLANKS);
            v.addValidation("passwd", Validator.CHECK_DIFFERENT, "oldPasswd");
        }
        String newDigestPass = sm.encrytPassword(newPwd, getUserDetails());
        List<String> pwdErrors = new ArrayList<String>();
        if (!StringUtils.isEmpty(newPwd)) {
            v.addValidation("passwd", Validator.IS_A_PASSWORD);
            v.addValidation("passwd1", Validator.CHECK_SAME, "passwd");
            ConfigurationDao configurationDao = SpringServletAccess.getApplicationContext(context).getBean(ConfigurationDao.class);
            PasswordRequirementsDao passwordRequirementsDao = new PasswordRequirementsDao(configurationDao);
            Locale locale = LocaleResolver.getLocale(request);
            ResourceBundle resexception = ResourceBundleProvider.getExceptionsBundle(locale);
            pwdErrors = PasswordValidator.validatePassword(passwordRequirementsDao, udao, ub.getId(), newPwd, newDigestPass, resexception);
        }
        errors = v.validate();
        for (String err : pwdErrors) {
            v.addError(errors, "passwd", err);
        }
        if (!errors.isEmpty()) {
            logger.info("ResetPassword page has validation errors");
            request.setAttribute("formMessages", errors);
            forwardPage(Page.RESET_PASSWORD);
        } else {
            logger.info("ResetPassword page has no errors");
            if (!StringUtils.isBlank(newPwd)) {
                ub.setPasswd(newDigestPass);
                ub.setPasswdTimestamp(new Date());
            } else if ("no".equalsIgnoreCase(mustChangePwd)) {
                ub.setPasswdTimestamp(new Date());
            }
            ub.setOwner(ub);
            // when update ub, updator id is required
            ub.setUpdater(ub);
            ub.setPasswdChallengeQuestion(passwdChallengeQ);
            ub.setPasswdChallengeAnswer(passwdChallengeA);
            udao.update(ub);
            ArrayList<String> pageMessages = new ArrayList<String>();
            request.setAttribute(PAGE_MESSAGE, pageMessages);
            addPageMessage(respage.getString("your_expired_password_reset_successfully"));
            ub.incNumVisitsToMainMenu();
            forwardPage(Page.MENU_SERVLET);
        }
    }
}
Also used : Locale(java.util.Locale) ConfigurationDao(org.akaza.openclinica.dao.hibernate.ConfigurationDao) SecurityManager(org.akaza.openclinica.core.SecurityManager) FormProcessor(org.akaza.openclinica.control.form.FormProcessor) ArrayList(java.util.ArrayList) UserAccountDAO(org.akaza.openclinica.dao.login.UserAccountDAO) Date(java.util.Date) UserAccountBean(org.akaza.openclinica.bean.login.UserAccountBean) ResourceBundle(java.util.ResourceBundle) PasswordRequirementsDao(org.akaza.openclinica.dao.hibernate.PasswordRequirementsDao) Validator(org.akaza.openclinica.control.form.Validator)

Example 14 with Validator

use of org.akaza.openclinica.control.form.Validator in project OpenClinica by OpenClinica.

the class CreateStudyServlet method confirmStudy3.

/**
     * Confirms the third section of study info inputs
     *
     * @throws Exception
     */
private void confirmStudy3() throws Exception {
    Validator v = new Validator(request);
    FormProcessor fp = new FormProcessor(request);
    v.addValidation("purpose", Validator.NO_BLANKS);
    for (int i = 0; i < 10; i++) {
        String type = fp.getString("interType" + i);
        String name = fp.getString("interName" + i);
        if (!StringUtil.isBlank(type) && StringUtil.isBlank(name)) {
            v.addValidation("interName", Validator.NO_BLANKS);
            request.setAttribute("interventionError", respage.getString("name_cannot_be_blank_if_type"));
            break;
        }
        if (!StringUtil.isBlank(name) && StringUtil.isBlank(type)) {
            v.addValidation("interType", Validator.NO_BLANKS);
            request.setAttribute("interventionError", respage.getString("name_cannot_be_blank_if_name"));
            break;
        }
    }
    errors = v.validate();
    boolean isInterventional = true;
    if (session.getAttribute("isInterventionalFlag") != null) {
        isInterventional = ((Boolean) session.getAttribute("isInterventionalFlag")).booleanValue();
    }
    updateStudy3(isInterventional);
    if (errors.isEmpty()) {
        logger.info("no errors");
        if (session.getAttribute("interventionArray") == null) {
            request.setAttribute("interventions", new ArrayList());
        } else {
            request.setAttribute("interventions", session.getAttribute("interventionArray"));
        }
        forwardPage(Page.CREATE_STUDY5);
    } else {
        logger.info("has validation errors");
        request.setAttribute("formMessages", errors);
        setMaps(isInterventional);
        if (isInterventional) {
            forwardPage(Page.CREATE_STUDY3);
        } else {
            forwardPage(Page.CREATE_STUDY4);
        }
    }
}
Also used : FormProcessor(org.akaza.openclinica.control.form.FormProcessor) ArrayList(java.util.ArrayList) Validator(org.akaza.openclinica.control.form.Validator)

Example 15 with Validator

use of org.akaza.openclinica.control.form.Validator in project OpenClinica by OpenClinica.

the class CreateStudyServlet method confirmStudy5.

/**
     * Validates the forth section of study and save it into study bean
     *
     * @param request
     * @param response
     * @throws Exception
     */
private void confirmStudy5() throws Exception {
    FormProcessor fp = new FormProcessor(request);
    Validator v = new Validator(request);
    if (!StringUtil.isBlank(fp.getString("facConEmail"))) {
        v.addValidation("facConEmail", Validator.IS_A_EMAIL);
    }
    v.addValidation("facName", Validator.LENGTH_NUMERIC_COMPARISON, NumericComparisonOperator.LESS_THAN_OR_EQUAL_TO, 255);
    v.addValidation("facCity", Validator.LENGTH_NUMERIC_COMPARISON, NumericComparisonOperator.LESS_THAN_OR_EQUAL_TO, 255);
    v.addValidation("facState", Validator.LENGTH_NUMERIC_COMPARISON, NumericComparisonOperator.LESS_THAN_OR_EQUAL_TO, 20);
    v.addValidation("facZip", Validator.LENGTH_NUMERIC_COMPARISON, NumericComparisonOperator.LESS_THAN_OR_EQUAL_TO, 64);
    v.addValidation("facCountry", Validator.LENGTH_NUMERIC_COMPARISON, NumericComparisonOperator.LESS_THAN_OR_EQUAL_TO, 64);
    v.addValidation("facConName", Validator.LENGTH_NUMERIC_COMPARISON, NumericComparisonOperator.LESS_THAN_OR_EQUAL_TO, 255);
    v.addValidation("facConDegree", Validator.LENGTH_NUMERIC_COMPARISON, NumericComparisonOperator.LESS_THAN_OR_EQUAL_TO, 255);
    v.addValidation("facConPhone", Validator.LENGTH_NUMERIC_COMPARISON, NumericComparisonOperator.LESS_THAN_OR_EQUAL_TO, 255);
    v.addValidation("facConEmail", Validator.LENGTH_NUMERIC_COMPARISON, NumericComparisonOperator.LESS_THAN_OR_EQUAL_TO, 255);
    errors = v.validate();
    StudyBean newStudy = (StudyBean) session.getAttribute("newStudy");
    newStudy.setFacilityCity(fp.getString("facCity"));
    newStudy.setFacilityContactDegree(fp.getString("facConDrgree"));
    newStudy.setFacilityName(fp.getString("facName"));
    newStudy.setFacilityContactEmail(fp.getString("facConEmail"));
    newStudy.setFacilityContactPhone(fp.getString("facConPhone"));
    newStudy.setFacilityContactName(fp.getString("facConName"));
    newStudy.setFacilityCountry(fp.getString("facCountry"));
    newStudy.setFacilityContactDegree(fp.getString("facConDegree"));
    // newStudy.setFacilityRecruitmentStatus(fp.getString("facRecStatus"));
    newStudy.setFacilityState(fp.getString("facState"));
    newStudy.setFacilityZip(fp.getString("facZip"));
    session.setAttribute("newStudy", newStudy);
    if (errors.isEmpty()) {
        forwardPage(Page.CREATE_STUDY7);
    } else {
        request.setAttribute("formMessages", errors);
        request.setAttribute("facRecruitStatusMap", facRecruitStatusMap);
        forwardPage(Page.CREATE_STUDY6);
    }
}
Also used : FormProcessor(org.akaza.openclinica.control.form.FormProcessor) StudyBean(org.akaza.openclinica.bean.managestudy.StudyBean) Validator(org.akaza.openclinica.control.form.Validator)

Aggregations

Validator (org.akaza.openclinica.control.form.Validator)53 FormProcessor (org.akaza.openclinica.control.form.FormProcessor)44 StudyBean (org.akaza.openclinica.bean.managestudy.StudyBean)28 ArrayList (java.util.ArrayList)26 HashMap (java.util.HashMap)20 StudyDAO (org.akaza.openclinica.dao.managestudy.StudyDAO)13 Date (java.util.Date)12 UserAccountBean (org.akaza.openclinica.bean.login.UserAccountBean)12 UserAccountDAO (org.akaza.openclinica.dao.login.UserAccountDAO)11 StudyEventDefinitionBean (org.akaza.openclinica.bean.managestudy.StudyEventDefinitionBean)7 ResourceBundle (java.util.ResourceBundle)6 StudyUserRoleBean (org.akaza.openclinica.bean.login.StudyUserRoleBean)6 Role (org.akaza.openclinica.bean.core.Role)5 ParseException (java.text.ParseException)4 SimpleDateFormat (java.text.SimpleDateFormat)4 SecurityManager (org.akaza.openclinica.core.SecurityManager)4 StudyParameterValueDAO (org.akaza.openclinica.dao.service.StudyParameterValueDAO)4 LinkedHashMap (java.util.LinkedHashMap)3 Locale (java.util.Locale)3 Map (java.util.Map)3