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"));
}
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());
}
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());
}
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);
}
}
}
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()));
}
}
Aggregations