Skip to content

Commit

Permalink
TEIID-5544 fixing the term for teiid annotations
Browse files Browse the repository at this point in the history
# Conflicts:
#	olingo/src/test/java/org/teiid/olingo/TestODataIntegration.java
  • Loading branch information
shawkins committed Nov 19, 2018
1 parent 022738d commit f720ae4
Show file tree
Hide file tree
Showing 3 changed files with 44 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -628,7 +628,7 @@ static boolean sameColumnSet(KeyRecord recordOne, KeyRecord recordTwo) {

private static void addTableAnnotations(Table table, CsdlEntityType entityType, CsdlSchema csdlSchema) {
if (table.getAnnotation() != null) {
addStringAnnotation(entityType, "core.Description", table.getAnnotation());
addStringAnnotation(entityType, "Core.Description", table.getAnnotation());
}

if (table.getCardinality() != -1) {
Expand Down Expand Up @@ -679,7 +679,7 @@ private static void addTableAnnotations(Table table, CsdlEntityType entityType,
private static void addColumnAnnotations(Column column,
CsdlProperty property, CsdlSchema csdlSchema) {
if (column.getAnnotation() != null) {
addStringAnnotation(property, "core.Description", column.getAnnotation());
addStringAnnotation(property, "Core.Description", column.getAnnotation());
}

if (column.getNameInSource() != null) {
Expand Down Expand Up @@ -728,7 +728,7 @@ private static void addColumnAnnotations(Column column,
private static void addOperationAnnotations(Procedure proc,
CsdlOperation operation, CsdlSchema csdlSchema) {
if (proc.getAnnotation() != null) {
addStringAnnotation(operation, "core.Description", proc.getAnnotation());
addStringAnnotation(operation, "Core.Description", proc.getAnnotation());
}

if (proc.getNameInSource() != null) {
Expand All @@ -749,7 +749,7 @@ private static void addOperationParameterAnnotations(
ProcedureParameter procedure, CsdlParameter parameter,
CsdlSchema csdlSchema) {
if (procedure.getAnnotation() != null) {
addStringAnnotation(parameter, "core.Description", procedure.getAnnotation());
addStringAnnotation(parameter, "Core.Description", procedure.getAnnotation());
}

if (procedure.getNameInSource() != null) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,15 +22,18 @@

import javax.xml.stream.XMLStreamException;

import org.apache.olingo.commons.api.edm.FullQualifiedName;
import org.apache.olingo.commons.api.edm.provider.CsdlAnnotation;
import org.apache.olingo.commons.api.edm.provider.CsdlSchema;
import org.apache.olingo.commons.api.edm.provider.CsdlTerm;
import org.apache.olingo.commons.api.edm.provider.annotation.CsdlConstantExpression;
import org.apache.olingo.commons.api.edm.provider.annotation.CsdlConstantExpression.ConstantExpressionType;
import org.apache.olingo.commons.api.edmx.EdmxReference;
import org.apache.olingo.commons.api.edmx.EdmxReferenceInclude;
import org.apache.olingo.commons.api.ex.ODataException;
import org.apache.olingo.server.core.MetadataParser;
import org.apache.olingo.server.core.SchemaBasedEdmProvider;
import org.teiid.core.TeiidRuntimeException;

public class TeiidEdmProvider extends SchemaBasedEdmProvider {
public TeiidEdmProvider(String baseUri, CsdlSchema schema,
Expand Down Expand Up @@ -59,6 +62,10 @@ public TeiidEdmProvider(String baseUri, CsdlSchema schema,
getClass().getClassLoader().getResourceAsStream("org.teiid.v1.xml")));
addVocabularySchema("org.teiid.v1", provider);

provider = parser.buildEdmProvider(new InputStreamReader(

This comment has been minimized.

Copy link
@rareddy

rareddy Nov 19, 2018

Member

I believe these are loaded implicitly

This comment has been minimized.

Copy link
@shawkins

shawkins Nov 19, 2018

Author Contributor

Unfortunately they don't seem to behave that way. Correcting the alias alone did not resolve the issue.

This comment has been minimized.

Copy link
@rareddy

rareddy Nov 20, 2018

Member

Line #56 is not working then? It is supposed to load all core annotations, can you see why?

This comment has been minimized.

Copy link
@shawkins

shawkins Nov 20, 2018

Author Contributor

It loads the core for those child providers being parsed, but not for the provider being constructed.

This comment has been minimized.

Copy link
@rareddy

rareddy Nov 20, 2018

Member

I think I wrote for generic case, if you see the buildServiceMetadata that does load them, but in Teiid we choose a different a way to build ServiceMetadata, then in that scenario, it will not load all the core capabilities. I need to make the "loadCoreVocabulary" as a public method in Olingo, then we can call here. Also, there are couple more core vocabularies we need to load.

This comment has been minimized.

Copy link
@shawkins

shawkins Nov 20, 2018

Author Contributor

You could optionally pass the provider being constructed into buildEdmProvider rather than constructing a new one - that way it wouldn't reload for each buildEdmProvider.

getClass().getClassLoader().getResourceAsStream("Org.OData.Core.V1.xml")));
addVocabularySchema("Org.OData.Core.V1", provider);

// <Annotation Term="org.apache.olingo.v1.xml10-incompatible-char-replacement" String="xxx"/>
if (invalidXmlReplacementChar != null) {
CsdlAnnotation xmlCharReplacement = new CsdlAnnotation();
Expand All @@ -69,5 +76,14 @@ public TeiidEdmProvider(String baseUri, CsdlSchema schema,
}
addSchema(schema);
}

@Override
public CsdlTerm getTerm(FullQualifiedName fqn) throws ODataException {
CsdlTerm term = super.getTerm(fqn);
if (term == null) {
throw new TeiidRuntimeException(fqn.toString() + " unknown term"); //$NON-NLS-1$
}
return term;
}
}

24 changes: 24 additions & 0 deletions olingo/src/test/java/org/teiid/olingo/TestODataIntegration.java
Original file line number Diff line number Diff line change
Expand Up @@ -3115,5 +3115,29 @@ private int invokeOData(String url) throws Exception {
return rowCount;
}

@Test
public void testAnnotationMetadata() throws Exception {
HardCodedExecutionFactory hc = buildHardCodedExecutionFactory();
teiid.addTranslator("x5", hc);

try {
ModelMetaData mmd = new ModelMetaData();
mmd.setName("m");
mmd.addSourceMetadata("DDL", "create foreign table x (a string primary key) OPTIONS (ANNOTATION 'hello', foo 'bar');");
mmd.setModelType(Model.Type.PHYSICAL);
mmd.addSourceMapping("x5", "x5", null);
teiid.deployVDB("northwind", mmd);

localClient = getClient(teiid.getDriver(), "northwind", new Properties());

ContentResponse response = http.newRequest(baseURL + "/northwind/m/$metadata")
.method("GET")
.send();
assertEquals(200, response.getStatus());
} finally {
localClient = null;
teiid.undeployVDB("northwind");
}
}

}

0 comments on commit f720ae4

Please sign in to comment.