Search in sources :

Example 16 with DatasetDAO

use of org.akaza.openclinica.dao.extract.DatasetDAO in project OpenClinica by OpenClinica.

the class CreateJobExportServlet method setUpServlet.

private void setUpServlet() {
    // TODO find all the form items and re-populate them if necessary
    FormProcessor fp2 = new FormProcessor(request);
    // Enumeration enumeration = request.getAttributeNames();
    // while (enumeration.hasMoreElements()) {
    // String attrName = (String)enumeration.nextElement();
    // if (fp.getString(attrName) != null) {
    // request.setAttribute(attrName, fp.getString(attrName));
    // }
    // // possible error with dates? yep
    // }
    DatasetDAO dsdao = new DatasetDAO(sm.getDataSource());
    Collection dsList = dsdao.findAllOrderByStudyIdAndName();
    // TODO will have to dress this up to allow for sites then datasets
    request.setAttribute("datasets", dsList);
    request.setAttribute(JOB_NAME, fp2.getString(JOB_NAME));
    request.setAttribute(JOB_DESC, fp2.getString(JOB_DESC));
    request.setAttribute("extractProperties", CoreResources.getExtractProperties());
    request.setAttribute(EMAIL, fp2.getString(EMAIL));
    request.setAttribute(FORMAT_ID, fp2.getInt(FORMAT_ID));
    request.setAttribute(PERIOD, fp2.getString(PERIOD));
    request.setAttribute(DATASET_ID, fp2.getInt(DATASET_ID));
    Date jobDate = fp2.getDateTime(DATE_START_JOB);
    HashMap presetValues = new HashMap();
    Calendar calendar = new GregorianCalendar();
    calendar.setTime(jobDate);
    presetValues.put(DATE_START_JOB + "Hour", calendar.get(Calendar.HOUR_OF_DAY));
    presetValues.put(DATE_START_JOB + "Minute", calendar.get(Calendar.MINUTE));
    presetValues.put(DATE_START_JOB + "Date", local_df.format(jobDate));
    // (calendar.get(Calendar.MONTH) + 1) + "/" +
    // calendar.get(Calendar.DATE) + "/" + calendar.get(Calendar.YEAR));
    fp2.setPresetValues(presetValues);
    setPresetValues(fp2.getPresetValues());
    request.setAttribute(DATE_START_JOB, fp2.getDateTime(DATE_START_JOB + "Date"));
// EMAIL, TAB, CDISC, SPSS, PERIOD, DATE_START_JOB
// TODO pick out the datasets and the date
}
Also used : FormProcessor(org.akaza.openclinica.control.form.FormProcessor) DatasetDAO(org.akaza.openclinica.dao.extract.DatasetDAO)

Example 17 with DatasetDAO

use of org.akaza.openclinica.dao.extract.DatasetDAO in project OpenClinica by OpenClinica.

the class ViewJobServlet method processRequest.

@Override
protected void processRequest() throws Exception {
    // TODO single stage servlet where we get the list of jobs
    // and push them out to the JSP page
    // related classes will be required to generate the table rows
    // and eventually links to view and edit the jobs as well
    FormProcessor fp = new FormProcessor(request);
    // First we must get a reference to a scheduler
    scheduler = getScheduler();
    XsltTriggerService xsltTriggerSrvc = new XsltTriggerService();
    // Scheduler sched = sfb.getScheduler();
    Set<TriggerKey> triggerKeys = scheduler.getTriggerKeys(GroupMatcher.triggerGroupEquals(xsltTriggerSrvc.getTriggerGroupNameForExportJobs()));
    String[] triggerNames = triggerKeys.stream().toArray(String[]::new);
    //      String[]    triggerNames          =           scheduler.getJobNames(XsltTriggerService.TRIGGER_GROUP_NAME);
    // logger.info("trigger list: "+triggerNames.length);
    // logger.info("trigger names: "+triggerNames.toString());
    ArrayList triggerBeans = new ArrayList();
    for (String triggerName : triggerNames) {
        Trigger trigger = scheduler.getTrigger(TriggerKey.triggerKey(triggerName, xsltTriggerSrvc.getTriggerGroupNameForExportJobs()));
        try {
            logger.debug("prev fire time " + trigger.getPreviousFireTime().toString());
            logger.debug("next fire time " + trigger.getNextFireTime().toString());
            logger.debug("final fire time: " + trigger.getFinalFireTime().toString());
        } catch (NullPointerException npe) {
        // could be nulls in the dates, etc
        }
        // logger.info(trigger.getDescription());
        // logger.info("");//getJobDataMap()
        TriggerBean triggerBean = new TriggerBean();
        triggerBean.setFullName(trigger.getKey().getName());
        triggerBean.setPreviousDate(trigger.getPreviousFireTime());
        triggerBean.setNextDate(trigger.getNextFireTime());
        if (trigger.getDescription() != null) {
            triggerBean.setDescription(trigger.getDescription());
        }
        // setting: frequency, dataset name
        JobDataMap dataMap = new JobDataMap();
        DatasetDAO datasetDAO = new DatasetDAO(sm.getDataSource());
        StudyDAO studyDao = new StudyDAO(sm.getDataSource());
        if (trigger.getJobDataMap().size() > 0) {
            dataMap = trigger.getJobDataMap();
            int dsId = dataMap.getInt(ExampleSpringJob.DATASET_ID);
            String periodToRun = dataMap.getString(ExampleSpringJob.PERIOD);
            triggerBean.setPeriodToRun(periodToRun);
            DatasetBean dataset = (DatasetBean) datasetDAO.findByPK(dsId);
            triggerBean.setDataset(dataset);
            triggerBean.setDatasetName(dataset.getName());
            StudyBean study = (StudyBean) studyDao.findByPK(dataset.getStudyId());
            triggerBean.setStudyName(study.getName());
        // triggerBean.setStudyName(dataMap.getString(ExampleSpringJob.STUDY_NAME));
        }
        logger.debug("Trigger Priority: " + trigger.getKey().getName() + " " + trigger.getPriority());
        if (scheduler.getTriggerState(TriggerKey.triggerKey(triggerName, XsltTriggerService.TRIGGER_GROUP_NAME)) == Trigger.TriggerState.PAUSED) {
            triggerBean.setActive(false);
            logger.debug("setting active to false for trigger: " + trigger.getKey().getName());
        } else {
            triggerBean.setActive(true);
            logger.debug("setting active to TRUE for trigger: " + trigger.getKey().getName());
        }
        triggerBeans.add(triggerBean);
    // our wrapper to show triggers
    }
    ArrayList allRows = TriggerRow.generateRowsFromBeans(triggerBeans);
    EntityBeanTable table = fp.getEntityBeanTable();
    String[] columns = { resword.getString("name"), resword.getString("previous_fire_time"), resword.getString("next_fire_time"), resword.getString("description"), resword.getString("period_to_run"), resword.getString("dataset"), resword.getString("study"), resword.getString("actions") };
    table.setColumns(new ArrayList(Arrays.asList(columns)));
    table.hideColumnLink(3);
    table.hideColumnLink(7);
    table.setQuery("ViewJob", new HashMap());
    // table.addLink("", "CreateUserAccount");
    table.setSortingColumnInd(0);
    table.setRows(allRows);
    table.computeDisplay();
    request.setAttribute("table", table);
    // throw new NullPointerException("faking an error here");
    forwardPage(Page.VIEW_JOB);
}
Also used : TriggerBean(org.akaza.openclinica.bean.admin.TriggerBean) JobDataMap(org.quartz.JobDataMap) HashMap(java.util.HashMap) FormProcessor(org.akaza.openclinica.control.form.FormProcessor) EntityBeanTable(org.akaza.openclinica.web.bean.EntityBeanTable) DatasetBean(org.akaza.openclinica.bean.extract.DatasetBean) StudyBean(org.akaza.openclinica.bean.managestudy.StudyBean) ArrayList(java.util.ArrayList) DatasetDAO(org.akaza.openclinica.dao.extract.DatasetDAO) TriggerKey(org.quartz.TriggerKey) Trigger(org.quartz.Trigger) XsltTriggerService(org.akaza.openclinica.service.extract.XsltTriggerService) StudyDAO(org.akaza.openclinica.dao.managestudy.StudyDAO)

Example 18 with DatasetDAO

use of org.akaza.openclinica.dao.extract.DatasetDAO in project OpenClinica by OpenClinica.

the class ViewSingleJobServlet method processRequest.

@Override
protected void processRequest() throws Exception {
    FormProcessor fp = new FormProcessor(request);
    // changes to this servlet, we now look at group name too, tbh 05/2009
    String triggerName = fp.getString("tname");
    String gName = fp.getString("gname");
    String groupName = "";
    if (gName.equals("") || gName.equals("0")) {
        groupName = XsltTriggerService.TRIGGER_GROUP_NAME;
    } else {
        // if (gName.equals("1")) {
        groupName = TRIGGER_IMPORT_GROUP;
    }
    // << tbh 09/03/2009 #4143
    scheduler = getScheduler();
    Trigger trigger = scheduler.getTrigger(new TriggerKey(triggerName, groupName));
    if (trigger == null) {
        groupName = XsltTriggerService.TRIGGER_GROUP_NAME;
        trigger = scheduler.getTrigger(new TriggerKey(triggerName.trim(), groupName));
    }
    // << tbh 09/03/2009 #4143
    // above is a hack, if we add more trigger groups this will have
    // to be redone
    logger.debug("found trigger name: " + triggerName);
    logger.debug("found group name: " + groupName);
    TriggerBean triggerBean = new TriggerBean();
    JobDataMap dataMap = new JobDataMap();
    AuditEventDAO auditEventDAO = new AuditEventDAO(sm.getDataSource());
    try {
        triggerBean.setFullName(trigger.getKey().getName());
        triggerBean.setPreviousDate(trigger.getPreviousFireTime());
        triggerBean.setNextDate(trigger.getNextFireTime());
        // >> set active here, tbh 10/08/2009
        if (scheduler.getTriggerState(new TriggerKey(triggerName, groupName)) == Trigger.TriggerState.PAUSED) {
            triggerBean.setActive(false);
            logger.debug("setting active to false for trigger: " + trigger.getKey().getName());
        } else {
            triggerBean.setActive(true);
            logger.debug("setting active to TRUE for trigger: " + trigger.getKey().getName());
        }
        // <<
        if (trigger.getDescription() != null) {
            triggerBean.setDescription(trigger.getDescription());
        }
        if (trigger.getJobDataMap().size() > 0) {
            dataMap = trigger.getJobDataMap();
            String contactEmail = dataMap.getString(XsltTriggerService.EMAIL);
            logger.debug("found email: " + contactEmail);
            // int dsId = new Integer(datasetId).intValue();
            if (gName.equals("") || gName.equals("0")) {
                String exportFormat = dataMap.getString(XsltTriggerService.EXPORT_FORMAT);
                String periodToRun = dataMap.getString(ExampleSpringJob.PERIOD);
                // int userId = new Integer(userAcctId).intValue();
                int dsId = dataMap.getInt(ExampleSpringJob.DATASET_ID);
                triggerBean.setExportFormat(exportFormat);
                triggerBean.setPeriodToRun(periodToRun);
                DatasetDAO datasetDAO = new DatasetDAO(sm.getDataSource());
                DatasetBean dataset = (DatasetBean) datasetDAO.findByPK(dsId);
                triggerBean.setDataset(dataset);
            }
            int userId = dataMap.getInt(ExampleSpringJob.USER_ID);
            // need to set information, extract bean, user account bean
            UserAccountDAO userAccountDAO = new UserAccountDAO(sm.getDataSource());
            triggerBean.setContactEmail(contactEmail);
            UserAccountBean userAccount = (UserAccountBean) userAccountDAO.findByPK(userId);
            triggerBean.setUserAccount(userAccount);
            ArrayList<AuditEventBean> triggerLogs = auditEventDAO.findAllByAuditTable(trigger.getKey().getName());
            // set the table for the audit event beans here
            ArrayList allRows = AuditEventRow.generateRowsFromBeans(triggerLogs);
            EntityBeanTable table = fp.getEntityBeanTable();
            String[] columns = { resword.getString("date_and_time"), resword.getString("action_message"), resword.getString("entity_operation"), // resword.getString("study_subject_ID"),
            resword.getString("changes_and_additions"), resword.getString("actions") };
            table.setColumns(new ArrayList(Arrays.asList(columns)));
            table.setAscendingSort(false);
            table.hideColumnLink(1);
            table.hideColumnLink(3);
            table.hideColumnLink(4);
            table.setQuery("ViewSingleJob?tname=" + triggerName + "&gname=" + gName, new HashMap());
            table.setRows(allRows);
            table.computeDisplay();
            request.setAttribute("table", table);
        }
    } catch (NullPointerException e) {
        // TODO Auto-generated catch block
        logger.debug(" found NPE " + e.getMessage());
        e.printStackTrace();
    }
    // need to show the extract for which this runs, which files, etc
    // in other words the job data map
    request.setAttribute("triggerBean", triggerBean);
    request.setAttribute("groupName", groupName);
    forwardPage(Page.VIEW_SINGLE_JOB);
}
Also used : TriggerBean(org.akaza.openclinica.bean.admin.TriggerBean) JobDataMap(org.quartz.JobDataMap) HashMap(java.util.HashMap) FormProcessor(org.akaza.openclinica.control.form.FormProcessor) EntityBeanTable(org.akaza.openclinica.web.bean.EntityBeanTable) DatasetBean(org.akaza.openclinica.bean.extract.DatasetBean) ArrayList(java.util.ArrayList) AuditEventDAO(org.akaza.openclinica.dao.admin.AuditEventDAO) DatasetDAO(org.akaza.openclinica.dao.extract.DatasetDAO) UserAccountDAO(org.akaza.openclinica.dao.login.UserAccountDAO) TriggerKey(org.quartz.TriggerKey) Trigger(org.quartz.Trigger) UserAccountBean(org.akaza.openclinica.bean.login.UserAccountBean) AuditEventBean(org.akaza.openclinica.bean.admin.AuditEventBean)

Example 19 with DatasetDAO

use of org.akaza.openclinica.dao.extract.DatasetDAO in project OpenClinica by OpenClinica.

the class UpdateJobExportServlet method setUpServlet.

private void setUpServlet(Trigger trigger) {
    FormProcessor fp2 = new FormProcessor(request);
    DatasetDAO dsdao = new DatasetDAO(sm.getDataSource());
    Collection dsList = dsdao.findAllOrderByStudyIdAndName();
    // TODO will have to dress this up to allow for sites then datasets
    request.setAttribute("datasets", dsList);
    request.setAttribute(CreateJobExportServlet.JOB_NAME, trigger.getKey().getName());
    request.setAttribute(CreateJobExportServlet.JOB_DESC, trigger.getDescription());
    dataMap = trigger.getJobDataMap();
    String contactEmail = dataMap.getString(ExampleSpringJob.EMAIL);
    int dsId = dataMap.getInt(XsltTriggerService.DATASET_ID);
    int userId = dataMap.getInt(XsltTriggerService.USER_ID);
    String period = dataMap.getString(XsltTriggerService.PERIOD);
    int exportFormatId = dataMap.getInt(XsltTriggerService.EXPORT_FORMAT_ID);
    request.setAttribute(FORMAT_ID, exportFormatId);
    request.setAttribute(ExampleSpringJob.EMAIL, contactEmail);
    // how to find out the period of time???
    request.setAttribute(PERIOD, period);
    request.setAttribute(DATASET_ID, dsId);
    request.setAttribute("extractProperties", CoreResources.getExtractProperties());
    // DatasetBean dataset = (DatasetBean)dsdao.findByPK(dsId);
    // >> tbh 5639: collate the correct study id
    // request.setAttribute("study_id", dataset.getStudyId());
    Date jobDate = trigger.getNextFireTime();
    HashMap presetValues = new HashMap();
    Calendar calendar = new GregorianCalendar();
    calendar.setTime(jobDate);
    presetValues.put(CreateJobExportServlet.DATE_START_JOB + "Hour", calendar.get(Calendar.HOUR_OF_DAY));
    presetValues.put(CreateJobExportServlet.DATE_START_JOB + "Minute", calendar.get(Calendar.MINUTE));
    presetValues.put(CreateJobExportServlet.DATE_START_JOB + "Date", local_df.format(jobDate));
    // (calendar.get(Calendar.MONTH) + 1) + "/" +
    // calendar.get(Calendar.DATE) + "/"
    // + calendar.get(Calendar.YEAR));
    fp2.setPresetValues(presetValues);
    setPresetValues(fp2.getPresetValues());
// request.setAttribute(DATE_START_JOB, fp2.getDateTime(DATE_START_JOB +
// "Date"));
// EMAIL, TAB, CDISC, SPSS, PERIOD, DATE_START_JOB
// TODO pick out the datasets and the date
}
Also used : FormProcessor(org.akaza.openclinica.control.form.FormProcessor) Calendar(java.util.Calendar) DatasetDAO(org.akaza.openclinica.dao.extract.DatasetDAO)

Example 20 with DatasetDAO

use of org.akaza.openclinica.dao.extract.DatasetDAO in project OpenClinica by OpenClinica.

the class ShowFileServlet method processRequest.

@Override
public void processRequest() throws Exception {
    FormProcessor fp = new FormProcessor(request);
    int fileId = fp.getInt("fileId");
    int dsId = fp.getInt("datasetId");
    DatasetDAO dsdao = new DatasetDAO(sm.getDataSource());
    DatasetBean db = (DatasetBean) dsdao.findByPK(dsId);
    ArchivedDatasetFileDAO asdfdao = new ArchivedDatasetFileDAO(sm.getDataSource());
    ArchivedDatasetFileBean asdfBean = (ArchivedDatasetFileBean) asdfdao.findByPK(fileId);
    ArrayList newFileList = new ArrayList();
    newFileList.add(asdfBean);
    // request.setAttribute("filelist",newFileList);
    ArrayList filterRows = ArchivedDatasetFileRow.generateRowsFromBeans(newFileList);
    EntityBeanTable table = fp.getEntityBeanTable();
    String[] columns = { resword.getString("file_name"), resword.getString("run_time"), resword.getString("file_size"), resword.getString("created_date"), resword.getString("created_by") };
    table.setColumns(new ArrayList(Arrays.asList(columns)));
    table.hideColumnLink(0);
    table.hideColumnLink(1);
    table.hideColumnLink(2);
    table.hideColumnLink(3);
    table.hideColumnLink(4);
    // table.setQuery("ExportDataset?datasetId=" +db.getId(), new
    // HashMap());
    // trying to continue...
    // session.setAttribute("newDataset",db);
    request.setAttribute("dataset", db);
    request.setAttribute("file", asdfBean);
    table.setRows(filterRows);
    table.computeDisplay();
    request.setAttribute("table", table);
    Page finalTarget = Page.EXPORT_DATA_CUSTOM;
    finalTarget.setFileName("/WEB-INF/jsp/extract/generateMetadataFile.jsp");
    forwardPage(finalTarget);
}
Also used : ArchivedDatasetFileDAO(org.akaza.openclinica.dao.extract.ArchivedDatasetFileDAO) FormProcessor(org.akaza.openclinica.control.form.FormProcessor) EntityBeanTable(org.akaza.openclinica.web.bean.EntityBeanTable) DatasetBean(org.akaza.openclinica.bean.extract.DatasetBean) ArrayList(java.util.ArrayList) Page(org.akaza.openclinica.view.Page) DatasetDAO(org.akaza.openclinica.dao.extract.DatasetDAO) ArchivedDatasetFileBean(org.akaza.openclinica.bean.extract.ArchivedDatasetFileBean)

Aggregations

DatasetDAO (org.akaza.openclinica.dao.extract.DatasetDAO)27 DatasetBean (org.akaza.openclinica.bean.extract.DatasetBean)19 FormProcessor (org.akaza.openclinica.control.form.FormProcessor)18 StudyDAO (org.akaza.openclinica.dao.managestudy.StudyDAO)15 ArrayList (java.util.ArrayList)14 StudyBean (org.akaza.openclinica.bean.managestudy.StudyBean)14 HashMap (java.util.HashMap)11 EntityBeanTable (org.akaza.openclinica.web.bean.EntityBeanTable)9 Date (java.util.Date)7 UserAccountDAO (org.akaza.openclinica.dao.login.UserAccountDAO)7 SimpleDateFormat (java.text.SimpleDateFormat)6 StudyEventDAO (org.akaza.openclinica.dao.managestudy.StudyEventDAO)6 StudyEventDefinitionDAO (org.akaza.openclinica.dao.managestudy.StudyEventDefinitionDAO)6 EventCRFDAO (org.akaza.openclinica.dao.submit.EventCRFDAO)6 StudySubjectBean (org.akaza.openclinica.bean.managestudy.StudySubjectBean)5 StudyUserRoleBean (org.akaza.openclinica.bean.login.StudyUserRoleBean)4 StudyEventBean (org.akaza.openclinica.bean.managestudy.StudyEventBean)4 StudyEventDefinitionBean (org.akaza.openclinica.bean.managestudy.StudyEventDefinitionBean)4 StudyGroupClassBean (org.akaza.openclinica.bean.managestudy.StudyGroupClassBean)4 EventCRFBean (org.akaza.openclinica.bean.submit.EventCRFBean)4