use of org.akaza.openclinica.dao.login.UserAccountDAO in project OpenClinica by OpenClinica.
the class UpdateJobImportServlet method setUpServlet.
private void setUpServlet(Trigger trigger) throws Exception {
FormProcessor fp2 = new FormProcessor(request);
request.setAttribute(CreateJobImportServlet.JOB_NAME, trigger.getName());
request.setAttribute(CreateJobImportServlet.JOB_DESC, trigger.getDescription());
dataMap = trigger.getJobDataMap();
String contactEmail = dataMap.getString(ImportSpringJob.EMAIL);
logger.debug("found email: " + contactEmail);
int userId = dataMap.getInt(ImportSpringJob.USER_ID);
int hours = dataMap.getInt(CreateJobImportServlet.HOURS);
int minutes = dataMap.getInt(CreateJobImportServlet.MINUTES);
String directory = dataMap.getString(ImportSpringJob.DIRECTORY);
String studyName = dataMap.getString(ImportSpringJob.STUDY_NAME);
request.setAttribute(ImportSpringJob.EMAIL, contactEmail);
request.setAttribute(ImportSpringJob.STUDY_NAME, studyName);
request.setAttribute("filePath", directory);
request.setAttribute("firstFilePath", IMPORT_DIR);
request.setAttribute("hours", new Integer(hours).toString());
request.setAttribute("minutes", new Integer(minutes).toString());
Date jobDate = trigger.getNextFireTime();
UserAccountDAO udao = new UserAccountDAO(sm.getDataSource());
StudyDAO sdao = new StudyDAO(sm.getDataSource());
// ArrayList studies = udao.findStudyByUser(ub.getName(), (ArrayList)
// sdao.findAll());
// request.setAttribute("studies", studies);
ArrayList<StudyBean> all = (ArrayList<StudyBean>) sdao.findAll();
ArrayList<StudyBean> finalList = new ArrayList<StudyBean>();
for (StudyBean sb : all) {
if (!(sb.getParentStudyId() > 0)) {
finalList.add(sb);
// System.out.println("found study name: " + sb.getName());
finalList.addAll(sdao.findAllByParent(sb.getId()));
}
}
// System.out.println("found list of studies: " + finalList.toString());
addEntityList("studies", finalList, respage.getString("a_user_cannot_be_created_no_study_as_active"), Page.ADMIN_SYSTEM);
// tbh >>
// HashMap presetValues = new HashMap();
// Calendar calendar = new GregorianCalendar();
// calendar.setTime(jobDate);
// presetValues.put(CreateJobImportServlet.DATE_START_JOB + "Hour",
// calendar.get(Calendar.HOUR_OF_DAY));
// presetValues.put(CreateJobImportServlet.DATE_START_JOB + "Minute",
// calendar.get(Calendar.MINUTE));
// // TODO this will have to match l10n formatting
// presetValues.put(CreateJobImportServlet.DATE_START_JOB + "Date",
// (calendar.get(Calendar.MONTH) + 1) + "/" +
// calendar.get(Calendar.DATE) + "/"
// + calendar.get(Calendar.YEAR));
// fp2.setPresetValues(presetValues);
// setPresetValues(fp2.getPresetValues());
}
use of org.akaza.openclinica.dao.login.UserAccountDAO in project OpenClinica by OpenClinica.
the class UnLockUserServlet 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);
UserAccountBean u = (UserAccountBean) udao.findByPK(userId);
String message;
if (!u.isActive() || u.getAccountNonLocked()) {
message = respage.getString("the_specified_user_not_exits");
} else {
u.setUpdater(ub);
SecurityManager sm = (SecurityManager) SpringServletAccess.getApplicationContext(context).getBean("securityManager");
String password = sm.genPassword();
if (!u.isLdapUser()) {
String passwordHash = sm.encrytPassword(password, getUserDetails());
u.setPasswd(passwordHash);
}
u.setPasswdTimestamp(null);
u.setAccountNonLocked(Boolean.TRUE);
u.setStatus(Status.AVAILABLE);
u.setLockCounter(0);
udao.update(u);
if (udao.isQuerySuccessful()) {
message = respage.getString("the_user_has_been_unlocked");
try {
if (!u.isLdapUser()) {
sendRestoreEmail(u, password);
}
} catch (Exception e) {
e.printStackTrace();
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.dao.login.UserAccountDAO in project OpenClinica by OpenClinica.
the class EditUserAccountServlet method isApiKeyExist.
public Boolean isApiKeyExist(String uuid) {
UserAccountDAO udao = new UserAccountDAO(sm.getDataSource());
UserAccountBean uBean = (UserAccountBean) udao.findByApiKey(uuid);
if (uBean == null || !uBean.isActive()) {
return false;
} else {
return true;
}
}
use of org.akaza.openclinica.dao.login.UserAccountDAO in project OpenClinica by OpenClinica.
the class EditUserAccountServlet method processRequest.
@Override
protected void processRequest() throws Exception {
FormProcessor fp = new FormProcessor(request);
// because we need to use this in the confirmation and error parts too
ArrayList studies = getAllStudies();
request.setAttribute("studies", studies);
int userId = fp.getInt(ARG_USERID);
UserAccountDAO udao = new UserAccountDAO(sm.getDataSource());
UserAccountBean user = (UserAccountBean) udao.findByPK(userId);
techAdminProtect(user);
int stepNum = fp.getInt(ARG_STEPNUM);
if (!fp.isSubmitted()) {
addEntityList("userTypes", getUserTypes(), respage.getString("the_user_could_not_be_edited_because_no_user_types"), Page.ADMIN_SYSTEM);
loadPresetValuesFromBean(fp, user);
fp.addPresetValue(ARG_STEPNUM, EDIT_STEP);
setPresetValues(fp.getPresetValues());
// addEntityList("userTypes", getUserTypes(),
// "The user could not be edited because there are no user types
// available.",
// Page.ADMIN_SYSTEM);
request.setAttribute("userName", user.getName());
forwardPage(Page.EDIT_ACCOUNT);
} else if (stepNum == EDIT_STEP) {
Validator v = new Validator(request);
v.addValidation(INPUT_FIRST_NAME, Validator.NO_BLANKS);
v.addValidation(INPUT_LAST_NAME, Validator.NO_BLANKS);
v.addValidation(INPUT_FIRST_NAME, Validator.LENGTH_NUMERIC_COMPARISON, NumericComparisonOperator.LESS_THAN_OR_EQUAL_TO, 50);
v.addValidation(INPUT_LAST_NAME, Validator.LENGTH_NUMERIC_COMPARISON, NumericComparisonOperator.LESS_THAN_OR_EQUAL_TO, 50);
v.addValidation(INPUT_EMAIL, Validator.NO_BLANKS);
v.addValidation(INPUT_EMAIL, Validator.LENGTH_NUMERIC_COMPARISON, NumericComparisonOperator.LESS_THAN_OR_EQUAL_TO, 120);
v.addValidation(INPUT_EMAIL, Validator.IS_A_EMAIL);
v.addValidation(INPUT_INSTITUTION, Validator.NO_BLANKS);
v.addValidation(INPUT_INSTITUTION, Validator.LENGTH_NUMERIC_COMPARISON, NumericComparisonOperator.LESS_THAN_OR_EQUAL_TO, 255);
HashMap errors = v.validate();
if (errors.isEmpty()) {
loadPresetValuesFromForm(fp);
fp.addPresetValue(ARG_STEPNUM, CONFIRM_STEP);
setPresetValues(fp.getPresetValues());
request.setAttribute("userName", user.getName());
forwardPage(Page.EDIT_ACCOUNT_CONFIRM);
} else {
loadPresetValuesFromForm(fp);
fp.addPresetValue(ARG_STEPNUM, EDIT_STEP);
setInputMessages(errors);
setPresetValues(fp.getPresetValues());
addEntityList("userTypes", getUserTypes(), respage.getString("the_user_could_not_be_edited_because_no_user_types"), Page.ADMIN_SYSTEM);
addPageMessage(respage.getString("there_were_some_errors_submission") + respage.getString("see_below_for_details"));
forwardPage(Page.EDIT_ACCOUNT);
}
} else if (stepNum == CONFIRM_STEP) {
String button = fp.getString(INPUT_CONFIRM_BUTTON);
if (button.equals(resword.getString("back"))) {
loadPresetValuesFromForm(fp);
fp.addPresetValue(ARG_STEPNUM, EDIT_STEP);
addEntityList("userTypes", getUserTypes(), respage.getString("the_user_could_not_be_edited_because_no_user_types"), Page.ADMIN_SYSTEM);
setPresetValues(fp.getPresetValues());
request.setAttribute("userName", user.getName());
forwardPage(Page.EDIT_ACCOUNT);
} else if (button.equals(resword.getString("confirm"))) {
user.setFirstName(fp.getString(INPUT_FIRST_NAME));
user.setLastName(fp.getString(INPUT_LAST_NAME));
user.setEmail(fp.getString(INPUT_EMAIL));
user.setInstitutionalAffiliation(fp.getString(INPUT_INSTITUTION));
user.setUpdater(ub);
user.setRunWebservices(fp.getBoolean(INPUT_RUN_WEBSERVICES));
user.setEnableApiKey(true);
String apiKey = null;
do {
apiKey = getRandom32ChApiKey();
} while (isApiKeyExist(apiKey));
user.setApiKey(apiKey);
UserType ut = UserType.get(fp.getInt(INPUT_USER_TYPE));
if (ut.equals(UserType.SYSADMIN)) {
user.addUserType(ut);
} else if (ut.equals(UserType.TECHADMIN)) {
user.addUserType(ut);
} else {
user.addUserType(UserType.USER);
}
if (fp.getBoolean(INPUT_RESET_PASSWORD)) {
SecurityManager sm = ((SecurityManager) SpringServletAccess.getApplicationContext(context).getBean("securityManager"));
String password = sm.genPassword();
String passwordHash = sm.encrytPassword(password, getUserDetails());
user.setPasswd(passwordHash);
user.setPasswdTimestamp(null);
udao.update(user);
if ("no".equalsIgnoreCase(fp.getString(INPUT_DISPLAY_PWD))) {
logger.info("displayPwd is no");
try {
sendResetPasswordEmail(user, password);
} catch (Exception e) {
addPageMessage(respage.getString("there_was_an_error_sending_reset_email_try_reset"));
}
} else {
addPageMessage(respage.getString("new_user_password") + ":<br/> " + password + "<br/>" + respage.getString("please_write_down_the_password_and_provide"));
}
} else {
udao.update(user);
}
addPageMessage(respage.getString("the_user_account") + " \"" + user.getName() + "\" " + respage.getString("was_updated_succesfully"));
forwardPage(Page.LIST_USER_ACCOUNTS_SERVLET);
} else {
throw new InconsistentStateException(Page.ADMIN_SYSTEM, resexception.getString("an_invalid_submit_button_was_clicked"));
}
} else {
throw new InconsistentStateException(Page.ADMIN_SYSTEM, resexception.getString("an_invalid_step_was_specified"));
}
}
use of org.akaza.openclinica.dao.login.UserAccountDAO in project OpenClinica by OpenClinica.
the class EnterDataForStudyEventServlet method populateUncompletedCRFsWithAnOwner.
private void populateUncompletedCRFsWithAnOwner(List<DisplayEventDefinitionCRFBean> displayEventDefinitionCRFBeans) {
if (displayEventDefinitionCRFBeans == null || displayEventDefinitionCRFBeans.isEmpty()) {
return;
}
UserAccountDAO userAccountDAO = new UserAccountDAO(sm.getDataSource());
UserAccountBean userAccountBean;
EventCRFBean eventCRFBean;
EventDefinitionCRFBean eventDefinitionCRFBean;
for (DisplayEventDefinitionCRFBean dedcBean : displayEventDefinitionCRFBeans) {
eventCRFBean = dedcBean.getEventCRF();
if (eventCRFBean != null && eventCRFBean.getOwner() == null && eventCRFBean.getOwnerId() > 0) {
userAccountBean = (UserAccountBean) userAccountDAO.findByPK(eventCRFBean.getOwnerId());
eventCRFBean.setOwner(userAccountBean);
}
// EventDefinitionCRFBean
if (eventCRFBean != null && eventCRFBean.getOwner() == null) {
int ownerId = dedcBean.getEdc().getOwnerId();
if (ownerId > 0) {
userAccountBean = (UserAccountBean) userAccountDAO.findByPK(ownerId);
eventCRFBean.setOwner(userAccountBean);
}
}
}
}
Aggregations