Esempio n. 1
0
 protected AbstractActionRepresentationStrategy(IOidStrategy oidStrategy, HttpRequest req, ActionContextFacade actionContext, RestControlFlags flags)
     : base(oidStrategy, flags)
 {
     Req           = req;
     ActionContext = actionContext;
     self          = new MemberRelType(RelValues.Self, new UriMtHelper(oidStrategy, req, actionContext));
 }
Esempio n. 2
0
 public ActionRepresentationStrategy(IOidStrategy oidStrategy, HttpRequestMessage req, ActionContextFacade actionContext, RestControlFlags flags)
     : base(oidStrategy, flags)
 {
     this.req           = req;
     this.actionContext = actionContext;
     self          = new MemberRelType(RelValues.Self, new UriMtHelper(oidStrategy, req, actionContext));
     parameterList = GetParameterList();
 }
Esempio n. 3
0
 public RestSnapshot(IOidStrategy oidStrategy, ActionContextFacade actionContext, HttpRequestMessage req, RestControlFlags flags)
     : this(oidStrategy, actionContext, req, true)
 {
     populator = () => {
         representation = ActionRepresentation.Create(oidStrategy, req, actionContext, flags);
         SetHeaders();
     };
 }
Esempio n. 4
0
        public ActionContextFacade ToActionContextFacade(IFrameworkFacade facade)
        {
            var ac = new ActionContextFacade {
                Action            = new ActionFacade(Action, Target, facade),
                VisibleParameters = VisibleParameters.Select(p => p.ToParameterContextFacade(facade)).ToArray()
            };

            return(ToContextFacade(ac, facade));
        }
        public ActionContextFacade ToActionContextFacade(IFrameworkFacade facade, INakedObjectsFramework framework)
        {
            var ac = new ActionContextFacade {
                Action            = new ActionFacade(Action, facade, framework, OverloadedUniqueId ?? ""),
                VisibleParameters = VisibleParameters.Select(p => p.ToParameterContextFacade(facade, framework)).ToArray()
            };

            return(ToContextFacade(ac, facade, framework));
        }
Esempio n. 6
0
        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);
        }
        public UriMtHelper(IOidStrategy oidStrategy, HttpRequestMessage req, ActionContextFacade actionContext)
            : this(oidStrategy, req)
        {
            action       = actionContext.Action;
            objectFacade = actionContext.Target;
            spec         = objectFacade.Specification;
            IOidTranslation oid = oidStrategy.FrameworkFacade.OidTranslator.GetOidTranslation(objectFacade);

            cachedId   = oid.InstanceId;
            CachedType = oid.DomainType;
        }
Esempio n. 8
0
        public static LinkRepresentation CreateTableRowValueLink(IObjectFacade no,
                                                                 ActionContextFacade actionContext,
                                                                 IOidStrategy oidStrategy,
                                                                 HttpRequestMessage req,
                                                                 RestControlFlags flags)
        {
            var           columns = actionContext?.Action?.TableViewData?.Item2;
            var           helper  = new UriMtHelper(oidStrategy, req, no);
            ObjectRelType rt      = no.Specification.IsService ? new ServiceRelType(helper) : new ObjectRelType(RelValues.Element, helper);

            return(CreateTableRowValueLink(no, columns, rt, oidStrategy, req, flags));
        }
Esempio n. 9
0
        public UriMtHelper(IOidStrategy oidStrategy, HttpRequestMessage req, ActionContextFacade actionContext)
            : this(oidStrategy, req)
        {
            action       = actionContext.Action;
            objectFacade = actionContext.Target;
            spec         = objectFacade.Specification;
            if (objectFacade.Specification.IsParseable)
            {
                throw new ArgumentException($"Cannot build URI  for parseable specification : {objectFacade.Specification.FullName}");
            }
            IOidTranslation oid = oidStrategy.FrameworkFacade.OidTranslator.GetOidTranslation(objectFacade);

            cachedId   = oid.InstanceId;
            CachedType = oid.DomainType;
        }
        // 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);
        }
Esempio n. 11
0
        protected ListRepresentation(IOidStrategy oidStrategy, IObjectFacade list, HttpRequestMessage req, RestControlFlags flags, ActionContextFacade actionContext)
            : base(oidStrategy, flags)
        {
            Value = list.ToEnumerable().Select(no => CreateObjectLink(oidStrategy, req, no)).ToArray();

            SetLinks(req, actionContext);
            SetExtensions();
            SetHeader(false);
        }
        private static ParameterContextFacade GetParameterByName(this IFrameworkFacade frameworkFacade, ActionContextFacade action, string parmName)
        {
            var parm = action.VisibleParameters.Single(p => p.Id == parmName);

            parm.Target = action.Target;
            return(parm);
        }
        public static InlineActionRepresentation Create(IOidStrategy oidStrategy, HttpRequestMessage req, ActionContextFacade actionContext, RestControlFlags flags)
        {
            IConsentFacade consent = actionContext.Action.IsUsable(actionContext.Target);

            var strategy  = AbstractActionRepresentationStrategy.GetStrategy(true, oidStrategy, req, actionContext, flags);
            var optionals = new List <OptionalProperty>();

            if (consent.IsVetoed)
            {
                optionals.Add(new OptionalProperty(JsonPropertyNames.DisabledReason, consent.Reason));
            }

            if (strategy.ShowParameters())
            {
                optionals.Add(new OptionalProperty(JsonPropertyNames.Parameters, strategy.GetParameters()));
            }

            if (optionals.Any())
            {
                return(CreateWithOptionals <InlineActionRepresentation>(new object[] { oidStrategy, strategy }, optionals));
            }

            return(new InlineActionRepresentation(oidStrategy, strategy));
        }
        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));
        }
 private LinkRepresentation CreateTableRowValueLink(IOidStrategy oidStrategy, HttpRequest req, IObjectFacade no, ActionContextFacade actionContext) => RestUtils.CreateTableRowValueLink(no, actionContext, OidStrategy, req, Flags);
 public ActionMemberRepresentationStrategy(IOidStrategy oidStrategy, HttpRequest req, ActionContextFacade actionContext, RestControlFlags flags) : base(oidStrategy, req, actionContext, flags)
 {
 }
 private bool IsVisibleAndUsable(ActionContextFacade actionContextFacade)
 {
     return(actionContextFacade.Action.IsVisible(actionContextFacade.Target) &&
            actionContextFacade.Action.IsUsable(actionContextFacade.Target).IsAllowed);
 }
 private static IObjectFacade Page(ObjectContextFacade objectContext, RestControlFlags flags, ActionContextFacade actionContext) => objectContext.Target.Page(flags.Page, PageSize(flags, actionContext), true);
Esempio n. 19
0
 private static bool IsVisibleAndUsable(ActionContextFacade actionContextFacade) =>
 actionContextFacade.Action.IsVisible(actionContextFacade.Target) &&
 actionContextFacade.Action.IsUsable(actionContextFacade.Target).IsAllowed;
Esempio n. 20
0
 private static bool InlineDetails(ActionContextFacade actionContext, RestControlFlags flags) => flags.InlineDetailsInActionMemberRepresentations || actionContext.Action.RenderEagerly;
 private static int PageSize(RestControlFlags flags, ActionContextFacade actionContext) => actionContext.Action.PageSize > 0 ? actionContext.Action.PageSize : flags.PageSize;
Esempio n. 22
0
        public static ActionRepresentation Create(IOidStrategy oidStrategy, HttpRequestMessage req, ActionContextFacade actionContext, RestControlFlags flags)
        {
            var actionRepresentationStrategy = AbstractActionRepresentationStrategy.GetStrategy(false, oidStrategy, req, actionContext, flags);

            return(new ActionRepresentation(oidStrategy, actionRepresentationStrategy));
        }
 protected override LinkRepresentation CreateObjectLink(IOidStrategy oidStrategy, HttpRequest req, IObjectFacade no, ActionContextFacade actionContext = null) => !Flags.InlineCollectionItems ? base.CreateObjectLink(oidStrategy, req, no, actionContext) : CreateTableRowValueLink(oidStrategy, req, no, actionContext);
Esempio n. 24
0
 private void SetLinks(HttpRequestMessage req, ActionContextFacade actionContext)
 {
     SetLinks(req, actionContext.ElementSpecification);
 }
        public static InlineActionRepresentation Create(IOidStrategy oidStrategy, HttpRequestMessage req, ActionContextFacade actionContext, RestControlFlags flags)
        {
            IConsentFacade consent = actionContext.Action.IsUsable(actionContext.Target);

            var actionRepresentationStrategy = new ActionRepresentationStrategy(oidStrategy, req, actionContext, flags);

            if (consent.IsVetoed)
            {
                var optionals = new List <OptionalProperty> {
                    new OptionalProperty(JsonPropertyNames.DisabledReason, consent.Reason)
                };
                return(CreateWithOptionals <InlineActionRepresentation>(new object[] { oidStrategy, actionRepresentationStrategy }, optionals));
            }

            return(new InlineActionRepresentation(oidStrategy, actionRepresentationStrategy));
        }
 protected PagedListRepresentation(IOidStrategy oidStrategy, ObjectContextFacade objectContext, HttpRequest req, RestControlFlags flags, ActionContextFacade actionContext)
     : base(oidStrategy, Page(objectContext, flags, actionContext), req, flags, actionContext)
 {
     SetPagination(objectContext.Target, flags, actionContext);
     SetActions(oidStrategy, objectContext, req, flags);
 }
        protected ListRepresentation(IOidStrategy oidStrategy, ObjectContextFacade objectContext, HttpRequestMessage req, RestControlFlags flags, ActionContextFacade actionContext)
            : base(oidStrategy, flags)
        {
            IObjectFacade list;

            if (flags.PageSize > 0 && objectContext.Target.Count() > flags.PageSize)
            {
                warnings.Add(string.Format("Result contains more than {0} objects only returning the first {0}", flags.PageSize));
                list = objectContext.Target.Page(1, flags.PageSize);
            }
            else
            {
                list = objectContext.Target;
            }

            Value = list.ToEnumerable().Select(no => CreateObjectLink(oidStrategy, req, no)).ToArray();

            SetLinks(req, actionContext);
            SetExtensions();
            SetHeader(false);
        }
Esempio n. 28
0
        public static ParameterRepresentation Create(IOidStrategy oidStrategy, HttpRequestMessage req, IObjectFacade objectFacade, IAssociationFacade assoc, ActionContextFacade actionContext, RestControlFlags flags)
        {
            var optionals = new List <OptionalProperty>();

            if (assoc.IsChoicesEnabled != Choices.NotEnabled && !assoc.GetChoicesParameters().Any())
            {
                IObjectFacade[] choices      = assoc.GetChoices(objectFacade, null);
                object[]        choicesArray = choices.Select(c => RestUtils.GetChoiceValue(oidStrategy, req, c, assoc, flags)).ToArray();
                optionals.Add(new OptionalProperty(JsonPropertyNames.Choices, choicesArray));
            }

            var adapter = new FieldFacadeAdapter(assoc);

            IObjectFacade defaultNakedObject = assoc.GetValue(objectFacade);

            if (defaultNakedObject != null)
            {
                string title        = defaultNakedObject.TitleString;
                object value        = RestUtils.ObjectToPredefinedType(defaultNakedObject.Object, true);
                var    isValue      = defaultNakedObject.Specification.IsParseable || (defaultNakedObject.Specification.IsCollection && defaultNakedObject.ElementSpecification.IsParseable);
                object defaultValue = isValue ? value : CreateDefaultLinks(oidStrategy, req, adapter, actionContext.Action, defaultNakedObject, title, flags);

                optionals.Add(new OptionalProperty(JsonPropertyNames.Default, defaultValue));
            }

            if (optionals.Count == 0)
            {
                return(new ParameterRepresentation(oidStrategy, req, objectFacade, adapter, flags));
            }
            return(CreateWithOptionals <ParameterRepresentation>(new object[] { oidStrategy, req, objectFacade, adapter, flags }, optionals));
        }
Esempio n. 29
0
        public static AbstractActionRepresentationStrategy GetStrategy(bool inline, IOidStrategy oidStrategy, HttpRequest req, ActionContextFacade actionContext, RestControlFlags flags)
        {
            AbstractActionRepresentationStrategy strategy;

            if (inline)
            {
                if (actionContext.Target.IsViewModelEditView)
                {
                    strategy = new FormActionMemberRepresentationStrategy(oidStrategy, req, actionContext, flags);
                }
                else if (InlineDetails(actionContext, flags))
                {
                    strategy = new ActionMemberWithDetailsRepresentationStrategy(oidStrategy, req, actionContext, flags);
                }
                else
                {
                    strategy = new ActionMemberRepresentationStrategy(oidStrategy, req, actionContext, flags);
                }
            }
            else
            {
                if (actionContext.Target.IsViewModelEditView)
                {
                    strategy = new FormActionRepresentationStrategy(oidStrategy, req, actionContext, flags);
                }
                else
                {
                    strategy = new ActionRepresentationStrategy(oidStrategy, req, actionContext, flags);
                }
            }

            strategy.CreateParameters();

            return(strategy);
        }
Esempio n. 30
0
        protected virtual LinkRepresentation CreateObjectLink(IOidStrategy oidStrategy, HttpRequest req, IObjectFacade no, ActionContextFacade actionContext = null)
        {
            var helper = new UriMtHelper(oidStrategy, req, no);
            var rt     = no.Specification.IsService ? new ServiceRelType(helper) : new ObjectRelType(RelValues.Element, helper);

            return(LinkRepresentation.Create(oidStrategy, rt, Flags, new OptionalProperty(JsonPropertyNames.Title, RestUtils.SafeGetTitle(no))));
        }