Search in sources :

Example 21 with OpenClinicaException

use of org.akaza.openclinica.exception.OpenClinicaException 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)

Example 22 with OpenClinicaException

use of org.akaza.openclinica.exception.OpenClinicaException in project OpenClinica by OpenClinica.

the class FormBeanUtil method createDisplaySectionBWithFormGroupsForPrint.

public DisplaySectionBean createDisplaySectionBWithFormGroupsForPrint(int sectionId, int crfVersionId, DataSource dataSource, int eventCRFDefId, EventCRFBean eventCrfBean, ServletContext context) {
    DisplaySectionBean displaySectionBean = new DisplaySectionBean();
    ItemGroupDAO formGroupDAO = new ItemGroupDAO(dataSource);
    ItemGroupMetadataDAO igMetaDAO = new ItemGroupMetadataDAO(dataSource);
    ItemDAO itemDao = new ItemDAO(dataSource);
    ItemFormMetadataDAO metaDao = new ItemFormMetadataDAO(dataSource);
    SectionDAO sectionDao = new SectionDAO(dataSource);
    // Give the DisplaySectionBean a legitimate SectionBean
    SectionBean secBean = (SectionBean) sectionDao.findByPK(sectionId);
    displaySectionBean.setSection(secBean);
    // changed from: findGroupBySectionId
    List<ItemGroupBean> itemGroupBeans = formGroupDAO.findLegitGroupAllBySectionId(sectionId);
    // all items associated with the section, including those not in a group
    List<ItemFormMetadataBean> allMetas = new ArrayList<ItemFormMetadataBean>();
    try {
        allMetas = metaDao.findAllBySectionId(sectionId);
    } catch (OpenClinicaException oce) {
        logger.info("oce.getOpenClinicaMessage() = " + oce.getOpenClinicaMessage());
    }
    // Sort these items according to their position on the CRF; their
    // ordinal
    Collections.sort(allMetas);
    // The DisplayItemGroupBean(s) for "nongrouped" items
    List<DisplayItemGroupBean> nonGroupBeans = null;
    // if(itemGroupBeans.isEmpty()) return displaySectionBean;
    // Find out whether there are any checkboxes/radios/select elements
    // and if so, get any null values
    // associated with them
    List<String> nullValuesList = new ArrayList<String>();
    boolean itemsHaveChecksRadios = itemsIncludeChecksRadiosSelects(allMetas);
    if (itemsHaveChecksRadios && eventCRFDefId > 0) {
        // method returns null values as a List<String>
        nullValuesList = this.getNullValuesByEventCRFDefId(eventCRFDefId, dataSource);
    }
    // Get the items associated with each group
    List<ItemBean> itBeans;
    List<DisplayItemBean> displayItems;
    List<DisplayItemGroupBean> displayFormBeans = new ArrayList<DisplayItemGroupBean>();
    DisplayItemGroupBean displayItemGBean;
    for (ItemGroupBean itemGroup : itemGroupBeans) {
        //TODO:fix me!
        itBeans = itemDao.findAllItemsByGroupIdForPrint(itemGroup.getId(), crfVersionId, sectionId);
        logger.debug("just ran find all by group id " + itemGroup.getId() + " found " + itBeans.size() + " item beans");
        //TODO:fix me add item_form_metadata.section_id to the query
        List<ItemGroupMetadataBean> metadata = igMetaDAO.findMetaByGroupAndSectionForPrint(itemGroup.getId(), crfVersionId, sectionId);
        if (!metadata.isEmpty()) {
            // for a given crf version, all the items in the same group
            // have the same group metadata info
            // so we can get one of the metadata and set the metadata for
            // the group
            ItemGroupMetadataBean meta = metadata.get(0);
            itemGroup.setMeta(meta);
        }
        displayItems = getDisplayBeansFromItemsForPrint(itBeans, dataSource, eventCrfBean, sectionId, nullValuesList, context, crfVersionId);
        displayItemGBean = this.createDisplayFormGroup(displayItems, itemGroup);
        displayFormBeans.add(displayItemGBean);
    }
    // We still have to sort these display item group beans on their
    // ItemGroupMetadataBean?
    // then number their ordinals accordingly
    Collections.sort(displayFormBeans, new Comparator<DisplayItemGroupBean>() {

        public int compare(DisplayItemGroupBean displayItemGroupBean, DisplayItemGroupBean displayItemGroupBean1) {
            return displayItemGroupBean.getGroupMetaBean().compareTo(displayItemGroupBean1.getGroupMetaBean());
        }
    });
    // Now provide the display item group beans with an ordinal
    int digOrdinal = 0;
    for (DisplayItemGroupBean digBean : displayFormBeans) {
        digBean.setOrdinal(++digOrdinal);
    }
    // find out whether there are any ungrouped items by comparing the
    // number of
    // grouped items to allMetas.size()
    // List<DisplayItemGroupBean> nonGroupBeans=null;
    int tempCount = 0;
    for (DisplayItemGroupBean groupBean : displayFormBeans) {
        tempCount += groupBean.getItems().size();
    }
    if (tempCount < allMetas.size()) {
        nonGroupBeans = createGroupBeansForNongroupedItems(allMetas, displayFormBeans, sectionId, dataSource, nullValuesList, eventCrfBean, context);
    }
    if (nonGroupBeans != null) {
        displayFormBeans.addAll(nonGroupBeans);
    }
    // sort the list according to the ordinal of the contained
    // DisplayItemGroupBeans
    Collections.sort(displayFormBeans, new Comparator<DisplayItemGroupBean>() {

        public int compare(DisplayItemGroupBean disFormGroupBean, DisplayItemGroupBean disFormGroupBean1) {
            Integer compInt = disFormGroupBean1.getOrdinal();
            Integer compInt2 = disFormGroupBean.getOrdinal();
            return compInt2.compareTo(compInt);
        }
    });
    displaySectionBean.setDisplayFormGroups(displayFormBeans);
    return displaySectionBean;
}
Also used : DisplayItemBean(org.akaza.openclinica.bean.submit.DisplayItemBean) ItemBean(org.akaza.openclinica.bean.submit.ItemBean) ItemDAO(org.akaza.openclinica.dao.submit.ItemDAO) ItemGroupDAO(org.akaza.openclinica.dao.submit.ItemGroupDAO) ArrayList(java.util.ArrayList) OpenClinicaException(org.akaza.openclinica.exception.OpenClinicaException) ItemGroupMetadataBean(org.akaza.openclinica.bean.submit.ItemGroupMetadataBean) DisplayItemBean(org.akaza.openclinica.bean.submit.DisplayItemBean) ItemFormMetadataDAO(org.akaza.openclinica.dao.submit.ItemFormMetadataDAO) DisplayItemGroupBean(org.akaza.openclinica.bean.submit.DisplayItemGroupBean) DisplaySectionBean(org.akaza.openclinica.bean.submit.DisplaySectionBean) ItemGroupMetadataDAO(org.akaza.openclinica.dao.submit.ItemGroupMetadataDAO) SectionBean(org.akaza.openclinica.bean.submit.SectionBean) DisplaySectionBean(org.akaza.openclinica.bean.submit.DisplaySectionBean) DisplayItemGroupBean(org.akaza.openclinica.bean.submit.DisplayItemGroupBean) ItemGroupBean(org.akaza.openclinica.bean.submit.ItemGroupBean) ItemFormMetadataBean(org.akaza.openclinica.bean.submit.ItemFormMetadataBean) SectionDAO(org.akaza.openclinica.dao.submit.SectionDAO)

Example 23 with OpenClinicaException

use of org.akaza.openclinica.exception.OpenClinicaException in project OpenClinica by OpenClinica.

the class FormBeanUtil method sectionHasUngroupedItems.

public boolean sectionHasUngroupedItems(DataSource dataSource, int sectionId, List<DisplayItemGroupBean> displayFormBeans) {
    ItemFormMetadataDAO metaDao = new ItemFormMetadataDAO(dataSource);
    List<ItemFormMetadataBean> allMetas = new ArrayList<ItemFormMetadataBean>();
    try {
        allMetas = metaDao.findAllBySectionId(sectionId);
    } catch (OpenClinicaException oce) {
        logger.info("oce.getOpenClinicaMessage() = " + oce.getOpenClinicaMessage());
    }
    int size = allMetas.size();
    int tempCount = 0;
    String grpName = "";
    // Only count grouped items
    for (DisplayItemGroupBean groupBean : displayFormBeans) {
        grpName = groupBean.getItemGroupBean().getName();
        if (!(grpName.equalsIgnoreCase("Ungrouped") || grpName.length() < 1)) {
            tempCount += groupBean.getItems().size();
        }
    }
    return tempCount < size;
}
Also used : DisplayItemGroupBean(org.akaza.openclinica.bean.submit.DisplayItemGroupBean) ArrayList(java.util.ArrayList) OpenClinicaException(org.akaza.openclinica.exception.OpenClinicaException) ItemFormMetadataDAO(org.akaza.openclinica.dao.submit.ItemFormMetadataDAO) ItemFormMetadataBean(org.akaza.openclinica.bean.submit.ItemFormMetadataBean)

Aggregations

OpenClinicaException (org.akaza.openclinica.exception.OpenClinicaException)23 ArrayList (java.util.ArrayList)18 HashMap (java.util.HashMap)11 ItemBean (org.akaza.openclinica.bean.submit.ItemBean)8 DisplayItemBean (org.akaza.openclinica.bean.submit.DisplayItemBean)7 ItemFormMetadataBean (org.akaza.openclinica.bean.submit.ItemFormMetadataBean)7 ItemDAO (org.akaza.openclinica.dao.submit.ItemDAO)7 Connection (java.sql.Connection)6 PreparedStatement (java.sql.PreparedStatement)6 ResultSet (java.sql.ResultSet)6 SQLException (java.sql.SQLException)6 StudyBean (org.akaza.openclinica.bean.managestudy.StudyBean)6 ItemFormMetadataDAO (org.akaza.openclinica.dao.submit.ItemFormMetadataDAO)6 MessageFormat (java.text.MessageFormat)5 EventCRFBean (org.akaza.openclinica.bean.submit.EventCRFBean)5 ItemGroupBean (org.akaza.openclinica.bean.submit.ItemGroupBean)5 StudyDAO (org.akaza.openclinica.dao.managestudy.StudyDAO)5 Iterator (java.util.Iterator)4 List (java.util.List)4 Status (org.akaza.openclinica.bean.core.Status)4