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