Search in sources :

Example 1 with EdmxFormatParser

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);
    }
}
Also used : Blob(java.sql.Blob) InputStreamReader(java.io.InputStreamReader) SQLException(java.sql.SQLException) BinaryWSProcedureExecution(org.teiid.translator.ws.BinaryWSProcedureExecution) EdmxFormatParser(org.odata4j.format.xml.EdmxFormatParser) TranslatorException(org.teiid.translator.TranslatorException) SQLException(java.sql.SQLException) TranslatorException(org.teiid.translator.TranslatorException)

Example 2 with EdmxFormatParser

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;
}
Also used : TransformationMetadata(org.teiid.query.metadata.TransformationMetadata) RealMetadataFactory(org.teiid.query.unittest.RealMetadataFactory) MetadataFactory(org.teiid.metadata.MetadataFactory) EdmxFormatParser(org.odata4j.format.xml.EdmxFormatParser) FileReader(java.io.FileReader) MetadataValidator(org.teiid.query.metadata.MetadataValidator) ValidatorReport(org.teiid.query.validator.ValidatorReport) ModelMetaData(org.teiid.adminapi.impl.ModelMetaData)

Example 3 with EdmxFormatParser

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);
    }
}
Also used : TransformationMetadata(org.teiid.query.metadata.TransformationMetadata) StringWriter(java.io.StringWriter) StringReader(java.io.StringReader) EdmxFormatParser(org.odata4j.format.xml.EdmxFormatParser) Test(org.junit.Test)

Example 4 with EdmxFormatParser

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);
    }
}
Also used : TransformationMetadata(org.teiid.query.metadata.TransformationMetadata) StringWriter(java.io.StringWriter) StringReader(java.io.StringReader) EdmxFormatParser(org.odata4j.format.xml.EdmxFormatParser) Test(org.junit.Test)

Example 5 with EdmxFormatParser

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());
}
Also used : UDFSource(org.teiid.query.function.UDFSource) TransformationMetadata(org.teiid.query.metadata.TransformationMetadata) FunctionTree(org.teiid.query.function.FunctionTree) InputStreamReader(java.io.InputStreamReader) EdmxFormatParser(org.odata4j.format.xml.EdmxFormatParser) Properties(java.util.Properties) ValidatorReport(org.teiid.query.validator.ValidatorReport) RealMetadataFactory(org.teiid.query.unittest.RealMetadataFactory) MetadataFactory(org.teiid.metadata.MetadataFactory) ByteArrayInputStream(java.io.ByteArrayInputStream) Procedure(org.teiid.metadata.Procedure) MetadataValidator(org.teiid.query.metadata.MetadataValidator) Test(org.junit.Test)

Aggregations

EdmxFormatParser (org.odata4j.format.xml.EdmxFormatParser)11 TransformationMetadata (org.teiid.query.metadata.TransformationMetadata)9 Test (org.junit.Test)8 MetadataFactory (org.teiid.metadata.MetadataFactory)8 RealMetadataFactory (org.teiid.query.unittest.RealMetadataFactory)8 FileReader (java.io.FileReader)5 ModelMetaData (org.teiid.adminapi.impl.ModelMetaData)5 InputStreamReader (java.io.InputStreamReader)4 EdmDataServices (org.odata4j.edm.EdmDataServices)4 Column (org.teiid.metadata.Column)4 MetadataValidator (org.teiid.query.metadata.MetadataValidator)4 ValidatorReport (org.teiid.query.validator.ValidatorReport)4 ByteArrayInputStream (java.io.ByteArrayInputStream)3 Properties (java.util.Properties)3 Procedure (org.teiid.metadata.Procedure)3 FunctionTree (org.teiid.query.function.FunctionTree)3 UDFSource (org.teiid.query.function.UDFSource)3 StringReader (java.io.StringReader)2 StringWriter (java.io.StringWriter)2 TranslationUtility (org.teiid.cdk.api.TranslationUtility)2