< Summary

Information
Class: Elsa.Bpmn.Interchange.Endpoints.Bpmn.BpmnCapabilityErrorFormatter
Assembly: Elsa.Bpmn.Interchange
File(s): /home/runner/work/elsa-core/elsa-core/src/modules/Elsa.Bpmn.Interchange/Endpoints/Bpmn/BpmnCapabilityErrorFormatter.cs
Line coverage
100%
Covered lines: 14
Uncovered lines: 0
Coverable lines: 14
Total lines: 47
Line coverage: 100%
Branch coverage
N/A
Covered branches: 0
Total branches: 0
Branch coverage: N/A
Method coverage

Feature is only available for sponsors

Upgrade to PRO version

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity Line coverage
Format(...)100%11100%
DataFor(...)100%11100%
MissingCapabilityNames(...)100%11100%

File(s)

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

#LineLine coverage
 1using Bpmn.Semantics;
 2using Elsa.Bpmn.Interchange.Services;
 3
 4namespace Elsa.Bpmn.Interchange.Endpoints.Bpmn;
 5
 6/// <summary>
 7/// Formats a <see cref="BpmnCapabilityException"/> into the one error message every endpoint that imports a BPMN
 8/// document — <c>Import</c> and the document <c>Put</c> endpoint — reports it as.
 9/// </summary>
 10/// <remarks>
 11/// <see cref="BpmnCapabilityException"/> carries <see cref="BpmnCapabilityException.DrivingElementIds"/> as a single
 12/// flat list, already unioned across every missing capability — it does not say which element drove which capability
 13/// (unlike <c>BpmnCapabilityRequirements.DrivingElementIds</c>, which is per-capability, but that type is gone by the
 14/// time an endpoint's catch clause sees the exception). Attributing the full, unioned list to each capability
 15/// individually would put elements next to a capability they may have nothing to do with, so this reports the
 16/// missing capabilities together with the combined element list once, rather than repeating it.
 17/// </remarks>
 18internal static class BpmnCapabilityErrorFormatter
 19{
 20    /// <summary>The message an endpoint reports for <paramref name="exception"/>.</summary>
 21    public static string Format(BpmnCapabilityException exception)
 22    {
 123        var missingCapabilities = string.Join(", ", MissingCapabilityNames(exception));
 124        var elementIds = string.Join(", ", exception.DrivingElementIds);
 25
 126        return
 127            $"This deployment does not declare the following BPMN host capabilities the document requires: {missingCapab
 128            + $"Offending elements (combined across all missing capabilities above, not attributable to any one of them)
 29    }
 30
 31    /// <summary>
 32    /// The structured <c>data</c> the <see cref="BpmnErrorCodes.ImportCapabilityUnsupported"/> response carries
 33    /// alongside <see cref="Format"/>'s message: the missing capability names and the offending element ids, under
 34    /// the same "combined, not attributable to any one capability" caveat <see cref="Format"/>'s remarks explain.
 35    /// </summary>
 136    public static object DataFor(BpmnCapabilityException exception) => new
 137    {
 138        Capabilities = MissingCapabilityNames(exception),
 139        ElementIds = exception.DrivingElementIds
 140    };
 41
 42    private static IReadOnlyList<string> MissingCapabilityNames(BpmnCapabilityException exception) =>
 243        BpmnInterchangeDocumentService.IndividualCapabilities
 844            .Where(capability => exception.Missing.HasFlag(capability))
 245            .Select(capability => capability.ToString())
 246            .ToList();
 47}