use of org.akaza.openclinica.bean.login.StudyUserRoleBean in project OpenClinica by OpenClinica.
the class UserAccountDAO method create.
@Override
public EntityBean create(EntityBean eb) {
UserAccountBean uab = (UserAccountBean) eb;
HashMap variables = new HashMap();
int id = getNextPK();
variables.put(new Integer(1), new Integer(id));
variables.put(new Integer(2), uab.getName());
variables.put(new Integer(3), uab.getPasswd());
variables.put(new Integer(4), uab.getFirstName());
variables.put(new Integer(5), uab.getLastName());
variables.put(new Integer(6), uab.getEmail());
variables.put(new Integer(7), new Integer(uab.getActiveStudyId()));
variables.put(new Integer(8), uab.getInstitutionalAffiliation());
variables.put(new Integer(9), new Integer(uab.getStatus().getId()));
variables.put(new Integer(10), new Integer(uab.getOwnerId()));
variables.put(new Integer(11), uab.getPasswdChallengeQuestion());
variables.put(new Integer(12), uab.getPasswdChallengeAnswer());
variables.put(new Integer(13), uab.getPhone());
if (uab.isTechAdmin()) {
variables.put(new Integer(14), new Integer(UserType.TECHADMIN.getId()));
} else if (uab.isSysAdmin()) {
variables.put(new Integer(14), new Integer(UserType.SYSADMIN.getId()));
} else {
variables.put(new Integer(14), new Integer(UserType.USER.getId()));
}
variables.put(new Integer(15), uab.getRunWebservices());
variables.put(new Integer(16), uab.getAccessCode());
variables.put(new Integer(17), uab.isEnableApiKey());
variables.put(new Integer(18), uab.getApiKey());
boolean success = true;
this.execute(digester.getQuery("insert"), variables);
success = success && isQuerySuccessful();
setSysAdminRole(uab, true);
ArrayList userRoles = uab.getRoles();
for (int i = 0; i < userRoles.size(); i++) {
StudyUserRoleBean studyRole = (StudyUserRoleBean) userRoles.get(i);
if (studyRole.equals(Role.ADMIN)) {
continue;
}
createStudyUserRole(uab, studyRole);
success = success && isQuerySuccessful();
}
if (success) {
uab.setId(id);
}
return uab;
}
use of org.akaza.openclinica.bean.login.StudyUserRoleBean in project OpenClinica by OpenClinica.
the class SubjectTransferValidator method validate.
public void validate(Object obj, Errors e) {
SubjectTransferBean subjectTransferBean = (SubjectTransferBean) obj;
StudyBean study = getStudyDAO().findByUniqueIdentifier(subjectTransferBean.getStudyOid());
if (study == null) {
e.reject("subjectTransferValidator.study_does_not_exist", new Object[] { subjectTransferBean.getStudyOid() }, "Study identifier you specified " + subjectTransferBean.getStudyOid() + " does not correspond to a valid study.");
return;
}
UserAccountBean ua = subjectTransferBean.getOwner();
StudyUserRoleBean role = ua.getRoleByStudy(study);
if (role.getId() == 0 || role.getRole().equals(Role.MONITOR)) {
e.reject("subjectTransferValidator.insufficient_permissions", "You do not have sufficient privileges to proceed with this operation.");
return;
}
if (subjectTransferBean.getSiteIdentifier() != null) {
study = getStudyDAO().findSiteByUniqueIdentifier(subjectTransferBean.getStudyOid(), subjectTransferBean.getSiteIdentifier());
}
subjectTransferBean.setStudy(study);
if (study == null) {
e.reject("subjectTransferValidator.site_does_not_exist", new Object[] { subjectTransferBean.getSiteIdentifier() }, "Site identifier you specified does not correspond to a valid site.");
return;
}
int handleStudyId = study.getParentStudyId() > 0 ? study.getParentStudyId() : study.getId();
StudyParameterValueBean studyParameter = getStudyParameterValueDAO().findByHandleAndStudy(handleStudyId, "subjectPersonIdRequired");
String personId = subjectTransferBean.getPersonId();
if ("required".equals(studyParameter.getValue()) && (personId == null || personId.length() < 1)) {
e.reject("subjectTransferValidator.personId_required", new Object[] { study.getName() }, "personId is required for the study: " + study.getName());
return;
}
if (personId != null && personId.length() > 255) {
e.reject("subjectTransferValidator.personId_invalid_length", new Object[] { personId }, "personId: " + personId + " cannot be longer than 255 characters.");
return;
}
String idSetting = "";
StudyParameterValueBean subjectIdGenerationParameter = getStudyParameterValueDAO().findByHandleAndStudy(handleStudyId, "subjectIdGeneration");
idSetting = subjectIdGenerationParameter.getValue();
if (idSetting.equals("auto editable") || idSetting.equals("auto non-editable")) {
int nextLabel = getStudySubjectDAO().findTheGreatestLabel() + 1;
subjectTransferBean.setStudySubjectId(new Integer(nextLabel).toString());
}
String studySubjectId = subjectTransferBean.getStudySubjectId();
if (studySubjectId == null || studySubjectId.length() < 1) {
e.reject("subjectTransferValidator.studySubjectId_required");
return;
} else if (studySubjectId.length() > 30) {
e.reject("subjectTransferValidator.studySubjectId_invalid_length", new Object[] { studySubjectId }, "studySubjectId: " + studySubjectId + " cannot be longer than 30 characters.");
return;
}
String secondaryId = subjectTransferBean.getSecondaryId();
if (secondaryId != null && secondaryId.length() > 30) {
e.reject("subjectTransferValidator.secondaryId_invalid_length", new Object[] { secondaryId }, "secondaryId: " + secondaryId + " cannot be longer than 30 characters.");
return;
}
String gender = subjectTransferBean.getGender() + "";
studyParameter = getStudyParameterValueDAO().findByHandleAndStudy(handleStudyId, "genderRequired");
if ("true".equals(studyParameter.getValue()) && (gender == null || gender.length() < 1)) {
e.reject("subjectTransferValidator.gender_required", new Object[] { study.getName() }, "Gender is required for the study: " + study.getName());
return;
}
if (!"m".equals(gender) && !"f".equals(gender)) {
e.reject("subjectTransferValidator.gender_is_m_or_f");
//e.reject("subjectTransferValidator.gender_required", new Object[] { study.getName() }, "Gender is required to be 'm' or 'f'");
return;
}
Date dateOfBirth = subjectTransferBean.getDateOfBirth();
String yearOfBirth = subjectTransferBean.getYearOfBirth();
studyParameter = getStudyParameterValueDAO().findByHandleAndStudy(handleStudyId, "collectDob");
if ("1".equals(studyParameter.getValue()) && (dateOfBirth == null)) {
e.reject("subjectTransferValidator.dateOfBirth_required", new Object[] { study.getName() }, "Date of birth is required for the study " + study.getName());
return;
} else if ("2".equals(studyParameter.getValue()) && (yearOfBirth == null)) {
e.reject("subjectTransferValidator.yearOfBirth_required", new Object[] { study.getName() }, "Year of birth is required for the study " + study.getName());
return;
} else if ("2".equals(studyParameter.getValue()) && (yearOfBirth != null)) {
try {
SimpleDateFormat sdf = new SimpleDateFormat("yyyy");
subjectTransferBean.setDateOfBirth(sdf.parse(subjectTransferBean.getYearOfBirth()));
} catch (ParseException xe) {
e.reject("subjectTransferValidator.yearOfBirth_invalid", new Object[] { yearOfBirth }, "Year of birth: " + yearOfBirth + " is not valid");
return;
}
}
Date enrollmentDate = subjectTransferBean.getEnrollmentDate();
if (enrollmentDate == null) {
e.reject("subjectTransferValidator.enrollmentDate_required");
return;
} else {
if ((new Date()).compareTo(enrollmentDate) < 0) {
e.reject("subjectTransferValidator.enrollmentDate_should_be_in_past");
return;
}
}
}
use of org.akaza.openclinica.bean.login.StudyUserRoleBean 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.login.StudyUserRoleBean in project OpenClinica by OpenClinica.
the class CreateUserAccountServlet method addActiveStudyRole.
private UserAccountBean addActiveStudyRole(UserAccountBean createdUserAccountBean, int studyId, Role r) {
createdUserAccountBean.setActiveStudyId(studyId);
StudyUserRoleBean activeStudyRole = new StudyUserRoleBean();
activeStudyRole.setStudyId(studyId);
activeStudyRole.setRoleName(r.getName());
activeStudyRole.setStatus(Status.AVAILABLE);
activeStudyRole.setOwner(ub);
createdUserAccountBean.addRole(activeStudyRole);
return createdUserAccountBean;
}
use of org.akaza.openclinica.bean.login.StudyUserRoleBean 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);
}
}
}
Aggregations