Search in sources :

Example 1 with ODataDeserializerException

use of org.apache.olingo.client.api.serialization.ODataDeserializerException in project teiid by teiid.

the class ODataProcedureExecution method execute.

@Override
public void execute() throws TranslatorException {
    try {
        String parameters = getQueryParameters(this.command);
        InputStream response = null;
        Procedure procedure = this.command.getMetadataObject();
        if (isFunction(procedure)) {
            String URI = buildFunctionURL(this.command, parameters);
            response = executeQuery("GET", URI, null, null, new HttpStatusCode[] { HttpStatusCode.OK });
            handleResponse(procedure, URI, response);
        } else {
            String URI = this.command.getProcedureName();
            response = executeQuery("POST", URI, parameters, null, new HttpStatusCode[] { HttpStatusCode.OK });
            handleResponse(procedure, URI, response);
        }
    } catch (ODataDeserializerException e) {
        throw new TranslatorException(e);
    } catch (EdmPrimitiveTypeException e) {
        throw new TranslatorException(e);
    }
}
Also used : InputStream(java.io.InputStream) HttpStatusCode(org.apache.olingo.commons.api.http.HttpStatusCode) Procedure(org.teiid.metadata.Procedure) TranslatorException(org.teiid.translator.TranslatorException) ODataDeserializerException(org.apache.olingo.client.api.serialization.ODataDeserializerException) EdmPrimitiveTypeException(org.apache.olingo.commons.api.edm.EdmPrimitiveTypeException)

Example 2 with ODataDeserializerException

use of org.apache.olingo.client.api.serialization.ODataDeserializerException in project teiid by teiid.

the class ODataResponse method parsePayload.

private Iterator<ODataDocument> parsePayload(InputStream payload) throws TranslatorException {
    try {
        JsonDeserializer parser = new JsonDeserializer(false);
        if (this.resultsType == ODataType.ENTITY) {
            Entity entity = parser.toEntity(payload).getPayload();
            ODataDocument document = ODataDocument.createDocument(entity);
            return Arrays.asList(document).iterator();
        } else if (this.resultsType == ODataType.ENTITY_COLLECTION) {
            EntityCollection entityCollection = parser.toEntitySet(payload).getPayload();
            this.nextUri = entityCollection.getNext();
            ArrayList<ODataDocument> documents = new ArrayList<ODataDocument>();
            for (Entity entity : entityCollection.getEntities()) {
                documents.add(ODataDocument.createDocument(entity));
            }
            return documents.iterator();
        } else {
            // complex
            Property property = parser.toProperty(payload).getPayload();
            if (property.isCollection()) {
                ArrayList<ODataDocument> documents = new ArrayList<ODataDocument>();
                for (Object obj : property.asCollection()) {
                    ComplexValue complexValue = (ComplexValue) obj;
                    documents.add(ODataDocument.createDocument(complexValue));
                }
                return documents.iterator();
            } else {
                ODataDocument document = ODataDocument.createDocument(property.asComplex());
                return Arrays.asList(document).iterator();
            }
        }
    } catch (ODataDeserializerException e) {
        throw new TranslatorException(e);
    }
}
Also used : Entity(org.apache.olingo.commons.api.data.Entity) ComplexValue(org.apache.olingo.commons.api.data.ComplexValue) EntityCollection(org.apache.olingo.commons.api.data.EntityCollection) ArrayList(java.util.ArrayList) TranslatorException(org.teiid.translator.TranslatorException) ODataDeserializerException(org.apache.olingo.client.api.serialization.ODataDeserializerException) JsonDeserializer(org.apache.olingo.client.core.serialization.JsonDeserializer) Property(org.apache.olingo.commons.api.data.Property)

Example 3 with ODataDeserializerException

use of org.apache.olingo.client.api.serialization.ODataDeserializerException in project teiid by teiid.

the class ODataUpdateExecution method handleInsert.

private void handleInsert(ODataUpdateQuery odataQuery) throws TranslatorException {
    try {
        Map<String, List<String>> headers = getDefaultUpdateHeaders();
        // $NON-NLS-1$
        headers.put("Prefer", Arrays.asList("return=representation"));
        String uri = odataQuery.buildInsertURL("");
        InputStream response = null;
        BinaryWSProcedureExecution execution = invokeHTTP(odataQuery.getInsertMethod(), uri, odataQuery.getPayload(null), headers);
        // 201 - the created entity returned
        if (HttpStatusCode.CREATED.getStatusCode() == execution.getResponseCode()) {
            Blob blob = (Blob) execution.getOutputParameterValues().get(0);
            response = blob.getBinaryStream();
        } else if (HttpStatusCode.NO_CONTENT.getStatusCode() == execution.getResponseCode()) {
            // get Location header and get content
            String entityUri = (String) execution.getResponseHeader("Location");
            if (entityUri != null) {
                // in the cases of property update there will be no Location header
                response = executeQuery("GET", entityUri, null, null, new HttpStatusCode[] { HttpStatusCode.OK });
            }
        } else {
            throw buildError(execution);
        }
        if (response != null) {
            JsonDeserializer serializer = new JsonDeserializer(false);
            this.createdEntity = serializer.toEntity(response).getPayload();
        }
    } catch (ODataDeserializerException e) {
        throw new TranslatorException(e);
    } catch (SQLException e) {
        throw new TranslatorException(e);
    }
}
Also used : Blob(java.sql.Blob) SQLException(java.sql.SQLException) InputStream(java.io.InputStream) BinaryWSProcedureExecution(org.teiid.translator.ws.BinaryWSProcedureExecution) ArrayList(java.util.ArrayList) List(java.util.List) TranslatorException(org.teiid.translator.TranslatorException) ODataDeserializerException(org.apache.olingo.client.api.serialization.ODataDeserializerException) JsonDeserializer(org.apache.olingo.client.core.serialization.JsonDeserializer)

Aggregations

ODataDeserializerException (org.apache.olingo.client.api.serialization.ODataDeserializerException)3 TranslatorException (org.teiid.translator.TranslatorException)3 InputStream (java.io.InputStream)2 ArrayList (java.util.ArrayList)2 JsonDeserializer (org.apache.olingo.client.core.serialization.JsonDeserializer)2 Blob (java.sql.Blob)1 SQLException (java.sql.SQLException)1 List (java.util.List)1 ComplexValue (org.apache.olingo.commons.api.data.ComplexValue)1 Entity (org.apache.olingo.commons.api.data.Entity)1 EntityCollection (org.apache.olingo.commons.api.data.EntityCollection)1 Property (org.apache.olingo.commons.api.data.Property)1 EdmPrimitiveTypeException (org.apache.olingo.commons.api.edm.EdmPrimitiveTypeException)1 HttpStatusCode (org.apache.olingo.commons.api.http.HttpStatusCode)1 Procedure (org.teiid.metadata.Procedure)1 BinaryWSProcedureExecution (org.teiid.translator.ws.BinaryWSProcedureExecution)1