Search in sources :

Example 11 with PayloadRoot

use of org.springframework.ws.server.endpoint.annotation.PayloadRoot 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) SubjectTransferBean(org.akaza.openclinica.bean.managestudy.SubjectTransferBean) ParseException(java.text.ParseException) OpenClinicaSystemException(org.akaza.openclinica.exception.OpenClinicaSystemException) PayloadRoot(org.springframework.ws.server.endpoint.annotation.PayloadRoot)

Example 12 with PayloadRoot

use of org.springframework.ws.server.endpoint.annotation.PayloadRoot 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)

Aggregations

PayloadRoot (org.springframework.ws.server.endpoint.annotation.PayloadRoot)12 DOMSource (javax.xml.transform.dom.DOMSource)6 Element (org.w3c.dom.Element)6 DataBinder (org.springframework.validation.DataBinder)4 Errors (org.springframework.validation.Errors)4 ParseException (java.text.ParseException)3 Date (java.util.Date)3 Locale (java.util.Locale)3 SubjectTransferBean (org.akaza.openclinica.bean.managestudy.SubjectTransferBean)3 SimpleDateFormat (java.text.SimpleDateFormat)2 JAXBElement (javax.xml.bind.JAXBElement)2 OpenClinicaSystemException (org.akaza.openclinica.exception.OpenClinicaSystemException)2 BaseStudyDefinitionBean (org.akaza.openclinica.ws.bean.BaseStudyDefinitionBean)2 SubjectTransferValidator (org.akaza.openclinica.ws.validator.SubjectTransferValidator)2 ResponsePayload (org.springframework.ws.server.endpoint.annotation.ResponsePayload)2 FileOutputStream (java.io.FileOutputStream)1 StringWriter (java.io.StringWriter)1 ArrayList (java.util.ArrayList)1 List (java.util.List)1 StreamResult (javax.xml.transform.stream.StreamResult)1