use of org.apache.olingo.commons.api.edm.EdmEntityType in project cxf by apache.
the class DemoEntityCollectionProcessor method readEntityCollection.
// CHECKSTYLE:ON
// the only method that is declared in the EntityCollectionProcessor interface
// this method is called, when the user fires a request to an EntitySet
// in our example, the URL would be:
// http://localhost:8080/ExampleService1/ExampleServlet1.svc/Products
public void readEntityCollection(ODataRequest request, ODataResponse response, UriInfo uriInfo, ContentType responseFormat) throws ODataApplicationException, SerializerException {
// 1st we have retrieve the requested EntitySet from the uriInfo object
// (representation of the parsed service URI)
List<UriResource> resourcePaths = uriInfo.getUriResourceParts();
// In our example, the first segment is the EntitySet
UriResourceEntitySet uriResourceEntitySet = (UriResourceEntitySet) resourcePaths.get(0);
EdmEntitySet edmEntitySet = uriResourceEntitySet.getEntitySet();
// 2nd: fetch the data from backend for this requested EntitySetName
// it has to be delivered as EntitySet object
EntityCollection entitySet = getData(edmEntitySet);
// 3rd: create a serializer based on the requested format (json)
ODataSerializer serializer = odata.createSerializer(responseFormat);
// 4th: Now serialize the content: transform from the EntitySet object to InputStream
EdmEntityType edmEntityType = edmEntitySet.getEntityType();
ContextURL contextUrl = ContextURL.with().entitySet(edmEntitySet).build();
final String id = request.getRawBaseUri() + "/" + edmEntitySet.getName();
EntityCollectionSerializerOptions opts = EntityCollectionSerializerOptions.with().id(id).contextURL(contextUrl).build();
SerializerResult serializedContent = serializer.entityCollection(serviceMetadata, edmEntityType, entitySet, opts);
// Finally: configure the response object: set the body, headers and status code
response.setContent(serializedContent.getContent());
response.setStatusCode(HttpStatusCode.OK.getStatusCode());
response.setHeader(HttpHeader.CONTENT_TYPE, responseFormat.toContentTypeString());
}
use of org.apache.olingo.commons.api.edm.EdmEntityType in project teiid by teiid.
the class ODataSQLBuilder method processExpandOption.
private void processExpandOption(ExpandOption option, DocumentNode node, Query outerQuery, int expandLevel, Integer cyclicLevel) throws TeiidException {
checkExpandLevel(expandLevel);
int starLevels = 0;
HashSet<String> seen = new HashSet<String>();
for (ExpandItem ei : option.getExpandItems()) {
if (ei.getSearchOption() != null) {
throw new TeiidNotImplementedException(ODataPlugin.Event.TEIID16035, ODataPlugin.Util.gs(ODataPlugin.Event.TEIID16035));
}
Integer levels = null;
if (cyclicLevel != null) {
levels = cyclicLevel - 1;
} else if (ei.getLevelsOption() != null) {
if (ei.getLevelsOption().isMax()) {
levels = MAX_EXPAND_LEVEL - expandLevel + 1;
} else {
levels = ei.getLevelsOption().getValue();
checkExpandLevel(expandLevel + levels - 1);
}
}
ExpandSQLBuilder esb = new ExpandSQLBuilder(ei);
EdmNavigationProperty property = esb.getNavigationProperty();
if (property == null) {
if (ei.isStar()) {
if (starLevels > 0) {
throw new TeiidProcessingException(ODataPlugin.Event.TEIID16058, // $NON-NLS-1$
ODataPlugin.Util.gs(ODataPlugin.Event.TEIID16058, "*"));
}
if (levels != null) {
starLevels = levels;
} else {
starLevels = 1;
}
continue;
}
throw new TeiidNotImplementedException(ODataPlugin.Event.TEIID16057, ODataPlugin.Util.gs(ODataPlugin.Event.TEIID16057));
}
if (!seen.add(property.getName())) {
throw new TeiidProcessingException(ODataPlugin.Event.TEIID16058, ODataPlugin.Util.gs(ODataPlugin.Event.TEIID16058, property.getName()));
}
// always pass in the root as the parent as that seems to be the definition of the current context
// if instead it should refer to the parent expands, then we would pass in the node instead
ExpandDocumentNode expandResource = ExpandDocumentNode.buildExpand(property, this.metadata, this.odata, this.nameGenerator, true, getUriInfo(), this.parseService, this.context);
node.addExpand(expandResource);
// process $filter
if (ei.getFilterOption() != null) {
Expression expandCriteria = processFilterOption(ei.getFilterOption(), expandResource);
expandResource.addCriteria(expandCriteria);
}
OrderBy expandOrder = null;
if (ei.getOrderByOption() != null) {
expandOrder = new OrderBy();
processOrderBy(expandOrder, ei.getOrderByOption().getOrders(), expandResource);
} else {
expandOrder = expandResource.addDefaultOrderBy();
}
// process $select
processSelectOption(ei.getSelectOption(), expandResource, this.reference);
if (ei.getSkipOption() != null) {
expandResource.setSkip(ei.getSkipOption().getValue());
}
if (ei.getTopOption() != null) {
expandResource.setTop(ei.getTopOption().getValue());
}
Query query = expandResource.buildQuery();
if (ei.getExpandOption() != null) {
processExpandOption(ei.getExpandOption(), expandResource, query, expandLevel + 1, null);
} else if (levels != null) {
// self reference check
if (!property.getType().getFullQualifiedName().equals(node.getEdmEntityType().getFullQualifiedName())) {
throw new TeiidProcessingException(ODataPlugin.Event.TEIID16060, ODataPlugin.Util.gs(ODataPlugin.Event.TEIID16060, node.getEdmEntityType().getFullQualifiedName(), property.getType().getFullQualifiedName()));
}
if (levels > 1) {
ExpandOptionImpl eoi = new ExpandOptionImpl();
eoi.addExpandItem(ei);
processExpandOption(eoi, expandResource, query, expandLevel + 1, levels);
}
}
buildAggregateQuery(node, outerQuery, expandResource, expandOrder, query, property);
}
if (starLevels > 0) {
List<ExpandNode> starExpand = new ArrayList<TeiidServiceHandler.ExpandNode>();
EdmEntityType edmEntityType = node.getEdmEntityType();
buildExpandGraph(seen, starExpand, edmEntityType, starLevels - 1);
if (!starExpand.isEmpty()) {
processExpand(starExpand, node, outerQuery, expandLevel);
}
}
}
use of org.apache.olingo.commons.api.edm.EdmEntityType in project teiid by teiid.
the class ODataSQLBuilder method visit.
@Override
public void visit(UriInfoCrossjoin info) {
for (String name : info.getEntitySetNames()) {
EdmEntitySet entitySet = this.serviceMetadata.getEdm().getEntityContainer().getEntitySet(name);
EdmEntityType entityType = entitySet.getEntityType();
CrossJoinNode resource = null;
try {
boolean hasExpand = hasExpand(entitySet.getName(), info.getExpandOption());
resource = CrossJoinNode.buildCrossJoin(entityType, null, this.metadata, this.odata, this.nameGenerator, this.aliasedGroups, getUriInfo(), this.parseService, hasExpand);
resource.addAllColumns(!hasExpand);
if (this.context == null) {
this.context = resource;
this.orderBy = this.context.addDefaultOrderBy();
} else {
this.context.addSibiling(resource);
OrderBy orderby = resource.addDefaultOrderBy();
int index = orderby.getVariableCount();
for (int i = 0; i < index; i++) {
this.orderBy.addVariable(orderby.getVariable(i));
}
}
} catch (TeiidException e) {
this.exceptions.add(e);
}
}
super.visit(info);
// the expand behavior is handled above with selection of the columns
this.expandOption = null;
}
use of org.apache.olingo.commons.api.edm.EdmEntityType in project teiid by teiid.
the class ReferenceUpdateSQLBuilder method visit.
@Override
public void visit(UriResourceEntitySet info) {
Table table = DocumentNode.findTable(info.getEntitySet(), this.metadata);
EdmEntityType type = info.getEntitySet().getEntityType();
List<UriParameter> keys = info.getKeyPredicates();
this.updateTable = new ScopedTable(table, type, keys);
}
use of org.apache.olingo.commons.api.edm.EdmEntityType in project teiid by teiid.
the class ReferenceUpdateSQLBuilder method updateReference.
public Update updateReference(URI referenceId, boolean prepared, boolean delete) throws SQLException {
try {
if (referenceId != null) {
UriInfo uriInfo = ODataSQLBuilder.buildUriInfo(referenceId, this.baseURI, this.serviceMetadata, this.odata);
UriResourceEntitySet uriEnitytSet = (UriResourceEntitySet) uriInfo.asUriInfoResource().getUriResourceParts().get(0);
if (this.collection) {
this.updateTable.setKeyPredicates(uriEnitytSet.getKeyPredicates());
} else {
this.referenceTable.setKeyPredicates(uriEnitytSet.getKeyPredicates());
}
}
} catch (UriParserException e) {
throw new SQLException(e);
} catch (URISyntaxException e) {
throw new SQLException(e);
} catch (UriValidationException e) {
throw new SQLException(e);
}
try {
Update update = new Update();
update.setGroup(this.updateTable.getGroupSymbol());
List<String> columnNames = DocumentNode.getColumnNames(this.updateTable.getFk().getColumns());
for (int i = 0; i < columnNames.size(); i++) {
Column column = this.updateTable.getFk().getColumns().get(i);
String columnName = columnNames.get(i);
ElementSymbol symbol = new ElementSymbol(columnName, this.updateTable.getGroupSymbol());
EdmEntityType entityType = this.updateTable.getEdmEntityType();
EdmProperty edmProperty = (EdmProperty) entityType.getProperty(columnName);
// reference table keys will be null for delete scenario
Object value = null;
if (!delete) {
UriParameter parameter = getParameter(this.updateTable.getFk().getReferenceColumns().get(i), this.referenceTable.getKeyPredicates());
value = ODataTypeManager.parseLiteral(edmProperty, column.getJavaType(), parameter.getText());
}
if (prepared) {
update.addChange(symbol, new Reference(i++));
this.params.add(ODataSQLBuilder.asParam(edmProperty, value));
} else {
update.addChange(symbol, new Constant(ODataSQLBuilder.asParam(edmProperty, value).getValue()));
}
}
Criteria criteria = DocumentNode.buildEntityKeyCriteria(this.updateTable, null, this.metadata, this.odata, null, null);
update.setCriteria(criteria);
return update;
} catch (TeiidException e) {
throw new SQLException(e);
}
}
Aggregations