コード例 #1
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();
 }
コード例 #2
0
 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);
 }
コード例 #3
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);
        }
コード例 #4
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, actionContext)).ToArray();

            SetLinks(req, actionContext);
            SetExtensions(oidStrategy, actionContext);
            SetHeader(false);
        }
コード例 #5
0
        private void SetExtensions(IOidStrategy oidStrategy, ActionContextFacade actionContext) {
            var exts = new Dictionary<string, object> {
                {
                    JsonPropertyNames.ElementType, RestUtils.SpecToTypeAndFormatString(actionContext.ElementSpecification, oidStrategy, false).Item1
                }
            };

            Extensions = RestUtils.CreateMap(exts);
        }
コード例 #6
0
 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;
 }
コード例 #7
0
        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);
        }
コード例 #8
0
        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);
        }
        // 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);
        }
        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 static IObjectFacade Page(ObjectContextFacade objectContext, RestControlFlags flags, ActionContextFacade actionContext) {
     return objectContext.Target.Page(flags.Page, PageSize(flags, actionContext), true);
 }
コード例 #12
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);
 }
コード例 #13
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);
        }
 private static int PageSize(RestControlFlags flags, ActionContextFacade actionContext) {
     return actionContext.Action.PageSize > 0 ? actionContext.Action.PageSize : flags.PageSize;
 }
 private LinkRepresentation CreateTableRowValueLink(IOidStrategy oidStrategy, HttpRequestMessage req, IObjectFacade no, ActionContextFacade actionContext) {
     return RestUtils.CreateTableRowValueLink(no, actionContext, OidStrategy, req, Flags);
 }
コード例 #16
0
 private void SetLinks(HttpRequestMessage req, ActionContextFacade actionContext) {
     SetLinks(req, actionContext.ElementSpecification);
 }
 protected AbstractActionRepresentationStrategy(IOidStrategy oidStrategy, HttpRequestMessage req, ActionContextFacade actionContext, RestControlFlags flags)
     : base(oidStrategy, flags) {
     Req = req;
     ActionContext = actionContext;
     self = new MemberRelType(RelValues.Self, new UriMtHelper(oidStrategy, req, actionContext));
 }
コード例 #18
0
 public static ActionRepresentation Create(IOidStrategy oidStrategy, HttpRequestMessage req, ActionContextFacade actionContext, RestControlFlags flags) {
     return new ActionRepresentation(oidStrategy, new ActionRepresentationStrategy(oidStrategy ,req, actionContext, flags));
 }
 private static bool InlineDetails(ActionContextFacade actionContext, RestControlFlags flags) {
     return flags.InlineDetailsInActionMemberRepresentations || actionContext.Action.RenderEagerly;
 }
        public static AbstractActionRepresentationStrategy GetStrategy(bool inline, IOidStrategy oidStrategy, HttpRequestMessage 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;
        }
コード例 #21
0
        private void SetMembers(ObjectContextFacade objectContext, HttpRequestMessage req, List<LinkRepresentation> tempLinks) {
            PropertyContextFacade[] visiblePropertiesAndCollections = objectContext.VisibleProperties;

            if (!Flags.BlobsClobs) {
                // filter any blobs and clobs 
                visiblePropertiesAndCollections = visiblePropertiesAndCollections.Where(vp => !RestUtils.IsBlobOrClob(vp.Specification)).ToArray();
            }

            PropertyContextFacade[] visibleProperties = visiblePropertiesAndCollections.Where(p => !p.Property.IsCollection).ToArray();

            if (!IsProtoPersistent(objectContext.Target) && !IsForm(objectContext.Target) && 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();

                var helper = GetHelper(OidStrategy, req, objectContext);

                LinkRepresentation 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)) {
                KeyValuePair<string, object>[] 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();
                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(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);
            }

            InlineMemberAbstractRepresentation[] 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());
            }

            InlineActionRepresentation[] actions = visibleActions.Select(a => InlineActionRepresentation.Create(OidStrategy, req, a, Flags)).ToArray();
          
            IEnumerable<InlineMemberAbstractRepresentation> allMembers = properties.Union(actions);

            Members = RestUtils.CreateMap(allMembers.ToDictionary(m => m.Id, m => (object) m));
        }
コード例 #22
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();
     };
 }
 protected override LinkRepresentation CreateObjectLink(IOidStrategy oidStrategy, HttpRequestMessage req, IObjectFacade no, ActionContextFacade actionContext = null) {
     return !Flags.InlineCollectionItems ? base.CreateObjectLink(oidStrategy, req, no, actionContext) : CreateTableRowValueLink(oidStrategy, req, no, actionContext);
 }
コード例 #24
0
        protected virtual LinkRepresentation CreateObjectLink(IOidStrategy oidStrategy, HttpRequestMessage req, IObjectFacade no, ActionContextFacade actionContext = null) {
            var helper = new UriMtHelper(oidStrategy, req, no);
            ObjectRelType 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)));
        }
コード例 #25
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;
 }
コード例 #26
0
 protected PagedListRepresentation(IOidStrategy oidStrategy, ObjectContextFacade objectContext, HttpRequestMessage req, RestControlFlags flags, ActionContextFacade actionContext)
     : base(oidStrategy, Page(objectContext, flags), req, flags, actionContext) {
   
     SetPagination(objectContext.Target, flags);
 }
        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);
        }
 public FormActionMemberRepresentationStrategy(IOidStrategy oidStrategy, HttpRequestMessage req, ActionContextFacade actionContext, RestControlFlags flags)
     : base(oidStrategy, req, actionContext, flags) {}
コード例 #29
0
 private ActionContextFacade[] FilterLocallyContributedActions(ActionContextFacade[] actions, PropertyContextFacade[] collections) {
     var lcas = collections.SelectMany(c => c.Target.Specification.GetLocallyContributedActions(c.Property.ElementSpecification, c.Property.Id));
     return actions.Where(a => !lcas.Select(lca => lca.Id).Contains(a.Id)).ToArray();
 }