use of org.akaza.openclinica.bean.login.UserAccountBean in project OpenClinica by OpenClinica.
the class DeleteUserServlet method processRequest.
@Override
protected void processRequest() throws Exception {
UserAccountDAO udao = new UserAccountDAO(sm.getDataSource());
FormProcessor fp = new FormProcessor(request);
int userId = fp.getInt(ARG_USERID);
int action = fp.getInt(ARG_ACTION);
UserAccountBean u = (UserAccountBean) udao.findByPK(userId);
String message;
if (!u.isActive()) {
message = respage.getString("the_specified_user_not_exits");
} else if (!EntityAction.contains(action)) {
message = respage.getString("the_specified_action_on_the_user_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 {
EntityAction desiredAction = EntityAction.get(action);
u.setUpdater(ub);
if (desiredAction.equals(EntityAction.DELETE)) {
udao.delete(u);
if (udao.isQuerySuccessful()) {
message = respage.getString("the_user_has_been_removed_successfully");
// YW 07-31-2007 << for feature that deletion doesn't need
// email the deleted user.
/*
* //YW 07-26-2007 << catch exception (eg. timeout) and
* inform users. try { sendDeleteEmail(u); } catch
* (Exception e) { message += " However, there has been an
* error sending the user an email regarding this
* deletion."; }
*/
// YW >>
} else {
message = respage.getString("the_user_could_not_be_deleted_due_database_error");
}
} else {
SecurityManager sm = (SecurityManager) SpringServletAccess.getApplicationContext(context).getBean("securityManager");
String password = sm.genPassword();
String passwordHash = sm.encrytPassword(password, getUserDetails());
if (!u.isLdapUser()) {
u.setPasswd(passwordHash);
u.setPasswdTimestamp(null);
}
udao.restore(u);
if (udao.isQuerySuccessful()) {
message = respage.getString("the_user_has_been_restored");
try {
if (!u.isLdapUser()) {
sendRestoreEmail(u, password);
}
} catch (Exception e) {
message += respage.getString("however_was_error_sending_user_email_regarding");
}
} else {
message = respage.getString("the_user_could_not_be_deleted_due_database_error");
}
}
}
addPageMessage(message);
forwardPage(Page.LIST_USER_ACCOUNTS_SERVLET);
}
use of org.akaza.openclinica.bean.login.UserAccountBean in project OpenClinica by OpenClinica.
the class SetUserRoleServlet method processRequest.
@Override
public void processRequest() throws Exception {
UserAccountDAO udao = new UserAccountDAO(sm.getDataSource());
StudyDAO sdao = new StudyDAO(sm.getDataSource());
FormProcessor fp = new FormProcessor(request);
int userId = fp.getInt("userId");
if (userId == 0) {
addPageMessage(respage.getString("please_choose_a_user_to_set_role_for"));
forwardPage(Page.LIST_USER_ACCOUNTS_SERVLET);
} else {
String action = request.getParameter("action");
UserAccountBean user = (UserAccountBean) udao.findByPK(userId);
ArrayList studies = (ArrayList) sdao.findAll();
ArrayList studiesHaveRole = (ArrayList) sdao.findAllByUser(user.getName());
studies.removeAll(studiesHaveRole);
HashSet<StudyBean> studiesNotHaveRole = new HashSet<StudyBean>();
HashSet<StudyBean> sitesNotHaveRole = new HashSet<StudyBean>();
for (int i = 0; i < studies.size(); i++) {
StudyBean study1 = (StudyBean) studies.get(i);
// TODO: implement equal() according to id
boolean hasStudy = false;
for (int j = 0; j < studiesHaveRole.size(); j++) {
StudyBean study2 = (StudyBean) studiesHaveRole.get(j);
if (study2.getId() == study1.getId()) {
hasStudy = true;
break;
}
}
if (!hasStudy) {
// YW 11-19-2007 <<
if (study1.getParentStudyId() > 0) {
sitesNotHaveRole.add(study1);
} else {
studiesNotHaveRole.add(study1);
}
// YW >>
}
}
Map roleMap = new LinkedHashMap();
for (Iterator it = getRoles().iterator(); it.hasNext(); ) {
Role role = (Role) it.next();
// I added the below if statement , to exclude displaying on study level the newly added 'ReseachAssisstant2' role by default.
if (role.getId() != 7)
roleMap.put(role.getId(), role.getDescription());
}
Boolean changeRoles = request.getParameter("changeRoles") == null ? false : Boolean.parseBoolean(request.getParameter("changeRoles"));
int studyId = fp.getInt("studyId");
if (changeRoles) {
StudyBean study = (StudyBean) sdao.findByPK(studyId);
roleMap = new LinkedHashMap();
ResourceBundle resterm = org.akaza.openclinica.i18n.util.ResourceBundleProvider.getTermsBundle();
if (study.getParentStudyId() > 0) {
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:
}
}
} else {
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 {
if (currentStudy.getParentStudyId() > 0) {
roleMap.remove(Role.COORDINATOR.getId());
roleMap.remove(Role.STUDYDIRECTOR.getId());
}
}
request.setAttribute("roles", roleMap);
request.setAttribute("studyId", studyId);
if ("confirm".equalsIgnoreCase(action) || changeRoles) {
// YW 11-19-2007 << re-order studiesNotHaveRole so that sites
// under their studies;
ArrayList finalStudiesNotHaveRole = new ArrayList();
Iterator iter_study = studiesNotHaveRole.iterator();
while (iter_study.hasNext()) {
StudyBean s = (StudyBean) iter_study.next();
finalStudiesNotHaveRole.add(s);
Iterator iter_site = sitesNotHaveRole.iterator();
while (iter_site.hasNext()) {
StudyBean site = (StudyBean) iter_site.next();
if (site.getParentStudyId() == s.getId()) {
finalStudiesNotHaveRole.add(site);
}
}
}
// YW >>
request.setAttribute("user", user);
request.setAttribute("studies", finalStudiesNotHaveRole);
StudyUserRoleBean uRole = new StudyUserRoleBean();
uRole.setFirstName(user.getFirstName());
uRole.setLastName(user.getLastName());
uRole.setUserName(user.getName());
request.setAttribute("uRole", uRole);
// ArrayList roles = Role.toArrayList();
// roles.remove(Role.ADMIN); // admin is not a user role, only used for tomcat
// if (currentStudy.getParentStudyId() > 0) {
// roles.remove(Role.COORDINATOR);
// roles.remove(Role.STUDYDIRECTOR);
// }
// request.setAttribute("roles", roles);
forwardPage(Page.SET_USER_ROLE);
} else {
// set role
String userName = fp.getString("name");
studyId = fp.getInt("studyId");
StudyBean userStudy = (StudyBean) sdao.findByPK(studyId);
int roleId = fp.getInt("roleId");
// new user role
StudyUserRoleBean sur = new StudyUserRoleBean();
sur.setName(userName);
sur.setRole(Role.get(roleId));
sur.setStudyId(studyId);
sur.setStudyName(userStudy.getName());
sur.setStatus(Status.AVAILABLE);
sur.setOwner(ub);
sur.setCreatedDate(new Date());
if (studyId > 0) {
udao.createStudyUserRole(user, sur);
addPageMessage(user.getFirstName() + " " + user.getLastName() + " (" + resword.getString("username") + ": " + user.getName() + ") " + respage.getString("has_been_granted_the_role") + " \"" + sur.getRole().getDescription() + "\" " + respage.getString("in_the_study_site") + " " + userStudy.getName() + ".");
}
ArrayList<String> pMessage = (ArrayList<String>) request.getAttribute(SecureController.PAGE_MESSAGE);
String url = response.encodeRedirectURL("ListUserAccounts" + "?alertmessage=" + URLEncoder.encode(pMessage.get(0), "UTF-8"));
response.sendRedirect(url);
// forwardPage(Page.LIST_USER_ACCOUNTS_SERVLET);
}
}
}
use of org.akaza.openclinica.bean.login.UserAccountBean in project OpenClinica by OpenClinica.
the class ListSubjectTableFactory method setDataAndLimitVariables.
@SuppressWarnings("unchecked")
@Override
public void setDataAndLimitVariables(TableFacade tableFacade) {
// initialize i18n
resword = ResourceBundleProvider.getWordsBundle(getLocale());
resformat = ResourceBundleProvider.getFormatBundle(getLocale());
Limit limit = tableFacade.getLimit();
ListSubjectFilter listSubjectFilter = getListSubjectFilter(limit);
if (!limit.isComplete()) {
Integer totalRows = getSubjectDao().getCountWithFilter(listSubjectFilter, getCurrentStudy());
if (totalRows == null) {
totalRows = 0;
}
tableFacade.setTotalRows(totalRows.intValue());
}
ListSubjectSort listSubjectSort = getListSubjectSort(limit);
int rowStart = limit.getRowSelect().getRowStart();
int rowEnd = limit.getRowSelect().getRowEnd();
Collection<SubjectBean> items = getSubjectDao().getWithFilterAndSort(getCurrentStudy(), listSubjectFilter, listSubjectSort, rowStart, rowEnd);
Collection<HashMap<Object, Object>> theItems = new ArrayList<HashMap<Object, Object>>();
for (SubjectBean subject : items) {
UserAccountBean owner = (UserAccountBean) getUserAccountDao().findByPK(subject.getOwnerId());
UserAccountBean updater = subject.getUpdaterId() == 0 ? null : (UserAccountBean) getUserAccountDao().findByPK(subject.getUpdaterId());
HashMap<Object, Object> h = new HashMap<Object, Object>();
String studySubjectIdAndStudy = "";
List<StudySubjectBean> studySubjects = getStudySubjectDao().findAllBySubjectId(subject.getId());
for (StudySubjectBean studySubjectBean : studySubjects) {
StudyBean study = (StudyBean) getStudyDao().findByPK(studySubjectBean.getStudyId());
studySubjectIdAndStudy += studySubjectIdAndStudy.length() == 0 ? "" : ",";
studySubjectIdAndStudy += study.getIdentifier() + "-" + studySubjectBean.getLabel();
}
h.put("studySubjectIdAndStudy", studySubjectIdAndStudy);
h.put("subject", subject);
h.put("subject.uniqueIdentifier", subject.getUniqueIdentifier());
h.put("subject.gender", subject.getGender());
Date tempDate = subject.getCreatedDate();
String tempDateStr = tempDate == null ? "" : I18nFormatUtil.getDateFormat(getLocale()).format(tempDate);
h.put("subject.createdDate", tempDateStr);
h.put("subject.owner", owner);
tempDate = subject.getUpdatedDate();
tempDateStr = tempDate == null ? "" : I18nFormatUtil.getDateFormat(getLocale()).format(tempDate);
h.put("subject.updatedDate", tempDateStr);
h.put("subject.updater", updater);
h.put("subject.status", subject.getStatus());
theItems.add(h);
}
tableFacade.setItems(theItems);
}
use of org.akaza.openclinica.bean.login.UserAccountBean in project OpenClinica by OpenClinica.
the class ListUserAccountsServlet method setStudyNamesInStudyUserRoles.
/**
* For each user, for each study user role, set the study user role's
* studyName property.
*
* @param users
* The users to display in the table of users. Each element is a
* UserAccountBean.
*/
private void setStudyNamesInStudyUserRoles(ArrayList users) {
StudyDAO sdao = new StudyDAO(sm.getDataSource());
ArrayList allStudies = (ArrayList) sdao.findAll();
HashMap studiesById = new HashMap();
int i;
for (i = 0; i < allStudies.size(); i++) {
StudyBean sb = (StudyBean) allStudies.get(i);
studiesById.put(new Integer(sb.getId()), sb);
}
for (i = 0; i < users.size(); i++) {
UserAccountBean u = (UserAccountBean) users.get(i);
ArrayList roles = u.getRoles();
for (int j = 0; j < roles.size(); j++) {
StudyUserRoleBean surb = (StudyUserRoleBean) roles.get(j);
StudyBean sb = (StudyBean) studiesById.get(new Integer(surb.getStudyId()));
if (sb != null) {
surb.setStudyName(sb.getName());
surb.setParentStudyId(sb.getParentStudyId());
}
roles.set(j, surb);
}
u.setRoles(roles);
users.set(i, u);
}
return;
}
use of org.akaza.openclinica.bean.login.UserAccountBean in project OpenClinica by OpenClinica.
the class ViewUserAccountServlet method getBean.
// public void processRequest(HttpServletRequest request,
// HttpServletResponse response)
// throws OpenClinicaException {
// session = request.getSession();
// session.setMaxInactiveInterval(60 * 60 * 3);
// logger.setLevel(Level.ALL);
// UserAccountBean ub = (UserAccountBean) session.getAttribute("userBean");
// try {
// String userName = request.getRemoteUser();
//
// sm = new SessionManager(ub, userName);
// ub = sm.getUserBean();
// if (logger.isLoggable(Level.INFO)) {
// logger.info("user bean from DB" + ub.getName());
// }
//
// FormProcessor fp = new FormProcessor(request);
// int userId = fp.getInt(ARG_USER_ID);
//
// SQLFactory factory = SQLFactory.getInstance();
// UserAccountDAO udao = new UserAccountDAO(sm.getDataSource());
//
// UserAccountBean user = getBean(udao, userId);
//
// if ((user.getFirstName() != null) && (!user.getFirstName().equals(""))) {
// request.setAttribute("user", user);
// request.setAttribute("message", "");
// }
// else {
// request.setAttribute("user", new UserAccountBean());
// request.setAttribute("message", "The specified user does not exist!");
// }
//
// forwardPage(Page.VIEW_USER_ACCOUNT, request, response);
// } catch (Exception e) {
// e.printStackTrace();
// logger.warn("OpenClinicaException::
// OpenClinica.control.viewUserAccount: " + e.getMessage());
//
// forwardPage(Page.ERROR, request, response);
// }
// }
private UserAccountBean getBean(UserAccountDAO udao, int id) {
UserAccountBean answer = (UserAccountBean) udao.findByPK(id);
StudyDAO sdao = new StudyDAO(sm.getDataSource());
ArrayList roles = answer.getRoles();
for (int i = 0; i < roles.size(); i++) {
StudyUserRoleBean sur = (StudyUserRoleBean) roles.get(i);
StudyBean sb = (StudyBean) sdao.findByPK(sur.getStudyId());
sur.setStudyName(sb.getName());
roles.set(i, sur);
}
answer.setRoles(roles);
return answer;
}
Aggregations