Search in sources :

Example 1 with DatasetDAO

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

the class XsltTransformJob method initDependencies.

/**
     * Initializes the dependencies of this job with the components from the Spring application context.
     *
     * @param scheduler
     */
private void initDependencies(Scheduler scheduler) {
    try {
        ApplicationContext ctx = (ApplicationContext) scheduler.getContext().get("applicationContext");
        DataSource dataSource = ctx.getBean(DataSource.class);
        mailSender = ctx.getBean(OpenClinicaMailSender.class);
        auditEventDAO = ctx.getBean(AuditEventDAO.class);
        datasetDao = ctx.getBean(DatasetDAO.class);
        userAccountDao = ctx.getBean(UserAccountDAO.class);
        studyDao = new StudyDAO(dataSource);
        archivedDatasetFileDao = ctx.getBean(ArchivedDatasetFileDAO.class);
        generateFileService = ctx.getBean(GenerateExtractFileService.class);
        odmFileCreation = ctx.getBean(OdmFileCreation.class);
    } catch (SchedulerException e) {
        throw new IllegalStateException("Could not load dependencies from scheduler context", e);
    }
}
Also used : ArchivedDatasetFileDAO(org.akaza.openclinica.dao.extract.ArchivedDatasetFileDAO) ApplicationContext(org.springframework.context.ApplicationContext) GenerateExtractFileService(org.akaza.openclinica.service.extract.GenerateExtractFileService) SchedulerException(org.quartz.SchedulerException) OpenClinicaMailSender(org.akaza.openclinica.core.OpenClinicaMailSender) AuditEventDAO(org.akaza.openclinica.dao.admin.AuditEventDAO) OdmFileCreation(org.akaza.openclinica.service.extract.OdmFileCreation) DatasetDAO(org.akaza.openclinica.dao.extract.DatasetDAO) UserAccountDAO(org.akaza.openclinica.dao.login.UserAccountDAO) StudyDAO(org.akaza.openclinica.dao.managestudy.StudyDAO) DataSource(javax.sql.DataSource)

Example 2 with DatasetDAO

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

the class OdmFileCreation method createODMFile.

public HashMap<String, Integer> createODMFile(String odmVersion, long sysTimeBegin, String generalFileDir, DatasetBean datasetBean, StudyBean currentStudy, String generalFileDirCopy, ExtractBean eb, Integer currentStudyId, Integer parentStudyId, String studySubjectNumber, boolean zipped, boolean saveToDB, boolean deleteOld, String odmType, UserAccountBean userBean) {
    Integer ssNumber = getStudySubjectNumber(studySubjectNumber);
    MetaDataCollector mdc = new MetaDataCollector(dataSource, datasetBean, currentStudy, ruleSetRuleDao);
    AdminDataCollector adc = new AdminDataCollector(dataSource, datasetBean, currentStudy);
    ClinicalDataCollector cdc = new ClinicalDataCollector(dataSource, datasetBean, currentStudy);
    MetaDataCollector.setTextLength(200);
    if (deleteOld) {
        File file = new File(generalFileDir);
        if (file.isDirectory()) {
            files = file.listFiles();
            oldFiles = Arrays.asList(files);
        }
    }
    if (odmVersion != null) {
        // by default odmVersion is 1.2
        if ("1.3".equals(odmVersion)) {
            ODMBean odmb = new ODMBean();
            odmb.setSchemaLocation("http://www.cdisc.org/ns/odm/v1.3 ODM1-3-0.xsd");
            ArrayList<String> xmlnsList = new ArrayList<String>();
            xmlnsList.add("xmlns=\"http://www.cdisc.org/ns/odm/v1.3\"");
            odmb.setXmlnsList(xmlnsList);
            odmb.setODMVersion("1.3");
            mdc.setODMBean(odmb);
            adc.setOdmbean(odmb);
            cdc.setODMBean(odmb);
        } else if ("oc1.2".equals(odmVersion)) {
            ODMBean odmb = new ODMBean();
            // odmb.setSchemaLocation("http://www.cdisc.org/ns/odm/v1.2 OpenClinica-ODM1-2-1.xsd");
            odmb.setSchemaLocation("http://www.cdisc.org/ns/odm/v1.2 OpenClinica-ODM1-2-1-OC1.xsd");
            ArrayList<String> xmlnsList = new ArrayList<String>();
            xmlnsList.add("xmlns=\"http://www.cdisc.org/ns/odm/v1.2\"");
            // xmlnsList.add("xmlns:OpenClinica=\"http://www.openclinica.org/ns/openclinica_odm/v1.2\"");
            xmlnsList.add("xmlns:OpenClinica=\"http://www.openclinica.org/ns/odm_ext_v121/v3.1\"");
            xmlnsList.add("xmlns:OpenClinicaRules=\"http://www.openclinica.org/ns/rules/v3.1\"");
            odmb.setXmlnsList(xmlnsList);
            odmb.setODMVersion("oc1.2");
            mdc.setODMBean(odmb);
            adc.setOdmbean(odmb);
            cdc.setODMBean(odmb);
        } else if ("oc1.3".equals(odmVersion)) {
            ODMBean odmb = mdc.getODMBean();
            // odmb.setSchemaLocation("http://www.cdisc.org/ns/odm/v1.3 OpenClinica-ODM1-3-0.xsd");
            // odmb.setSchemaLocation("http://www.cdisc.org/ns/odm/v1.3 OpenClinica-ODM1-3-0-OC1.xsd");
            odmb.setSchemaLocation("http://www.cdisc.org/ns/odm/v1.3 OpenClinica-ODM1-3-0-OC3-0.xsd");
            ArrayList<String> xmlnsList = new ArrayList<String>();
            xmlnsList.add("xmlns=\"http://www.cdisc.org/ns/odm/v1.3\"");
            // xmlnsList.add("xmlns:OpenClinica=\"http://www.openclinica.org/ns/openclinica_odm/v1.3\"");
            xmlnsList.add("xmlns:OpenClinica=\"http://www.openclinica.org/ns/odm_ext_v130/v3.1\"");
            xmlnsList.add("xmlns:OpenClinicaRules=\"http://www.openclinica.org/ns/rules/v3.1\"");
            odmb.setXmlnsList(xmlnsList);
            odmb.setODMVersion("oc1.3");
            odmb.setOdmType(odmType);
            mdc.setODMBean(odmb);
            adc.setOdmbean(odmb);
            cdc.setODMBean(odmb);
        }
    }
    //////////////////////////////////////////
    ////////// MetaData Extraction //////////
    mdc.collectFileData();
    MetaDataReportBean metaReport = new MetaDataReportBean(mdc.getOdmStudyMap(), coreResources);
    metaReport.setODMVersion(odmVersion);
    metaReport.setOdmBean(mdc.getODMBean());
    metaReport.createChunkedOdmXml(Boolean.TRUE);
    long sysTimeEnd = System.currentTimeMillis() - sysTimeBegin;
    String ODMXMLFileName = mdc.getODMBean().getFileOID() + ".xml";
    int fId = createFileK(ODMXMLFileName, generalFileDir, metaReport.getXmlOutput().toString(), datasetBean, sysTimeEnd, ExportFormatBean.XMLFILE, false, zipped, deleteOld, userBean);
    if (!"".equals(generalFileDirCopy)) {
        int fId2 = createFileK(ODMXMLFileName, generalFileDirCopy, metaReport.getXmlOutput().toString(), datasetBean, sysTimeEnd, ExportFormatBean.XMLFILE, false, zipped, deleteOld, userBean);
    }
    //////////////////////////////////////////
    ////////// AdminData Extraction //////////
    adc.collectFileData();
    AdminDataReportBean adminReport = new AdminDataReportBean(adc.getOdmAdminDataMap());
    adminReport.setODMVersion(odmVersion);
    adminReport.setOdmBean(mdc.getODMBean());
    adminReport.createChunkedOdmXml(Boolean.TRUE);
    sysTimeEnd = System.currentTimeMillis() - sysTimeBegin;
    fId = createFileK(ODMXMLFileName, generalFileDir, adminReport.getXmlOutput().toString(), datasetBean, sysTimeEnd, ExportFormatBean.XMLFILE, false, zipped, deleteOld, userBean);
    if (!"".equals(generalFileDirCopy)) {
        int fId2 = createFileK(ODMXMLFileName, generalFileDirCopy, adminReport.getXmlOutput().toString(), datasetBean, sysTimeEnd, ExportFormatBean.XMLFILE, false, zipped, deleteOld, userBean);
    }
    //////////////////////////////////////////
    ////////// ClinicalData Extraction ///////
    DatasetDAO dsdao = new DatasetDAO(dataSource);
    String sql = eb.getDataset().getSQLStatement();
    String st_sed_in = dsdao.parseSQLDataset(sql, true, true);
    String st_itemid_in = dsdao.parseSQLDataset(sql, false, true);
    int datasetItemStatusId = eb.getDataset().getDatasetItemStatus().getId();
    String ecStatusConstraint = dsdao.getECStatusConstraint(datasetItemStatusId);
    String itStatusConstraint = dsdao.getItemDataStatusConstraint(datasetItemStatusId);
    Iterator<OdmStudyBase> it = cdc.getStudyBaseMap().values().iterator();
    while (it.hasNext()) {
        JobTerminationMonitor.check();
        OdmStudyBase u = it.next();
        ArrayList newRows = dsdao.selectStudySubjects(u.getStudy().getId(), 0, st_sed_in, st_itemid_in, dsdao.genDatabaseDateConstraint(eb), ecStatusConstraint, itStatusConstraint);
        ///////////////
        int fromIndex = 0;
        boolean firstIteration = true;
        while (fromIndex < newRows.size()) {
            JobTerminationMonitor.check();
            int toIndex = fromIndex + ssNumber < newRows.size() ? fromIndex + ssNumber : newRows.size() - 1;
            List x = newRows.subList(fromIndex, toIndex + 1);
            fromIndex = toIndex + 1;
            String studySubjectIds = "";
            for (int i = 0; i < x.size(); i++) {
                StudySubjectBean sub = new StudySubjectBean();
                sub = (StudySubjectBean) x.get(i);
                studySubjectIds += "," + sub.getId();
            }
            // for
            studySubjectIds = studySubjectIds.replaceFirst(",", "");
            ClinicalDataUnit cdata = new ClinicalDataUnit(dataSource, datasetBean, cdc.getOdmbean(), u.getStudy(), cdc.getCategory(), studySubjectIds);
            cdata.setCategory(cdc.getCategory());
            cdata.collectOdmClinicalData();
            FullReportBean report = new FullReportBean();
            report.setClinicalData(cdata.getOdmClinicalData());
            report.setOdmStudyMap(mdc.getOdmStudyMap());
            report.setODMVersion(odmVersion);
            // report.setOdmStudy(mdc.getOdmStudy());
            report.setOdmBean(mdc.getODMBean());
            if (firstIteration && fromIndex >= newRows.size()) {
                report.createChunkedOdmXml(Boolean.TRUE, true, true);
                firstIteration = false;
            } else if (firstIteration) {
                report.createChunkedOdmXml(Boolean.TRUE, true, false);
                firstIteration = false;
            } else if (fromIndex >= newRows.size()) {
                report.createChunkedOdmXml(Boolean.TRUE, false, true);
            } else {
                report.createChunkedOdmXml(Boolean.TRUE, false, false);
            }
            fId = createFileK(ODMXMLFileName, generalFileDir, report.getXmlOutput().toString(), datasetBean, sysTimeEnd, ExportFormatBean.XMLFILE, false, zipped, deleteOld, userBean);
            if (!"".equals(generalFileDirCopy)) {
                int fId2 = createFileK(ODMXMLFileName, generalFileDirCopy, report.getXmlOutput().toString(), datasetBean, sysTimeEnd, ExportFormatBean.XMLFILE, false, zipped, deleteOld, userBean);
            }
        }
    }
    sysTimeEnd = System.currentTimeMillis() - sysTimeBegin;
    fId = createFileK(ODMXMLFileName, generalFileDir, "</ODM>", datasetBean, sysTimeEnd, ExportFormatBean.XMLFILE, saveToDB, zipped, deleteOld, userBean);
    if (!"".equals(generalFileDirCopy)) {
        int fId2 = createFileK(ODMXMLFileName, generalFileDirCopy, "</ODM>", datasetBean, sysTimeEnd, ExportFormatBean.XMLFILE, false, zipped, deleteOld, userBean);
    }
    //////////////////////////////////////////
    ////////// pre pagination extraction /////
    /*
         * mdc.collectFileData();
         * adc.collectOdmAdminDataMap();
         * cdc.collectOdmClinicalDataMap();
         * FullReportBean report = new FullReportBean();
         * report.setClinicalDataMap(cdc.getOdmClinicalDataMap());
         * report.setAdminDataMap(adc.getOdmAdminDataMap());
         * report.setOdmStudyMap(mdc.getOdmStudyMap());
         * report.setOdmBean(mdc.getODMBean());
         * report.setODMVersion(odmVersion);
         * report.createOdmXml(Boolean.TRUE);
         * long sysTimeEnd = System.currentTimeMillis() - sysTimeBegin;
         * String ODMXMLFileName = mdc.getODMBean().getFileOID() + ".xml";
         * int fId = this.createFile(ODMXMLFileName, generalFileDir, report.getXmlOutput().toString(), datasetBean,
         * sysTimeEnd, ExportFormatBean.XMLFILE, true);
         * if (!"".equals(generalFileDirCopy)) {
         * int fId2 = this.createFile(ODMXMLFileName, generalFileDirCopy, report.getXmlOutput().toString(), datasetBean,
         * sysTimeEnd, ExportFormatBean.XMLFILE, false);
         * }
         */
    HashMap answerMap = new HashMap<String, Integer>();
    // JN: Zipped in the next stage as thats where the ODM file is named and copied over in default categories.
    // if(zipped)
    // { try {
    // zipFile(ODMXMLFileName,generalFileDir);
    //
    // } catch (IOException e) {
    // // TODO Auto-generated catch block
    // logger.error(e.getMessage());
    // e.printStackTrace();
    // }
    //
    // } // return ODMXMLFileName;
    answerMap.put(ODMXMLFileName, new Integer(fId));
    return answerMap;
}
Also used : ClinicalDataCollector(org.akaza.openclinica.logic.odmExport.ClinicalDataCollector) ClinicalDataUnit(org.akaza.openclinica.logic.odmExport.ClinicalDataUnit) HashMap(java.util.HashMap) AdminDataCollector(org.akaza.openclinica.logic.odmExport.AdminDataCollector) ArrayList(java.util.ArrayList) OdmStudyBase(org.akaza.openclinica.logic.odmExport.OdmStudyBase) MetaDataReportBean(org.akaza.openclinica.bean.extract.odm.MetaDataReportBean) DatasetDAO(org.akaza.openclinica.dao.extract.DatasetDAO) FullReportBean(org.akaza.openclinica.bean.extract.odm.FullReportBean) AdminDataReportBean(org.akaza.openclinica.bean.extract.odm.AdminDataReportBean) StudySubjectBean(org.akaza.openclinica.bean.managestudy.StudySubjectBean) ODMBean(org.akaza.openclinica.bean.odmbeans.ODMBean) ArrayList(java.util.ArrayList) LinkedList(java.util.LinkedList) List(java.util.List) MetaDataCollector(org.akaza.openclinica.logic.odmExport.MetaDataCollector) File(java.io.File)

Example 3 with DatasetDAO

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

the class GenerateExtractFileService method createTabFile.

/**
     * createTabFile, added by tbh, 01/2009
     */
public HashMap<String, Integer> createTabFile(ExtractBean eb, long sysTimeBegin, String generalFileDir, DatasetBean datasetBean, int activeStudyId, int parentStudyId, String generalFileDirCopy, UserAccountBean userBean) {
    TabReportBean answer = new TabReportBean();
    DatasetDAO dsdao = new DatasetDAO(ds);
    // create the extract bean here, tbh
    eb = dsdao.getDatasetData(eb, activeStudyId, parentStudyId);
    eb.getMetadata();
    eb.computeReport(answer);
    long sysTimeEnd = System.currentTimeMillis() - sysTimeBegin;
    String TXTFileName = datasetBean.getName() + "_tab.xls";
    int fId = this.createFile(TXTFileName, generalFileDir, answer.toString(), datasetBean, sysTimeEnd, ExportFormatBean.TXTFILE, true, userBean);
    if (!"".equals(generalFileDirCopy)) {
        int fId2 = this.createFile(TXTFileName, generalFileDirCopy, answer.toString(), datasetBean, sysTimeEnd, ExportFormatBean.TXTFILE, false, userBean);
    }
    logger.info("created txt file");
    // return TXTFileName;
    HashMap answerMap = new HashMap<String, Integer>();
    answerMap.put(TXTFileName, new Integer(fId));
    return answerMap;
}
Also used : HashMap(java.util.HashMap) TabReportBean(org.akaza.openclinica.bean.extract.TabReportBean) DatasetDAO(org.akaza.openclinica.dao.extract.DatasetDAO)

Example 4 with DatasetDAO

use of org.akaza.openclinica.dao.extract.DatasetDAO 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);
        }
    }
}
Also used : SubjectGroupMapBean(org.akaza.openclinica.bean.submit.SubjectGroupMapBean) StudyGroupClassDAO(org.akaza.openclinica.dao.managestudy.StudyGroupClassDAO) DatasetBean(org.akaza.openclinica.bean.extract.DatasetBean) ArrayList(java.util.ArrayList) StudyEventDefinitionBean(org.akaza.openclinica.bean.managestudy.StudyEventDefinitionBean) StudyGroupDAO(org.akaza.openclinica.dao.managestudy.StudyGroupDAO) StudyEventBean(org.akaza.openclinica.bean.managestudy.StudyEventBean) ItemDataDAO(org.akaza.openclinica.dao.submit.ItemDataDAO) EventCRFBean(org.akaza.openclinica.bean.submit.EventCRFBean) ItemDataBean(org.akaza.openclinica.bean.submit.ItemDataBean) StudyEventDAO(org.akaza.openclinica.dao.managestudy.StudyEventDAO) StudyGroupClassBean(org.akaza.openclinica.bean.managestudy.StudyGroupClassBean) StudyDAO(org.akaza.openclinica.dao.managestudy.StudyDAO) EventCRFDAO(org.akaza.openclinica.dao.submit.EventCRFDAO) SubjectGroupMapDAO(org.akaza.openclinica.dao.submit.SubjectGroupMapDAO) FormProcessor(org.akaza.openclinica.control.form.FormProcessor) StudyBean(org.akaza.openclinica.bean.managestudy.StudyBean) StudyUserRoleBean(org.akaza.openclinica.bean.login.StudyUserRoleBean) EventDefinitionCRFDAO(org.akaza.openclinica.dao.managestudy.EventDefinitionCRFDAO) UserAccountDAO(org.akaza.openclinica.dao.login.UserAccountDAO) StudySubjectDAO(org.akaza.openclinica.dao.managestudy.StudySubjectDAO) DatasetDAO(org.akaza.openclinica.dao.extract.DatasetDAO) Date(java.util.Date) StudyEventDefinitionDAO(org.akaza.openclinica.dao.managestudy.StudyEventDefinitionDAO) StudySubjectBean(org.akaza.openclinica.bean.managestudy.StudySubjectBean) EventDefinitionCRFBean(org.akaza.openclinica.bean.managestudy.EventDefinitionCRFBean)

Example 5 with DatasetDAO

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

the class UpdateJobExportServlet method processRequest.

@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();
    ExtractUtils extractUtils = new ExtractUtils();
    Trigger updatingTrigger = scheduler.getTrigger(new TriggerKey(triggerName.trim(), XsltTriggerService.TRIGGER_GROUP_NAME));
    if (StringUtil.isBlank(action)) {
        setUpServlet(updatingTrigger);
        forwardPage(Page.UPDATE_JOB_EXPORT);
    } else if ("confirmall".equalsIgnoreCase(action)) {
        // change and update trigger here
        // validate first
        // then update or send back
        String name = XsltTriggerService.TRIGGER_GROUP_NAME;
        Set<TriggerKey> triggerKeys = scheduler.getTriggerKeys(GroupMatcher.triggerGroupEquals(name));
        String[] triggerNames = triggerKeys.stream().toArray(String[]::new);
        HashMap errors = validateForm(fp, request, triggerNames, updatingTrigger.getKey().getName());
        if (!errors.isEmpty()) {
            // send back
            addPageMessage("Your modifications caused an error, please see the messages for more information.");
            setUpServlet(updatingTrigger);
            logger.error("errors : " + errors.toString());
            forwardPage(Page.UPDATE_JOB_EXPORT);
        } else {
            // change trigger, update in database
            StudyDAO studyDAO = new StudyDAO(sm.getDataSource());
            StudyBean study = (StudyBean) studyDAO.findByPK(sm.getUserBean().getActiveStudyId());
            DatasetDAO datasetDao = new DatasetDAO(sm.getDataSource());
            CoreResources cr = new CoreResources();
            UserAccountBean userBean = (UserAccountBean) request.getSession().getAttribute("userBean");
            int datasetId = fp.getInt(DATASET_ID);
            String period = fp.getString(PERIOD);
            String email = fp.getString(EMAIL);
            String jobName = fp.getString(JOB_NAME);
            String jobDesc = fp.getString(JOB_DESC);
            Date startDateTime = fp.getDateTime(DATE_START_JOB);
            Integer exportFormatId = fp.getInt(FORMAT_ID);
            ExtractPropertyBean epBean = cr.findExtractPropertyBeanById(exportFormatId, "" + datasetId);
            DatasetBean dsBean = (DatasetBean) datasetDao.findByPK(new Integer(datasetId).intValue());
            String[] files = epBean.getFileName();
            String exportFileName;
            int fileSize = files.length;
            int cnt = 0;
            dsBean.setName(dsBean.getName().replaceAll(" ", "_"));
            String[] exportFiles = epBean.getExportFileName();
            String pattern = "yyyy" + File.separator + "MM" + File.separator + "dd" + File.separator + "HHmmssSSS" + File.separator;
            SimpleDateFormat sdfDir = new SimpleDateFormat(pattern);
            int i = 0;
            String[] temp = new String[exportFiles.length];
            //JN: The following logic is for comma separated variables, to avoid the second file be treated as a old file and deleted.
            String datasetFilePath = SQLInitServlet.getField("filePath") + "datasets";
            while (i < exportFiles.length) {
                temp[i] = extractUtils.resolveVars(exportFiles[i], dsBean, sdfDir, datasetFilePath);
                i++;
            }
            epBean.setDoNotDelFiles(temp);
            epBean.setExportFileName(temp);
            XsltTriggerService xsltService = new XsltTriggerService();
            String generalFileDir = SQLInitServlet.getField("filePath");
            generalFileDir = generalFileDir + "datasets" + File.separator + dsBean.getId() + File.separator + sdfDir.format(new java.util.Date());
            exportFileName = epBean.getExportFileName()[cnt];
            String xsltPath = SQLInitServlet.getField("filePath") + "xslt" + File.separator + files[cnt];
            String endFilePath = epBean.getFileLocation();
            endFilePath = extractUtils.getEndFilePath(endFilePath, dsBean, sdfDir, datasetFilePath);
            //  exportFileName = resolveVars(exportFileName,dsBean,sdfDir);
            if (epBean.getPostProcExportName() != null) {
                String preProcExportPathName = extractUtils.resolveVars(epBean.getPostProcExportName(), dsBean, sdfDir, datasetFilePath);
                epBean.setPostProcExportName(preProcExportPathName);
            }
            if (epBean.getPostProcLocation() != null) {
                String prePocLoc = extractUtils.getEndFilePath(epBean.getPostProcLocation(), dsBean, sdfDir, datasetFilePath);
                epBean.setPostProcLocation(prePocLoc);
            }
            extractUtils.setAllProps(epBean, dsBean, sdfDir, datasetFilePath);
            SimpleTrigger trigger = null;
            trigger = xsltService.generateXsltTrigger(scheduler, xsltPath, // xml_file_path
            generalFileDir, endFilePath + File.separator, exportFileName, dsBean.getId(), epBean, userBean, LocaleResolver.getLocale(request).getLanguage(), cnt, SQLInitServlet.getField("filePath") + "xslt", TRIGGER_GROUP_JOB);
            //Updating the original trigger with user given inputs
            trigger.getTriggerBuilder().withDescription(jobDesc).startAt(startDateTime).forJob(jobName).withSchedule(simpleSchedule().withIntervalInSeconds(new Long(XsltTriggerService.getIntervalTime(period)).intValue()).withRepeatCount(64000).withMisfireHandlingInstructionNextWithExistingCount());
            trigger.getJobDataMap().put(XsltTriggerService.EMAIL, email);
            trigger.getJobDataMap().put(XsltTriggerService.PERIOD, period);
            trigger.getJobDataMap().put(XsltTriggerService.EXPORT_FORMAT, epBean.getFiledescription());
            trigger.getJobDataMap().put(XsltTriggerService.EXPORT_FORMAT_ID, exportFormatId);
            trigger.getJobDataMap().put(XsltTriggerService.JOB_NAME, jobName);
            JobDetailFactoryBean JobDetailFactoryBean = new JobDetailFactoryBean();
            JobDetailFactoryBean.setGroup(xsltService.TRIGGER_GROUP_NAME);
            JobDetailFactoryBean.setName(trigger.getKey().getName());
            JobDetailFactoryBean.setJobClass(org.akaza.openclinica.job.XsltStatefulJob.class);
            JobDetailFactoryBean.setJobDataMap(trigger.getJobDataMap());
            // need durability?
            JobDetailFactoryBean.setDurability(true);
            try {
                // scheduler.unscheduleJob(triggerName, "DEFAULT");
                scheduler.deleteJob(new JobKey(triggerName, XsltTriggerService.TRIGGER_GROUP_NAME));
                Date dataStart = scheduler.scheduleJob(JobDetailFactoryBean.getObject(), trigger);
                // Date dateStart = scheduler.rescheduleJob(triggerName,
                // "DEFAULT", trigger);
                // scheduler.rescheduleJob(triggerName, groupName,
                // newTrigger)
                addPageMessage("Your job has been successfully modified.");
                forwardPage(Page.VIEW_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_EXPORT);
            }
        }
    }
}
Also used : CoreResources(org.akaza.openclinica.dao.core.CoreResources) DatasetBean(org.akaza.openclinica.bean.extract.DatasetBean) ExtractUtils(org.akaza.openclinica.service.extract.ExtractUtils) UserAccountBean(org.akaza.openclinica.bean.login.UserAccountBean) ExtractPropertyBean(org.akaza.openclinica.bean.extract.ExtractPropertyBean) XsltTriggerService(org.akaza.openclinica.service.extract.XsltTriggerService) StudyDAO(org.akaza.openclinica.dao.managestudy.StudyDAO) FormProcessor(org.akaza.openclinica.control.form.FormProcessor) StudyBean(org.akaza.openclinica.bean.managestudy.StudyBean) DatasetDAO(org.akaza.openclinica.dao.extract.DatasetDAO) XsltTriggerService(org.akaza.openclinica.service.extract.XsltTriggerService) TriggerService(org.akaza.openclinica.web.job.TriggerService) SimpleDateFormat(java.text.SimpleDateFormat) JobDetailFactoryBean(org.springframework.scheduling.quartz.JobDetailFactoryBean)

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