use of org.akaza.openclinica.bean.login.StudyUserRoleBean in project OpenClinica by OpenClinica.
the class CreateStudyServlet method processRequest.
/**
* Processes user request
*/
@Override
public void processRequest() throws Exception {
// updateMaps();
String action = request.getParameter("action");
resetPanel();
panel.setStudyInfoShown(false);
panel.setOrderedData(true);
panel.setExtractData(false);
panel.setSubmitDataModule(false);
panel.setCreateDataset(false);
panel.setIconInfoShown(true);
panel.setManageSubject(false);
if (StringUtil.isBlank(action)) {
session.setAttribute("newStudy", new StudyBean());
// request.setAttribute("facRecruitStatusMap", facRecruitStatusMap);
// request.setAttribute("statuses", Status.toActiveArrayList());
UserAccountDAO udao = new UserAccountDAO(sm.getDataSource());
Collection users = udao.findAllByRole("coordinator", "director");
request.setAttribute("users", users);
forwardPage(Page.CREATE_STUDY1);
} else {
if ("confirm".equalsIgnoreCase(action)) {
confirmWholeStudy();
} else if ("cancel".equalsIgnoreCase(action)) {
addPageMessage(respage.getString("study_creation_cancelled"));
forwardPage(Page.STUDY_LIST_SERVLET);
return;
} else if ("submit".equalsIgnoreCase(action)) {
submitStudy();
session.removeAttribute("interventions");
session.removeAttribute("isInterventionalFlag");
session.removeAttribute("interventionArray");
// swith user to the newly created study
session.setAttribute("study", session.getAttribute("newStudy"));
session.removeAttribute("newStudy");
currentStudy = (StudyBean) session.getAttribute("study");
UserAccountDAO udao = new UserAccountDAO(sm.getDataSource());
StudyUserRoleBean sub = new StudyUserRoleBean();
sub.setRole(Role.COORDINATOR);
sub.setStudyId(currentStudy.getId());
sub.setStatus(Status.AVAILABLE);
sub.setOwner(ub);
udao.createStudyUserRole(ub, sub);
currentRole = sub;
session.setAttribute("userRole", sub);
addPageMessage(respage.getString("the_new_study_created_succesfully_current"));
// forwardPage(Page.STUDY_LIST_SERVLET);
ArrayList pageMessages = (ArrayList) request.getAttribute(PAGE_MESSAGE);
session.setAttribute("pageMessages", pageMessages);
response.sendRedirect(request.getContextPath() + Page.MANAGE_STUDY_MODULE.getFileName());
} else if ("next".equalsIgnoreCase(action)) {
Integer pageNumber = Integer.valueOf(request.getParameter("pageNum"));
if (pageNumber != null) {
if (pageNumber.intValue() == 6) {
confirmStudy6();
} else if (pageNumber.intValue() == 5) {
confirmStudy5();
} else if (pageNumber.intValue() == 4) {
confirmStudy4();
} else if (pageNumber.intValue() == 3) {
confirmStudy3();
} else if (pageNumber.intValue() == 2) {
confirmStudy2();
} else {
logger.info("confirm study 1" + pageNumber.intValue());
confirmStudy1();
}
} else {
if (session.getAttribute("newStudy") == null) {
session.setAttribute("newStudy", new StudyBean());
}
UserAccountDAO udao = new UserAccountDAO(sm.getDataSource());
Collection users = udao.findAllByRole("coordinator", "director");
request.setAttribute("users", users);
forwardPage(Page.CREATE_STUDY1);
}
}
}
}
use of org.akaza.openclinica.bean.login.StudyUserRoleBean in project OpenClinica by OpenClinica.
the class AssignUserToStudyServlet method addUser.
private void addUser(ArrayList users) throws Exception {
String pageMass = "";
UserAccountDAO udao = new UserAccountDAO(sm.getDataSource());
FormProcessor fp = new FormProcessor(request);
Map tmpSelectedUsersMap = (HashMap) session.getAttribute("tmpSelectedUsersMap");
Set addedUsers = new HashSet();
boolean continueLoop = true;
for (int i = 0; i < users.size() && continueLoop; i++) {
int id = fp.getInt("id" + i);
String firstName = fp.getString("firstName" + i);
String lastName = fp.getString("lastName" + i);
String name = fp.getString("name" + i);
String email = fp.getString("email" + i);
int roleId = fp.getInt("activeStudyRoleId" + i);
String checked = fp.getString("selected" + i);
if (!StringUtil.isBlank(checked) && "yes".equalsIgnoreCase(checked.trim())) {
logger.info("one user selected");
UserAccountBean u = new UserAccountBean();
u.setId(id);
u.setLastName(lastName);
u.setFirstName(firstName);
u.setName(name);
u.setEmail(email);
u.setActiveStudyId(ub.getActiveStudyId());
u.setOwnerId(id);
addedUsers.add(id);
StudyUserRoleBean sub = new StudyUserRoleBean();
sub.setRoleName(Role.get(roleId).getName());
sub.setStudyId(currentStudy.getId());
sub.setStatus(Status.AVAILABLE);
sub.setOwner(ub);
if (//create only when it doesn't exist in database
udao.findStudyUserRole(u, sub).getName() != null && udao.findStudyUserRole(u, sub).getName().isEmpty())
udao.createStudyUserRole(u, sub);
else {
continueLoop = false;
break;
}
logger.info("one user added");
pageMass = pageMass + sendEmail(u, sub);
} else {
if (tmpSelectedUsersMap != null && tmpSelectedUsersMap.containsKey(id)) {
tmpSelectedUsersMap.remove(id);
}
}
}
/* Assigning users which might have been selected during list navigation */
if (tmpSelectedUsersMap != null) {
// exception
for (Iterator iterator = tmpSelectedUsersMap.keySet().iterator(); iterator.hasNext(); ) {
int id = (Integer) iterator.next();
int roleId = (Integer) tmpSelectedUsersMap.get(id);
boolean alreadyAdded = false;
for (Iterator it = addedUsers.iterator(); it.hasNext(); ) {
if (id == (Integer) it.next()) {
alreadyAdded = true;
}
}
if (!alreadyAdded) {
UserAccountBean u = new UserAccountBean();
u.setId(id);
u.setName(udao.findByPK(id).getName());
u.setActiveStudyId(ub.getActiveStudyId());
u.setOwnerId(id);
StudyUserRoleBean sub = new StudyUserRoleBean();
sub.setRoleName(Role.get(roleId).getName());
sub.setStudyId(currentStudy.getId());
sub.setStatus(Status.AVAILABLE);
sub.setOwner(ub);
udao.createStudyUserRole(u, sub);
logger.info("one user added");
pageMass = pageMass + sendEmail(u, sub);
}
}
}
session.removeAttribute("tmpSelectedUsersMap");
if ("".equals(pageMass)) {
addPageMessage(respage.getString("no_new_user_assigned_to_study"));
} else {
addPageMessage(pageMass);
}
ArrayList pageMessages = (ArrayList) request.getAttribute(PAGE_MESSAGE);
session.setAttribute("pageMessages", pageMessages);
// tbh #3936 07/2009
if (currentStudy.getParentStudyId() == 0) {
response.sendRedirect(request.getContextPath() + Page.MANAGE_STUDY_MODULE.getFileName());
} else {
// you are in a site which means you should NOT access build study
// module
forwardPage(Page.LIST_USER_IN_STUDY_SERVLET);
}
// << tbh
}
use of org.akaza.openclinica.bean.login.StudyUserRoleBean in project OpenClinica by OpenClinica.
the class ChangeStudyServlet method processRequest.
@Override
public void processRequest() throws Exception {
// action sent by user
String action = request.getParameter("action");
UserAccountDAO udao = new UserAccountDAO(sm.getDataSource());
StudyDAO sdao = new StudyDAO(sm.getDataSource());
ArrayList studies = udao.findStudyByUser(ub.getName(), (ArrayList) sdao.findAll());
request.setAttribute("siteRoleMap", Role.siteRoleMap);
request.setAttribute("studyRoleMap", Role.studyRoleMap);
if (request.getAttribute("label") != null) {
String label = (String) request.getAttribute("label");
if (label.length() > 0) {
request.setAttribute("label", label);
}
}
ArrayList validStudies = new ArrayList();
for (int i = 0; i < studies.size(); i++) {
StudyUserRoleBean sr = (StudyUserRoleBean) studies.get(i);
StudyBean study = (StudyBean) sdao.findByPK(sr.getStudyId());
if (study != null && study.getStatus().equals(Status.PENDING)) {
sr.setStatus(study.getStatus());
}
validStudies.add(sr);
}
if (StringUtil.isBlank(action)) {
request.setAttribute("studies", validStudies);
forwardPage(Page.CHANGE_STUDY);
} else {
if ("confirm".equalsIgnoreCase(action)) {
logger.info("confirm");
confirmChangeStudy(studies);
} else if ("submit".equalsIgnoreCase(action)) {
logger.info("submit");
changeStudy();
}
}
}
use of org.akaza.openclinica.bean.login.StudyUserRoleBean in project OpenClinica by OpenClinica.
the class StudyModuleController method mayProceed.
private boolean mayProceed(HttpServletRequest request) {
StudyUserRoleBean currentRole = (StudyUserRoleBean) request.getSession().getAttribute("userRole");
Role r = currentRole.getRole();
if (r.equals(Role.ADMIN) || r.equals(Role.STUDYDIRECTOR) || r.equals(Role.COORDINATOR)) {
return true;
}
return false;
}
use of org.akaza.openclinica.bean.login.StudyUserRoleBean in project OpenClinica by OpenClinica.
the class RestODMFilter method checkAuth.
private Boolean checkAuth(UserAccountBean userBean) {
Boolean auth = false;
ArrayList userRoles = userBean.getRoles();
for (int i = 0; (i < userRoles.size() && auth == false); i++) {
StudyUserRoleBean studyRole = (StudyUserRoleBean) userRoles.get(i);
if (studyRole.getRole().equals(Role.ADMIN) || studyRole.getRole().equals(Role.COORDINATOR) || studyRole.getRole().equals(Role.STUDYDIRECTOR)) {
auth = true;
}
}
return auth;
}
Aggregations