Search in sources :

Example 6 with StudyUserRoleBean

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

the class UserAccountDAO method create.

@Override
public EntityBean create(EntityBean eb) {
    UserAccountBean uab = (UserAccountBean) eb;
    HashMap variables = new HashMap();
    int id = getNextPK();
    variables.put(new Integer(1), new Integer(id));
    variables.put(new Integer(2), uab.getName());
    variables.put(new Integer(3), uab.getPasswd());
    variables.put(new Integer(4), uab.getFirstName());
    variables.put(new Integer(5), uab.getLastName());
    variables.put(new Integer(6), uab.getEmail());
    variables.put(new Integer(7), new Integer(uab.getActiveStudyId()));
    variables.put(new Integer(8), uab.getInstitutionalAffiliation());
    variables.put(new Integer(9), new Integer(uab.getStatus().getId()));
    variables.put(new Integer(10), new Integer(uab.getOwnerId()));
    variables.put(new Integer(11), uab.getPasswdChallengeQuestion());
    variables.put(new Integer(12), uab.getPasswdChallengeAnswer());
    variables.put(new Integer(13), uab.getPhone());
    if (uab.isTechAdmin()) {
        variables.put(new Integer(14), new Integer(UserType.TECHADMIN.getId()));
    } else if (uab.isSysAdmin()) {
        variables.put(new Integer(14), new Integer(UserType.SYSADMIN.getId()));
    } else {
        variables.put(new Integer(14), new Integer(UserType.USER.getId()));
    }
    variables.put(new Integer(15), uab.getRunWebservices());
    variables.put(new Integer(16), uab.getAccessCode());
    variables.put(new Integer(17), uab.isEnableApiKey());
    variables.put(new Integer(18), uab.getApiKey());
    boolean success = true;
    this.execute(digester.getQuery("insert"), variables);
    success = success && isQuerySuccessful();
    setSysAdminRole(uab, true);
    ArrayList userRoles = uab.getRoles();
    for (int i = 0; i < userRoles.size(); i++) {
        StudyUserRoleBean studyRole = (StudyUserRoleBean) userRoles.get(i);
        if (studyRole.equals(Role.ADMIN)) {
            continue;
        }
        createStudyUserRole(uab, studyRole);
        success = success && isQuerySuccessful();
    }
    if (success) {
        uab.setId(id);
    }
    return uab;
}
Also used : HashMap(java.util.HashMap) StudyUserRoleBean(org.akaza.openclinica.bean.login.StudyUserRoleBean) UserAccountBean(org.akaza.openclinica.bean.login.UserAccountBean) ArrayList(java.util.ArrayList)

Example 7 with StudyUserRoleBean

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

the class SubjectTransferValidator method validate.

public void validate(Object obj, Errors e) {
    SubjectTransferBean subjectTransferBean = (SubjectTransferBean) obj;
    StudyBean study = getStudyDAO().findByUniqueIdentifier(subjectTransferBean.getStudyOid());
    if (study == null) {
        e.reject("subjectTransferValidator.study_does_not_exist", new Object[] { subjectTransferBean.getStudyOid() }, "Study identifier you specified " + subjectTransferBean.getStudyOid() + " does not correspond to a valid study.");
        return;
    }
    UserAccountBean ua = subjectTransferBean.getOwner();
    StudyUserRoleBean role = ua.getRoleByStudy(study);
    if (role.getId() == 0 || role.getRole().equals(Role.MONITOR)) {
        e.reject("subjectTransferValidator.insufficient_permissions", "You do not have sufficient privileges to proceed with this operation.");
        return;
    }
    if (subjectTransferBean.getSiteIdentifier() != null) {
        study = getStudyDAO().findSiteByUniqueIdentifier(subjectTransferBean.getStudyOid(), subjectTransferBean.getSiteIdentifier());
    }
    subjectTransferBean.setStudy(study);
    if (study == null) {
        e.reject("subjectTransferValidator.site_does_not_exist", new Object[] { subjectTransferBean.getSiteIdentifier() }, "Site identifier you specified does not correspond to a valid site.");
        return;
    }
    int handleStudyId = study.getParentStudyId() > 0 ? study.getParentStudyId() : study.getId();
    StudyParameterValueBean studyParameter = getStudyParameterValueDAO().findByHandleAndStudy(handleStudyId, "subjectPersonIdRequired");
    String personId = subjectTransferBean.getPersonId();
    if ("required".equals(studyParameter.getValue()) && (personId == null || personId.length() < 1)) {
        e.reject("subjectTransferValidator.personId_required", new Object[] { study.getName() }, "personId is required for the study: " + study.getName());
        return;
    }
    if (personId != null && personId.length() > 255) {
        e.reject("subjectTransferValidator.personId_invalid_length", new Object[] { personId }, "personId: " + personId + " cannot be longer than 255 characters.");
        return;
    }
    String idSetting = "";
    StudyParameterValueBean subjectIdGenerationParameter = getStudyParameterValueDAO().findByHandleAndStudy(handleStudyId, "subjectIdGeneration");
    idSetting = subjectIdGenerationParameter.getValue();
    if (idSetting.equals("auto editable") || idSetting.equals("auto non-editable")) {
        int nextLabel = getStudySubjectDAO().findTheGreatestLabel() + 1;
        subjectTransferBean.setStudySubjectId(new Integer(nextLabel).toString());
    }
    String studySubjectId = subjectTransferBean.getStudySubjectId();
    if (studySubjectId == null || studySubjectId.length() < 1) {
        e.reject("subjectTransferValidator.studySubjectId_required");
        return;
    } else if (studySubjectId.length() > 30) {
        e.reject("subjectTransferValidator.studySubjectId_invalid_length", new Object[] { studySubjectId }, "studySubjectId: " + studySubjectId + " cannot be longer than 30 characters.");
        return;
    }
    String secondaryId = subjectTransferBean.getSecondaryId();
    if (secondaryId != null && secondaryId.length() > 30) {
        e.reject("subjectTransferValidator.secondaryId_invalid_length", new Object[] { secondaryId }, "secondaryId: " + secondaryId + " cannot be longer than 30 characters.");
        return;
    }
    String gender = subjectTransferBean.getGender() + "";
    studyParameter = getStudyParameterValueDAO().findByHandleAndStudy(handleStudyId, "genderRequired");
    if ("true".equals(studyParameter.getValue()) && (gender == null || gender.length() < 1)) {
        e.reject("subjectTransferValidator.gender_required", new Object[] { study.getName() }, "Gender is required for the study: " + study.getName());
        return;
    }
    if (!"m".equals(gender) && !"f".equals(gender)) {
        e.reject("subjectTransferValidator.gender_is_m_or_f");
        //e.reject("subjectTransferValidator.gender_required", new Object[] { study.getName() }, "Gender is required to be 'm' or 'f'");
        return;
    }
    Date dateOfBirth = subjectTransferBean.getDateOfBirth();
    String yearOfBirth = subjectTransferBean.getYearOfBirth();
    studyParameter = getStudyParameterValueDAO().findByHandleAndStudy(handleStudyId, "collectDob");
    if ("1".equals(studyParameter.getValue()) && (dateOfBirth == null)) {
        e.reject("subjectTransferValidator.dateOfBirth_required", new Object[] { study.getName() }, "Date of birth is required for the study " + study.getName());
        return;
    } else if ("2".equals(studyParameter.getValue()) && (yearOfBirth == null)) {
        e.reject("subjectTransferValidator.yearOfBirth_required", new Object[] { study.getName() }, "Year of birth is required for the study " + study.getName());
        return;
    } else if ("2".equals(studyParameter.getValue()) && (yearOfBirth != null)) {
        try {
            SimpleDateFormat sdf = new SimpleDateFormat("yyyy");
            subjectTransferBean.setDateOfBirth(sdf.parse(subjectTransferBean.getYearOfBirth()));
        } catch (ParseException xe) {
            e.reject("subjectTransferValidator.yearOfBirth_invalid", new Object[] { yearOfBirth }, "Year of birth: " + yearOfBirth + " is not valid");
            return;
        }
    }
    Date enrollmentDate = subjectTransferBean.getEnrollmentDate();
    if (enrollmentDate == null) {
        e.reject("subjectTransferValidator.enrollmentDate_required");
        return;
    } else {
        if ((new Date()).compareTo(enrollmentDate) < 0) {
            e.reject("subjectTransferValidator.enrollmentDate_should_be_in_past");
            return;
        }
    }
}
Also used : StudyParameterValueBean(org.akaza.openclinica.bean.service.StudyParameterValueBean) StudyBean(org.akaza.openclinica.bean.managestudy.StudyBean) StudyUserRoleBean(org.akaza.openclinica.bean.login.StudyUserRoleBean) UserAccountBean(org.akaza.openclinica.bean.login.UserAccountBean) ParseException(java.text.ParseException) SubjectTransferBean(org.akaza.openclinica.bean.managestudy.SubjectTransferBean) SimpleDateFormat(java.text.SimpleDateFormat) Date(java.util.Date)

Example 8 with StudyUserRoleBean

use of org.akaza.openclinica.bean.login.StudyUserRoleBean 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);
    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) StudyDAO(org.akaza.openclinica.dao.managestudy.StudyDAO) Validator(org.akaza.openclinica.control.form.Validator)

Example 9 with StudyUserRoleBean

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

the class CreateUserAccountServlet method addActiveStudyRole.

private UserAccountBean addActiveStudyRole(UserAccountBean createdUserAccountBean, int studyId, Role r) {
    createdUserAccountBean.setActiveStudyId(studyId);
    StudyUserRoleBean activeStudyRole = new StudyUserRoleBean();
    activeStudyRole.setStudyId(studyId);
    activeStudyRole.setRoleName(r.getName());
    activeStudyRole.setStatus(Status.AVAILABLE);
    activeStudyRole.setOwner(ub);
    createdUserAccountBean.addRole(activeStudyRole);
    return createdUserAccountBean;
}
Also used : StudyUserRoleBean(org.akaza.openclinica.bean.login.StudyUserRoleBean)

Example 10 with StudyUserRoleBean

use of org.akaza.openclinica.bean.login.StudyUserRoleBean 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)

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