use of org.odata4j.format.xml.EdmxFormatParser in project teiid by teiid.
the class ODataMetadataProcessor method getEds.
private EdmDataServices getEds(WSConnection conn) throws TranslatorException {
try {
BaseQueryExecution execution = new BaseQueryExecution(ef, null, null, conn);
// $NON-NLS-1$ //$NON-NLS-2$
BinaryWSProcedureExecution call = execution.executeDirect("GET", "$metadata", null, execution.getDefaultHeaders());
if (call.getResponseCode() != Status.OK.getStatusCode()) {
throw execution.buildError(call);
}
Blob out = (Blob) call.getOutputParameterValues().get(0);
EdmDataServices eds = new EdmxFormatParser().parseMetadata(StaxUtil.newXMLEventReader(new InputStreamReader(out.getBinaryStream())));
return eds;
} catch (SQLException e) {
throw new TranslatorException(e);
} catch (Exception e) {
throw new TranslatorException(e);
}
}
use of org.odata4j.format.xml.EdmxFormatParser in project teiid by teiid.
the class TestDataEntitySchemaBuilder method getNorthwindMetadataFromODataXML.
static TransformationMetadata getNorthwindMetadataFromODataXML() throws Exception {
ModelMetaData model = new ModelMetaData();
model.setName("nw");
model.setModelType(Type.PHYSICAL);
MetadataFactory mf = new MetadataFactory("northwind", 1, SystemMetadata.getInstance().getRuntimeTypeMap(), model);
EdmDataServices edm = new EdmxFormatParser().parseMetadata(StaxUtil.newXMLEventReader(new FileReader(UnitTestUtil.getTestDataFile("northwind.xml"))));
ODataMetadataProcessor metadataProcessor = new ODataMetadataProcessor();
// $NON-NLS-1$
PropertiesUtils.setBeanProperties(metadataProcessor, mf.getModelProperties(), "importer");
metadataProcessor.getMetadata(mf, edm);
String ddl = DDLStringVisitor.getDDLString(mf.getSchema(), null, null);
TransformationMetadata metadata = RealMetadataFactory.fromDDL(ddl, "northwind", "nw");
ValidatorReport report = new MetadataValidator().validate(metadata.getVdbMetaData(), metadata.getMetadataStore());
if (report.hasItems()) {
throw new RuntimeException(report.getFailureMessage());
}
return metadata;
}
use of org.odata4j.format.xml.EdmxFormatParser in project teiid by teiid.
the class TestDataEntitySchemaBuilder method testMetadataWithSelfJoin.
@Test
public void testMetadataWithSelfJoin() throws Exception {
TransformationMetadata metadata = RealMetadataFactory.fromDDL(ObjectConverterUtil.convertFileToString(UnitTestUtil.getTestDataFile("categories.ddl")), "northwind", "nw");
StringWriter sw = new StringWriter();
EdmDataServices eds = ODataEntitySchemaBuilder.buildMetadata(metadata.getMetadataStore());
EdmxFormatWriter.write(eds, sw);
String expectedXML = "<?xml version=\"1.0\" encoding=\"utf-8\"?><edmx:Edmx Version=\"1.0\" xmlns:edmx=\"http://schemas.microsoft.com/ado/2007/06/edmx\"><edmx:DataServices m:DataServiceVersion=\"2.0\" xmlns:m=\"http://schemas.microsoft.com/ado/2007/08/dataservices/metadata\"><Schema Namespace=\"nw\" xmlns=\"http://schemas.microsoft.com/ado/2008/09/edm\"><EntityType Name=\"Category\"><Key><PropertyRef Name=\"CategoryID\"></PropertyRef></Key><Property Name=\"CategoryID\" Type=\"Edm.Int32\" Nullable=\"false\"></Property><Property Name=\"Name\" Type=\"Edm.String\" Nullable=\"false\" MaxLength=\"25\" FixedLength=\"false\" Unicode=\"true\"></Property><Property Name=\"ParentCategoryID\" Type=\"Edm.Int32\" Nullable=\"false\"></Property><NavigationProperty Name=\"Category\" Relationship=\"nw.Category_FK_CATEGORY_ID\" FromRole=\"Category\" ToRole=\"Category\"></NavigationProperty></EntityType><Association Name=\"Category_FK_CATEGORY_ID\"><End Type=\"nw.Category\" Multiplicity=\"*\" Role=\"Category\"></End><End Type=\"nw.Category\" Multiplicity=\"0..1\" Role=\"Category\"></End><ReferentialConstraint><Principal Role=\"Category\"><PropertyRef Name=\"CategoryID\"></PropertyRef></Principal><Dependent Role=\"Category\"><PropertyRef Name=\"ParentCategoryID\"></PropertyRef></Dependent></ReferentialConstraint></Association><EntityContainer Name=\"nw\" m:IsDefaultEntityContainer=\"false\"><EntitySet Name=\"Category\" EntityType=\"nw.Category\"></EntitySet><AssociationSet Name=\"Category_FK_CATEGORY_ID\" Association=\"nw.Category_FK_CATEGORY_ID\"><End EntitySet=\"Category\" Role=\"Category\"></End><End EntitySet=\"Category\" Role=\"Category\"></End></AssociationSet></EntityContainer></Schema></edmx:DataServices></edmx:Edmx>\n";
EdmDataServices pds = new EdmxFormatParser().parseMetadata(StaxUtil.newXMLEventReader(new StringReader(expectedXML)));
assertEquals(eds.getSchemas().size(), pds.getSchemas().size());
for (int i = 0; i < eds.getSchemas().size(); i++) {
EdmSchema expected = eds.getSchemas().get(i);
EdmSchema actual = pds.getSchemas().get(i);
assertEdmSchema(expected, actual);
}
}
use of org.odata4j.format.xml.EdmxFormatParser in project teiid by teiid.
the class TestDataEntitySchemaBuilder method testMetadata.
@Test
public void testMetadata() throws Exception {
TransformationMetadata metadata = RealMetadataFactory.fromDDL(ObjectConverterUtil.convertFileToString(UnitTestUtil.getTestDataFile("northwind.ddl")), "northwind", "nw");
StringWriter sw = new StringWriter();
EdmDataServices eds = ODataEntitySchemaBuilder.buildMetadata(metadata.getMetadataStore());
EdmxFormatWriter.write(eds, sw);
// System.out.println(sw.toString());
EdmDataServices pds = new EdmxFormatParser().parseMetadata(StaxUtil.newXMLEventReader(new StringReader(sw.toString())));
assertEquals(eds.getSchemas().size(), pds.getSchemas().size());
for (int i = 0; i < eds.getSchemas().size(); i++) {
EdmSchema expected = eds.getSchemas().get(i);
EdmSchema actual = pds.getSchemas().get(i);
assertEdmSchema(expected, actual);
}
}
use of org.odata4j.format.xml.EdmxFormatParser in project teiid by teiid.
the class TestODataMetadataProcessor method testSchema.
@Test
public void testSchema() throws Exception {
translator = new ODataExecutionFactory();
translator.start();
String csdl = ObjectConverterUtil.convertFileToString(UnitTestUtil.getTestDataFile("northwind.xml"));
ODataMetadataProcessor processor = new ODataMetadataProcessor();
Properties props = new Properties();
props.setProperty("schemaNamespace", "ODataWeb.Northwind.Model");
props.setProperty("entityContainer", "NorthwindEntities");
MetadataFactory mf = new MetadataFactory("vdb", 1, "northwind", SystemMetadata.getInstance().getRuntimeTypeMap(), props, null);
processor.getMetadata(mf, new EdmxFormatParser().parseMetadata(StaxUtil.newXMLEventReader(new InputStreamReader(new ByteArrayInputStream(csdl.getBytes())))));
TransformationMetadata metadata = RealMetadataFactory.createTransformationMetadata(mf.asMetadataStore(), "northwind", new FunctionTree("foo", new UDFSource(translator.getPushDownFunctions())));
ValidatorReport report = new MetadataValidator().validate(metadata.getVdbMetaData(), metadata.getMetadataStore());
if (report.hasItems()) {
throw new RuntimeException(report.getFailureMessage());
}
String ddl = DDLStringVisitor.getDDLString(mf.getSchema(), null, null);
// System.out.println(ddl);
MetadataFactory mf2 = new MetadataFactory("vdb", 1, "northwind", SystemMetadata.getInstance().getRuntimeTypeMap(), new Properties(), null);
QueryParser.getQueryParser().parseDDL(mf2, ddl);
Procedure p = mf.getSchema().getProcedure("executeVoid");
assertNotNull(p);
assertEquals(1, p.getParameters().size());
}
Aggregations