| | | 1 | | using Elsa.Workflows.Runtime.Entities; |
| | | 2 | | |
| | | 3 | | namespace Elsa.Workflows.Runtime.Filters; |
| | | 4 | | |
| | | 5 | | /// <summary> |
| | | 6 | | /// A specification to use when finding activity execution log records. Only non-null fields will be included in the con |
| | | 7 | | /// </summary> |
| | | 8 | | public class ActivityExecutionRecordFilter |
| | | 9 | | { |
| | | 10 | | /// <summary> |
| | | 11 | | /// The ID of the activity execution record. |
| | | 12 | | /// </summary> |
| | 30 | 13 | | public string? Id { get; set; } |
| | | 14 | | |
| | | 15 | | /// <summary> |
| | | 16 | | /// The IDs of the activity execution records. |
| | | 17 | | /// </summary> |
| | 30 | 18 | | public ICollection<string>? Ids { get; set; } |
| | | 19 | | |
| | | 20 | | /// <summary> |
| | | 21 | | /// The ID of the workflow instance. |
| | | 22 | | /// </summary> |
| | 50 | 23 | | public string? WorkflowInstanceId { get; set; } |
| | | 24 | | |
| | | 25 | | /// <summary> |
| | | 26 | | /// The IDs of the workflow instances. |
| | | 27 | | /// </summary> |
| | 56 | 28 | | public ICollection<string>? WorkflowInstanceIds { get; set; } |
| | | 29 | | |
| | | 30 | | /// <summary> |
| | | 31 | | /// The ID of the activity. |
| | | 32 | | /// </summary> |
| | 51 | 33 | | public string? ActivityId { get; set; } |
| | | 34 | | |
| | | 35 | | /// <summary> |
| | | 36 | | /// The IDs of the activities. |
| | | 37 | | /// </summary> |
| | 30 | 38 | | public ICollection<string>? ActivityIds { get; set; } |
| | | 39 | | |
| | | 40 | | /// <summary> |
| | | 41 | | /// The node ID of the activity. |
| | | 42 | | /// </summary> |
| | 30 | 43 | | public string? ActivityNodeId { get; set; } |
| | | 44 | | |
| | | 45 | | /// <summary> |
| | | 46 | | /// The node IDs of the activities. |
| | | 47 | | /// </summary> |
| | 30 | 48 | | public ICollection<string>? ActivityNodeIds { get; set; } |
| | | 49 | | |
| | | 50 | | /// <summary> |
| | | 51 | | /// The name of the activity. |
| | | 52 | | /// </summary> |
| | 32 | 53 | | public string? Name { get; set; } |
| | | 54 | | |
| | | 55 | | /// <summary> |
| | | 56 | | /// The names of the activities. |
| | | 57 | | /// </summary> |
| | 30 | 58 | | public ICollection<string>? Names { get; set; } |
| | | 59 | | |
| | | 60 | | /// <summary> |
| | | 61 | | /// The status of the activity. |
| | | 62 | | /// </summary> |
| | 30 | 63 | | public ActivityStatus? Status { get; set; } |
| | | 64 | | |
| | | 65 | | /// <summary> |
| | | 66 | | /// The statuses of the activities. |
| | | 67 | | /// </summary> |
| | 30 | 68 | | public ICollection<ActivityStatus>? Statuses { get; set; } |
| | | 69 | | |
| | | 70 | | /// <summary> |
| | | 71 | | /// Whether to include completed activity execution records. If not specified, all activity execution records will b |
| | | 72 | | /// </summary> |
| | 30 | 73 | | public bool? Completed { get; set; } |
| | | 74 | | |
| | | 75 | | /// <summary> |
| | | 76 | | /// Returns true if the filter is empty. |
| | | 77 | | /// </summary> |
| | | 78 | | public bool IsEmpty => |
| | 0 | 79 | | Id == null |
| | 0 | 80 | | && Ids == null |
| | 0 | 81 | | && WorkflowInstanceId == null |
| | 0 | 82 | | && WorkflowInstanceIds == null |
| | 0 | 83 | | && ActivityId == null |
| | 0 | 84 | | && ActivityIds == null |
| | 0 | 85 | | && ActivityNodeId == null |
| | 0 | 86 | | && ActivityNodeIds == null |
| | 0 | 87 | | && Name == null |
| | 0 | 88 | | && Names == null |
| | 0 | 89 | | && Status == null |
| | 0 | 90 | | && Statuses == null |
| | 0 | 91 | | && Completed == null; |
| | | 92 | | |
| | | 93 | | /// <summary> |
| | | 94 | | /// Applies the filter to the specified queryable. |
| | | 95 | | /// </summary> |
| | | 96 | | public IQueryable<ActivityExecutionRecord> Apply(IQueryable<ActivityExecutionRecord> queryable) |
| | | 97 | | { |
| | 30 | 98 | | var filter = this; |
| | 30 | 99 | | if (filter.Id != null) queryable = queryable.Where(x => x.Id == filter.Id); |
| | 30 | 100 | | if (filter.Ids != null) queryable = queryable.Where(x => filter.Ids.Contains(x.Id)); |
| | 40 | 101 | | if (filter.WorkflowInstanceId != null) queryable = queryable.Where(x => x.WorkflowInstanceId == filter.WorkflowI |
| | 43 | 102 | | if (filter.WorkflowInstanceIds != null) queryable = queryable.Where(x => filter.WorkflowInstanceIds.Contains(x.W |
| | 36 | 103 | | if (filter.ActivityId != null) queryable = queryable.Where(x => x.ActivityId == filter.ActivityId); |
| | 30 | 104 | | if (filter.ActivityIds != null && filter.ActivityIds.Any()) queryable = queryable.Where(x => filter.ActivityIds. |
| | 30 | 105 | | if (filter.ActivityNodeId != null) queryable = queryable.Where(x => x.ActivityNodeId == filter.ActivityNodeId); |
| | 30 | 106 | | if (filter.ActivityNodeIds != null && filter.ActivityNodeIds.Any()) queryable = queryable.Where(x => filter.Acti |
| | 31 | 107 | | if (filter.Name != null) queryable = queryable.Where(x => x.ActivityName == filter.Name); |
| | 30 | 108 | | if (filter.Names != null && filter.Names.Any()) queryable = queryable.Where(x => filter.Names.Contains(x.Activit |
| | 30 | 109 | | if (filter.Status != null) queryable = queryable.Where(x => x.Status == filter.Status); |
| | 30 | 110 | | if (filter.Statuses != null && filter.Statuses.Any()) queryable = queryable.Where(x => filter.Statuses.Contains( |
| | 30 | 111 | | if (filter.Completed != null) queryable = filter.Completed == true ? queryable.Where(x => x.CompletedAt != null) |
| | | 112 | | |
| | 30 | 113 | | return queryable; |
| | | 114 | | } |
| | | 115 | | } |