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));
}
Aggregations