Search in sources :

Example 1 with CRFDataImportValidator

use of org.akaza.openclinica.ws.validator.CRFDataImportValidator 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)1 HashMap (java.util.HashMap)1 Locale (java.util.Locale)1 DOMSource (javax.xml.transform.dom.DOMSource)1 UserAccountBean (org.akaza.openclinica.bean.login.UserAccountBean)1 StudyBean (org.akaza.openclinica.bean.managestudy.StudyBean)1 DisplayItemBeanWrapper (org.akaza.openclinica.bean.submit.DisplayItemBeanWrapper)1 ODMContainer (org.akaza.openclinica.bean.submit.crfdata.ODMContainer)1 SubjectDataBean (org.akaza.openclinica.bean.submit.crfdata.SubjectDataBean)1 ImportDataRuleRunnerContainer (org.akaza.openclinica.logic.rulerunner.ImportDataRuleRunnerContainer)1 DataImportService (org.akaza.openclinica.web.crfdata.DataImportService)1 ImportCRFInfoContainer (org.akaza.openclinica.web.crfdata.ImportCRFInfoContainer)1 BaseStudyDefinitionBean (org.akaza.openclinica.ws.bean.BaseStudyDefinitionBean)1 CRFDataImportValidator (org.akaza.openclinica.ws.validator.CRFDataImportValidator)1 DataBinder (org.springframework.validation.DataBinder)1 Errors (org.springframework.validation.Errors)1