Search in sources :

Example 36 with Procedure

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

the class TestSwaggerMetadataProcessor method testOnetoOneEmbeddedReturn.

@Test
public void testOnetoOneEmbeddedReturn() throws TranslatorException {
    SwaggerExecutionFactory translator = new SwaggerExecutionFactory();
    translator.start();
    MetadataFactory mf = swaggerMetadata(translator);
    Procedure p = mf.getSchema().getProcedure("size");
    assertNotNull(p);
    assertEquals("GET", p.getProperty(RestMetadataExtension.METHOD, false).toUpperCase());
    assertEquals("http://localhost:8080/customer/status", p.getProperty(RestMetadataExtension.URI, false));
    assertNotNull(p.getResultSet());
    ColumnSet<Procedure> results = p.getResultSet();
    assertNotNull(results.getColumnByName("size"));
    assertNotNull(results.getColumnByName("heap_maxMemory"));
    assertNotNull(results.getColumnByName("heap_freeMemory"));
}
Also used : RealMetadataFactory(org.teiid.query.unittest.RealMetadataFactory) MetadataFactory(org.teiid.metadata.MetadataFactory) Procedure(org.teiid.metadata.Procedure) Test(org.junit.Test)

Example 37 with Procedure

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

the class TestSwaggerMetadataProcessor method testObjectArrayTypes.

@Test
public void testObjectArrayTypes() throws Exception {
    SwaggerExecutionFactory translator = new SwaggerExecutionFactory();
    translator.start();
    MetadataFactory mf = getMetadata(translator, UnitTestUtil.getTestDataPath() + "/doubleclick-swagger.json");
    Procedure p = mf.getSchema().getProcedure("doubleclicksearch.reports.request");
    ProcedureParameter param = p.getParameterByName("filters_values");
    assertEquals("string[]", param.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 38 with Procedure

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

the class TestSwaggerMetadataProcessor method testURI.

@Test
public void testURI() throws TranslatorException {
    SwaggerExecutionFactory translator = new SwaggerExecutionFactory();
    translator.start();
    MetadataFactory mf = swaggerMetadata(translator);
    Procedure p = mf.getSchema().getProcedure("addCustomer");
    assertNotNull(p);
    assertEquals("POST", p.getProperty(RestMetadataExtension.METHOD, false).toUpperCase());
    assertEquals("http://localhost:8080/customer", p.getProperty(RestMetadataExtension.URI, false));
    assertNull(p.getResultSet());
    p = mf.getSchema().getProcedure("getCustomers");
    assertNotNull(p);
    assertEquals("GET", p.getProperty(RestMetadataExtension.METHOD, false).toUpperCase());
    assertEquals("http://localhost:8080/customer/customerList", p.getProperty(RestMetadataExtension.URI, false));
    assertEquals("application/xml", p.getProperty(RestMetadataExtension.PRODUCES, false));
    assertNull(p.getResultSet());
    assertEquals("return", p.getParameters().get(0).getName());
    assertEquals("string", p.getParameters().get(0).getRuntimeType());
    p = mf.getSchema().getProcedure("removeCustomer");
    assertNotNull(p);
    assertEquals("DELETE", p.getProperty(RestMetadataExtension.METHOD, false).toUpperCase());
    assertEquals("http://localhost:8080/customer/delete/{id}", p.getProperty(RestMetadataExtension.URI, false));
    assertEquals("application/json", p.getProperty(RestMetadataExtension.PRODUCES, false));
    assertNull(p.getResultSet());
    assertEquals("id", p.getParameters().get(0).getName());
    assertEquals(1, p.getParameters().size());
}
Also used : RealMetadataFactory(org.teiid.query.unittest.RealMetadataFactory) MetadataFactory(org.teiid.metadata.MetadataFactory) Procedure(org.teiid.metadata.Procedure) Test(org.junit.Test)

Example 39 with Procedure

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

the class SwaggerMetadataProcessor method addProcedure.

private void addProcedure(MetadataFactory mf, Swagger swagger, String basePath, String endpoint, Path operations) throws TranslatorException {
    for (Entry<HttpMethod, Operation> entry : getOperationMap(operations).entrySet()) {
        Operation operation = entry.getValue();
        String produces = getTypes(nvl(operation.getProduces(), swagger.getProduces()), getPreferredProduces());
        String consumes = getTypes(nvl(operation.getConsumes(), swagger.getConsumes()), getPreferredConsumes());
        String name = operation.getOperationId();
        if (name == null) {
            // determine a name from the endpoint
            int start = 0;
            if (endpoint.startsWith("/")) {
                // $NON-NLS-1$
                start = 1;
            }
            name = endpoint.substring(start);
            // $NON-NLS-1$ //$NON-NLS-2$
            name = name.replaceAll("\\{([^}]*)\\}", "$1");
            if (operations.getOperationMap().entrySet().size() > 1) {
                // $NON-NLS-1$
                name = name + "_" + entry.getKey().name();
            }
        }
        Procedure procedure = mf.addProcedure(name);
        procedure.setVirtual(false);
        procedure.setProperty(METHOD, entry.getKey().name());
        if (operation.getSchemes() != null && !operation.getSchemes().isEmpty()) {
            procedure.setProperty(SCHEME, getSchemes(operation));
        }
        procedure.setProperty(URI, buildURL(basePath, endpoint));
        procedure.setProperty(PRODUCES, produces);
        procedure.setProperty(CONSUMES, consumes);
        procedure.setAnnotation(getOperationSummary(operation));
        for (Entry<String, Object> extension : operation.getVendorExtensions().entrySet()) {
            procedure.setProperty(extension.getKey(), extension.getValue().toString());
        }
        addProcedureParameters(mf, swagger, procedure, operation);
        boolean returnAdded = false;
        Map<String, Response> respMap = operation.getResponses();
        for (String code : respMap.keySet()) {
            if (code.equalsIgnoreCase("default")) {
                continue;
            }
            int httpCode = Integer.valueOf(code);
            // Success codes
            if (httpCode > 100 && httpCode < 300) {
                Response resp = respMap.get(code);
                returnAdded = buildResponse(mf, swagger, procedure, resp);
                break;
            }
        }
        if (!returnAdded && respMap.get("default") != null) {
            Response resp = respMap.get("default");
            returnAdded = buildResponse(mf, swagger, procedure, resp);
        }
    }
}
Also used : Response(io.swagger.models.Response) Procedure(org.teiid.metadata.Procedure) Operation(io.swagger.models.Operation) HttpMethod(io.swagger.models.HttpMethod)

Example 40 with Procedure

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

the class SwaggerProcedureExecution method execute.

@Override
public void execute() throws TranslatorException {
    Procedure procedure = this.command.getMetadataObject();
    BinaryWSProcedureExecution execution = buildWSExecution(this.command);
    execution.execute();
    if (execution.getResponseCode() >= 200 && execution.getResponseCode() < 300) {
        this.responseHeaders = execution.getResponseHeaders();
        // Success
        if (procedure.getResultSet() != null) {
            if (procedure.getResultSet().getColumns().get(0).getName().equals("return")) {
                // this procedure with return, but headers made this into a resultset.
                this.returnValue = getReturnValue(execution);
            } else {
                try {
                    Blob blob = (Blob) execution.getOutputParameterValues().get(0);
                    InputStream wsResponse = blob.getBinaryStream();
                    Object obj = execution.getResponseHeader("Content-Type");
                    if (obj == null) {
                        throw new TranslatorException(SwaggerPlugin.Event.TEIID28017, SwaggerPlugin.Util.gs(SwaggerPlugin.Event.TEIID28017, "Not Defined"));
                    } else {
                        List<?> contentType = (List<?>) obj;
                        SwaggerSerializer serializer = getSerializer(contentType.get(0).toString());
                        if (serializer == null) {
                            throw new TranslatorException(SwaggerPlugin.Event.TEIID28017, SwaggerPlugin.Util.gs(SwaggerPlugin.Event.TEIID28017, obj.toString()));
                        }
                        handleResponse(procedure, wsResponse, execution.getResponseHeaders(), serializer);
                    }
                } catch (SQLException e) {
                    throw new TranslatorException(e);
                }
            }
        } else if (getReturnParameter() != null) {
            // this is scalar result
            this.returnValue = getReturnValue(execution);
        }
    } else if (execution.getResponseCode() == 404) {
    // treat as empty response. Typically that when someone uses it.
    } else {
        throw new TranslatorException(SwaggerPlugin.Event.TEIID28018, SwaggerPlugin.Util.gs(SwaggerPlugin.Event.TEIID28018, execution.getResponseCode()));
    }
}
Also used : Blob(java.sql.Blob) SQLException(java.sql.SQLException) InputStream(java.io.InputStream) BinaryWSProcedureExecution(org.teiid.translator.ws.BinaryWSProcedureExecution) Procedure(org.teiid.metadata.Procedure) TranslatorException(org.teiid.translator.TranslatorException) List(java.util.List)

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