Search in sources :

Example 16 with Validator

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

the class CreateStudyServlet method confirmStudy2.

/**
     * Validates the second section of study info inputs
     *
     * @throws Exception
     */
private void confirmStudy2() throws Exception {
    Validator v = new Validator(request);
    FormProcessor fp = new FormProcessor(request);
    v.addValidation(INPUT_START_DATE, Validator.IS_A_DATE);
    if (!StringUtil.isBlank(fp.getString(INPUT_END_DATE))) {
        v.addValidation(INPUT_END_DATE, Validator.IS_A_DATE);
    }
    v.addValidation("protocolType", Validator.NO_BLANKS);
    if (!StringUtil.isBlank(fp.getString(INPUT_VER_DATE))) {
        v.addValidation(INPUT_VER_DATE, Validator.IS_A_DATE_WITHOUT_REQUIRED_CHECK);
    }
    errors = v.validate();
    boolean isInterventional = updateStudy2();
    session.setAttribute("isInterventionalFlag", new Boolean(isInterventional));
    if (errors.isEmpty()) {
        logger.info("no errors");
        setMaps(isInterventional);
        if (isInterventional) {
            forwardPage(Page.CREATE_STUDY3);
        } else {
            forwardPage(Page.CREATE_STUDY4);
        }
    } else {
        logger.info("has validation errors");
        try {
            local_df.parse(fp.getString(INPUT_START_DATE));
            fp.addPresetValue(INPUT_START_DATE, local_df.format(fp.getDate(INPUT_START_DATE)));
        } catch (ParseException pe) {
            fp.addPresetValue(INPUT_START_DATE, fp.getString(INPUT_START_DATE));
        }
        try {
            local_df.parse(fp.getString(INPUT_VER_DATE));
            fp.addPresetValue(INPUT_VER_DATE, local_df.format(fp.getDate(INPUT_VER_DATE)));
        } catch (ParseException pe) {
            fp.addPresetValue(INPUT_VER_DATE, fp.getString(INPUT_VER_DATE));
        }
        try {
            local_df.parse(fp.getString(INPUT_END_DATE));
            fp.addPresetValue(INPUT_END_DATE, local_df.format(fp.getDate(INPUT_END_DATE)));
        } catch (ParseException pe) {
            fp.addPresetValue(INPUT_END_DATE, fp.getString(INPUT_END_DATE));
        }
        setPresetValues(fp.getPresetValues());
        request.setAttribute("formMessages", errors);
        request.setAttribute("studyPhaseMap", studyPhaseMap);
        request.setAttribute("statuses", Status.toActiveArrayList());
        // request.setAttribute("studyTypes", StudyType.toArrayList());
        forwardPage(Page.CREATE_STUDY2);
    }
}
Also used : FormProcessor(org.akaza.openclinica.control.form.FormProcessor) ParseException(java.text.ParseException) Validator(org.akaza.openclinica.control.form.Validator)

Example 17 with Validator

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

the class ContactServlet method processRequest.

@Override
public void processRequest() throws Exception {
    String action = request.getParameter("action");
    if (StringUtil.isBlank(action)) {
        if (ub != null && ub.getId() > 0) {
            request.setAttribute("name", ub.getName());
            request.setAttribute("email", ub.getEmail());
        }
        forwardPage(Page.CONTACT);
    } else {
        if ("submit".equalsIgnoreCase(action)) {
            Validator v = new Validator(request);
            v.addValidation("name", Validator.NO_BLANKS);
            v.addValidation("email", Validator.IS_A_EMAIL);
            v.addValidation("subject", Validator.NO_BLANKS);
            v.addValidation("message", Validator.NO_BLANKS);
            errors = v.validate();
            FormProcessor fp = new FormProcessor(request);
            if (!errors.isEmpty()) {
                request.setAttribute("name", fp.getString("name"));
                request.setAttribute("email", fp.getString("email"));
                request.setAttribute("subject", fp.getString("subject"));
                request.setAttribute("message", fp.getString("message"));
                request.setAttribute("formMessages", errors);
                forwardPage(Page.CONTACT);
            } else {
                sendEmail();
            }
        } else {
            if (ub != null && ub.getId() > 0) {
                request.setAttribute("name", ub.getName());
                request.setAttribute("email", ub.getEmail());
            }
            forwardPage(Page.CONTACT);
        }
    }
}
Also used : FormProcessor(org.akaza.openclinica.control.form.FormProcessor) Validator(org.akaza.openclinica.control.form.Validator)

Example 18 with Validator

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

the class CreateStudyServlet method confirmWholeStudy.

/**
     * Lets user confirm all the study info entries input
     *
     * @throws Exception
     */
private void confirmWholeStudy() throws Exception {
    FormProcessor fp = new FormProcessor(request);
    Validator v = new Validator(request);
    errors = v.validate();
    StudyBean newStudy = (StudyBean) session.getAttribute("newStudy");
    newStudy.getStudyParameterConfig().setCollectDob(fp.getString("collectDob"));
    newStudy.getStudyParameterConfig().setDiscrepancyManagement(fp.getString("discrepancyManagement"));
    newStudy.getStudyParameterConfig().setGenderRequired(fp.getString("genderRequired"));
    newStudy.getStudyParameterConfig().setInterviewerNameRequired(fp.getString("interviewerNameRequired"));
    newStudy.getStudyParameterConfig().setInterviewerNameDefault(fp.getString("interviewerNameDefault"));
    newStudy.getStudyParameterConfig().setInterviewDateEditable(fp.getString("interviewDateEditable"));
    newStudy.getStudyParameterConfig().setInterviewDateRequired(fp.getString("interviewDateRequired"));
    newStudy.getStudyParameterConfig().setInterviewerNameEditable(fp.getString("interviewerNameEditable"));
    newStudy.getStudyParameterConfig().setInterviewDateDefault(fp.getString("interviewDateDefault"));
    newStudy.getStudyParameterConfig().setSubjectIdGeneration(fp.getString("subjectIdGeneration"));
    newStudy.getStudyParameterConfig().setSubjectPersonIdRequired(fp.getString("subjectPersonIdRequired"));
    newStudy.getStudyParameterConfig().setSubjectIdPrefixSuffix(fp.getString("subjectIdPrefixSuffix"));
    newStudy.getStudyParameterConfig().setPersonIdShownOnCRF(fp.getString("personIdShownOnCRF"));
    newStudy.getStudyParameterConfig().setSecondaryLabelViewable(fp.getString("secondaryLabelViewable"));
    newStudy.getStudyParameterConfig().setAdminForcedReasonForChange(fp.getString("adminForcedReasonForChange"));
    //  newStudy.getStudyParameterConfig().setParticipantPortant(fp.getString("participantPortal"));
    session.setAttribute("newStudy", newStudy);
    if (errors.isEmpty()) {
        if (session.getAttribute("interventionArray") == null) {
            request.setAttribute("interventions", new ArrayList());
        } else {
            request.setAttribute("interventions", session.getAttribute("interventionArray"));
        }
        forwardPage(Page.STUDY_CREATE_CONFIRM);
    } else {
        request.setAttribute("formMessages", errors);
        forwardPage(Page.CREATE_STUDY8);
    }
}
Also used : FormProcessor(org.akaza.openclinica.control.form.FormProcessor) StudyBean(org.akaza.openclinica.bean.managestudy.StudyBean) ArrayList(java.util.ArrayList) Validator(org.akaza.openclinica.control.form.Validator)

Example 19 with Validator

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

the class DefineStudyEventServlet method confirmWholeDefinition.

/**
     * Validates the entire definition
     * 
     * @throws Exception
     */
private void confirmWholeDefinition() throws Exception {
    Validator v = new Validator(request);
    FormProcessor fp = new FormProcessor(request);
    StudyEventDefinitionBean sed = (StudyEventDefinitionBean) session.getAttribute("definition");
    ArrayList eventDefinitionCRFs = new ArrayList();
    FormLayoutDAO fldao = new FormLayoutDAO(sm.getDataSource());
    for (int i = 0; i < sed.getCrfs().size(); i++) {
        EventDefinitionCRFBean edcBean = new EventDefinitionCRFBean();
        int crfId = fp.getInt("crfId" + i);
        int defaultVersionId = fp.getInt("defaultVersionId" + i);
        edcBean.setCrfId(crfId);
        edcBean.setDefaultVersionId(defaultVersionId);
        FormLayoutBean defaultVersion = (FormLayoutBean) fldao.findByPK(edcBean.getDefaultVersionId());
        edcBean.setDefaultVersionName(defaultVersion.getName());
        String crfName = fp.getString("crfName" + i);
        edcBean.setCrfName(crfName);
        String requiredCRF = fp.getString("requiredCRF" + i);
        String doubleEntry = fp.getString("doubleEntry" + i);
        String decisionCondition = fp.getString("decisionCondition" + i);
        String electronicSignature = fp.getString("electronicSignature" + i);
        String participantForm = fp.getString("participantForm" + i);
        String allowAnonymousSubmission = fp.getString("allowAnonymousSubmission" + i);
        String submissionUrl = fp.getString("submissionUrl" + i);
        String offline = fp.getString("offline" + i);
        // issue 312 BWP<<
        String hiddenCrf = fp.getString("hiddenCrf" + i);
        // hideCRF is false by default in the bean
        if (!StringUtil.isBlank(hiddenCrf) && "yes".equalsIgnoreCase(hiddenCrf.trim())) {
            edcBean.setHideCrf(true);
        } else {
            edcBean.setHideCrf(false);
        }
        // >>
        String sdvOption = fp.getString("sdvOption" + i);
        if (!StringUtils.isBlank(sdvOption)) {
            int id = Integer.valueOf(sdvOption);
            edcBean.setSourceDataVerification(SourceDataVerification.getByCode(id));
        }
        if (!StringUtils.isBlank(requiredCRF) && "yes".equalsIgnoreCase(requiredCRF.trim())) {
            edcBean.setRequiredCRF(true);
        } else {
            edcBean.setRequiredCRF(false);
        }
        if (!StringUtils.isBlank(participantForm) && "yes".equalsIgnoreCase(participantForm.trim())) {
            edcBean.setParticipantForm(true);
        } else {
            edcBean.setParticipantForm(false);
        }
        // when participant form is not selected, force allow anonymous to be not selected
        if (edcBean.isParticipantForm() && !StringUtils.isBlank(allowAnonymousSubmission) && "yes".equalsIgnoreCase(allowAnonymousSubmission.trim())) {
            edcBean.setAllowAnonymousSubmission(true);
        } else {
            edcBean.setAllowAnonymousSubmission(false);
        }
        if (!StringUtils.isBlank(offline) && "yes".equalsIgnoreCase(offline.trim())) {
            edcBean.setOffline(true);
        } else {
            edcBean.setOffline(false);
        }
        if (!StringUtils.isBlank(doubleEntry) && "yes".equalsIgnoreCase(doubleEntry.trim())) {
            edcBean.setDoubleEntry(true);
        } else {
            edcBean.setDoubleEntry(false);
        }
        if (!StringUtils.isBlank(decisionCondition) && "yes".equalsIgnoreCase(decisionCondition.trim())) {
            edcBean.setDecisionCondition(true);
        } else {
            edcBean.setDecisionCondition(false);
        }
        if (!StringUtils.isBlank(electronicSignature) && "yes".equalsIgnoreCase(electronicSignature.trim())) {
            edcBean.setElectronicSignature(true);
        } else {
            edcBean.setElectronicSignature(false);
        }
        // also useful to protect from naughty submission not coming from our html form
        if (edcBean.isParticipantForm() && edcBean.isAllowAnonymousSubmission()) {
            edcBean.setSubmissionUrl(submissionUrl.trim());
        }
        ArrayList<CRFVersionBean> versions = fldao.findAllByCRFId(crfId);
        edcBean.setVersions(versions);
        String nullString = "";
        // process null values
        ArrayList nulls = NullValue.toArrayList();
        for (int a = 0; a < nulls.size(); a++) {
            NullValue n = (NullValue) nulls.get(a);
            String myNull = fp.getString(n.getName().toLowerCase() + i);
            if (!StringUtils.isBlank(myNull) && "yes".equalsIgnoreCase(myNull.trim())) {
                nullString = nullString + n.getName().toUpperCase() + ",";
            }
        }
        edcBean.setNullValues(nullString);
        edcBean.setStudyId(ub.getActiveStudyId());
        eventDefinitionCRFs.add(edcBean);
    }
    StudyParameterValueDAO spvdao = new StudyParameterValueDAO(sm.getDataSource());
    String participateFormStatus = spvdao.findByHandleAndStudy(sed.getStudyId(), "participantPortal").getValue();
    request.setAttribute("participateFormStatus", participateFormStatus);
    if (participateFormStatus.equals("enabled"))
        baseUrl();
    request.setAttribute("participateFormStatus", participateFormStatus);
    request.setAttribute("eventDefinitionCRFs", eventDefinitionCRFs);
    // not used on page
    session.setAttribute("edCRFs", eventDefinitionCRFs);
    ArrayList<EventDefinitionCRFBean> edcsInSession = (ArrayList<EventDefinitionCRFBean>) session.getAttribute("edCRFs");
    int parentStudyId = sed.getStudyId();
    EventDefinitionCRFDAO edcdao = new EventDefinitionCRFDAO(sm.getDataSource());
    ArrayList<EventDefinitionCRFBean> eventDefCrfList = (ArrayList<EventDefinitionCRFBean>) edcdao.findAllActiveSitesAndStudiesPerParentStudy(parentStudyId);
    if (eventDefCrfList.size() != 0)
        validateSubmissionUrl(edcsInSession, eventDefCrfList, v);
    errors = v.validate();
    if (!errors.isEmpty()) {
        ArrayList<String> sdvOptions = new ArrayList<String>();
        sdvOptions.add(SourceDataVerification.AllREQUIRED.toString());
        sdvOptions.add(SourceDataVerification.PARTIALREQUIRED.toString());
        sdvOptions.add(SourceDataVerification.NOTREQUIRED.toString());
        sdvOptions.add(SourceDataVerification.NOTAPPLICABLE.toString());
        request.setAttribute("sdvOptions", sdvOptions);
        logger.info("has errors");
        session.setAttribute("eventDefinitionCRFs", eventDefinitionCRFs);
        request.setAttribute("formMessages", errors);
        forwardPage(Page.DEFINE_STUDY_EVENT4);
    }
    forwardPage(Page.DEFINE_STUDY_EVENT_CONFIRM);
}
Also used : FormProcessor(org.akaza.openclinica.control.form.FormProcessor) ArrayList(java.util.ArrayList) FormLayoutBean(org.akaza.openclinica.bean.submit.FormLayoutBean) StudyEventDefinitionBean(org.akaza.openclinica.bean.managestudy.StudyEventDefinitionBean) EventDefinitionCRFDAO(org.akaza.openclinica.dao.managestudy.EventDefinitionCRFDAO) NullValue(org.akaza.openclinica.bean.core.NullValue) FormLayoutDAO(org.akaza.openclinica.dao.submit.FormLayoutDAO) CRFVersionBean(org.akaza.openclinica.bean.submit.CRFVersionBean) EventDefinitionCRFBean(org.akaza.openclinica.bean.managestudy.EventDefinitionCRFBean) StudyParameterValueDAO(org.akaza.openclinica.dao.service.StudyParameterValueDAO) Validator(org.akaza.openclinica.control.form.Validator)

Example 20 with Validator

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

the class DefineStudyEventServlet method confirmDefinition1.

/**
     * Validates the first section of definition inputs
     * 
     * @throws Exception
     */
private void confirmDefinition1() 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, 2000);
    v.addValidation("description", Validator.LENGTH_NUMERIC_COMPARISON, NumericComparisonOperator.LESS_THAN_OR_EQUAL_TO, 2000);
    v.addValidation("category", Validator.LENGTH_NUMERIC_COMPARISON, NumericComparisonOperator.LESS_THAN_OR_EQUAL_TO, 2000);
    errors = v.validate();
    session.setAttribute("definition", createStudyEventDefinition());
    if (errors.isEmpty()) {
        logger.debug("no errors in the first section");
        // logger.debug("actionName*******" + fp.getString("actionName"));
        // debugger.debug("pageNum*******" + fp.getString("pageNum"));
        ArrayList crfArray = new ArrayList();
        /*
             * The tmpCRFIdMap will hold all the selected CRFs in the session
             * when the user is navigating through the list. This has been done
             * so that when the user moves to the next page of CRF list, the
             * selection made in the previous page doesn't get lost.
             */
        Map tmpCRFIdMap = (HashMap) session.getAttribute("tmpCRFIdMap");
        if (tmpCRFIdMap == null) {
            tmpCRFIdMap = new HashMap();
        }
        ArrayList crfsWithVersion = (ArrayList) session.getAttribute("crfsWithVersion");
        for (int i = 0; i < crfsWithVersion.size(); i++) {
            int id = fp.getInt("id" + i);
            String name = fp.getString("name" + i);
            String selected = fp.getString("selected" + i);
            if (!StringUtil.isBlank(selected) && "yes".equalsIgnoreCase(selected.trim())) {
                tmpCRFIdMap.put(id, name);
            } else {
                // deselected.
                if (tmpCRFIdMap.containsKey(id)) {
                    tmpCRFIdMap.remove(id);
                }
            }
        }
        session.setAttribute("tmpCRFIdMap", tmpCRFIdMap);
        EntityBeanTable table = fp.getEntityBeanTable();
        ArrayList allRows = CRFRow.generateRowsFromBeans(crfsWithVersion);
        String[] columns = { resword.getString("CRF_name"), resword.getString("date_created"), resword.getString("owner"), resword.getString("date_updated"), resword.getString("last_updated_by"), resword.getString("selected") };
        table.setColumns(new ArrayList(Arrays.asList(columns)));
        table.hideColumnLink(5);
        StudyEventDefinitionBean def1 = (StudyEventDefinitionBean) session.getAttribute("definition");
        HashMap args = new HashMap();
        args.put("actionName", "next");
        args.put("pageNum", "1");
        args.put("name", URLEncoder.encode(def1.getName(), "UTF-8"));
        args.put("repeating", new Boolean(def1.isRepeating()).toString());
        args.put("category", def1.getCategory());
        args.put("description", URLEncoder.encode(def1.getDescription(), "UTF-8"));
        args.put("type", def1.getType());
        table.setQuery("DefineStudyEvent", args, true);
        table.setRows(allRows);
        table.computeDisplay();
        request.setAttribute("table", table);
        forwardPage(Page.DEFINE_STUDY_EVENT2);
    } else {
        logger.debug("has validation errors in the first section");
        request.setAttribute("formMessages", errors);
        forwardPage(Page.DEFINE_STUDY_EVENT1);
    }
}
Also used : HashMap(java.util.HashMap) FormProcessor(org.akaza.openclinica.control.form.FormProcessor) EntityBeanTable(org.akaza.openclinica.web.bean.EntityBeanTable) ArrayList(java.util.ArrayList) StudyEventDefinitionBean(org.akaza.openclinica.bean.managestudy.StudyEventDefinitionBean) HashMap(java.util.HashMap) Map(java.util.Map) 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