< Summary

Information
Class: Elsa.Bpmn.Interchange.Endpoints.Bpmn.Import.Import
Assembly: Elsa.Bpmn.Interchange
File(s): /home/runner/work/elsa-core/elsa-core/src/modules/Elsa.Bpmn.Interchange/Endpoints/Bpmn/Import/Endpoint.cs
Line coverage
85%
Covered lines: 23
Uncovered lines: 4
Coverable lines: 27
Total lines: 63
Line coverage: 85.1%
Branch coverage
75%
Covered branches: 3
Total branches: 4
Branch coverage: 75%
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()75%4485%

File(s)

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

#LineLine coverage
 1using Elsa.Authorization;
 2using Bpmn.Semantics;
 3using Elsa.Abstractions;
 4using Elsa.Bpmn.Interchange.Endpoints.Bpmn;
 5using Elsa.Bpmn.Interchange.Services;
 6using JetBrains.Annotations;
 7using Microsoft.AspNetCore.Http;
 8
 9namespace Elsa.Bpmn.Interchange.Endpoints.Bpmn.Import;
 10
 11/// <summary>
 12/// Reads a <c>.bpmn</c> document and persists it as a workflow definition whose root is the <see cref="Elsa.Bpmn.Activi
 13/// scope <c>BpmnWorkBinder</c> builds for it.
 14/// </summary>
 15/// <remarks>
 16/// A thin wrapper over <see cref="BpmnInterchangeDocumentService.ImportAsync"/>. Its remarks explain why capability
 17/// refusal is surfaced here rather than left to first execution, and why nothing beyond the source XML is persisted
 18/// alongside the bound activity graph.
 19/// </remarks>
 20[UsedImplicitly]
 8021internal sealed class Import(BpmnInterchangeDocumentService documentService) : ElsaEndpoint<Request>
 22{
 23    /// <inheritdoc />
 24    public override void Configure()
 25    {
 4626        Post("bpmn/import");
 4627        AllowFileUploads();
 4628        RequirePermission(Elsa.Bpmn.Interchange.Permissions.BpmnPermissions.Definitions, CoreVerbs.Write);
 4629    }
 30
 31    /// <inheritdoc />
 32    public override async Task HandleAsync(Request request, CancellationToken cancellationToken)
 33    {
 3434        if (Files.Count != 1)
 35        {
 036            AddError("Upload exactly one .bpmn file.");
 037            await Send.ErrorsAsync(StatusCodes.Status400BadRequest, cancellationToken);
 038            return;
 39        }
 40
 3441        var xml = await BpmnUploadedFileReader.ReadTextAsync(Files[0], cancellationToken);
 42
 3443        var result = await BpmnImportErrorResponses.RunAsync(
 3444            () => documentService.ImportAsync(xml, request.DefinitionId, request.Name, request.ProcessId, cancellationTo
 3445            HttpContext.Response,
 046            message => AddError(message),
 3447            Send.ErrorsAsync,
 3448            cancellationToken);
 49
 3450        if (result is null)
 451            return;
 52
 3053        var definition = result.ImportResult.WorkflowDefinition;
 54
 3055        await Send.OkAsync(new Response
 3056        {
 3057            Id = definition.Id,
 3058            DefinitionId = definition.DefinitionId,
 3059            Version = definition.Version,
 3060            Analysis = BpmnImportAnalysisModel.From(result.Analysis)
 3061        }, cancellationToken);
 3462    }
 63}