Search in sources :

Example 31 with DataBinder

use of org.springframework.validation.DataBinder 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)

Example 32 with DataBinder

use of org.springframework.validation.DataBinder in project OpenClinica by OpenClinica.

the class StudyEndpoint method getStudyMetadata.

/**
     * if NAMESPACE_URI_V1:getStudyListRequest execute this method
     * 
     * @return
     * @throws Exception
     */
@PayloadRoot(localPart = "getMetadataRequest", namespace = NAMESPACE_URI_V1)
public Source getStudyMetadata(@XPathParam("//study:studyMetadata") NodeList studyNodeList) throws Exception {
    ResourceBundleProvider.updateLocale(new Locale("en_US"));
    Element studyRefElement = (Element) studyNodeList.item(0);
    //StudyMetadataRequestBean studyMetadataRequestBean = unMarshallRequest(studyRefElement);
    BaseStudyDefinitionBean studyMetadataRequestBean = unMarshallRequest(studyRefElement);
    DataBinder dataBinder = new DataBinder((studyMetadataRequestBean));
    Errors errors = dataBinder.getBindingResult();
    StudyMetadataRequestValidator studyMetadataRequestValidator = new StudyMetadataRequestValidator(dataSource);
    studyMetadataRequestValidator.validate((studyMetadataRequestBean), errors);
    if (!errors.hasErrors()) {
        return new DOMSource(mapSuccessConfirmation(getStudy(studyMetadataRequestBean), messages.getMessage("studyEndpoint.success", null, "Success", locale)));
    } else {
        return new DOMSource(mapConfirmation(messages.getMessage("studyEndpoint.fail", null, "Fail", locale), errors));
    }
}
Also used : Locale(java.util.Locale) Errors(org.springframework.validation.Errors) DOMSource(javax.xml.transform.dom.DOMSource) BaseStudyDefinitionBean(org.akaza.openclinica.ws.bean.BaseStudyDefinitionBean) Element(org.w3c.dom.Element) StudyMetadataRequestValidator(org.akaza.openclinica.ws.validator.StudyMetadataRequestValidator) DataBinder(org.springframework.validation.DataBinder) PayloadRoot(org.springframework.ws.server.endpoint.annotation.PayloadRoot)

Example 33 with DataBinder

use of org.springframework.validation.DataBinder in project OpenClinica by OpenClinica.

the class StudyEventDefinitionEndpoint method getStudyList.

/**
     * if NAMESPACE_URI_V1:getStudyListRequest execute this method
     * 
     * @return
     * @throws Exception
     */
@PayloadRoot(localPart = "listAllRequest", namespace = NAMESPACE_URI_V1)
public Source getStudyList(@XPathParam("//sed:studyEventDefinitionListAll") NodeList studyNodeList) throws Exception {
    ResourceBundleProvider.updateLocale(new Locale("en_US"));
    Element studyRefElement = (Element) studyNodeList.item(0);
    // StudyEventDefinitionRequestBean studyEventDefinitionRequestBean = unMarshallRequest(studyRefElement);
    BaseStudyDefinitionBean studyEventDefinitionRequestBean = unMarshallRequest(studyRefElement);
    DataBinder dataBinder = new DataBinder((studyEventDefinitionRequestBean));
    Errors errors = dataBinder.getBindingResult();
    StudyEventDefinitionRequestValidator studyEventDefinitionRequestValidator = new StudyEventDefinitionRequestValidator(dataSource);
    studyEventDefinitionRequestValidator.validate((studyEventDefinitionRequestBean), errors);
    if (!errors.hasErrors()) {
        return new DOMSource(mapConfirmation(getStudy(studyEventDefinitionRequestBean), messages.getMessage("studyEventDefinitionEndpoint.success", null, "Success", locale)));
    } else {
        return new DOMSource(mapFailConfirmation(messages.getMessage("studyEventDefinitionEndpoint.fail", null, "Fail", locale), errors));
    }
}
Also used : Locale(java.util.Locale) Errors(org.springframework.validation.Errors) StudyEventDefinitionRequestValidator(org.akaza.openclinica.ws.validator.StudyEventDefinitionRequestValidator) DOMSource(javax.xml.transform.dom.DOMSource) BaseStudyDefinitionBean(org.akaza.openclinica.ws.bean.BaseStudyDefinitionBean) Element(org.w3c.dom.Element) DataBinder(org.springframework.validation.DataBinder) PayloadRoot(org.springframework.ws.server.endpoint.annotation.PayloadRoot)

Example 34 with DataBinder

use of org.springframework.validation.DataBinder in project OpenClinica by OpenClinica.

the class StudySubjectEndpoint method isStudySubject.

/**
       * Use this method to find if studysubject exists by study/site/subject lable.
     * 
     * @param requestElement
     * @return studySubjectOID
     * @throws Exception
  */
@PayloadRoot(localPart = "isStudySubjectRequest", namespace = NAMESPACE_URI_V1)
public Source isStudySubject(@XPathParam("//studySubject:studySubject") NodeList subject) throws Exception {
    ResourceBundleProvider.updateLocale(locale);
    Element subjectElement = (Element) subject.item(0);
    // Element studyElement = (Element) study.item(0);
    //,studyElement);
    SubjectStudyDefinitionBean subjectStudyBean = unMarshallToSubjectStudy(subjectElement);
    DataBinder dataBinder = new DataBinder((subjectStudyBean));
    Errors errors = dataBinder.getBindingResult();
    SubjectTransferValidator subjectTransferValidator = new SubjectTransferValidator(dataSource);
    subjectTransferValidator.validateIsSubjectExists((subjectStudyBean), errors);
    if (subjectStudyBean.getSubjectOIDId() == null) {
        //case for core misfunction
        errors.reject("studySubjectEndpoint.fail");
    }
    if (!errors.hasErrors()) {
        return new DOMSource(mapConfirmation(messages.getMessage("studySubjectEndpoint.success", null, "Success", locale), subjectStudyBean.getSubjectOIDId(), errors, "subjectOID"));
    } else {
        return new DOMSource(mapConfirmation(messages.getMessage("studySubjectEndpoint.fail", null, "Fail", locale), null, errors));
    }
}
Also used : SubjectTransferValidator(org.akaza.openclinica.ws.validator.SubjectTransferValidator) Errors(org.springframework.validation.Errors) DOMSource(javax.xml.transform.dom.DOMSource) SubjectStudyDefinitionBean(org.akaza.openclinica.ws.bean.SubjectStudyDefinitionBean) JAXBElement(javax.xml.bind.JAXBElement) Element(org.w3c.dom.Element) DataBinder(org.springframework.validation.DataBinder) PayloadRoot(org.springframework.ws.server.endpoint.annotation.PayloadRoot)

Example 35 with DataBinder

use of org.springframework.validation.DataBinder in project OpenClinica by OpenClinica.

the class StudySubjectEndpoint method createStudySubject.

/**
     * Use this method to create new study subjects in OpenClinica.
     * 
     * @param subject
     * @return Source
     * @throws Exception
     */
@PayloadRoot(localPart = "createRequest", namespace = NAMESPACE_URI_V1)
public Source createStudySubject(@XPathParam("//studySubject:studySubject") NodeList subject) throws Exception {
    Errors errors = null;
    try {
        ResourceBundleProvider.updateLocale(locale);
        Element subjectElement = (Element) subject.item(0);
        SubjectTransferBean subjectTransferBean = unMarshallToSubjectTransfer(subjectElement);
        DataBinder dataBinder = new DataBinder((subjectTransferBean));
        errors = dataBinder.getBindingResult();
        subjectTransferBean.setOwner(getUserAccount());
        SubjectTransferValidator subjectTransferValidator = new SubjectTransferValidator(dataSource);
        subjectTransferValidator.validate((subjectTransferBean), errors);
        if (!errors.hasErrors()) {
            String label = create(subjectTransferBean);
            return new DOMSource(mapConfirmation(messages.getMessage("studySubjectEndpoint.success", null, "Success", locale), label, errors));
        } else {
            return new DOMSource(mapConfirmation(messages.getMessage("studySubjectEndpoint.fail", null, "Fail", locale), null, errors));
        }
    } catch (NullPointerException npe) {
        npe.printStackTrace();
        return new DOMSource(mapConfirmation(messages.getMessage("studySubjectEndpoint.fail", null, "Null Pointer Exception", locale), null, errors));
    } catch (Exception e) {
        List<String> error_messages = new ArrayList<String>();
        error_messages.add(e.getMessage());
        return new DOMSource(mapConfirmation(messages.getMessage("studySubjectEndpoint.fail", null, "Fail", locale), null, errors, "label", error_messages));
    }
}
Also used : SubjectTransferValidator(org.akaza.openclinica.ws.validator.SubjectTransferValidator) Errors(org.springframework.validation.Errors) DOMSource(javax.xml.transform.dom.DOMSource) JAXBElement(javax.xml.bind.JAXBElement) Element(org.w3c.dom.Element) List(java.util.List) ArrayList(java.util.ArrayList) NodeList(org.w3c.dom.NodeList) DataBinder(org.springframework.validation.DataBinder) ParseException(java.text.ParseException) OpenClinicaSystemException(org.akaza.openclinica.exception.OpenClinicaSystemException) PayloadRoot(org.springframework.ws.server.endpoint.annotation.PayloadRoot)

Aggregations

DataBinder (org.springframework.validation.DataBinder)36 Test (org.junit.Test)15 Errors (org.springframework.validation.Errors)14 Locale (java.util.Locale)8 MutablePropertyValues (org.springframework.beans.MutablePropertyValues)7 ArrayList (java.util.ArrayList)6 DOMSource (javax.xml.transform.dom.DOMSource)6 OpenClinicaSystemException (org.akaza.openclinica.exception.OpenClinicaSystemException)5 Element (org.w3c.dom.Element)5 HashMap (java.util.HashMap)4 FileItem (org.apache.commons.fileupload.FileItem)4 DiskFileItemFactory (org.apache.commons.fileupload.disk.DiskFileItemFactory)4 ServletFileUpload (org.apache.commons.fileupload.servlet.ServletFileUpload)4 MapPropertySource (org.springframework.core.env.MapPropertySource)4 PayloadRoot (org.springframework.ws.server.endpoint.annotation.PayloadRoot)4 File (java.io.File)3 LinkedHashMap (java.util.LinkedHashMap)3 FileProperties (org.akaza.openclinica.bean.rule.FileProperties)3 Study (org.akaza.openclinica.domain.datamap.Study)3 PFormCache (org.akaza.openclinica.web.pform.PFormCache)3