Search in sources :

Example 21 with FormProcessor

use of org.akaza.openclinica.control.form.FormProcessor in project OpenClinica by OpenClinica.

the class ConfigureServlet method processRequest.

@SuppressWarnings("unchecked")
@Override
protected void processRequest() throws Exception {
    FormProcessor fp = new FormProcessor(request);
    if (!fp.isSubmitted()) {
        loadPresetValuesFromBean(fp);
        setPresetValues(fp.getPresetValues());
        forwardPage(Page.CONFIGURATION);
    } else {
        Validator v = new Validator(request);
        v.addValidation("lockcount", Validator.IS_AN_INTEGER);
        v.addValidation("lockcount", Validator.NO_BLANKS);
        v.addValidation("lockcount", Validator.IS_IN_RANGE, 1, 25);
        HashMap errors = v.validate();
        if (!errors.isEmpty()) {
            loadPresetValuesFromForm(fp);
            setPresetValues(fp.getPresetValues());
            setInputMessages(errors);
            forwardPage(Page.CONFIGURATION);
        } else {
            ConfigurationBean userLockSwitch = getConfigurationDao().findByKey("user.lock.switch");
            ConfigurationBean userLockAllowedFailedConsecutiveLoginAttempts = getConfigurationDao().findByKey("user.lock.allowedFailedConsecutiveLoginAttempts");
            userLockSwitch.setValue(fp.getString("lockswitch"));
            userLockAllowedFailedConsecutiveLoginAttempts.setValue(fp.getString("lockcount"));
            getConfigurationDao().saveOrUpdate(userLockSwitch);
            getConfigurationDao().saveOrUpdate(userLockAllowedFailedConsecutiveLoginAttempts);
            addPageMessage(respage.getString("lockout_changes_have_been_saved"));
            forwardPage(Page.LIST_USER_ACCOUNTS_SERVLET);
        }
    }
}
Also used : ConfigurationBean(org.akaza.openclinica.domain.technicaladmin.ConfigurationBean) HashMap(java.util.HashMap) FormProcessor(org.akaza.openclinica.control.form.FormProcessor) Validator(org.akaza.openclinica.control.form.Validator)

Example 22 with FormProcessor

use of org.akaza.openclinica.control.form.FormProcessor in project OpenClinica by OpenClinica.

the class CreateJobImportServlet method setUpServlet.

/*
     * Find all the form items and re-populate as necessary
     */
private void setUpServlet() throws Exception {
    String directory = SQLInitServlet.getField("filePath") + DIR_PATH + File.separator;
    logger.debug("found directory: " + directory);
    // find all the form items and re-populate them if necessary
    FormProcessor fp2 = new FormProcessor(request);
    UserAccountDAO udao = new UserAccountDAO(sm.getDataSource());
    StudyDAO sdao = new StudyDAO(sm.getDataSource());
    // ArrayList studies = udao.findStudyByUser(ub.getName(), (ArrayList)
    // sdao.findAll());
    // request.setAttribute("studies", studies);
    // tbh, replacing the above with another version, 06/2009
    ArrayList<StudyBean> all = (ArrayList<StudyBean>) sdao.findAll();
    ArrayList<StudyBean> finalList = new ArrayList<StudyBean>();
    for (StudyBean sb : all) {
        if (!(sb.getParentStudyId() > 0)) {
            finalList.add(sb);
            // System.out.println("found study name: " + sb.getName());
            finalList.addAll(sdao.findAllByParent(sb.getId()));
        }
    }
    // System.out.println("found list of studies: " + finalList.toString());
    addEntityList("studies", finalList, respage.getString("a_user_cannot_be_created_no_study_as_active"), Page.ADMIN_SYSTEM);
    // YW >>
    // << tbh
    request.setAttribute("filePath", directory);
    // request.setAttribute("activeStudy", activeStudy);
    request.setAttribute(JOB_NAME, fp2.getString(JOB_NAME));
    request.setAttribute(JOB_DESC, fp2.getString(JOB_DESC));
    request.setAttribute(EMAIL, fp2.getString(EMAIL));
    request.setAttribute(HOURS, new Integer(fp2.getInt(HOURS)).toString());
    request.setAttribute(MINUTES, new Integer(fp2.getInt(MINUTES)).toString());
}
Also used : FormProcessor(org.akaza.openclinica.control.form.FormProcessor) StudyBean(org.akaza.openclinica.bean.managestudy.StudyBean) ArrayList(java.util.ArrayList) UserAccountDAO(org.akaza.openclinica.dao.login.UserAccountDAO) StudyDAO(org.akaza.openclinica.dao.managestudy.StudyDAO)

Example 23 with FormProcessor

use of org.akaza.openclinica.control.form.FormProcessor 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);
        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 24 with FormProcessor

use of org.akaza.openclinica.control.form.FormProcessor 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 25 with FormProcessor

use of org.akaza.openclinica.control.form.FormProcessor in project OpenClinica by OpenClinica.

the class RemoveSubjectServlet method processRequest.

@Override
public void processRequest() throws Exception {
    SubjectDAO sdao = new SubjectDAO(sm.getDataSource());
    FormProcessor fp = new FormProcessor(request);
    int subjectId = fp.getInt("id");
    String action = fp.getString("action");
    if (subjectId == 0 || StringUtil.isBlank(action)) {
        addPageMessage(respage.getString("please_choose_a_subject_to_remove"));
        forwardPage(Page.SUBJECT_LIST_SERVLET);
    } else {
        SubjectBean subject = (SubjectBean) sdao.findByPK(subjectId);
        // find all study subjects
        StudySubjectDAO ssdao = new StudySubjectDAO(sm.getDataSource());
        ArrayList studySubs = ssdao.findAllBySubjectId(subjectId);
        // find study events
        StudyEventDAO sedao = new StudyEventDAO(sm.getDataSource());
        ArrayList events = sedao.findAllBySubjectId(subjectId);
        if ("confirm".equalsIgnoreCase(action)) {
            request.setAttribute("subjectToRemove", subject);
            request.setAttribute("studySubs", studySubs);
            request.setAttribute("events", events);
            forwardPage(Page.REMOVE_SUBJECT);
        } else {
            logger.info("submit to remove the subject");
            // change all statuses to deleted
            subject.setStatus(Status.DELETED);
            subject.setUpdater(ub);
            subject.setUpdatedDate(new Date());
            sdao.update(subject);
            // remove subject references from study
            for (int i = 0; i < studySubs.size(); i++) {
                StudySubjectBean studySub = (StudySubjectBean) studySubs.get(i);
                if (!studySub.getStatus().equals(Status.DELETED)) {
                    studySub.setStatus(Status.AUTO_DELETED);
                    studySub.setUpdater(ub);
                    studySub.setUpdatedDate(new Date());
                    ssdao.update(studySub);
                }
            }
            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.setStatus(Status.AUTO_DELETED);
                            eventCRF.setUpdater(ub);
                            eventCRF.setUpdatedDate(new Date());
                            ecdao.update(eventCRF);
                            // remove all the item data
                            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.setStatus(Status.AUTO_DELETED);
                                    item.setUpdater(ub);
                                    item.setUpdatedDate(new Date());
                                    iddao.update(item);
                                }
                            }
                        }
                    }
                }
            }
            String emailBody = respage.getString("the_subject") + " " + subject.getUniqueIdentifier() + " " + respage.getString("has_been_removed_succesfully");
            addPageMessage(emailBody);
            //                sendEmail(emailBody);
            forwardPage(Page.SUBJECT_LIST_SERVLET);
        }
    }
}
Also used : StudySubjectDAO(org.akaza.openclinica.dao.managestudy.StudySubjectDAO) SubjectDAO(org.akaza.openclinica.dao.submit.SubjectDAO) FormProcessor(org.akaza.openclinica.control.form.FormProcessor) ArrayList(java.util.ArrayList) StudyEventBean(org.akaza.openclinica.bean.managestudy.StudyEventBean) StudySubjectDAO(org.akaza.openclinica.dao.managestudy.StudySubjectDAO) Date(java.util.Date) ItemDataDAO(org.akaza.openclinica.dao.submit.ItemDataDAO) SubjectBean(org.akaza.openclinica.bean.submit.SubjectBean) StudySubjectBean(org.akaza.openclinica.bean.managestudy.StudySubjectBean) EventCRFBean(org.akaza.openclinica.bean.submit.EventCRFBean) StudySubjectBean(org.akaza.openclinica.bean.managestudy.StudySubjectBean) ItemDataBean(org.akaza.openclinica.bean.submit.ItemDataBean) StudyEventDAO(org.akaza.openclinica.dao.managestudy.StudyEventDAO) EventCRFDAO(org.akaza.openclinica.dao.submit.EventCRFDAO)

Aggregations

FormProcessor (org.akaza.openclinica.control.form.FormProcessor)224 ArrayList (java.util.ArrayList)139 StudyBean (org.akaza.openclinica.bean.managestudy.StudyBean)92 StudyDAO (org.akaza.openclinica.dao.managestudy.StudyDAO)73 HashMap (java.util.HashMap)69 Date (java.util.Date)49 StudyEventDefinitionBean (org.akaza.openclinica.bean.managestudy.StudyEventDefinitionBean)48 CRFDAO (org.akaza.openclinica.dao.admin.CRFDAO)46 EventCRFDAO (org.akaza.openclinica.dao.submit.EventCRFDAO)46 Validator (org.akaza.openclinica.control.form.Validator)44 StudyEventDefinitionDAO (org.akaza.openclinica.dao.managestudy.StudyEventDefinitionDAO)44 EventCRFBean (org.akaza.openclinica.bean.submit.EventCRFBean)42 EventDefinitionCRFDAO (org.akaza.openclinica.dao.managestudy.EventDefinitionCRFDAO)41 StudySubjectDAO (org.akaza.openclinica.dao.managestudy.StudySubjectDAO)41 CRFBean (org.akaza.openclinica.bean.admin.CRFBean)40 CRFVersionBean (org.akaza.openclinica.bean.submit.CRFVersionBean)36 UserAccountDAO (org.akaza.openclinica.dao.login.UserAccountDAO)36 EventDefinitionCRFBean (org.akaza.openclinica.bean.managestudy.EventDefinitionCRFBean)35 StudySubjectBean (org.akaza.openclinica.bean.managestudy.StudySubjectBean)35 StudyEventDAO (org.akaza.openclinica.dao.managestudy.StudyEventDAO)35