use of org.akaza.openclinica.bean.core.Role 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.core.Role in project OpenClinica by OpenClinica.
the class UpdateStudyServletNew method mayProceed.
/**
*
*/
@Override
public void mayProceed() throws InsufficientPermissionException {
if (ub.isSysAdmin()) {
return;
}
Role r = currentRole.getRole();
if (r.equals(Role.STUDYDIRECTOR) || r.equals(Role.COORDINATOR)) {
return;
}
addPageMessage(respage.getString("no_have_correct_privilege_current_study") + respage.getString("change_study_contact_sysadmin"));
throw new InsufficientPermissionException(Page.MENU_SERVLET, resexception.getString("may_not_submit_data"), "1");
}
use of org.akaza.openclinica.bean.core.Role 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.core.Role 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);
}
}
}
}
use of org.akaza.openclinica.bean.core.Role in project OpenClinica by OpenClinica.
the class AuditLogStudyServlet method mayProceed.
/*
* (non-Javadoc) Since access to this servlet is admin-only, restricts user
* to see logs of specific users only @author thickerson
*
* @see org.akaza.openclinica.control.core.SecureController#mayProceed()
*/
@Override
protected void mayProceed() throws InsufficientPermissionException {
if (ub.isSysAdmin()) {
return;
}
Role r = currentRole.getRole();
if (r.equals(Role.STUDYDIRECTOR) || r.equals(Role.COORDINATOR)) {
return;
}
addPageMessage(respage.getString("no_have_correct_privilege_current_study") + respage.getString("change_study_contact_sysadmin"));
throw new InsufficientPermissionException(Page.MENU_SERVLET, resexception.getString("not_director"), "1");
}
Aggregations