Search in sources :

Example 56 with Procedure

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

the class TestSwaggerMetadataProcessor method testAnnotation.

@Test
public void testAnnotation() throws TranslatorException {
    SwaggerExecutionFactory translator = new SwaggerExecutionFactory();
    translator.start();
    MetadataFactory mf = swaggerMetadata(translator);
    for (Procedure p : mf.getSchema().getProcedures().values()) {
        if (p.getName().equals("addCustomer")) {
            assertEquals("Add a Customer", p.getAnnotation());
        } else if (p.getName().equals("getByNumCityCountry")) {
            assertEquals("get customer by Number, City, Country as return xml/json", p.getAnnotation());
        }
    }
}
Also used : RealMetadataFactory(org.teiid.query.unittest.RealMetadataFactory) MetadataFactory(org.teiid.metadata.MetadataFactory) Procedure(org.teiid.metadata.Procedure) Test(org.junit.Test)

Example 57 with Procedure

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

the class TestSwaggerMetadataProcessor method testResultSets.

@Test
public void testResultSets() throws TranslatorException {
    SwaggerExecutionFactory translator = new SwaggerExecutionFactory();
    translator.start();
    MetadataFactory mf = swaggerMetadata(translator);
    Procedure p = mf.getSchema().getProcedure("getCustomerList");
    assertNotNull(p);
    assertEquals("GET", p.getProperty(RestMetadataExtension.METHOD, false).toUpperCase());
    assertEquals("http://localhost:8080/customer/getAll", p.getProperty(RestMetadataExtension.URI, false));
    assertNotNull(p.getResultSet());
    ColumnSet<Procedure> results = p.getResultSet();
    assertEquals(13, results.getColumns().size());
    Column c = results.getColumnByName("customernumber");
    assertNotNull(c);
    assertEquals("string", c.getRuntimeType());
    c = results.getColumnByName("postalcode");
    assertNotNull(c);
    assertEquals("string", c.getRuntimeType());
}
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 58 with Procedure

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

the class TestSwaggerMetadataProcessor method testTypes.

@Test
public void testTypes() throws TranslatorException {
    SwaggerExecutionFactory translator = new SwaggerExecutionFactory();
    translator.start();
    MetadataFactory mf = swaggerMetadata(translator);
    Procedure p = mf.getSchema().getProcedure("testReturnTypes");
    assertNotNull(p);
    assertEquals("GET", p.getProperty(RestMetadataExtension.METHOD, false).toUpperCase());
    assertEquals("http://localhost:8080/test/testReturnTypes", p.getProperty(RestMetadataExtension.URI, false));
    assertNotNull(p.getResultSet());
    ColumnSet<Procedure> results = p.getResultSet();
    assertEquals("byte", results.getColumnByName("a").getRuntimeType());
    assertEquals("integer", results.getColumnByName("b").getRuntimeType());
    assertEquals("integer", results.getColumnByName("c").getRuntimeType());
    assertEquals("long", results.getColumnByName("d").getRuntimeType());
    assertEquals("float", results.getColumnByName("e").getRuntimeType());
    assertEquals("double", results.getColumnByName("f").getRuntimeType());
    assertEquals("boolean", results.getColumnByName("g").getRuntimeType());
    assertEquals("string", results.getColumnByName("h").getRuntimeType());
    assertEquals("byte[]", results.getColumnByName("i").getRuntimeType());
    assertEquals("timestamp", results.getColumnByName("l").getRuntimeType());
    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());
    results = p.getResultSet();
    assertEquals("timestamp", results.getColumnByName("date").getRuntimeType());
    assertEquals("timestamp", results.getColumnByName("sqlDate").getRuntimeType());
    // test types in parameters
    p = mf.getSchema().getProcedure("testTypes");
    assertNotNull(p);
    assertEquals("GET", p.getProperty(RestMetadataExtension.METHOD, false).toUpperCase());
    assertEquals("http://localhost:8080/test/testTypes", p.getProperty(RestMetadataExtension.URI, false));
    assertNotNull(p.getResultSet());
    List<ProcedureParameter> pp = p.getParameters();
    assertEquals("integer", pp.get(0).getRuntimeType());
    assertEquals("long", pp.get(1).getRuntimeType());
    assertEquals("float", pp.get(2).getRuntimeType());
    assertEquals("double", pp.get(3).getRuntimeType());
    assertEquals("string", pp.get(4).getRuntimeType());
    assertEquals("byte", pp.get(5).getRuntimeType());
    assertEquals("string[]", pp.get(6).getRuntimeType());
    assertEquals("boolean", pp.get(7).getRuntimeType());
    assertEquals("timestamp", pp.get(8).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 59 with Procedure

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

the class TestSwaggerMetadataProcessor method testBodyandPathProcedure.

@Test
public void testBodyandPathProcedure() throws Exception {
    SwaggerExecutionFactory translator = new SwaggerExecutionFactory();
    translator.start();
    MetadataFactory mf = swaggerMetadata(translator);
    Procedure p = mf.getSchema().getProcedure("executeOperation");
    assertNotNull(p);
    assertEquals("PUT", p.getProperty(RestMetadataExtension.METHOD, false).toUpperCase());
    assertEquals("http://localhost:8080/operation/{operationId}", p.getProperty(RestMetadataExtension.URI, false));
    assertNotNull(p.getResultSet());
    assertNotNull(p.getParameterByName("operationId"));
    assertNotNull(p.getParameterByName("id"));
    assertNotNull(p.getParameterByName("name"));
    assertNotNull(p.getParameterByName("resourceId"));
    assertNotNull(p.getParameterByName("definitionId"));
    assertNotNull(p.getParameterByName("readyToSubmit"));
    assertNotNull(p.getParameterByName("params_arguments"));
    List<Column> columns = p.getResultSet().getColumns();
    assertEquals(2, columns.size());
}
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 60 with Procedure

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

the class TestVisitors method exampleSalesforce.

public static QueryMetadataInterface exampleSalesforce() {
    try {
        ModelMetaData mmd = new ModelMetaData();
        mmd.setName("SalesforceModel");
        MetadataFactory mf = new MetadataFactory("sf", 1, SystemMetadata.getInstance().getRuntimeTypeMap(), mmd);
        mf.setParser(new QueryParser());
        // load the metadata as captured from 8.9 on 9/3/2014
        mf.parse(new FileReader(UnitTestUtil.getTestDataFile("sf.ddl")));
        SalesForceExecutionFactory factory = new SalesForceExecutionFactory();
        factory.start();
        for (FunctionMethod func : factory.getPushDownFunctions()) {
            mf.addFunction(func);
        }
        SalesForceMetadataProcessor.addProcedrues(mf);
        // Create Contacts group - which has different name in sources
        // $NON-NLS-1$
        Table contactTable = RealMetadataFactory.createPhysicalGroup("Contacts", mf.getSchema());
        // $NON-NLS-1$
        contactTable.setNameInSource("Contact");
        // $NON-NLS-1$
        contactTable.setProperty("Supports Query", Boolean.TRUE.toString());
        // Create Contact Columns
        String[] elemNames = new String[] { // $NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
        "ContactID", // $NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
        "Name", // $NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
        "AccountId", // $NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
        "InitialContact", // $NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
        "LastTime" };
        String[] elemTypes = new String[] { DataTypeManager.DefaultDataTypes.STRING, DataTypeManager.DefaultDataTypes.STRING, DataTypeManager.DefaultDataTypes.STRING, DataTypeManager.DefaultDataTypes.TIMESTAMP, DataTypeManager.DefaultDataTypes.TIME };
        List<Column> contactCols = RealMetadataFactory.createElements(contactTable, elemNames, elemTypes);
        // Set name in source on each column
        String[] contactNameInSource = new String[] { // $NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
        "id", // $NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
        "ContactName", // $NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
        "accountid", // $NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
        "InitialContact", // $NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
        "LastTime" };
        for (int i = 0; i < 2; i++) {
            Column obj = contactCols.get(i);
            obj.setNameInSource(contactNameInSource[i]);
        }
        // add a procedure with a native query property
        List<ProcedureParameter> params = new LinkedList<ProcedureParameter>();
        params.add(RealMetadataFactory.createParameter("x", SPParameter.IN, TypeFacility.RUNTIME_NAMES.STRING));
        Procedure nativeProc = RealMetadataFactory.createStoredProcedure("foo", mf.getSchema(), params);
        nativeProc.setProperty(SQLStringVisitor.TEIID_NATIVE_QUERY, "search;select accountname from account where accountid = $1");
        nativeProc.setResultSet(RealMetadataFactory.createResultSet("rs", new String[] { "accountname" }, new String[] { TypeFacility.RUNTIME_NAMES.STRING }));
        TransformationMetadata tm = RealMetadataFactory.createTransformationMetadata(mf.asMetadataStore(), "x");
        ValidatorReport report = new MetadataValidator().validate(tm.getVdbMetaData(), tm.getMetadataStore());
        if (report.hasItems()) {
            throw new RuntimeException(report.getFailureMessage());
        }
        return tm;
    } catch (Exception e) {
        throw new RuntimeException(e);
    }
}
Also used : ProcedureParameter(org.teiid.metadata.ProcedureParameter) TransformationMetadata(org.teiid.query.metadata.TransformationMetadata) Table(org.teiid.metadata.Table) SalesForceExecutionFactory(org.teiid.translator.salesforce.SalesForceExecutionFactory) LinkedList(java.util.LinkedList) ValidatorReport(org.teiid.query.validator.ValidatorReport) ModelMetaData(org.teiid.adminapi.impl.ModelMetaData) QueryParser(org.teiid.query.parser.QueryParser) RealMetadataFactory(org.teiid.query.unittest.RealMetadataFactory) MetadataFactory(org.teiid.metadata.MetadataFactory) Column(org.teiid.metadata.Column) FunctionMethod(org.teiid.metadata.FunctionMethod) Procedure(org.teiid.metadata.Procedure) FileReader(java.io.FileReader) MetadataValidator(org.teiid.query.metadata.MetadataValidator)

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