use of org.akaza.openclinica.bean.login.StudyUserRoleBean in project OpenClinica by OpenClinica.
the class SetStudyUserRoleServlet method processRequest.
@Override
public void processRequest() throws Exception {
UserAccountDAO udao = new UserAccountDAO(sm.getDataSource());
StudyDAO sdao = new StudyDAO(sm.getDataSource());
String name = request.getParameter("name");
String studyIdString = request.getParameter("studyId");
if (StringUtil.isBlank(name) || StringUtil.isBlank(studyIdString)) {
addPageMessage(respage.getString("please_choose_a_user_to_set_role_for"));
forwardPage(Page.LIST_USER_IN_STUDY_SERVLET);
} else {
String action = request.getParameter("action");
FormProcessor fp = new FormProcessor(request);
UserAccountBean user = (UserAccountBean) udao.findByUserName(name);
StudyBean userStudy = (StudyBean) sdao.findByPK(fp.getInt("studyId"));
if ("confirm".equalsIgnoreCase(action)) {
int studyId = Integer.valueOf(studyIdString.trim()).intValue();
request.setAttribute("user", user);
StudyUserRoleBean uRole = udao.findRoleByUserNameAndStudyId(name, studyId);
uRole.setStudyName(userStudy.getName());
request.setAttribute("uRole", uRole);
ArrayList roles = Role.toArrayList();
// admin is not a user role, only used for tomcat
roles.remove(Role.ADMIN);
roles.remove(Role.RESEARCHASSISTANT2);
StudyBean studyBean = (StudyBean) sdao.findByPK(uRole.getStudyId());
if (currentStudy.getParentStudyId() > 0) {
roles.remove(Role.COORDINATOR);
roles.remove(Role.STUDYDIRECTOR);
} else if (studyBean.getParentStudyId() > 0) {
roles.remove(Role.COORDINATOR);
roles.remove(Role.STUDYDIRECTOR);
// TODO: redo this fix
Role r = Role.RESEARCHASSISTANT;
r.setDescription("site_Data_Entry_Person");
roles.remove(Role.RESEARCHASSISTANT);
roles.add(r);
Role ri = Role.INVESTIGATOR;
ri.setDescription("site_investigator");
roles.remove(Role.INVESTIGATOR);
roles.add(ri);
Role r2 = Role.RESEARCHASSISTANT2;
r2.setDescription("site_Data_Entry_Person2");
roles.remove(Role.RESEARCHASSISTANT2);
roles.add(r2);
}
request.setAttribute("roles", roles);
forwardPage(Page.SET_USER_ROLE_IN_STUDY);
} else {
// set role
String userName = fp.getString("name");
int studyId = fp.getInt("studyId");
int roleId = fp.getInt("roleId");
StudyUserRoleBean sur = new StudyUserRoleBean();
sur.setName(userName);
sur.setRole(Role.get(roleId));
sur.setStudyId(studyId);
sur.setStudyName(userStudy.getName());
sur.setStatus(Status.AVAILABLE);
sur.setUpdater(ub);
sur.setUpdatedDate(new Date());
udao.updateStudyUserRole(sur, userName);
addPageMessage(sendEmail(user, sur));
forwardPage(Page.LIST_USER_IN_STUDY_SERVLET);
}
}
}
use of org.akaza.openclinica.bean.login.StudyUserRoleBean in project OpenClinica by OpenClinica.
the class UserAccountDAO method findStudyByUser.
/**
* Finds all the studies with roles for a user
*
* @param userName
* @param allStudies
* The result of calling StudyDAO.findAll();
*/
public ArrayList findStudyByUser(String userName, ArrayList allStudies) {
this.unsetTypeExpected();
this.setTypeExpected(1, TypeNames.STRING);
this.setTypeExpected(2, TypeNames.INT);
this.setTypeExpected(3, TypeNames.STRING);
HashMap allStudyUserRoleBeans = new HashMap();
HashMap variables = new HashMap();
variables.put(new Integer(1), userName);
ArrayList alist = this.select(digester.getQuery("findStudyByUser"), variables);
Iterator it = alist.iterator();
while (it.hasNext()) {
HashMap hm = (HashMap) it.next();
String roleName = (String) hm.get("role_name");
String studyName = (String) hm.get("name");
Integer studyId = (Integer) hm.get("study_id");
StudyUserRoleBean sur = new StudyUserRoleBean();
sur.setRoleName(roleName);
sur.setStudyId(studyId.intValue());
sur.setStudyName(studyName);
allStudyUserRoleBeans.put(studyId, sur);
}
// pseudocode:
// for each parent study P in the system
// if the user has a role in that study, add it to the answer
// otherwise, let parentAdded = false
//
// for each study, C, which is a child of P
// if the user has a role in C,
// if parentAdded = false
// add a StudyUserRole with study = P, role = invalid to the answer
// let parentAdded = true
// add the user's role in C to the answer
ArrayList answer = new ArrayList();
StudyDAO sdao = new StudyDAO(ds);
HashMap childrenByParentId = sdao.getChildrenByParentIds(allStudies);
for (int i = 0; i < allStudies.size(); i++) {
StudyBean parent = (StudyBean) allStudies.get(i);
if (parent == null || parent.getParentStudyId() > 0) {
continue;
}
boolean parentAdded = false;
Integer studyId = new Integer(parent.getId());
StudyUserRoleBean roleInStudy;
ArrayList subTreeRoles = new ArrayList();
if (allStudyUserRoleBeans.containsKey(studyId)) {
roleInStudy = (StudyUserRoleBean) allStudyUserRoleBeans.get(studyId);
subTreeRoles.add(roleInStudy);
parentAdded = true;
} else {
// we do this so that we can compute Role.max below
// without
// throwing a NullPointerException
roleInStudy = new StudyUserRoleBean();
}
ArrayList children = (ArrayList) childrenByParentId.get(studyId);
if (children == null) {
children = new ArrayList();
}
for (int j = 0; j < children.size(); j++) {
StudyBean child = (StudyBean) children.get(j);
Integer childId = new Integer(child.getId());
if (allStudyUserRoleBeans.containsKey(childId)) {
if (!parentAdded) {
roleInStudy.setStudyId(studyId.intValue());
roleInStudy.setRole(Role.INVALID);
roleInStudy.setStudyName(parent.getName());
subTreeRoles.add(roleInStudy);
parentAdded = true;
}
StudyUserRoleBean roleInChild = (StudyUserRoleBean) allStudyUserRoleBeans.get(childId);
Role max = Role.max(roleInChild.getRole(), roleInStudy.getRole());
roleInChild.setRole(max);
roleInChild.setParentStudyId(studyId.intValue());
subTreeRoles.add(roleInChild);
} else {
StudyUserRoleBean roleInChild = new StudyUserRoleBean();
roleInChild.setStudyId(child.getId());
roleInChild.setStudyName(child.getName());
roleInChild.setRole(roleInStudy.getRole());
roleInChild.setParentStudyId(studyId.intValue());
subTreeRoles.add(roleInChild);
}
}
if (parentAdded) {
answer.addAll(subTreeRoles);
}
}
return answer;
}
use of org.akaza.openclinica.bean.login.StudyUserRoleBean in project OpenClinica by OpenClinica.
the class UserAccountDAO method findAllUsersByStudy.
/**
* Finds all user and roles in a study
*
* @param studyId
*/
public ArrayList findAllUsersByStudy(int studyId) {
// SELECT ua.user_name,ua.first_name, ua.last_name, sur.role_name,
// sur.study_id,sur.status_id,sur.date_updated,sur.update_id, s.name
// ua.user_id
// FROM user_account ua, study_user_role sur, study s
// WHERE ua.user_name=sur.user_name
// AND (sur.study_id=s.study_id)
// AND (sur.study_id=?
// OR sur.study_id in (select s.study_id FROM study s WHERE
// s.parent_study_id=? ))
// order by ua.date_created asc
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(studyId));
ArrayList alist = this.select(digester.getQuery("findAllUsersByStudy"), 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 findAllUsersByStudyIdAndLimit.
/**
* Finds all user and roles in a study
*
* @param studyId
*/
public ArrayList findAllUsersByStudyIdAndLimit(int studyId, boolean isLimited) {
this.setRoleTypesExpected();
ArrayList answer = new ArrayList();
HashMap variables = new HashMap();
variables.put(new Integer(1), new Integer(studyId));
variables.put(new Integer(2), new Integer(studyId));
ArrayList alist = null;
if (isLimited) {
alist = this.select(digester.getQuery("findAllByStudyIdAndLimit"), variables);
} else {
alist = this.select(digester.getQuery("findAllByStudyId"), variables);
}
Iterator it = alist.iterator();
while (it.hasNext()) {
StudyUserRoleBean surb = this.getRoleFromHashMap((HashMap) it.next());
answer.add(surb);
}
return answer;
}
use of org.akaza.openclinica.bean.login.StudyUserRoleBean in project OpenClinica by OpenClinica.
the class UserAccountDAO method findAllRolesByUserName.
public Collection findAllRolesByUserName(String userName) {
this.setRoleTypesExpected();
ArrayList answer = new ArrayList();
HashMap variables = new HashMap();
variables.put(new Integer(1), userName);
ArrayList alist = this.select(digester.getQuery("findAllRolesByUserName"), variables);
Iterator it = alist.iterator();
while (it.hasNext()) {
StudyUserRoleBean surb = this.getRoleFromHashMap((HashMap) it.next());
answer.add(surb);
}
return answer;
}
Aggregations