Search in sources :

Example 1 with RetrievedDocument

use of org.openehealth.ipf.commons.ihe.xds.core.responses.RetrievedDocument in project MobileAccessGateway by i4mi.

the class Iti68ResponseConverter method retrievedDocumentSetToHttResponse.

public static Object retrievedDocumentSetToHttResponse(@Body RetrievedDocumentSet retrievedDocumentSet, @Headers Map<String, Object> headers) throws IOException {
    if (Status.SUCCESS.equals(retrievedDocumentSet.getStatus())) {
        List<RetrievedDocument> documentResponses = retrievedDocumentSet.getDocuments();
        if (documentResponses.size() == 1) {
            RetrievedDocument documentResponse = documentResponses.get(0);
            final InputStream in = documentResponse.getDataHandler().getInputStream();
            byte[] byteArray = org.apache.commons.io.IOUtils.toByteArray(in);
            headers.clear();
            headers.put("Content-Type", documentResponse.getMimeType());
            return byteArray;
        }
    } else {
        headers.put(Exchange.HTTP_RESPONSE_CODE, 400);
        List<ErrorInfo> errors = retrievedDocumentSet.getErrors();
        StringBuffer result = new StringBuffer();
        for (ErrorInfo error : errors) {
            result.append(error.getCodeContext());
        }
        return result;
    }
    return null;
}
Also used : RetrievedDocument(org.openehealth.ipf.commons.ihe.xds.core.responses.RetrievedDocument) InputStream(java.io.InputStream) ErrorInfo(org.openehealth.ipf.commons.ihe.xds.core.responses.ErrorInfo)

Example 2 with RetrievedDocument

use of org.openehealth.ipf.commons.ihe.xds.core.responses.RetrievedDocument in project ipf by oehf.

the class SerializationTest method testRetrievedDocumentSet.

@Test
public void testRetrievedDocumentSet() throws Exception {
    RetrievedDocumentSet response = SampleData.createRetrievedDocumentSet();
    for (RetrievedDocument doc : response.getDocuments()) {
        doc.setDataHandler(null);
    }
    checkSerialization(response);
}
Also used : RetrievedDocument(org.openehealth.ipf.commons.ihe.xds.core.responses.RetrievedDocument) RetrievedDocumentSet(org.openehealth.ipf.commons.ihe.xds.core.responses.RetrievedDocumentSet) Test(org.junit.jupiter.api.Test)

Aggregations

RetrievedDocument (org.openehealth.ipf.commons.ihe.xds.core.responses.RetrievedDocument)2 InputStream (java.io.InputStream)1 Test (org.junit.jupiter.api.Test)1 ErrorInfo (org.openehealth.ipf.commons.ihe.xds.core.responses.ErrorInfo)1 RetrievedDocumentSet (org.openehealth.ipf.commons.ihe.xds.core.responses.RetrievedDocumentSet)1