use of org.akaza.openclinica.control.form.FormProcessor in project OpenClinica by OpenClinica.
the class ConfigureServlet method processRequest.
@SuppressWarnings("unchecked")
@Override
protected void processRequest() throws Exception {
FormProcessor fp = new FormProcessor(request);
if (!fp.isSubmitted()) {
loadPresetValuesFromBean(fp);
setPresetValues(fp.getPresetValues());
forwardPage(Page.CONFIGURATION);
} else {
Validator v = new Validator(request);
v.addValidation("lockcount", Validator.IS_AN_INTEGER);
v.addValidation("lockcount", Validator.NO_BLANKS);
v.addValidation("lockcount", Validator.IS_IN_RANGE, 1, 25);
HashMap errors = v.validate();
if (!errors.isEmpty()) {
loadPresetValuesFromForm(fp);
setPresetValues(fp.getPresetValues());
setInputMessages(errors);
forwardPage(Page.CONFIGURATION);
} else {
ConfigurationBean userLockSwitch = getConfigurationDao().findByKey("user.lock.switch");
ConfigurationBean userLockAllowedFailedConsecutiveLoginAttempts = getConfigurationDao().findByKey("user.lock.allowedFailedConsecutiveLoginAttempts");
userLockSwitch.setValue(fp.getString("lockswitch"));
userLockAllowedFailedConsecutiveLoginAttempts.setValue(fp.getString("lockcount"));
getConfigurationDao().saveOrUpdate(userLockSwitch);
getConfigurationDao().saveOrUpdate(userLockAllowedFailedConsecutiveLoginAttempts);
addPageMessage(respage.getString("lockout_changes_have_been_saved"));
forwardPage(Page.LIST_USER_ACCOUNTS_SERVLET);
}
}
}
use of org.akaza.openclinica.control.form.FormProcessor in project OpenClinica by OpenClinica.
the class CreateJobImportServlet method setUpServlet.
/*
* Find all the form items and re-populate as necessary
*/
private void setUpServlet() throws Exception {
String directory = SQLInitServlet.getField("filePath") + DIR_PATH + File.separator;
logger.debug("found directory: " + directory);
// find all the form items and re-populate them if necessary
FormProcessor fp2 = new FormProcessor(request);
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);
// tbh, replacing the above with another version, 06/2009
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);
// YW >>
// << tbh
request.setAttribute("filePath", directory);
// request.setAttribute("activeStudy", activeStudy);
request.setAttribute(JOB_NAME, fp2.getString(JOB_NAME));
request.setAttribute(JOB_DESC, fp2.getString(JOB_DESC));
request.setAttribute(EMAIL, fp2.getString(EMAIL));
request.setAttribute(HOURS, new Integer(fp2.getInt(HOURS)).toString());
request.setAttribute(MINUTES, new Integer(fp2.getInt(MINUTES)).toString());
}
use of org.akaza.openclinica.control.form.FormProcessor 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);
}
}
}
use of org.akaza.openclinica.control.form.FormProcessor in project OpenClinica by OpenClinica.
the class RemoveStudyServlet method processRequest.
@Override
public void processRequest() throws Exception {
StudyDAO sdao = new StudyDAO(sm.getDataSource());
FormProcessor fp = new FormProcessor(request);
int studyId = fp.getInt("id");
StudyBean study = (StudyBean) sdao.findByPK(studyId);
// find all sites
ArrayList sites = (ArrayList) sdao.findAllByParent(studyId);
// find all user and roles in the study, include ones in sites
UserAccountDAO udao = new UserAccountDAO(sm.getDataSource());
ArrayList userRoles = udao.findAllByStudyId(studyId);
// find all subjects in the study, include ones in sites
StudySubjectDAO ssdao = new StudySubjectDAO(sm.getDataSource());
ArrayList subjects = ssdao.findAllByStudy(study);
// find all events in the study, include ones in sites
StudyEventDefinitionDAO sefdao = new StudyEventDefinitionDAO(sm.getDataSource());
ArrayList definitions = sefdao.findAllByStudy(study);
String action = request.getParameter("action");
if (studyId == 0) {
addPageMessage(respage.getString("please_choose_a_study_to_remove"));
forwardPage(Page.STUDY_LIST_SERVLET);
} else {
if ("confirm".equalsIgnoreCase(action)) {
request.setAttribute("studyToRemove", study);
request.setAttribute("sitesToRemove", sites);
request.setAttribute("userRolesToRemove", userRoles);
request.setAttribute("subjectsToRemove", subjects);
request.setAttribute("definitionsToRemove", definitions);
forwardPage(Page.REMOVE_STUDY);
} else {
logger.info("submit to remove the study");
// change all statuses to unavailable
StudyDAO studao = new StudyDAO(sm.getDataSource());
study.setOldStatus(study.getStatus());
study.setStatus(Status.DELETED);
study.setUpdater(ub);
study.setUpdatedDate(new Date());
studao.update(study);
// remove all sites
for (int i = 0; i < sites.size(); i++) {
StudyBean site = (StudyBean) sites.get(i);
if (!site.getStatus().equals(Status.DELETED)) {
site.setOldStatus(site.getStatus());
site.setStatus(Status.AUTO_DELETED);
site.setUpdater(ub);
site.setUpdatedDate(new Date());
sdao.update(site);
}
}
// remove all users and roles
for (int i = 0; i < userRoles.size(); i++) {
StudyUserRoleBean role = (StudyUserRoleBean) userRoles.get(i);
logger.info("remove user role" + role.getName());
if (!role.getStatus().equals(Status.DELETED)) {
role.setStatus(Status.AUTO_DELETED);
role.setUpdater(ub);
role.setUpdatedDate(new Date());
udao.updateStudyUserRole(role, role.getUserName());
}
}
// YW << bug fix for that current active study has been deleted
if (study.getId() == currentStudy.getId()) {
currentStudy.setStatus(Status.DELETED);
currentRole.setStatus(Status.DELETED);
} else // (auto-removed)
if (currentStudy.getParentStudyId() == study.getId()) {
currentStudy.setStatus(Status.AUTO_DELETED);
// we may need handle this later?
currentRole.setStatus(Status.DELETED);
}
// remove all subjects
for (int i = 0; i < subjects.size(); i++) {
StudySubjectBean subject = (StudySubjectBean) subjects.get(i);
if (!subject.getStatus().equals(Status.DELETED)) {
subject.setStatus(Status.AUTO_DELETED);
subject.setUpdater(ub);
subject.setUpdatedDate(new Date());
ssdao.update(subject);
}
}
// remove all study_group_class
// changed by jxu on 08-31-06, to fix the problem of no study_id
// in study_group table
StudyGroupClassDAO sgcdao = new StudyGroupClassDAO(sm.getDataSource());
StudyGroupDAO sgdao = new StudyGroupDAO(sm.getDataSource());
SubjectGroupMapDAO sgmdao = new SubjectGroupMapDAO(sm.getDataSource());
// YW 09-27-2007, enable status updating for StudyGroupClassBean
ArrayList groups = sgcdao.findAllByStudy(study);
for (int i = 0; i < groups.size(); i++) {
StudyGroupClassBean group = (StudyGroupClassBean) groups.get(i);
if (!group.getStatus().equals(Status.DELETED)) {
group.setStatus(Status.AUTO_DELETED);
group.setUpdater(ub);
group.setUpdatedDate(new Date());
sgcdao.update(group);
// all subject_group_map
ArrayList subjectGroupMaps = sgmdao.findAllByStudyGroupClassId(group.getId());
for (int j = 0; j < subjectGroupMaps.size(); j++) {
SubjectGroupMapBean sgMap = (SubjectGroupMapBean) subjectGroupMaps.get(j);
if (!sgMap.getStatus().equals(Status.DELETED)) {
sgMap.setStatus(Status.AUTO_DELETED);
sgMap.setUpdater(ub);
sgMap.setUpdatedDate(new Date());
sgmdao.update(sgMap);
}
}
}
}
ArrayList groupClasses = sgcdao.findAllActiveByStudy(study);
for (int i = 0; i < groupClasses.size(); i++) {
StudyGroupClassBean gc = (StudyGroupClassBean) groupClasses.get(i);
if (!gc.getStatus().equals(Status.DELETED)) {
gc.setStatus(Status.AUTO_DELETED);
gc.setUpdater(ub);
gc.setUpdatedDate(new Date());
sgcdao.update(gc);
}
}
// remove all event definitions and event
EventDefinitionCRFDAO edcdao = new EventDefinitionCRFDAO(sm.getDataSource());
StudyEventDAO sedao = new StudyEventDAO(sm.getDataSource());
for (int i = 0; i < definitions.size(); i++) {
StudyEventDefinitionBean definition = (StudyEventDefinitionBean) definitions.get(i);
if (!definition.getStatus().equals(Status.DELETED)) {
definition.setStatus(Status.AUTO_DELETED);
definition.setUpdater(ub);
definition.setUpdatedDate(new Date());
sefdao.update(definition);
ArrayList edcs = (ArrayList) edcdao.findAllByDefinition(definition.getId());
for (int j = 0; j < edcs.size(); j++) {
EventDefinitionCRFBean edc = (EventDefinitionCRFBean) edcs.get(j);
if (!edc.getStatus().equals(Status.DELETED)) {
edc.setStatus(Status.AUTO_DELETED);
edc.setUpdater(ub);
edc.setUpdatedDate(new Date());
edcdao.update(edc);
}
}
ArrayList events = (ArrayList) sedao.findAllByDefinition(definition.getId());
EventCRFDAO ecdao = new EventCRFDAO(sm.getDataSource());
for (int j = 0; j < events.size(); j++) {
StudyEventBean event = (StudyEventBean) events.get(j);
if (!event.getStatus().equals(Status.DELETED)) {
event.setStatus(Status.AUTO_DELETED);
event.setUpdater(ub);
event.setUpdatedDate(new Date());
sedao.update(event);
ArrayList eventCRFs = ecdao.findAllByStudyEvent(event);
ItemDataDAO iddao = new ItemDataDAO(sm.getDataSource());
for (int k = 0; k < eventCRFs.size(); k++) {
EventCRFBean eventCRF = (EventCRFBean) eventCRFs.get(k);
if (!eventCRF.getStatus().equals(Status.DELETED)) {
eventCRF.setOldStatus(eventCRF.getStatus());
eventCRF.setStatus(Status.AUTO_DELETED);
eventCRF.setUpdater(ub);
eventCRF.setUpdatedDate(new Date());
ecdao.update(eventCRF);
ArrayList itemDatas = iddao.findAllByEventCRFId(eventCRF.getId());
for (int a = 0; a < itemDatas.size(); a++) {
ItemDataBean item = (ItemDataBean) itemDatas.get(a);
if (!item.getStatus().equals(Status.DELETED)) {
item.setOldStatus(item.getStatus());
item.setStatus(Status.AUTO_DELETED);
item.setUpdater(ub);
item.setUpdatedDate(new Date());
iddao.update(item);
}
}
}
}
}
}
}
}
// for definitions
DatasetDAO datadao = new DatasetDAO(sm.getDataSource());
ArrayList dataset = datadao.findAllByStudyId(study.getId());
for (int i = 0; i < dataset.size(); i++) {
DatasetBean data = (DatasetBean) dataset.get(i);
if (!data.getStatus().equals(Status.DELETED)) {
data.setStatus(Status.AUTO_DELETED);
data.setUpdater(ub);
data.setUpdatedDate(new Date());
datadao.update(data);
}
}
addPageMessage(resexception.getString("this_study_has_been_removed_succesfully"));
forwardPage(Page.STUDY_LIST_SERVLET);
}
}
}
use of org.akaza.openclinica.control.form.FormProcessor in project OpenClinica by OpenClinica.
the class RemoveSubjectServlet method processRequest.
@Override
public void processRequest() throws Exception {
SubjectDAO sdao = new SubjectDAO(sm.getDataSource());
FormProcessor fp = new FormProcessor(request);
int subjectId = fp.getInt("id");
String action = fp.getString("action");
if (subjectId == 0 || StringUtil.isBlank(action)) {
addPageMessage(respage.getString("please_choose_a_subject_to_remove"));
forwardPage(Page.SUBJECT_LIST_SERVLET);
} else {
SubjectBean subject = (SubjectBean) sdao.findByPK(subjectId);
// find all study subjects
StudySubjectDAO ssdao = new StudySubjectDAO(sm.getDataSource());
ArrayList studySubs = ssdao.findAllBySubjectId(subjectId);
// find study events
StudyEventDAO sedao = new StudyEventDAO(sm.getDataSource());
ArrayList events = sedao.findAllBySubjectId(subjectId);
if ("confirm".equalsIgnoreCase(action)) {
request.setAttribute("subjectToRemove", subject);
request.setAttribute("studySubs", studySubs);
request.setAttribute("events", events);
forwardPage(Page.REMOVE_SUBJECT);
} else {
logger.info("submit to remove the subject");
// change all statuses to deleted
subject.setStatus(Status.DELETED);
subject.setUpdater(ub);
subject.setUpdatedDate(new Date());
sdao.update(subject);
// remove subject references from study
for (int i = 0; i < studySubs.size(); i++) {
StudySubjectBean studySub = (StudySubjectBean) studySubs.get(i);
if (!studySub.getStatus().equals(Status.DELETED)) {
studySub.setStatus(Status.AUTO_DELETED);
studySub.setUpdater(ub);
studySub.setUpdatedDate(new Date());
ssdao.update(studySub);
}
}
EventCRFDAO ecdao = new EventCRFDAO(sm.getDataSource());
for (int j = 0; j < events.size(); j++) {
StudyEventBean event = (StudyEventBean) events.get(j);
if (!event.getStatus().equals(Status.DELETED)) {
event.setStatus(Status.AUTO_DELETED);
event.setUpdater(ub);
event.setUpdatedDate(new Date());
sedao.update(event);
ArrayList eventCRFs = ecdao.findAllByStudyEvent(event);
ItemDataDAO iddao = new ItemDataDAO(sm.getDataSource());
for (int k = 0; k < eventCRFs.size(); k++) {
EventCRFBean eventCRF = (EventCRFBean) eventCRFs.get(k);
if (!eventCRF.getStatus().equals(Status.DELETED)) {
eventCRF.setStatus(Status.AUTO_DELETED);
eventCRF.setUpdater(ub);
eventCRF.setUpdatedDate(new Date());
ecdao.update(eventCRF);
// remove all the item data
ArrayList itemDatas = iddao.findAllByEventCRFId(eventCRF.getId());
for (int a = 0; a < itemDatas.size(); a++) {
ItemDataBean item = (ItemDataBean) itemDatas.get(a);
if (!item.getStatus().equals(Status.DELETED)) {
item.setStatus(Status.AUTO_DELETED);
item.setUpdater(ub);
item.setUpdatedDate(new Date());
iddao.update(item);
}
}
}
}
}
}
String emailBody = respage.getString("the_subject") + " " + subject.getUniqueIdentifier() + " " + respage.getString("has_been_removed_succesfully");
addPageMessage(emailBody);
// sendEmail(emailBody);
forwardPage(Page.SUBJECT_LIST_SERVLET);
}
}
}
Aggregations