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