use of org.akaza.openclinica.dao.login.UserAccountDAO 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.dao.login.UserAccountDAO in project OpenClinica by OpenClinica.
the class CreateStudyServlet method confirmStudy1.
/**
* Validates the first section of study and save it into study bean
*
* @param request
* @param response
* @throws Exception
*/
private void confirmStudy1() throws Exception {
Validator v = new Validator(request);
FormProcessor fp = new FormProcessor(request);
v.addValidation("name", Validator.NO_BLANKS);
v.addValidation("uniqueProId", Validator.NO_BLANKS);
v.addValidation("description", Validator.NO_BLANKS);
v.addValidation("prinInvestigator", Validator.NO_BLANKS);
v.addValidation("sponsor", Validator.NO_BLANKS);
v.addValidation("secondProId", Validator.LENGTH_NUMERIC_COMPARISON, NumericComparisonOperator.LESS_THAN_OR_EQUAL_TO, 255);
v.addValidation("collaborators", Validator.LENGTH_NUMERIC_COMPARISON, NumericComparisonOperator.LESS_THAN_OR_EQUAL_TO, 1000);
v.addValidation("protocolDescription", Validator.LENGTH_NUMERIC_COMPARISON, NumericComparisonOperator.LESS_THAN_OR_EQUAL_TO, 1000);
errors = v.validate();
// check to see if name and uniqueProId are unique, tbh
StudyDAO studyDAO = new StudyDAO(sm.getDataSource());
ArrayList<StudyBean> allStudies = (ArrayList<StudyBean>) studyDAO.findAll();
for (StudyBean thisBean : allStudies) {
if (fp.getString("name").trim().equals(thisBean.getName())) {
MessageFormat mf = new MessageFormat("");
mf.applyPattern(respage.getString("brief_title_existed"));
Object[] arguments = { fp.getString("name").trim() };
Validator.addError(errors, "name", mf.format(arguments));
}
if (fp.getString("uniqueProId").trim().equals(thisBean.getIdentifier())) {
Validator.addError(errors, "uniqueProId", resexception.getString("unique_protocol_id_existed"));
}
}
if (fp.getString("name").trim().length() > 100) {
Validator.addError(errors, "name", resexception.getString("maximum_lenght_name_100"));
}
if (fp.getString("uniqueProId").trim().length() > 30) {
Validator.addError(errors, "uniqueProId", resexception.getString("maximum_lenght_unique_protocol_30"));
}
if (fp.getString("description").trim().length() > 255) {
Validator.addError(errors, "description", resexception.getString("maximum_lenght_brief_summary_255"));
}
if (fp.getString("prinInvestigator").trim().length() > 255) {
Validator.addError(errors, "prinInvestigator", resexception.getString("maximum_lenght_principal_investigator_255"));
}
if (fp.getString("sponsor").trim().length() > 255) {
Validator.addError(errors, "sponsor", resexception.getString("maximum_lenght_sponsor_255"));
}
if (fp.getString("officialTitle").trim().length() > 255) {
Validator.addError(errors, "officialTitle", resexception.getString("maximum_lenght_official_title_255"));
}
StudyBean studyBean = createStudyBean();
if (errors.isEmpty()) {
logger.info("no errors in the first section");
request.setAttribute("studyPhaseMap", studyPhaseMap);
request.setAttribute("statuses", Status.toActiveArrayList());
logger.info("setting arrays to request, size of list: " + Status.toArrayList().size());
if (request.getParameter("Save") != null && request.getParameter("Save").length() > 0) {
StudyDAO sdao = new StudyDAO(sm.getDataSource());
studyBean.setOwner(ub);
studyBean.setCreatedDate(new Date());
studyBean.setStatus(Status.PENDING);
studyBean = (StudyBean) sdao.create(studyBean);
StudyBean newstudyBean = (StudyBean) sdao.findByName(studyBean.getName());
UserAccountDAO udao = new UserAccountDAO(sm.getDataSource());
String selectedUserIdStr = fp.getString("selectedUser");
int selectedUserId = 0;
if (selectedUserIdStr != null && selectedUserIdStr.length() > 0) {
selectedUserId = Integer.parseInt(fp.getString("selectedUser"));
}
if (selectedUserId > 0) {
UserAccountBean user = (UserAccountBean) udao.findByPK(selectedUserId);
StudyUserRoleBean sub = new StudyUserRoleBean();
sub.setRole(Role.COORDINATOR);
sub.setStudyId(newstudyBean.getId());
sub.setStatus(Status.AVAILABLE);
sub.setOwner(ub);
udao.createStudyUserRole(user, sub);
if (ub.getId() != selectedUserId) {
sub = new StudyUserRoleBean();
sub.setRole(Role.COORDINATOR);
sub.setStudyId(newstudyBean.getId());
sub.setStatus(Status.AVAILABLE);
sub.setOwner(ub);
udao.createStudyUserRole(ub, sub);
}
} else {
StudyUserRoleBean sub = new StudyUserRoleBean();
sub.setRole(Role.COORDINATOR);
sub.setStudyId(newstudyBean.getId());
sub.setStatus(Status.AVAILABLE);
sub.setOwner(ub);
udao.createStudyUserRole(ub, sub);
}
// response.sendRedirect(request.getContextPath() +
// Page.MANAGE_STUDY_MODULE);
addPageMessage(respage.getString("the_new_study_created_succesfully_current"));
forwardPage(Page.STUDY_LIST_SERVLET);
} else {
session.setAttribute("newStudy", studyBean);
forwardPage(Page.CREATE_STUDY2);
}
} else {
session.setAttribute("newStudy", studyBean);
logger.info("has validation errors in the first section");
request.setAttribute("formMessages", errors);
// request.setAttribute("facRecruitStatusMap", facRecruitStatusMap);
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.dao.login.UserAccountDAO 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.dao.login.UserAccountDAO 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());
}
if (study != null && study.getStatus().equals(Status.DELETED)) {
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");
// pull out/update the roles and privs here
ArrayList userRoleBeans = (ArrayList) udao.findAllRolesByUserName(ub.getName());
ub.setRoles(userRoleBeans);
confirmChangeStudy(studies);
} else if ("submit".equalsIgnoreCase(action)) {
logger.info("submit");
changeStudy();
}
}
}
use of org.akaza.openclinica.dao.login.UserAccountDAO in project OpenClinica by OpenClinica.
the class ChangeStudyServlet method changeStudy.
private void changeStudy() throws Exception {
Validator v = new Validator(request);
FormProcessor fp = new FormProcessor(request);
int studyId = fp.getInt("studyId");
int prevStudyId = currentStudy.getId();
StudyDAO sdao = new StudyDAO(sm.getDataSource());
StudyBean current = (StudyBean) sdao.findByPK(studyId);
// reset study parameters -jxu 02/09/2007
StudyParameterValueDAO spvdao = new StudyParameterValueDAO(sm.getDataSource());
ArrayList studyParameters = spvdao.findParamConfigByStudy(current);
current.setStudyParameters(studyParameters);
int parentStudyId = currentStudy.getParentStudyId() > 0 ? currentStudy.getParentStudyId() : currentStudy.getId();
StudyParameterValueBean parentSPV = spvdao.findByHandleAndStudy(parentStudyId, "subjectIdGeneration");
current.getStudyParameterConfig().setSubjectIdGeneration(parentSPV.getValue());
String idSetting = current.getStudyParameterConfig().getSubjectIdGeneration();
if (idSetting.equals("auto editable") || idSetting.equals("auto non-editable")) {
int nextLabel = this.getStudySubjectDAO().findTheGreatestLabel() + 1;
request.setAttribute("label", new Integer(nextLabel).toString());
}
StudyConfigService scs = new StudyConfigService(sm.getDataSource());
if (current.getParentStudyId() <= 0) {
// top study
scs.setParametersForStudy(current);
} else {
// YW <<
if (current.getParentStudyId() > 0) {
current.setParentStudyName(((StudyBean) sdao.findByPK(current.getParentStudyId())).getName());
}
// YW 06-12-2007>>
scs.setParametersForSite(current);
}
if (current.getStatus().equals(Status.DELETED) || current.getStatus().equals(Status.AUTO_DELETED)) {
session.removeAttribute("studyWithRole");
addPageMessage(restext.getString("study_choosed_removed_restore_first"));
} else {
session.setAttribute("study", current);
currentStudy = current;
// change user's active study id
UserAccountDAO udao = new UserAccountDAO(sm.getDataSource());
ub.setActiveStudyId(current.getId());
ub.setUpdater(ub);
ub.setUpdatedDate(new java.util.Date());
udao.update(ub);
if (current.getParentStudyId() > 0) {
/*
* The Role decription will be set depending on whether the user
* logged in at study lever or site level. issue-2422
*/
List roles = Role.toArrayList();
for (Iterator it = roles.iterator(); it.hasNext(); ) {
Role role = (Role) it.next();
switch(role.getId()) {
case 2:
role.setDescription("site_Study_Coordinator");
break;
case 3:
role.setDescription("site_Study_Director");
break;
case 4:
role.setDescription("site_investigator");
break;
case 5:
role.setDescription("site_Data_Entry_Person");
break;
case 6:
role.setDescription("site_monitor");
break;
case 7:
role.setDescription("site_Data_Entry_Person2");
break;
default:
}
}
} else {
/*
* If the current study is a site, we will change the role
* description. issue-2422
*/
List roles = Role.toArrayList();
for (Iterator it = roles.iterator(); it.hasNext(); ) {
Role role = (Role) it.next();
switch(role.getId()) {
case 2:
role.setDescription("Study_Coordinator");
break;
case 3:
role.setDescription("Study_Director");
break;
case 4:
role.setDescription("investigator");
break;
case 5:
role.setDescription("Data_Entry_Person");
break;
case 6:
role.setDescription("monitor");
break;
default:
}
}
}
currentRole = (StudyUserRoleBean) session.getAttribute("studyWithRole");
session.setAttribute("userRole", currentRole);
session.removeAttribute("studyWithRole");
addPageMessage(restext.getString("current_study_changed_succesfully"));
}
ub.incNumVisitsToMainMenu();
// YW 2-18-2008, if study has been really changed <<
if (prevStudyId != studyId) {
session.removeAttribute("eventsForCreateDataset");
session.setAttribute("tableFacadeRestore", "false");
}
request.setAttribute("studyJustChanged", "yes");
// YW >>
// Integer assignedDiscrepancies = getDiscrepancyNoteDAO().countAllItemDataByStudyAndUser(currentStudy, ub);
Integer assignedDiscrepancies = getDiscrepancyNoteDAO().getViewNotesCountWithFilter(" AND dn.assigned_user_id =" + ub.getId() + " AND (dn.resolution_status_id=1 OR dn.resolution_status_id=2 OR dn.resolution_status_id=3)", currentStudy);
request.setAttribute("assignedDiscrepancies", assignedDiscrepancies == null ? 0 : assignedDiscrepancies);
if (currentRole.isInvestigator() || currentRole.isResearchAssistant() || currentRole.isResearchAssistant2()) {
setupListStudySubjectTable();
}
if (currentRole.isMonitor()) {
setupSubjectSDVTable();
} else if (currentRole.isCoordinator() || currentRole.isDirector()) {
if (currentStudy.getStatus().isPending()) {
response.sendRedirect(request.getContextPath() + Page.MANAGE_STUDY_MODULE.getFileName());
return;
}
setupStudySiteStatisticsTable();
setupSubjectEventStatusStatisticsTable();
setupStudySubjectStatusStatisticsTable();
if (currentStudy.getParentStudyId() == 0) {
setupStudyStatisticsTable();
}
}
forwardPage(Page.MENU);
}
Aggregations