Search in sources :

Example 16 with FormProcessor

use of org.akaza.openclinica.control.form.FormProcessor 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);
        }
    }
}
Also used : ConfigurationDao(org.akaza.openclinica.dao.hibernate.ConfigurationDao) FormProcessor(org.akaza.openclinica.control.form.FormProcessor) PasswordRequirementsDao(org.akaza.openclinica.dao.hibernate.PasswordRequirementsDao) Validator(org.akaza.openclinica.control.form.Validator)

Example 17 with FormProcessor

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

the class DeleteEventCRFServlet method processRequest.

@Override
public void processRequest() throws Exception {
    FormProcessor fp = new FormProcessor(request);
    int studySubId = fp.getInt(STUDY_SUB_ID, true);
    int eventCRFId = fp.getInt(EVENT_CRF_ID);
    String action = request.getParameter("action");
    StudyEventDAO sedao = new StudyEventDAO(sm.getDataSource());
    StudySubjectDAO subdao = new StudySubjectDAO(sm.getDataSource());
    EventCRFDAO ecdao = new EventCRFDAO(sm.getDataSource());
    StudyDAO sdao = new StudyDAO(sm.getDataSource());
    if (eventCRFId == 0) {
        addPageMessage(respage.getString("please_choose_an_event_CRF_to_delete"));
        request.setAttribute("id", new Integer(studySubId).toString());
        forwardPage(Page.VIEW_STUDY_SUBJECT_SERVLET);
    } else {
        EventCRFBean eventCRF = (EventCRFBean) ecdao.findByPK(eventCRFId);
        StudySubjectBean studySub = (StudySubjectBean) subdao.findByPK(studySubId);
        request.setAttribute("studySub", studySub);
        // construct info needed on view event crf page
        CRFDAO cdao = new CRFDAO(sm.getDataSource());
        CRFVersionDAO cvdao = new CRFVersionDAO(sm.getDataSource());
        int crfVersionId = eventCRF.getCRFVersionId();
        CRFBean cb = cdao.findByVersionId(crfVersionId);
        eventCRF.setCrf(cb);
        CRFVersionBean cvb = (CRFVersionBean) cvdao.findByPK(crfVersionId);
        eventCRF.setCrfVersion(cvb);
        // then get the definition so we can call
        // DisplayEventCRFBean.setFlags
        int studyEventId = eventCRF.getStudyEventId();
        StudyEventBean event = (StudyEventBean) sedao.findByPK(studyEventId);
        int studyEventDefinitionId = sedao.getDefinitionIdFromStudyEventId(studyEventId);
        StudyEventDefinitionDAO seddao = new StudyEventDefinitionDAO(sm.getDataSource());
        StudyEventDefinitionBean sed = (StudyEventDefinitionBean) seddao.findByPK(studyEventDefinitionId);
        event.setStudyEventDefinition(sed);
        request.setAttribute("event", event);
        EventDefinitionCRFDAO edcdao = new EventDefinitionCRFDAO(sm.getDataSource());
        StudyBean study = (StudyBean) sdao.findByPK(studySub.getStudyId());
        EventDefinitionCRFBean edc = edcdao.findByStudyEventDefinitionIdAndCRFId(study, studyEventDefinitionId, cb.getId());
        DisplayEventCRFBean dec = new DisplayEventCRFBean();
        dec.setEventCRF(eventCRF);
        dec.setFlags(eventCRF, ub, currentRole, edc.isDoubleEntry());
        // find all item data
        ItemDataDAO iddao = new ItemDataDAO(sm.getDataSource());
        dnDao = new DiscrepancyNoteDAO(sm.getDataSource());
        ArrayList<ItemDataBean> itemData = iddao.findAllByEventCRFId(eventCRF.getId());
        request.setAttribute("items", itemData);
        if ("confirm".equalsIgnoreCase(action)) {
            request.setAttribute("displayEventCRF", dec);
            forwardPage(Page.DELETE_EVENT_CRF);
        } else {
            logger.info("submit to delete the event CRF from event");
            // OC-6303 Deleting Event CRF resets Show / Hide logic
            // delete records from DynamicItemForm and DynamicItemGroup
            // getDynamicsItemFormMetadataDao().delete(eventCRFId);
            // getDynamicsItemGroupMetadataDao().delete(eventCRFId);
            eventCRF.setOldStatus(eventCRF.getStatus());
            eventCRF.setStatus(Status.RESET);
            eventCRF.setUpdater(ub);
            ecdao.update(eventCRF);
            for (ItemDataBean itemdata : itemData) {
                // OC-6343 Rule behaviour must be reset if an Event CRF is deleted
                // delete the records from ruleActionRunLogDao
                List<RuleActionRunLogBean> ruleActionRunLog = getRuleActionRunLogDao().findAllItemData(itemdata.getId());
                if (ruleActionRunLog.size() != 0) {
                    getRuleActionRunLogDao().delete(itemdata.getId());
                }
                // OC-6344 Notes & Discrepancies must be set to "closed" when event CRF is deleted
                // parentDiscrepancyNoteList is the list of the parent DNs records only
                ArrayList<DiscrepancyNoteBean> parentDiscrepancyNoteList = getDnDao().findParentNotesOnlyByItemData(itemdata.getId());
                for (DiscrepancyNoteBean parentDiscrepancyNote : parentDiscrepancyNoteList) {
                    if (parentDiscrepancyNote.getResolutionStatusId() != 4) {
                        // if the DN's resolution status is
                        // not set to Closed
                        String description = resword.getString("dn_auto-closed_description");
                        String detailedNotes = resword.getString("dn_auto_closed_detailed_notes");
                        // create new DN record , new DN Map record , also update the parent record
                        createDiscrepancyNoteBean(description, detailedNotes, itemdata.getId(), study, ub, parentDiscrepancyNote);
                    }
                }
                iddao = new ItemDataDAO(sm.getDataSource());
                ifmdao = new ItemFormMetadataDAO(sm.getDataSource());
                ItemDataBean idBean = (ItemDataBean) iddao.findByPK(itemdata.getId());
                ItemFormMetadataBean ifmBean = ifmdao.findByItemIdAndCRFVersionId(idBean.getItemId(), crfVersionId);
                // Updating Dn_item_data_map actovated column into false for the existing DNs
                ArrayList<DiscrepancyNoteBean> dnBeans = getDnDao().findExistingNotesForItemData(itemdata.getId());
                if (dnBeans.size() != 0) {
                    DiscrepancyNoteBean dnBean = new DiscrepancyNoteBean();
                    dnBean.setEntityId(itemdata.getId());
                    dnBean.setActivated(false);
                    getDnDao().updateDnMapActivation(dnBean);
                }
                // Default Values are not addressed
                itemdata.setValue("");
                itemdata.setOldStatus(itemdata.getStatus());
                itemdata.setOwner(ub);
                itemdata.setStatus(Status.AVAILABLE);
                itemdata.setUpdater(ub);
                iddao.updateUser(itemdata);
                iddao.update(itemdata);
            }
            // OC-6291 event_crf status change
            eventCRF.setOldStatus(eventCRF.getStatus());
            eventCRF.setStatus(Status.AVAILABLE);
            eventCRF.setUpdater(ub);
            ecdao.update(eventCRF);
            if (event.getSubjectEventStatus().isCompleted() || event.getSubjectEventStatus().isSigned()) {
                event.setSubjectEventStatus(SubjectEventStatus.DATA_ENTRY_STARTED);
                event.setUpdater(ub);
                sedao = new StudyEventDAO(sm.getDataSource());
                sedao.update(event);
            }
            String emailBody = respage.getString("the_event_CRF") + cb.getName() + respage.getString("has_been_deleted_from_the_event") + event.getStudyEventDefinition().getName() + ". " + respage.getString("has_been_deleted_from_the_event_cont");
            addPageMessage(emailBody);
            // sendEmail(emailBody);
            request.setAttribute("id", new Integer(studySubId).toString());
            forwardPage(Page.VIEW_STUDY_SUBJECT_SERVLET);
        }
    }
}
Also used : StudyEventDefinitionBean(org.akaza.openclinica.bean.managestudy.StudyEventDefinitionBean) StudyEventBean(org.akaza.openclinica.bean.managestudy.StudyEventBean) ItemDataDAO(org.akaza.openclinica.dao.submit.ItemDataDAO) EventCRFBean(org.akaza.openclinica.bean.submit.EventCRFBean) DisplayEventCRFBean(org.akaza.openclinica.bean.submit.DisplayEventCRFBean) RuleActionRunLogBean(org.akaza.openclinica.domain.rule.action.RuleActionRunLogBean) ItemDataBean(org.akaza.openclinica.bean.submit.ItemDataBean) StudyEventDAO(org.akaza.openclinica.dao.managestudy.StudyEventDAO) StudyDAO(org.akaza.openclinica.dao.managestudy.StudyDAO) EventCRFDAO(org.akaza.openclinica.dao.submit.EventCRFDAO) ItemFormMetadataDAO(org.akaza.openclinica.dao.submit.ItemFormMetadataDAO) EventDefinitionCRFDAO(org.akaza.openclinica.dao.managestudy.EventDefinitionCRFDAO) EventCRFDAO(org.akaza.openclinica.dao.submit.EventCRFDAO) CRFDAO(org.akaza.openclinica.dao.admin.CRFDAO) DiscrepancyNoteDAO(org.akaza.openclinica.dao.managestudy.DiscrepancyNoteDAO) CRFVersionDAO(org.akaza.openclinica.dao.submit.CRFVersionDAO) FormProcessor(org.akaza.openclinica.control.form.FormProcessor) StudyBean(org.akaza.openclinica.bean.managestudy.StudyBean) EventDefinitionCRFDAO(org.akaza.openclinica.dao.managestudy.EventDefinitionCRFDAO) StudySubjectDAO(org.akaza.openclinica.dao.managestudy.StudySubjectDAO) EventCRFBean(org.akaza.openclinica.bean.submit.EventCRFBean) CRFBean(org.akaza.openclinica.bean.admin.CRFBean) DisplayEventCRFBean(org.akaza.openclinica.bean.submit.DisplayEventCRFBean) EventDefinitionCRFBean(org.akaza.openclinica.bean.managestudy.EventDefinitionCRFBean) DisplayEventCRFBean(org.akaza.openclinica.bean.submit.DisplayEventCRFBean) StudySubjectBean(org.akaza.openclinica.bean.managestudy.StudySubjectBean) StudyEventDefinitionDAO(org.akaza.openclinica.dao.managestudy.StudyEventDefinitionDAO) DiscrepancyNoteBean(org.akaza.openclinica.bean.managestudy.DiscrepancyNoteBean) CRFVersionBean(org.akaza.openclinica.bean.submit.CRFVersionBean) EventDefinitionCRFBean(org.akaza.openclinica.bean.managestudy.EventDefinitionCRFBean) ItemFormMetadataBean(org.akaza.openclinica.bean.submit.ItemFormMetadataBean)

Example 18 with FormProcessor

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

the class AuditDatabaseServlet method processRequest.

@Override
protected void processRequest() throws Exception {
    FormProcessor fp = new FormProcessor(request);
    String auditDatabaseHtml = renderAuditDatabaseTable(getDatabaseChangeLogDao().findAll());
    request.setAttribute("auditDatabaseHtml", auditDatabaseHtml);
    forwardPage(Page.AUDIT_DATABASE);
}
Also used : FormProcessor(org.akaza.openclinica.control.form.FormProcessor)

Example 19 with FormProcessor

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

the class AuditLogStudyServlet method processRequest.

/*
     * (non-Javadoc) Assume that we get the user id automatically. We will jump
     * from the edit user page if the user is an admin, they can get to see the
     * users' log
     * 
     * @see org.akaza.openclinica.control.core.SecureController#processRequest()
     */
/*
     * (non-Javadoc) redo this servlet to run the audits per study subject for
     * the study; need to add a studyId param and then use the
     * StudySubjectDAO.findAllByStudyOrderByLabel() method to grab a lot of
     * study subject beans and then return them much like in
     * ViewStudySubjectAuditLogServet.process()
     * 
     * currentStudy instead of studyId?
     */
@Override
protected void processRequest() throws Exception {
    int studyId = currentStudy.getId();
    StudySubjectDAO subdao = new StudySubjectDAO(sm.getDataSource());
    SubjectDAO sdao = new SubjectDAO(sm.getDataSource());
    AuditDAO adao = new AuditDAO(sm.getDataSource());
    FormProcessor fp = new FormProcessor(request);
    StudyEventDAO sedao = new StudyEventDAO(sm.getDataSource());
    StudyEventDefinitionDAO seddao = new StudyEventDefinitionDAO(sm.getDataSource());
    EventDefinitionCRFDAO edcdao = new EventDefinitionCRFDAO(sm.getDataSource());
    EventCRFDAO ecdao = new EventCRFDAO(sm.getDataSource());
    StudyDAO studydao = new StudyDAO(sm.getDataSource());
    CRFDAO cdao = new CRFDAO(sm.getDataSource());
    CRFVersionDAO cvdao = new CRFVersionDAO(sm.getDataSource());
    HashMap eventCRFAuditsHashMap = new HashMap();
    HashMap eventsHashMap = new HashMap();
    HashMap studySubjectAuditsHashMap = new HashMap();
    HashMap subjectHashMap = new HashMap();
    ArrayList studySubjects = subdao.findAllByStudyOrderByLabel(currentStudy);
    logger.info("found " + studySubjects.size() + " study subjects");
    request.setAttribute("studySubjects", studySubjects);
    for (int ss = 0; ss < studySubjects.size(); ss++) {
        ArrayList studySubjectAudits = new ArrayList();
        ArrayList eventCRFAudits = new ArrayList();
        StudySubjectBean studySubject = (StudySubjectBean) studySubjects.get(ss);
        // request.setAttribute("studySub"+ss, studySubject);
        SubjectBean subject = (SubjectBean) sdao.findByPK(studySubject.getSubjectId());
        subjectHashMap.put(new Integer(studySubject.getId()), subject);
        // logger.info("just set a subject with a status of
        // "+subject.getStatus().getName());
        // request.setAttribute("subject"+ss, subject);
        StudyBean study = (StudyBean) studydao.findByPK(studySubject.getStudyId());
        request.setAttribute("study", study);
        // hmm, repetitive work?
        // Show both study subject and subject audit events together
        // Study
        studySubjectAudits.addAll(adao.findStudySubjectAuditEvents(studySubject.getId()));
        // subject
        // value
        // changed
        // Global
        studySubjectAudits.addAll(adao.findSubjectAuditEvents(subject.getId()));
        // subject
        // value
        // changed
        studySubjectAuditsHashMap.put(new Integer(studySubject.getId()), studySubjectAudits);
        // request.setAttribute("studySubjectAudits"+ss,
        // studySubjectAudits);
        // Get the list of events
        ArrayList events = sedao.findAllByStudySubject(studySubject);
        for (int i = 0; i < events.size(); i++) {
            // Link study event definitions
            StudyEventBean studyEvent = (StudyEventBean) events.get(i);
            studyEvent.setStudyEventDefinition((StudyEventDefinitionBean) seddao.findByPK(studyEvent.getStudyEventDefinitionId()));
            // Link event CRFs
            studyEvent.setEventCRFs(ecdao.findAllByStudyEvent(studyEvent));
        }
        // for (int i = 0; i < events.size(); i++) {
        // StudyEventBean studyEvent = (StudyEventBean) events.get(i);
        // ArrayList eventCRFs = studyEvent.getEventCRFs();
        // for (int j = 0; j < eventCRFs.size(); j++) {
        // //Link CRF and CRF Versions
        // EventCRFBean eventCRF = (EventCRFBean) eventCRFs.get(j);
        // eventCRF.setCrfVersion((CRFVersionBean)
        // cvdao.findByPK(eventCRF.getCRFVersionId()));
        // eventCRF.setCrf((CRFBean)
        // cdao.findByVersionId(eventCRF.getCRFVersionId()));
        // //Get the event crf audits
        // eventCRFAudits.addAll(adao.findEventCRFAuditEvents(eventCRF.getId()));
        // }
        // }
        eventsHashMap.put(new Integer(studySubject.getId()), events);
    // request.setAttribute("events"+ss, events);
    // eventCRFAuditsHashMap.put(new Integer(studySubject.getId()),
    // eventCRFAudits);
    // request.setAttribute("eventCRFAudits"+ss, eventCRFAudits);
    }
    // request.setAttribute("eventCRFAudits", eventCRFAuditsHashMap);
    request.setAttribute("events", eventsHashMap);
    request.setAttribute("studySubjectAudits", studySubjectAuditsHashMap);
    request.setAttribute("study", currentStudy);
    request.setAttribute("subjects", subjectHashMap);
    // FormProcessor fp = new FormProcessor(request);
    //
    // AuditEventDAO aeDAO = new AuditEventDAO(sm.getDataSource());
    // ArrayList al = aeDAO.findAllByStudyId(currentStudy.getId());
    //
    // EntityBeanTable table = fp.getEntityBeanTable();
    // ArrayList allRows = AuditEventStudyRow.generateRowsFromBeans(al);
    // String[] columns = { "Date and Time", "Action", "Entity/Operation",
    // "Record ID", "Changes and Additions","Other Info" };
    // table.setColumns(new ArrayList(Arrays.asList(columns)));
    // table.hideColumnLink(4);
    // table.hideColumnLink(1);
    // table.hideColumnLink(5);
    // table.setQuery("AuditLogUser?userLogId="+userId, new HashMap());
    // String[] columns =
    // {resword.getString("date_and_time"),resword.getString("action_message"),
    // resword.getString("entity_operation"),
    // resword.getString("updated_by"),resword.getString("subject_unique_ID"),resword.getString("changes_and_additions"),
    // //"Other Info",
    // resword.getString("actions")};
    // table.setColumns(new ArrayList(Arrays.asList(columns)));
    // table.setAscendingSort(false);
    // table.hideColumnLink(1);
    // table.hideColumnLink(5);
    // table.hideColumnLink(6);
    // //table.hideColumnLink(7);
    // table.setQuery("AuditLogStudy", new HashMap());
    // table.setRows(allRows);
    // table.computeDisplay();
    //
    //
    // request.setAttribute("table", table);
    logger.warn("*** found servlet, sending to page ***");
    String pattn = "";
    String pattern2 = "";
    pattn = ResourceBundleProvider.getFormatBundle().getString("date_format_string");
    pattern2 = ResourceBundleProvider.getFormatBundle().getString("date_time_format_string");
    request.setAttribute("dateFormatPattern", pattn);
    request.setAttribute("dateTimeFormatPattern", pattern2);
    forwardPage(Page.AUDIT_LOG_STUDY);
}
Also used : EventDefinitionCRFDAO(org.akaza.openclinica.dao.managestudy.EventDefinitionCRFDAO) EventCRFDAO(org.akaza.openclinica.dao.submit.EventCRFDAO) CRFDAO(org.akaza.openclinica.dao.admin.CRFDAO) CRFVersionDAO(org.akaza.openclinica.dao.submit.CRFVersionDAO) HashMap(java.util.HashMap) StudySubjectDAO(org.akaza.openclinica.dao.managestudy.StudySubjectDAO) SubjectDAO(org.akaza.openclinica.dao.submit.SubjectDAO) FormProcessor(org.akaza.openclinica.control.form.FormProcessor) StudyBean(org.akaza.openclinica.bean.managestudy.StudyBean) ArrayList(java.util.ArrayList) EventDefinitionCRFDAO(org.akaza.openclinica.dao.managestudy.EventDefinitionCRFDAO) StudyEventBean(org.akaza.openclinica.bean.managestudy.StudyEventBean) StudySubjectDAO(org.akaza.openclinica.dao.managestudy.StudySubjectDAO) AuditDAO(org.akaza.openclinica.dao.admin.AuditDAO) SubjectBean(org.akaza.openclinica.bean.submit.SubjectBean) StudySubjectBean(org.akaza.openclinica.bean.managestudy.StudySubjectBean) StudyEventDefinitionDAO(org.akaza.openclinica.dao.managestudy.StudyEventDefinitionDAO) StudySubjectBean(org.akaza.openclinica.bean.managestudy.StudySubjectBean) StudyEventDAO(org.akaza.openclinica.dao.managestudy.StudyEventDAO) StudyDAO(org.akaza.openclinica.dao.managestudy.StudyDAO) EventCRFDAO(org.akaza.openclinica.dao.submit.EventCRFDAO)

Example 20 with FormProcessor

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

the class CreateCRFVersionServlet method processRequest.

@SuppressWarnings("unchecked")
@Override
public void processRequest() throws Exception {
    resetPanel();
    panel.setStudyInfoShown(true);
    CRFDAO cdao = new CRFDAO(sm.getDataSource());
    CRFVersionDAO vdao = new CRFVersionDAO(sm.getDataSource());
    EventDefinitionCRFDAO edao = new EventDefinitionCRFDAO(sm.getDataSource());
    FormProcessor fp = new FormProcessor(request);
    // checks which module the requests are from
    String module = fp.getString(MODULE);
    // keep the module in the session
    session.setAttribute(MODULE, module);
    request.setAttribute("xformEnabled", CoreResources.getField("xform.enabled"));
    String action = request.getParameter("action");
    CRFVersionBean version = (CRFVersionBean) session.getAttribute("version");
    if (StringUtil.isBlank(action)) {
        logger.debug("action is blank");
        request.setAttribute("version", version);
        forwardPage(Page.CREATE_CRF_VERSION);
    } else if ("confirm".equalsIgnoreCase(action)) {
        String dir = SQLInitServlet.getField("filePath");
        if (!new File(dir).exists()) {
            logger.debug("The filePath in datainfo.properties is invalid " + dir);
            addPageMessage(resword.getString("the_filepath_you_defined"));
            forwardPage(Page.CREATE_CRF_VERSION);
            // BWP 01/13/2009 >>
            return;
        // >>
        }
        // All the uploaded files will be saved in filePath/crf/original/
        String theDir = dir + "crf" + File.separator + "original" + File.separator;
        if (!new File(theDir).isDirectory()) {
            new File(theDir).mkdirs();
            logger.debug("Made the directory " + theDir);
        }
        // MultipartRequest multi = new MultipartRequest(request, theDir, 50 * 1024 * 1024);
        String tempFile = "";
        try {
            tempFile = uploadFile(theDir, version);
        } catch (CRFReadingException crfException) {
            Validator.addError(errors, "excel_file", crfException.getMessage());
            String msg = crfException.getMessage();
            request.setAttribute("formMessages", errors);
            forwardPage(Page.CREATE_CRF_VERSION);
            return;
        } catch (Exception e) {
            //
            logger.warn("*** Found exception during file upload***");
            e.printStackTrace();
        }
        session.setAttribute("tempFileName", tempFile);
        // provided and/or not xls format
        if (errors.isEmpty()) {
            String s = ((NewCRFBean) session.getAttribute("nib")).getVersionName();
            if (s.length() > 255) {
                Validator.addError(errors, "excel_file", resword.getString("the_version_CRF_version_more_than_255"));
            } else if (s.length() <= 0) {
                Validator.addError(errors, "excel_file", resword.getString("the_VERSION_column_was_blank"));
            }
            version.setName(s);
            if (version.getCrfId() == 0) {
                version.setCrfId(fp.getInt("crfId"));
            }
            session.setAttribute("version", version);
        }
        if (!errors.isEmpty()) {
            logger.debug("has validation errors ");
            request.setAttribute("formMessages", errors);
            forwardPage(Page.CREATE_CRF_VERSION);
        } else {
            CRFBean crf = (CRFBean) cdao.findByPK(version.getCrfId());
            ArrayList versions = (ArrayList) vdao.findAllByCRF(crf.getId());
            for (int i = 0; i < versions.size(); i++) {
                CRFVersionBean version1 = (CRFVersionBean) versions.get(i);
                if (version.getName().equals(version1.getName())) {
                    // version already exists
                    logger.debug("Version already exists; owner or not:" + ub.getId() + "," + version1.getOwnerId());
                    if (ub.getId() != version1.getOwnerId()) {
                        // not owner
                        addPageMessage(respage.getString("CRF_version_try_upload_exists_database") + version1.getOwner().getName() + respage.getString("please_contact_owner_to_delete"));
                        forwardPage(Page.CREATE_CRF_VERSION);
                        return;
                    } else {
                        // owner,
                        ArrayList definitions = edao.findByDefaultVersion(version1.getId());
                        if (!definitions.isEmpty()) {
                            // used in
                            // definition
                            request.setAttribute("definitions", definitions);
                            forwardPage(Page.REMOVE_CRF_VERSION_DEF);
                            return;
                        } else {
                            // not used in definition
                            int previousVersionId = version1.getId();
                            version.setId(previousVersionId);
                            session.setAttribute("version", version);
                            session.setAttribute("previousVersionId", new Integer(previousVersionId));
                            forwardPage(Page.REMOVE_CRF_VERSION_CONFIRM);
                            return;
                        }
                    }
                }
            }
            // didn't find same version in the DB,let user upload the excel
            // file
            logger.debug("didn't find same version in the DB,let user upload the excel file.");
            // List excelErr =
            // ((ArrayList)request.getAttribute("excelErrors"));
            List excelErr = (ArrayList) session.getAttribute("excelErrors");
            logger.debug("excelErr.isEmpty()=" + excelErr.isEmpty());
            if (excelErr != null && excelErr.isEmpty()) {
                addPageMessage(resword.getString("congratulations_your_spreadsheet_no_errors"));
                forwardPage(Page.VIEW_SECTION_DATA_ENTRY_PREVIEW);
            } else {
                logger.debug("OpenClinicaException thrown, forwarding to CREATE_CRF_VERSION_CONFIRM.");
                forwardPage(Page.CREATE_CRF_VERSION_CONFIRM);
            }
            return;
        }
    } else if ("confirmsql".equalsIgnoreCase(action)) {
        NewCRFBean nib = (NewCRFBean) session.getAttribute("nib");
        if (nib != null && nib.getItemQueries() != null) {
            request.setAttribute("openQueries", nib.getItemQueries());
        } else {
            request.setAttribute("openQueries", new HashMap());
        }
        boolean canDelete = false;
        // check whether need to delete previous version
        Boolean deletePreviousVersion = (Boolean) session.getAttribute("deletePreviousVersion");
        Integer previousVersionId = (Integer) session.getAttribute("previousVersionId");
        if (deletePreviousVersion != null && deletePreviousVersion.equals(Boolean.TRUE) && previousVersionId != null && previousVersionId.intValue() > 0) {
            logger.debug("Need to delete previous version");
            // whether we can delete
            canDelete = canDeleteVersion(previousVersionId.intValue());
            if (!canDelete) {
                logger.debug("but cannot delete previous version");
                if (session.getAttribute("itemsHaveData") == null && session.getAttribute("eventsForVersion") == null) {
                    addPageMessage(respage.getString("you_are_not_owner_some_items_cannot_delete"));
                }
                if (session.getAttribute("itemsHaveData") == null) {
                    session.setAttribute("itemsHaveData", new ArrayList());
                }
                if (session.getAttribute("eventsForVersion") == null) {
                    session.setAttribute("eventsForVersion", new ArrayList());
                }
                forwardPage(Page.CREATE_CRF_VERSION_NODELETE);
                return;
            }
            ArrayList<ItemBean> nonSharedItems = (ArrayList<ItemBean>) vdao.findNotSharedItemsByVersion(previousVersionId.intValue());
            // htaycher: here is the trick we need to put in nib1.setItemQueries()
            // update statements for shared items and insert for nonShared that were just deleted 5927
            HashMap item_table_statements = new HashMap();
            ArrayList<String> temp = new ArrayList<String>(nonSharedItems.size());
            for (ItemBean item : nonSharedItems) {
                temp.add(item.getName());
                item_table_statements.put(item.getName(), nib.getBackupItemQueries().get(item.getName()));
            }
            for (String item_name : (Set<String>) nib.getItemQueries().keySet()) {
                // check if item shared
                if (!temp.contains(item_name)) {
                    item_table_statements.put(item_name, nib.getItemQueries().get(item_name));
                }
            }
            // statements to run
            if (!nonSharedItems.isEmpty()) {
                request.setAttribute("openQueries", item_table_statements);
            }
            // htaycher: put all statements in
            nib.setItemQueries(item_table_statements);
            session.setAttribute("nib", nib);
        }
        // submit
        logger.debug("commit sql");
        NewCRFBean nib1 = (NewCRFBean) session.getAttribute("nib");
        if (nib1 != null) {
            try {
                if (canDelete) {
                    nib1.deleteInsertToDB();
                } else {
                    nib1.insertToDB();
                }
                request.setAttribute("queries", nib1.getQueries());
                // YW << for add a link to "View CRF Version Data Entry".
                // For this purpose, CRFVersion id is needed.
                // So the latest CRFVersion Id of A CRF Id is it.
                CRFVersionDAO cvdao = new CRFVersionDAO(sm.getDataSource());
                ArrayList crfvbeans = new ArrayList();
                logger.debug("CRF-ID [" + version.getCrfId() + "]");
                int crfVersionId = 0;
                String versionOID = null;
                if (version.getCrfId() != 0) {
                    crfvbeans = cvdao.findAllByCRFId(version.getCrfId());
                    CRFVersionBean cvbean = (CRFVersionBean) crfvbeans.get(crfvbeans.size() - 1);
                    crfVersionId = cvbean.getId();
                    versionOID = cvbean.getOid();
                    for (Iterator iter = crfvbeans.iterator(); iter.hasNext(); ) {
                        cvbean = (CRFVersionBean) iter.next();
                        if (crfVersionId < cvbean.getId()) {
                            crfVersionId = cvbean.getId();
                        }
                    }
                }
                // Not needed; crfVersionId will be autoboxed in Java 5
                // this was added for the old CVS java compiler
                Integer cfvID = new Integer(crfVersionId);
                if (cfvID == 0) {
                    cfvID = cvdao.findCRFVersionId(nib1.getCrfId(), nib1.getVersionName());
                }
                CRFVersionBean finalVersion = (CRFVersionBean) cvdao.findByPK(cfvID);
                version.setCrfId(nib1.getCrfId());
                version.setOid(finalVersion.getOid());
                CRFBean crfBean = (CRFBean) cdao.findByPK(version.getCrfId());
                crfBean.setUpdatedDate(version.getCreatedDate());
                crfBean.setUpdater(ub);
                cdao.update(crfBean);
                // workaround to get a correct file name below, tbh 06/2008
                request.setAttribute("crfVersionId", cfvID);
                // YW >>
                // return those properties to initial values
                session.removeAttribute("version");
                session.removeAttribute("eventsForVersion");
                session.removeAttribute("itemsHaveData");
                session.removeAttribute("nib");
                session.removeAttribute("deletePreviousVersion");
                session.removeAttribute("previousVersionId");
                // save new version spreadsheet
                String tempFile = (String) session.getAttribute("tempFileName");
                if (tempFile != null) {
                    logger.debug("*** ^^^ *** saving new version spreadsheet" + tempFile);
                    try {
                        String dir = SQLInitServlet.getField("filePath");
                        File f = new File(dir + "crf" + File.separator + "original" + File.separator + tempFile);
                        // check to see whether crf/new/ folder exists
                        // inside, if not,
                        // creates
                        // the crf/new/ folder
                        String finalDir = dir + "crf" + File.separator + "new" + File.separator;
                        if (!new File(finalDir).isDirectory()) {
                            logger.debug("need to create folder for excel files" + finalDir);
                            new File(finalDir).mkdirs();
                        }
                        // String newFile = version.getCrfId() +
                        // version.getName() + ".xls";
                        String newFile = version.getCrfId() + version.getOid() + ".xls";
                        logger.debug("*** ^^^ *** new file: " + newFile);
                        File nf = new File(finalDir + newFile);
                        logger.debug("copying old file " + f.getName() + " to new file " + nf.getName());
                        copy(f, nf);
                    // ?
                    } catch (IOException ie) {
                        logger.debug("==============");
                        addPageMessage(respage.getString("CRF_version_spreadsheet_could_not_saved_contact"));
                    }
                }
                session.removeAttribute("tempFileName");
                session.removeAttribute(MODULE);
                session.removeAttribute("excelErrors");
                session.removeAttribute("htmlTab");
                forwardPage(Page.CREATE_CRF_VERSION_DONE);
            } catch (OpenClinicaException pe) {
                logger.debug("--------------");
                session.setAttribute("excelErrors", nib1.getErrors());
                // request.setAttribute("excelErrors", nib1.getErrors());
                forwardPage(Page.CREATE_CRF_VERSION_ERROR);
            }
        } else {
            forwardPage(Page.CREATE_CRF_VERSION);
        }
    } else if ("delete".equalsIgnoreCase(action)) {
        logger.debug("user wants to delete previous version");
        List excelErr = (ArrayList) session.getAttribute("excelErrors");
        logger.debug("for overwrite CRF version, excelErr.isEmpty()=" + excelErr.isEmpty());
        if (excelErr != null && excelErr.isEmpty()) {
            addPageMessage(resword.getString("congratulations_your_spreadsheet_no_errors"));
            // should be moved to excelErr != null block
            session.setAttribute("deletePreviousVersion", Boolean.TRUE);
            forwardPage(Page.VIEW_SECTION_DATA_ENTRY_PREVIEW);
        } else {
            // should be moved to excelErr != null
            session.setAttribute("deletePreviousVersion", Boolean.FALSE);
            // block
            logger.debug("OpenClinicaException thrown, forwarding to CREATE_CRF_VERSION_CONFIRM.");
            forwardPage(Page.CREATE_CRF_VERSION_CONFIRM);
        }
    }
}
Also used : ItemBean(org.akaza.openclinica.bean.submit.ItemBean) Set(java.util.Set) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) CRFReadingException(org.akaza.openclinica.exception.CRFReadingException) OpenClinicaException(org.akaza.openclinica.exception.OpenClinicaException) Iterator(java.util.Iterator) ArrayList(java.util.ArrayList) List(java.util.List) EventDefinitionCRFDAO(org.akaza.openclinica.dao.managestudy.EventDefinitionCRFDAO) EventCRFDAO(org.akaza.openclinica.dao.submit.EventCRFDAO) CRFDAO(org.akaza.openclinica.dao.admin.CRFDAO) CRFVersionDAO(org.akaza.openclinica.dao.submit.CRFVersionDAO) FormProcessor(org.akaza.openclinica.control.form.FormProcessor) EventDefinitionCRFDAO(org.akaza.openclinica.dao.managestudy.EventDefinitionCRFDAO) IOException(java.io.IOException) OpenClinicaException(org.akaza.openclinica.exception.OpenClinicaException) InsufficientPermissionException(org.akaza.openclinica.web.InsufficientPermissionException) CRFReadingException(org.akaza.openclinica.exception.CRFReadingException) IOException(java.io.IOException) NewCRFBean(org.akaza.openclinica.bean.admin.NewCRFBean) CRFBean(org.akaza.openclinica.bean.admin.CRFBean) NewCRFBean(org.akaza.openclinica.bean.admin.NewCRFBean) CRFVersionBean(org.akaza.openclinica.bean.submit.CRFVersionBean) File(java.io.File)

Aggregations

FormProcessor (org.akaza.openclinica.control.form.FormProcessor)224 ArrayList (java.util.ArrayList)139 StudyBean (org.akaza.openclinica.bean.managestudy.StudyBean)92 StudyDAO (org.akaza.openclinica.dao.managestudy.StudyDAO)73 HashMap (java.util.HashMap)69 Date (java.util.Date)49 StudyEventDefinitionBean (org.akaza.openclinica.bean.managestudy.StudyEventDefinitionBean)48 CRFDAO (org.akaza.openclinica.dao.admin.CRFDAO)46 EventCRFDAO (org.akaza.openclinica.dao.submit.EventCRFDAO)46 Validator (org.akaza.openclinica.control.form.Validator)44 StudyEventDefinitionDAO (org.akaza.openclinica.dao.managestudy.StudyEventDefinitionDAO)44 EventCRFBean (org.akaza.openclinica.bean.submit.EventCRFBean)42 EventDefinitionCRFDAO (org.akaza.openclinica.dao.managestudy.EventDefinitionCRFDAO)41 StudySubjectDAO (org.akaza.openclinica.dao.managestudy.StudySubjectDAO)41 CRFBean (org.akaza.openclinica.bean.admin.CRFBean)40 CRFVersionBean (org.akaza.openclinica.bean.submit.CRFVersionBean)36 UserAccountDAO (org.akaza.openclinica.dao.login.UserAccountDAO)36 EventDefinitionCRFBean (org.akaza.openclinica.bean.managestudy.EventDefinitionCRFBean)35 StudySubjectBean (org.akaza.openclinica.bean.managestudy.StudySubjectBean)35 StudyEventDAO (org.akaza.openclinica.dao.managestudy.StudyEventDAO)35