Search in sources :

Example 21 with UserAccountDAO

use of org.akaza.openclinica.dao.login.UserAccountDAO in project OpenClinica by OpenClinica.

the class ManageStudyServlet method processRequest.

/*
     * (non-Javadoc)
     *
     * @see org.akaza.openclinica.control.core.SecureController#processRequest()
     */
@Override
protected void processRequest() throws Exception {
    // for the sake of testing a prototype; 2560
    if (!INSTRUCTIONS.isEmpty()) {
        INSTRUCTIONS.clear();
    }
    INSTRUCTIONS.add(restext.getString("director_coordinator_privileges_manage"));
    INSTRUCTIONS.add(restext.getString("side_tables_shows_last_modified"));
    request.setAttribute("instructions", INSTRUCTIONS);
    // show icon keys on the sidebar, and display the instructions and
    // alert messages fields
    request.setAttribute("showIcons", true);
    request.setAttribute("openIcons", true);
    request.setAttribute("openAlerts", true);
    request.setAttribute("openInstructions", true);
    // find last 5 modifed sites
    StudyDAO sdao = new StudyDAO(sm.getDataSource());
    // ArrayList sites = (ArrayList)
    // sdao.findAllByParentAndLimit(currentStudy.getId(),true);
    ArrayList allSites = (ArrayList) sdao.findAllByParent(currentStudy.getId());
    ArrayList sites = new ArrayList();
    for (int i = 0; i < allSites.size(); i++) {
        sites.add(allSites.get(i));
        if (i == 5) {
            break;
        }
    }
    request.setAttribute("sites", sites);
    request.setAttribute("sitesCount", new Integer(sites.size()));
    request.setAttribute("allSitesCount", new Integer(allSites.size()));
    // BWP 3057: add study name to JSP
    if (currentStudy != null) {
        request.setAttribute("studyIdentifier", currentStudy.getIdentifier());
    }
    StudyEventDefinitionDAO edao = new StudyEventDefinitionDAO(sm.getDataSource());
    ArrayList seds = (ArrayList) edao.findAllByStudyAndLimit(currentStudy.getId());
    ArrayList allSeds = edao.findAllByStudy(currentStudy);
    request.setAttribute("seds", seds);
    request.setAttribute("sedsCount", new Integer(seds.size()));
    request.setAttribute("allSedsCount", new Integer(allSeds.size()));
    UserAccountDAO udao = new UserAccountDAO(sm.getDataSource());
    ArrayList users = udao.findAllUsersByStudyIdAndLimit(currentStudy.getId(), true);
    ArrayList allUsers = udao.findAllUsersByStudy(currentStudy.getId());
    request.setAttribute("users", users);
    request.setAttribute("usersCount", new Integer(users.size()));
    request.setAttribute("allUsersCount", new Integer(allUsers.size()));
    StudySubjectDAO ssdao = new StudySubjectDAO(sm.getDataSource());
    // ArrayList subjects = (ArrayList)
    // ssdao.findAllByStudyIdAndLimit(currentStudy.getId(),true);
    ArrayList allSubjects = ssdao.findAllByStudyId(currentStudy.getId());
    ArrayList subjects = new ArrayList();
    for (int i = 0; i < allSubjects.size(); i++) {
        subjects.add(allSubjects.get(i));
        if (i == 5) {
            break;
        }
    }
    request.setAttribute("subs", subjects);
    request.setAttribute("subsCount", new Integer(subjects.size()));
    request.setAttribute("allSubsCount", new Integer(allSubjects.size()));
    // added tbh, 9-21-2005
    // AuditEventDAO aedao = new AuditEventDAO(sm.getDataSource());
    // ArrayList audits = (ArrayList)
    // aedao.findAllByStudyIdAndLimit(currentStudy.getId());
    // request.setAttribute("audits", audits);
    resetPanel();
    if (allSubjects.size() > 0) {
        setToPanel("Subjects", new Integer(allSubjects.size()).toString());
    }
    if (allUsers.size() > 0) {
        setToPanel("Users", new Integer(allUsers.size()).toString());
    }
    if (allSites.size() > 0) {
        setToPanel("Sites", new Integer(allSites.size()).toString());
    }
    if (allSeds.size() > 0) {
        setToPanel("Event Definitions", new Integer(allSeds.size()).toString());
    }
    String proto = request.getParameter("proto");
    if (proto == null || "".equalsIgnoreCase(proto)) {
        forwardPage(Page.MANAGE_STUDY);
    } else {
        forwardPage(Page.MANAGE_STUDY_BODY);
    }
}
Also used : StudyEventDefinitionDAO(org.akaza.openclinica.dao.managestudy.StudyEventDefinitionDAO) ArrayList(java.util.ArrayList) StudyDAO(org.akaza.openclinica.dao.managestudy.StudyDAO) UserAccountDAO(org.akaza.openclinica.dao.login.UserAccountDAO) StudySubjectDAO(org.akaza.openclinica.dao.managestudy.StudySubjectDAO)

Example 22 with UserAccountDAO

use of org.akaza.openclinica.dao.login.UserAccountDAO in project OpenClinica by OpenClinica.

the class RestoreSiteServlet method processRequest.

@Override
public void processRequest() throws Exception {
    StudyDAO sdao = new StudyDAO(sm.getDataSource());
    String idString = request.getParameter("id");
    logger.info("site id:" + idString);
    int siteId = Integer.valueOf(idString.trim()).intValue();
    StudyBean study = (StudyBean) sdao.findByPK(siteId);
    // find all user and roles
    UserAccountDAO udao = new UserAccountDAO(sm.getDataSource());
    ArrayList userRoles = udao.findAllByStudyId(siteId);
    // find all subjects
    StudySubjectDAO ssdao = new StudySubjectDAO(sm.getDataSource());
    ArrayList subjects = ssdao.findAllByStudy(study);
    // find all events
    StudyEventDefinitionDAO sefdao = new StudyEventDefinitionDAO(sm.getDataSource());
    ArrayList definitions = sefdao.findAllByStudy(study);
    String action = request.getParameter("action");
    if (StringUtil.isBlank(idString)) {
        addPageMessage(respage.getString("please_choose_a_site_to_restore"));
        forwardPage(Page.SITE_LIST_SERVLET);
    } else {
        if ("confirm".equalsIgnoreCase(action)) {
            // site can be restored when its parent study is not "removed"
            // -- YW -6-21-2007
            StudyBean parentstudy = (StudyBean) sdao.findByPK(study.getParentStudyId());
            if (!"removed".equals(parentstudy.getStatus().getName())) {
                request.setAttribute("siteToRestore", study);
                request.setAttribute("userRolesToRestore", userRoles);
                request.setAttribute("subjectsToRestore", subjects);
            // request.setAttribute("definitionsToRestore",
            // definitions);
            } else {
                MessageFormat mf = new MessageFormat("");
                mf.applyPattern(respage.getString("choosen_site_cannot_restored"));
                Object[] arguments = { study.getName(), parentstudy.getName() };
                addPageMessage(mf.format(arguments));
                forwardPage(Page.STUDY_LIST_SERVLET);
            }
            forwardPage(Page.RESTORE_SITE);
        } else {
            logger.info("submit to restore the site");
            // change all statuses to unavailable
            StudyDAO studao = new StudyDAO(sm.getDataSource());
            study.setStatus(study.getOldStatus());
            study.setUpdater(ub);
            study.setUpdatedDate(new Date());
            studao.update(study);
            // restore all users and roles
            for (int i = 0; i < userRoles.size(); i++) {
                StudyUserRoleBean role = (StudyUserRoleBean) userRoles.get(i);
                if (role.getStatus().equals(Status.AUTO_DELETED)) {
                    role.setStatus(Status.AVAILABLE);
                    role.setUpdater(ub);
                    role.setUpdatedDate(new Date());
                    // YW << So study_user_role table status_id field can be
                    // updated
                    udao.updateStudyUserRole(role, role.getUserName());
                }
            // YW 06-18-2007 >>
            }
            // study
            if (study.getId() == currentStudy.getId()) {
                currentStudy.setStatus(Status.AVAILABLE);
                StudyUserRoleBean r = (new UserAccountDAO(sm.getDataSource())).findRoleByUserNameAndStudyId(ub.getName(), currentStudy.getId());
                StudyUserRoleBean rInParent = (new UserAccountDAO(sm.getDataSource())).findRoleByUserNameAndStudyId(ub.getName(), currentStudy.getParentStudyId());
                // according to logic in SecureController.java: inherited
                // role from parent study, pick the higher role
                currentRole.setRole(Role.max(r.getRole(), rInParent.getRole()));
            }
            // YW >>
            // restore all study_group
            StudyGroupDAO sgdao = new StudyGroupDAO(sm.getDataSource());
            SubjectGroupMapDAO sgmdao = new SubjectGroupMapDAO(sm.getDataSource());
            ArrayList groups = sgdao.findAllByStudy(study);
            for (int i = 0; i < groups.size(); i++) {
                StudyGroupBean group = (StudyGroupBean) groups.get(i);
                if (group.getStatus().equals(Status.AUTO_DELETED)) {
                    group.setStatus(Status.AVAILABLE);
                    group.setUpdater(ub);
                    group.setUpdatedDate(new Date());
                    sgdao.update(group);
                    // all subject_group_map
                    ArrayList subjectGroupMaps = sgmdao.findAllByStudyGroupId(group.getId());
                    for (int j = 0; j < subjectGroupMaps.size(); j++) {
                        SubjectGroupMapBean sgMap = (SubjectGroupMapBean) subjectGroupMaps.get(j);
                        if (sgMap.getStatus().equals(Status.AUTO_DELETED)) {
                            sgMap.setStatus(Status.AVAILABLE);
                            sgMap.setUpdater(ub);
                            sgMap.setUpdatedDate(new Date());
                            sgmdao.update(sgMap);
                        }
                    }
                }
            }
            // restore all events with subjects
            EventDefinitionCRFDAO edcdao = new EventDefinitionCRFDAO(sm.getDataSource());
            StudyEventDAO sedao = new StudyEventDAO(sm.getDataSource());
            for (int i = 0; i < subjects.size(); i++) {
                StudySubjectBean subject = (StudySubjectBean) subjects.get(i);
                if (subject.getStatus().equals(Status.AUTO_DELETED)) {
                    subject.setStatus(Status.AVAILABLE);
                    subject.setUpdater(ub);
                    subject.setUpdatedDate(new Date());
                    ssdao.update(subject);
                    ArrayList events = sedao.findAllByStudySubject(subject);
                    EventCRFDAO ecdao = new EventCRFDAO(sm.getDataSource());
                    for (int j = 0; j < events.size(); j++) {
                        StudyEventBean event = (StudyEventBean) events.get(j);
                        if (event.getStatus().equals(Status.AUTO_DELETED)) {
                            event.setStatus(Status.AVAILABLE);
                            event.setUpdater(ub);
                            event.setUpdatedDate(new Date());
                            sedao.update(event);
                            ArrayList eventCRFs = ecdao.findAllByStudyEvent(event);
                            ItemDataDAO iddao = new ItemDataDAO(sm.getDataSource());
                            for (int k = 0; k < eventCRFs.size(); k++) {
                                // YW << fix broken page for storing site
                                EventCRFBean eventCRF = (EventCRFBean) eventCRFs.get(k);
                                // >> YW
                                if (eventCRF.getStatus().equals(Status.AUTO_DELETED)) {
                                    eventCRF.setStatus(eventCRF.getOldStatus());
                                    eventCRF.setUpdater(ub);
                                    eventCRF.setUpdatedDate(new Date());
                                    ecdao.update(eventCRF);
                                    ArrayList itemDatas = iddao.findAllByEventCRFId(eventCRF.getId());
                                    for (int a = 0; a < itemDatas.size(); a++) {
                                        ItemDataBean item = (ItemDataBean) itemDatas.get(a);
                                        if (item.getStatus().equals(Status.AUTO_DELETED)) {
                                            item.setStatus(item.getOldStatus());
                                            item.setUpdater(ub);
                                            item.setUpdatedDate(new Date());
                                            iddao.update(item);
                                        }
                                    }
                                }
                            }
                        }
                    }
                }
            }
            // for subjects
            DatasetDAO datadao = new DatasetDAO(sm.getDataSource());
            ArrayList dataset = datadao.findAllByStudyId(study.getId());
            for (int i = 0; i < dataset.size(); i++) {
                DatasetBean data = (DatasetBean) dataset.get(i);
                data.setStatus(Status.AVAILABLE);
                data.setUpdater(ub);
                data.setUpdatedDate(new Date());
                datadao.update(data);
            }
            addPageMessage(respage.getString("this_site_has_been_restored_succesfully"));
            String fromListSite = (String) session.getAttribute("fromListSite");
            if (fromListSite != null && fromListSite.equals("yes") && currentRole.getRole().equals(Role.STUDYDIRECTOR)) {
                session.removeAttribute("fromListSite");
                forwardPage(Page.SITE_LIST_SERVLET);
            } else {
                session.removeAttribute("fromListSite");
                if (currentRole.getRole().equals(Role.ADMIN)) {
                    forwardPage(Page.STUDY_LIST_SERVLET);
                } else {
                    forwardPage(Page.SITE_LIST_SERVLET);
                }
            }
        }
    }
}
Also used : SubjectGroupMapBean(org.akaza.openclinica.bean.submit.SubjectGroupMapBean) DatasetBean(org.akaza.openclinica.bean.extract.DatasetBean) ArrayList(java.util.ArrayList) StudyGroupDAO(org.akaza.openclinica.dao.managestudy.StudyGroupDAO) StudyEventBean(org.akaza.openclinica.bean.managestudy.StudyEventBean) ItemDataDAO(org.akaza.openclinica.dao.submit.ItemDataDAO) EventCRFBean(org.akaza.openclinica.bean.submit.EventCRFBean) 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) MessageFormat(java.text.MessageFormat) SubjectGroupMapDAO(org.akaza.openclinica.dao.submit.SubjectGroupMapDAO) StudyBean(org.akaza.openclinica.bean.managestudy.StudyBean) StudyUserRoleBean(org.akaza.openclinica.bean.login.StudyUserRoleBean) EventDefinitionCRFDAO(org.akaza.openclinica.dao.managestudy.EventDefinitionCRFDAO) UserAccountDAO(org.akaza.openclinica.dao.login.UserAccountDAO) StudySubjectDAO(org.akaza.openclinica.dao.managestudy.StudySubjectDAO) DatasetDAO(org.akaza.openclinica.dao.extract.DatasetDAO) Date(java.util.Date) StudyGroupBean(org.akaza.openclinica.bean.managestudy.StudyGroupBean) StudyEventDefinitionDAO(org.akaza.openclinica.dao.managestudy.StudyEventDefinitionDAO) StudySubjectBean(org.akaza.openclinica.bean.managestudy.StudySubjectBean)

Example 23 with UserAccountDAO

use of org.akaza.openclinica.dao.login.UserAccountDAO in project OpenClinica by OpenClinica.

the class RestoreStudyUserRoleServlet method processRequest.

@Override
public void processRequest() throws Exception {
    UserAccountDAO udao = new UserAccountDAO(sm.getDataSource());
    String name = request.getParameter("name");
    String studyIdString = request.getParameter("studyId");
    if (StringUtil.isBlank(name) || StringUtil.isBlank(studyIdString)) {
        addPageMessage(respage.getString("please_choose_a_user_to_restore_his_role"));
        forwardPage(Page.LIST_USER_IN_STUDY_SERVLET);
    } else {
        String action = request.getParameter("action");
        UserAccountBean user = (UserAccountBean) udao.findByUserName(name);
        if ("confirm".equalsIgnoreCase(action)) {
            int studyId = Integer.valueOf(studyIdString.trim()).intValue();
            request.setAttribute("user", user);
            StudyUserRoleBean uRole = udao.findRoleByUserNameAndStudyId(name, studyId);
            request.setAttribute("uRole", uRole);
            StudyDAO sdao = new StudyDAO(sm.getDataSource());
            StudyBean study = (StudyBean) sdao.findByPK(studyId);
            request.setAttribute("uStudy", study);
            forwardPage(Page.RESTORE_USER_ROLE_IN_STUDY);
        } else {
            // restore role
            FormProcessor fp = new FormProcessor(request);
            String userName = fp.getString("name");
            int studyId = fp.getInt("studyId");
            int roleId = fp.getInt("roleId");
            StudyUserRoleBean sur = new StudyUserRoleBean();
            sur.setName(userName);
            sur.setRole(Role.get(roleId));
            sur.setStudyId(studyId);
            sur.setStatus(Status.AVAILABLE);
            sur.setUpdater(ub);
            sur.setUpdatedDate(new Date());
            udao.updateStudyUserRole(sur, userName);
            addPageMessage(sendEmail(user, sur));
            forwardPage(Page.LIST_USER_IN_STUDY_SERVLET);
        }
    }
}
Also used : FormProcessor(org.akaza.openclinica.control.form.FormProcessor) StudyUserRoleBean(org.akaza.openclinica.bean.login.StudyUserRoleBean) StudyBean(org.akaza.openclinica.bean.managestudy.StudyBean) UserAccountBean(org.akaza.openclinica.bean.login.UserAccountBean) UserAccountDAO(org.akaza.openclinica.dao.login.UserAccountDAO) StudyDAO(org.akaza.openclinica.dao.managestudy.StudyDAO) Date(java.util.Date)

Example 24 with UserAccountDAO

use of org.akaza.openclinica.dao.login.UserAccountDAO in project OpenClinica by OpenClinica.

the class RemoveStudyUserRoleServlet method processRequest.

@Override
public void processRequest() throws Exception {
    UserAccountDAO udao = new UserAccountDAO(sm.getDataSource());
    String name = request.getParameter("name");
    String studyIdString = request.getParameter("studyId");
    if (StringUtil.isBlank(name) || StringUtil.isBlank(studyIdString)) {
        addPageMessage(respage.getString("please_choose_a_user_to_remove_his_role"));
        forwardPage(Page.LIST_USER_IN_STUDY_SERVLET);
    } else {
        String action = request.getParameter("action");
        UserAccountBean user = (UserAccountBean) udao.findByUserName(name);
        if ("confirm".equalsIgnoreCase(action)) {
            int studyId = Integer.valueOf(studyIdString.trim()).intValue();
            request.setAttribute("user", user);
            StudyUserRoleBean uRole = udao.findRoleByUserNameAndStudyId(name, studyId);
            request.setAttribute("uRole", uRole);
            StudyDAO sdao = new StudyDAO(sm.getDataSource());
            StudyBean study = (StudyBean) sdao.findByPK(studyId);
            request.setAttribute("uStudy", study);
            forwardPage(Page.REMOVE_USER_ROLE_IN_STUDY);
        } else {
            // remove role
            FormProcessor fp = new FormProcessor(request);
            String userName = fp.getString("name");
            int studyId = fp.getInt("studyId");
            int roleId = fp.getInt("roleId");
            StudyUserRoleBean sur = new StudyUserRoleBean();
            sur.setName(userName);
            sur.setRole(Role.get(roleId));
            sur.setStudyId(studyId);
            sur.setStatus(Status.DELETED);
            sur.setUpdater(ub);
            sur.setUpdatedDate(new Date());
            udao.updateStudyUserRole(sur, userName);
            addPageMessage(sendEmail(user, sur));
            forwardPage(Page.LIST_USER_IN_STUDY_SERVLET);
        }
    }
}
Also used : FormProcessor(org.akaza.openclinica.control.form.FormProcessor) StudyUserRoleBean(org.akaza.openclinica.bean.login.StudyUserRoleBean) StudyBean(org.akaza.openclinica.bean.managestudy.StudyBean) UserAccountBean(org.akaza.openclinica.bean.login.UserAccountBean) UserAccountDAO(org.akaza.openclinica.dao.login.UserAccountDAO) StudyDAO(org.akaza.openclinica.dao.managestudy.StudyDAO) Date(java.util.Date)

Example 25 with UserAccountDAO

use of org.akaza.openclinica.dao.login.UserAccountDAO in project OpenClinica by OpenClinica.

the class ViewStudyUserServlet method processRequest.

@Override
public void processRequest() throws Exception {
    UserAccountDAO udao = new UserAccountDAO(sm.getDataSource());
    String name = request.getParameter("name");
    String studyIdString = request.getParameter("studyId");
    //if(request.getParameter("submit")!=null)
    {
        if (StringUtil.isBlank(name) || StringUtil.isBlank(studyIdString)) {
            addPageMessage(respage.getString("please_choose_a_user_to_view"));
            forwardPage(Page.LIST_USER_IN_STUDY_SERVLET);
        } else {
            int studyId = Integer.valueOf(studyIdString.trim()).intValue();
            UserAccountBean user = (UserAccountBean) udao.findByUserName(name);
            request.setAttribute("user", user);
            StudyUserRoleBean uRole = udao.findRoleByUserNameAndStudyId(name, studyId);
            request.setAttribute("uRole", uRole);
            StudyDAO sdao = new StudyDAO(sm.getDataSource());
            StudyBean study = (StudyBean) sdao.findByPK(studyId);
            request.setAttribute("uStudy", study);
            request.setAttribute("siteRoleMap", Role.siteRoleMap);
            // BWP 12/7/07 >>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);
            request.setAttribute("action", "");
            forwardPage(Page.VIEW_USER_IN_STUDY);
        }
    }
}
Also used : StudyUserRoleBean(org.akaza.openclinica.bean.login.StudyUserRoleBean) StudyBean(org.akaza.openclinica.bean.managestudy.StudyBean) UserAccountBean(org.akaza.openclinica.bean.login.UserAccountBean) UserAccountDAO(org.akaza.openclinica.dao.login.UserAccountDAO) StudyDAO(org.akaza.openclinica.dao.managestudy.StudyDAO)

Aggregations

UserAccountDAO (org.akaza.openclinica.dao.login.UserAccountDAO)92 UserAccountBean (org.akaza.openclinica.bean.login.UserAccountBean)64 ArrayList (java.util.ArrayList)42 StudyDAO (org.akaza.openclinica.dao.managestudy.StudyDAO)42 StudyBean (org.akaza.openclinica.bean.managestudy.StudyBean)39 FormProcessor (org.akaza.openclinica.control.form.FormProcessor)36 Date (java.util.Date)23 StudyUserRoleBean (org.akaza.openclinica.bean.login.StudyUserRoleBean)22 HashMap (java.util.HashMap)21 StudySubjectDAO (org.akaza.openclinica.dao.managestudy.StudySubjectDAO)17 StudyEventDefinitionDAO (org.akaza.openclinica.dao.managestudy.StudyEventDefinitionDAO)16 StudySubjectBean (org.akaza.openclinica.bean.managestudy.StudySubjectBean)14 StudyEventDAO (org.akaza.openclinica.dao.managestudy.StudyEventDAO)14 Locale (java.util.Locale)13 EventCRFDAO (org.akaza.openclinica.dao.submit.EventCRFDAO)13 ItemDataDAO (org.akaza.openclinica.dao.submit.ItemDataDAO)12 SubjectDAO (org.akaza.openclinica.dao.submit.SubjectDAO)12 StudyEventBean (org.akaza.openclinica.bean.managestudy.StudyEventBean)11 EventDefinitionCRFDAO (org.akaza.openclinica.dao.managestudy.EventDefinitionCRFDAO)11 DiscrepancyNoteBean (org.akaza.openclinica.bean.managestudy.DiscrepancyNoteBean)10