/** * Send email to the user, director and administrator * * @param request * @param response */ private String sendEmail(UserAccountBean u, StudyUserRoleBean sub) throws Exception { StudyDAO sdao = new StudyDAO(sm.getDataSource()); StudyBean study = (StudyBean) sdao.findByPK(sub.getStudyId()); logger.info("Sending email..."); String body = u.getFirstName() + " " + u.getLastName() + " (" + resword.getString("username") + ": " + u.getName() + ") " + respage.getString("has_been_granted_the_role") + " " + sub.getRoleName() + " " + respage.getString("in_the_study_site") + " " + study.getName() + "."; // boolean emailSent = sendEmail(u.getEmail().trim(), respage.getString("set_user_role"), // body, false); // if (emailSent) { // sendEmail(ub.getEmail().trim(), respage.getString("set_user_role"), body, false); // sendEmail(EmailEngine.getAdminEmail(), respage.getString("set_user_role"), body, // false); // } return body; }
@Override protected void processRequest() throws Exception { FormProcessor fp = new FormProcessor(request); TriggerService triggerService = new TriggerService(); String action = fp.getString("action"); String triggerName = fp.getString("tname"); scheduler = getScheduler(); System.out.println("found trigger name " + triggerName); Trigger trigger = scheduler.getTrigger(triggerName.trim(), TRIGGER_IMPORT_GROUP); System.out.println("found trigger from the other side " + trigger.getFullName()); if (StringUtil.isBlank(action)) { setUpServlet(trigger); forwardPage(Page.UPDATE_JOB_IMPORT); } else if ("confirmall".equalsIgnoreCase(action)) { HashMap errors = triggerService.validateImportJobForm( fp, request, scheduler.getTriggerNames("DEFAULT"), trigger.getName()); if (!errors.isEmpty()) { // send back addPageMessage( "Your modifications caused an error, please see the messages for more information."); setUpServlet(trigger); forwardPage(Page.UPDATE_JOB_IMPORT); } else { StudyDAO studyDAO = new StudyDAO(sm.getDataSource()); int studyId = fp.getInt(CreateJobImportServlet.STUDY_ID); StudyBean study = (StudyBean) studyDAO.findByPK(studyId); // in the place of a users' current study, tbh Date startDate = trigger.getStartTime(); trigger = triggerService.generateImportTrigger( fp, sm.getUserBean(), study, startDate, request.getLocale().getLanguage()); // scheduler = getScheduler(); JobDetailBean jobDetailBean = new JobDetailBean(); jobDetailBean.setGroup(TRIGGER_IMPORT_GROUP); jobDetailBean.setName(trigger.getName()); jobDetailBean.setJobClass(org.akaza.openclinica.web.job.ImportStatefulJob.class); jobDetailBean.setJobDataMap(trigger.getJobDataMap()); jobDetailBean.setDurability(true); // need durability? jobDetailBean.setVolatility(false); try { scheduler.deleteJob(triggerName, TRIGGER_IMPORT_GROUP); Date dateStart = scheduler.scheduleJob(jobDetailBean, trigger); addPageMessage("Your job has been successfully modified."); forwardPage(Page.VIEW_IMPORT_JOB_SERVLET); } catch (SchedulerException se) { se.printStackTrace(); // set a message here with the exception message setUpServlet(trigger); addPageMessage( "There was an unspecified error with your creation, please contact an administrator."); forwardPage(Page.UPDATE_JOB_IMPORT); } } } }
private StudyBean getParentStudy(String studyOid) { StudyBean study = getStudy(studyOid); if (study.getParentStudyId() == 0) { return study; } else { StudyBean parentStudy = (StudyBean) sdao.findByPK(study.getParentStudyId()); return parentStudy; } }
@Override public void processRequest() throws Exception { FormProcessor fp = new FormProcessor(request); StudyGroupClassDAO sgcdao = new StudyGroupClassDAO(sm.getDataSource()); // YW << StudyDAO stdao = new StudyDAO(sm.getDataSource()); int parentStudyId = currentStudy.getParentStudyId(); ArrayList groups = new ArrayList(); if (parentStudyId > 0) { StudyBean parentStudy = (StudyBean) stdao.findByPK(parentStudyId); groups = sgcdao.findAllByStudy(parentStudy); } else { groups = sgcdao.findAllByStudy(currentStudy); } // YW >> String isReadOnly = request.getParameter("read"); StudyGroupDAO sgdao = new StudyGroupDAO(sm.getDataSource()); for (int i = 0; i < groups.size(); i++) { StudyGroupClassBean group = (StudyGroupClassBean) groups.get(i); ArrayList studyGroups = sgdao.findAllByGroupClass(group); group.setStudyGroups(studyGroups); } EntityBeanTable table = fp.getEntityBeanTable(); ArrayList allGroupRows = StudyGroupClassRow.generateRowsFromBeans(groups); boolean isParentStudy = currentStudy.getParentStudyId() > 0 ? false : true; request.setAttribute("isParentStudy", isParentStudy); String[] columns = { resword.getString("subject_group_class"), resword.getString("type"), resword.getString("subject_assignment"), resword.getString("study_name"), resword.getString("subject_groups"), resword.getString("status"), resword.getString("actions") }; table.setColumns(new ArrayList(Arrays.asList(columns))); table.hideColumnLink(4); table.hideColumnLink(6); table.setQuery("ListSubjectGroupClass", new HashMap()); // if (isParentStudy && (!currentStudy.getStatus().isLocked())) { // table.addLink(resword.getString("create_a_subject_group_class"), // "CreateSubjectGroupClass"); // } table.setRows(allGroupRows); table.computeDisplay(); request.setAttribute("table", table); if (request.getParameter("read") != null && request.getParameter("read").equals("true")) { request.setAttribute("readOnly", true); } forwardPage(Page.SUBJECT_GROUP_CLASS_LIST); }
/** Inserts the new study into database */ private void submitStudy() { FormProcessor fp = new FormProcessor(request); StudyDAO sdao = new StudyDAO(sm.getDataSource()); StudyBean study = (StudyBean) session.getAttribute("newStudy"); ArrayList parameters = study.getStudyParameters(); logger.info("study bean to be created:\n"); logger.info( study.getName() + "\n" + study.getIdentifier() + "\n" + study.getParentStudyId() + "\n" + study.getSummary() + "\n" + study.getPrincipalInvestigator() + "\n" + study.getDatePlannedStart() + "\n" + study.getDatePlannedEnd() + "\n" + study.getFacilityName() + "\n" + study.getFacilityCity() + "\n" + study.getFacilityState() + "\n" + study.getFacilityZip() + "\n" + study.getFacilityCountry() + "\n" + study.getFacilityRecruitmentStatus() + "\n" + study.getFacilityContactName() + "\n" + study.getFacilityContactEmail() + "\n" + study.getFacilityContactPhone() + "\n" + study.getFacilityContactDegree()); study.setOwner(ub); study.setCreatedDate(new Date()); StudyBean parent = (StudyBean) sdao.findByPK(study.getParentStudyId()); study.setType(parent.getType()); // YW 10-10-2007, enable setting site status study.setStatus(study.getStatus()); // YW >> study.setGenetic(parent.isGenetic()); study = (StudyBean) sdao.create(study); StudyParameterValueDAO spvdao = new StudyParameterValueDAO(sm.getDataSource()); for (int i = 0; i < parameters.size(); i++) { StudyParamsConfig config = (StudyParamsConfig) parameters.get(i); StudyParameterValueBean spv = config.getValue(); spv.setStudyId(study.getId()); spv = (StudyParameterValueBean) spvdao.create(config.getValue()); } // YW << here only "collectDob" and "genderRequired" have been corrected // for sites. StudyParameterValueBean spv = new StudyParameterValueBean(); StudyParameterValueBean parentSPV = spvdao.findByHandleAndStudy(parent.getId(), "collectDob"); spv.setStudyId(study.getId()); spv.setParameter("collectDob"); spv.setValue(parentSPV.getValue()); spvdao.create(spv); parentSPV = spvdao.findByHandleAndStudy(parent.getId(), "genderRequired"); spv.setParameter("genderRequired"); spv.setValue(parentSPV.getValue()); spvdao.create(spv); // YW >> // switch user to the newly created site session.setAttribute("study", session.getAttribute("newStudy")); currentStudy = (StudyBean) session.getAttribute("study"); session.removeAttribute("newStudy"); addPageMessage(respage.getString("the_new_site_created_succesfully_current")); forwardPage(Page.SITE_LIST_SERVLET); }
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("Please choose a study to restore."); forwardPage(Page.STUDY_LIST_SERVLET); } else { if ("confirm".equalsIgnoreCase(action)) { request.setAttribute("studyToRestore", study); request.setAttribute("sitesToRestore", sites); request.setAttribute("userRolesToRestore", userRoles); request.setAttribute("subjectsToRestore", subjects); request.setAttribute("definitionsToRRestore", definitions); forwardPage(Page.RESTORE_STUDY); } else { logger.info("submit to restore the study"); // change all statuses to unavailable StudyDAO studao = new StudyDAO(sm.getDataSource()); study.setStatus(Status.AVAILABLE); 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); site.setStatus(Status.AVAILABLE); 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); role.setStatus(Status.AVAILABLE); role.setUpdater(ub); role.setUpdatedDate(new Date()); udao.updateStudyUserRole(role, role.getUserName()); } // remove all subjects for (int i = 0; i < subjects.size(); i++) { StudySubjectBean subject = (StudySubjectBean) subjects.get(i); subject.setStatus(Status.AVAILABLE); subject.setUpdater(ub); subject.setUpdatedDate(new Date()); ssdao.update(subject); } // remove all study_group StudyGroupDAO sgdao = new StudyGroupDAO(sm.getDataSource()); SubjectGroupMapDAO sgmdao = new SubjectGroupMapDAO(sm.getDataSource()); ArrayList groups = sgdao.findAllByStudy(study); for (int i = 0; i < groups.size(); i++) { StudyGroupBean group = (StudyGroupBean) groups.get(i); group.setStatus(Status.AVAILABLE); group.setUpdater(ub); group.setUpdatedDate(new Date()); sgdao.update(group); // all subject_group_map ArrayList subjectGroupMaps = sgmdao.findAllByStudyGroupId(group.getId()); for (int j = 0; j < subjectGroupMaps.size(); j++) { SubjectGroupMapBean sgMap = (SubjectGroupMapBean) subjectGroupMaps.get(j); sgMap.setStatus(Status.AVAILABLE); sgMap.setUpdater(ub); sgMap.setUpdatedDate(new Date()); sgmdao.update(sgMap); } } // 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); definition.setStatus(Status.AVAILABLE); 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); edc.setStatus(Status.AVAILABLE); 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); event.setStatus(Status.AVAILABLE); 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); eventCRF.setStatus(Status.AVAILABLE); 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); item.setStatus(Status.AVAILABLE); 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); data.setStatus(Status.AVAILABLE); data.setUpdater(ub); data.setUpdatedDate(new Date()); datadao.update(data); } addPageMessage("This study has been restored successfully."); forwardPage(Page.STUDY_LIST_SERVLET); } } }
@Override public void processRequest() throws Exception { FormProcessor fp = new FormProcessor(request); int studySubId = fp.getInt(STUDY_SUB_ID, true); int eventCRFId = fp.getInt(EVENT_CRF_ID); String action = request.getParameter("action"); StudyEventDAO sedao = new StudyEventDAO(sm.getDataSource()); StudySubjectDAO subdao = new StudySubjectDAO(sm.getDataSource()); EventCRFDAO ecdao = new EventCRFDAO(sm.getDataSource()); StudyDAO sdao = new StudyDAO(sm.getDataSource()); if (eventCRFId == 0) { addPageMessage(respage.getString("please_choose_an_event_CRF_to_delete")); request.setAttribute("id", new Integer(studySubId).toString()); forwardPage(Page.VIEW_STUDY_SUBJECT_SERVLET); } else { EventCRFBean eventCRF = (EventCRFBean) ecdao.findByPK(eventCRFId); StudySubjectBean studySub = (StudySubjectBean) subdao.findByPK(studySubId); request.setAttribute("studySub", studySub); // construct info needed on view event crf page CRFDAO cdao = new CRFDAO(sm.getDataSource()); CRFVersionDAO cvdao = new CRFVersionDAO(sm.getDataSource()); int crfVersionId = eventCRF.getCRFVersionId(); CRFBean cb = cdao.findByVersionId(crfVersionId); eventCRF.setCrf(cb); CRFVersionBean cvb = (CRFVersionBean) cvdao.findByPK(crfVersionId); eventCRF.setCrfVersion(cvb); // then get the definition so we can call // DisplayEventCRFBean.setFlags int studyEventId = eventCRF.getStudyEventId(); StudyEventBean event = (StudyEventBean) sedao.findByPK(studyEventId); int studyEventDefinitionId = sedao.getDefinitionIdFromStudyEventId(studyEventId); StudyEventDefinitionDAO seddao = new StudyEventDefinitionDAO(sm.getDataSource()); StudyEventDefinitionBean sed = (StudyEventDefinitionBean) seddao.findByPK(studyEventDefinitionId); event.setStudyEventDefinition(sed); request.setAttribute("event", event); EventDefinitionCRFDAO edcdao = new EventDefinitionCRFDAO(sm.getDataSource()); StudyBean study = (StudyBean) sdao.findByPK(studySub.getStudyId()); EventDefinitionCRFBean edc = edcdao.findByStudyEventDefinitionIdAndCRFId(study, studyEventDefinitionId, cb.getId()); DisplayEventCRFBean dec = new DisplayEventCRFBean(); dec.setEventCRF(eventCRF); dec.setFlags(eventCRF, ub, currentRole, edc.isDoubleEntry()); // find all item data ItemDataDAO iddao = new ItemDataDAO(sm.getDataSource()); dnDao = new DiscrepancyNoteDAO(sm.getDataSource()); ArrayList<ItemDataBean> itemData = iddao.findAllByEventCRFId(eventCRF.getId()); request.setAttribute("items", itemData); if ("confirm".equalsIgnoreCase(action)) { request.setAttribute("displayEventCRF", dec); forwardPage(Page.DELETE_EVENT_CRF); } else { logger.info("submit to delete the event CRF from event"); // OC-6303 Deleting Event CRF resets Show / Hide logic // delete records from DynamicItemForm and DynamicItemGroup getDynamicsItemFormMetadataDao().delete(eventCRFId); getDynamicsItemGroupMetadataDao().delete(eventCRFId); eventCRF.setOldStatus(eventCRF.getStatus()); eventCRF.setStatus(Status.RESET); eventCRF.setUpdater(ub); ecdao.update(eventCRF); for (ItemDataBean itemdata : itemData) { // OC-6343 Rule behaviour must be reset if an Event CRF is deleted // delete the records from ruleActionRunLogDao getRuleActionRunLogDao().delete(itemdata.getId()); // OC-6344 Notes & Discrepancies must be set to "closed" when event CRF is deleted // parentDiscrepancyNoteList is the list of the parent DNs records only ArrayList<DiscrepancyNoteBean> parentDiscrepancyNoteList = getDnDao().findParentNotesOnlyByItemData(itemdata.getId()); for (DiscrepancyNoteBean parentDiscrepancyNote : parentDiscrepancyNoteList) { if (parentDiscrepancyNote.getResolutionStatusId() != 4) { // if the DN's resolution status is not set to Closed String description = resword.getString("dn_auto-closed_description"); String detailedNotes = resword.getString("dn_auto_closed_detailed_notes"); // create new DN record , new DN Map record , also update the parent record createDiscrepancyNoteBean( description, detailedNotes, itemdata.getId(), study, ub, parentDiscrepancyNote); } } iddao = new ItemDataDAO(sm.getDataSource()); ifmdao = new ItemFormMetadataDAO(sm.getDataSource()); ItemDataBean idBean = (ItemDataBean) iddao.findByPK(itemdata.getId()); ItemFormMetadataBean ifmBean = ifmdao.findByItemIdAndCRFVersionId(idBean.getItemId(), crfVersionId); // Updating Dn_item_data_map actovated column into false for the existing DNs ArrayList<DiscrepancyNoteBean> dnBeans = getDnDao().findExistingNotesForItemData(itemdata.getId()); if (dnBeans.size() != 0) { DiscrepancyNoteBean dnBean = new DiscrepancyNoteBean(); dnBean.setEntityId(itemdata.getId()); dnBean.setActivated(false); getDnDao().updateDnMapActivation(dnBean); } // Default Values are not addressed itemdata.setValue(""); itemdata.setOldStatus(itemdata.getStatus()); itemdata.setOwner(ub); itemdata.setStatus(Status.AVAILABLE); itemdata.setUpdater(ub); iddao.updateUser(itemdata); iddao.update(itemdata); } // OC-6291 event_crf status change eventCRF.setOldStatus(eventCRF.getStatus()); eventCRF.setStatus(Status.AVAILABLE); eventCRF.setUpdater(ub); ecdao.update(eventCRF); if (event.getSubjectEventStatus().isCompleted() || event.getSubjectEventStatus().isSigned()) { event.setSubjectEventStatus(SubjectEventStatus.DATA_ENTRY_STARTED); event.setUpdater(ub); sedao = new StudyEventDAO(sm.getDataSource()); sedao.update(event); } String emailBody = respage.getString("the_event_CRF") + cb.getName() + respage.getString("has_been_deleted_from_the_event") + event.getStudyEventDefinition().getName() + ". " + respage.getString("has_been_deleted_from_the_event_cont"); addPageMessage(emailBody); // sendEmail(emailBody); request.setAttribute("id", new Integer(studySubId).toString()); forwardPage(Page.VIEW_STUDY_SUBJECT_SERVLET); } } }
@Override public void processRequest() throws Exception { resetPanel(); FormProcessor fp = new FormProcessor(request); Validator v = new Validator(request); int studyId = fp.getInt("id"); studyId = studyId == 0 ? fp.getInt("studyId") : studyId; String action = fp.getString("action"); StudyDAO sdao = new StudyDAO(sm.getDataSource()); boolean isInterventional = false; study = (StudyBean) sdao.findByPK(studyId); if (study.getId() != currentStudy.getId()) { addPageMessage( respage.getString("not_current_study") + respage.getString("change_study_contact_sysadmin")); forwardPage(Page.MENU_SERVLET); return; } study.setId(studyId); StudyConfigService scs = new StudyConfigService(sm.getDataSource()); study = scs.setParametersForStudy(study); request.setAttribute("studyToView", study); request.setAttribute("studyId", studyId + ""); request.setAttribute("studyPhaseMap", CreateStudyServlet.studyPhaseMap); ArrayList statuses = Status.toStudyUpdateMembersList(); statuses.add(Status.PENDING); request.setAttribute("statuses", statuses); String interventional = resadmin.getString("interventional"); isInterventional = interventional.equalsIgnoreCase(study.getProtocolType()); request.setAttribute("isInterventional", isInterventional ? "1" : "0"); String protocolType = study.getProtocolTypeKey(); // A. Hamid. 5001 if (study.getParentStudyId() > 0) { StudyBean parentStudy = (StudyBean) sdao.findByPK(study.getParentStudyId()); request.setAttribute("parentStudy", parentStudy); } ArrayList interventionArray = new ArrayList(); if (isInterventional) { interventionArray = parseInterventions((study)); setMaps(isInterventional, interventionArray); } else { setMaps(isInterventional, interventionArray); } if (!action.equals("submit")) { // First Load First Form if (study.getDatePlannedStart() != null) { fp.addPresetValue(INPUT_START_DATE, local_df.format(study.getDatePlannedStart())); } if (study.getDatePlannedEnd() != null) { fp.addPresetValue(INPUT_END_DATE, local_df.format(study.getDatePlannedEnd())); } if (study.getProtocolDateVerification() != null) { fp.addPresetValue(INPUT_VER_DATE, local_df.format(study.getProtocolDateVerification())); } setPresetValues(fp.getPresetValues()); // first load 2nd form } if (study == null) { addPageMessage(respage.getString("please_choose_a_study_to_edit")); forwardPage(Page.STUDY_LIST_SERVLET); return; } if (action.equals("submit")) { validateStudy1(fp, v); validateStudy2(fp, v); validateStudy3(isInterventional, v, fp); validateStudy4(fp, v); validateStudy5(fp, v); validateStudy6(fp, v); confirmWholeStudy(fp, v); request.setAttribute("studyToView", study); if (!errors.isEmpty()) { System.out.println("found errors : " + errors.toString()); request.setAttribute("formMessages", errors); forwardPage(Page.UPDATE_STUDY_NEW); } else { study.setProtocolType(protocolType); submitStudy(study); addPageMessage(respage.getString("the_study_has_been_updated_succesfully")); ArrayList pageMessages = (ArrayList) request.getAttribute(PAGE_MESSAGE); session.setAttribute("pageMessages", pageMessages); response.sendRedirect(request.getContextPath() + "/pages/studymodule"); // forwardPage(Page.MANAGE_STUDY_MODULE); } } else { forwardPage(Page.UPDATE_STUDY_NEW); } }
private StudyBean getStudy(Integer id) { sdao = new StudyDAO(dataSource); StudyBean studyBean = (StudyBean) sdao.findByPK(id); return studyBean; }
@Override public void processRequest() throws Exception { String studySubIdString = request.getParameter("id"); // studySubjectId String subIdString = request.getParameter("subjectId"); String studyIdString = request.getParameter("studyId"); SubjectDAO sdao = new SubjectDAO(sm.getDataSource()); StudySubjectDAO subdao = new StudySubjectDAO(sm.getDataSource()); if (StringUtil.isBlank(studySubIdString) || StringUtil.isBlank(subIdString) || StringUtil.isBlank(studyIdString)) { addPageMessage(respage.getString("please_choose_a_study_subject_to_remove")); forwardPage(Page.LIST_STUDY_SUBJECT_SERVLET); } else { int studyId = Integer.valueOf(studyIdString.trim()).intValue(); int studySubId = Integer.valueOf(studySubIdString.trim()).intValue(); int subjectId = Integer.valueOf(subIdString.trim()).intValue(); SubjectBean subject = (SubjectBean) sdao.findByPK(subjectId); StudySubjectBean studySub = (StudySubjectBean) subdao.findByPK(studySubId); StudyDAO studydao = new StudyDAO(sm.getDataSource()); StudyBean study = (StudyBean) studydao.findByPK(studyId); // find study events StudyEventDAO sedao = new StudyEventDAO(sm.getDataSource()); ArrayList events = sedao.findAllByStudyAndStudySubjectId(study, studySubId); String action = request.getParameter("action"); if ("confirm".equalsIgnoreCase(action)) { if (!studySub.getStatus().equals(Status.AVAILABLE)) { addPageMessage( respage.getString("this_subject_is_not_available_for_this_study") + " " + respage.getString("please_contact_sysadmin_for_more_information")); forwardPage(Page.LIST_STUDY_SUBJECT_SERVLET); return; } request.setAttribute("subject", subject); request.setAttribute("study", study); request.setAttribute("studySub", studySub); request.setAttribute("events", events); forwardPage(Page.REMOVE_STUDY_SUBJECT); } else { logger.info("submit to remove the subject from study"); // remove subject from study studySub.setStatus(Status.DELETED); studySub.setUpdater(ub); studySub.setUpdatedDate(new Date()); subdao.update(studySub); // remove all study events // remove all event crfs 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.getName() + " " + respage.getString("has_been_removed_from_the_study") + study.getName() + "."; addPageMessage(emailBody); sendEmail(emailBody); forwardPage(Page.LIST_STUDY_SUBJECT_SERVLET); } } }
@Override protected void executeInternal(JobExecutionContext context) throws JobExecutionException { // need to generate a Locale so that user beans and other things will // generate normally Locale locale = new Locale("en-US"); ResourceBundleProvider.updateLocale(locale); ResourceBundle pageMessages = ResourceBundleProvider.getPageMessagesBundle(); // logger.debug("--"); // logger.debug("-- executing a job " + message + " at " + new // java.util.Date().toString()); JobDataMap dataMap = context.getMergedJobDataMap(); SimpleTrigger trigger = (SimpleTrigger) context.getTrigger(); try { ApplicationContext appContext = (ApplicationContext) context.getScheduler().getContext().get("applicationContext"); String studySubjectNumber = ((CoreResources) appContext.getBean("coreResources")).getField("extract.number"); coreResources = (CoreResources) appContext.getBean("coreResources"); ruleSetRuleDao = (RuleSetRuleDao) appContext.getBean("ruleSetRuleDao"); dataSource = (DataSource) appContext.getBean("dataSource"); mailSender = (OpenClinicaMailSender) appContext.getBean("openClinicaMailSender"); AuditEventDAO auditEventDAO = new AuditEventDAO(dataSource); // Scheduler scheduler = context.getScheduler(); // JobDetail detail = context.getJobDetail(); // jobDetailBean = (JobDetailBean) detail; /* * data map here should coincide with the job data map found in * CreateJobExportServlet, with the following code: jobDataMap = new * JobDataMap(); jobDataMap.put(DATASET_ID, datasetId); * jobDataMap.put(PERIOD, period); jobDataMap.put(EMAIL, email); * jobDataMap.put(TAB, tab); jobDataMap.put(CDISC, cdisc); * jobDataMap.put(SPSS, spss); */ String alertEmail = dataMap.getString(EMAIL); String localeStr = dataMap.getString(LOCALE); if (localeStr != null) { locale = new Locale(localeStr); ResourceBundleProvider.updateLocale(locale); pageMessages = ResourceBundleProvider.getPageMessagesBundle(); } int dsId = dataMap.getInt(DATASET_ID); String tab = dataMap.getString(TAB); String cdisc = dataMap.getString(CDISC); String cdisc12 = dataMap.getString(CDISC12); if (cdisc12 == null) { cdisc12 = "0"; } String cdisc13 = dataMap.getString(CDISC13); if (cdisc13 == null) { cdisc13 = "0"; } String cdisc13oc = dataMap.getString(CDISC13OC); if (cdisc13oc == null) { cdisc13oc = "0"; } String spss = dataMap.getString(SPSS); int userId = dataMap.getInt(USER_ID); int studyId = dataMap.getInt(STUDY_ID); // String datasetId = dataMap.getString(DATASET_ID); // int dsId = new Integer(datasetId).intValue(); // String userAcctId = dataMap.getString(USER_ID); // int userId = new Integer(userAcctId).intValue(); // why the flip-flop? if one property is set to 'true' we can // see jobs in another screen but all properties have to be // strings logger.debug("-- found the job: " + dsId + " dataset id"); // for (Iterator it = dataMap.entrySet().iterator(); it.hasNext();) // { // java.util.Map.Entry entry = (java.util.Map.Entry) it.next(); // Object key = entry.getKey(); // Object value = entry.getValue(); // // logger.debug("-- found datamap property: " + key.toString() + // // " : " + value.toString()); // } HashMap fileName = new HashMap<String, Integer>(); if (dsId > 0) { // trying to not throw an error if there's no dataset id DatasetDAO dsdao = new DatasetDAO(dataSource); DatasetBean datasetBean = (DatasetBean) dsdao.findByPK(dsId); StudyDAO studyDao = new StudyDAO(dataSource); UserAccountDAO userAccountDAO = new UserAccountDAO(dataSource); // hmm, three lines in the if block DRY? String generalFileDir = ""; String generalFileDirCopy = ""; String exportFilePath = SQLInitServlet.getField("exportFilePath"); String pattern = "yyyy" + File.separator + "MM" + File.separator + "dd" + File.separator + "HHmmssSSS" + File.separator; SimpleDateFormat sdfDir = new SimpleDateFormat(pattern); generalFileDir = DATASET_DIR + datasetBean.getId() + File.separator + sdfDir.format(new java.util.Date()); if (!"".equals(exportFilePath)) { generalFileDirCopy = SQLInitServlet.getField("filePath") + exportFilePath + File.separator; } // logger.debug("-- created the following dir: " + // generalFileDir); long sysTimeBegin = System.currentTimeMillis(); // set up the user bean here, tbh // logger.debug("-- gen tab file 00"); userBean = (UserAccountBean) userAccountDAO.findByPK(userId); // needs to also be captured by the servlet, tbh // logger.debug("-- gen tab file 00"); generateFileService = new GenerateExtractFileService(dataSource, userBean, coreResources, ruleSetRuleDao); // logger.debug("-- gen tab file 00"); // tbh #5796 - covers a bug when the user changes studies, 10/2010 StudyBean activeStudy = (StudyBean) studyDao.findByPK(studyId); StudyBean parentStudy = new StudyBean(); logger.debug( "active study: " + studyId + " parent study: " + activeStudy.getParentStudyId()); if (activeStudy.getParentStudyId() > 0) { // StudyDAO sdao = new StudyDAO(sm.getDataSource()); parentStudy = (StudyBean) studyDao.findByPK(activeStudy.getParentStudyId()); } else { parentStudy = activeStudy; // covers a bug in tab file creation, tbh 01/2009 } logger.debug("-- found extract bean "); ExtractBean eb = generateFileService.generateExtractBean(datasetBean, activeStudy, parentStudy); MessageFormat mf = new MessageFormat(""); StringBuffer message = new StringBuffer(); StringBuffer auditMessage = new StringBuffer(); // use resource bundle page messages to generate the email, tbh // 02/2009 // message.append(pageMessages.getString("html_email_header_1") // + " " + alertEmail + // pageMessages.getString("html_email_header_2") + "<br/>"); message.append( "<p>" + pageMessages.getString("email_header_1") + " " + EmailEngine.getAdminEmail() + " " + pageMessages.getString("email_header_2") + " Job Execution " + pageMessages.getString("email_header_3") + "</p>"); message.append("<P>Dataset: " + datasetBean.getName() + "</P>"); message.append("<P>Study: " + activeStudy.getName() + "</P>"); message.append( "<p>" + pageMessages.getString("html_email_body_1") + datasetBean.getName() + pageMessages.getString("html_email_body_2") + SQLInitServlet.getField("sysURL") + pageMessages.getString("html_email_body_3") + "</p>"); // logger.debug("-- gen tab file 00"); if ("1".equals(tab)) { logger.debug("-- gen tab file 01"); fileName = generateFileService.createTabFile( eb, sysTimeBegin, generalFileDir, datasetBean, activeStudy.getId(), parentStudy.getId(), generalFileDirCopy); message.append( "<p>" + pageMessages.getString("html_email_body_4") + " " + getFileNameStr(fileName) + pageMessages.getString("html_email_body_4_5") + SQLInitServlet.getField("sysURL.base") + "AccessFile?fileId=" + getFileIdInt(fileName) + pageMessages.getString("html_email_body_3") + "</p>"); // MessageFormat mf = new MessageFormat(""); // mf.applyPattern(pageMessages.getString( // "you_can_access_tab_delimited")); // Object[] arguments = { getFileIdInt(fileName) }; // auditMessage.append(mf.format(arguments)); // auditMessage.append( // "You can access your tab-delimited file <a href='AccessFile?fileId=" // + getFileIdInt(fileName) + "'>here</a>.<br/>"); auditMessage.append( pageMessages.getString("you_can_access_tab_delimited") + getFileIdInt(fileName) + pageMessages.getString("access_end")); } if ("1".equals(cdisc)) { String odmVersion = "oc1.2"; fileName = generateFileService.createODMFile( odmVersion, sysTimeBegin, generalFileDir, datasetBean, activeStudy, generalFileDirCopy, eb, activeStudy.getId(), parentStudy.getId(), studySubjectNumber, true, true, true, null); logger.debug("-- gen odm file"); message.append( "<p>" + pageMessages.getString("html_email_body_4") + " " + getFileNameStr(fileName) + pageMessages.getString("html_email_body_4_5") + SQLInitServlet.getField("sysURL.base") + "AccessFile?fileId=" + getFileIdInt(fileName) + pageMessages.getString("html_email_body_3") + "</p>"); // MessageFormat mf = new MessageFormat(""); // mf.applyPattern(pageMessages.getString( // "you_can_access_odm_12")); // Object[] arguments = { getFileIdInt(fileName) }; // auditMessage.append(mf.format(arguments)); // auditMessage.append( // "You can access your ODM 1.2 w/OpenClinica Extension XML file <a // href='AccessFile?fileId=" // + getFileIdInt(fileName) // + "'>here</a>.<br/>"); auditMessage.append( pageMessages.getString("you_can_access_odm_12") + getFileIdInt(fileName) + pageMessages.getString("access_end")); } if ("1".equals(cdisc12)) { String odmVersion = "1.2"; fileName = generateFileService.createODMFile( odmVersion, sysTimeBegin, generalFileDir, datasetBean, activeStudy, generalFileDirCopy, eb, activeStudy.getId(), parentStudy.getId(), studySubjectNumber, true, true, true, null); logger.debug("-- gen odm file 1.2 default"); message.append( "<p>" + pageMessages.getString("html_email_body_4") + " " + getFileNameStr(fileName) + pageMessages.getString("html_email_body_4_5") + SQLInitServlet.getField("sysURL.base") + "AccessFile?fileId=" + getFileIdInt(fileName) + pageMessages.getString("html_email_body_3") + "</p>"); // mf.applyPattern(pageMessages.getString( // "you_can_access_odm_12_xml")); // Object[] arguments = { getFileIdInt(fileName) }; // auditMessage.append(mf.format(arguments)); // // auditMessage.append( // "You can access your ODM 1.2 XML file <a href='AccessFile?fileId=" // + getFileIdInt(fileName) + "'>here</a>.<br/>"); auditMessage.append( pageMessages.getString("you_can_access_odm_12_xml") + getFileIdInt(fileName) + pageMessages.getString("access_end")); } if ("1".equals(cdisc13)) { String odmVersion = "1.3"; fileName = generateFileService.createODMFile( odmVersion, sysTimeBegin, generalFileDir, datasetBean, activeStudy, generalFileDirCopy, eb, activeStudy.getId(), parentStudy.getId(), studySubjectNumber, true, true, true, null); logger.debug("-- gen odm file 1.3"); message.append( "<p>" + pageMessages.getString("html_email_body_4") + " " + getFileNameStr(fileName) + pageMessages.getString("html_email_body_4_5") + SQLInitServlet.getField("sysURL.base") + "AccessFile?fileId=" + getFileIdInt(fileName) + pageMessages.getString("html_email_body_3") + "</p>"); // MessageFormat mf = new MessageFormat(""); // mf.applyPattern(pageMessages.getString( // "you_can_access_odm_13")); // Object[] arguments = { getFileIdInt(fileName) }; // auditMessage.append(mf.format(arguments)); // auditMessage.append( // "You can access your ODM 1.3 XML file <a href='AccessFile?fileId=" // + getFileIdInt(fileName) + "'>here</a>.<br/>"); auditMessage.append( pageMessages.getString("you_can_access_odm_13") + getFileIdInt(fileName) + pageMessages.getString("access_end")); } if ("1".equals(cdisc13oc)) { String odmVersion = "oc1.3"; fileName = generateFileService.createODMFile( odmVersion, sysTimeBegin, generalFileDir, datasetBean, activeStudy, generalFileDirCopy, eb, activeStudy.getId(), parentStudy.getId(), studySubjectNumber, true, true, true, null); logger.debug("-- gen odm file 1.3 oc"); message.append( "<p>" + pageMessages.getString("html_email_body_4") + " " + getFileNameStr(fileName) + pageMessages.getString("html_email_body_4_5") + SQLInitServlet.getField("sysURL.base") + "AccessFile?fileId=" + getFileIdInt(fileName) + pageMessages.getString("html_email_body_3") + "</p>"); // MessageFormat mf = new MessageFormat(""); // mf.applyPattern(pageMessages.getString( // "you_can_access_odm_13_xml")); // Object[] arguments = { getFileIdInt(fileName) }; // auditMessage.append(mf.format(arguments)); // auditMessage.append( // "You can access your ODM 1.3 w/OpenClinica Extension XML file <a // href='AccessFile?fileId=" // + getFileIdInt(fileName) // + "'>here</a>.<br/>"); auditMessage.append( pageMessages.getString("you_can_access_odm_13_xml") + getFileIdInt(fileName) + pageMessages.getString("access_end")); } if ("1".equals(spss)) { SPSSReportBean answer = new SPSSReportBean(); fileName = generateFileService.createSPSSFile( datasetBean, eb, activeStudy, parentStudy, sysTimeBegin, generalFileDir, answer, generalFileDirCopy); logger.debug("-- gen spss file"); message.append( "<p>" + pageMessages.getString("html_email_body_4") + " " + getFileNameStr(fileName) + pageMessages.getString("html_email_body_4_5") + SQLInitServlet.getField("sysURL.base") + "AccessFile?fileId=" + getFileIdInt(fileName) + pageMessages.getString("html_email_body_3") + "</p>"); // MessageFormat mf = new MessageFormat(""); // mf.applyPattern(pageMessages.getString( // "you_can_access_spss")); // Object[] arguments = { getFileIdInt(fileName) }; // auditMessage.append(mf.format(arguments)); // auditMessage.append( // "You can access your SPSS files <a href='AccessFile?fileId=" // + getFileIdInt(fileName) + "'>here</a>.<br/>"); auditMessage.append( pageMessages.getString("you_can_access_spss") + getFileIdInt(fileName) + pageMessages.getString("access_end")); } // wrap up the message, and send the email message.append( "<p>" + pageMessages.getString("html_email_body_5") + "</P><P>" + pageMessages.getString("email_footer")); try { mailSender.sendEmail( alertEmail.trim(), pageMessages.getString("job_ran_for") + " " + datasetBean.getName(), message.toString(), true); } catch (OpenClinicaSystemException ose) { // Do Nothing, In the future we might want to have an email // status added to system. } TriggerBean triggerBean = new TriggerBean(); triggerBean.setDataset(datasetBean); triggerBean.setUserAccount(userBean); triggerBean.setFullName(trigger.getName()); auditEventDAO.createRowForExtractDataJobSuccess(triggerBean, auditMessage.toString()); } else { TriggerBean triggerBean = new TriggerBean(); // triggerBean.setDataset(datasetBean); triggerBean.setUserAccount(userBean); triggerBean.setFullName(trigger.getName()); auditEventDAO.createRowForExtractDataJobFailure(triggerBean); // logger.debug("-- made it here for some reason, ds id: " // + dsId); } // logger.debug("-- generated file: " + fileNameStr); // dataSource. } catch (Exception e) { // TODO Auto-generated catch block -- ideally should generate a fail // msg here, tbh 02/2009 logger.debug("-- found exception: " + e.getMessage()); e.printStackTrace(); } }
@Override public void processRequest() throws Exception { UserAccountDAO udao = new UserAccountDAO(sm.getDataSource()); StudyDAO sdao = new StudyDAO(sm.getDataSource()); String name = request.getParameter("name"); String studyIdString = request.getParameter("studyId"); if (StringUtil.isBlank(name) || StringUtil.isBlank(studyIdString)) { addPageMessage(respage.getString("please_choose_a_user_to_set_role_for")); forwardPage(Page.LIST_USER_IN_STUDY_SERVLET); } else { String action = request.getParameter("action"); FormProcessor fp = new FormProcessor(request); UserAccountBean user = (UserAccountBean) udao.findByUserName(name); StudyBean userStudy = (StudyBean) sdao.findByPK(fp.getInt("studyId")); if ("confirm".equalsIgnoreCase(action)) { int studyId = Integer.valueOf(studyIdString.trim()).intValue(); request.setAttribute("user", user); StudyUserRoleBean uRole = udao.findRoleByUserNameAndStudyId(name, studyId); uRole.setStudyName(userStudy.getName()); request.setAttribute("uRole", uRole); ArrayList roles = Role.toArrayList(); roles.remove(Role.ADMIN); // admin is not a user role, only used for tomcat StudyBean studyBean = (StudyBean) sdao.findByPK(uRole.getStudyId()); if (currentStudy.getParentStudyId() > 0) { roles.remove(Role.COORDINATOR); roles.remove(Role.STUDYDIRECTOR); } else if (studyBean.getParentStudyId() > 0) { roles.remove(Role.COORDINATOR); roles.remove(Role.STUDYDIRECTOR); // TODO: redo this fix Role r = Role.RESEARCHASSISTANT; r.setDescription("site_Data_Entry_Person"); roles.remove(Role.RESEARCHASSISTANT); roles.add(r); Role ri = Role.INVESTIGATOR; ri.setDescription("site_investigator"); roles.remove(Role.INVESTIGATOR); roles.add(ri); } request.setAttribute("roles", roles); forwardPage(Page.SET_USER_ROLE_IN_STUDY); } else { // set role String userName = fp.getString("name"); int studyId = fp.getInt("studyId"); int roleId = fp.getInt("roleId"); StudyUserRoleBean sur = new StudyUserRoleBean(); sur.setName(userName); sur.setRole(Role.get(roleId)); sur.setStudyId(studyId); sur.setStudyName(userStudy.getName()); sur.setStatus(Status.AVAILABLE); sur.setUpdater(ub); sur.setUpdatedDate(new Date()); udao.updateStudyUserRole(sur, userName); addPageMessage(sendEmail(user, sur)); forwardPage(Page.LIST_USER_IN_STUDY_SERVLET); } } }