Search in sources :

Example 6 with ImportDataRuleRunnerContainer

use of org.akaza.openclinica.logic.rulerunner.ImportDataRuleRunnerContainer in project OpenClinica by OpenClinica.

the class DataEndpoint method importDataInTransaction.

protected Source importDataInTransaction(Element odmElement) throws Exception {
    ResourceBundleProvider.updateLocale(new Locale("en_US"));
    // logger.debug("rootElement=" + odmElement);
    LOG.debug("rootElement=" + odmElement);
    // String xml = null;
    UserAccountBean userBean = null;
    try {
        if (odmElement == null) {
            return new DOMSource(mapFailConfirmation(null, "Your XML is not well-formed."));
        }
        // xml = node2String(odmElement);
        // xml = xml.replaceAll("<ODM>", this.ODM_HEADER_NAMESPACE);
        ODMContainer odmContainer = unmarshallToODMContainer(odmElement);
        // Element clinicalDataNode = (Element) odmElement.getElementsByTagName("ClinicalData").item(0);
        // String studyUniqueID = clinicalDataNode.getAttribute("StudyOID");
        String studyUniqueID = odmContainer.getCrfDataPostImportContainer().getStudyOID();
        userBean = getUserAccount();
        // CRFDataImportBean crfDataImportBean = new CRFDataImportBean(studyUniqueID, userBean);
        BaseStudyDefinitionBean crfDataImportBean = new BaseStudyDefinitionBean(studyUniqueID, userBean);
        DataBinder dataBinder = new DataBinder(crfDataImportBean);
        Errors errors = dataBinder.getBindingResult();
        CRFDataImportValidator crfDataImportValidator = new CRFDataImportValidator(dataSource);
        crfDataImportValidator.validate(crfDataImportBean, errors);
        if (!errors.hasErrors()) {
            StudyBean studyBean = crfDataImportBean.getStudy();
            List<DisplayItemBeanWrapper> displayItemBeanWrappers = new ArrayList<DisplayItemBeanWrapper>();
            HashMap<Integer, String> importedCRFStatuses = new HashMap<Integer, String>();
            List<String> errorMessagesFromValidation = dataImportService.validateMetaData(odmContainer, dataSource, coreResources, studyBean, userBean, displayItemBeanWrappers, importedCRFStatuses);
            if (errorMessagesFromValidation.size() > 0) {
                String err_msg = convertToErrorString(errorMessagesFromValidation);
                return new DOMSource(mapFailConfirmation(null, err_msg));
            }
            ImportCRFInfoContainer importCrfInfo = new ImportCRFInfoContainer(odmContainer, dataSource);
            errorMessagesFromValidation = dataImportService.validateData(odmContainer, dataSource, coreResources, studyBean, userBean, displayItemBeanWrappers, importedCRFStatuses);
            if (errorMessagesFromValidation.size() > 0) {
                String err_msg = convertToErrorString(errorMessagesFromValidation);
                return new DOMSource(mapFailConfirmation(null, err_msg));
            }
            // setup ruleSets to run if applicable
            ArrayList<SubjectDataBean> subjectDataBeans = odmContainer.getCrfDataPostImportContainer().getSubjectData();
            List<ImportDataRuleRunnerContainer> containers = dataImportService.runRulesSetup(dataSource, studyBean, userBean, subjectDataBeans, ruleSetService);
            List<String> auditMsgs = new DataImportService().submitData(odmContainer, dataSource, studyBean, userBean, displayItemBeanWrappers, importedCRFStatuses);
            // run rules if applicable
            List<String> ruleActionMsgs = dataImportService.runRules(studyBean, userBean, containers, ruleSetService, ExecutionMode.SAVE);
            List<String> skippedCRFMsgs = getSkippedCRFMessages(importCrfInfo);
            return new DOMSource(mapConfirmation(auditMsgs, ruleActionMsgs, skippedCRFMsgs, importCrfInfo));
        } else {
            return new DOMSource(mapFailConfirmation(errors, null));
        }
    // //
    } catch (Exception e) {
        // return new DOMSource(mapFailConfirmation(null,"Your XML is not well-formed. "+ npe.getMessage()));
        LOG.error("Error processing data import request", e);
        throw new Exception(e);
    }
// return new DOMSource(mapConfirmation(xml, studyBean, userBean));
}
Also used : Locale(java.util.Locale) DOMSource(javax.xml.transform.dom.DOMSource) HashMap(java.util.HashMap) CRFDataImportValidator(org.akaza.openclinica.ws.validator.CRFDataImportValidator) StudyBean(org.akaza.openclinica.bean.managestudy.StudyBean) ArrayList(java.util.ArrayList) ImportDataRuleRunnerContainer(org.akaza.openclinica.logic.rulerunner.ImportDataRuleRunnerContainer) Errors(org.springframework.validation.Errors) ODMContainer(org.akaza.openclinica.bean.submit.crfdata.ODMContainer) BaseStudyDefinitionBean(org.akaza.openclinica.ws.bean.BaseStudyDefinitionBean) ImportCRFInfoContainer(org.akaza.openclinica.web.crfdata.ImportCRFInfoContainer) SubjectDataBean(org.akaza.openclinica.bean.submit.crfdata.SubjectDataBean) UserAccountBean(org.akaza.openclinica.bean.login.UserAccountBean) DataImportService(org.akaza.openclinica.web.crfdata.DataImportService) DataBinder(org.springframework.validation.DataBinder) DisplayItemBeanWrapper(org.akaza.openclinica.bean.submit.DisplayItemBeanWrapper)

Aggregations

ArrayList (java.util.ArrayList)6 ImportDataRuleRunnerContainer (org.akaza.openclinica.logic.rulerunner.ImportDataRuleRunnerContainer)6 SubjectDataBean (org.akaza.openclinica.bean.submit.crfdata.SubjectDataBean)5 HashMap (java.util.HashMap)3 DisplayItemBeanWrapper (org.akaza.openclinica.bean.submit.DisplayItemBeanWrapper)3 ODMContainer (org.akaza.openclinica.bean.submit.crfdata.ODMContainer)3 Date (java.util.Date)2 List (java.util.List)2 DiscrepancyNoteBean (org.akaza.openclinica.bean.managestudy.DiscrepancyNoteBean)2 DisplayItemBean (org.akaza.openclinica.bean.submit.DisplayItemBean)2 EventCRFBean (org.akaza.openclinica.bean.submit.EventCRFBean)2 ItemBean (org.akaza.openclinica.bean.submit.ItemBean)2 ItemDataBean (org.akaza.openclinica.bean.submit.ItemDataBean)2 ItemDAO (org.akaza.openclinica.dao.submit.ItemDAO)2 BufferedWriter (java.io.BufferedWriter)1 File (java.io.File)1 FileReader (java.io.FileReader)1 FileWriter (java.io.FileWriter)1 IOException (java.io.IOException)1 MessageFormat (java.text.MessageFormat)1