Skip to content

Commit

Permalink
TEIID-5544 fixing the term for teiid annotations
Browse files Browse the repository at this point in the history
  • Loading branch information
shawkins committed Nov 19, 2018
1 parent 78fa6cc commit fe232ce
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -645,7 +645,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 @@ -696,7 +696,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 @@ -745,7 +745,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 @@ -766,7 +766,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(
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;
}
}

25 changes: 25 additions & 0 deletions olingo/src/test/java/org/teiid/olingo/TestODataIntegration.java
Original file line number Diff line number Diff line change
Expand Up @@ -3148,4 +3148,29 @@ public void testDecimalPrecisionScale() throws Exception {
}
}

@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 fe232ce

Please sign in to comment.