use of org.akaza.openclinica.control.form.FormProcessor in project OpenClinica by OpenClinica.
the class UpdateStudyServlet method updateStudy2.
/**
* Updates the study bean with inputs from second section
*
* @param request
* @return true if study type is Interventional, otherwise false
*/
private boolean updateStudy2() {
FormProcessor fp = new FormProcessor(request);
StudyBean newStudy = (StudyBean) session.getAttribute("newStudy");
// this is not fully supported yet, because the system will not handle
// studies which are pending
// or private...
newStudy.setStatus(Status.get(fp.getInt("statusId")));
newStudy.setProtocolDateVerification(fp.getDate(INPUT_VER_DATE));
newStudy.setDatePlannedStart(fp.getDate(INPUT_START_DATE));
if (StringUtil.isBlank(fp.getString(INPUT_END_DATE))) {
newStudy.setDatePlannedEnd(null);
} else {
newStudy.setDatePlannedEnd(fp.getDate(INPUT_END_DATE));
}
newStudy.setPhase(fp.getString("phase"));
if (fp.getInt("genetic") == 1) {
newStudy.setGenetic(true);
} else {
newStudy.setGenetic(false);
}
session.setAttribute("newStudy", newStudy);
String interventional = resadmin.getString("interventional");
return interventional.equalsIgnoreCase(newStudy.getProtocolType());
}
use of org.akaza.openclinica.control.form.FormProcessor in project OpenClinica by OpenClinica.
the class DeleteUserServlet 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);
int action = fp.getInt(ARG_ACTION);
UserAccountBean u = (UserAccountBean) udao.findByPK(userId);
String message;
if (!u.isActive()) {
message = respage.getString("the_specified_user_not_exits");
} else if (!EntityAction.contains(action)) {
message = respage.getString("the_specified_action_on_the_user_is_invalid");
} else if (!EntityAction.get(action).equals(EntityAction.DELETE) && !EntityAction.get(action).equals(EntityAction.RESTORE)) {
message = respage.getString("the_specified_action_is_not_allowed");
} else {
EntityAction desiredAction = EntityAction.get(action);
u.setUpdater(ub);
if (desiredAction.equals(EntityAction.DELETE)) {
udao.delete(u);
if (udao.isQuerySuccessful()) {
message = respage.getString("the_user_has_been_removed_successfully");
// YW 07-31-2007 << for feature that deletion doesn't need
// email the deleted user.
/*
* //YW 07-26-2007 << catch exception (eg. timeout) and
* inform users. try { sendDeleteEmail(u); } catch
* (Exception e) { message += " However, there has been an
* error sending the user an email regarding this
* deletion."; }
*/
// YW >>
} else {
message = respage.getString("the_user_could_not_be_deleted_due_database_error");
}
} else {
SecurityManager sm = (SecurityManager) SpringServletAccess.getApplicationContext(context).getBean("securityManager");
String password = sm.genPassword();
String passwordHash = sm.encrytPassword(password, getUserDetails());
if (!u.isLdapUser()) {
u.setPasswd(passwordHash);
u.setPasswdTimestamp(null);
}
udao.restore(u);
if (udao.isQuerySuccessful()) {
message = respage.getString("the_user_has_been_restored");
try {
if (!u.isLdapUser()) {
sendRestoreEmail(u, password);
}
} catch (Exception e) {
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.control.form.FormProcessor in project OpenClinica by OpenClinica.
the class DownloadVersionSpreadSheetServlet method processRequest.
@Override
public void processRequest() throws Exception {
String dir = SQLInitServlet.getField("filePath") + "crf" + File.separator + "new" + File.separator;
// YW 09-10-2007 << Now CRF_Design_Template_v2.xls is located at
// $CATALINA_HOME/webapps/OpenClinica-instanceName/properties
FormProcessor fp = new FormProcessor(request);
String crfIdString = fp.getString(CRF_ID);
int crfVersionId = fp.getInt(CRF_VERSION_ID);
CRFVersionDAO cvdao = new CRFVersionDAO(sm.getDataSource());
CRFVersionBean version = (CRFVersionBean) cvdao.findByPK(crfVersionId);
boolean isTemplate = fp.getBoolean("template");
String excelFileName = crfIdString + version.getOid() + ".xls";
// aha, what if it's the old style? next line is for backwards compat,
// tbh 07/2008
File excelFile = null;
String oldExcelFileName = crfIdString + version.getName() + ".xls";
if (isTemplate) {
// excelFile = new File(dir + CRF_VERSION_TEMPLATE);
excelFile = getCoreResources().getFile(CRF_VERSION_TEMPLATE, "crf" + File.separator + "original" + File.separator);
excelFileName = CRF_VERSION_TEMPLATE;
// FileOutputStream fos = new FileOutputStream(excelFile);
// IOUtils.copy(getCoreResources().getInputStream(CRF_VERSION_TEMPLATE), fos);
// IOUtils.closeQuietly(fos);
} else {
excelFile = new File(dir + excelFileName);
// backwards compat
File oldExcelFile = new File(dir + oldExcelFileName);
if (oldExcelFile.exists() && oldExcelFile.length() > 0) {
if (!excelFile.exists() || excelFile.length() <= 0) {
// if the old name exists and the new name does not...
excelFile = oldExcelFile;
excelFileName = oldExcelFileName;
}
}
}
logger.info("looking for : " + excelFile.getName());
if (!excelFile.exists() || excelFile.length() <= 0) {
addPageMessage(respage.getString("the_excel_is_not_available_on_server_contact"));
forwardPage(Page.CRF_LIST_SERVLET);
} else {
response.setHeader("Content-disposition", "attachment; filename=\"" + excelFileName + "\";");
response.setContentType("application/vnd.ms-excel");
response.setHeader("Pragma", "public");
ServletOutputStream op = response.getOutputStream();
DataInputStream in = null;
try {
response.setContentType("application/vnd.ms-excel");
response.setHeader("Pragma", "public");
response.setContentLength((int) excelFile.length());
byte[] bbuf = new byte[(int) excelFile.length()];
in = new DataInputStream(new FileInputStream(excelFile));
int length;
while ((in != null) && ((length = in.read(bbuf)) != -1)) {
op.write(bbuf, 0, length);
}
in.close();
op.flush();
op.close();
} catch (Exception ee) {
ee.printStackTrace();
} finally {
if (in != null) {
in.close();
}
if (op != null) {
op.close();
}
}
}
}
use of org.akaza.openclinica.control.form.FormProcessor in project OpenClinica by OpenClinica.
the class EditStudyUserRoleServlet method processRequest.
@Override
protected void processRequest() throws Exception {
UserAccountDAO udao = new UserAccountDAO(sm.getDataSource());
FormProcessor fp = new FormProcessor(request);
int studyId = fp.getInt(ARG_STUDY_ID);
String uName = fp.getString(ARG_USER_NAME);
StudyUserRoleBean studyUserRole = udao.findRoleByUserNameAndStudyId(uName, studyId);
StudyDAO sdao = new StudyDAO(sm.getDataSource());
StudyBean sb = (StudyBean) sdao.findByPK(studyUserRole.getStudyId());
if (sb != null) {
studyUserRole.setStudyName(sb.getName());
}
if (!studyUserRole.isActive()) {
String message = respage.getString("the_user_has_no_role_in_study");
addPageMessage(message);
forwardPage(Page.LIST_USER_ACCOUNTS_SERVLET);
} else {
Map roleMap = new LinkedHashMap();
for (Iterator it = getRoles().iterator(); it.hasNext(); ) {
Role role = (Role) it.next();
roleMap.put(role.getId(), role.getDescription());
}
roleMap = new LinkedHashMap();
ResourceBundle resterm = org.akaza.openclinica.i18n.util.ResourceBundleProvider.getTermsBundle();
StudyBean study = (StudyBean) sdao.findByPK(studyUserRole.getStudyId());
if (study.getParentStudyId() == 0) {
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 {
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:
}
}
}
if (study.getParentStudyId() > 0) {
roleMap.remove(Role.COORDINATOR.getId());
roleMap.remove(Role.STUDYDIRECTOR.getId());
}
// send the user to the right place..
if (!fp.isSubmitted()) {
request.setAttribute("userName", uName);
request.setAttribute("studyUserRole", studyUserRole);
request.setAttribute("roles", roleMap);
request.setAttribute("chosenRoleId", new Integer(studyUserRole.getRole().getId()));
forwardPage(Page.EDIT_STUDY_USER_ROLE);
} else // process the form
{
Validator v = new Validator(request);
v.addValidation(INPUT_ROLE, Validator.IS_VALID_TERM, TermType.ROLE);
HashMap errors = v.validate();
if (errors.isEmpty()) {
int roleId = fp.getInt(INPUT_ROLE);
Role r = Role.get(roleId);
studyUserRole.setRoleName(r.getName());
studyUserRole.setUpdater(ub);
udao.updateStudyUserRole(studyUserRole, uName);
String message = respage.getString("the_user_in_study_has_been_updated");
addPageMessage(message);
forwardPage(Page.LIST_USER_ACCOUNTS_SERVLET);
} else {
String message = respage.getString("the_role_choosen_was_invalid_choose_another");
addPageMessage(message);
request.setAttribute("userName", uName);
request.setAttribute("studyUserRole", studyUserRole);
request.setAttribute("chosenRoleId", new Integer(fp.getInt(INPUT_ROLE)));
request.setAttribute("roles", roleMap);
forwardPage(Page.EDIT_STUDY_USER_ROLE);
}
}
}
}
use of org.akaza.openclinica.control.form.FormProcessor in project OpenClinica by OpenClinica.
the class BatchCRFMigrationServlet method processRequest.
@SuppressWarnings({ "rawtypes", "unchecked" })
@Override
public void processRequest() throws Exception {
FormProcessor fp = new FormProcessor(request);
ArrayList<CRFVersionBean> crfVersionList = null;
ArrayList<FormLayoutBean> formLayoutList = null;
ArrayList<StudyEventDefinitionBean> eventList = null;
ArrayList<StudyBean> siteList = null;
// checks which module the requests are from, manage or admin
String module = fp.getString(MODULE);
request.setAttribute(MODULE, module);
int crfId = fp.getInt(CRF_ID);
if (crfId == 0) {
addPageMessage(respage.getString("please_choose_a_CRF_to_view"));
forwardPage(Page.CRF_LIST);
} else {
CRFDAO cdao = new CRFDAO(sm.getDataSource());
// CRFVersionDAO vdao = new CRFVersionDAO(sm.getDataSource());
FormLayoutDAO fldao = new FormLayoutDAO(sm.getDataSource());
CRFBean crf = (CRFBean) cdao.findByPK(crfId);
request.setAttribute("crfName", crf.getName());
// ArrayList<CRFVersionBean> versions = (ArrayList<CRFVersionBean>) vdao.findAllByCRF(crfId);
ArrayList<FormLayoutBean> formLayouts = (ArrayList<FormLayoutBean>) fldao.findAllByCRF(crfId);
crfVersionList = new ArrayList<CRFVersionBean>();
formLayoutList = new ArrayList<FormLayoutBean>();
for (FormLayoutBean version : formLayouts) {
if (version.getStatus().isAvailable())
formLayoutList.add(version);
}
// for (CRFVersionBean version : versions) {
// if (version.getStatus().isAvailable())
// crfVersionList.add(version);
// }
// crf.setVersions(crfVersionList);
crf.setFormLayouts(formLayoutList);
ArrayList<StudyBean> listOfSites = (ArrayList<StudyBean>) sdao().findAllByParent(currentStudy.getId());
siteList = new ArrayList<StudyBean>();
StudyBean studyBean = new StudyBean();
studyBean.setOid(currentStudy.getOid());
studyBean.setName(resterm.getString("Study_Level_Subjects_Only"));
siteList.add(studyBean);
for (StudyBean s : listOfSites) {
if (s.getStatus().isAvailable()) {
siteList.add(s);
}
}
ArrayList<StudyEventDefinitionBean> listOfDefn = seddao().findAllByStudy(currentStudy);
eventList = new ArrayList<StudyEventDefinitionBean>();
for (StudyEventDefinitionBean d : listOfDefn) {
if (d.getStatus().isAvailable()) {
eventList.add(d);
}
}
// if coming from change crf version -> display message
String crfVersionChangeMsg = fp.getString("isFromCRFVersionBatchChange");
if (crfVersionChangeMsg != null && !crfVersionChangeMsg.equals("")) {
addPageMessage(crfVersionChangeMsg);
}
request.setAttribute("study", currentStudy);
request.setAttribute("siteList", siteList);
request.setAttribute("eventList", eventList);
request.setAttribute(CRF, crf);
forwardPage(Page.BATCH_CRF_MIGRATION);
}
}
Aggregations