Search in sources :

Example 1 with ODataType

use of org.teiid.translator.odata4.ODataMetadataProcessor.ODataType in project teiid by teiid.

the class TestODataMetadataProcessor method testAction.

@Test
public void testAction() throws Exception {
    CsdlReturnType returnType = new CsdlReturnType();
    returnType.setType("Edm.String");
    MetadataFactory mf = actionMetadata("invoke", returnType, null);
    Procedure p = mf.getSchema().getProcedure("invoke");
    assertNotNull(p);
    assertEquals(3, p.getParameters().size());
    assertNull(p.getResultSet());
    assertNotNull(getReturnParameter(p));
    ProcedureParameter pp = getReturnParameter(p);
    assertEquals("string", pp.getRuntimeType());
    ODataType type = ODataType.valueOf(p.getProperty(ODataMetadataProcessor.ODATA_TYPE, false));
    assertEquals(ODataType.ACTION, type);
}
Also used : ProcedureParameter(org.teiid.metadata.ProcedureParameter) RealMetadataFactory(org.teiid.query.unittest.RealMetadataFactory) MetadataFactory(org.teiid.metadata.MetadataFactory) ODataType(org.teiid.translator.odata4.ODataMetadataProcessor.ODataType) Procedure(org.teiid.metadata.Procedure) Test(org.junit.Test)

Example 2 with ODataType

use of org.teiid.translator.odata4.ODataMetadataProcessor.ODataType in project teiid by teiid.

the class TestODataMetadataProcessor method testFunctionReturnComplexCollection.

@Test
public void testFunctionReturnComplexCollection() throws Exception {
    CsdlComplexType complex = complexType("Address");
    CsdlReturnType returnType = new CsdlReturnType();
    returnType.setType("namespace.Address");
    returnType.setCollection(true);
    MetadataFactory mf = functionMetadata("invoke", returnType, complex);
    Procedure p = mf.getSchema().getProcedure("invoke");
    assertNotNull(p);
    assertEquals(2, p.getParameters().size());
    assertNotNull(p.getResultSet());
    assertNull(getReturnParameter(p));
    ColumnSet<Procedure> table = p.getResultSet();
    ODataType type = ODataType.valueOf(p.getProperty(ODataMetadataProcessor.ODATA_TYPE, false));
    assertEquals(ODataType.FUNCTION, type);
    type = ODataType.valueOf(table.getProperty(ODataMetadataProcessor.ODATA_TYPE, false));
    assertEquals(ODataType.COMPLEX_COLLECTION, type);
}
Also used : RealMetadataFactory(org.teiid.query.unittest.RealMetadataFactory) MetadataFactory(org.teiid.metadata.MetadataFactory) ODataType(org.teiid.translator.odata4.ODataMetadataProcessor.ODataType) Procedure(org.teiid.metadata.Procedure) Test(org.junit.Test)

Example 3 with ODataType

use of org.teiid.translator.odata4.ODataMetadataProcessor.ODataType in project teiid by teiid.

the class TestODataMetadataProcessor method testFunctionReturnPrimitiveCollection.

@Test
public void testFunctionReturnPrimitiveCollection() throws Exception {
    CsdlReturnType returnType = new CsdlReturnType();
    returnType.setType("Edm.String");
    returnType.setCollection(true);
    MetadataFactory mf = functionMetadata("invoke", returnType, null);
    Procedure p = mf.getSchema().getProcedure("invoke");
    assertNotNull(p);
    assertEquals(3, p.getParameters().size());
    assertNull(p.getResultSet());
    assertNotNull(getReturnParameter(p));
    ProcedureParameter pp = getReturnParameter(p);
    assertEquals("string[]", pp.getRuntimeType());
    ODataType type = ODataType.valueOf(p.getProperty(ODataMetadataProcessor.ODATA_TYPE, false));
    assertEquals(ODataType.FUNCTION, type);
}
Also used : ProcedureParameter(org.teiid.metadata.ProcedureParameter) RealMetadataFactory(org.teiid.query.unittest.RealMetadataFactory) MetadataFactory(org.teiid.metadata.MetadataFactory) ODataType(org.teiid.translator.odata4.ODataMetadataProcessor.ODataType) Procedure(org.teiid.metadata.Procedure) Test(org.junit.Test)

Example 4 with ODataType

use of org.teiid.translator.odata4.ODataMetadataProcessor.ODataType in project teiid by teiid.

the class ODataProcedureExecution method handleResponse.

private void handleResponse(final Procedure procedure, final String baseUri, final InputStream payload) throws TranslatorException, ODataDeserializerException {
    if (procedure.getResultSet() != null) {
        ODataType type = ODataType.valueOf(procedure.getResultSet().getProperty(ODataMetadataProcessor.ODATA_TYPE, false));
        this.response = new ODataResponse(payload, type, new DocumentNode()) {

            @Override
            public InputStream nextBatch(java.net.URI uri) throws TranslatorException {
                return executeSkipToken(uri, baseUri, new HttpStatusCode[] { HttpStatusCode.OK });
            }
        };
    } else if (getReturnParameter() != null) {
        // this is scalar result
        JsonDeserializer parser = new JsonDeserializer(false);
        Property property = parser.toProperty(payload).getPayload();
        if (property.isCollection()) {
            this.returnValue = property.asCollection();
        } else {
            this.returnValue = property.asPrimitive();
        }
    }
}
Also used : DocumentNode(org.teiid.translator.document.DocumentNode) InputStream(java.io.InputStream) ODataType(org.teiid.translator.odata4.ODataMetadataProcessor.ODataType) HttpStatusCode(org.apache.olingo.commons.api.http.HttpStatusCode) TranslatorException(org.teiid.translator.TranslatorException) JsonDeserializer(org.apache.olingo.client.core.serialization.JsonDeserializer) Property(org.apache.olingo.commons.api.data.Property)

Example 5 with ODataType

use of org.teiid.translator.odata4.ODataMetadataProcessor.ODataType in project teiid by teiid.

the class TestODataMetadataProcessor method testFunctionReturnComplex.

@Test
public void testFunctionReturnComplex() throws Exception {
    CsdlComplexType complex = complexType("Address");
    CsdlReturnType returnType = new CsdlReturnType();
    returnType.setType("namespace.Address");
    MetadataFactory mf = functionMetadata("invoke", returnType, complex);
    Procedure p = mf.getSchema().getProcedure("invoke");
    assertNotNull(p);
    assertEquals(2, p.getParameters().size());
    assertNotNull(p.getResultSet());
    assertNull(getReturnParameter(p));
    ColumnSet<Procedure> table = p.getResultSet();
    ODataType type = ODataType.valueOf(p.getProperty(ODataMetadataProcessor.ODATA_TYPE, false));
    assertEquals(ODataType.FUNCTION, type);
    type = ODataType.valueOf(table.getProperty(ODataMetadataProcessor.ODATA_TYPE, false));
    assertEquals(ODataType.COMPLEX, type);
}
Also used : RealMetadataFactory(org.teiid.query.unittest.RealMetadataFactory) MetadataFactory(org.teiid.metadata.MetadataFactory) ODataType(org.teiid.translator.odata4.ODataMetadataProcessor.ODataType) Procedure(org.teiid.metadata.Procedure) Test(org.junit.Test)

Aggregations

ODataType (org.teiid.translator.odata4.ODataMetadataProcessor.ODataType)6 Test (org.junit.Test)5 MetadataFactory (org.teiid.metadata.MetadataFactory)5 Procedure (org.teiid.metadata.Procedure)5 RealMetadataFactory (org.teiid.query.unittest.RealMetadataFactory)5 ProcedureParameter (org.teiid.metadata.ProcedureParameter)3 InputStream (java.io.InputStream)1 JsonDeserializer (org.apache.olingo.client.core.serialization.JsonDeserializer)1 Property (org.apache.olingo.commons.api.data.Property)1 HttpStatusCode (org.apache.olingo.commons.api.http.HttpStatusCode)1 TranslatorException (org.teiid.translator.TranslatorException)1 DocumentNode (org.teiid.translator.document.DocumentNode)1