Skip to content

Commit

Permalink
TEIID-4271: Providing an option to exclude system metadata from OData…
Browse files Browse the repository at this point in the history
… schema document

Introduces exclude-system-schema set in odata/src/main/webapp/WEB-INF/web.xml
  • Loading branch information
rareddy authored and johnathonlee committed Aug 18, 2016
1 parent 7f77f57 commit 9634e9c
Show file tree
Hide file tree
Showing 5 changed files with 48 additions and 21 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -237,6 +237,12 @@ <h4 class="western">from ${project.version}</h4>
<a href='https://issues.jboss.org/browse/TEIID-4245'>TEIID-4245</a>] - Add support for fetch syntax "FETCH cursorname" (supporing just fetch cursor name)
<li/>
<p style="margin-bottom: 0in">
<a href='https://issues.jboss.org/browse/TEIID-4247'>TEIID-4247</a>] - OData - support date and time functions (adding date and time functions)
<li/>
<p style="margin-bottom: 0in">
<a href='https://issues.jboss.org/browse/TEIID-4271'>TEIID-4271</a>] - Consume Teiid OData from Salesforce (Providing an option to exclude system metadata from OData schema document)
<li/>
<p style="margin-bottom: 0in">
<a href='https://issues.jboss.org/browse/TEIID-4278'>TEIID-4278</a>] - MySQL 5 should support distinct aggregates
<li/>
<p style="margin-bottom: 0in">
Expand Down
27 changes: 22 additions & 5 deletions odata/src/main/java/org/teiid/odata/LocalClient.java
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,11 @@
import java.sql.Statement;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Properties;
import java.util.Set;

import org.odata4j.core.OCollection;
import org.odata4j.core.OCollection.Builder;
Expand Down Expand Up @@ -93,11 +95,13 @@
import org.teiid.translator.odata.ODataTypeManager;
import org.teiid.transport.LocalServerConnection;


public class LocalClient implements Client {
private static final String BATCH_SIZE = "batch-size"; //$NON-NLS-1$
private static final String SKIPTOKEN_TIME = "skiptoken-cache-time"; //$NON-NLS-1$
static final String INVALID_CHARACTER_REPLACEMENT = "invalid-xml10-character-replacement"; //$NON-NLS-1$
static final String DELIMITER = "--" ; //$NON-NLS-1$
private static final String EXCLUDE_SYSTEMS_SCHEMAS = "exclude-system-schema"; //$NON-NLS-1$

private volatile VDBMetaData vdb;
private String vdbName;
Expand All @@ -109,6 +113,7 @@ public class LocalClient implements Client {
private EdmDataServices edmMetaData;
private TeiidDriver driver = TeiidDriver.getInstance();
private String invalidCharacterReplacement;
private HashSet<String> excludeSchemas = new HashSet<String>();

public LocalClient(String vdbName, int vdbVersion, Properties props) {
this.vdbName = vdbName;
Expand All @@ -129,6 +134,17 @@ public LocalClient(String vdbName, int vdbVersion, Properties props) {
this.initProperties.put(EmbeddedProfile.WAIT_FOR_LOAD, "0"); //$NON-NLS-1$
}
this.connectionString = sb.toString();

if (PropertiesUtils.getBooleanProperty(props, EXCLUDE_SYSTEMS_SCHEMAS, false)) {
this.excludeSchemas.add("SYS");
this.excludeSchemas.add("SYSADMIN");
this.excludeSchemas.add("pg_catalog");
}
}

static boolean isExcludeSchema(String schemaName,
Set<String> excludeSchemas) {
return excludeSchemas.contains(schemaName);
}

@Override
Expand Down Expand Up @@ -482,26 +498,27 @@ private Map<String, Object> getGeneratedKeys(ResultSet result) throws SQLExcepti
@Override
public EdmDataServices getMetadata() {
if (this.edmMetaData == null) {
this.edmMetaData = buildMetadata(getVDB(), getMetadataStore());
this.edmMetaData = buildMetadata(getVDB(), getMetadataStore(), this.excludeSchemas);
}
return this.edmMetaData;
}

public static EdmDataServices buildMetadata(VDBMetaData vdb, MetadataStore metadataStore) {
public static EdmDataServices buildMetadata(VDBMetaData vdb,
MetadataStore metadataStore, Set<String> excludeSchemas) {
try {
List<EdmSchema.Builder> edmSchemas = new ArrayList<EdmSchema.Builder>();
for (Schema schema:metadataStore.getSchemaList()) {
if (isVisible(vdb, schema)) {
if (isVisible(vdb, schema) && !isExcludeSchema(schema.getName(), excludeSchemas)) {
ODataEntitySchemaBuilder.buildEntityTypes(schema, edmSchemas, false);
}
}
for (Schema schema:metadataStore.getSchemaList()) {
if (isVisible(vdb, schema)) {
if (isVisible(vdb, schema) && !isExcludeSchema(schema.getName(), excludeSchemas)) {
ODataEntitySchemaBuilder.buildFunctionImports(schema, edmSchemas, false);
}
}
for (Schema schema:metadataStore.getSchemaList()) {
if (isVisible(vdb, schema)) {
if (isVisible(vdb, schema) && !isExcludeSchema(schema.getName(), excludeSchemas)) {
ODataEntitySchemaBuilder.buildAssosiationSets(schema, edmSchemas, false);
}
}
Expand Down
8 changes: 7 additions & 1 deletion odata/src/main/webapp/WEB-INF/web.xml
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,13 @@
<param-name>resteasy.document.expand.entity.references</param-name>
<param-value>false</param-value>
</context-param>

<!--
uncomment if you want exclude system schemas from $metadata, The below property takes true/false
<context-param>
<param-name>exclude-system-schema</param-name>
<param-value>true</param-value>
</context-param>
-->
<!--
If you want to restrict access to single VDB, uncomment and provide the VDB name(must be in format vdbName.vdbVersion),
and provide a context name in jboss-web.xml that is not "odata"
Expand Down
22 changes: 9 additions & 13 deletions odata/src/test/java/org/teiid/odata/TestODataIntegration.java
Original file line number Diff line number Diff line change
Expand Up @@ -22,23 +22,19 @@
package org.teiid.odata;

import static org.junit.Assert.*;
import static org.mockito.Matchers.*;
import static org.mockito.Mockito.*;
import static org.mockito.Matchers.any;
import static org.mockito.Matchers.anyListOf;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.stub;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;

import java.io.IOException;
import java.io.StringWriter;
import java.math.BigDecimal;
import java.net.URL;
import java.net.URLDecoder;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.EnumSet;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.Properties;
import java.util.StringTokenizer;
import java.util.*;

import javax.ws.rs.core.MediaType;

Expand Down Expand Up @@ -208,7 +204,7 @@ protected Client mockClient2() {
stub(model.isVisible()).toReturn(false);
stub(vdb.getModel("nw")).toReturn(model);
stub(client.getMetadataStore()).toReturn(metadata.getMetadataStore());
EdmDataServices eds = LocalClient.buildMetadata(vdb, metadata.getMetadataStore());
EdmDataServices eds = LocalClient.buildMetadata(vdb, metadata.getMetadataStore(), new HashSet<String>());
stub(client.getMetadata()).toReturn(eds);
return client;
}
Expand All @@ -234,7 +230,7 @@ protected Client mockClient() {
Client client = mock(Client.class);
VDBMetaData vdb = mock(VDBMetaData.class);
stub(client.getMetadataStore()).toReturn(metadata.getMetadataStore());
EdmDataServices eds = LocalClient.buildMetadata(vdb, metadata.getMetadataStore());
EdmDataServices eds = LocalClient.buildMetadata(vdb, metadata.getMetadataStore(), new HashSet<String>());
stub(client.getMetadata()).toReturn(eds);
return client;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,14 @@
package org.teiid.odata;

import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashSet;
import java.util.List;
import java.util.StringTokenizer;
import java.util.regex.Matcher;

import org.junit.Test;
import org.mockito.Mockito;
Expand Down Expand Up @@ -343,7 +346,7 @@ public void testMultiEntitykey() throws Exception {
TransformationMetadata metadata = RealMetadataFactory.fromDDL(ObjectConverterUtil.convertFileToString(UnitTestUtil.getTestDataFile("northwind.ddl")), "northwind", "nw");
ODataSQLBuilder visitor = new ODataSQLBuilder(metadata.getMetadataStore(), false);
OEntityKey key = OEntityKey.parse("(11044)");
EdmDataServices eds = LocalClient.buildMetadata(metadata.getVdbMetaData(), metadata.getMetadataStore());
EdmDataServices eds = LocalClient.buildMetadata(metadata.getVdbMetaData(), metadata.getMetadataStore(), new HashSet<String>());
EdmEntitySet entitySet = eds.getEdmEntitySet("Categories");
Delete delete = visitor.delete(entitySet, key);
assertEquals("DELETE FROM nw.Categories WHERE nw.Categories.CategoryID = 11044", delete.toString());
Expand All @@ -355,7 +358,6 @@ public void testMultiEntitykey() throws Exception {
Insert insert = visitor.insert(entitySet, entity);
assertEquals("INSERT INTO nw.Categories (Description) VALUES (?)", insert.toString());
}

}


0 comments on commit 9634e9c

Please sign in to comment.