use of org.akaza.openclinica.dao.login.UserAccountDAO in project OpenClinica by OpenClinica.
the class CreateOneDiscrepancyNoteServlet method processRequest.
@Override
protected void processRequest() throws Exception {
FormProcessor fp = new FormProcessor(request);
DiscrepancyNoteDAO dndao = new DiscrepancyNoteDAO(sm.getDataSource());
int eventCRFId = fp.getInt(CreateDiscrepancyNoteServlet.EVENT_CRF_ID);
request.setAttribute(CreateDiscrepancyNoteServlet.EVENT_CRF_ID, new Integer(eventCRFId));
int parentId = fp.getInt(PARENT_ID);
DiscrepancyNoteBean parent = parentId > 0 ? (DiscrepancyNoteBean) dndao.findByPK(parentId) : new DiscrepancyNoteBean();
HashMap<Integer, DiscrepancyNoteBean> boxDNMap = (HashMap<Integer, DiscrepancyNoteBean>) session.getAttribute(BOX_DN_MAP);
boxDNMap = boxDNMap == null ? new HashMap<Integer, DiscrepancyNoteBean>() : boxDNMap;
DiscrepancyNoteBean dn = boxDNMap.size() > 0 && boxDNMap.containsKey(Integer.valueOf(parentId)) ? boxDNMap.get(Integer.valueOf(parentId)) : new DiscrepancyNoteBean();
int entityId = fp.getInt(ENTITY_ID, true);
entityId = entityId > 0 ? entityId : parent.getEntityId();
if (entityId == 0) {
Validator.addError(errors, "newChildAdded" + parentId, respage.getString("note_cannot_be_saved"));
logger.info("entityId is 0. Note saving can not be started.");
}
String entityType = fp.getString(ENTITY_TYPE, true);
FormDiscrepancyNotes noteTree = (FormDiscrepancyNotes) session.getAttribute(AddNewSubjectServlet.FORM_DISCREPANCY_NOTES_NAME);
if (noteTree == null) {
noteTree = new FormDiscrepancyNotes();
}
String ypos = fp.getString("ypos" + parentId);
int refresh = 0;
String field = fp.getString(ENTITY_FIELD, true);
String description = fp.getString("description" + parentId);
int typeId = fp.getInt("typeId" + parentId);
String detailedDes = fp.getString("detailedDes" + parentId);
int resStatusId = fp.getInt(RES_STATUS_ID + parentId);
int assignedUserAccountId = fp.getInt(SUBMITTED_USER_ACCOUNT_ID + parentId);
String viewNoteLink = fp.getString("viewDNLink" + parentId);
viewNoteLink = this.appendPageFileName(viewNoteLink, "fromBox", "1");
Validator v = new Validator(request);
v.addValidation("description" + parentId, Validator.NO_BLANKS);
v.addValidation("description" + parentId, Validator.LENGTH_NUMERIC_COMPARISON, NumericComparisonOperator.LESS_THAN_OR_EQUAL_TO, 255);
v.addValidation("detailedDes" + parentId, Validator.LENGTH_NUMERIC_COMPARISON, NumericComparisonOperator.LESS_THAN_OR_EQUAL_TO, 1000);
v.addValidation("typeId" + parentId, Validator.NO_BLANKS);
HashMap errors = v.validate();
dn.setParentDnId(parentId);
dn.setDescription(description);
dn.setDiscrepancyNoteTypeId(typeId);
dn.setDetailedNotes(detailedDes);
dn.setResolutionStatusId(resStatusId);
if (typeId != DiscrepancyNoteType.ANNOTATION.getId() && typeId != DiscrepancyNoteType.REASON_FOR_CHANGE.getId()) {
dn.setAssignedUserId(assignedUserAccountId);
}
if (DiscrepancyNoteType.ANNOTATION.getId() == dn.getDiscrepancyNoteTypeId()) {
updateStudyEvent(entityType, entityId);
updateStudySubjectStatus(entityType, entityId);
}
if (DiscrepancyNoteType.ANNOTATION.getId() == dn.getDiscrepancyNoteTypeId() || DiscrepancyNoteType.REASON_FOR_CHANGE.getId() == dn.getDiscrepancyNoteTypeId()) {
dn.setResStatus(ResolutionStatus.NOT_APPLICABLE);
dn.setResolutionStatusId(ResolutionStatus.NOT_APPLICABLE.getId());
}
if (DiscrepancyNoteType.FAILEDVAL.getId() == dn.getDiscrepancyNoteTypeId() || DiscrepancyNoteType.QUERY.getId() == dn.getDiscrepancyNoteTypeId()) {
if (ResolutionStatus.NOT_APPLICABLE.getId() == dn.getResolutionStatusId()) {
Validator.addError(errors, RES_STATUS_ID + parentId, restext.getString("not_valid_res_status"));
}
}
if (errors.isEmpty()) {
HashMap<String, ArrayList<String>> results = new HashMap<String, ArrayList<String>>();
ArrayList<String> mess = new ArrayList<String>();
String column = fp.getString(ENTITY_COLUMN, true);
dn.setOwner(ub);
dn.setStudyId(currentStudy.getId());
dn.setEntityId(entityId);
dn.setEntityType(entityType);
dn.setColumn(column);
dn.setField(field);
if (parentId > 0) {
if (dn.getResolutionStatusId() != parent.getResolutionStatusId()) {
parent.setResolutionStatusId(dn.getResolutionStatusId());
dndao.update(parent);
if (!parent.isActive()) {
logger.info("Failed to update resolution status ID for the parent dn ID = " + parentId + ". ");
}
}
if (dn.getAssignedUserId() != parent.getAssignedUserId()) {
parent.setAssignedUserId(dn.getAssignedUserId());
if (parent.getAssignedUserId() > 0) {
dndao.updateAssignedUser(parent);
} else {
dndao.updateAssignedUserToNull(parent);
}
if (!parent.isActive()) {
logger.info("Failed to update assigned user ID for the parent dn ID= " + parentId + ". ");
}
}
} else {
ypos = "0";
}
dn = (DiscrepancyNoteBean) dndao.create(dn);
boolean success = dn.getId() > 0 ? true : false;
if (success) {
refresh = 1;
dndao.createMapping(dn);
success = dndao.isQuerySuccessful();
if (success == false) {
mess.add(restext.getString("failed_create_dn_mapping_for_dnId") + dn.getId() + ". ");
}
noteTree.addNote(eventCRFId + "_" + field, dn);
noteTree.addIdNote(dn.getEntityId(), field);
session.setAttribute(AddNewSubjectServlet.FORM_DISCREPANCY_NOTES_NAME, noteTree);
if (dn.getParentDnId() == 0) {
// see issue 2659 this is a new thread, we will create
// two notes in this case,
// This way one can be the parent that updates as the
// status changes, but one also stays as New.
dn.setParentDnId(dn.getId());
dn = (DiscrepancyNoteBean) dndao.create(dn);
if (dn.getId() > 0) {
dndao.createMapping(dn);
if (!dndao.isQuerySuccessful()) {
mess.add(restext.getString("failed_create_dn_mapping_for_dnId") + dn.getId() + ". ");
}
noteTree.addNote(eventCRFId + "_" + field, dn);
noteTree.addIdNote(dn.getEntityId(), field);
session.setAttribute(AddNewSubjectServlet.FORM_DISCREPANCY_NOTES_NAME, noteTree);
} else {
mess.add(restext.getString("failed_create_child_dn_for_new_parent_dnId") + dn.getId() + ". ");
}
}
} else {
mess.add(restext.getString("failed_create_new_dn") + ". ");
}
if (success) {
if (boxDNMap.size() > 0 && boxDNMap.containsKey(parentId)) {
boxDNMap.remove(parentId);
}
session.removeAttribute(BOX_TO_SHOW);
/*
* Copied from CreateDiscrepancyNoteServlet
* Setting a marker to check
* later while saving administrative edited data. This is needed to
* make sure the system flags error while changing data for items
* which already has a DiscrepanyNote
*/
manageReasonForChangeState(session, eventCRFId + "_" + field);
String email = fp.getString(EMAIL_USER_ACCOUNT + parentId);
if (dn.getAssignedUserId() > 0 && "1".equals(email.trim())) {
logger.info("++++++ found our way here");
// generate email for user here
StringBuffer message = new StringBuffer();
dn = getNoteInfo(dn);
// generate message here
EmailEngine em = new EmailEngine(EmailEngine.getSMTPHost());
UserAccountDAO userAccountDAO = new UserAccountDAO(sm.getDataSource());
ItemDAO itemDAO = new ItemDAO(sm.getDataSource());
ItemDataDAO iddao = new ItemDataDAO(sm.getDataSource());
ItemBean item = new ItemBean();
ItemDataBean itemData = new ItemDataBean();
StudyDAO studyDAO = new StudyDAO(sm.getDataSource());
UserAccountBean assignedUser = (UserAccountBean) userAccountDAO.findByPK(dn.getAssignedUserId());
String alertEmail = assignedUser.getEmail();
message.append(MessageFormat.format(respage.getString("mailDNHeader"), assignedUser.getFirstName(), assignedUser.getLastName()));
message.append("<A HREF='" + SQLInitServlet.getField("sysURL.base") + "ViewNotes?module=submit&listNotes_f_discrepancyNoteBean.user=" + assignedUser.getName() + "&listNotes_f_entityName=" + dn.getEntityName() + "'>" + SQLInitServlet.getField("sysURL.base") + "</A><BR/>");
message.append(respage.getString("you_received_this_from"));
StudyBean study = (StudyBean) studyDAO.findByPK(dn.getStudyId());
if ("itemData".equalsIgnoreCase(entityType)) {
itemData = (ItemDataBean) iddao.findByPK(dn.getEntityId());
item = (ItemBean) itemDAO.findByPK(itemData.getItemId());
}
message.append(respage.getString("email_body_separator"));
message.append(respage.getString("disc_note_info"));
message.append(respage.getString("email_body_separator"));
message.append(MessageFormat.format(respage.getString("mailDNParameters1"), dn.getDescription(), dn.getDetailedNotes(), ub.getName()));
message.append(respage.getString("email_body_separator"));
message.append(respage.getString("entity_information"));
message.append(respage.getString("email_body_separator"));
message.append(MessageFormat.format(respage.getString("mailDNParameters2"), study.getName(), dn.getSubjectName()));
if (!("studySub".equalsIgnoreCase(entityType) || "subject".equalsIgnoreCase(entityType))) {
message.append(MessageFormat.format(respage.getString("mailDNParameters3"), dn.getEventName()));
if (!"studyEvent".equalsIgnoreCase(dn.getEntityType())) {
message.append(MessageFormat.format(respage.getString("mailDNParameters4"), dn.getCrfName()));
if (!"eventCrf".equalsIgnoreCase(dn.getEntityType())) {
message.append(MessageFormat.format(respage.getString("mailDNParameters6"), item.getName()));
}
}
}
message.append(respage.getString("email_body_separator"));
message.append(MessageFormat.format(respage.getString("mailDNThanks"), study.getName()));
message.append(respage.getString("email_body_separator"));
message.append(respage.getString("disclaimer"));
message.append(respage.getString("email_body_separator"));
message.append(respage.getString("email_footer"));
/*
*
*
*
* Please select the link below to view the information
* provided. You may need to login to
* OpenClinica_testbed with your user name and password
* after selecting the link. If you receive a page
* cannot be displayed message, please make sure to
* select the Change Study/Site link in the upper right
* table of the page, select the study referenced above,
* and select the link again.
*
* https://openclinica.s-3.com/OpenClinica_testbed/
* ViewSectionDataEntry ?ecId=117§ionId=142&tabId=2
*/
String emailBodyString = message.toString();
sendEmail(alertEmail.trim(), EmailEngine.getAdminEmail(), MessageFormat.format(respage.getString("mailDNSubject"), study.getName(), dn.getEntityName()), emailBodyString, true, null, null, true);
}
String close = fp.getString("close" + parentId);
// session.setAttribute(CLOSE_WINDOW, "true".equals(close)?"true":"");
if ("true".equals(close)) {
addPageMessage(respage.getString("note_saved_into_db"));
addPageMessage(respage.getString("page_close_automatically"));
forwardPage(Page.ADD_DISCREPANCY_NOTE_SAVE_DONE);
logger.info("Should forwardPage to ADD_DISCREPANCY_NOTE_SAVE_DONE.");
} else {
if (parentId == dn.getParentDnId()) {
mess.add(restext.getString("a_new_child_dn_added"));
results.put("newChildAdded" + parentId, mess);
setInputMessages(results);
} else {
addPageMessage(restext.getString("a_new_dn_thread_added"));
}
}
} else {
session.setAttribute(BOX_TO_SHOW, parentId + "");
}
} else {
setInputMessages(errors);
boxDNMap.put(Integer.valueOf(parentId), dn);
session.setAttribute(BOX_TO_SHOW, parentId + "");
}
session.setAttribute(BOX_DN_MAP, boxDNMap);
viewNoteLink = this.appendPageFileName(viewNoteLink, "refresh", refresh + "");
viewNoteLink = this.appendPageFileName(viewNoteLink, "y", ypos != null && ypos.length() > 0 ? ypos : "0");
getServletContext().getRequestDispatcher(viewNoteLink).forward(request, response);
// forwardPage(Page.setNewPage(viewNoteLink, Page.VIEW_DISCREPANCY_NOTE.getTitle()));
}
use of org.akaza.openclinica.dao.login.UserAccountDAO in project OpenClinica by OpenClinica.
the class CrfEndpoint method getUserAccount.
/**
* Helper Method to get the user account
*
* @return UserAccountBean
*/
private UserAccountBean getUserAccount() {
Object principal = SecurityContextHolder.getContext().getAuthentication().getPrincipal();
String username = null;
if (principal instanceof UserDetails) {
username = ((UserDetails) principal).getUsername();
} else {
username = principal.toString();
}
UserAccountDAO userAccountDao = new UserAccountDAO(dataSource);
return (UserAccountBean) userAccountDao.findByUserName(username);
}
use of org.akaza.openclinica.dao.login.UserAccountDAO in project OpenClinica by OpenClinica.
the class MainMenuServlet method processRequest.
@Override
public void processRequest() throws Exception {
FormProcessor fp = new FormProcessor(request);
ub.incNumVisitsToMainMenu();
session.setAttribute(USER_BEAN_NAME, ub);
request.setAttribute("iconInfoShown", true);
request.setAttribute("closeInfoShowIcons", false);
if (ub == null || ub.getId() == 0) {
// in case database connection is
// broken
forwardPage(Page.MENU, false);
return;
}
StudyDAO sdao = new StudyDAO(sm.getDataSource());
ArrayList studies = null;
long pwdExpireDay = new Long(SQLInitServlet.getField("passwd_expiration_time")).longValue();
Date lastPwdChangeDate = ub.getPasswdTimestamp();
// a flag tells whether users are required to change pwd upon the first
// time log in or pwd expired
int pwdChangeRequired = new Integer(SQLInitServlet.getField("change_passwd_required")).intValue();
// update last visit date to current date
UserAccountDAO udao = new UserAccountDAO(sm.getDataSource());
UserAccountBean ub1 = (UserAccountBean) udao.findByPK(ub.getId());
ub1.setLastVisitDate(new Date(System.currentTimeMillis()));
// have to actually set the above to a timestamp? tbh
ub1.setOwner(ub1);
ub1.setUpdater(ub1);
udao.update(ub1);
// Use study Id in JSPs
request.setAttribute("studyId", currentStudy.getId());
// Event Definition list and Group Class list for add suybject window.
request.setAttribute("allDefsArray", super.getEventDefinitionsByCurrentStudy());
request.setAttribute("studyGroupClasses", super.getStudyGroupClassesByCurrentStudy());
if (ub.isLdapUser()) {
// "Forge" a password change date for LDAP user
lastPwdChangeDate = new Date();
}
System.out.println("is ub a ldapuser??" + ub.isLdapUser());
// @pgawade 18-Sep-2012: fix for issue #14506 (https://issuetracker.openclinica.com/view.php?id=14506#c58197)
if ((lastPwdChangeDate != null) || ((lastPwdChangeDate == null) && (pwdChangeRequired == 0))) {
// not a new user
if (lastPwdChangeDate != null) {
Calendar cal = Calendar.getInstance();
// compute difference between current date and lastPwdChangeDate
long difference = Math.abs(cal.getTime().getTime() - lastPwdChangeDate.getTime());
long days = difference / (1000 * 60 * 60 * 24);
session.setAttribute("passwordExpired", "no");
if (!ub.isLdapUser() && pwdExpireDay > 0 && days >= pwdExpireDay) {
// password expired, need to be changed
System.out.println("here");
studies = (ArrayList) sdao.findAllByUser(ub.getName());
request.setAttribute("studies", studies);
session.setAttribute("userBean1", ub);
addPageMessage(respage.getString("password_expired"));
// YW 06-25-2007 << add the feature that if password is expired,
// have to go through /ResetPassword page
session.setAttribute("passwordExpired", "yes");
if (pwdChangeRequired == 1) {
request.setAttribute("mustChangePass", "yes");
addPageMessage(respage.getString("your_password_has_expired_must_change"));
} else {
request.setAttribute("mustChangePass", "no");
addPageMessage(respage.getString("password_expired") + " " + respage.getString("if_you_do_not_want_change_leave_blank"));
}
forwardPage(Page.RESET_PASSWORD);
// YW >>
}
}
if (ub.getNumVisitsToMainMenu() <= 1) {
if (ub.getLastVisitDate() != null) {
addPageMessage(respage.getString("welcome") + " " + ub.getFirstName() + " " + ub.getLastName() + ". " + respage.getString("last_logged") + " " + local_df.format(ub.getLastVisitDate()) + ". ");
} else {
addPageMessage(respage.getString("welcome") + " " + ub.getFirstName() + " " + ub.getLastName() + ". ");
}
if (currentStudy.getStatus().isLocked()) {
addPageMessage(respage.getString("current_study_locked"));
} else if (currentStudy.getStatus().isFrozen()) {
addPageMessage(respage.getString("current_study_frozen"));
}
}
// //Integer assignedDiscrepancies = getDiscrepancyNoteDAO().countAllItemDataByStudyAndUser(currentStudy, ub);
// when change study will also call the same method, so the logic is consistent
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);
// Yufang code added by Jamuna, to optimize the query on MainMenu
request.setAttribute("assignedDiscrepancies", assignedDiscrepancies == null ? 0 : assignedDiscrepancies);
int parentStudyId = currentStudy.getParentStudyId() > 0 ? currentStudy.getParentStudyId() : currentStudy.getId();
StudyParameterValueDAO spvdao = new StudyParameterValueDAO(sm.getDataSource());
StudyParameterValueBean parentSPV = spvdao.findByHandleAndStudy(parentStudyId, "subjectIdGeneration");
currentStudy.getStudyParameterConfig().setSubjectIdGeneration(parentSPV.getValue());
String idSetting = parentSPV.getValue();
if (idSetting.equals("auto editable") || idSetting.equals("auto non-editable")) {
// Shaoyu Su
// int nextLabel = this.getStudySubjectDAO().findTheGreatestLabel() + 1;
// request.setAttribute("label", new Integer(nextLabel).toString());
request.setAttribute("label", resword.getString("id_generated_Save_Add"));
// @pgawade 27-June-2012 fix for issue 13477: set label to "ID will be generated on Save or Add" in case of auto generated subject id
fp.addPresetValue("label", resword.getString("id_generated_Save_Add"));
}
setPresetValues(fp.getPresetValues());
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);
// }
} else {
// a new user's first log in
studies = (ArrayList) sdao.findAllByUser(ub.getName());
request.setAttribute("studies", studies);
session.setAttribute("userBean1", ub);
if (pwdChangeRequired == 1) {
} else {
forwardPage(Page.MENU);
}
}
}
use of org.akaza.openclinica.dao.login.UserAccountDAO in project OpenClinica by OpenClinica.
the class AuditLogUserServlet method processRequest.
/*
* (non-Javadoc) Assume that we get the user id automatically. We will jump
* from the edit user page if the user is an admin, they can get to see the
* users' log
*
* @see org.akaza.openclinica.control.core.SecureController#processRequest()
*/
@Override
protected void processRequest() throws Exception {
FormProcessor fp = new FormProcessor(request);
int userId = fp.getInt(ARG_USERID);
if (userId == 0) {
Integer userIntId = (Integer) session.getAttribute(ARG_USERID);
userId = userIntId.intValue();
} else {
session.setAttribute(ARG_USERID, new Integer(userId));
}
AuditEventDAO aeDAO = new AuditEventDAO(sm.getDataSource());
ArrayList al = aeDAO.findAllByUserId(userId);
EntityBeanTable table = fp.getEntityBeanTable();
ArrayList allRows = AuditEventRow.generateRowsFromBeans(al);
// String[] columns = { "Date and Time", "Action", "Entity/Operation",
// "Record ID", "Changes and Additions","Other Info" };
// table.setColumns(new ArrayList(Arrays.asList(columns)));
// table.hideColumnLink(4);
// table.hideColumnLink(1);
// table.hideColumnLink(5);
// table.setQuery("AuditLogUser?userLogId="+userId, new HashMap());
String[] columns = { resword.getString("date_and_time"), resword.getString("action_message"), resword.getString("entity_operation"), resword.getString("study_site"), resword.getString("study_subject_ID"), resword.getString("changes_and_additions"), // "Other Info",
resword.getString("actions") };
table.setColumns(new ArrayList(Arrays.asList(columns)));
table.setAscendingSort(false);
table.hideColumnLink(1);
table.hideColumnLink(5);
table.hideColumnLink(6);
// table.hideColumnLink(7);
table.setQuery("AuditLogUser?userLogId=" + userId, new HashMap());
table.setRows(allRows);
table.computeDisplay();
request.setAttribute("table", table);
UserAccountDAO uadao = new UserAccountDAO(sm.getDataSource());
UserAccountBean uabean = (UserAccountBean) uadao.findByPK(userId);
request.setAttribute("auditUserBean", uabean);
forwardPage(Page.AUDIT_LOG_USER);
}
use of org.akaza.openclinica.dao.login.UserAccountDAO in project OpenClinica by OpenClinica.
the class ApiSecurityFilter method doFilterInternal.
@Override
protected void doFilterInternal(HttpServletRequest request, HttpServletResponse response, FilterChain filterChain) throws ServletException, IOException {
System.out.println("Oh look at you triggering API calls i see !!!!!!");
String authHeader = request.getHeader("Authorization");
if (authHeader != null) {
StringTokenizer st = new StringTokenizer(authHeader);
if (st.hasMoreTokens()) {
String basic = st.nextToken();
if (basic.equalsIgnoreCase("Basic")) {
try {
String credentials = new String(Base64.decodeBase64(st.nextToken().getBytes()), "UTF-8");
int p = credentials.indexOf(":");
if (p != -1) {
String _username = credentials.substring(0, p).trim();
String _password = credentials.substring(p + 1).trim();
UserAccountDAO userAccountDAO = new UserAccountDAO(dataSource);
UserAccountBean ub = (UserAccountBean) userAccountDAO.findByApiKey(_username);
if (!_username.equals("") && ub.getId() != 0) {
request.getSession().setAttribute("userBean", ub);
} else {
unauthorized(response, "Bad credentials");
return;
}
} else {
unauthorized(response, "Invalid authentication token");
return;
}
} catch (UnsupportedEncodingException e) {
throw new Error("Couldn't retrieve authentication", e);
}
}
}
} else {
unauthorized(response);
}
filterChain.doFilter(request, response);
}
Aggregations