Search in sources :

Example 61 with MetadataStore

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

the class RestASMBasedWebArchiveBuilder method hasRestMetadata.

@Override
public boolean hasRestMetadata(VDBMetaData vdb) {
    // $NON-NLS-1$
    String generate = vdb.getPropertyValue(REST_NAMESPACE + "auto-generate");
    if (generate == null || !Boolean.parseBoolean(generate)) {
        return false;
    }
    // $NON-NLS-1$
    String securityType = vdb.getPropertyValue(REST_NAMESPACE + "security-type");
    if (securityType != null && !securityType.equalsIgnoreCase("none") && !securityType.equalsIgnoreCase("httpbasic")) {
        // $NON-NLS-1$ //$NON-NLS-2$
        return false;
    }
    MetadataStore metadataStore = vdb.getAttachment(TransformationMetadata.class).getMetadataStore();
    for (ModelMetaData model : vdb.getModelMetaDatas().values()) {
        Schema schema = metadataStore.getSchema(model.getName());
        if (schema == null) {
            // OTHER type, which does not have a corresponding Teiid schema
            continue;
        }
        Collection<Procedure> procedures = schema.getProcedures().values();
        for (Procedure procedure : procedures) {
            // $NON-NLS-1$
            String uri = procedure.getProperty(REST_NAMESPACE + "URI", false);
            // $NON-NLS-1$
            String method = procedure.getProperty(REST_NAMESPACE + "METHOD", false);
            if (uri != null && method != null) {
                return true;
            }
        }
    }
    return false;
}
Also used : MetadataStore(org.teiid.metadata.MetadataStore) TransformationMetadata(org.teiid.query.metadata.TransformationMetadata) Schema(org.teiid.metadata.Schema) Procedure(org.teiid.metadata.Procedure) ModelMetaData(org.teiid.adminapi.impl.ModelMetaData)

Example 62 with MetadataStore

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

the class TestRestWebArchiveBuilder method getTestVDBMetaData.

private VDBMetaData getTestVDBMetaData() throws FileNotFoundException, XMLStreamException {
    VDBMetaData vdb = VDBMetadataParser.unmarshell(new FileInputStream(UnitTestUtil.getTestDataFile("sample-vdb.xml")));
    MetadataStore ms = new MetadataStore();
    for (ModelMetaData model : vdb.getModelMetaDatas().values()) {
        MetadataFactory mf = TestDDLParser.helpParse(model.getSchemaText(), model.getName());
        ms.addSchema(mf.getSchema());
    }
    TransformationMetadata metadata = RealMetadataFactory.createTransformationMetadata(ms, "Rest");
    vdb.addAttchment(QueryMetadataInterface.class, metadata);
    vdb.addAttchment(TransformationMetadata.class, metadata);
    vdb.addAttchment(MetadataStore.class, ms);
    return vdb;
}
Also used : MetadataStore(org.teiid.metadata.MetadataStore) TransformationMetadata(org.teiid.query.metadata.TransformationMetadata) RealMetadataFactory(org.teiid.query.unittest.RealMetadataFactory) MetadataFactory(org.teiid.metadata.MetadataFactory) VDBMetaData(org.teiid.adminapi.impl.VDBMetaData) FileInputStream(java.io.FileInputStream) ModelMetaData(org.teiid.adminapi.impl.ModelMetaData)

Example 63 with MetadataStore

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

the class TestRestWebArchiveBuilder method testBuildArchiveSwagger.

@Test
public void testBuildArchiveSwagger() throws Exception {
    VDBMetaData vdb = getTestVDBMetaData();
    RestASMBasedWebArchiveBuilder builder = new RestASMBasedWebArchiveBuilder();
    MetadataStore metadataStore = vdb.getAttachment(TransformationMetadata.class).getMetadataStore();
    for (ModelMetaData model : vdb.getModelMetaDatas().values()) {
        Schema schema = metadataStore.getSchema(model.getName());
        byte[] viewContents = builder.getViewClass(vdb.getName(), vdb.getVersion(), model.getName(), schema, false);
        if (viewContents != null) {
            Class<?> cls = ASMUtilities.defineClass("org.teiid.jboss.rest.View", viewContents);
            Set<Annotation> annotationSet = new HashSet<Annotation>();
            for (Annotation annotation : cls.getAnnotations()) {
                annotationSet.add(annotation);
            }
            assertEquals(2, annotationSet.size());
            for (Method m : cls.getMethods()) {
                if (m.getName().equals("g1Tableapplication_xml")) {
                    ApiOperation annotation = m.getAnnotation(ApiOperation.class);
                    assertEquals("g1Table", annotation.value());
                } else if (m.getName().equals("sqlQueryxml")) {
                    ApiOperation annotation = m.getAnnotation(ApiOperation.class);
                    assertEquals("xml", annotation.value());
                } else if (m.getName().equals("sqlQueryjson")) {
                    ApiOperation annotation = m.getAnnotation(ApiOperation.class);
                    assertEquals("json", annotation.value());
                }
            }
        }
    }
}
Also used : TransformationMetadata(org.teiid.query.metadata.TransformationMetadata) Schema(org.teiid.metadata.Schema) Method(java.lang.reflect.Method) Annotation(java.lang.annotation.Annotation) ModelMetaData(org.teiid.adminapi.impl.ModelMetaData) MetadataStore(org.teiid.metadata.MetadataStore) VDBMetaData(org.teiid.adminapi.impl.VDBMetaData) ApiOperation(io.swagger.annotations.ApiOperation) HashSet(java.util.HashSet) Test(org.junit.Test)

Example 64 with MetadataStore

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

the class CompositeVDB method metadataLoadFinished.

public void metadataLoadFinished(boolean allowEnv) {
    if (this.metadataloadFinished) {
        return;
    }
    this.metadataloadFinished = true;
    MetadataStore mergedStore = getMetadataStore();
    // the order of the models is important for resolving ddl
    // TODO we might consider not using the intermediate MetadataStore
    List<Schema> schemas = mergedStore.getSchemaList();
    schemas.clear();
    for (ModelMetaData model : this.vdb.getModelMetaDatas().values()) {
        Schema s = mergedStore.getSchema(model.getName());
        if (s != null) {
            schemas.add(s);
        } else {
            mergedStore.getSchemas().remove(model.getName());
        }
    }
    if (this.children != null && !this.children.isEmpty()) {
        for (CompositeVDB child : this.children.values()) {
            MetadataStore childStore = child.getMetadataStore();
            if (childStore != null) {
                mergedStore.merge(childStore);
            }
        }
    }
    TransformationMetadata metadata = buildTransformationMetaData(mergedVDB, getVisibilityMap(), mergedStore, getUDF(), systemFunctions, this.additionalStores, allowEnv);
    QueryMetadataInterface qmi = metadata;
    Map<String, String> multiSourceModels = MultiSourceMetadataWrapper.getMultiSourceModels(mergedVDB);
    if (multiSourceModels != null && !multiSourceModels.isEmpty()) {
        qmi = new MultiSourceMetadataWrapper(metadata, multiSourceModels);
    }
    mergedVDB.addAttchment(QueryMetadataInterface.class, qmi);
    mergedVDB.addAttchment(TransformationMetadata.class, metadata);
    mergedVDB.addAttchment(MetadataStore.class, mergedStore);
}
Also used : CompositeMetadataStore(org.teiid.query.metadata.CompositeMetadataStore) MetadataStore(org.teiid.metadata.MetadataStore) MultiSourceMetadataWrapper(org.teiid.dqp.internal.process.multisource.MultiSourceMetadataWrapper) TransformationMetadata(org.teiid.query.metadata.TransformationMetadata) Schema(org.teiid.metadata.Schema) QueryMetadataInterface(org.teiid.query.metadata.QueryMetadataInterface) ModelMetaData(org.teiid.adminapi.impl.ModelMetaData)

Example 65 with MetadataStore

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

the class CompositeVDB method buildTransformationMetaData.

private static TransformationMetadata buildTransformationMetaData(VDBMetaData vdb, LinkedHashMap<String, VDBResources.Resource> visibilityMap, MetadataStore store, UDFMetaData udf, FunctionTree systemFunctions, MetadataStore[] additionalStores, boolean allowEnv) {
    Collection<FunctionTree> udfs = new ArrayList<FunctionTree>();
    if (udf != null) {
        for (Map.Entry<String, UDFSource> entry : udf.getFunctions().entrySet()) {
            udfs.add(new FunctionTree(entry.getKey(), entry.getValue(), true));
        }
    }
    // add functions for procedures
    for (Schema schema : store.getSchemas().values()) {
        if (!schema.getProcedures().isEmpty()) {
            FunctionTree ft = FunctionTree.getFunctionProcedures(schema);
            if (ft != null) {
                udfs.add(ft);
            }
        }
    }
    CompositeMetadataStore compositeStore = new CompositeMetadataStore(store);
    for (MetadataStore s : additionalStores) {
        compositeStore.merge(s);
        for (Schema schema : s.getSchemas().values()) {
            if (!schema.getFunctions().isEmpty()) {
                UDFSource source = new UDFSource(schema.getFunctions().values());
                if (udf != null) {
                    source.setClassLoader(udf.getClassLoader());
                }
                udfs.add(new FunctionTree(schema.getName(), source, true));
            }
            if (!schema.getProcedures().isEmpty()) {
                FunctionTree ft = FunctionTree.getFunctionProcedures(schema);
                if (ft != null) {
                    udfs.add(ft);
                }
            }
        }
    }
    TransformationMetadata metadata = new TransformationMetadata(vdb, compositeStore, visibilityMap, systemFunctions, udfs);
    metadata.setAllowENV(allowEnv);
    metadata.setUseOutputNames(false);
    metadata.setWidenComparisonToString(WIDEN_COMPARISON_TO_STRING);
    return metadata;
}
Also used : UDFSource(org.teiid.query.function.UDFSource) CompositeMetadataStore(org.teiid.query.metadata.CompositeMetadataStore) MetadataStore(org.teiid.metadata.MetadataStore) TransformationMetadata(org.teiid.query.metadata.TransformationMetadata) FunctionTree(org.teiid.query.function.FunctionTree) CompositeMetadataStore(org.teiid.query.metadata.CompositeMetadataStore) Schema(org.teiid.metadata.Schema) ArrayList(java.util.ArrayList) LinkedHashMap(java.util.LinkedHashMap) Map(java.util.Map)

Aggregations

MetadataStore (org.teiid.metadata.MetadataStore)73 Schema (org.teiid.metadata.Schema)47 Test (org.junit.Test)38 Table (org.teiid.metadata.Table)37 TransformationMetadata (org.teiid.query.metadata.TransformationMetadata)22 QueryNode (org.teiid.query.mapping.relational.QueryNode)19 Column (org.teiid.metadata.Column)17 VDBMetaData (org.teiid.adminapi.impl.VDBMetaData)15 Properties (java.util.Properties)12 MetadataFactory (org.teiid.metadata.MetadataFactory)12 QueryMetadataInterface (org.teiid.query.metadata.QueryMetadataInterface)12 Procedure (org.teiid.metadata.Procedure)11 List (java.util.List)9 ModelMetaData (org.teiid.adminapi.impl.ModelMetaData)9 Connection (java.sql.Connection)8 ConnectorManagerRepository (org.teiid.dqp.internal.datamgr.ConnectorManagerRepository)8 ArrayList (java.util.ArrayList)7 ProcedureParameter (org.teiid.metadata.ProcedureParameter)7 BasicSourceCapabilities (org.teiid.query.optimizer.capabilities.BasicSourceCapabilities)7 TempMetadataStore (org.teiid.query.metadata.TempMetadataStore)6