Search in sources :

Example 6 with InconsistentStateException

use of org.akaza.openclinica.web.InconsistentStateException in project OpenClinica by OpenClinica.

the class ViewUserAccountServlet method processRequest.

@Override
protected void processRequest() throws Exception {
    FormProcessor fp = new FormProcessor(request);
    int userId = fp.getInt(ARG_USER_ID, true);
    UserAccountDAO udao = new UserAccountDAO(sm.getDataSource());
    UserAccountBean user = getBean(udao, userId);
    if (user.isActive()) {
        request.setAttribute("user", user);
    } else {
        throw new InconsistentStateException(Page.ADMIN_SYSTEM, resexception.getString("the_user_attemping_to_view_not_exists"));
    }
    // BWP>>To provide the view with the correct date format pattern, locale
    // sensitive
    String pattn = "";
    pattn = ResourceBundleProvider.getFormatBundle().getString("date_format_string");
    request.setAttribute("dateFormatPattern", pattn);
    forwardPage(Page.VIEW_USER_ACCOUNT);
}
Also used : FormProcessor(org.akaza.openclinica.control.form.FormProcessor) UserAccountBean(org.akaza.openclinica.bean.login.UserAccountBean) UserAccountDAO(org.akaza.openclinica.dao.login.UserAccountDAO) InconsistentStateException(org.akaza.openclinica.web.InconsistentStateException)

Example 7 with InconsistentStateException

use of org.akaza.openclinica.web.InconsistentStateException in project OpenClinica by OpenClinica.

the class EditUserAccountServlet method processRequest.

@Override
protected void processRequest() throws Exception {
    FormProcessor fp = new FormProcessor(request);
    // because we need to use this in the confirmation and error parts too
    ArrayList studies = getAllStudies();
    request.setAttribute("studies", studies);
    int userId = fp.getInt(ARG_USERID);
    UserAccountDAO udao = new UserAccountDAO(sm.getDataSource());
    UserAccountBean user = (UserAccountBean) udao.findByPK(userId);
    int stepNum = fp.getInt(ARG_STEPNUM);
    if (!fp.isSubmitted()) {
        addEntityList("userTypes", getUserTypes(), respage.getString("the_user_could_not_be_edited_because_no_user_types"), Page.ADMIN_SYSTEM);
        loadPresetValuesFromBean(fp, user);
        fp.addPresetValue(ARG_STEPNUM, EDIT_STEP);
        setPresetValues(fp.getPresetValues());
        // addEntityList("userTypes", getUserTypes(),
        // "The user could not be edited because there are no user types
        // available.",
        // Page.ADMIN_SYSTEM);
        request.setAttribute("userName", user.getName());
        forwardPage(Page.EDIT_ACCOUNT);
    } else if (stepNum == EDIT_STEP) {
        Validator v = new Validator(request);
        v.addValidation(INPUT_FIRST_NAME, Validator.NO_BLANKS);
        v.addValidation(INPUT_LAST_NAME, Validator.NO_BLANKS);
        v.addValidation(INPUT_FIRST_NAME, Validator.LENGTH_NUMERIC_COMPARISON, NumericComparisonOperator.LESS_THAN_OR_EQUAL_TO, 50);
        v.addValidation(INPUT_LAST_NAME, Validator.LENGTH_NUMERIC_COMPARISON, NumericComparisonOperator.LESS_THAN_OR_EQUAL_TO, 50);
        v.addValidation(INPUT_EMAIL, Validator.NO_BLANKS);
        v.addValidation(INPUT_EMAIL, Validator.LENGTH_NUMERIC_COMPARISON, NumericComparisonOperator.LESS_THAN_OR_EQUAL_TO, 120);
        v.addValidation(INPUT_EMAIL, Validator.IS_A_EMAIL);
        v.addValidation(INPUT_INSTITUTION, Validator.NO_BLANKS);
        v.addValidation(INPUT_INSTITUTION, Validator.LENGTH_NUMERIC_COMPARISON, NumericComparisonOperator.LESS_THAN_OR_EQUAL_TO, 255);
        HashMap errors = v.validate();
        if (errors.isEmpty()) {
            loadPresetValuesFromForm(fp);
            fp.addPresetValue(ARG_STEPNUM, CONFIRM_STEP);
            setPresetValues(fp.getPresetValues());
            request.setAttribute("userName", user.getName());
            forwardPage(Page.EDIT_ACCOUNT_CONFIRM);
        } else {
            loadPresetValuesFromForm(fp);
            fp.addPresetValue(ARG_STEPNUM, EDIT_STEP);
            setInputMessages(errors);
            setPresetValues(fp.getPresetValues());
            addEntityList("userTypes", getUserTypes(), respage.getString("the_user_could_not_be_edited_because_no_user_types"), Page.ADMIN_SYSTEM);
            addPageMessage(respage.getString("there_were_some_errors_submission") + respage.getString("see_below_for_details"));
            forwardPage(Page.EDIT_ACCOUNT);
        }
    } else if (stepNum == CONFIRM_STEP) {
        String button = fp.getString(INPUT_CONFIRM_BUTTON);
        if (button.equals(resword.getString("back"))) {
            loadPresetValuesFromForm(fp);
            fp.addPresetValue(ARG_STEPNUM, EDIT_STEP);
            addEntityList("userTypes", getUserTypes(), respage.getString("the_user_could_not_be_edited_because_no_user_types"), Page.ADMIN_SYSTEM);
            setPresetValues(fp.getPresetValues());
            request.setAttribute("userName", user.getName());
            forwardPage(Page.EDIT_ACCOUNT);
        } else if (button.equals(resword.getString("confirm"))) {
            user.setFirstName(fp.getString(INPUT_FIRST_NAME));
            user.setLastName(fp.getString(INPUT_LAST_NAME));
            user.setEmail(fp.getString(INPUT_EMAIL));
            user.setInstitutionalAffiliation(fp.getString(INPUT_INSTITUTION));
            user.setUpdater(ub);
            user.setRunWebservices(fp.getBoolean(INPUT_RUN_WEBSERVICES));
            user.setEnableApiKey(true);
            String apiKey = null;
            do {
                apiKey = getRandom32ChApiKey();
            } while (isApiKeyExist(apiKey));
            user.setApiKey(apiKey);
            UserType ut = UserType.get(fp.getInt(INPUT_USER_TYPE));
            if (ut.equals(UserType.SYSADMIN)) {
                user.addUserType(ut);
            } else if (ut.equals(UserType.TECHADMIN)) {
                user.addUserType(ut);
            } else {
                user.addUserType(UserType.USER);
            }
            if (fp.getBoolean(INPUT_RESET_PASSWORD)) {
                SecurityManager sm = ((SecurityManager) SpringServletAccess.getApplicationContext(context).getBean("securityManager"));
                String password = sm.genPassword();
                String passwordHash = sm.encrytPassword(password, getUserDetails());
                user.setPasswd(passwordHash);
                user.setPasswdTimestamp(null);
                udao.update(user);
                if ("no".equalsIgnoreCase(fp.getString(INPUT_DISPLAY_PWD))) {
                    logger.info("displayPwd is no");
                    try {
                        sendResetPasswordEmail(user, password);
                    } catch (Exception e) {
                        addPageMessage(respage.getString("there_was_an_error_sending_reset_email_try_reset"));
                    }
                } else {
                    addPageMessage(respage.getString("new_user_password") + ":<br/> " + password + "<br/>" + respage.getString("please_write_down_the_password_and_provide"));
                }
            } else {
                udao.update(user);
            }
            addPageMessage(respage.getString("the_user_account") + " \"" + user.getName() + "\" " + respage.getString("was_updated_succesfully"));
            forwardPage(Page.LIST_USER_ACCOUNTS_SERVLET);
        } else {
            throw new InconsistentStateException(Page.ADMIN_SYSTEM, resexception.getString("an_invalid_submit_button_was_clicked"));
        }
    } else {
        throw new InconsistentStateException(Page.ADMIN_SYSTEM, resexception.getString("an_invalid_step_was_specified"));
    }
}
Also used : SecurityManager(org.akaza.openclinica.core.SecurityManager) HashMap(java.util.HashMap) FormProcessor(org.akaza.openclinica.control.form.FormProcessor) ArrayList(java.util.ArrayList) UserAccountBean(org.akaza.openclinica.bean.login.UserAccountBean) UserAccountDAO(org.akaza.openclinica.dao.login.UserAccountDAO) UserType(org.akaza.openclinica.bean.core.UserType) InconsistentStateException(org.akaza.openclinica.web.InconsistentStateException) Validator(org.akaza.openclinica.control.form.Validator) InsufficientPermissionException(org.akaza.openclinica.web.InsufficientPermissionException) InconsistentStateException(org.akaza.openclinica.web.InconsistentStateException)

Example 8 with InconsistentStateException

use of org.akaza.openclinica.web.InconsistentStateException in project OpenClinica by OpenClinica.

the class DataEntryServlet method getInputBeans.

/**
     * Get the input beans - the EventCRFBean and the SectionBean. For both beans, look first in the request attributes to see if the bean has been stored
     * there. If not, look in the parameters for the bean id, and then retrieve the bean from the database. The beans are stored as protected class members.
     * @param request TODO
     */
protected void getInputBeans(HttpServletRequest request) throws InsufficientPermissionException {
    HttpSession session = request.getSession();
    StudyBean currentStudy = (StudyBean) session.getAttribute("study");
    // BWP >>we should have the correct crfVersionId, in order to acquire
    // the correct
    // section IDs
    FormProcessor fp = new FormProcessor(request);
    EventCRFDAO ecdao = new EventCRFDAO(getDataSource());
    SectionDAO sdao = new SectionDAO(getDataSource());
    EventCRFBean ecb = (EventCRFBean) request.getAttribute(INPUT_EVENT_CRF);
    //JN:Happening when drilling down?
    if (ecb == null) {
        int eventCRFId = fp.getInt(INPUT_EVENT_CRF_ID, true);
        LOGGER.debug("found event crf id: " + eventCRFId);
        if (eventCRFId > 0) {
            LOGGER.debug("***NOTE*** that we didnt have to create an event crf because we already have one: " + eventCRFId);
            // there is an event CRF already, only need to update
            ecb = (EventCRFBean) ecdao.findByPK(eventCRFId);
            // ecb.setUpdatedDate(new Date());
            // ecb.setUpdater(ub);
            // ecb = (EventCRFBean) ecdao.update(ecb);
            // logger.trace("found an event crf id "+eventCRFId);
            // YW 11-12-2007 << if interviewer or/and interview date
            // has/have been updated for study/site from "blank" to
            // "pre-populated"
            // But at this point, this update only shows on web page and
            // will not be updated to database.
            int studyEventId = fp.getInt(INPUT_STUDY_EVENT_ID);
            request.setAttribute(INPUT_EVENT_CRF, ecb);
            if (studyEventId > 0) {
                StudyEventDAO sedao = new StudyEventDAO(getDataSource());
                StudyEventBean sEvent = (StudyEventBean) sedao.findByPK(studyEventId);
                ecb = updateECB(sEvent, request);
            }
            request.setAttribute(INPUT_EVENT_CRF, ecb);
        // YW >>
        } else {
            // CRF id <=0, so we need to create a new CRF
            // use toCreateCRF as a flag to prevent user to submit event CRF
            // more than once
            // for example, user reloads the page
            String toCreateCRF = (String) session.getAttribute("to_create_crf");
            if (StringUtil.isBlank(toCreateCRF) || "0".equals(toCreateCRF)) {
                session.setAttribute("to_create_crf", "1");
            }
            try {
                // if (ecb.getInterviewerName() != null) {
                LOGGER.debug("Initial: to create an event CRF.");
                String toCreateCRF1 = (String) session.getAttribute("to_create_crf");
                if (!StringUtil.isBlank(toCreateCRF1) && "1".equals(toCreateCRF1)) {
                    ecb = createEventCRF(request, fp);
                    session.setAttribute("ecb", ecb);
                    request.setAttribute(INPUT_EVENT_CRF, ecb);
                    session.setAttribute("to_create_crf", "0");
                } else {
                    ecb = (EventCRFBean) session.getAttribute("ecb");
                }
            // }
            } catch (InconsistentStateException ie) {
                ie.printStackTrace();
                addPageMessage(ie.getOpenClinicaMessage(), request);
                throw new InsufficientPermissionException(Page.LIST_STUDY_SUBJECTS_SERVLET, ie.getOpenClinicaMessage(), "1");
            } catch (NullPointerException ne) {
                ne.printStackTrace();
                addPageMessage(ne.getMessage(), request);
                throw new InsufficientPermissionException(Page.LIST_STUDY_SUBJECTS_SERVLET, ne.getMessage(), "1");
            }
        }
    }
    // added to allow sections shown on this page
    DisplayTableOfContentsBean displayBean = new DisplayTableOfContentsBean();
    displayBean = TableOfContentsServlet.getDisplayBean(ecb, getDataSource(), currentStudy);
    // escape apostrophe in event name
    displayBean.getStudyEventDefinition().setName(StringEscapeUtils.escapeJavaScript(displayBean.getStudyEventDefinition().getName()));
    request.setAttribute(TOC_DISPLAY, displayBean);
    int sectionId = fp.getInt(INPUT_SECTION_ID, true);
    ArrayList sections;
    if (sectionId <= 0) {
        StudyEventDAO studyEventDao = new StudyEventDAO(getDataSource());
        int maximumSampleOrdinal = studyEventDao.getMaxSampleOrdinal(displayBean.getStudyEventDefinition(), displayBean.getStudySubject());
        request.setAttribute("maximumSampleOrdinal", maximumSampleOrdinal);
        sections = sdao.findAllByCRFVersionId(ecb.getCRFVersionId());
        for (int i = 0; i < sections.size(); i++) {
            SectionBean sb = (SectionBean) sections.get(i);
            // find the first section of this CRF
            sectionId = sb.getId();
            break;
        }
    }
    SectionBean sb = new SectionBean();
    if (sectionId > 0) {
        // int sectionId = fp.getInt(INPUT_SECTION_ID, true);
        //synchronized(this)
        {
            sb = (SectionBean) sdao.findByPK(sectionId);
        }
    }
    int tabId = fp.getInt("tab", true);
    if (tabId <= 0) {
        tabId = 1;
    }
    request.setAttribute(INPUT_TAB, new Integer(tabId));
    request.setAttribute(SECTION_BEAN, sb);
}
Also used : HttpSession(javax.servlet.http.HttpSession) FormProcessor(org.akaza.openclinica.control.form.FormProcessor) StudyBean(org.akaza.openclinica.bean.managestudy.StudyBean) InsufficientPermissionException(org.akaza.openclinica.web.InsufficientPermissionException) ArrayList(java.util.ArrayList) DisplayTableOfContentsBean(org.akaza.openclinica.bean.submit.DisplayTableOfContentsBean) StudyEventBean(org.akaza.openclinica.bean.managestudy.StudyEventBean) InconsistentStateException(org.akaza.openclinica.web.InconsistentStateException) SectionBean(org.akaza.openclinica.bean.submit.SectionBean) DisplaySectionBean(org.akaza.openclinica.bean.submit.DisplaySectionBean) EventCRFBean(org.akaza.openclinica.bean.submit.EventCRFBean) StudyEventDAO(org.akaza.openclinica.dao.managestudy.StudyEventDAO) EventCRFDAO(org.akaza.openclinica.dao.submit.EventCRFDAO) SectionDAO(org.akaza.openclinica.dao.submit.SectionDAO)

Example 9 with InconsistentStateException

use of org.akaza.openclinica.web.InconsistentStateException in project OpenClinica by OpenClinica.

the class ResolveDiscrepancyServlet method processRequest.

/*
     * (non-Javadoc)
     *
     * @see org.akaza.openclinica.control.core.SecureController#processRequest()
     */
@Override
protected void processRequest() throws Exception {
    FormProcessor fp = new FormProcessor(request);
    int noteId = fp.getInt(INPUT_NOTE_ID);
    String module = (String) session.getAttribute("module");
    StudySubjectDAO studySubjectDAO = new StudySubjectDAO(sm.getDataSource());
    DiscrepancyNoteDAO dndao = new DiscrepancyNoteDAO(sm.getDataSource());
    dndao.setFetchMapping(true);
    // check that the note exists
    DiscrepancyNoteBean discrepancyNoteBean = (DiscrepancyNoteBean) dndao.findByPK(noteId);
    if (!discrepancyNoteBean.isActive()) {
        throw new InconsistentStateException(Page.MANAGE_STUDY_SERVLET, resexception.getString("you_are_trying_resolve_discrepancy_not_exist"));
    }
    // check that the note has not already been closed
    ArrayList children = dndao.findAllByParent(discrepancyNoteBean);
    discrepancyNoteBean.setChildren(children);
    // This logic has been reverted, issue-7459
    // if (parentNoteIsClosed(discrepancyNoteBean)) {
    // throw new InconsistentStateException(Page.VIEW_DISCREPANCY_NOTES_IN_STUDY_SERVLET, respage
    // .getString("the_discrepancy_choose_has_been_closed_resolved_create_new"));
    // }
    // all clear, send the user to the resolved screen
    String entityType = discrepancyNoteBean.getEntityType().toLowerCase();
    discrepancyNoteBean.setResStatus(ResolutionStatus.get(discrepancyNoteBean.getResolutionStatusId()));
    discrepancyNoteBean.setDisType(DiscrepancyNoteType.get(discrepancyNoteBean.getDiscrepancyNoteTypeId()));
    // View Study Events <<
    if (currentRole.getRole().equals(Role.MONITOR) && !"itemdata".equalsIgnoreCase(entityType) && !"eventcrf".equalsIgnoreCase(entityType)) {
        redirectMonitor(module, discrepancyNoteBean);
        return;
    }
    // If Study is Frozen or Locked
    if (currentStudy.getStatus().isFrozen() && !"itemdata".equalsIgnoreCase(entityType) && !"eventcrf".equalsIgnoreCase(entityType)) {
        redirectMonitor(module, discrepancyNoteBean);
        return;
    }
    boolean toView = false;
    boolean isCompleted = false;
    if ("itemdata".equalsIgnoreCase(entityType)) {
        ItemDataDAO iddao = new ItemDataDAO(sm.getDataSource());
        ItemDataBean idb = (ItemDataBean) iddao.findByPK(discrepancyNoteBean.getEntityId());
        EventCRFDAO ecdao = new EventCRFDAO(sm.getDataSource());
        EventCRFBean ecb = (EventCRFBean) ecdao.findByPK(idb.getEventCRFId());
        StudySubjectBean studySubjectBean = (StudySubjectBean) studySubjectDAO.findByPK(ecb.getStudySubjectId());
        discrepancyNoteBean.setSubjectId(studySubjectBean.getId());
        discrepancyNoteBean.setItemId(idb.getItemId());
        if (ecb.getStatus().equals(Status.UNAVAILABLE)) {
            isCompleted = true;
        }
        // we want to go to view note page if the note is
        toView = true;
    // for item data
    }
    // logger.info("set up pop up url: " + createNoteURL);
    // System.out.println("set up pop up url: " + createNoteURL);
    boolean goNext = prepareRequestForResolution(request, sm.getDataSource(), currentStudy, discrepancyNoteBean, isCompleted);
    Page p = getPageForForwarding(discrepancyNoteBean, isCompleted);
    // logger.info("found page for forwarding: " + p.getFileName());
    if (p == null) {
        throw new InconsistentStateException(Page.VIEW_DISCREPANCY_NOTES_IN_STUDY_SERVLET, resexception.getString("the_discrepancy_note_triying_resolve_has_invalid_type"));
    } else {
        if (p.getFileName().contains("?")) {
            if (!p.getFileName().contains("fromViewNotes=1")) {
                p.setFileName(p.getFileName() + "&fromViewNotes=1");
            }
        } else {
            p.setFileName(p.getFileName() + "?fromViewNotes=1");
        }
        String createNoteURL = CreateDiscrepancyNoteServlet.getAddChildURL(discrepancyNoteBean, ResolutionStatus.CLOSED, true);
        setPopUpURL(createNoteURL);
    }
    if (!goNext) {
        setPopUpURL("");
        addPageMessage(respage.getString("you_may_not_perform_admin_edit_on_CRF_not_completed_by_user"));
        p = Page.VIEW_DISCREPANCY_NOTES_IN_STUDY_SERVLET;
    }
    forwardPage(p);
}
Also used : DiscrepancyNoteDAO(org.akaza.openclinica.dao.managestudy.DiscrepancyNoteDAO) FormProcessor(org.akaza.openclinica.control.form.FormProcessor) ArrayList(java.util.ArrayList) Page(org.akaza.openclinica.view.Page) StudySubjectDAO(org.akaza.openclinica.dao.managestudy.StudySubjectDAO) InconsistentStateException(org.akaza.openclinica.web.InconsistentStateException) ItemDataDAO(org.akaza.openclinica.dao.submit.ItemDataDAO) EventCRFBean(org.akaza.openclinica.bean.submit.EventCRFBean) StudySubjectBean(org.akaza.openclinica.bean.managestudy.StudySubjectBean) DiscrepancyNoteBean(org.akaza.openclinica.bean.managestudy.DiscrepancyNoteBean) ItemDataBean(org.akaza.openclinica.bean.submit.ItemDataBean) EventCRFDAO(org.akaza.openclinica.dao.submit.EventCRFDAO)

Example 10 with InconsistentStateException

use of org.akaza.openclinica.web.InconsistentStateException in project OpenClinica by OpenClinica.

the class CoreSecureController method process.

private void process(HttpServletRequest request, HttpServletResponse response) throws OpenClinicaException, UnsupportedEncodingException {
    request.setCharacterEncoding("UTF-8");
    response.setHeader("Content-Encoding", "gzip");
    HttpSession session = request.getSession();
    // BWP >> 1/8/2008
    try {
        // YW 10-03-2007 <<
        session.setMaxInactiveInterval(Integer.parseInt(SQLInitServlet.getField("max_inactive_interval")));
    // YW >>
    } catch (NumberFormatException nfe) {
        // BWP>>3600 is the datainfo.properties maxInactiveInterval on
        // 1/8/2008
        session.setMaxInactiveInterval(3600);
    }
    // If the session already has a value with key SUPPORT_URL don't reset
    if (session.getAttribute(SUPPORT_URL) == null) {
        session.setAttribute(SUPPORT_URL, SQLInitServlet.getSupportURL());
    }
    UserAccountBean ub = (UserAccountBean) session.getAttribute(USER_BEAN_NAME);
    StudyBean currentStudy = (StudyBean) session.getAttribute("study");
    StudyUserRoleBean currentRole = (StudyUserRoleBean) session.getAttribute("userRole");
    // Set current language preferences
    Locale locale = LocaleResolver.getLocale(request);
    ResourceBundleProvider.updateLocale(locale);
    resadmin = ResourceBundleProvider.getAdminBundle(locale);
    resaudit = ResourceBundleProvider.getAuditEventsBundle(locale);
    resexception = ResourceBundleProvider.getExceptionsBundle(locale);
    resformat = ResourceBundleProvider.getFormatBundle(locale);
    restext = ResourceBundleProvider.getTextsBundle(locale);
    resterm = ResourceBundleProvider.getTermsBundle(locale);
    resword = ResourceBundleProvider.getWordsBundle(locale);
    respage = ResourceBundleProvider.getPageMessagesBundle(locale);
    resworkflow = ResourceBundleProvider.getWorkflowBundle(locale);
    try {
        String userName = request.getRemoteUser();
        ServletContext context = getServletContext();
        // BWP 1/8/08<< the sm variable may already be set with a mock
        // object,
        // from the perspective of
        // JUnit servlets tests
        /*
             * if(sm==null && (!StringUtil.isBlank(userName))) {//check if user
             * logged in, then create a new sessionmanger to get ub //create a
             * new sm in order to get a new ub object sm = new
             * SessionManager(ub, userName); }
             */
        // BWP 01/08 >>
        // sm = new SessionManager(ub, userName);
        SessionManager sm = new SessionManager(ub, userName, SpringServletAccess.getApplicationContext(context));
        ub = sm.getUserBean();
        request.getSession().setAttribute("sm", sm);
        session.setAttribute("userBean", ub);
        StudyDAO sdao = new StudyDAO(getDataSource());
        if (currentStudy == null || currentStudy.getId() <= 0) {
            if (ub.getId() > 0 && ub.getActiveStudyId() > 0) {
                StudyParameterValueDAO spvdao = new StudyParameterValueDAO(getDataSource());
                currentStudy = (StudyBean) sdao.findByPK(ub.getActiveStudyId());
                ArrayList studyParameters = spvdao.findParamConfigByStudy(currentStudy);
                currentStudy.setStudyParameters(studyParameters);
                StudyConfigService scs = new StudyConfigService(getDataSource());
                if (currentStudy.getParentStudyId() <= 0) {
                    // top study
                    scs.setParametersForStudy(currentStudy);
                } else {
                    // YW <<
                    currentStudy.setParentStudyName(((StudyBean) sdao.findByPK(currentStudy.getParentStudyId())).getName());
                    // YW >>
                    scs.setParametersForSite(currentStudy);
                }
                // set up the panel here, tbh
                panel.reset();
                /*
                     * panel.setData("Study", currentStudy.getName());
                     * panel.setData("Summary", currentStudy.getSummary());
                     * panel.setData("Start Date",
                     * sdf.format(currentStudy.getDatePlannedStart()));
                     * panel.setData("End Date",
                     * sdf.format(currentStudy.getDatePlannedEnd()));
                     * panel.setData("Principal Investigator",
                     * currentStudy.getPrincipalInvestigator());
                     */
                session.setAttribute(STUDY_INFO_PANEL, panel);
            } else {
                currentStudy = new StudyBean();
            }
            // The above line is moved here since currentstudy's value is set in else block and could change
            session.setAttribute("study", currentStudy);
        } else if (currentStudy.getId() > 0) {
            // restored
            if (currentStudy.getParentStudyId() > 0) {
                currentStudy.setParentStudyName(((StudyBean) sdao.findByPK(currentStudy.getParentStudyId())).getName());
            }
        // YW >>
        }
        if (currentStudy.getParentStudyId() > 0) {
            /*
                 * The Role decription will be set depending on whether the user
                 * logged in at study lever or site level. issue-2422
                 */
            List roles = Role.toArrayList();
            for (Iterator it = roles.iterator(); it.hasNext(); ) {
                Role role = (Role) it.next();
                switch(role.getId()) {
                    case 2:
                        role.setDescription("site_Study_Coordinator");
                        break;
                    case 3:
                        role.setDescription("site_Study_Director");
                        break;
                    case 4:
                        role.setDescription("site_investigator");
                        break;
                    case 5:
                        role.setDescription("site_Data_Entry_Person");
                        break;
                    case 6:
                        role.setDescription("site_monitor");
                        break;
                    case 7:
                        role.setDescription("site_Data_Entry_Person2");
                        break;
                    default:
                }
            }
        } else {
            /*
                 * If the current study is a site, we will change the role
                 * description. issue-2422
                 */
            List roles = Role.toArrayList();
            for (Iterator it = roles.iterator(); it.hasNext(); ) {
                Role role = (Role) it.next();
                switch(role.getId()) {
                    case 2:
                        role.setDescription("Study_Coordinator");
                        break;
                    case 3:
                        role.setDescription("Study_Director");
                        break;
                    case 4:
                        role.setDescription("Investigator");
                        break;
                    case 5:
                        role.setDescription("Data_Entry_Person");
                        break;
                    case 6:
                        role.setDescription("Monitor");
                        break;
                    default:
                }
            }
        }
        if (currentRole == null || currentRole.getId() <= 0) {
            // kept as "invalid" -- YW 06-21-2007
            if (ub.getId() > 0 && currentStudy.getId() > 0 && !currentStudy.getStatus().getName().equals("removed")) {
                currentRole = ub.getRoleByStudy(currentStudy.getId());
                if (currentStudy.getParentStudyId() > 0) {
                    // Checking if currentStudy has been removed or not will
                    // ge good enough -- YW 10-17-2007
                    StudyUserRoleBean roleInParent = ub.getRoleByStudy(currentStudy.getParentStudyId());
                    // inherited role from parent study, pick the higher
                    // role
                    currentRole.setRole(Role.max(currentRole.getRole(), roleInParent.getRole()));
                }
            // logger.info("currentRole:" + currentRole.getRoleName());
            } else {
                currentRole = new StudyUserRoleBean();
            }
            session.setAttribute("userRole", currentRole);
        } else // active study has been removed.
        if (currentRole.getId() > 0 && (currentStudy.getStatus().equals(Status.DELETED) || currentStudy.getStatus().equals(Status.AUTO_DELETED))) {
            currentRole.setRole(Role.INVALID);
            currentRole.setStatus(Status.DELETED);
            session.setAttribute("userRole", currentRole);
        }
        // YW 06-19-2007 >>
        request.setAttribute("isAdminServlet", getAdminServlet());
        // logger.info(rq_names);
        if (!request.getRequestURI().endsWith("ResetPassword")) {
            passwdTimeOut(request, response, ub);
        }
        mayProceed(request, response);
        //   pingJobServer(request);
        processRequest(request, response);
    } catch (InconsistentStateException ise) {
        ise.printStackTrace();
        LOGGER.warn("InconsistentStateException: org.akaza.openclinica.control.CoreSecureController: ", ise);
        unlockCRFOnError(request);
        addPageMessage(ise.getOpenClinicaMessage(), request);
        forwardPage(ise.getGoTo(), request, response);
    } catch (InsufficientPermissionException ipe) {
        ipe.printStackTrace();
        LOGGER.warn("InsufficientPermissionException: org.akaza.openclinica.control.CoreSecureController: ", ipe);
        unlockCRFOnError(request);
        // addPageMessage(ipe.getOpenClinicaMessage());
        forwardPage(ipe.getGoTo(), request, response);
    } catch (Exception e) {
        LOGGER.error("Error processing request", e);
        unlockCRFOnError(request);
        forwardPage(Page.ERROR, request, response);
    }
}
Also used : Locale(java.util.Locale) HttpSession(javax.servlet.http.HttpSession) SessionManager(org.akaza.openclinica.core.SessionManager) StudyBean(org.akaza.openclinica.bean.managestudy.StudyBean) StudyUserRoleBean(org.akaza.openclinica.bean.login.StudyUserRoleBean) ArrayList(java.util.ArrayList) InsufficientPermissionException(org.akaza.openclinica.web.InsufficientPermissionException) InconsistentStateException(org.akaza.openclinica.web.InconsistentStateException) ServletException(javax.servlet.ServletException) OpenClinicaException(org.akaza.openclinica.exception.OpenClinicaException) MessagingException(javax.mail.MessagingException) MailException(org.springframework.mail.MailException) UnsupportedEncodingException(java.io.UnsupportedEncodingException) InconsistentStateException(org.akaza.openclinica.web.InconsistentStateException) InsufficientPermissionException(org.akaza.openclinica.web.InsufficientPermissionException) SchedulerException(org.quartz.SchedulerException) IOException(java.io.IOException) Role(org.akaza.openclinica.bean.core.Role) StudyConfigService(org.akaza.openclinica.dao.service.StudyConfigService) UserAccountBean(org.akaza.openclinica.bean.login.UserAccountBean) Iterator(java.util.Iterator) ServletContext(javax.servlet.ServletContext) List(java.util.List) ArrayList(java.util.ArrayList) StudyParameterValueDAO(org.akaza.openclinica.dao.service.StudyParameterValueDAO) StudyDAO(org.akaza.openclinica.dao.managestudy.StudyDAO)

Aggregations

InconsistentStateException (org.akaza.openclinica.web.InconsistentStateException)11 ArrayList (java.util.ArrayList)8 StudyBean (org.akaza.openclinica.bean.managestudy.StudyBean)6 EventCRFBean (org.akaza.openclinica.bean.submit.EventCRFBean)6 Date (java.util.Date)5 UserAccountBean (org.akaza.openclinica.bean.login.UserAccountBean)5 StudyEventBean (org.akaza.openclinica.bean.managestudy.StudyEventBean)5 StudyEventDAO (org.akaza.openclinica.dao.managestudy.StudyEventDAO)5 EventCRFDAO (org.akaza.openclinica.dao.submit.EventCRFDAO)5 StudySubjectBean (org.akaza.openclinica.bean.managestudy.StudySubjectBean)4 FormProcessor (org.akaza.openclinica.control.form.FormProcessor)4 StudySubjectDAO (org.akaza.openclinica.dao.managestudy.StudySubjectDAO)4 HashMap (java.util.HashMap)3 Iterator (java.util.Iterator)3 HttpSession (javax.servlet.http.HttpSession)3 StudyUserRoleBean (org.akaza.openclinica.bean.login.StudyUserRoleBean)3 StudyEventDefinitionBean (org.akaza.openclinica.bean.managestudy.StudyEventDefinitionBean)3 DisplayTableOfContentsBean (org.akaza.openclinica.bean.submit.DisplayTableOfContentsBean)3 SessionManager (org.akaza.openclinica.core.SessionManager)3 StudyDAO (org.akaza.openclinica.dao.managestudy.StudyDAO)3