Search in sources :

Example 76 with MetadataFactory

use of org.teiid.metadata.MetadataFactory in project teiid by teiid.

the class TestSwaggerMetadataProcessor method getMetadata.

private static MetadataFactory getMetadata(SwaggerExecutionFactory ef, final String file) throws TranslatorException {
    SwaggerMetadataProcessor processor = new SwaggerMetadataProcessor(ef) {

        protected Swagger getSchema(WSConnection conn) throws TranslatorException {
            File f = new File(file);
            ObjectMapper objectMapper = new ObjectMapper();
            try (FileInputStream fis = new FileInputStream(f)) {
                JsonNode rootNode = objectMapper.readTree(fis);
                return new SwaggerParser().read(rootNode, true);
            } catch (IOException e) {
                throw new TranslatorException(e);
            }
        }
    };
    processor.setPreferredProduces("application/json");
    processor.setPreferredConsumes("application/json");
    processor.setPreferredScheme("http");
    Properties props = new Properties();
    MetadataFactory mf = new MetadataFactory("vdb", 1, "swagger", SystemMetadata.getInstance().getRuntimeTypeMap(), props, null);
    processor.process(mf, null);
    return mf;
}
Also used : SwaggerParser(io.swagger.parser.SwaggerParser) WSConnection(org.teiid.translator.WSConnection) RealMetadataFactory(org.teiid.query.unittest.RealMetadataFactory) MetadataFactory(org.teiid.metadata.MetadataFactory) JsonNode(com.fasterxml.jackson.databind.JsonNode) TranslatorException(org.teiid.translator.TranslatorException) IOException(java.io.IOException) Properties(java.util.Properties) File(java.io.File) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) FileInputStream(java.io.FileInputStream)

Example 77 with MetadataFactory

use of org.teiid.metadata.MetadataFactory 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());
}
Also used : RealMetadataFactory(org.teiid.query.unittest.RealMetadataFactory) MetadataFactory(org.teiid.metadata.MetadataFactory) Procedure(org.teiid.metadata.Procedure) Test(org.junit.Test)

Example 78 with MetadataFactory

use of org.teiid.metadata.MetadataFactory in project teiid by teiid.

the class TestRowBasedSecurity method testSecurity.

@Test
public void testSecurity() throws Exception {
    es = new EmbeddedServer();
    EmbeddedConfiguration ec = new EmbeddedConfiguration();
    final Vector<Principal> v = new Vector<Principal>();
    v.add(new Identity("myrole") {
    });
    final Subject subject = new Subject();
    Group g = Mockito.mock(Group.class);
    Mockito.stub(g.getName()).toReturn("Roles");
    Mockito.stub(g.members()).toReturn((Enumeration) v.elements());
    subject.getPrincipals().add(g);
    ec.setSecurityHelper(new DoNothingSecurityHelper() {

        @Override
        public Subject getSubjectInContext(String securityDomain) {
            return subject;
        }

        @Override
        public Subject getSubjectInContext(Object context) {
            return subject;
        }
    });
    es.start(ec);
    HardCodedExecutionFactory hcef = new HardCodedExecutionFactory() {

        @Override
        public void getMetadata(MetadataFactory metadataFactory, Object conn) throws TranslatorException {
            Table t = metadataFactory.addTable("x");
            Column col = metadataFactory.addColumn("col", TypeFacility.RUNTIME_NAMES.STRING, t);
            metadataFactory.addColumn("col2", TypeFacility.RUNTIME_NAMES.STRING, t);
            metadataFactory.addPermission("y", t, null, null, Boolean.TRUE, null, null, null, "col = 'a'", null);
            metadataFactory.addColumnPermission("y", col, null, null, null, null, "null", null);
            t = metadataFactory.addTable("y");
            col = metadataFactory.addColumn("col", TypeFacility.RUNTIME_NAMES.STRING, t);
            metadataFactory.addColumn("col2", TypeFacility.RUNTIME_NAMES.STRING, t);
            metadataFactory.addPermission("z", t, null, null, null, null, null, null, "col = 'e'", null);
            Table v = metadataFactory.addTable("v");
            metadataFactory.addPermission("y", v, null, null, Boolean.TRUE, null, null, null, null, null);
            col = metadataFactory.addColumn("col", TypeFacility.RUNTIME_NAMES.STRING, v);
            metadataFactory.addColumn("col2", TypeFacility.RUNTIME_NAMES.STRING, v);
            v.setTableType(Type.View);
            v.setVirtual(true);
            v.setSelectTransformation("/*+ cache(scope:session) */ select col, col2 from y");
        }

        @Override
        public boolean isSourceRequiredForMetadata() {
            return false;
        }
    };
    hcef.addData("SELECT x.col, x.col2 FROM x", Arrays.asList(Arrays.asList("a", "b"), Arrays.asList("c", "d")));
    hcef.addData("SELECT y.col, y.col2 FROM y", Arrays.asList(Arrays.asList("e", "f"), Arrays.asList("h", "g")));
    es.addTranslator("hc", hcef);
    es.deployVDB(new FileInputStream(UnitTestUtil.getTestDataFile("roles-vdb.xml")));
    Connection c = es.getDriver().connect("jdbc:teiid:z;PassthroughAuthentication=true", null);
    Statement s = c.createStatement();
    ResultSet rs = s.executeQuery("select * from x");
    rs.next();
    // masking
    assertEquals(null, rs.getString(1));
    assertEquals("b", rs.getString(2));
    // row filter
    assertFalse(rs.next());
    rs.close();
    s = c.createStatement();
    rs = s.executeQuery("select lookup('myschema.x', 'col', 'col2', 'b')");
    rs.next();
    // global scoped
    assertEquals(null, rs.getString(1));
    s = c.createStatement();
    rs = s.executeQuery("select count(col2) from v where col is not null");
    rs.next();
    assertEquals(1, rs.getInt(1));
    // different session with different roles
    v.clear();
    c = es.getDriver().connect("jdbc:teiid:z;PassthroughAuthentication=true", null);
    s = c.createStatement();
    rs = s.executeQuery("select count(col2) from v where col is not null");
    rs.next();
    assertEquals(2, rs.getInt(1));
}
Also used : Group(java.security.acl.Group) Table(org.teiid.metadata.Table) Statement(java.sql.Statement) EmbeddedServer(org.teiid.runtime.EmbeddedServer) Connection(java.sql.Connection) EmbeddedConfiguration(org.teiid.runtime.EmbeddedConfiguration) DoNothingSecurityHelper(org.teiid.runtime.DoNothingSecurityHelper) Subject(javax.security.auth.Subject) FileInputStream(java.io.FileInputStream) MetadataFactory(org.teiid.metadata.MetadataFactory) Column(org.teiid.metadata.Column) ResultSet(java.sql.ResultSet) HardCodedExecutionFactory(org.teiid.runtime.HardCodedExecutionFactory) Identity(java.security.Identity) Vector(java.util.Vector) Principal(java.security.Principal) Test(org.junit.Test)

Example 79 with MetadataFactory

use of org.teiid.metadata.MetadataFactory in project teiid by teiid.

the class TestMatViewAliasing method setUp.

@Before
public void setUp() throws Exception {
    server = new FakeServer(true);
    VDBRepository vdbRepository = new VDBRepository();
    MetadataFactory mf = new MetadataFactory(null, 1, "foo", vdbRepository.getRuntimeTypeMap(), new Properties(), null);
    mf.getSchema().setPhysical(false);
    Table mat = mf.addTable("mat");
    mat.setVirtual(true);
    mat.setMaterialized(true);
    mat.setSelectTransformation("/*+ cache(ttl:0) */ select 1 as x, 'y' as Name");
    mf.addColumn("x", DataTypeManager.DefaultDataTypes.INTEGER, mat);
    mf.addColumn("Name", DataTypeManager.DefaultDataTypes.STRING, mat);
    MetadataStore ms = mf.asMetadataStore();
    server.deployVDB(MATVIEWS, ms);
    conn = server.createConnection("jdbc:teiid:" + MATVIEWS);
}
Also used : MetadataStore(org.teiid.metadata.MetadataStore) Table(org.teiid.metadata.Table) MetadataFactory(org.teiid.metadata.MetadataFactory) FakeServer(org.teiid.jdbc.FakeServer) VDBRepository(org.teiid.deployers.VDBRepository) Properties(java.util.Properties) Before(org.junit.Before)

Example 80 with MetadataFactory

use of org.teiid.metadata.MetadataFactory in project teiid by teiid.

the class AbstractVDBDeployer method createMetadataFactory.

protected MetadataFactory createMetadataFactory(VDBMetaData vdb, MetadataStore store, ModelMetaData model, Map<String, ? extends VDBResource> vdbResources) {
    Map<String, Datatype> datatypes = store.getDatatypes();
    MetadataFactory factory = new MetadataFactory(vdb.getName(), vdb.getVersion(), datatypes, model);
    factory.getSchema().setPhysical(model.isSource());
    // for thread safety each factory gets it's own instance.
    factory.setParser(new QueryParser());
    factory.setVdbResources(vdbResources);
    return factory;
}
Also used : QueryParser(org.teiid.query.parser.QueryParser) MetadataFactory(org.teiid.metadata.MetadataFactory) Datatype(org.teiid.metadata.Datatype)

Aggregations

MetadataFactory (org.teiid.metadata.MetadataFactory)159 Test (org.junit.Test)116 RealMetadataFactory (org.teiid.query.unittest.RealMetadataFactory)91 Properties (java.util.Properties)74 Table (org.teiid.metadata.Table)59 TransformationMetadata (org.teiid.query.metadata.TransformationMetadata)35 Procedure (org.teiid.metadata.Procedure)30 ModelMetaData (org.teiid.adminapi.impl.ModelMetaData)21 Column (org.teiid.metadata.Column)20 Connection (java.sql.Connection)18 FunctionTree (org.teiid.query.function.FunctionTree)15 UDFSource (org.teiid.query.function.UDFSource)14 CouchbaseMetadataProcessor (org.teiid.translator.couchbase.CouchbaseMetadataProcessor)14 Dimension (org.teiid.translator.couchbase.CouchbaseMetadataProcessor.Dimension)14 CouchbaseProperties (org.teiid.translator.couchbase.CouchbaseProperties)14 TranslationUtility (org.teiid.cdk.api.TranslationUtility)13 ValidatorReport (org.teiid.query.validator.ValidatorReport)13 XMLMetadata (org.apache.olingo.client.api.edm.xml.XMLMetadata)12 ClientCsdlXMLMetadata (org.apache.olingo.client.core.edm.ClientCsdlXMLMetadata)12 ForeignKey (org.teiid.metadata.ForeignKey)12