Search in sources :

Example 16 with StudyUserRoleBean

use of org.akaza.openclinica.bean.login.StudyUserRoleBean in project OpenClinica by OpenClinica.

the class RequestStudyServlet method submit.

/**
     * Gets user basic info and set email to the administrator
     *
     * @param request
     * @param response
     */
private void submit() throws Exception {
    StudyUserRoleBean newRole = (StudyUserRoleBean) session.getAttribute("newRole");
    logger.info("Sending email...");
    StringBuffer email = new StringBuffer(restext.getString("dear_openclinica_administrator") + ", <br>");
    email.append(ub.getFirstName() + restext.getString("request_to_acces_the_following_study") + ": <br>");
    email.append(resword.getString("user_full_name") + ": " + ub.getFirstName() + " " + ub.getLastName());
    email.append("<br>" + resword.getString("username2") + ": " + ub.getName());
    email.append("<br>" + resword.getString("email") + ": " + ub.getEmail());
    email.append("<br>" + resword.getString("study_requested") + ":" + newRole.getStudyName() + ", id:" + newRole.getStudyId());
    email.append("<br>" + resword.getString("user_role_requested") + ": " + newRole.getRole().getDescription());
    String emailBody = email.toString();
    logger.info("Sending email...begin" + emailBody);
    sendEmail(EmailEngine.getAdminEmail(), ub.getEmail().trim(), "request study access", emailBody, false);
    session.removeAttribute("newRole");
    forwardPage(Page.MENU);
}
Also used : StudyUserRoleBean(org.akaza.openclinica.bean.login.StudyUserRoleBean)

Example 17 with StudyUserRoleBean

use of org.akaza.openclinica.bean.login.StudyUserRoleBean in project OpenClinica by OpenClinica.

the class AssignUserToStudyServlet method findUsers.

/**
     * Find all users in the system
     * 
     * @return
     */
private ArrayList findUsers() {
    UserAccountDAO udao = new UserAccountDAO(sm.getDataSource());
    ArrayList userList = (ArrayList) udao.findAll();
    ArrayList userAvailable = new ArrayList();
    for (int i = 0; i < userList.size(); i++) {
        UserAccountBean u = (UserAccountBean) userList.get(i);
        int activeStudyId = currentStudy.getId();
        StudyUserRoleBean sub = udao.findRoleByUserNameAndStudyId(u.getName(), activeStudyId);
        if (!sub.isActive()) {
            // doesn't have a role in the current study
            sub.setRole(Role.RESEARCHASSISTANT);
            sub.setStudyId(activeStudyId);
            u.setActiveStudyId(activeStudyId);
            u.addRole(sub);
            u.setStatus(Status.AVAILABLE);
            // try to find whether this user has role in site or parent
            if (currentStudy.getParentStudyId() > 0) {
                // this is a site
                StudyUserRoleBean subParent = udao.findRoleByUserNameAndStudyId(u.getName(), currentStudy.getParentStudyId());
                if (subParent.isActive()) {
                    u.setNotes(subParent.getRole().getDescription() + " " + respage.getString("in_parent_study"));
                }
            } else {
                // find all the sites for this top study
                StudyDAO sdao = new StudyDAO(sm.getDataSource());
                ArrayList sites = (ArrayList) sdao.findAllByParent(currentStudy.getId());
                String notes = "";
                for (int j = 0; j < sites.size(); j++) {
                    StudyBean site = (StudyBean) sites.get(j);
                    StudyUserRoleBean subSite = udao.findRoleByUserNameAndStudyId(u.getName(), site.getId());
                    if (subSite.isActive()) {
                        notes = notes + subSite.getRole().getDescription() + respage.getString("in_site") + ":" + site.getName() + "; ";
                    }
                }
                u.setNotes(notes);
            }
        } else {
            // already have a role in the current study
            sub.setStudyId(activeStudyId);
            u.setActiveStudyId(activeStudyId);
            u.addRole(sub);
            u.setStatus(Status.UNAVAILABLE);
        }
        userAvailable.add(u);
    }
    return userAvailable;
}
Also used : StudyUserRoleBean(org.akaza.openclinica.bean.login.StudyUserRoleBean) StudyBean(org.akaza.openclinica.bean.managestudy.StudyBean) ArrayList(java.util.ArrayList) UserAccountBean(org.akaza.openclinica.bean.login.UserAccountBean) UserAccountDAO(org.akaza.openclinica.dao.login.UserAccountDAO) StudyDAO(org.akaza.openclinica.dao.managestudy.StudyDAO)

Example 18 with StudyUserRoleBean

use of org.akaza.openclinica.bean.login.StudyUserRoleBean in project OpenClinica by OpenClinica.

the class RequestAccountServlet method getUserBean.

/**
     * Constructs userbean from request
     *
     * @param request
     * @return
     */
private UserAccountBean getUserBean() {
    FormProcessor fp = new FormProcessor(request);
    UserAccountBean ubForm = new UserAccountBean();
    ubForm.setName(fp.getString("name"));
    ubForm.setFirstName(fp.getString("firstName"));
    ubForm.setLastName(fp.getString("lastName"));
    ubForm.setEmail(fp.getString("email"));
    ubForm.setInstitutionalAffiliation(fp.getString("institutionalAffiliation"));
    ubForm.setActiveStudyId(fp.getInt("activeStudyId"));
    StudyUserRoleBean uRole = new StudyUserRoleBean();
    uRole.setStudyId(fp.getInt("activeStudyId"));
    uRole.setRole(Role.get(fp.getInt("activeStudyRole")));
    ubForm.addRole(uRole);
    return ubForm;
}
Also used : FormProcessor(org.akaza.openclinica.control.form.FormProcessor) StudyUserRoleBean(org.akaza.openclinica.bean.login.StudyUserRoleBean) UserAccountBean(org.akaza.openclinica.bean.login.UserAccountBean)

Example 19 with StudyUserRoleBean

use of org.akaza.openclinica.bean.login.StudyUserRoleBean in project OpenClinica by OpenClinica.

the class PrintAllSiteEventCRFServlet method mayProceed.

/**
     * Checks whether the user has the correct privilege
     */
@Override
public void mayProceed(HttpServletRequest request, HttpServletResponse response) throws InsufficientPermissionException {
    locale = LocaleResolver.getLocale(request);
    UserAccountBean ub = (UserAccountBean) request.getSession().getAttribute(USER_BEAN_NAME);
    StudyUserRoleBean currentRole = (StudyUserRoleBean) request.getSession().getAttribute("userRole");
    if (ub.isSysAdmin()) {
        return;
    }
    if (SubmitDataServlet.mayViewData(ub, currentRole)) {
        return;
    }
    addPageMessage(respage.getString("no_have_correct_privilege_current_study") + respage.getString("change_study_contact_sysadmin"), request);
    throw new InsufficientPermissionException(Page.MENU_SERVLET, resexception.getString("not_director"), "1");
}
Also used : StudyUserRoleBean(org.akaza.openclinica.bean.login.StudyUserRoleBean) UserAccountBean(org.akaza.openclinica.bean.login.UserAccountBean) InsufficientPermissionException(org.akaza.openclinica.web.InsufficientPermissionException)

Example 20 with StudyUserRoleBean

use of org.akaza.openclinica.bean.login.StudyUserRoleBean in project OpenClinica by OpenClinica.

the class RemoveSiteServlet 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);
    if (currentStudy.getId() != study.getParentStudyId()) {
        addPageMessage(respage.getString("no_have_correct_privilege_current_study") + " " + respage.getString("change_active_study_or_contact"));
        forwardPage(Page.MENU_SERVLET);
        return;
    }
    // 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_remove"));
        forwardPage(Page.SITE_LIST_SERVLET);
    } else {
        if ("confirm".equalsIgnoreCase(action)) {
            request.setAttribute("siteToRemove", study);
            request.setAttribute("userRolesToRemove", userRoles);
            request.setAttribute("subjectsToRemove", subjects);
            forwardPage(Page.REMOVE_SITE);
        } else {
            logger.info("submit to remove the site");
            // change all statuses to unavailable
            StudyDAO studao = new StudyDAO(sm.getDataSource());
            study.setOldStatus(study.getStatus());
            study.setStatus(Status.DELETED);
            study.setUpdater(ub);
            study.setUpdatedDate(new Date());
            studao.update(study);
            // remove all users and roles
            for (int i = 0; i < userRoles.size(); i++) {
                StudyUserRoleBean role = (StudyUserRoleBean) userRoles.get(i);
                if (!role.getStatus().equals(Status.DELETED)) {
                    role.setStatus(Status.AUTO_DELETED);
                    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 >>
            }
            // YW << bug fix that current active study has been deleted
            if (study.getId() == currentStudy.getId()) {
                currentStudy.setStatus(Status.DELETED);
                // currentRole.setRole(Role.INVALID);
                currentRole.setStatus(Status.DELETED);
            }
            // remove all subjects
            for (int i = 0; i < subjects.size(); i++) {
                StudySubjectBean subject = (StudySubjectBean) subjects.get(i);
            }
            // remove 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.DELETED)) {
                    group.setStatus(Status.AUTO_DELETED);
                    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.DELETED)) {
                            sgMap.setStatus(Status.AUTO_DELETED);
                            sgMap.setUpdater(ub);
                            sgMap.setUpdatedDate(new Date());
                            sgmdao.update(sgMap);
                        }
                    }
                }
            }
            // remove all events
            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.DELETED)) {
                    subject.setStatus(Status.AUTO_DELETED);
                    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.DELETED)) {
                            event.setStatus(Status.AUTO_DELETED);
                            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++) {
                                EventCRFBean eventCRF = (EventCRFBean) eventCRFs.get(k);
                                if (!eventCRF.getStatus().equals(Status.DELETED)) {
                                    eventCRF.setOldStatus(eventCRF.getStatus());
                                    eventCRF.setStatus(Status.AUTO_DELETED);
                                    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.DELETED)) {
                                            item.setOldStatus(item.getStatus());
                                            item.setStatus(Status.AUTO_DELETED);
                                            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);
                if (!data.getStatus().equals(Status.DELETED)) {
                    data.setStatus(Status.AUTO_DELETED);
                    data.setUpdater(ub);
                    data.setUpdatedDate(new Date());
                    datadao.update(data);
                }
            }
            addPageMessage(respage.getString("this_site_has_been_removed_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) SubjectGroupMapDAO(org.akaza.openclinica.dao.submit.SubjectGroupMapDAO) StudyBean(org.akaza.openclinica.bean.managestudy.StudyBean) StudyUserRoleBean(org.akaza.openclinica.bean.login.StudyUserRoleBean) DatasetBean(org.akaza.openclinica.bean.extract.DatasetBean) ArrayList(java.util.ArrayList) EventDefinitionCRFDAO(org.akaza.openclinica.dao.managestudy.EventDefinitionCRFDAO) StudyGroupDAO(org.akaza.openclinica.dao.managestudy.StudyGroupDAO) StudyEventBean(org.akaza.openclinica.bean.managestudy.StudyEventBean) 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) ItemDataDAO(org.akaza.openclinica.dao.submit.ItemDataDAO) StudyGroupBean(org.akaza.openclinica.bean.managestudy.StudyGroupBean) EventCRFBean(org.akaza.openclinica.bean.submit.EventCRFBean) StudyEventDefinitionDAO(org.akaza.openclinica.dao.managestudy.StudyEventDefinitionDAO) StudySubjectBean(org.akaza.openclinica.bean.managestudy.StudySubjectBean) 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)

Aggregations

StudyUserRoleBean (org.akaza.openclinica.bean.login.StudyUserRoleBean)76 UserAccountBean (org.akaza.openclinica.bean.login.UserAccountBean)35 ArrayList (java.util.ArrayList)34 StudyBean (org.akaza.openclinica.bean.managestudy.StudyBean)28 StudyDAO (org.akaza.openclinica.dao.managestudy.StudyDAO)23 UserAccountDAO (org.akaza.openclinica.dao.login.UserAccountDAO)22 Date (java.util.Date)16 FormProcessor (org.akaza.openclinica.control.form.FormProcessor)16 Role (org.akaza.openclinica.bean.core.Role)15 HashMap (java.util.HashMap)14 Iterator (java.util.Iterator)12 InsufficientPermissionException (org.akaza.openclinica.web.InsufficientPermissionException)10 EventCRFBean (org.akaza.openclinica.bean.submit.EventCRFBean)9 Validator (org.akaza.openclinica.control.form.Validator)6 SimpleDateFormat (java.text.SimpleDateFormat)4 HttpSession (javax.servlet.http.HttpSession)4 DatasetBean (org.akaza.openclinica.bean.extract.DatasetBean)4 EventDefinitionCRFBean (org.akaza.openclinica.bean.managestudy.EventDefinitionCRFBean)4 StudyEventBean (org.akaza.openclinica.bean.managestudy.StudyEventBean)4 StudyEventDefinitionBean (org.akaza.openclinica.bean.managestudy.StudyEventDefinitionBean)4