/// <inheritdoc/>
        public HalDocument Map(ContentSummaries resource, ContentSummariesResponseMappingContext context)
        {
            IEnumerable <HalDocument> mappedSummaries = resource.Summaries.Select(x => this.contentSummaryMapper.Map(x, context));
            HalDocument response = this.halDocumentFactory.CreateHalDocumentFrom(new { Summaries = mappedSummaries.ToArray() });

            response.ResolveAndAddByOwnerAndRelationType(
                this.linkResolver,
                resource,
                Constants.LinkRelations.Self,
                (Constants.ParameterNames.TenantId, context.TenantId),
                (Constants.ParameterNames.Slug, context.Slug),
                (Constants.ParameterNames.Limit, context.Limit),
                (Constants.ParameterNames.ContinuationToken, context.ContinuationToken));

            if (!string.IsNullOrEmpty(resource.ContinuationToken))
            {
                response.ResolveAndAddByOwnerAndRelationType(
                    this.linkResolver,
                    resource,
                    Constants.LinkRelations.Next,
                    (Constants.ParameterNames.TenantId, context.TenantId),
                    (Constants.ParameterNames.Slug, context.Slug),
                    (Constants.ParameterNames.Limit, context.Limit),
                    (Constants.ParameterNames.ContinuationToken, resource.ContinuationToken));
            }

            return(response);
        }
Beispiel #2
0
        public async Task <OpenApiResult> ListPets(int limit = 10, string?continuationToken = null)
        {
            int skip = ParseContinuationToken(continuationToken);

            PetResource[] pets = this.pets.Skip(skip).Take(limit).ToArray();

            string?     nextContinuationToken = (skip + limit < this.pets.Count) ? BuildContinuationToken(limit + skip) : null;
            HalDocument response = await this.petListMapper.MapAsync(
                new PetListResource(pets)
            {
                TotalCount = this.pets.Count,
                PageSize   = limit,
                CurrentContinuationToken = continuationToken,
                NextContinuationToken    = nextContinuationToken,
            }).ConfigureAwait(false);

            OpenApiResult result = this.OkResult(response, "application/hal+json");

            // We also add the next page link to the header, just to demonstrate that it's possible
            // to use WebLink items in this way.
            WebLink nextLink = response.GetLinksForRelation("next").FirstOrDefault();

            if (nextLink != default)
            {
                result.Results.Add("x-next", nextLink.Href);
            }

            result.AddAuditData(("skip", skip), ("limit", limit));

            return(result);
        }
Beispiel #3
0
        public async Task <OpenApiResult> GetContentHistory(string tenantId, string slug, int?limit, string continuationToken, string ifNoneMatch)
        {
            IContentStore contentStore = await this.contentStoreFactory.GetContentStoreForTenantAsync(tenantId).ConfigureAwait(false);

            ContentSummaries result = await contentStore.GetContentSummariesAsync(slug, limit ?? 20, continuationToken).ConfigureAwait(false);

            string resultEtag = EtagHelper.BuildEtag(nameof(ContentSummary), result.Summaries.Select(x => x.ETag).ToArray());

            // If the etag in the result matches ifNoneMatch then we return 304 Not Modified
            if (EtagHelper.IsMatch(ifNoneMatch, resultEtag))
            {
                return(this.NotModifiedResult());
            }

            var mappingContext = new ContentSummariesResponseMappingContext
            {
                ContinuationToken = continuationToken,
                Limit             = limit,
                Slug     = slug,
                TenantId = tenantId,
            };

            HalDocument resultDocument = this.contentSummariesMapper.Map(result, mappingContext);

            OpenApiResult response = this.OkResult(resultDocument);

            response.Results.Add(HeaderNames.ETag, resultEtag);

            return(response);
        }
        public async Task <OpenApiResult> GetNotificationsForUserAsync(
            IOpenApiContext context,
            string userId,
            string?sinceNotificationId,
            int?maxItems,
            string?continuationToken)
        {
            // We can guarantee tenant Id is available because it's part of the Uri.
            ITenant tenant = await this.marainServicesTenancy.GetRequestingTenantAsync(context.CurrentTenantId !).ConfigureAwait(false);

            IUserNotificationStore userNotificationStore =
                await this.userNotificationStoreFactory.GetUserNotificationStoreForTenantAsync(tenant).ConfigureAwait(false);

            maxItems ??= 50;

            GetNotificationsResult results = await this.GetNotificationsAsync(
                userId,
                sinceNotificationId,
                maxItems.Value,
                continuationToken,
                userNotificationStore).ConfigureAwait(false);

            await this.EnsureAllNotificationsMarkedAsDelivered(context, results).ConfigureAwait(false);

            HalDocument result = await this.userNotificationsMapper.MapAsync(
                results,
                new UserNotificationsMappingContext(context, userId, sinceNotificationId, maxItems.Value, continuationToken)).ConfigureAwait(false);

            return(this.OkResult(result));
        }
Beispiel #5
0
        public void GivenIAddAnEmbeddedResourceToTheHalDocumentT()
        {
            HalDocument         document           = this.scenarioContext.Get <HalDocument>();
            IHalDocumentFactory halDocumentFactory = ContainerBindings.GetServiceProvider(this.scenarioContext).GetService <IHalDocumentFactory>();

            document.AddEmbeddedResource("somerel", halDocumentFactory.CreateHalDocument());
        }
Beispiel #6
0
        public void GivenIHaveCreatedAnInstanceOfHalDocumentFromTheDomainClass()
        {
            IHalDocumentFactory halDocumentFactory = ContainerBindings.GetServiceProvider(this.scenarioContext).GetService <IHalDocumentFactory>();
            HalDocument         halDocument        = halDocumentFactory.CreateHalDocumentFrom(this.scenarioContext.Get <TestDomainClass>());

            this.scenarioContext.Set(halDocument);
        }
Beispiel #7
0
        public async Task <OpenApiResult> GetContentSummary(IOpenApiContext context, string slug, string contentId, string ifNoneMatch)
        {
            IContentStore contentStore = await this.contentStoreFactory.GetContentStoreForTenantAsync(context.CurrentTenantId).ConfigureAwait(false);

            ContentSummary result = await contentStore.GetContentSummaryAsync(contentId, slug).ConfigureAwait(false);

            string etag = EtagHelper.BuildEtag(nameof(ContentSummary), result.ETag);

            // If the etag in the result matches ifNoneMatch then we return 304 Not Modified
            if (EtagHelper.IsMatch(ifNoneMatch, etag))
            {
                return(this.NotModifiedResult());
            }

            HalDocument resultDocument = this.contentSummaryMapper.Map(result, new ResponseMappingContext {
                TenantId = context.CurrentTenantId
            });

            OpenApiResult response = this.OkResult(resultDocument);

            response.Results.Add(HeaderNames.ETag, etag);

            // Since content is immutable we can allow clients to cache it indefinitely.
            response.Results.Add(HeaderNames.CacheControl, Constants.CacheControlHeaderOptions.NeverExpire);

            return(response);
        }
Beispiel #8
0
        /// <inheritdoc/>
        public HalDocument Map(ContentSummary resource, ResponseMappingContext context)
        {
            HalDocument response = this.halDocumentFactory.CreateHalDocumentFrom(resource);

            response.ResolveAndAddByOwnerAndRelationType(
                this.linkResolver,
                resource,
                Constants.LinkRelations.Self,
                (Constants.ParameterNames.TenantId, context.TenantId),
                (Constants.ParameterNames.Slug, resource.Slug),
                (Constants.ParameterNames.ContentId, resource.Id));

            response.ResolveAndAddByOwnerAndRelationType(
                this.linkResolver,
                resource,
                Constants.LinkRelations.Content,
                (Constants.ParameterNames.TenantId, context.TenantId),
                (Constants.ParameterNames.Slug, resource.Slug),
                (Constants.ParameterNames.ContentId, resource.Id));

            response.ResolveAndAddByOwnerAndRelationType(
                this.linkResolver,
                resource,
                Constants.LinkRelations.History,
                (Constants.ParameterNames.TenantId, context.TenantId),
                (Constants.ParameterNames.Slug, resource.Slug));

            return(response);
        }
Beispiel #9
0
        /// <inheritdoc/>
        public HalDocument CreateHalDocumentFrom <T>(T entity)
        {
            HalDocument halDocument = this.serviceProvider.GetService <HalDocument>();

            halDocument.SetProperties(entity);
            return(halDocument);
        }
        public async Task <OpenApiResult> GetNotificationAsync(
            IOpenApiContext context,
            string notificationId)
        {
            // We can guarantee tenant Id is available because it's part of the Uri.
            ITenant tenant = await this.marainServicesTenancy.GetRequestingTenantAsync(context.CurrentTenantId !).ConfigureAwait(false);

            IUserNotificationStore userNotificationStore =
                await this.userNotificationStoreFactory.GetUserNotificationStoreForTenantAsync(tenant).ConfigureAwait(false);

            UserNotification notifications;

            try
            {
                notifications = await userNotificationStore.GetByIdAsync(notificationId).ConfigureAwait(false);
            }
            catch (ArgumentException)
            {
                // This will happen if the supplied notification Id is invalid. Return a BadRequest response.
                throw new OpenApiBadRequestException("The supplied notificationId is not valid");
            }

            HalDocument response = await this.userNotificationMapper.MapAsync(notifications, context).ConfigureAwait(false);

            return(this.OkResult(response, "application/json"));
        }
        public async Task <OpenApiResult> GetWorkflowStateHistory(
            string tenantId,
            string workflowId,
            string stateName,
            string slug,
            int?limit,
            string continuationToken,
            string embed)
        {
            IContentStore contentStore = await this.contentStoreFactory.GetContentStoreForTenantAsync(tenantId).ConfigureAwait(false);

            ContentStates result = await contentStore.GetContentStatesForWorkflowAsync(slug, workflowId, stateName, limit ?? 20, continuationToken).ConfigureAwait(false);

            var mappingContext = new ContentStatesResponseMappingContext {
                TenantId = tenantId
            };

            if (embed == Constants.LinkRelations.ContentSummary)
            {
                mappingContext.ContentSummaries = await contentStore.GetContentSummariesForStatesAsync(result.States).ConfigureAwait(false);
            }

            HalDocument resultDocument = this.contentStatesMapper.Map(result, mappingContext);

            return(this.OkResult(resultDocument));
        }
        /// <inheritdoc/>
        public ValueTask <HalDocument> MapAsync(UserNotification resource, IOpenApiContext context)
        {
            // Note that we're hard coding "delivered" to true. This is because we're mapping the notification so we
            // can return it from a request to the API - which means that even if it hasn't been delivered on any other
            // channel, it's being delivered now on this one.
            HalDocument response = this.halDocumentFactory.CreateHalDocumentFrom(new
            {
                ContentType = "application/vnd.marain.usernotifications.apidelivery.notification",
                resource.UserId,
                resource.NotificationType,
                resource.Properties,
                resource.Timestamp,
                Delivered = true,
                Read      = resource.HasBeenReadOnAtLeastOneChannel(),
            });

            response.ResolveAndAddByOwnerAndRelationType(
                this.openApiWebLinkResolver,
                resource,
                "self",
                ("tenantId", context.CurrentTenantId),
                ("notificationId", resource.Id));

            if (resource.GetReadStatusForChannel(Constants.ApiDeliveryChannelId) != UserNotificationReadStatus.Read)
            {
                response.ResolveAndAddByOwnerAndRelationType(
                    this.openApiWebLinkResolver,
                    resource,
                    "mark-read",
                    ("tenantId", context.CurrentTenantId),
                    ("notificationId", resource.Id));
            }

            return(new ValueTask <HalDocument>(response));
        }
        /// <inheritdoc/>
        public ValueTask <HalDocument> MapAsync(ITenant input)
        {
            HalDocument response = this.halDocumentFactory.CreateHalDocumentFrom(input);

            response.ResolveAndAddByOwnerAndRelationType(this.linkResolver, input, "self", ("tenantId", input.Id));
            response.ResolveAndAddByOwnerAndRelationType(this.linkResolver, input, "children", ("tenantId", input.Id));

            return(new ValueTask <HalDocument>(response));
        }
        public async Task <OpenApiResult> GetChildrenAsync(
            string tenantId,
            int?maxItems,
            string continuationToken,
            IOpenApiContext context)
        {
            if (string.IsNullOrEmpty(tenantId))
            {
                throw new OpenApiBadRequestException("Bad request");
            }

            if (context is null)
            {
                throw new ArgumentNullException(nameof(context));
            }

            try
            {
                TenantCollectionResult result = await this.tenantStore.GetChildrenAsync(tenantId, maxItems ?? 20, continuationToken).ConfigureAwait(false);

                HalDocument document = await this.tenantCollectionResultMapper.MapAsync(result).ConfigureAwait(false);

                if (result.ContinuationToken != null)
                {
                    OpenApiWebLink link = maxItems.HasValue
                        ? this.linkResolver.ResolveByOperationIdAndRelationType(GetChildrenOperationId, "next", ("tenantId", tenantId), ("continuationToken", result.ContinuationToken), ("maxItems", maxItems))
                        : this.linkResolver.ResolveByOperationIdAndRelationType(GetChildrenOperationId, "next", ("tenantId", tenantId), ("continuationToken", result.ContinuationToken));
                    document.AddLink("next", link);
                }

                var values = new List <(string, object?)> {
                    ("tenantId", tenantId)
                };
                if (maxItems.HasValue)
                {
                    values.Add(("maxItems", maxItems));
                }

                if (!string.IsNullOrEmpty(continuationToken))
                {
                    values.Add(("continuationToken", continuationToken));
                }

                OpenApiWebLink selfLink = this.linkResolver.ResolveByOperationIdAndRelationType(GetChildrenOperationId, "self", values.ToArray());
                document.AddLink("self", selfLink);

                return(this.OkResult(document, "application/json"));
            }
            catch (TenantNotFoundException)
            {
                return(this.NotFoundResult());
            }
            catch (TenantConflictException)
            {
                return(this.ConflictResult());
            }
        }
Beispiel #15
0
        /// <inheritdoc/>
        public async ValueTask <HalDocument> MapAsync(GetNotificationsResult resource, UserNotificationsMappingContext context)
        {
            HalDocument response = this.halDocumentFactory.CreateHalDocumentFrom(new
            {
                ContentType = "application/vnd.marain.usernotifications.apidelivery.notificationslist",
            });

            HalDocument[] mappedItems =
                await Task.WhenAll(
                    resource.Results.Select(n => this.userNotificationMapper.MapAsync(n, context.OpenApiContext).AsTask())).ConfigureAwait(false);

            response.AddEmbeddedResources("items", mappedItems);

            foreach (HalDocument current in mappedItems)
            {
                response.AddLink("items", current.GetLinksForRelation("self").First());
            }

            response.ResolveAndAddByOwnerAndRelationType(
                this.openApiWebLinkResolver,
                resource,
                "self",
                ("tenantId", context.OpenApiContext.CurrentTenantId),
                ("userId", context.UserId),
                ("sinceNotificationId", context.SinceNotificationId),
                ("maxItems", context.MaxItems),
                ("continuationToken", context.ContinuationToken));

            if (!string.IsNullOrEmpty(resource.ContinuationToken))
            {
                response.ResolveAndAddByOwnerAndRelationType(
                    this.openApiWebLinkResolver,
                    resource,
                    "next",
                    ("tenantId", context.OpenApiContext.CurrentTenantId),
                    ("userId", context.UserId),
                    ("continuationToken", resource.ContinuationToken));
            }

            // If there are any results, we can also return a "newer" link, which can be used to request notifications
            // newer than those in this result set. If there aren't any, the user can just make the same request again
            // to get any newly created notifications.
            if (resource.Results.Length > 0)
            {
                response.ResolveAndAddByOwnerAndRelationType(
                    this.openApiWebLinkResolver,
                    resource,
                    "newer",
                    ("tenantId", context.OpenApiContext.CurrentTenantId),
                    ("userId", context.UserId),
                    ("sinceNotificationId", resource.Results[0].Id),
                    ("maxItems", context.MaxItems));
            }

            return(response);
        }
Beispiel #16
0
        public void WhenIDeserializeTheJSONBackToAHalDocument()
        {
            JObject previouslySerializedHalDocument = this.scenarioContext.Get <JObject>();

            IJsonSerializerSettingsProvider serializerSettingsProvider = ContainerBindings.GetServiceProvider(this.scenarioContext).GetRequiredService <IJsonSerializerSettingsProvider>();
            var         serializer = JsonSerializer.Create(serializerSettingsProvider.Instance);
            HalDocument result     = previouslySerializedHalDocument.ToObject <HalDocument>(serializer);

            this.scenarioContext.Set(result);
        }
Beispiel #17
0
        public void ThenThe_LinksCollectionShouldBePresentInTheDeserializedDocument()
        {
            HalDocument result = this.scenarioContext.Get <HalDocument>();

            Assert.AreEqual(1, result.Links.Count());

            WebLink link = result.GetLinksForRelation("somrel").Single();

            Assert.AreEqual("http://marain.io/examples/link", link.Href);
        }
Beispiel #18
0
        /// <inheritdoc/>
        public ValueTask <HalDocument> MapAsync(PetResource input)
        {
            HalDocument response = this.halDocumentFactory.CreateHalDocumentFrom(input);

            response.ResolveAndAddByOwnerAndRelationType(this.linkResolver, input, "self", ("petId", input.Id));
            response.ResolveAndAddByOwnerAndRelationType(this.linkResolver, input, "image", ("petId", input.Id));
            response.ResolveAndAddByOwnerAndRelationType(this.linkResolver, input, "pocoimage", ("petId", input.Id));

            return(new ValueTask <HalDocument>(response));
        }
Beispiel #19
0
        public void ThenThePropertiesOfTheOriginalDocumentShouldBePresentInTheDeserializedDocument()
        {
            HalDocument     result = this.scenarioContext.Get <HalDocument>();
            TestDomainClass dtoIn  = this.scenarioContext.Get <TestDomainClass>();

            Assert.IsTrue(result.TryGetProperties(out TestDomainClass? dtoOut));

            Assert.AreEqual(dtoIn.Property1, dtoOut !.Property1);
            Assert.AreEqual(dtoIn.Property2, dtoOut.Property2);
            Assert.AreEqual(dtoIn.Property3, dtoOut.Property3);
        }
Beispiel #20
0
        public void WhenISerializeItToJSON()
        {
            HalDocument document = this.scenarioContext.Get <HalDocument>();

            // We're actually going to serialize to a JObject as this will make it easier to
            // check the results.
            IJsonSerializerSettingsProvider serializerSettingsProvider = ContainerBindings.GetServiceProvider(this.scenarioContext).GetRequiredService <IJsonSerializerSettingsProvider>();
            var serializer = JsonSerializer.Create(serializerSettingsProvider.Instance);
            var result     = JObject.FromObject(document, serializer);

            this.scenarioContext.Set(result);
        }
Beispiel #21
0
        private async Task <OpenApiResult> MapAndReturnPetAsync(PetResource result)
        {
            if (result == null)
            {
                throw new OpenApiNotFoundException();
            }

            HalDocument response = await this.petMapper.MapAsync(result).ConfigureAwait(false);

            return(this
                   .OkResult(response, "application/hal+json")
                   .WithAuditData(("id", (object)result.Id)));
        }
Beispiel #22
0
        public async Task <OpenApiResult> CreatePets(PetResource body)
        {
            if (!this.pets.Any(p => p.Id == body.Id))
            {
                this.pets.Add(body);
            }

            HalDocument response = await this.petMapper.MapAsync(body).ConfigureAwait(false);

            WebLink location = response.GetLinksForRelation("self").First();

            return(this.CreatedResult(location.Href, response).WithAuditData(("id", (object)body.Id)));
        }
Beispiel #23
0
        /// <inheritdoc/>
        public HalDocument Map(ContentStates resource, ContentStatesResponseMappingContext context)
        {
            IEnumerable <HalDocument> mappedSummaries = resource.States.Select(state =>
            {
                var stateContext = new ContentStateResponseMappingContext
                {
                    TenantId       = context.TenantId,
                    ContentSummary = context.ContentSummaries?.FirstOrDefault(summary => summary.Id == state.ContentId && summary.Slug == state.Slug),
                };

                return(this.contentStateMapper.Map(state, stateContext));
            });

            HalDocument response = this.halDocumentFactory.CreateHalDocumentFrom(new { States = mappedSummaries.ToArray() });

            string linkMappingContext = string.IsNullOrEmpty(context.StateName)
                ? MappingContextWithoutState
                : MappingContextWithState;

            response.ResolveAndAddByOwnerAndRelationTypeAndContext(
                this.linkResolver,
                resource,
                Constants.LinkRelations.Self,
                linkMappingContext,
                (Constants.ParameterNames.TenantId, context.TenantId),
                (Constants.ParameterNames.WorkflowId, context.WorkflowId),
                (Constants.ParameterNames.StateName, context.StateName),
                (Constants.ParameterNames.Slug, context.Slug),
                (Constants.ParameterNames.Limit, context.Limit),
                (Constants.ParameterNames.ContinuationToken, context.ContinuationToken),
                (Constants.ParameterNames.Embed, context.Embed));

            if (!string.IsNullOrEmpty(resource.ContinuationToken))
            {
                response.ResolveAndAddByOwnerAndRelationTypeAndContext(
                    this.linkResolver,
                    resource,
                    Constants.LinkRelations.Next,
                    linkMappingContext,
                    (Constants.ParameterNames.TenantId, context.TenantId),
                    (Constants.ParameterNames.WorkflowId, context.WorkflowId),
                    (Constants.ParameterNames.StateName, context.StateName),
                    (Constants.ParameterNames.Slug, context.Slug),
                    (Constants.ParameterNames.Limit, context.Limit),
                    (Constants.ParameterNames.ContinuationToken, resource.ContinuationToken),
                    (Constants.ParameterNames.Embed, context.Embed));
            }

            return(response);
        }
Beispiel #24
0
        /// <inheritdoc/>
        public HalDocument Map(ContentState resource, ContentStateResponseMappingContext context)
        {
            HalDocument response = this.halDocumentFactory.CreateHalDocumentFrom(resource);

            response.ResolveAndAddByOwnerAndRelationType(
                this.linkResolver,
                resource,
                Constants.LinkRelations.Self,
                (Constants.ParameterNames.TenantId, context.TenantId),
                (Constants.ParameterNames.Slug, resource.Slug),
                (Constants.ParameterNames.ContentId, resource.Id),
                (Constants.ParameterNames.Embed, context.Embed));

            response.ResolveAndAddByOwnerAndRelationType(
                this.linkResolver,
                resource,
                Constants.LinkRelations.Content,
                (Constants.ParameterNames.TenantId, context.TenantId),
                (Constants.ParameterNames.Slug, resource.Slug),
                (Constants.ParameterNames.ContentId, resource.Id));

            response.ResolveAndAddByOwnerAndRelationType(
                this.linkResolver,
                resource,
                Constants.LinkRelations.ContentSummary,
                (Constants.ParameterNames.TenantId, context.TenantId),
                (Constants.ParameterNames.Slug, resource.Slug),
                (Constants.ParameterNames.ContentId, resource.Id));

            if (context.Content != null)
            {
                response.AddEmbeddedResource(
                    Constants.LinkRelations.Content,
                    this.contentResponseMapper.Map(context.Content, context));
            }
            else if (context.ContentSummary != null)
            {
                response.AddEmbeddedResource(
                    Constants.LinkRelations.ContentSummary,
                    this.contentSummaryResponseMapper.Map(context.ContentSummary, context));
            }

            return(response);
        }
Beispiel #25
0
        /// <inheritdoc/>
        public async ValueTask <HalDocument> MapAsync(PetListResource pets)
        {
            HalDocument response = this.halDocumentFactory.CreateHalDocumentFrom(pets);

            IEnumerable <Task <HalDocument> > petResourceTasks = pets.Pets.Select(pet => this.petResourceMapper.MapAsync(pet).AsTask());

            HalDocument[] petResources = await Task.WhenAll(petResourceTasks).ConfigureAwait(false);

            response.AddEmbeddedResources(PetsRelation, petResources);

            response.ResolveAndAddByOwnerAndRelationType(this.linkResolver, pets, "self", ("limit", pets.PageSize), ("continuationToken", pets.CurrentContinuationToken));
            response.ResolveAndAddByOwnerAndRelationType(this.linkResolver, pets, "create");

            if (!string.IsNullOrEmpty(pets.NextContinuationToken))
            {
                response.ResolveAndAddByOwnerAndRelationType(this.linkResolver, pets, "next", ("limit", pets.PageSize), ("continuationToken", pets.NextContinuationToken));
            }

            return(response);
        }
        /// <inheritdoc/>
        public ValueTask <HalDocument> MapAsync(SmsTemplate resource, IOpenApiContext context)
        {
            HalDocument response = this.halDocumentFactory.CreateHalDocumentFrom(
                new
            {
                resource.ContentType,
                resource.Body,
                resource.NotificationType,
                CommunicationType = CommunicationType.Sms,
            });

            response.ResolveAndAddByOwnerAndRelationType(
                this.openApiWebLinkResolver,
                resource,
                "self",
                ("tenantId", context.CurrentTenantId),
                ("notificationType", resource.NotificationType),
                ("communicationType", CommunicationType.Sms.ToString()));

            return(new ValueTask <HalDocument>(response));
        }
        public async Task <OpenApiResult> CreateContent(string tenantId, string slug, CreateContentRequest body)
        {
            IContentStore contentStore = await this.contentStoreFactory.GetContentStoreForTenantAsync(tenantId).ConfigureAwait(false);

            Content request = body.AsContent(slug);

            Content result = await contentStore.StoreContentAsync(request).ConfigureAwait(false);

            string etag = EtagHelper.BuildEtag(nameof(Content), result.ETag);

            HalDocument resultDocument = this.contentMapper.Map(result, new ResponseMappingContext {
                TenantId = tenantId
            });

            WebLink location = resultDocument.GetLinksForRelation("self").First();

            OpenApiResult response = this.CreatedResult(location.Href, resultDocument);

            response.Results.Add(HeaderNames.ETag, etag);

            return(response);
        }
Beispiel #28
0
        /// <inheritdoc/>
        public ValueTask <HalDocument> MapAsync(TenantCollectionResult input)
        {
            HalDocument response = this.halDocumentFactory.CreateHalDocument();

            foreach (string tenantId in input.Tenants)
            {
                string?parentId = tenantId.GetParentId();

                response.AddLink(
                    "getTenant",
                    this.linkResolver.ResolveByOperationIdAndRelationType(TenancyService.GetTenantOperationId, "self", ("tenantId", tenantId)));

                if (parentId != null)
                {
                    response.AddLink(
                        "deleteTenant",
                        this.linkResolver.ResolveByOperationIdAndRelationType(TenancyService.DeleteChildTenantOperationId, "delete", ("tenantId", parentId), ("childTenantId", tenantId)));
                }
            }

            return(new ValueTask <HalDocument>(response));
        }
        public async Task <OpenApiResult> GetWorkflowState(string tenantId, string slug, string workflowId, string embed)
        {
            IContentStore contentStore = await this.contentStoreFactory.GetContentStoreForTenantAsync(tenantId).ConfigureAwait(false);

            ContentState result = await contentStore.GetContentStateForWorkflowAsync(slug, workflowId).ConfigureAwait(false);

            var mappingContext = new ContentStateResponseMappingContext {
                TenantId = tenantId, Embed = embed
            };

            if (embed == Constants.LinkRelations.Content)
            {
                mappingContext.Content = await contentStore.GetContentAsync(result.ContentId, result.Slug).ConfigureAwait(false);
            }
            else if (embed == Constants.LinkRelations.ContentSummary)
            {
                mappingContext.ContentSummary = await contentStore.GetContentSummaryAsync(result.ContentId, result.Slug).ConfigureAwait(false);
            }

            HalDocument resultDocument = this.contentStateMapper.Map(result, mappingContext);

            return(this.OkResult(resultDocument));
        }
Beispiel #30
0
 private static void AddHalDocumentLinksToMap(HalDocument target, Dictionary <(string, OpenApiWebLink), List <HalDocument> > linkMap, bool recursive, bool unsafeChecking)