use of org.akaza.openclinica.control.form.FormProcessor in project OpenClinica by OpenClinica.
the class ResetPasswordServlet method processRequest.
/**
* Tasks include:
* <ol>
* <li>Validation:
* <ol>
* <li>1. old password match database record
* <li>2. new password is follows requirements
* <li>4. two times entered passwords are same
* <li>5. all required fields are filled
* </ol>
* <li>Update ub - UserAccountBean - in session and database
* </ol>
*/
@Override
public void processRequest() throws Exception {
logger.info("Change expired password");
UserAccountDAO udao = new UserAccountDAO(sm.getDataSource());
Validator v = new Validator(request);
errors.clear();
FormProcessor fp = new FormProcessor(request);
String mustChangePwd = request.getParameter("mustChangePwd");
String newPwd = fp.getString("passwd").trim();
String passwdChallengeQ = fp.getString("passwdChallengeQ");
String passwdChallengeA = fp.getString("passwdChallengeA");
if ("yes".equalsIgnoreCase(mustChangePwd)) {
addPageMessage(respage.getString("your_password_has_expired_must_change"));
} else {
addPageMessage(respage.getString("password_expired") + " " + respage.getString("if_you_do_not_want_change_leave_blank"));
}
request.setAttribute("mustChangePass", mustChangePwd);
String oldPwd = fp.getString("oldPasswd").trim();
// user bean from web
UserAccountBean ubForm = new UserAccountBean();
// form
ubForm.setPasswd(oldPwd);
ubForm.setPasswdChallengeQuestion(passwdChallengeQ);
ubForm.setPasswdChallengeAnswer(passwdChallengeA);
request.setAttribute("userBean1", ubForm);
SecurityManager sm = ((SecurityManager) SpringServletAccess.getApplicationContext(context).getBean("securityManager"));
if (!sm.isPasswordValid(ub.getPasswd(), oldPwd, getUserDetails())) {
Validator.addError(errors, "oldPasswd", resexception.getString("wrong_old_password"));
request.setAttribute("formMessages", errors);
forwardPage(Page.RESET_PASSWORD);
} else {
if (mustChangePwd.equalsIgnoreCase("yes")) {
v.addValidation("passwd", Validator.NO_BLANKS);
v.addValidation("passwd1", Validator.NO_BLANKS);
v.addValidation("passwdChallengeQ", Validator.NO_BLANKS);
v.addValidation("passwdChallengeA", Validator.NO_BLANKS);
v.addValidation("passwd", Validator.CHECK_DIFFERENT, "oldPasswd");
}
String newDigestPass = sm.encrytPassword(newPwd, getUserDetails());
List<String> pwdErrors = new ArrayList<String>();
if (!StringUtils.isEmpty(newPwd)) {
v.addValidation("passwd", Validator.IS_A_PASSWORD);
v.addValidation("passwd1", Validator.CHECK_SAME, "passwd");
ConfigurationDao configurationDao = SpringServletAccess.getApplicationContext(context).getBean(ConfigurationDao.class);
PasswordRequirementsDao passwordRequirementsDao = new PasswordRequirementsDao(configurationDao);
Locale locale = LocaleResolver.getLocale(request);
ResourceBundle resexception = ResourceBundleProvider.getExceptionsBundle(locale);
pwdErrors = PasswordValidator.validatePassword(passwordRequirementsDao, udao, ub.getId(), newPwd, newDigestPass, resexception);
}
errors = v.validate();
for (String err : pwdErrors) {
v.addError(errors, "passwd", err);
}
if (!errors.isEmpty()) {
logger.info("ResetPassword page has validation errors");
request.setAttribute("formMessages", errors);
forwardPage(Page.RESET_PASSWORD);
} else {
logger.info("ResetPassword page has no errors");
if (!StringUtils.isBlank(newPwd)) {
ub.setPasswd(newDigestPass);
ub.setPasswdTimestamp(new Date());
} else if ("no".equalsIgnoreCase(mustChangePwd)) {
ub.setPasswdTimestamp(new Date());
}
ub.setOwner(ub);
// when update ub, updator id is required
ub.setUpdater(ub);
ub.setPasswdChallengeQuestion(passwdChallengeQ);
ub.setPasswdChallengeAnswer(passwdChallengeA);
udao.update(ub);
ArrayList<String> pageMessages = new ArrayList<String>();
request.setAttribute(PAGE_MESSAGE, pageMessages);
addPageMessage(respage.getString("your_expired_password_reset_successfully"));
ub.incNumVisitsToMainMenu();
forwardPage(Page.MENU_SERVLET);
}
}
}
use of org.akaza.openclinica.control.form.FormProcessor in project OpenClinica by OpenClinica.
the class AddCRFToDefinitionServlet method processRequest.
@Override
public void processRequest() throws Exception {
String actionName = request.getParameter("actionName");
String submit = request.getParameter("Submit");
CRFDAO cdao = new CRFDAO(sm.getDataSource());
ArrayList crfs = (ArrayList) cdao.findAllByStatus(Status.AVAILABLE);
ArrayList edcs = (ArrayList) session.getAttribute("eventDefinitionCRFs");
if (edcs == null) {
edcs = new ArrayList();
}
HashMap crfIds = new HashMap();
for (int i = 0; i < edcs.size(); i++) {
EventDefinitionCRFBean edc = (EventDefinitionCRFBean) edcs.get(i);
Integer crfId = new Integer(edc.getCrfId());
crfIds.put(crfId, edc);
}
for (int i = 0; i < crfs.size(); i++) {
CRFBean crf = (CRFBean) crfs.get(i);
if (crfIds.containsKey(new Integer(crf.getId()))) {
crf.setSelected(true);
}
}
session.setAttribute("crfsWithVersion", crfs);
if (submit != null) {
addCRF();
} else {
if (StringUtil.isBlank(actionName)) {
FormProcessor fp = new FormProcessor(request);
EntityBeanTable table = fp.getEntityBeanTable();
ArrayList allRows = CRFRow.generateRowsFromBeans(crfs);
String[] columns = { resword.getString("CRF_name"), resword.getString("date_created"), resword.getString("owner"), resword.getString("date_updated"), resword.getString("last_updated_by"), resword.getString("selected") };
table.setColumns(new ArrayList(Arrays.asList(columns)));
table.hideColumnLink(5);
table.setQuery("AddCRFToDefinition", new HashMap());
table.setRows(allRows);
table.computeDisplay();
request.setAttribute("table", table);
forwardPage(Page.UPDATE_EVENT_DEFINITION2);
} else if (actionName.equalsIgnoreCase("next")) {
Integer pageNumber = Integer.valueOf(request.getParameter("pageNum"));
if (pageNumber != null) {
if (pageNumber.intValue() == 2) {
String nextListPage = request.getParameter("next_list_page");
if (nextListPage != null && nextListPage.equalsIgnoreCase("true")) {
confirmDefinition();
}
} else {
confirmDefinition();
}
}
}
}
}
use of org.akaza.openclinica.control.form.FormProcessor in project OpenClinica by OpenClinica.
the class AddCRFToDefinitionServlet method addCRF.
private void addCRF() throws Exception {
FormProcessor fp = new FormProcessor(request);
FormLayoutDAO fldao = new FormLayoutDAO(sm.getDataSource());
ArrayList crfArray = new ArrayList();
Map tmpCRFIdMap = (HashMap) session.getAttribute("tmpCRFIdMap");
if (tmpCRFIdMap == null) {
tmpCRFIdMap = new HashMap();
}
ArrayList crfsWithVersion = (ArrayList) session.getAttribute("crfsWithVersion");
for (int i = 0; i < crfsWithVersion.size(); i++) {
int id = fp.getInt("id" + i);
String name = fp.getString("name" + i);
String selected = fp.getString("selected" + i);
if (!StringUtil.isBlank(selected) && "yes".equalsIgnoreCase(selected.trim())) {
logger.info("one crf selected");
CRFBean cb = new CRFBean();
cb.setId(id);
cb.setName(name);
// only find active verions
ArrayList versions = (ArrayList) fldao.findAllActiveByCRF(cb.getId());
cb.setVersions(versions);
crfArray.add(cb);
} else {
if (tmpCRFIdMap.containsKey(id)) {
tmpCRFIdMap.remove(id);
}
}
}
for (Iterator tmpCRFIterator = tmpCRFIdMap.keySet().iterator(); tmpCRFIterator.hasNext(); ) {
int id = (Integer) tmpCRFIterator.next();
String name = (String) tmpCRFIdMap.get(id);
boolean isExists = false;
for (Iterator it = crfArray.iterator(); it.hasNext(); ) {
CRFBean cb = (CRFBean) it.next();
if (id == cb.getId()) {
isExists = true;
}
}
if (!isExists) {
CRFBean cb = new CRFBean();
cb.setId(id);
cb.setName(name);
// only find active verions
ArrayList versions = (ArrayList) fldao.findAllActiveByCRF(cb.getId());
cb.setVersions(versions);
crfArray.add(cb);
}
}
session.removeAttribute("tmpCRFIdMap");
StudyParameterValueDAO spvdao = new StudyParameterValueDAO(sm.getDataSource());
if (crfArray.size() == 0) {
// no crf seleted
addPageMessage(respage.getString("no_new_CRF_added"));
StudyEventDefinitionBean sed = (StudyEventDefinitionBean) session.getAttribute("definition");
String participateFormStatus = spvdao.findByHandleAndStudy(sed.getStudyId(), "participantPortal").getValue();
request.setAttribute("participateFormStatus", participateFormStatus);
sed.setCrfs(new ArrayList());
session.setAttribute("definition", sed);
forwardPage(Page.UPDATE_EVENT_DEFINITION1);
} else {
StudyEventDefinitionBean sed = (StudyEventDefinitionBean) session.getAttribute("definition");
String participateFormStatus = spvdao.findByHandleAndStudy(sed.getStudyId(), "participantPortal").getValue();
if (participateFormStatus.equals("enabled"))
baseUrl();
request.setAttribute("participateFormStatus", participateFormStatus);
ArrayList edcs = (ArrayList) session.getAttribute("eventDefinitionCRFs");
int ordinalForNewCRF = edcs.size();
for (int i = 0; i < crfArray.size(); i++) {
CRFBean crf = (CRFBean) crfArray.get(i);
EventDefinitionCRFBean edcBean = new EventDefinitionCRFBean();
edcBean.setCrfId(crf.getId());
edcBean.setCrfName(crf.getName());
edcBean.setStudyId(ub.getActiveStudyId());
edcBean.setStatus(Status.AVAILABLE);
edcBean.setStudyEventDefinitionId(sed.getId());
edcBean.setStudyId(ub.getActiveStudyId());
edcBean.setSourceDataVerification(SourceDataVerification.NOTREQUIRED);
ordinalForNewCRF = ordinalForNewCRF + 1;
edcBean.setOrdinal(ordinalForNewCRF);
edcBean.setVersions(crf.getVersions());
FormLayoutBean defaultVersion1 = (FormLayoutBean) fldao.findByPK(edcBean.getDefaultVersionId());
edcBean.setDefaultVersionName(defaultVersion1.getName());
ordinalForNewCRF++;
edcs.add(edcBean);
}
session.setAttribute("eventDefinitionCRFs", edcs);
ArrayList<String> sdvOptions = new ArrayList<String>();
sdvOptions.add(SourceDataVerification.AllREQUIRED.toString());
sdvOptions.add(SourceDataVerification.PARTIALREQUIRED.toString());
sdvOptions.add(SourceDataVerification.NOTREQUIRED.toString());
sdvOptions.add(SourceDataVerification.NOTAPPLICABLE.toString());
request.setAttribute("sdvOptions", sdvOptions);
addPageMessage(respage.getString("has_have_been_added_need_confirmation"));
forwardPage(Page.UPDATE_EVENT_DEFINITION1);
}
}
use of org.akaza.openclinica.control.form.FormProcessor in project OpenClinica by OpenClinica.
the class AssignUserToStudyServlet method processRequest.
@Override
public void processRequest() throws Exception {
String action = request.getParameter("action");
ArrayList users = findUsers();
String nextListPage = request.getParameter("next_list_page");
if (StringUtil.isBlank(action) || (nextListPage != null && nextListPage.equalsIgnoreCase("true"))) {
FormProcessor fp = new FormProcessor(request);
EntityBeanTable table = fp.getEntityBeanTable();
ArrayList allRows = UserAccountRow.generateRowsFromBeans(users);
if (nextListPage == null) {
session.removeAttribute("tmpSelectedUsersMap");
}
/*
* The tmpSelectedUsersMap will hold all the selected users in the
* session when the user is navigating through the list. This has
* been done so that when the user moves to the next page of Users
* list, the selection made in the previous page doesn't get lost.
*/
Map tmpSelectedUsersMap = (HashMap) session.getAttribute("tmpSelectedUsersMap");
if (tmpSelectedUsersMap == null) {
tmpSelectedUsersMap = new HashMap();
}
if (nextListPage != null && nextListPage.equalsIgnoreCase("true")) {
for (int i = 0; i < users.size(); i++) {
int id = fp.getInt("id" + i);
int roleId = fp.getInt("activeStudyRoleId" + i);
String checked = fp.getString("selected" + i);
// logger.info("selected:" + checked);
if (!StringUtil.isBlank(checked) && "yes".equalsIgnoreCase(checked.trim())) {
tmpSelectedUsersMap.put(id, roleId);
} else {
// deselected.
if (tmpSelectedUsersMap.containsKey(id)) {
tmpSelectedUsersMap.remove(id);
}
}
}
session.setAttribute("tmpSelectedUsersMap", tmpSelectedUsersMap);
}
String[] columns = { resword.getString("user_name"), resword.getString("first_name"), resword.getString("last_name"), resword.getString("role"), resword.getString("selected"), resword.getString("notes") };
table.setColumns(new ArrayList(Arrays.asList(columns)));
table.hideColumnLink(3);
table.hideColumnLink(4);
table.hideColumnLink(5);
table.setQuery("AssignUserToStudy", new HashMap());
table.setRows(allRows);
table.computeDisplay();
request.setAttribute("table", table);
// request.setAttribute("studyUsers", users);
ArrayList roles = Role.toArrayList();
if (currentStudy.getParentStudyId() > 0) {
roles.remove(Role.COORDINATOR);
roles.remove(Role.STUDYDIRECTOR);
}
// admin is not a user role, only used
roles.remove(Role.ADMIN);
// for
// tomcat
request.setAttribute("roles", roles);
forwardPage(Page.STUDY_USER_LIST);
} else {
if ("submit".equalsIgnoreCase(action)) {
addUser(users);
}
}
}
use of org.akaza.openclinica.control.form.FormProcessor in project OpenClinica by OpenClinica.
the class CreateStudyServlet method createStudyBean.
/**
* Constructs study bean from the first section
*
* @param request
* @return
*/
private StudyBean createStudyBean() {
FormProcessor fp = new FormProcessor(request);
StudyBean newStudy = new StudyBean();
newStudy.setName(fp.getString("name"));
newStudy.setOfficialTitle(fp.getString("officialTitle"));
newStudy.setIdentifier(fp.getString("uniqueProId"));
newStudy.setSecondaryIdentifier(fp.getString("secondProId"));
newStudy.setPrincipalInvestigator(fp.getString("prinInvestigator"));
newStudy.setProtocolType(fp.getString("protocolType"));
newStudy.setSummary(fp.getString("description"));
newStudy.setProtocolDescription(fp.getString("protocolDescription"));
newStudy.setSponsor(fp.getString("sponsor"));
newStudy.setCollaborators(fp.getString("collaborators"));
return newStudy;
}
Aggregations