< Summary

Information
Class: Elsa.Workflows.Management.Filters.WorkflowDefinitionFilter
Assembly: Elsa.Workflows.Management
File(s): /home/runner/work/elsa-core/elsa-core/src/modules/Elsa.Workflows.Management/Filters/WorkflowDefinitionFilter.cs
Line coverage
46%
Covered lines: 14
Uncovered lines: 16
Coverable lines: 30
Total lines: 111
Line coverage: 46.6%
Branch coverage
0%
Covered branches: 0
Total branches: 36
Branch coverage: 0%
Method coverage

Feature is only available for sponsors

Upgrade to PRO version

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity Line coverage
get_Id()100%11100%
get_Ids()100%11100%
get_DefinitionId()100%11100%
get_DefinitionIds()100%11100%
get_VersionOptions()100%11100%
get_DefinitionHandle()100%11100%
get_Name()100%11100%
get_SearchTerm()100%11100%
get_Names()100%11100%
get_MaterializerName()100%11100%
get_UsableAsActivity()100%11100%
get_IsSystem()100%11100%
get_IsReadonly()100%11100%
get_TenantAgnostic()100%11100%
Apply(...)0%1332360%

File(s)

/home/runner/work/elsa-core/elsa-core/src/modules/Elsa.Workflows.Management/Filters/WorkflowDefinitionFilter.cs

#LineLine coverage
 1using Elsa.Common.Models;
 2using Elsa.Extensions;
 3using Elsa.Workflows.Management.Entities;
 4using Elsa.Workflows.Models;
 5using JetBrains.Annotations;
 6
 7namespace Elsa.Workflows.Management.Filters;
 8
 9/// <summary>
 10/// A specification to use when finding workflow definitions. Only non-null fields will be included in the conditional e
 11/// </summary>
 12[PublicAPI]
 13public class WorkflowDefinitionFilter
 14{
 15    /// <summary>
 16    /// Filter by the ID of the workflow definition.
 17    /// </summary>
 631818    public string? Id { get; set; }
 19
 20    /// <summary>
 21    /// Filter by the IDs of the workflow definitions.
 22    /// </summary>
 549023    public ICollection<string>? Ids { get; set; }
 24
 25    /// <summary>
 26    /// Filter by the ID of the workflow definition.
 27    /// </summary>
 783928    public string? DefinitionId { get; set; }
 29
 30    /// <summary>
 31    /// Filter by the IDs of the workflow definitions.
 32    /// </summary>
 550133    public ICollection<string>? DefinitionIds { get; set; }
 34
 35    /// <summary>
 36    /// Filter by the version options.
 37    /// </summary>
 737938    public VersionOptions? VersionOptions { get; set; }
 39
 40    /// <summary>
 41    /// Filter by the handle of the workflow definition.
 42    /// </summary>
 613043    public WorkflowDefinitionHandle? DefinitionHandle { get; set; }
 44
 45    /// <summary>
 46    /// Filter by the name of the workflow definition.
 47    /// </summary>
 549048    public string? Name { get; set; }
 49
 50    /// <summary>
 51    /// Filter by the name or id of the workflow definition.
 52    /// </summary>
 549053    public string? SearchTerm { get; set; }
 54
 55    /// <summary>
 56    /// Filter by the names of the workflow definitions.
 57    /// </summary>
 549058    public ICollection<string>? Names { get; set; }
 59
 60    /// <summary>
 61    /// Filter by the name of the workflow definition materializer.
 62    /// </summary>
 549063    public string? MaterializerName { get; set; }
 64
 65    /// <summary>
 66    /// Filter on workflows that are usable as activities.
 67    /// </summary>
 556668    public bool? UsableAsActivity { get; set; }
 69
 70    /// <summary>
 71    /// Filter on workflows that are system workflows.
 72    /// </summary>
 549073    public bool? IsSystem { get; set; }
 74
 75    /// <summary>
 76    /// Filter on workflows that are read-only.
 77    /// </summary>
 550378    public bool? IsReadonly { get; set; }
 79
 80    /// <summary>
 81    /// Gets or sets a value indicating whether to include tenant matching in the filter.
 82    /// </summary>
 548983    public bool TenantAgnostic { get; set; }
 84
 85    /// <summary>
 86    /// Applies the filter to the specified queryable.
 87    /// </summary>
 88    /// <param name="queryable">The queryable to apply the filter to.</param>
 89    /// <returns>The filtered queryable.</returns>
 90    public IQueryable<WorkflowDefinition> Apply(IQueryable<WorkflowDefinition> queryable)
 91    {
 092        var definitionId = DefinitionId ?? DefinitionHandle?.DefinitionId;
 093        var versionOptions = VersionOptions ?? DefinitionHandle?.VersionOptions;
 094        var id = Id ?? DefinitionHandle?.DefinitionVersionId;
 95
 096        if (definitionId != null) queryable = queryable.Where(x => x.DefinitionId == definitionId);
 097        if (DefinitionIds != null) queryable = queryable.Where(x => DefinitionIds.Contains(x.DefinitionId));
 098        if (id != null) queryable = queryable.Where(x => x.Id == id);
 099        if (Ids != null) queryable = queryable.Where(x => Ids.Contains(x.Id));
 0100        if (versionOptions != null) queryable = queryable.WithVersion(versionOptions.Value);
 0101        if (MaterializerName != null) queryable = queryable.Where(x => x.MaterializerName == MaterializerName);
 0102        if (Name != null) queryable = queryable.Where(x => x.Name == Name);
 0103        if (Names != null) queryable = queryable.Where(x => Names.Contains(x.Name!));
 0104        if (UsableAsActivity != null) queryable = queryable.Where(x => x.Options.UsableAsActivity == UsableAsActivity);
 0105        if (!string.IsNullOrWhiteSpace(SearchTerm)) queryable = queryable.Where(x => x.Name!.ToLower().Contains(SearchTe
 0106        if (IsSystem != null) queryable = queryable.Where(x => x.IsSystem == IsSystem);
 0107        if (IsReadonly != null) queryable = queryable.Where(x => x.IsReadonly == IsReadonly);
 108
 0109        return queryable;
 110    }
 111}