| | | 1 | | using Elsa.Abstractions; |
| | | 2 | | using Elsa.Alterations.Core.Contracts; |
| | | 3 | | using Elsa.Alterations.Core.Models; |
| | | 4 | | using Elsa.Common; |
| | | 5 | | using Elsa.Workflows; |
| | | 6 | | using JetBrains.Annotations; |
| | | 7 | | using Microsoft.AspNetCore.Http; |
| | | 8 | | |
| | | 9 | | namespace Elsa.Alterations.Endpoints.Alterations.Submit; |
| | | 10 | | |
| | | 11 | | /// <summary> |
| | | 12 | | /// Submits an alteration plan to be executed targeting workflow instances by a filter. |
| | | 13 | | /// </summary> |
| | | 14 | | [PublicAPI] |
| | | 15 | | public class Submit : ElsaEndpoint<AlterationPlanParams, Response> |
| | | 16 | | { |
| | | 17 | | private readonly IAlterationPlanScheduler _alterationPlanScheduler; |
| | | 18 | | private readonly IIdentityGenerator _identityGenerator; |
| | | 19 | | private readonly ISystemClock _systemClock; |
| | | 20 | | |
| | | 21 | | /// <inheritdoc /> |
| | 14 | 22 | | public Submit(IAlterationPlanScheduler alterationPlanScheduler, IIdentityGenerator identityGenerator, ISystemClock s |
| | | 23 | | { |
| | 14 | 24 | | _alterationPlanScheduler = alterationPlanScheduler; |
| | 14 | 25 | | _identityGenerator = identityGenerator; |
| | 14 | 26 | | _systemClock = systemClock; |
| | 14 | 27 | | } |
| | | 28 | | |
| | | 29 | | /// <inheritdoc /> |
| | | 30 | | public override void Configure() |
| | | 31 | | { |
| | 10 | 32 | | Post("/alterations/submit"); |
| | 10 | 33 | | ConfigurePermissions("run:alterations"); |
| | 10 | 34 | | } |
| | | 35 | | |
| | | 36 | | /// <inheritdoc /> |
| | | 37 | | public override async Task HandleAsync(AlterationPlanParams planParams, CancellationToken cancellationToken) |
| | | 38 | | { |
| | 4 | 39 | | if (!ValidateInput(planParams)) |
| | | 40 | | { |
| | 3 | 41 | | await Send.ErrorsAsync(StatusCodes.Status400BadRequest, cancellationToken); |
| | 3 | 42 | | return; |
| | | 43 | | } |
| | | 44 | | |
| | | 45 | | // Submit the plan. |
| | 1 | 46 | | var planId = await _alterationPlanScheduler.SubmitAsync(planParams, cancellationToken); |
| | | 47 | | |
| | | 48 | | // Write response. |
| | 1 | 49 | | var response = new Response(planId); |
| | 1 | 50 | | await Send.OkAsync(response, cancellationToken); |
| | 4 | 51 | | } |
| | | 52 | | |
| | | 53 | | private bool ValidateInput(AlterationPlanParams planParams) |
| | | 54 | | { |
| | 8 | 55 | | return TimestampFilterValidation.Validate(planParams.Filter?.TimestampFilters, error => AddError(error)); |
| | | 56 | | } |
| | | 57 | | } |