Search in sources :

Example 1 with ODataVersion

use of org.odata4j.core.ODataVersion in project teiid by teiid.

the class BaseQueryExecution method getDataServiceVersion.

protected static ODataVersion getDataServiceVersion(String headerValue) {
    ODataVersion version = ODataConstants.DATA_SERVICE_VERSION;
    if (headerValue != null) {
        // $NON-NLS-1$
        String[] str = headerValue.split(";");
        version = ODataVersion.parse(str[0]);
    }
    return version;
}
Also used : ODataVersion(org.odata4j.core.ODataVersion)

Example 2 with ODataVersion

use of org.odata4j.core.ODataVersion in project teiid by teiid.

the class ODataProcedureExecution method execute.

@Override
public void execute() throws TranslatorException {
    String URI = this.visitor.buildURL();
    Schema schema = visitor.getProcedure().getParent();
    EdmDataServices edm = new TeiidEdmMetadata(schema.getName(), ODataEntitySchemaBuilder.buildMetadata(schema));
    if (this.visitor.hasCollectionReturn()) {
        if (this.visitor.isReturnComplexType()) {
            // complex return
            this.response = executeWithComplexReturn(this.visitor.getMethod(), URI, null, this.visitor.getReturnEntityTypeName(), edm, null, Status.OK, Status.NO_CONTENT);
        } else {
            // entity type return
            this.response = executeWithReturnEntity(this.visitor.getMethod(), URI, null, this.visitor.getTable().getName(), edm, null, Status.OK, Status.NO_CONTENT);
        }
        if (this.response != null && this.response.hasError()) {
            throw this.response.getError();
        }
    } else {
        try {
            BinaryWSProcedureExecution execution = executeDirect(this.visitor.getMethod(), URI, null, getDefaultHeaders());
            if (execution.getResponseCode() != Status.OK.getStatusCode()) {
                throw buildError(execution);
            }
            Blob blob = (Blob) execution.getOutputParameterValues().get(0);
            ODataVersion version = getODataVersion(execution);
            // if the procedure is not void
            if (this.visitor.getReturnType() != null) {
                FormatParser<? extends OObject> parser = FormatParserFactory.getParser(OSimpleObject.class, FormatType.ATOM, new Settings(version, edm, this.visitor.getProcedure().getName(), // entitykey
                null, // isResponse
                true, ODataTypeManager.odataType(this.visitor.getReturnType())));
                OSimpleObject object = (OSimpleObject) parser.parse(new InputStreamReader(blob.getBinaryStream()));
                this.returnValue = this.translator.retrieveValue(object.getValue(), this.visitor.getReturnTypeClass());
            }
        } catch (SQLException e) {
            throw new TranslatorException(e);
        }
    }
}
Also used : Blob(java.sql.Blob) OSimpleObject(org.odata4j.core.OSimpleObject) InputStreamReader(java.io.InputStreamReader) SQLException(java.sql.SQLException) Schema(org.teiid.metadata.Schema) BinaryWSProcedureExecution(org.teiid.translator.ws.BinaryWSProcedureExecution) ODataVersion(org.odata4j.core.ODataVersion) EdmDataServices(org.odata4j.edm.EdmDataServices) TranslatorException(org.teiid.translator.TranslatorException) Settings(org.odata4j.format.Settings)

Example 3 with ODataVersion

use of org.odata4j.core.ODataVersion in project teiid by teiid.

the class BaseQueryExecution method executeWithReturnEntity.

protected ODataEntitiesResponse executeWithReturnEntity(String method, String uri, String payload, String entityTable, EdmDataServices edsMetadata, String eTag, Status... expectedStatus) throws TranslatorException {
    Map<String, List<String>> headers = getDefaultHeaders();
    if (eTag != null) {
        // $NON-NLS-1$
        headers.put("If-Match", Arrays.asList(eTag));
    }
    if (payload != null) {
        // $NON-NLS-1$ //$NON-NLS-2$
        headers.put("Content-Type", Arrays.asList("application/atom+xml"));
    }
    BinaryWSProcedureExecution execution = executeDirect(method, uri, payload, headers);
    for (Status status : expectedStatus) {
        if (status.getStatusCode() == execution.getResponseCode()) {
            if (execution.getResponseCode() != Status.NO_CONTENT.getStatusCode() && execution.getResponseCode() != Status.NOT_FOUND.getStatusCode()) {
                Blob blob = (Blob) execution.getOutputParameterValues().get(0);
                ODataVersion version = getODataVersion(execution);
                Feed feed = parse(blob, version, entityTable, edsMetadata);
                return new ODataEntitiesResponse(uri, feed, entityTable, edsMetadata);
            }
            // this is success with no-data
            return new ODataEntitiesResponse();
        }
    }
    // throw an error
    return new ODataEntitiesResponse(buildError(execution));
}
Also used : Status(javax.ws.rs.core.Response.Status) Blob(java.sql.Blob) BinaryWSProcedureExecution(org.teiid.translator.ws.BinaryWSProcedureExecution) ODataVersion(org.odata4j.core.ODataVersion) ArrayList(java.util.ArrayList) List(java.util.List) Feed(org.odata4j.format.Feed)

Aggregations

ODataVersion (org.odata4j.core.ODataVersion)3 Blob (java.sql.Blob)2 BinaryWSProcedureExecution (org.teiid.translator.ws.BinaryWSProcedureExecution)2 InputStreamReader (java.io.InputStreamReader)1 SQLException (java.sql.SQLException)1 ArrayList (java.util.ArrayList)1 List (java.util.List)1 Status (javax.ws.rs.core.Response.Status)1 OSimpleObject (org.odata4j.core.OSimpleObject)1 EdmDataServices (org.odata4j.edm.EdmDataServices)1 Feed (org.odata4j.format.Feed)1 Settings (org.odata4j.format.Settings)1 Schema (org.teiid.metadata.Schema)1 TranslatorException (org.teiid.translator.TranslatorException)1