Search in sources :

Example 51 with Procedure

use of org.teiid.metadata.Procedure in project teiid by teiid.

the class ODataProcedureVisitor method visit.

@Override
public void visit(Call obj) {
    Procedure proc = obj.getMetadataObject();
    this.method = proc.getProperty(ODataMetadataProcessor.HTTP_METHOD, false);
    this.procedure = proc;
    this.buffer.append(obj.getProcedureName());
    final List<Argument> params = obj.getArguments();
    if (params != null && params.size() != 0) {
        // $NON-NLS-1$
        this.buffer.append("?");
        Argument param = null;
        StringBuilder temp = new StringBuilder();
        for (int i = 0; i < params.size(); i++) {
            param = params.get(i);
            if (param.getDirection() == Direction.IN || param.getDirection() == Direction.INOUT) {
                if (i != 0) {
                    // $NON-NLS-1$
                    this.buffer.append("&");
                }
                this.buffer.append(WSConnection.Util.httpURLEncode(param.getMetadataObject().getName()));
                this.buffer.append(Tokens.EQ);
                this.executionFactory.convertToODataInput(param.getArgumentValue(), temp);
                this.buffer.append(WSConnection.Util.httpURLEncode(temp.toString()));
                temp.setLength(0);
            }
        }
    }
    // this is collection based result
    if (proc.getResultSet() != null) {
        this.returnsTable = true;
        this.returnEntityTypeName = proc.getProperty(ODataMetadataProcessor.ENTITY_TYPE, false);
        this.entity = getTableWithEntityType(proc.getParent(), returnEntityTypeName);
        this.isComplexReturnType = (this.entity == null);
        this.returnColumns = proc.getResultSet().getColumns();
    } else {
        for (ProcedureParameter param : proc.getParameters()) {
            if (param.getType().equals(ProcedureParameter.Type.ReturnValue)) {
                this.returnType = param.getRuntimeType();
                this.returnTypeClass = param.getJavaType();
            }
        }
    }
}
Also used : ProcedureParameter(org.teiid.metadata.ProcedureParameter) Argument(org.teiid.language.Argument) Procedure(org.teiid.metadata.Procedure)

Example 52 with Procedure

use of org.teiid.metadata.Procedure in project teiid by teiid.

the class SwaggerProcedureExecution method next.

@Override
public List<?> next() throws TranslatorException, DataNotAvailableException {
    Procedure procedure = this.command.getMetadataObject();
    if (this.response != null) {
        Map<String, Object> row = this.response.getNext();
        if (row != null) {
            row.putAll(this.responseHeaders);
            return buildRow(procedure.getResultSet().getColumns(), this.response.isMapResponse(), this.expectedColumnTypes, row);
        }
    }
    if (this.returnValue != null) {
        Map<String, Object> row = new LinkedHashMap<String, Object>();
        row.put("return", SwaggerTypeManager.convertTeiidRuntimeType(this.returnValue, this.expectedColumnTypes[0]));
        row.putAll(this.responseHeaders);
        this.returnValue = null;
        return buildRow(procedure.getResultSet().getColumns(), false, this.expectedColumnTypes, row);
    }
    return null;
}
Also used : Procedure(org.teiid.metadata.Procedure) LinkedHashMap(java.util.LinkedHashMap)

Example 53 with Procedure

use of org.teiid.metadata.Procedure in project teiid by teiid.

the class TestSwaggerMetadataProcessor method testDateTime.

@Test
public void testDateTime() throws TranslatorException {
    SwaggerExecutionFactory translator = new SwaggerExecutionFactory();
    translator.start();
    MetadataFactory mf = swaggerMetadata(translator);
    Procedure p = mf.getSchema().getProcedure("testTimeTypes");
    assertNotNull(p);
    assertEquals("GET", p.getProperty(RestMetadataExtension.METHOD, false).toUpperCase());
    assertEquals("http://localhost:8080/test/testTimeTypes", p.getProperty(RestMetadataExtension.URI, false));
    assertNotNull(p.getResultSet());
    List<Column> columns = p.getResultSet().getColumns();
    for (int i = 0; i < columns.size(); i++) {
        Column column = columns.get(i);
        Class<?> type = column.getJavaType();
        assertEquals(java.sql.Timestamp.class, type);
    }
}
Also used : RealMetadataFactory(org.teiid.query.unittest.RealMetadataFactory) MetadataFactory(org.teiid.metadata.MetadataFactory) Column(org.teiid.metadata.Column) Procedure(org.teiid.metadata.Procedure) Test(org.junit.Test)

Example 54 with Procedure

use of org.teiid.metadata.Procedure in project teiid by teiid.

the class TestSwaggerMetadataProcessor method testRefToProcedureParam.

@Test
public void testRefToProcedureParam() throws TranslatorException {
    SwaggerExecutionFactory translator = new SwaggerExecutionFactory();
    translator.start();
    MetadataFactory mf = petstoreMetadata(translator);
    Procedure p = mf.getSchema().getProcedure("addPet");
    assertNotNull(p);
    assertEquals("POST", p.getProperty(RestMetadataExtension.METHOD, false).toUpperCase());
    assertEquals("http://petstore.swagger.io/v2/pet", p.getProperty(RestMetadataExtension.URI, false));
    ProcedureParameter pa = p.getParameterByName("id");
    assertNull(pa.getNameInSource());
    assertEquals("body", pa.getProperty("teiid_rest:PARAMETER_TYPE", false));
    pa = p.getParameterByName("category_id");
    assertEquals("category/id", pa.getNameInSource());
    assertEquals("body", pa.getProperty("teiid_rest:PARAMETER_TYPE", false));
    pa = p.getParameterByName("tags_Tag_id");
    assertEquals("tags[]/Tag/id", pa.getNameInSource());
    assertEquals("body", pa.getProperty("teiid_rest:PARAMETER_TYPE", false));
    // TODO: the logic could support this as a long array as well
    assertEquals("long", pa.getRuntimeType());
}
Also used : ProcedureParameter(org.teiid.metadata.ProcedureParameter) RealMetadataFactory(org.teiid.query.unittest.RealMetadataFactory) MetadataFactory(org.teiid.metadata.MetadataFactory) Procedure(org.teiid.metadata.Procedure) Test(org.junit.Test)

Example 55 with Procedure

use of org.teiid.metadata.Procedure in project teiid by teiid.

the class TestSwaggerMetadataProcessor method testSwaggerINParameterTypes.

@Test
public void testSwaggerINParameterTypes() throws TranslatorException {
    SwaggerExecutionFactory translator = new SwaggerExecutionFactory();
    translator.start();
    MetadataFactory mf = swaggerMetadata(translator);
    for (Procedure p : mf.getSchema().getProcedures().values()) {
        // multiple in parameter
        if (p.getName().equals("getByNumCityCountry")) {
            List<ProcedureParameter> params = p.getParameters();
            for (ProcedureParameter param : params) {
                assertEquals(RestMetadataExtension.ParameterType.QUERY.name(), param.getProperty(RestMetadataExtension.PARAMETER_TYPE, false).toUpperCase());
            }
            assertEquals(3, params.size());
            assertTrue(params.get(0).getName().equalsIgnoreCase("customernumber"));
            assertTrue(params.get(1).getName().equalsIgnoreCase("city"));
            assertTrue(params.get(2).getName().equalsIgnoreCase("country"));
        } else // QueryParameter and  PathParameter
        if (p.getName().equals("getCustomerByCity") || p.getName().equals("getCustomerByCountry") && p.getName().equals("getByNumCityCountry")) {
            for (ProcedureParameter param : p.getParameters()) {
                assertEquals(RestMetadataExtension.ParameterType.QUERY.name(), param.getProperty(RestMetadataExtension.PARAMETER_TYPE, false).toUpperCase());
            }
        } else if (p.getName().equals("getCustomerByNumber") || p.getName().equals("getCustomerByName")) {
            for (ProcedureParameter param : p.getParameters()) {
                assertEquals(RestMetadataExtension.ParameterType.PATH.name(), param.getProperty(RestMetadataExtension.PARAMETER_TYPE, false).toUpperCase());
            }
        } else // Post parameter
        if (p.getName().equals("addCustomer") || p.getName().equals("addOneCustomer") || p.getName().equals("addCustomerList")) {
            ProcedureParameter param = p.getParameters().get(0);
            assertEquals(RestMetadataExtension.ParameterType.BODY.name(), param.getProperty(RestMetadataExtension.PARAMETER_TYPE, false).toUpperCase());
        }
        if (p.getName().equals("addCustomer")) {
            List<ProcedureParameter> params = p.getParameters();
            assertEquals(13, params.size());
            assertEquals("customernumber", params.get(0).getName());
            assertEquals("creditlimit", params.get(12).getName());
        }
    }
}
Also used : ProcedureParameter(org.teiid.metadata.ProcedureParameter) RealMetadataFactory(org.teiid.query.unittest.RealMetadataFactory) MetadataFactory(org.teiid.metadata.MetadataFactory) Procedure(org.teiid.metadata.Procedure) Test(org.junit.Test)

Aggregations

Procedure (org.teiid.metadata.Procedure)82 ProcedureParameter (org.teiid.metadata.ProcedureParameter)36 Test (org.junit.Test)35 MetadataFactory (org.teiid.metadata.MetadataFactory)30 RealMetadataFactory (org.teiid.query.unittest.RealMetadataFactory)27 Schema (org.teiid.metadata.Schema)16 Column (org.teiid.metadata.Column)14 MetadataStore (org.teiid.metadata.MetadataStore)11 Properties (java.util.Properties)10 TransformationMetadata (org.teiid.query.metadata.TransformationMetadata)10 Table (org.teiid.metadata.Table)9 QueryNode (org.teiid.query.mapping.relational.QueryNode)8 List (java.util.List)6 QueryMetadataInterface (org.teiid.query.metadata.QueryMetadataInterface)6 TempMetadataStore (org.teiid.query.metadata.TempMetadataStore)5 TranslatorException (org.teiid.translator.TranslatorException)5 ODataType (org.teiid.translator.odata4.ODataMetadataProcessor.ODataType)5 ArrayList (java.util.ArrayList)4 Call (org.teiid.language.Call)4 ByteArrayInputStream (java.io.ByteArrayInputStream)3