Search in sources :

Example 31 with OpenClinicaSystemException

use of org.akaza.openclinica.exception.OpenClinicaSystemException in project OpenClinica by OpenClinica.

the class ImportRuleServlet method handleLoadCastor.

private RulesPostImportContainer handleLoadCastor(File xmlFile) {
    RulesPostImportContainer ruleImport = null;
    try {
        // create an XMLContext instance
        XMLContext xmlContext = new XMLContext();
        // create and set a Mapping instance
        Mapping mapping = xmlContext.createMapping();
        // mapping.loadMapping(SpringServletAccess.getPropertiesDir(context) + "mapping.xml");
        mapping.loadMapping(getCoreResources().getURL("mapping.xml"));
        xmlContext.addMapping(mapping);
        // create a new Unmarshaller
        Unmarshaller unmarshaller = xmlContext.createUnmarshaller();
        unmarshaller.setWhitespacePreserve(false);
        unmarshaller.setClass(RulesPostImportContainer.class);
        // Create a Reader to the file to unmarshal from
        FileReader reader = new FileReader(xmlFile);
        ruleImport = (RulesPostImportContainer) unmarshaller.unmarshal(reader);
        ruleImport.initializeRuleDef();
        logRuleImport(ruleImport);
        return ruleImport;
    } catch (FileNotFoundException ex) {
        throw new OpenClinicaSystemException(ex.getMessage(), ex.getCause());
    } catch (IOException ex) {
        throw new OpenClinicaSystemException(ex.getMessage(), ex.getCause());
    } catch (MarshalException e) {
        throw new OpenClinicaSystemException(e.getMessage(), e.getCause());
    } catch (ValidationException e) {
        throw new OpenClinicaSystemException(e.getMessage(), e.getCause());
    } catch (MappingException e) {
        throw new OpenClinicaSystemException(e.getMessage(), e.getCause());
    }
}
Also used : RulesPostImportContainer(org.akaza.openclinica.domain.rule.RulesPostImportContainer) MarshalException(org.exolab.castor.xml.MarshalException) ValidationException(org.exolab.castor.xml.ValidationException) XMLContext(org.exolab.castor.xml.XMLContext) FileNotFoundException(java.io.FileNotFoundException) Mapping(org.exolab.castor.mapping.Mapping) FileReader(java.io.FileReader) IOException(java.io.IOException) Unmarshaller(org.exolab.castor.xml.Unmarshaller) OpenClinicaSystemException(org.akaza.openclinica.exception.OpenClinicaSystemException) MappingException(org.exolab.castor.mapping.MappingException)

Example 32 with OpenClinicaSystemException

use of org.akaza.openclinica.exception.OpenClinicaSystemException in project OpenClinica by OpenClinica.

the class OpenRosaSubmissionController method processUploadedFile.

private File processUploadedFile(FileItem item, String dirToSaveUploadedFileIn) {
    dirToSaveUploadedFileIn = dirToSaveUploadedFileIn == null ? System.getProperty("java.io.tmpdir") : dirToSaveUploadedFileIn;
    String fileName = item.getName();
    // Some browsers IE 6,7 getName returns the whole path
    int startIndex = fileName.lastIndexOf('\\');
    if (startIndex != -1) {
        fileName = fileName.substring(startIndex + 1, fileName.length());
    }
    File uploadedFile = new File(dirToSaveUploadedFileIn + File.separator + fileName);
    /*
         * try {
         * uploadedFile = new UploadFileServlet().new OCFileRename().rename(uploadedFile, item.getInputStream());
         * } catch (IOException e) {
         * throw new OpenClinicaSystemException(e.getMessage());
         * }
         */
    try {
        item.write(uploadedFile);
    } catch (Exception e) {
        throw new OpenClinicaSystemException(e.getMessage());
    }
    return uploadedFile;
}
Also used : OpenClinicaSystemException(org.akaza.openclinica.exception.OpenClinicaSystemException) File(java.io.File) OpenClinicaSystemException(org.akaza.openclinica.exception.OpenClinicaSystemException)

Example 33 with OpenClinicaSystemException

use of org.akaza.openclinica.exception.OpenClinicaSystemException in project OpenClinica by OpenClinica.

the class ExampleSpringJob method executeInternal.

@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, 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, userBean);
                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, userBean);
                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, userBean);
                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, userBean);
                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, userBean);
                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, userBean);
                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.getKey().getName());
            auditEventDAO.createRowForExtractDataJobSuccess(triggerBean, auditMessage.toString());
        } else {
            TriggerBean triggerBean = new TriggerBean();
            // triggerBean.setDataset(datasetBean);
            triggerBean.setUserAccount(userBean);
            triggerBean.setFullName(trigger.getKey().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();
    }
}
Also used : Locale(java.util.Locale) HashMap(java.util.HashMap) CoreResources(org.akaza.openclinica.dao.core.CoreResources) DatasetBean(org.akaza.openclinica.bean.extract.DatasetBean) ApplicationContext(org.springframework.context.ApplicationContext) SimpleTrigger(org.quartz.SimpleTrigger) StudyDAO(org.akaza.openclinica.dao.managestudy.StudyDAO) SPSSReportBean(org.akaza.openclinica.bean.extract.SPSSReportBean) JobDataMap(org.quartz.JobDataMap) GenerateExtractFileService(org.akaza.openclinica.service.extract.GenerateExtractFileService) TriggerBean(org.akaza.openclinica.bean.admin.TriggerBean) MessageFormat(java.text.MessageFormat) StudyBean(org.akaza.openclinica.bean.managestudy.StudyBean) AuditEventDAO(org.akaza.openclinica.dao.admin.AuditEventDAO) OpenClinicaSystemException(org.akaza.openclinica.exception.OpenClinicaSystemException) DatasetDAO(org.akaza.openclinica.dao.extract.DatasetDAO) UserAccountDAO(org.akaza.openclinica.dao.login.UserAccountDAO) JobExecutionException(org.quartz.JobExecutionException) OpenClinicaSystemException(org.akaza.openclinica.exception.OpenClinicaSystemException) ExtractBean(org.akaza.openclinica.bean.extract.ExtractBean) ResourceBundle(java.util.ResourceBundle) SimpleDateFormat(java.text.SimpleDateFormat)

Example 34 with OpenClinicaSystemException

use of org.akaza.openclinica.exception.OpenClinicaSystemException in project OpenClinica by OpenClinica.

the class ImportSpringJob method executeInternalInTransaction.

protected void executeInternalInTransaction(JobExecutionContext context) {
    locale = new Locale("en-US");
    ResourceBundleProvider.updateLocale(locale);
    respage = ResourceBundleProvider.getPageMessagesBundle();
    resword = ResourceBundleProvider.getWordsBundle();
    triggerService = new TriggerService();
    JobDataMap dataMap = context.getMergedJobDataMap();
    SimpleTrigger trigger = (SimpleTrigger) context.getTrigger();
    TriggerBean triggerBean = new TriggerBean();
    triggerBean.setFullName(trigger.getKey().getName());
    String contactEmail = dataMap.getString(EMAIL);
    logger.debug("=== starting to run trigger " + trigger.getKey().getName() + " ===");
    try {
        ApplicationContext appContext = (ApplicationContext) context.getScheduler().getContext().get("applicationContext");
        dataSource = (DataSource) appContext.getBean("dataSource");
        mailSender = (OpenClinicaMailSender) appContext.getBean("openClinicaMailSender");
        RuleSetServiceInterface ruleSetService = (RuleSetServiceInterface) appContext.getBean("ruleSetService");
        itemDataDao = new ItemDataDAO(dataSource);
        eventCrfDao = new EventCRFDAO(dataSource);
        auditEventDAO = new AuditEventDAO(dataSource);
        int userId = dataMap.getInt(USER_ID);
        UserAccountDAO userAccountDAO = new UserAccountDAO(dataSource);
        UserAccountBean ub = (UserAccountBean) userAccountDAO.findByPK(userId);
        triggerBean.setUserAccount(ub);
        String directory = dataMap.getString(DIRECTORY);
        String studyName = dataMap.getString(STUDY_NAME);
        String studyOid = dataMap.getString(STUDY_OID);
        String localeStr = dataMap.getString(ExampleSpringJob.LOCALE);
        if (localeStr != null) {
            locale = new Locale(localeStr);
            ResourceBundleProvider.updateLocale(locale);
            respage = ResourceBundleProvider.getPageMessagesBundle();
            resword = ResourceBundleProvider.getWordsBundle();
        }
        StudyDAO studyDAO = new StudyDAO(dataSource);
        StudyBean studyBean;
        if (studyOid != null) {
            studyBean = studyDAO.findByOid(studyOid);
        } else {
            studyBean = (StudyBean) studyDAO.findByName(studyName);
        }
        // might also need study id here for the data service?
        File fileDirectory = new File(SQLInitServlet.getField("filePath") + DIR_PATH + File.separator);
        // File fileDirectory = new File(IMPORT_DIR);
        if ("".equals(directory)) {
        // avoid NPEs
        // do nothing here?
        } else {
            // there is a separator at the end of IMPORT_DIR already...
            // fileDirectory = new File(IMPORT_DIR + directory +
            // File.separator);
            fileDirectory = new File(SQLInitServlet.getField("filePath") + DIR_PATH + File.separator + directory + File.separator);
        }
        if (!fileDirectory.isDirectory()) {
            fileDirectory.mkdirs();
        }
        // this is necessary the first time this is run, tbh
        // File destDirectory = new File(IMPORT_DIR_2);
        File destDirectory = new File(SQLInitServlet.getField("filePath") + DEST_DIR + File.separator);
        if (!destDirectory.isDirectory()) {
            destDirectory.mkdirs();
        }
        // look at directory, if there are new files, move them over and
        // read them
        // File fileDirectory = new File(directory);
        String[] files = fileDirectory.list();
        logger.debug("found " + files.length + " files under directory " + SQLInitServlet.getField("filePath") + DIR_PATH + File.separator + directory);
        File[] target = new File[files.length];
        File[] destination = new File[files.length];
        for (int i = 0; i < files.length; i++) {
            // hmm
            if (!new File(fileDirectory + File.separator + files[i]).isDirectory()) {
                File f = new File(fileDirectory + File.separator + files[i]);
                if (f == null || f.getName() == null) {
                    logger.debug("found a null file");
                } else if (f.getName().indexOf(".xml") < 0 && f.getName().indexOf(".XML") < 0) {
                    logger.debug("does not seem to be an xml file");
                // we need a place holder to avoid 'gaps' in the file
                // list
                } else {
                    logger.debug("adding: " + f.getName());
                    // new File(IMPORT_DIR +
                    target[i] = f;
                    // directory +
                    // File.separator + files[i]);
                    // destination[i] = new File(IMPORT_DIR_2 + files[i]);
                    destination[i] = new File(SQLInitServlet.getField("filePath") + DEST_DIR + File.separator + files[i]);
                }
            }
        }
        if (target.length > 0 && destination.length > 0) {
            cutAndPaste(target, destination);
            // @pgawade 28-June-2012: Fix for issue #13964 - Remove the null
            // elements from destination array of files
            // which might be created because of presense of sub-directories
            // or non-xml files under scheduled_data_import directory
            // which are non-usable files for import.
            destination = removeNullElements(destination);
            // do everything else here with 'destination'
            ArrayList<String> auditMessages = processData(destination, dataSource, respage, resword, ub, studyBean, destDirectory, triggerBean, ruleSetService);
            auditEventDAO.createRowForExtractDataJobSuccess(triggerBean, auditMessages.get(1));
            try {
                if (contactEmail != null && !"".equals(contactEmail)) {
                    mailSender.sendEmail(contactEmail, respage.getString("job_ran_for") + " " + triggerBean.getFullName(), generateMsg(auditMessages.get(0), contactEmail), true);
                    logger.debug("email body: " + auditMessages.get(1));
                }
            } catch (OpenClinicaSystemException e) {
                // Do nothing
                logger.error("=== throw an ocse === " + e.getMessage());
                e.printStackTrace();
            }
        } else {
            logger.debug("no real files found");
            auditEventDAO.createRowForExtractDataJobSuccess(triggerBean, respage.getString("job_ran_but_no_files"));
        // no email here, tbh
        }
    // use the business logic to go through each one and import that
    // data
    // check to see if they were imported before?
    // using the four methods:
    // importCRFDataServce.validateStudyMetadata,
    // service.lookupValidationErrors, service.fetchEventCRFBeans(?),
    // and
    // service.generateSummaryStatsBean(for the email we send out later)
    } catch (Exception e) {
        // more detailed reporting here
        logger.error("found a fail exception: " + e.getMessage());
        e.printStackTrace();
        auditEventDAO.createRowForExtractDataJobFailure(triggerBean, e.getMessage());
        try {
            mailSender.sendEmail(contactEmail, respage.getString("job_failure_for") + " " + triggerBean.getFullName(), e.getMessage(), true);
        } catch (OpenClinicaSystemException ose) {
            // Do nothing
            logger.error("=== throw an ocse: " + ose.getMessage());
        }
    }
}
Also used : Locale(java.util.Locale) JobDataMap(org.quartz.JobDataMap) TriggerBean(org.akaza.openclinica.bean.admin.TriggerBean) StudyBean(org.akaza.openclinica.bean.managestudy.StudyBean) AuditEventDAO(org.akaza.openclinica.dao.admin.AuditEventDAO) OpenClinicaSystemException(org.akaza.openclinica.exception.OpenClinicaSystemException) UserAccountDAO(org.akaza.openclinica.dao.login.UserAccountDAO) ItemDataDAO(org.akaza.openclinica.dao.submit.ItemDataDAO) OpenClinicaException(org.akaza.openclinica.exception.OpenClinicaException) JobExecutionException(org.quartz.JobExecutionException) OpenClinicaSystemException(org.akaza.openclinica.exception.OpenClinicaSystemException) SchedulerException(org.quartz.SchedulerException) IOException(java.io.IOException) RuleSetServiceInterface(org.akaza.openclinica.service.rule.RuleSetServiceInterface) ApplicationContext(org.springframework.context.ApplicationContext) UserAccountBean(org.akaza.openclinica.bean.login.UserAccountBean) SimpleTrigger(org.quartz.SimpleTrigger) StudyDAO(org.akaza.openclinica.dao.managestudy.StudyDAO) File(java.io.File) EventCRFDAO(org.akaza.openclinica.dao.submit.EventCRFDAO)

Example 35 with OpenClinicaSystemException

use of org.akaza.openclinica.exception.OpenClinicaSystemException in project OpenClinica by OpenClinica.

the class StudySubjectEndpoint method listStudySubjectsInStudy.

/**
     * Use this method to list all study subjects. Scheduled event data will also be show if available.
     * 
     * @param requestElement
     * @return ListAllByStudyResponse
     * @throws Exception
     */
@PayloadRoot(localPart = "listAllByStudyRequest", namespace = NAMESPACE_URI_V1)
public ListAllByStudyResponse listStudySubjectsInStudy(JAXBElement<ListStudySubjectsInStudyType> requestElement) throws Exception {
    try {
        ResourceBundleProvider.updateLocale(new Locale("en_US"));
        ListStudySubjectsInStudyType listStudySubjectsInStudyType = requestElement.getValue();
        StudyBean study = null;
        try {
            study = validateRequestAndReturnStudy(listStudySubjectsInStudyType.getStudyRef());
        } catch (OpenClinicaSystemException e) {
            e.printStackTrace();
            ListAllByStudyResponse response = new ListAllByStudyResponse();
            response.setResult(messages.getMessage("studySubjectEndpoint.fail", null, "Fail", locale));
            response.getError().add(messages.getMessage(e.getErrorCode(), null, e.getErrorCode(), locale));
            return response;
        }
        return mapListStudySubjectsInStudyResponse(study, messages.getMessage("studySubjectEndpoint.success", null, "Success", locale), listStudySubjectsInStudyType.getStudyRef());
    } catch (Exception eee) {
        eee.printStackTrace();
        throw eee;
    }
}
Also used : Locale(java.util.Locale) ListStudySubjectsInStudyType(org.openclinica.ws.beans.ListStudySubjectsInStudyType) ListAllByStudyResponse(org.openclinica.ws.studysubject.v1.ListAllByStudyResponse) OpenClinicaSystemException(org.akaza.openclinica.exception.OpenClinicaSystemException) ParseException(java.text.ParseException) OpenClinicaSystemException(org.akaza.openclinica.exception.OpenClinicaSystemException) PayloadRoot(org.springframework.ws.server.endpoint.annotation.PayloadRoot)

Aggregations

OpenClinicaSystemException (org.akaza.openclinica.exception.OpenClinicaSystemException)76 IOException (java.io.IOException)19 File (java.io.File)13 HashMap (java.util.HashMap)11 ItemDataBean (org.akaza.openclinica.bean.submit.ItemDataBean)11 OpenClinicaExpressionParser (org.akaza.openclinica.logic.expressionTree.OpenClinicaExpressionParser)11 ArrayList (java.util.ArrayList)10 ItemBean (org.akaza.openclinica.bean.submit.ItemBean)10 FileNotFoundException (java.io.FileNotFoundException)8 MessageFormat (java.text.MessageFormat)8 RuleSetBean (org.akaza.openclinica.domain.rule.RuleSetBean)7 RuleActionBean (org.akaza.openclinica.domain.rule.action.RuleActionBean)7 ExpressionBean (org.akaza.openclinica.domain.rule.expression.ExpressionBean)7 ExpressionObjectWrapper (org.akaza.openclinica.domain.rule.expression.ExpressionObjectWrapper)7 FileOutputStream (java.io.FileOutputStream)6 Date (java.util.Date)6 CRFBean (org.akaza.openclinica.bean.admin.CRFBean)6 StudyEventDefinitionBean (org.akaza.openclinica.bean.managestudy.StudyEventDefinitionBean)6 RuleBean (org.akaza.openclinica.domain.rule.RuleBean)6 RuleSetRuleBean (org.akaza.openclinica.domain.rule.RuleSetRuleBean)6