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;
}
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;
}
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;
}
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;
}
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);
}
Aggregations