< Summary

Information
Class: Elsa.Bpmn.Interchange.Endpoints.Bpmn.Document.Get.Get
Assembly: Elsa.Bpmn.Interchange
File(s): /home/runner/work/elsa-core/elsa-core/src/modules/Elsa.Bpmn.Interchange/Endpoints/Bpmn/Document/Get/Endpoint.cs
Line coverage
95%
Covered lines: 22
Uncovered lines: 1
Coverable lines: 23
Total lines: 67
Line coverage: 95.6%
Branch coverage
100%
Covered branches: 2
Total branches: 2
Branch coverage: 100%
Method coverage

Feature is only available for sponsors

Upgrade to PRO version

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity Line coverage
.ctor(...)100%11100%
Configure()100%11100%
HandleAsync()100%22100%
<HandleAsync()100%11100%

File(s)

/home/runner/work/elsa-core/elsa-core/src/modules/Elsa.Bpmn.Interchange/Endpoints/Bpmn/Document/Get/Endpoint.cs

#LineLine coverage
 1using System.Net.Mime;
 2using System.Text.Json;
 3using Elsa.Authorization;
 4using Bpmn.Model;
 5using Elsa.Abstractions;
 6using Elsa.Bpmn.Interchange.Endpoints.Bpmn;
 7using Elsa.Bpmn.Interchange.Services;
 8using Elsa.Common.Models;
 9using Elsa.Workflows.Management;
 10using Elsa.Workflows.Models;
 11using JetBrains.Annotations;
 12using Microsoft.AspNetCore.Http;
 13
 14namespace Elsa.Bpmn.Interchange.Endpoints.Bpmn.Document.Get;
 15
 16/// <summary>
 17/// Reads a stored workflow definition's BPMN source back out as the library's own <c>bpmnDefinitions</c> JSON
 18/// document — the shape <c>Endpoints.Bpmn.Document.Put.Put</c> accepts back — rather than as <c>.bpmn</c> XML.
 19/// </summary>
 20/// <remarks>
 21/// A thin wrapper over <see cref="BpmnInterchangeDocumentService.ReadDocument"/>. Studio never holds the whole
 22/// document as JSON; the round trip this endpoint and <c>Put</c> exist for is what lets an edit made there — a
 23/// binding (W11), a moved shape (W14) — be written back without a client-side reimplementation of
 24/// <c>BpmnXmlWriter</c>. Same missing/stale-source refusals as <c>Export</c>; see
 25/// <see cref="BpmnInterchangeDocumentService"/>'s remarks for what each means.
 26/// <para>
 27/// The response body is written with <see cref="BpmnDocumentJsonOptions"/>, not through FastEndpoints' configured
 28/// serializer — see that type's remarks for why the two disagree on shape.
 29/// </para>
 30/// </remarks>
 31[UsedImplicitly]
 8032internal sealed class Get(IWorkflowDefinitionStore store, BpmnInterchangeDocumentService documentService) : ElsaEndpoint
 33{
 34    /// <inheritdoc />
 35    public override void Configure()
 36    {
 4637        Get("bpmn/definitions/{definitionId}/document");
 4638        RequirePermission(Elsa.Bpmn.Interchange.Permissions.BpmnPermissions.Definitions, CoreVerbs.View);
 4639    }
 40
 41    /// <inheritdoc />
 42    public override async Task HandleAsync(CancellationToken cancellationToken)
 43    {
 3444        var definitionId = Route<string>("definitionId")!;
 3445        var filter = WorkflowDefinitionHandle.ByDefinitionId(definitionId, VersionOptions.Latest).ToFilter();
 3446        var definition = await store.FindAsync(filter, cancellationToken);
 47
 3448        if (definition == null)
 49        {
 150            await Send.NotFoundAsync(cancellationToken);
 151            return;
 52        }
 53
 3354        await BpmnExportErrorResponses.RunAsync(
 3355            async () =>
 3356            {
 3357                var document = documentService.ReadDocument(definition);
 3158                var json = JsonSerializer.Serialize(document, BpmnDocumentJsonOptions.Value);
 3159                HttpContext.Response.Headers.ETag = BpmnDocumentETag.From(definition);
 3160                await Send.StringAsync(json, contentType: MediaTypeNames.Application.Json, cancellation: cancellationTok
 3161            },
 3362            HttpContext.Response,
 063            message => AddError(message),
 3364            Send.ErrorsAsync,
 3365            cancellationToken);
 3466    }
 67}