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