public static CollectionRepresentation Create(IOidStrategy oidStrategy, HttpRequestMessage req, PropertyContextFacade propertyContext, IList <OptionalProperty> optionals, RestControlFlags flags) { var collectionRepresentationStrategy = AbstractCollectionRepresentationStrategy.GetStrategy(false, false, oidStrategy, req, propertyContext, flags); var value = collectionRepresentationStrategy.GetValue(); if (value != null) { optionals.Add(new OptionalProperty(JsonPropertyNames.Value, value)); } var actions = collectionRepresentationStrategy.GetActions(); if (actions.Length > 0) { var members = RestUtils.CreateMap(actions.ToDictionary(m => m.Id, m => (object)m)); optionals.Add(new OptionalProperty(JsonPropertyNames.Members, members)); } if (optionals.Count == 0) { return(new CollectionRepresentation(oidStrategy, collectionRepresentationStrategy)); } return(CreateWithOptionals <CollectionRepresentation>(new object[] { oidStrategy, collectionRepresentationStrategy }, optionals)); }
public static InlineCollectionRepresentation Create(IOidStrategy oidStrategy, HttpRequest req, PropertyContextFacade propertyContext, IList <OptionalProperty> optionals, RestControlFlags flags, bool asTableColumn) { var collectionRepresentationStrategy = AbstractCollectionRepresentationStrategy.GetStrategy(asTableColumn, true, oidStrategy, req, propertyContext, flags); var size = collectionRepresentationStrategy.GetSize(); if (size != null) { optionals.Add(new OptionalProperty(JsonPropertyNames.Size, size)); } var value = collectionRepresentationStrategy.GetValue(); if (value != null) { optionals.Add(new OptionalProperty(JsonPropertyNames.Value, value)); } var actions = collectionRepresentationStrategy.GetActions(); if (actions.Any()) { var members = RestUtils.CreateMap(actions.ToDictionary(m => m.Id, m => (object)m)); optionals.Add(new OptionalProperty(JsonPropertyNames.Members, members)); } return(optionals.Any() ? CreateWithOptionals <InlineCollectionRepresentation>(new object[] { oidStrategy, collectionRepresentationStrategy }, optionals) : new InlineCollectionRepresentation(oidStrategy, collectionRepresentationStrategy)); }
private void SetMembers(IMenuFacade menu, HttpRequestMessage req, List <LinkRepresentation> tempLinks) { var actionFacades = menu.MenuItems.SelectMany(i => GetMenuItem(i)); InlineActionRepresentation[] actions = actionFacades.Select(a => InlineActionRepresentation.Create(OidStrategy, req, a.Item2, Flags)).ToArray(); Members = RestUtils.CreateMap(actions.ToDictionary(m => m.Id, m => (object)m)); }
private void SetExtensions(ActionResultContextFacade actionResult) { var exts = new Dictionary <string, object>(); AddIfPresent(exts, actionResult.Warnings, JsonPropertyNames.CustomWarnings); AddIfPresent(exts, actionResult.Messages, JsonPropertyNames.CustomMessages); Extensions = exts.Count > 0 ? RestUtils.CreateMap(exts) : new MapRepresentation(); }
private void SetExtensions(IOidStrategy oidStrategy, ActionContextFacade actionContext) { var exts = new Dictionary <string, object> { { JsonPropertyNames.ElementType, RestUtils.SpecToTypeAndFormatString(actionContext.ElementSpecification, oidStrategy, false).typeString } }; Extensions = RestUtils.CreateMap(exts); }
private void SetMembers(ObjectContextSurface objectContext, HttpRequestMessage req, List <LinkRepresentation> tempLinks) { PropertyContextSurface[] visiblePropertiesAndCollections = objectContext.VisibleProperties; if (!Flags.BlobsClobs) { // filter any blobs and clobs visiblePropertiesAndCollections = visiblePropertiesAndCollections.Where(vp => !RestUtils.IsBlobOrClob(vp.Specification)).ToArray(); } PropertyContextSurface[] visibleProperties = visiblePropertiesAndCollections.Where(p => !p.Property.IsCollection()).ToArray(); if (!objectContext.Target.IsTransient() && visibleProperties.Any(p => p.Property.IsUsable(objectContext.Target).IsAllowed)) { string[] ids = visibleProperties.Where(p => p.Property.IsUsable(objectContext.Target).IsAllowed&& !p.Property.IsInline()).Select(p => p.Id).ToArray(); OptionalProperty[] props = ids.Select(s => new OptionalProperty(s, MapRepresentation.Create(new OptionalProperty(JsonPropertyNames.Value, null, typeof(object))))).ToArray(); LinkRepresentation modifyLink = LinkRepresentation.Create(new ObjectRelType(RelValues.Update, new UriMtHelper(req, objectContext.Target)) { Method = RelMethod.Put }, Flags, new OptionalProperty(JsonPropertyNames.Arguments, MapRepresentation.Create(props))); tempLinks.Add(modifyLink); } if (objectContext.Target.IsTransient()) { KeyValuePair <string, object>[] ids = objectContext.Target.Specification.Properties.Where(p => !p.IsCollection() && !p.IsInline()).ToDictionary(p => p.Id, p => GetPropertyValue(req, p, objectContext.Target, Flags, true)).ToArray(); OptionalProperty[] props = ids.Select(kvp => new OptionalProperty(kvp.Key, MapRepresentation.Create(new OptionalProperty(JsonPropertyNames.Value, kvp.Value)))).ToArray(); var argMembers = new OptionalProperty(JsonPropertyNames.Members, MapRepresentation.Create(props)); var args = new List <OptionalProperty> { argMembers }; LinkRepresentation persistLink = LinkRepresentation.Create(new ObjectsRelType(RelValues.Persist, new UriMtHelper(req, objectContext.Target.Specification)) { Method = RelMethod.Post }, Flags, new OptionalProperty(JsonPropertyNames.Arguments, MapRepresentation.Create(args.ToArray()))); tempLinks.Add(persistLink); } InlineMemberAbstractRepresentation[] properties = visiblePropertiesAndCollections.Select(p => InlineMemberAbstractRepresentation.Create(req, p, Flags)).ToArray(); InlineActionRepresentation[] actions = objectContext.Target.IsTransient() ? new InlineActionRepresentation[] {} : objectContext.VisibleActions.Select(a => InlineActionRepresentation.Create(req, a, Flags)).ToArray(); IEnumerable <InlineMemberAbstractRepresentation> allMembers = properties.Union(actions); Members = RestUtils.CreateMap(allMembers.ToDictionary(m => m.Id, m => (object)m)); }
private void SetMembers(IMenuFacade menu, HttpRequestMessage req, List <LinkRepresentation> tempLinks) { var actionFacades = menu.MenuItems.SelectMany(i => GetMenuItem(i)).Where(af => IsVisibleAndUsable(af.Item2)); InlineActionRepresentation[] actions = actionFacades.Select(a => InlineActionRepresentation.Create(OidStrategy, req, a.Item2, Flags)).ToArray(); var eq = new Eq(); // todo fix distinct actions = actions.Distinct(eq).ToArray(); Members = RestUtils.CreateMap(actions.ToDictionary(m => m.Id, m => (object)m)); }
private void SetMembers(IMenuFacade menu, HttpRequest req) { ActionContextFacade SetMenuId(ActionContextFacade action) { action.MenuId = menu.Id; return(action); } var actionFacades = menu.MenuItems.SelectMany(i => GetMenuItem(i)).Where(af => IsVisibleAndUsable(af.action)).ToArray(); var actions = actionFacades.Select(a => InlineActionRepresentation.Create(OidStrategy, req, SetMenuId(a.action), Flags)).ToArray(); var actionComparer = new ActionComparer(); actions = actions.Distinct(actionComparer).ToArray(); Members = RestUtils.CreateMap(actions.ToDictionary(m => m.Id, m => (object)m)); }
// custom extension for pagination private void SetPagination(IObjectFacade list, RestControlFlags flags, ActionContextFacade actionContext) { Pagination = new MapRepresentation(); var totalCount = list.Count(); var pageSize = PageSize(flags, actionContext); var page = flags.Page; var numPages = (int)Math.Round(totalCount / (decimal)pageSize + 0.5m); numPages = numPages == 0 ? 1 : numPages; var exts = new Dictionary <string, object> { { JsonPropertyNames.Page, page }, { JsonPropertyNames.PageSize, pageSize }, { JsonPropertyNames.NumPages, numPages }, { JsonPropertyNames.TotalCount, totalCount } }; Pagination = RestUtils.CreateMap(exts); }
// custom extension for pagination private void SetPagination(IObjectFacade list, RestControlFlags flags) { Pagination = new MapRepresentation(); var totalCount = list.Count(); var pageSize = flags.PageSize; var page = flags.Page; var numPages = (int)Math.Round(totalCount / (decimal)pageSize + 0.5m); numPages = numPages == 0 ? 1 : numPages; var exts = new Dictionary <string, object> { { "page", page }, { "pageSize", pageSize }, { "numPages", numPages }, { "totalCount", totalCount } }; Pagination = RestUtils.CreateMap(exts); }
private void SetMembers(ObjectContextFacade objectContext, HttpRequest req, List <LinkRepresentation> tempLinks) { var visiblePropertiesAndCollections = objectContext.VisibleProperties; if (!Flags.BlobsClobs) { // filter any blobs and clobs visiblePropertiesAndCollections = visiblePropertiesAndCollections.Where(vp => !RestUtils.IsBlobOrClob(vp.Specification)).ToArray(); } var visibleProperties = visiblePropertiesAndCollections.Where(p => !p.Property.IsCollection).ToArray(); if (!IsProtoPersistent(objectContext.Target) && !IsForm(objectContext.Target) && visibleProperties.Any(p => p.Property.IsUsable(objectContext.Target).IsAllowed)) { var ids = visibleProperties.Where(p => p.Property.IsUsable(objectContext.Target).IsAllowed&& !p.Property.IsInline).Select(p => p.Id).ToArray(); var props = ids.Select(s => new OptionalProperty(s, MapRepresentation.Create(new OptionalProperty(JsonPropertyNames.Value, null, typeof(object))))).ToArray(); var helper = GetHelper(OidStrategy, req, objectContext); var modifyLink = LinkRepresentation.Create(OidStrategy, new ObjectRelType(RelValues.Update, helper) { Method = RelMethod.Put }, Flags, new OptionalProperty(JsonPropertyNames.Arguments, MapRepresentation.Create(props))); tempLinks.Add(modifyLink); } if (IsProtoPersistent(objectContext.Target)) { var ids = objectContext.Target.Specification.Properties.Where(p => !p.IsCollection && !p.IsInline).ToDictionary(p => p.Id, p => { var useDate = p.IsDateOnly; return(GetPropertyValue(OidStrategy, req, p, objectContext.Target, Flags, true, useDate)); }).ToArray(); var props = ids.Select(kvp => new OptionalProperty(kvp.Key, MapRepresentation.Create(new OptionalProperty(JsonPropertyNames.Value, kvp.Value)))).ToArray(); var argMembers = new OptionalProperty(JsonPropertyNames.Members, MapRepresentation.Create(props)); var args = new List <OptionalProperty> { argMembers }; var persistLink = LinkRepresentation.Create(OidStrategy, new ObjectsRelType(RelValues.Persist, new UriMtHelper(OidStrategy, req, objectContext.Target.Specification)) { Method = RelMethod.Post }, Flags, new OptionalProperty(JsonPropertyNames.Arguments, MapRepresentation.Create(args.ToArray()))); tempLinks.Add(persistLink); } var properties = visiblePropertiesAndCollections.Select(p => InlineMemberAbstractRepresentation.Create(OidStrategy, req, p, Flags, false)).ToArray(); ActionContextFacade[] visibleActions; if (IsProtoPersistent(objectContext.Target)) { visibleActions = new ActionContextFacade[] { }; } else if (IsForm(objectContext.Target)) { visibleActions = objectContext.VisibleActions.Where(af => af.Action.ParameterCount == 0).ToArray(); } else { visibleActions = FilterLocallyContributedActions(objectContext.VisibleActions, visiblePropertiesAndCollections.Where(p => p.Property.IsCollection).ToArray()); } var actions = visibleActions.Select(a => InlineActionRepresentation.Create(OidStrategy, req, a, Flags)).ToArray(); var allMembers = properties.Union(actions); Members = RestUtils.CreateMap(allMembers.ToDictionary(m => m.Id, m => (object)m)); }
public virtual MapRepresentation GetParameters() => RestUtils.CreateMap(parameterList.ToDictionary(p => p.Name, p => (object)p));
private void SetActions(IOidStrategy oidStrategy, ObjectContextFacade objectContext, HttpRequest req, RestControlFlags flags) { var actions = objectContext.VisibleActions.Select(a => InlineActionRepresentation.Create(oidStrategy, req, a, flags)).ToArray(); Members = RestUtils.CreateMap(actions.ToDictionary(m => m.Id, m => (object)m)); }
public MapRepresentation GetParameters() { return(RestUtils.CreateMap(parameterList.ToDictionary(p => p.Name, p => (object)p))); }