| | | 1 | | using Elsa.Common.Models; |
| | | 2 | | using Elsa.Extensions; |
| | | 3 | | using Elsa.Workflows.Management.Entities; |
| | | 4 | | using Elsa.Workflows.Models; |
| | | 5 | | using JetBrains.Annotations; |
| | | 6 | | |
| | | 7 | | namespace 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] |
| | | 13 | | public class WorkflowDefinitionFilter |
| | | 14 | | { |
| | | 15 | | /// <summary> |
| | | 16 | | /// Filter by the ID of the workflow definition. |
| | | 17 | | /// </summary> |
| | 6318 | 18 | | public string? Id { get; set; } |
| | | 19 | | |
| | | 20 | | /// <summary> |
| | | 21 | | /// Filter by the IDs of the workflow definitions. |
| | | 22 | | /// </summary> |
| | 5490 | 23 | | public ICollection<string>? Ids { get; set; } |
| | | 24 | | |
| | | 25 | | /// <summary> |
| | | 26 | | /// Filter by the ID of the workflow definition. |
| | | 27 | | /// </summary> |
| | 7839 | 28 | | public string? DefinitionId { get; set; } |
| | | 29 | | |
| | | 30 | | /// <summary> |
| | | 31 | | /// Filter by the IDs of the workflow definitions. |
| | | 32 | | /// </summary> |
| | 5501 | 33 | | public ICollection<string>? DefinitionIds { get; set; } |
| | | 34 | | |
| | | 35 | | /// <summary> |
| | | 36 | | /// Filter by the version options. |
| | | 37 | | /// </summary> |
| | 7379 | 38 | | public VersionOptions? VersionOptions { get; set; } |
| | | 39 | | |
| | | 40 | | /// <summary> |
| | | 41 | | /// Filter by the handle of the workflow definition. |
| | | 42 | | /// </summary> |
| | 6130 | 43 | | public WorkflowDefinitionHandle? DefinitionHandle { get; set; } |
| | | 44 | | |
| | | 45 | | /// <summary> |
| | | 46 | | /// Filter by the name of the workflow definition. |
| | | 47 | | /// </summary> |
| | 5490 | 48 | | public string? Name { get; set; } |
| | | 49 | | |
| | | 50 | | /// <summary> |
| | | 51 | | /// Filter by the name or id of the workflow definition. |
| | | 52 | | /// </summary> |
| | 5490 | 53 | | public string? SearchTerm { get; set; } |
| | | 54 | | |
| | | 55 | | /// <summary> |
| | | 56 | | /// Filter by the names of the workflow definitions. |
| | | 57 | | /// </summary> |
| | 5490 | 58 | | public ICollection<string>? Names { get; set; } |
| | | 59 | | |
| | | 60 | | /// <summary> |
| | | 61 | | /// Filter by the name of the workflow definition materializer. |
| | | 62 | | /// </summary> |
| | 5490 | 63 | | public string? MaterializerName { get; set; } |
| | | 64 | | |
| | | 65 | | /// <summary> |
| | | 66 | | /// Filter on workflows that are usable as activities. |
| | | 67 | | /// </summary> |
| | 5566 | 68 | | public bool? UsableAsActivity { get; set; } |
| | | 69 | | |
| | | 70 | | /// <summary> |
| | | 71 | | /// Filter on workflows that are system workflows. |
| | | 72 | | /// </summary> |
| | 5490 | 73 | | public bool? IsSystem { get; set; } |
| | | 74 | | |
| | | 75 | | /// <summary> |
| | | 76 | | /// Filter on workflows that are read-only. |
| | | 77 | | /// </summary> |
| | 5503 | 78 | | 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> |
| | 5489 | 83 | | 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 | | { |
| | 0 | 92 | | var definitionId = DefinitionId ?? DefinitionHandle?.DefinitionId; |
| | 0 | 93 | | var versionOptions = VersionOptions ?? DefinitionHandle?.VersionOptions; |
| | 0 | 94 | | var id = Id ?? DefinitionHandle?.DefinitionVersionId; |
| | | 95 | | |
| | 0 | 96 | | if (definitionId != null) queryable = queryable.Where(x => x.DefinitionId == definitionId); |
| | 0 | 97 | | if (DefinitionIds != null) queryable = queryable.Where(x => DefinitionIds.Contains(x.DefinitionId)); |
| | 0 | 98 | | if (id != null) queryable = queryable.Where(x => x.Id == id); |
| | 0 | 99 | | if (Ids != null) queryable = queryable.Where(x => Ids.Contains(x.Id)); |
| | 0 | 100 | | if (versionOptions != null) queryable = queryable.WithVersion(versionOptions.Value); |
| | 0 | 101 | | if (MaterializerName != null) queryable = queryable.Where(x => x.MaterializerName == MaterializerName); |
| | 0 | 102 | | if (Name != null) queryable = queryable.Where(x => x.Name == Name); |
| | 0 | 103 | | if (Names != null) queryable = queryable.Where(x => Names.Contains(x.Name!)); |
| | 0 | 104 | | if (UsableAsActivity != null) queryable = queryable.Where(x => x.Options.UsableAsActivity == UsableAsActivity); |
| | 0 | 105 | | if (!string.IsNullOrWhiteSpace(SearchTerm)) queryable = queryable.Where(x => x.Name!.ToLower().Contains(SearchTe |
| | 0 | 106 | | if (IsSystem != null) queryable = queryable.Where(x => x.IsSystem == IsSystem); |
| | 0 | 107 | | if (IsReadonly != null) queryable = queryable.Where(x => x.IsReadonly == IsReadonly); |
| | | 108 | | |
| | 0 | 109 | | return queryable; |
| | | 110 | | } |
| | | 111 | | } |