Search in sources :

Example 41 with StudyUserRoleBean

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

the class StudySubjectEndpoint method validateRequestAndReturnStudy.

/**
     * Validate the listStudySubjectsInStudy request.
     * 
     * @param studyRef
     * @return StudyBean
     */
private StudyBean validateRequestAndReturnStudy(StudyRefType studyRef) {
    String studyIdentifier = studyRef == null ? null : studyRef.getIdentifier().trim();
    String siteIdentifier = studyRef.getSiteRef() == null ? null : studyRef.getSiteRef().getIdentifier().trim();
    if (studyIdentifier == null && siteIdentifier == null) {
        throw new OpenClinicaSystemException("studySubjectEndpoint.provide_valid_study_site", "Provide a valid study/site.");
    }
    if (studyIdentifier != null && siteIdentifier == null) {
        StudyBean study = getStudyDao().findByUniqueIdentifier(studyIdentifier);
        if (study == null) {
            throw new OpenClinicaSystemException("studySubjectEndpoint.invalid_study_identifier", "The study identifier you provided is not valid.");
        }
        StudyUserRoleBean studySur = getUserAccountDao().findRoleByUserNameAndStudyId(getUserAccount().getName(), study.getId());
        if (studySur.getStatus() != Status.AVAILABLE) {
            throw new OpenClinicaSystemException("studySubjectEndpoint.insufficient_permissions", "You do not have sufficient privileges to proceed with this operation.");
        }
        return study;
    }
    if (studyIdentifier != null && siteIdentifier != null) {
        StudyBean study = getStudyDao().findByUniqueIdentifier(studyIdentifier);
        StudyBean site = getStudyDao().findByUniqueIdentifier(siteIdentifier);
        if (study == null || site == null || site.getParentStudyId() != study.getId()) {
            throw new OpenClinicaSystemException("studySubjectEndpoint.invalid_study_site_identifier", "The study/site identifier you provided is not valid.");
        }
        StudyUserRoleBean siteSur = getUserAccountDao().findRoleByUserNameAndStudyId(getUserAccount().getName(), site.getId());
        if (siteSur.getStatus() != Status.AVAILABLE) {
            throw new OpenClinicaSystemException("studySubjectEndpoint.insufficient_permissions", "You do not have sufficient privileges to proceed with this operation.");
        }
        return site;
    }
    return null;
}
Also used : StudyUserRoleBean(org.akaza.openclinica.bean.login.StudyUserRoleBean) OpenClinicaSystemException(org.akaza.openclinica.exception.OpenClinicaSystemException)

Example 42 with StudyUserRoleBean

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

the class UserAccountDAO method findAllUsersByStudyOrSite.

public ArrayList findAllUsersByStudyOrSite(int studyId, int parentStudyId, int studySubjectId) {
    this.unsetTypeExpected();
    this.setTypeExpected(1, TypeNames.STRING);
    this.setTypeExpected(2, TypeNames.STRING);
    this.setTypeExpected(3, TypeNames.STRING);
    this.setTypeExpected(4, TypeNames.STRING);
    this.setTypeExpected(5, TypeNames.INT);
    this.setTypeExpected(6, TypeNames.INT);
    this.setTypeExpected(7, TypeNames.DATE);
    this.setTypeExpected(8, TypeNames.INT);
    this.setTypeExpected(9, TypeNames.STRING);
    this.setTypeExpected(10, TypeNames.INT);
    this.setTypeExpected(11, TypeNames.INT);
    ArrayList answer = new ArrayList();
    HashMap variables = new HashMap();
    variables.put(new Integer(1), new Integer(studyId));
    variables.put(new Integer(2), new Integer(parentStudyId));
    variables.put(new Integer(3), new Integer(studySubjectId));
    ArrayList alist = this.select(digester.getQuery("findAllUsersByStudyOrSite"), variables);
    Iterator it = alist.iterator();
    while (it.hasNext()) {
        HashMap hm = (HashMap) it.next();
        StudyUserRoleBean surb = new StudyUserRoleBean();
        surb.setUserName((String) hm.get("user_name"));
        surb.setLastName((String) hm.get("last_name"));
        surb.setFirstName((String) hm.get("first_name"));
        surb.setRoleName((String) hm.get("role_name"));
        surb.setStudyName((String) hm.get("name"));
        surb.setStudyId(((Integer) hm.get("study_id")).intValue());
        surb.setParentStudyId(((Integer) hm.get("parent_study_id")).intValue());
        surb.setUserAccountId(((Integer) hm.get("user_id")).intValue());
        Integer statusId = (Integer) hm.get("status_id");
        Date dateUpdated = (Date) hm.get("date_updated");
        surb.setUpdatedDate(dateUpdated);
        surb.setStatus(Status.get(statusId.intValue()));
        answer.add(surb);
    }
    return answer;
}
Also used : HashMap(java.util.HashMap) StudyUserRoleBean(org.akaza.openclinica.bean.login.StudyUserRoleBean) ArrayList(java.util.ArrayList) Iterator(java.util.Iterator) Date(java.util.Date)

Example 43 with StudyUserRoleBean

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

the class UserAccountDAO method getRoleFromHashMap.

public StudyUserRoleBean getRoleFromHashMap(HashMap hm) {
    StudyUserRoleBean surb = new StudyUserRoleBean();
    Date dateCreated = (Date) hm.get("date_created");
    Date dateUpdated = (Date) hm.get("date_updated");
    Integer statusId = (Integer) hm.get("status_id");
    Integer studyId = (Integer) hm.get("study_id");
    Integer ownerId = (Integer) hm.get("owner_id");
    Integer updateId = (Integer) hm.get("update_id");
    surb.setName((String) hm.get("user_name"));
    surb.setUserName((String) hm.get("user_name"));
    surb.setRoleName((String) hm.get("role_name"));
    surb.setCreatedDate(dateCreated);
    surb.setUpdatedDate(dateUpdated);
    surb.setStatus(Status.get(statusId.intValue()));
    surb.setStudyId(studyId.intValue());
    // surb.setUpdater()
    return surb;
}
Also used : StudyUserRoleBean(org.akaza.openclinica.bean.login.StudyUserRoleBean) Date(java.util.Date)

Example 44 with StudyUserRoleBean

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

the class UserAccountDAO method findRoleByUserNameAndStudyId.

public StudyUserRoleBean findRoleByUserNameAndStudyId(String userName, int studyId) {
    Collection roles = findAllRolesByUserName(userName);
    Iterator roleIt = roles.iterator();
    while (roleIt.hasNext()) {
        StudyUserRoleBean s = (StudyUserRoleBean) roleIt.next();
        if (s.getStudyId() == studyId) {
            s.setActive(true);
            return s;
        }
    }
    StudyUserRoleBean doesntExist = new StudyUserRoleBean();
    doesntExist.setActive(false);
    return doesntExist;
}
Also used : StudyUserRoleBean(org.akaza.openclinica.bean.login.StudyUserRoleBean) Iterator(java.util.Iterator) Collection(java.util.Collection)

Example 45 with StudyUserRoleBean

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

the class DeleteStudyUserRoleServlet method processRequest.

@Override
protected void processRequest() throws Exception {
    UserAccountDAO udao = new UserAccountDAO(sm.getDataSource());
    FormProcessor fp = new FormProcessor(request);
    int studyId = fp.getInt(ARG_STUDYID);
    String uName = fp.getString(ARG_USERNAME);
    UserAccountBean user = (UserAccountBean) udao.findByUserName(uName);
    int action = fp.getInt(ARG_ACTION);
    StudyUserRoleBean s = udao.findRoleByUserNameAndStudyId(uName, studyId);
    String message;
    if (!s.isActive()) {
        message = respage.getString("the_specified_user_role_not_exits_for_study");
    } else if (!EntityAction.contains(action)) {
        message = respage.getString("the_specified_action_is_invalid");
    } else if (!EntityAction.get(action).equals(EntityAction.DELETE) && !EntityAction.get(action).equals(EntityAction.RESTORE)) {
        message = respage.getString("the_specified_action_is_not_allowed");
    } else if (EntityAction.get(action).equals(EntityAction.RESTORE) && user.getStatus().equals(Status.DELETED)) {
        message = respage.getString("the_role_cannot_be_restored_since_user_deleted");
    } else {
        EntityAction desiredAction = EntityAction.get(action);
        if (desiredAction.equals(EntityAction.DELETE)) {
            s.setStatus(Status.DELETED);
            message = respage.getString("the_study_user_role_deleted");
        } else {
            s.setStatus(Status.AVAILABLE);
            message = respage.getString("the_study_user_role_restored");
        }
        s.setUpdater(ub);
        udao.updateStudyUserRole(s, uName);
    }
    addPageMessage(message);
    forwardPage(Page.LIST_USER_ACCOUNTS_SERVLET);
}
Also used : EntityAction(org.akaza.openclinica.bean.core.EntityAction) FormProcessor(org.akaza.openclinica.control.form.FormProcessor) StudyUserRoleBean(org.akaza.openclinica.bean.login.StudyUserRoleBean) UserAccountBean(org.akaza.openclinica.bean.login.UserAccountBean) UserAccountDAO(org.akaza.openclinica.dao.login.UserAccountDAO)

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