private ODataEntity Project(Content content, List <Property> expandTree, HttpContext httpContext) { var outfields = new ODataEntity(); var selfurl = GetSelfUrl(content); if (this.Request.EntityMetadata != MetadataFormat.None) { outfields.Add("__metadata", GetMetadata(content, selfurl, this.Request.EntityMetadata, httpContext)); } var fields = content.Fields.Values; var expansionEnabled = !content.ContentHandler.IsHeadOnly; foreach (var field in fields) { if (ODataMiddleware.DisabledFieldNames.Contains(field.Name)) { continue; } var propertyName = field.Name; var expansion = expansionEnabled ? GetExpansion(propertyName, expandTree) : null; if (expansion != null) { outfields.Add(propertyName, Project(field, expansion.Children, httpContext)); } else { outfields.Add(propertyName, base.IsAllowedField(content, field.Name) ? ODataWriter.GetJsonObject(field, selfurl) : null); } } AddField(content, expandTree, outfields, ACTIONSPROPERTY, httpContext, GetActions); AddField(content, expandTree, outfields, ODataMiddleware.ChildrenPropertyName, httpContext, (c, ctx) => { // disable autofilters by default the same way as in ODataWriter.WriteChildrenCollection c.ChildrenDefinition.EnableAutofilters = Request.AutofiltersEnabled != FilterStatus.Default ? Request.AutofiltersEnabled : FilterStatus.Disabled; var expansion = GetExpansion(ODataMiddleware.ChildrenPropertyName, expandTree); return(ProjectMultiRefContents(c.Children.AsEnumerable().Select(cnt => cnt.ContentHandler), expansion.Children, httpContext)); }); if (!outfields.ContainsKey(ICONPROPERTY)) { outfields.Add(ICONPROPERTY, content.Icon ?? content.ContentType.Icon); } outfields.Add(ISFILEPROPERTY, content.Fields.ContainsKey(ODataMiddleware.BinaryPropertyName)); return(outfields); }
internal override ODataEntity Project(Content content, HttpContext httpContext) { var fields = new ODataEntity(); var selfurl = GetSelfUrl(content); if (Request.EntityMetadata != MetadataFormat.None) { fields.Add("__metadata", GetMetadata(content, selfurl, Request.EntityMetadata, httpContext)); } IEnumerable <string> fieldNames; if (Request.HasSelect) { fieldNames = Request.Select; } else { if (IsCollectionItem) { if (_fieldNamesForPaths.ContainsKey(content.ContentHandler.ParentPath)) { fieldNames = _fieldNamesForPaths[content.ContentHandler.ParentPath]; } else { _fieldNamesForPaths[content.ContentHandler.ParentPath] = fieldNames = content.GetFieldNamesInParentTable(); } if (content.AspectFields != null && content.AspectFields.Count > 0) { fieldNames = fieldNames.Concat(content.AspectFields.Keys); } } else { fieldNames = content.Fields.Keys; } } if (Request.HasSelect) { foreach (var selectItem in Request.Select) { if (selectItem.Contains("/")) { throw new ODataException("Bad item in $select: " + selectItem, ODataExceptionCode.InvalidSelectParameter); } } } if (!Request.HasSelect) { fieldNames = fieldNames.Concat(new[] { ACTIONSPROPERTY, ISFILEPROPERTY, ODataMiddleware.ChildrenPropertyName }); } foreach (var fieldName in fieldNames) { if (fields.ContainsKey(fieldName)) { continue; } if (ODataMiddleware.DisabledFieldNames.Contains(fieldName)) { fields.Add(fieldName, null); continue; } if (IsAllowedField(content, fieldName)) { if (content.Fields.TryGetValue(fieldName, out var field)) { fields.Add(fieldName, ODataWriter.GetJsonObject(field, selfurl)); } else if (fieldName == ACTIONSPROPERTY) { fields.Add(ACTIONSPROPERTY, ODataReference.Create(String.Concat(selfurl, "/", ODataMiddleware.ActionsPropertyName))); } else if (fieldName == ISFILEPROPERTY) { fields.Add(ISFILEPROPERTY, content.Fields.ContainsKey(ODataMiddleware.BinaryPropertyName)); } else if (fieldName == ICONPROPERTY) { fields.Add(fieldName, content.Icon ?? content.ContentType.Icon); } else if (fieldName == ODataMiddleware.ChildrenPropertyName) { fields.Add(fieldName, ODataReference.Create(string.Concat(selfurl, "/", ODataMiddleware.ChildrenPropertyName))); } else { fields.Add(fieldName, null); } } else { fields.Add(fieldName, null); } } return(fields); }
private ODataEntity Project(Content content, List <Property> expandTree, List <Property> selectTree, HttpContext httpContext) { var outfields = new ODataEntity(); var selfurl = GetSelfUrl(content); if (this.Request.EntityMetadata != MetadataFormat.None) { outfields.Add("__metadata", GetMetadata(content, selfurl, this.Request.EntityMetadata, httpContext)); } var hasJoker = false; foreach (var property in selectTree) { var propertyName = property.Name; if (propertyName == "*") { hasJoker = true; continue; } if (!content.Fields.TryGetValue(propertyName, out var field)) { var expansion = GetPropertyFromList(propertyName, expandTree); switch (propertyName) { case ACTIONSPROPERTY: AddField(content, expansion, outfields, propertyName, httpContext, (c, ctx) => { var actions = Content.CreateCollection(GetActions(c, ctx), ODataActionItem.Ctd); return(ProjectMultiRefContents(actions.Select(cnt => cnt.ContentHandler), expansion.Children, property.Children, httpContext)); }); break; case ICONPROPERTY: outfields.Add(ICONPROPERTY, content.Icon ?? content.ContentType.Icon); break; case ISFILEPROPERTY: outfields.Add(ISFILEPROPERTY, content.Fields.ContainsKey(ODataMiddleware.BinaryPropertyName)); break; case ODataMiddleware.ChildrenPropertyName: AddField(content, expansion, outfields, propertyName, httpContext, (c, ctx) => { // disable autofilters by default the same way as in ODataWriter.WriteChildrenCollection c.ChildrenDefinition.EnableAutofilters = Request.AutofiltersEnabled != FilterStatus.Default ? Request.AutofiltersEnabled : FilterStatus.Disabled; return(ProjectMultiRefContents( c.Children.AsEnumerable().Select(cnt => cnt.ContentHandler), expansion.Children, property.Children, httpContext)); }); break; default: outfields.Add(propertyName, null); break; } } else { if (ODataMiddleware.DisabledFieldNames.Contains(field.Name)) { outfields.Add(propertyName, null); } else { var expansion = GetPropertyFromList(propertyName, expandTree); if (expansion != null) { outfields.Add(propertyName, Project(field, expansion.Children, property.Children ?? Property.JokerList, httpContext)); } else { outfields.Add(propertyName, IsAllowedField(content, field.Name) ? ODataWriter.GetJsonObject(field, selfurl) : null); } } } } if (hasJoker) { foreach (var contentField in content.Fields.Values) { if (outfields.ContainsKey(contentField.Name)) { continue; } var propertyName = contentField.Name; var expansion = GetPropertyFromList(propertyName, expandTree); outfields.Add(propertyName, expansion != null ? Project(contentField, expansion.Children, Property.JokerList, httpContext) : ODataWriter.GetJsonObject(contentField, selfurl)); } } return(outfields); }