| | | 1 | | using Elsa.Models; |
| | | 2 | | using Elsa.Workflows.Api.Models; |
| | | 3 | | using Elsa.Workflows.Management.Entities; |
| | | 4 | | using Elsa.Workflows.Management.Mappers; |
| | | 5 | | using Elsa.Workflows.Management.Models; |
| | | 6 | | using Elsa.Workflows.Management.Options; |
| | | 7 | | using Microsoft.Extensions.Options; |
| | | 8 | | |
| | | 9 | | namespace Elsa.Workflows.Api.Services; |
| | | 10 | | |
| | | 11 | | /// <inheritdoc/> |
| | 2 | 12 | | public class StaticWorkflowDefinitionLinker( |
| | 2 | 13 | | IOptions<ManagementOptions> managementOptions, |
| | 2 | 14 | | WorkflowDefinitionMapper workflowDefinitionMapper) |
| | | 15 | | : IWorkflowDefinitionLinker |
| | | 16 | | { |
| | | 17 | | /// <inheritdoc /> |
| | | 18 | | public async Task<LinkedWorkflowDefinitionModel> MapAsync(WorkflowDefinition definition, CancellationToken cancellat |
| | | 19 | | { |
| | 1 | 20 | | var workflowDefinitionModel = await workflowDefinitionMapper.MapAsync(definition, cancellationToken); |
| | 1 | 21 | | var linkedModel = new LinkedWorkflowDefinitionModel(GenerateLinksForSingleEntry(definition.DefinitionId, definit |
| | 1 | 22 | | { |
| | 1 | 23 | | Id = workflowDefinitionModel.Id, |
| | 1 | 24 | | DefinitionId = workflowDefinitionModel.DefinitionId, |
| | 1 | 25 | | Name = workflowDefinitionModel.Name, |
| | 1 | 26 | | Description = workflowDefinitionModel.Description, |
| | 1 | 27 | | CreatedAt = workflowDefinitionModel.CreatedAt, |
| | 1 | 28 | | Version = workflowDefinitionModel.Version, |
| | 1 | 29 | | ToolVersion = workflowDefinitionModel.ToolVersion, |
| | 1 | 30 | | Variables = workflowDefinitionModel.Variables, |
| | 1 | 31 | | Inputs = workflowDefinitionModel.Inputs, |
| | 1 | 32 | | Outputs = workflowDefinitionModel.Outputs, |
| | 1 | 33 | | Outcomes = workflowDefinitionModel.Outcomes, |
| | 1 | 34 | | CustomProperties = workflowDefinitionModel.CustomProperties, |
| | 1 | 35 | | IsReadonly = workflowDefinitionModel.IsReadonly, |
| | 1 | 36 | | IsSystem = workflowDefinitionModel.IsSystem, |
| | 1 | 37 | | IsLatest = workflowDefinitionModel.IsLatest, |
| | 1 | 38 | | IsPublished = workflowDefinitionModel.IsPublished, |
| | 1 | 39 | | Options = workflowDefinitionModel.Options, |
| | 1 | 40 | | UsableAsActivity = workflowDefinitionModel.UsableAsActivity, |
| | 1 | 41 | | Root = workflowDefinitionModel.Root |
| | 1 | 42 | | }; |
| | | 43 | | |
| | 1 | 44 | | return linkedModel; |
| | 1 | 45 | | } |
| | | 46 | | |
| | | 47 | | /// <inheritdoc /> |
| | | 48 | | public PagedListResponse<LinkedWorkflowDefinitionSummary> MapAsync(PagedListResponse<WorkflowDefinitionSummary> list |
| | | 49 | | { |
| | 0 | 50 | | var items = new List<LinkedWorkflowDefinitionSummary>(); |
| | | 51 | | |
| | 0 | 52 | | foreach (var item in list.Items) |
| | | 53 | | { |
| | 0 | 54 | | items.Add(new LinkedWorkflowDefinitionSummary |
| | 0 | 55 | | { |
| | 0 | 56 | | Links = GenerateLinksForSingleEntry(item.DefinitionId, item.IsReadonly), |
| | 0 | 57 | | Id = item.Id, |
| | 0 | 58 | | DefinitionId = item.DefinitionId, |
| | 0 | 59 | | Name = item.Name, |
| | 0 | 60 | | Description = item.Description, |
| | 0 | 61 | | Version = item.Version, |
| | 0 | 62 | | ToolVersion = item.ToolVersion, |
| | 0 | 63 | | IsLatest = item.IsLatest, |
| | 0 | 64 | | IsPublished = item.IsPublished, |
| | 0 | 65 | | ProviderName = item.ProviderName, |
| | 0 | 66 | | MaterializerName = item.MaterializerName, |
| | 0 | 67 | | CreatedAt = item.CreatedAt, |
| | 0 | 68 | | IsReadonly = item.IsReadonly |
| | 0 | 69 | | }); |
| | | 70 | | } |
| | | 71 | | |
| | 0 | 72 | | return new PagedListResponse<LinkedWorkflowDefinitionSummary> |
| | 0 | 73 | | { |
| | 0 | 74 | | TotalCount = list.TotalCount, |
| | 0 | 75 | | Items = items, |
| | 0 | 76 | | Links = GenerateLinksForPagedList().ToArray() |
| | 0 | 77 | | }; |
| | | 78 | | } |
| | | 79 | | |
| | | 80 | | /// <inheritdoc /> |
| | | 81 | | public async Task<List<LinkedWorkflowDefinitionModel>> MapAsync(List<WorkflowDefinition> definitions, CancellationTo |
| | | 82 | | { |
| | 0 | 83 | | var models = (await workflowDefinitionMapper.MapAsync(definitions, cancellationToken)).ToList(); |
| | 0 | 84 | | var result = new List<LinkedWorkflowDefinitionModel>(); |
| | | 85 | | |
| | 0 | 86 | | foreach (var item in models) |
| | | 87 | | { |
| | 0 | 88 | | var linkedModel = new LinkedWorkflowDefinitionModel(GenerateLinksForSingleEntry(item.DefinitionId, item.IsRe |
| | 0 | 89 | | { |
| | 0 | 90 | | Id = item.Id, |
| | 0 | 91 | | DefinitionId = item.DefinitionId, |
| | 0 | 92 | | Name = item.Name, |
| | 0 | 93 | | Description = item.Description, |
| | 0 | 94 | | CreatedAt = item.CreatedAt, |
| | 0 | 95 | | Version = item.Version, |
| | 0 | 96 | | ToolVersion = item.ToolVersion, |
| | 0 | 97 | | Variables = item.Variables, |
| | 0 | 98 | | Inputs = item.Inputs, |
| | 0 | 99 | | Outputs = item.Outputs, |
| | 0 | 100 | | Outcomes = item.Outcomes, |
| | 0 | 101 | | CustomProperties = item.CustomProperties, |
| | 0 | 102 | | IsReadonly = item.IsReadonly, |
| | 0 | 103 | | IsSystem = item.IsSystem, |
| | 0 | 104 | | IsLatest = item.IsLatest, |
| | 0 | 105 | | IsPublished = item.IsPublished, |
| | 0 | 106 | | Options = item.Options, |
| | 0 | 107 | | UsableAsActivity = item.UsableAsActivity, |
| | 0 | 108 | | Root = item.Root |
| | 0 | 109 | | }; |
| | | 110 | | |
| | 0 | 111 | | result.Add(linkedModel); |
| | | 112 | | } |
| | | 113 | | |
| | 0 | 114 | | return result; |
| | 0 | 115 | | } |
| | | 116 | | |
| | | 117 | | private Link[] GenerateLinksForPagedList() |
| | | 118 | | { |
| | 0 | 119 | | var linksList = new List<Link> |
| | 0 | 120 | | { |
| | 0 | 121 | | new($"/workflow-definitions", "self", "GET"), |
| | 0 | 122 | | new($"/workflow-definitions/validation/is-name-unique", "is-name-unique", "GET"), |
| | 0 | 123 | | new($"/workflow-definitions/query/count", "count", "GET"), |
| | 0 | 124 | | new($"/workflow-definitions/many-by-id", "many-by-id", "GET") |
| | 0 | 125 | | }; |
| | | 126 | | |
| | 0 | 127 | | if (!managementOptions.Value.IsReadOnlyMode) |
| | | 128 | | { |
| | 0 | 129 | | linksList.Add(new Link($"/bulk-actions/delete/workflow-definitions/by-definition-id", "bulk-delete-by-defini |
| | 0 | 130 | | linksList.Add(new Link($"/bulk-actions/delete/workflow-definitions/by-id", "bulk-delete-by-id", "POST")); |
| | 0 | 131 | | linksList.Add(new Link($"/bulk-actions/publish/workflow-definitions/by-definition-ids", "bulk-publish", "POS |
| | 0 | 132 | | linksList.Add(new Link($"/bulk-actions/retract/workflow-definitions/by-definition-ids", "bulk-retract", "POS |
| | 0 | 133 | | linksList.Add(new Link($"/workflow-definitions/import", "import", "POST")); |
| | 0 | 134 | | linksList.Add(new Link($"/workflow-definitions/import-files", "import-files", "POST")); |
| | 0 | 135 | | linksList.Add(new Link($"/workflow-definitions", "create", "POST")); |
| | | 136 | | } |
| | | 137 | | |
| | 0 | 138 | | return linksList.ToArray(); |
| | | 139 | | } |
| | | 140 | | |
| | | 141 | | private Link[] GenerateLinksForSingleEntry(string definitionId, bool definitionIsReadonly) |
| | | 142 | | { |
| | 1 | 143 | | var links = new List<Link> |
| | 1 | 144 | | { |
| | 1 | 145 | | new($"/workflow-definitions/{definitionId}", "self", "GET"), |
| | 1 | 146 | | new($"/workflow-definitions/by-definition-id/{definitionId}", "self", "GET"), |
| | 1 | 147 | | new($"/workflow-definitions/{definitionId}/versions", "versions", "GET"), |
| | 1 | 148 | | new($"/workflow-definitions/{definitionId}/bulk-dispatch", "bulk-dispatch", "POST"), |
| | 1 | 149 | | new($"/workflow-definitions/{definitionId}/dispatch", "dispatch", "POST"), |
| | 1 | 150 | | new($"/workflow-definitions/{definitionId}/execute", "execute", "POST"), |
| | 1 | 151 | | new($"/workflow-definitions/{definitionId}/export", "export", "POST") |
| | 1 | 152 | | }; |
| | | 153 | | |
| | 1 | 154 | | if (!managementOptions.Value.IsReadOnlyMode && !definitionIsReadonly) |
| | | 155 | | { |
| | 1 | 156 | | links.Add(new Link($"/workflow-definitions/{definitionId}/publish", "publish", "POST")); |
| | 1 | 157 | | links.Add(new Link($"/workflow-definitions/{definitionId}/retract", "retract", "POST")); |
| | 1 | 158 | | links.Add(new Link($"/workflow-definitions/{definitionId}", "delete", "DELETE")); |
| | 1 | 159 | | links.Add(new Link($"/workflow-definitions/{definitionId}/import", "import", "PUT")); |
| | 1 | 160 | | links.Add(new Link($"/workflow-definitions/{definitionId}/update-references", "update-references", "POST")); |
| | | 161 | | } |
| | | 162 | | |
| | 1 | 163 | | return links.ToArray(); |
| | | 164 | | } |
| | | 165 | | } |