use of org.apache.olingo.server.core.uri.queryoption.ExpandOptionImpl 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);
}
}
}
Aggregations