Search in sources :

Example 31 with StudyDAO

use of org.akaza.openclinica.dao.managestudy.StudyDAO in project OpenClinica by OpenClinica.

the class EditStudyUserRoleServlet method processRequest.

@Override
protected void processRequest() throws Exception {
    UserAccountDAO udao = new UserAccountDAO(sm.getDataSource());
    FormProcessor fp = new FormProcessor(request);
    int studyId = fp.getInt(ARG_STUDY_ID);
    String uName = fp.getString(ARG_USER_NAME);
    StudyUserRoleBean studyUserRole = udao.findRoleByUserNameAndStudyId(uName, studyId);
    UserAccountBean user = (UserAccountBean) udao.findByUserName(uName);
    techAdminProtect(user);
    StudyDAO sdao = new StudyDAO(sm.getDataSource());
    StudyBean sb = (StudyBean) sdao.findByPK(studyUserRole.getStudyId());
    if (sb != null) {
        studyUserRole.setStudyName(sb.getName());
    }
    if (!studyUserRole.isActive()) {
        String message = respage.getString("the_user_has_no_role_in_study");
        addPageMessage(message);
        forwardPage(Page.LIST_USER_ACCOUNTS_SERVLET);
    } else {
        Map roleMap = new LinkedHashMap();
        for (Iterator it = getRoles().iterator(); it.hasNext(); ) {
            Role role = (Role) it.next();
            roleMap.put(role.getId(), role.getDescription());
        }
        roleMap = new LinkedHashMap();
        ResourceBundle resterm = org.akaza.openclinica.i18n.util.ResourceBundleProvider.getTermsBundle();
        StudyBean study = (StudyBean) sdao.findByPK(studyUserRole.getStudyId());
        if (study.getParentStudyId() == 0) {
            for (Iterator it = getRoles().iterator(); it.hasNext(); ) {
                Role role = (Role) it.next();
                switch(role.getId()) {
                    case 2:
                        roleMap.put(role.getId(), resterm.getString("Study_Coordinator").trim());
                        break;
                    case 3:
                        roleMap.put(role.getId(), resterm.getString("Study_Director").trim());
                        break;
                    case 4:
                        roleMap.put(role.getId(), resterm.getString("Investigator").trim());
                        break;
                    case 5:
                        roleMap.put(role.getId(), resterm.getString("Data_Entry_Person").trim());
                        break;
                    case 6:
                        roleMap.put(role.getId(), resterm.getString("Monitor").trim());
                        break;
                    default:
                }
            }
        } else {
            for (Iterator it = getRoles().iterator(); it.hasNext(); ) {
                Role role = (Role) it.next();
                switch(role.getId()) {
                    // break;
                    case 4:
                        roleMap.put(role.getId(), resterm.getString("site_investigator").trim());
                        break;
                    case 5:
                        roleMap.put(role.getId(), resterm.getString("site_Data_Entry_Person").trim());
                        break;
                    case 6:
                        roleMap.put(role.getId(), resterm.getString("site_monitor").trim());
                        break;
                    case 7:
                        roleMap.put(role.getId(), resterm.getString("site_Data_Entry_Person2").trim());
                        break;
                    default:
                }
            }
        }
        if (study.getParentStudyId() > 0) {
            roleMap.remove(Role.COORDINATOR.getId());
            roleMap.remove(Role.STUDYDIRECTOR.getId());
        }
        // send the user to the right place..
        if (!fp.isSubmitted()) {
            request.setAttribute("userName", uName);
            request.setAttribute("studyUserRole", studyUserRole);
            request.setAttribute("roles", roleMap);
            request.setAttribute("chosenRoleId", new Integer(studyUserRole.getRole().getId()));
            forwardPage(Page.EDIT_STUDY_USER_ROLE);
        } else // process the form
        {
            Validator v = new Validator(request);
            v.addValidation(INPUT_ROLE, Validator.IS_VALID_TERM, TermType.ROLE);
            HashMap errors = v.validate();
            if (errors.isEmpty()) {
                int roleId = fp.getInt(INPUT_ROLE);
                Role r = Role.get(roleId);
                studyUserRole.setRoleName(r.getName());
                studyUserRole.setUpdater(ub);
                udao.updateStudyUserRole(studyUserRole, uName);
                String message = respage.getString("the_user_in_study_has_been_updated");
                addPageMessage(message);
                forwardPage(Page.LIST_USER_ACCOUNTS_SERVLET);
            } else {
                String message = respage.getString("the_role_choosen_was_invalid_choose_another");
                addPageMessage(message);
                request.setAttribute("userName", uName);
                request.setAttribute("studyUserRole", studyUserRole);
                request.setAttribute("chosenRoleId", new Integer(fp.getInt(INPUT_ROLE)));
                request.setAttribute("roles", roleMap);
                forwardPage(Page.EDIT_STUDY_USER_ROLE);
            }
        }
    }
}
Also used : FormProcessor(org.akaza.openclinica.control.form.FormProcessor) StudyUserRoleBean(org.akaza.openclinica.bean.login.StudyUserRoleBean) StudyBean(org.akaza.openclinica.bean.managestudy.StudyBean) UserAccountDAO(org.akaza.openclinica.dao.login.UserAccountDAO) Role(org.akaza.openclinica.bean.core.Role) UserAccountBean(org.akaza.openclinica.bean.login.UserAccountBean) StudyDAO(org.akaza.openclinica.dao.managestudy.StudyDAO) Validator(org.akaza.openclinica.control.form.Validator)

Example 32 with StudyDAO

use of org.akaza.openclinica.dao.managestudy.StudyDAO in project OpenClinica by OpenClinica.

the class RemoveStudyServlet method processRequest.

@Override
public void processRequest() throws Exception {
    StudyDAO sdao = new StudyDAO(sm.getDataSource());
    FormProcessor fp = new FormProcessor(request);
    int studyId = fp.getInt("id");
    StudyBean study = (StudyBean) sdao.findByPK(studyId);
    // find all sites
    ArrayList sites = (ArrayList) sdao.findAllByParent(studyId);
    // find all user and roles in the study, include ones in sites
    UserAccountDAO udao = new UserAccountDAO(sm.getDataSource());
    ArrayList userRoles = udao.findAllByStudyId(studyId);
    // find all subjects in the study, include ones in sites
    StudySubjectDAO ssdao = new StudySubjectDAO(sm.getDataSource());
    ArrayList subjects = ssdao.findAllByStudy(study);
    // find all events in the study, include ones in sites
    StudyEventDefinitionDAO sefdao = new StudyEventDefinitionDAO(sm.getDataSource());
    ArrayList definitions = sefdao.findAllByStudy(study);
    String action = request.getParameter("action");
    if (studyId == 0) {
        addPageMessage(respage.getString("please_choose_a_study_to_remove"));
        forwardPage(Page.STUDY_LIST_SERVLET);
    } else {
        if ("confirm".equalsIgnoreCase(action)) {
            request.setAttribute("studyToRemove", study);
            request.setAttribute("sitesToRemove", sites);
            request.setAttribute("userRolesToRemove", userRoles);
            request.setAttribute("subjectsToRemove", subjects);
            request.setAttribute("definitionsToRemove", definitions);
            forwardPage(Page.REMOVE_STUDY);
        } else {
            logger.info("submit to remove the study");
            // 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 sites
            for (int i = 0; i < sites.size(); i++) {
                StudyBean site = (StudyBean) sites.get(i);
                if (!site.getStatus().equals(Status.DELETED)) {
                    site.setOldStatus(site.getStatus());
                    site.setStatus(Status.AUTO_DELETED);
                    site.setUpdater(ub);
                    site.setUpdatedDate(new Date());
                    sdao.update(site);
                }
            }
            // remove all users and roles
            for (int i = 0; i < userRoles.size(); i++) {
                StudyUserRoleBean role = (StudyUserRoleBean) userRoles.get(i);
                logger.info("remove user role" + role.getName());
                if (!role.getStatus().equals(Status.DELETED)) {
                    role.setStatus(Status.AUTO_DELETED);
                    role.setUpdater(ub);
                    role.setUpdatedDate(new Date());
                    udao.updateStudyUserRole(role, role.getUserName());
                }
            }
            // YW << bug fix for that current active study has been deleted
            if (study.getId() == currentStudy.getId()) {
                currentStudy.setStatus(Status.DELETED);
                currentRole.setStatus(Status.DELETED);
            } else // (auto-removed)
            if (currentStudy.getParentStudyId() == study.getId()) {
                currentStudy.setStatus(Status.AUTO_DELETED);
                // we may need handle this later?
                currentRole.setStatus(Status.DELETED);
            }
            // remove all subjects
            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);
                }
            }
            // remove all study_group_class
            // changed by jxu on 08-31-06, to fix the problem of no study_id
            // in study_group table
            StudyGroupClassDAO sgcdao = new StudyGroupClassDAO(sm.getDataSource());
            StudyGroupDAO sgdao = new StudyGroupDAO(sm.getDataSource());
            SubjectGroupMapDAO sgmdao = new SubjectGroupMapDAO(sm.getDataSource());
            // YW 09-27-2007, enable status updating for StudyGroupClassBean
            ArrayList groups = sgcdao.findAllByStudy(study);
            for (int i = 0; i < groups.size(); i++) {
                StudyGroupClassBean group = (StudyGroupClassBean) groups.get(i);
                if (!group.getStatus().equals(Status.DELETED)) {
                    group.setStatus(Status.AUTO_DELETED);
                    group.setUpdater(ub);
                    group.setUpdatedDate(new Date());
                    sgcdao.update(group);
                    // all subject_group_map
                    ArrayList subjectGroupMaps = sgmdao.findAllByStudyGroupClassId(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);
                        }
                    }
                }
            }
            ArrayList groupClasses = sgcdao.findAllActiveByStudy(study);
            for (int i = 0; i < groupClasses.size(); i++) {
                StudyGroupClassBean gc = (StudyGroupClassBean) groupClasses.get(i);
                if (!gc.getStatus().equals(Status.DELETED)) {
                    gc.setStatus(Status.AUTO_DELETED);
                    gc.setUpdater(ub);
                    gc.setUpdatedDate(new Date());
                    sgcdao.update(gc);
                }
            }
            // remove all event definitions and event
            EventDefinitionCRFDAO edcdao = new EventDefinitionCRFDAO(sm.getDataSource());
            StudyEventDAO sedao = new StudyEventDAO(sm.getDataSource());
            for (int i = 0; i < definitions.size(); i++) {
                StudyEventDefinitionBean definition = (StudyEventDefinitionBean) definitions.get(i);
                if (!definition.getStatus().equals(Status.DELETED)) {
                    definition.setStatus(Status.AUTO_DELETED);
                    definition.setUpdater(ub);
                    definition.setUpdatedDate(new Date());
                    sefdao.update(definition);
                    ArrayList edcs = (ArrayList) edcdao.findAllByDefinition(definition.getId());
                    for (int j = 0; j < edcs.size(); j++) {
                        EventDefinitionCRFBean edc = (EventDefinitionCRFBean) edcs.get(j);
                        if (!edc.getStatus().equals(Status.DELETED)) {
                            edc.setStatus(Status.AUTO_DELETED);
                            edc.setUpdater(ub);
                            edc.setUpdatedDate(new Date());
                            edcdao.update(edc);
                        }
                    }
                    ArrayList events = (ArrayList) sedao.findAllByDefinition(definition.getId());
                    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 definitions
            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(resexception.getString("this_study_has_been_removed_succesfully"));
            forwardPage(Page.STUDY_LIST_SERVLET);
        }
    }
}
Also used : SubjectGroupMapBean(org.akaza.openclinica.bean.submit.SubjectGroupMapBean) StudyGroupClassDAO(org.akaza.openclinica.dao.managestudy.StudyGroupClassDAO) DatasetBean(org.akaza.openclinica.bean.extract.DatasetBean) ArrayList(java.util.ArrayList) StudyEventDefinitionBean(org.akaza.openclinica.bean.managestudy.StudyEventDefinitionBean) 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) StudyGroupClassBean(org.akaza.openclinica.bean.managestudy.StudyGroupClassBean) StudyDAO(org.akaza.openclinica.dao.managestudy.StudyDAO) EventCRFDAO(org.akaza.openclinica.dao.submit.EventCRFDAO) SubjectGroupMapDAO(org.akaza.openclinica.dao.submit.SubjectGroupMapDAO) FormProcessor(org.akaza.openclinica.control.form.FormProcessor) 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) StudyEventDefinitionDAO(org.akaza.openclinica.dao.managestudy.StudyEventDefinitionDAO) StudySubjectBean(org.akaza.openclinica.bean.managestudy.StudySubjectBean) EventDefinitionCRFBean(org.akaza.openclinica.bean.managestudy.EventDefinitionCRFBean)

Example 33 with StudyDAO

use of org.akaza.openclinica.dao.managestudy.StudyDAO in project OpenClinica by OpenClinica.

the class SetUserRoleServlet method processRequest.

@Override
public void processRequest() throws Exception {
    UserAccountDAO udao = new UserAccountDAO(sm.getDataSource());
    StudyDAO sdao = new StudyDAO(sm.getDataSource());
    FormProcessor fp = new FormProcessor(request);
    int userId = fp.getInt("userId");
    if (userId == 0) {
        addPageMessage(respage.getString("please_choose_a_user_to_set_role_for"));
        forwardPage(Page.LIST_USER_ACCOUNTS_SERVLET);
    } else {
        String action = request.getParameter("action");
        UserAccountBean user = (UserAccountBean) udao.findByPK(userId);
        techAdminProtect(user);
        ArrayList studies = (ArrayList) sdao.findAll();
        ArrayList studiesHaveRole = (ArrayList) sdao.findAllByUser(user.getName());
        studies.removeAll(studiesHaveRole);
        HashSet<StudyBean> studiesNotHaveRole = new HashSet<StudyBean>();
        HashSet<StudyBean> sitesNotHaveRole = new HashSet<StudyBean>();
        for (int i = 0; i < studies.size(); i++) {
            StudyBean study1 = (StudyBean) studies.get(i);
            // TODO: implement equal() according to id
            boolean hasStudy = false;
            for (int j = 0; j < studiesHaveRole.size(); j++) {
                StudyBean study2 = (StudyBean) studiesHaveRole.get(j);
                if (study2.getId() == study1.getId()) {
                    hasStudy = true;
                    break;
                }
            }
            if (!hasStudy) {
                // YW 11-19-2007 <<
                if (study1.getParentStudyId() > 0) {
                    sitesNotHaveRole.add(study1);
                } else {
                    studiesNotHaveRole.add(study1);
                }
            // YW >>
            }
        }
        Map roleMap = new LinkedHashMap();
        for (Iterator it = getRoles().iterator(); it.hasNext(); ) {
            Role role = (Role) it.next();
            // I added the below if statement , to exclude displaying on study level the newly added 'ReseachAssisstant2' role by default.
            if (role.getId() != 7)
                roleMap.put(role.getId(), role.getDescription());
        }
        Boolean changeRoles = request.getParameter("changeRoles") == null ? false : Boolean.parseBoolean(request.getParameter("changeRoles"));
        int studyId = fp.getInt("studyId");
        if (changeRoles) {
            StudyBean study = (StudyBean) sdao.findByPK(studyId);
            roleMap = new LinkedHashMap();
            ResourceBundle resterm = org.akaza.openclinica.i18n.util.ResourceBundleProvider.getTermsBundle();
            if (study.getParentStudyId() > 0) {
                for (Iterator it = getRoles().iterator(); it.hasNext(); ) {
                    Role role = (Role) it.next();
                    switch(role.getId()) {
                        // break;
                        case 4:
                            roleMap.put(role.getId(), resterm.getString("site_investigator").trim());
                            break;
                        case 5:
                            roleMap.put(role.getId(), resterm.getString("site_Data_Entry_Person").trim());
                            break;
                        case 6:
                            roleMap.put(role.getId(), resterm.getString("site_monitor").trim());
                            break;
                        case 7:
                            roleMap.put(role.getId(), resterm.getString("site_Data_Entry_Person2").trim());
                            break;
                        default:
                    }
                }
            } else {
                for (Iterator it = getRoles().iterator(); it.hasNext(); ) {
                    Role role = (Role) it.next();
                    switch(role.getId()) {
                        case 2:
                            roleMap.put(role.getId(), resterm.getString("Study_Coordinator").trim());
                            break;
                        case 3:
                            roleMap.put(role.getId(), resterm.getString("Study_Director").trim());
                            break;
                        case 4:
                            roleMap.put(role.getId(), resterm.getString("Investigator").trim());
                            break;
                        case 5:
                            roleMap.put(role.getId(), resterm.getString("Data_Entry_Person").trim());
                            break;
                        case 6:
                            roleMap.put(role.getId(), resterm.getString("Monitor").trim());
                            break;
                        default:
                    }
                }
            }
        } else {
            if (currentStudy.getParentStudyId() > 0) {
                roleMap.remove(Role.COORDINATOR.getId());
                roleMap.remove(Role.STUDYDIRECTOR.getId());
            }
        }
        request.setAttribute("roles", roleMap);
        request.setAttribute("studyId", studyId);
        if ("confirm".equalsIgnoreCase(action) || changeRoles) {
            // YW 11-19-2007 << re-order studiesNotHaveRole so that sites
            // under their studies;
            ArrayList finalStudiesNotHaveRole = new ArrayList();
            Iterator iter_study = studiesNotHaveRole.iterator();
            while (iter_study.hasNext()) {
                StudyBean s = (StudyBean) iter_study.next();
                finalStudiesNotHaveRole.add(s);
                Iterator iter_site = sitesNotHaveRole.iterator();
                while (iter_site.hasNext()) {
                    StudyBean site = (StudyBean) iter_site.next();
                    if (site.getParentStudyId() == s.getId()) {
                        finalStudiesNotHaveRole.add(site);
                    }
                }
            }
            // YW >>
            request.setAttribute("user", user);
            request.setAttribute("studies", finalStudiesNotHaveRole);
            StudyUserRoleBean uRole = new StudyUserRoleBean();
            uRole.setFirstName(user.getFirstName());
            uRole.setLastName(user.getLastName());
            uRole.setUserName(user.getName());
            request.setAttribute("uRole", uRole);
            // ArrayList roles = Role.toArrayList();
            // roles.remove(Role.ADMIN); // admin is not a user role, only used for tomcat
            // if (currentStudy.getParentStudyId() > 0) {
            // roles.remove(Role.COORDINATOR);
            // roles.remove(Role.STUDYDIRECTOR);
            // }
            // request.setAttribute("roles", roles);
            forwardPage(Page.SET_USER_ROLE);
        } else {
            // set role
            String userName = fp.getString("name");
            studyId = fp.getInt("studyId");
            StudyBean userStudy = (StudyBean) sdao.findByPK(studyId);
            int roleId = fp.getInt("roleId");
            // new user role
            StudyUserRoleBean sur = new StudyUserRoleBean();
            sur.setName(userName);
            sur.setRole(Role.get(roleId));
            sur.setStudyId(studyId);
            sur.setStudyName(userStudy.getName());
            sur.setStatus(Status.AVAILABLE);
            sur.setOwner(ub);
            sur.setCreatedDate(new Date());
            if (studyId > 0) {
                udao.createStudyUserRole(user, sur);
                addPageMessage(user.getFirstName() + " " + user.getLastName() + " (" + resword.getString("username") + ": " + user.getName() + ") " + respage.getString("has_been_granted_the_role") + " \"" + sur.getRole().getDescription() + "\" " + respage.getString("in_the_study_site") + " " + userStudy.getName() + ".");
            }
            ArrayList<String> pMessage = (ArrayList<String>) request.getAttribute(SecureController.PAGE_MESSAGE);
            String url = response.encodeRedirectURL("ListUserAccounts" + "?alertmessage=" + URLEncoder.encode(pMessage.get(0), "UTF-8"));
            response.sendRedirect(url);
        // forwardPage(Page.LIST_USER_ACCOUNTS_SERVLET);
        }
    }
}
Also used : FormProcessor(org.akaza.openclinica.control.form.FormProcessor) StudyBean(org.akaza.openclinica.bean.managestudy.StudyBean) StudyUserRoleBean(org.akaza.openclinica.bean.login.StudyUserRoleBean) ArrayList(java.util.ArrayList) UserAccountDAO(org.akaza.openclinica.dao.login.UserAccountDAO) Date(java.util.Date) LinkedHashMap(java.util.LinkedHashMap) Role(org.akaza.openclinica.bean.core.Role) UserAccountBean(org.akaza.openclinica.bean.login.UserAccountBean) Iterator(java.util.Iterator) ResourceBundle(java.util.ResourceBundle) StudyDAO(org.akaza.openclinica.dao.managestudy.StudyDAO) LinkedHashMap(java.util.LinkedHashMap) Map(java.util.Map) HashSet(java.util.HashSet)

Example 34 with StudyDAO

use of org.akaza.openclinica.dao.managestudy.StudyDAO in project OpenClinica by OpenClinica.

the class ListSubjectServlet method processRequest.

@Override
public void processRequest() throws Exception {
    SubjectDAO sdao = new SubjectDAO(sm.getDataSource());
    StudySubjectDAO subdao = new StudySubjectDAO(sm.getDataSource());
    StudyDAO studyDao = new StudyDAO(sm.getDataSource());
    UserAccountDAO uadao = new UserAccountDAO(sm.getDataSource());
    ListSubjectTableFactory factory = new ListSubjectTableFactory();
    factory.setSubjectDao(sdao);
    factory.setStudySubjectDao(subdao);
    factory.setUserAccountDao(uadao);
    factory.setStudyDao(studyDao);
    factory.setCurrentStudy(currentStudy);
    String auditLogsHtml = factory.createTable(request, response).render();
    request.setAttribute("listSubjectsHtml", auditLogsHtml);
    forwardPage(Page.SUBJECT_LIST);
}
Also used : StudySubjectDAO(org.akaza.openclinica.dao.managestudy.StudySubjectDAO) SubjectDAO(org.akaza.openclinica.dao.submit.SubjectDAO) StudySubjectDAO(org.akaza.openclinica.dao.managestudy.StudySubjectDAO) StudyDAO(org.akaza.openclinica.dao.managestudy.StudyDAO) UserAccountDAO(org.akaza.openclinica.dao.login.UserAccountDAO)

Example 35 with StudyDAO

use of org.akaza.openclinica.dao.managestudy.StudyDAO in project OpenClinica by OpenClinica.

the class ListUserAccountsServlet method setStudyNamesInStudyUserRoles.

/**
 * For each user, for each study user role, set the study user role's
 * studyName property.
 *
 * @param users
 *            The users to display in the table of users. Each element is a
 *            UserAccountBean.
 */
private void setStudyNamesInStudyUserRoles(ArrayList users) {
    StudyDAO sdao = new StudyDAO(sm.getDataSource());
    ArrayList allStudies = (ArrayList) sdao.findAll();
    HashMap studiesById = new HashMap();
    int i;
    for (i = 0; i < allStudies.size(); i++) {
        StudyBean sb = (StudyBean) allStudies.get(i);
        studiesById.put(new Integer(sb.getId()), sb);
    }
    for (i = 0; i < users.size(); i++) {
        UserAccountBean u = (UserAccountBean) users.get(i);
        ArrayList roles = u.getRoles();
        for (int j = 0; j < roles.size(); j++) {
            StudyUserRoleBean surb = (StudyUserRoleBean) roles.get(j);
            StudyBean sb = (StudyBean) studiesById.get(new Integer(surb.getStudyId()));
            if (sb != null) {
                surb.setStudyName(sb.getName());
                surb.setParentStudyId(sb.getParentStudyId());
            }
            roles.set(j, surb);
        }
        u.setRoles(roles);
        users.set(i, u);
    }
    return;
}
Also used : HashMap(java.util.HashMap) StudyBean(org.akaza.openclinica.bean.managestudy.StudyBean) StudyUserRoleBean(org.akaza.openclinica.bean.login.StudyUserRoleBean) ArrayList(java.util.ArrayList) UserAccountBean(org.akaza.openclinica.bean.login.UserAccountBean) StudyDAO(org.akaza.openclinica.dao.managestudy.StudyDAO)

Aggregations

StudyDAO (org.akaza.openclinica.dao.managestudy.StudyDAO)205 StudyBean (org.akaza.openclinica.bean.managestudy.StudyBean)184 ArrayList (java.util.ArrayList)116 FormProcessor (org.akaza.openclinica.control.form.FormProcessor)73 StudySubjectDAO (org.akaza.openclinica.dao.managestudy.StudySubjectDAO)59 StudyEventDefinitionDAO (org.akaza.openclinica.dao.managestudy.StudyEventDefinitionDAO)57 StudySubjectBean (org.akaza.openclinica.bean.managestudy.StudySubjectBean)50 Date (java.util.Date)49 StudyEventDAO (org.akaza.openclinica.dao.managestudy.StudyEventDAO)49 StudyEventBean (org.akaza.openclinica.bean.managestudy.StudyEventBean)47 EventCRFDAO (org.akaza.openclinica.dao.submit.EventCRFDAO)46 StudyEventDefinitionBean (org.akaza.openclinica.bean.managestudy.StudyEventDefinitionBean)45 UserAccountDAO (org.akaza.openclinica.dao.login.UserAccountDAO)43 EventDefinitionCRFDAO (org.akaza.openclinica.dao.managestudy.EventDefinitionCRFDAO)43 HashMap (java.util.HashMap)42 UserAccountBean (org.akaza.openclinica.bean.login.UserAccountBean)39 EventCRFBean (org.akaza.openclinica.bean.submit.EventCRFBean)37 CRFVersionDAO (org.akaza.openclinica.dao.submit.CRFVersionDAO)35 CRFDAO (org.akaza.openclinica.dao.admin.CRFDAO)34 CRFVersionBean (org.akaza.openclinica.bean.submit.CRFVersionBean)30