Now able to delete a workflow tamplate completely.
This commit is contained in:
parent
44ada3f332
commit
55d1beadbc
@ -0,0 +1,17 @@
|
|||||||
|
using e_suite.Database.Core.Models;
|
||||||
|
using eSuite.Core.Miscellaneous;
|
||||||
|
|
||||||
|
namespace e_suite.API.Common;
|
||||||
|
|
||||||
|
public class CreateWorkflowTemplateVersion
|
||||||
|
{
|
||||||
|
public List<TaskDefinition> Tasks { get; set; } = [];
|
||||||
|
|
||||||
|
public required string WorkflowName { get; set; }
|
||||||
|
|
||||||
|
public required GeneralIdRef DomainId { get; set; }
|
||||||
|
|
||||||
|
public string Description { get; set; } = String.Empty;
|
||||||
|
|
||||||
|
public required string ActivityNameTemplate { get; set; } = String.Empty;
|
||||||
|
}
|
||||||
@ -0,0 +1,50 @@
|
|||||||
|
using e_suite.Database.Core.Extensions;
|
||||||
|
using e_suite.Database.Core.Models;
|
||||||
|
using e_suite.Database.Core.Tables.Workflow;
|
||||||
|
using eSuite.Core.Miscellaneous;
|
||||||
|
|
||||||
|
namespace e_suite.API.Common;
|
||||||
|
|
||||||
|
public class GetWorkflowTemplateVersion : IGeneralId
|
||||||
|
{
|
||||||
|
public GetWorkflowTemplateVersion()
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
public GetWorkflowTemplateVersion(WorkflowVersion workflowVersion)
|
||||||
|
{
|
||||||
|
Id = workflowVersion.Id;
|
||||||
|
Guid = workflowVersion.Guid;
|
||||||
|
Deleted = workflowVersion.Deleted;
|
||||||
|
ActivityNameTemplate = workflowVersion.ActivityNameTemplate;
|
||||||
|
Description = workflowVersion.Description;
|
||||||
|
DomainId = workflowVersion.Domain.ToGeneralIdRef()!;
|
||||||
|
LastUpdated = workflowVersion.LastUpdated;
|
||||||
|
Version = workflowVersion.Version;
|
||||||
|
WorkflowId = workflowVersion.Workflow.ToGeneralIdRef()!;
|
||||||
|
WorkflowName = workflowVersion.Workflow.Name;
|
||||||
|
Tasks = workflowVersion.Tasks;
|
||||||
|
}
|
||||||
|
|
||||||
|
public List<TaskDefinition> Tasks { get; set; } = [];
|
||||||
|
|
||||||
|
public string WorkflowName { get; set; } = string.Empty;
|
||||||
|
|
||||||
|
public GeneralIdRef WorkflowId { get; set; } = null!;
|
||||||
|
|
||||||
|
public long Version { get; set; }
|
||||||
|
|
||||||
|
public DateTimeOffset LastUpdated { get; set; }
|
||||||
|
|
||||||
|
public GeneralIdRef DomainId { get; set; } = null!;
|
||||||
|
|
||||||
|
public string Description { get; set; } = string.Empty;
|
||||||
|
|
||||||
|
public string ActivityNameTemplate { get; set; } = string.Empty;
|
||||||
|
|
||||||
|
public bool Deleted { get; set; }
|
||||||
|
|
||||||
|
public long Id { get; set; }
|
||||||
|
public Guid Guid { get; set; }
|
||||||
|
}
|
||||||
@ -1,91 +1,9 @@
|
|||||||
using e_suite.Database.Audit;
|
using e_suite.Database.Audit;
|
||||||
using e_suite.Database.Core.Extensions;
|
|
||||||
using e_suite.Database.Core.Models;
|
|
||||||
using e_suite.Database.Core.Tables.Workflow;
|
|
||||||
using e_suite.Utilities.Pagination;
|
using e_suite.Utilities.Pagination;
|
||||||
using eSuite.Core.Miscellaneous;
|
using eSuite.Core.Miscellaneous;
|
||||||
|
|
||||||
namespace e_suite.API.Common;
|
namespace e_suite.API.Common;
|
||||||
|
|
||||||
public class GetWorkflowTemplateVersion : IGeneralId
|
|
||||||
{
|
|
||||||
public GetWorkflowTemplateVersion()
|
|
||||||
{
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
public GetWorkflowTemplateVersion(WorkflowVersion workflowVersion)
|
|
||||||
{
|
|
||||||
Id = workflowVersion.Id;
|
|
||||||
Guid = workflowVersion.Guid;
|
|
||||||
Deleted = workflowVersion.Deleted;
|
|
||||||
ActivityNameTemplate = workflowVersion.ActivityNameTemplate;
|
|
||||||
Description = workflowVersion.Description;
|
|
||||||
DomainId = workflowVersion.Domain.ToGeneralIdRef()!;
|
|
||||||
LastUpdated = workflowVersion.LastUpdated;
|
|
||||||
Version = workflowVersion.Version;
|
|
||||||
WorkflowId = workflowVersion.Workflow.ToGeneralIdRef()!;
|
|
||||||
WorkflowName = workflowVersion.Workflow.Name;
|
|
||||||
Tasks = workflowVersion.Tasks;
|
|
||||||
}
|
|
||||||
|
|
||||||
public List<TaskDefinition> Tasks { get; set; } = [];
|
|
||||||
|
|
||||||
public string WorkflowName { get; set; } = string.Empty;
|
|
||||||
|
|
||||||
public GeneralIdRef WorkflowId { get; set; } = null!;
|
|
||||||
|
|
||||||
public long Version { get; set; }
|
|
||||||
|
|
||||||
public DateTimeOffset LastUpdated { get; set; }
|
|
||||||
|
|
||||||
public GeneralIdRef DomainId { get; set; } = null!;
|
|
||||||
|
|
||||||
public string Description { get; set; } = string.Empty;
|
|
||||||
|
|
||||||
public string ActivityNameTemplate { get; set; } = string.Empty;
|
|
||||||
|
|
||||||
public bool Deleted { get; set; }
|
|
||||||
|
|
||||||
public long Id { get; set; }
|
|
||||||
public Guid Guid { get; set; }
|
|
||||||
}
|
|
||||||
|
|
||||||
public class PatchWorkflowTemplateVersion
|
|
||||||
{
|
|
||||||
|
|
||||||
public string? WorkflowName { get; set; }
|
|
||||||
|
|
||||||
public GeneralIdRef? DomainId { get; set; }
|
|
||||||
|
|
||||||
public string? Description { get; set; }
|
|
||||||
|
|
||||||
public string? ActivityNameTemplate { get; set; }
|
|
||||||
}
|
|
||||||
|
|
||||||
public class CreateWorkflowTemplateVersion
|
|
||||||
{
|
|
||||||
public List<TaskDefinition> Tasks { get; set; } = [];
|
|
||||||
|
|
||||||
public required string WorkflowName { get; set; }
|
|
||||||
|
|
||||||
public required GeneralIdRef DomainId { get; set; }
|
|
||||||
|
|
||||||
public string Description { get; set; } = String.Empty;
|
|
||||||
|
|
||||||
public required string ActivityNameTemplate { get; set; } = String.Empty;
|
|
||||||
}
|
|
||||||
|
|
||||||
public class TaskMetadata
|
|
||||||
{
|
|
||||||
public string TaskType { get; set; }
|
|
||||||
public string DisplayName { get; set; }
|
|
||||||
public List<string> Capabilities { get; set; } = [];
|
|
||||||
|
|
||||||
public string OutcomeLabel { get; set; }
|
|
||||||
public List<string> Outcomes { get; set; } = [];
|
|
||||||
}
|
|
||||||
|
|
||||||
public interface IWorkflowTemplateManager
|
public interface IWorkflowTemplateManager
|
||||||
{
|
{
|
||||||
Task<PaginatedData<GetWorkflowTemplate>> GetWorkflowTemplatesAsync(Paging paging, CancellationToken cancellationToken);
|
Task<PaginatedData<GetWorkflowTemplate>> GetWorkflowTemplatesAsync(Paging paging, CancellationToken cancellationToken);
|
||||||
@ -97,4 +15,5 @@ public interface IWorkflowTemplateManager
|
|||||||
Task PostTemplateVersion(AuditUserDetails auditUserDetails, CreateWorkflowTemplateVersion template, CancellationToken cancellationToken);
|
Task PostTemplateVersion(AuditUserDetails auditUserDetails, CreateWorkflowTemplateVersion template, CancellationToken cancellationToken);
|
||||||
Task DeleteTemplateVersion(AuditUserDetails auditUserDetails, IGeneralIdRef templateId, CancellationToken cancellationToken);
|
Task DeleteTemplateVersion(AuditUserDetails auditUserDetails, IGeneralIdRef templateId, CancellationToken cancellationToken);
|
||||||
Task<List<TaskMetadata>> GetAllowedTaskMetadataList(string taskType, CancellationToken cancellationToken);
|
Task<List<TaskMetadata>> GetAllowedTaskMetadataList(string taskType, CancellationToken cancellationToken);
|
||||||
|
Task DeleteTemplate(AuditUserDetails auditUserDetails, GeneralIdRef templateId, CancellationToken cancellationToken);
|
||||||
}
|
}
|
||||||
@ -0,0 +1,15 @@
|
|||||||
|
using eSuite.Core.Miscellaneous;
|
||||||
|
|
||||||
|
namespace e_suite.API.Common;
|
||||||
|
|
||||||
|
public class PatchWorkflowTemplateVersion
|
||||||
|
{
|
||||||
|
|
||||||
|
public string? WorkflowName { get; set; }
|
||||||
|
|
||||||
|
public GeneralIdRef? DomainId { get; set; }
|
||||||
|
|
||||||
|
public string? Description { get; set; }
|
||||||
|
|
||||||
|
public string? ActivityNameTemplate { get; set; }
|
||||||
|
}
|
||||||
11
e-suite.API.Common/e-suite.API.Common/TaskMetadata.cs
Normal file
11
e-suite.API.Common/e-suite.API.Common/TaskMetadata.cs
Normal file
@ -0,0 +1,11 @@
|
|||||||
|
namespace e_suite.API.Common;
|
||||||
|
|
||||||
|
public class TaskMetadata
|
||||||
|
{
|
||||||
|
public string TaskType { get; set; }
|
||||||
|
public string DisplayName { get; set; }
|
||||||
|
public List<string> Capabilities { get; set; } = [];
|
||||||
|
|
||||||
|
public string OutcomeLabel { get; set; }
|
||||||
|
public List<string> Outcomes { get; set; } = [];
|
||||||
|
}
|
||||||
@ -11,4 +11,5 @@ public interface IWorkflowTemplateRepository : IRepository
|
|||||||
Task EditWorkflowVersionAsync(AuditUserDetails auditUserDetails, WorkflowVersion workflowVersion, CancellationToken cancellationToken);
|
Task EditWorkflowVersionAsync(AuditUserDetails auditUserDetails, WorkflowVersion workflowVersion, CancellationToken cancellationToken);
|
||||||
Task AddWorkflow(AuditUserDetails auditUserDetails, Database.Core.Tables.Workflow.Workflow workflow, CancellationToken cancellationToken);
|
Task AddWorkflow(AuditUserDetails auditUserDetails, Database.Core.Tables.Workflow.Workflow workflow, CancellationToken cancellationToken);
|
||||||
Task AddWorkflowVersion(AuditUserDetails auditUserDetails, WorkflowVersion workflowVersion, CancellationToken cancellationToken);
|
Task AddWorkflowVersion(AuditUserDetails auditUserDetails, WorkflowVersion workflowVersion, CancellationToken cancellationToken);
|
||||||
|
Task EditWorkflowAsync(AuditUserDetails auditUserDetails, Database.Core.Tables.Workflow.Workflow workflow, CancellationToken cancellationToken);
|
||||||
}
|
}
|
||||||
@ -39,6 +39,26 @@ public class WorkflowTemplateController : ESuiteControllerBase
|
|||||||
return Ok(result);
|
return Ok(result);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Use this to deactivate a template
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="email"></param>
|
||||||
|
/// <param name="cancellationToken"></param>
|
||||||
|
[Route("template")]
|
||||||
|
[HttpDelete]
|
||||||
|
[ProducesResponseType(StatusCodes.Status200OK)]
|
||||||
|
[ProducesResponseType(StatusCodes.Status404NotFound, Type = typeof(ProblemDetails))]
|
||||||
|
[ProducesResponseType(StatusCodes.Status400BadRequest, Type = typeof(ProblemDetails))]
|
||||||
|
[AccessKey(SecurityAccess.DeleteWorkflowTemplate)]
|
||||||
|
public async Task<IActionResult> DeleteWorkflowTemplate(
|
||||||
|
[FromBody] GeneralIdRef templateId,
|
||||||
|
CancellationToken cancellationToken = default!
|
||||||
|
)
|
||||||
|
{
|
||||||
|
await _workflowTemplateManager.DeleteTemplate(AuditUserDetails, templateId, cancellationToken);
|
||||||
|
return Ok();
|
||||||
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Get a list of workflow templates
|
/// Get a list of workflow templates
|
||||||
/// </summary>
|
/// </summary>
|
||||||
|
|||||||
@ -46,4 +46,9 @@ public class WorkflowTemplateRepository : RepositoryBase, IWorkflowTemplateRepos
|
|||||||
DatabaseDbContext.WorkflowVersions.Add(workflowVersion);
|
DatabaseDbContext.WorkflowVersions.Add(workflowVersion);
|
||||||
await DatabaseDbContext.SaveChangesAsync(auditUserDetails, cancellationToken);
|
await DatabaseDbContext.SaveChangesAsync(auditUserDetails, cancellationToken);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public async Task EditWorkflowAsync(AuditUserDetails auditUserDetails, Database.Core.Tables.Workflow.Workflow workflow, CancellationToken cancellationToken)
|
||||||
|
{
|
||||||
|
await DatabaseDbContext.SaveChangesAsync(auditUserDetails, cancellationToken);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
@ -168,15 +168,13 @@ public class WorkflowTemplateManager : IWorkflowTemplateManager
|
|||||||
};
|
};
|
||||||
|
|
||||||
//This will attempt to parse the data onto the internal workflow structure.
|
//This will attempt to parse the data onto the internal workflow structure.
|
||||||
//Workflow.Core.WorkflowVersion? workflowTemplate = _workflowConverter.DeserialiseFromDatabase(dbWorkflowTemplate);
|
Workflow.Core.WorkflowVersion? workflowTemplate = _workflowConverter.DeserialiseFromDatabase(dbWorkflowTemplate);
|
||||||
//if (workflowTemplate is null)
|
if (workflowTemplate is null)
|
||||||
//{
|
{
|
||||||
// throw new InvalidDataException("The workflow template is not valid");
|
throw new InvalidDataException("The workflow template is not valid");
|
||||||
//}
|
}
|
||||||
|
|
||||||
await _workflowTemplateRepository.AddWorkflowVersion(auditUserDetails, dbWorkflowTemplate, cancellationToken);
|
await _workflowTemplateRepository.AddWorkflowVersion(auditUserDetails, dbWorkflowTemplate, cancellationToken);
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
@ -203,7 +201,7 @@ public class WorkflowTemplateManager : IWorkflowTemplateManager
|
|||||||
var workflowVersion =
|
var workflowVersion =
|
||||||
await _workflowTemplateRepository.GetWorkflowVersions()
|
await _workflowTemplateRepository.GetWorkflowVersions()
|
||||||
.FindByGeneralIdRefAsync(generalIdRef, cancellationToken) ??
|
.FindByGeneralIdRefAsync(generalIdRef, cancellationToken) ??
|
||||||
throw new NotFoundException("SsoProvider with this id does not exists");
|
throw new NotFoundException("WorkflowVersion with this id does not exists");
|
||||||
|
|
||||||
var newVersion = await applyChanges(workflowVersion);
|
var newVersion = await applyChanges(workflowVersion);
|
||||||
if (newVersion != workflowVersion)
|
if (newVersion != workflowVersion)
|
||||||
@ -269,4 +267,36 @@ public class WorkflowTemplateManager : IWorkflowTemplateManager
|
|||||||
|
|
||||||
return Task.FromResult(result);
|
return Task.FromResult(result);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private async Task AlterWorkflowTemplateAsync(
|
||||||
|
AuditUserDetails auditUserDetails,
|
||||||
|
IGeneralIdRef generalIdRef,
|
||||||
|
Func<e_suite.Database.Core.Tables.Workflow.Workflow,
|
||||||
|
Task<e_suite.Database.Core.Tables.Workflow.Workflow?>> applyChanges,
|
||||||
|
CancellationToken cancellationToken
|
||||||
|
)
|
||||||
|
{
|
||||||
|
await _workflowTemplateRepository.TransactionAsync(async () =>
|
||||||
|
{
|
||||||
|
var workflow =
|
||||||
|
await _workflowTemplateRepository.GetWorkflows()
|
||||||
|
.FindByGeneralIdRefAsync(generalIdRef, cancellationToken) ??
|
||||||
|
throw new NotFoundException("Workflow with this id does not exists");
|
||||||
|
|
||||||
|
var newWorkflow = await applyChanges(workflow);
|
||||||
|
if (newWorkflow != workflow)
|
||||||
|
await _workflowTemplateRepository.AddWorkflow(auditUserDetails, newWorkflow, cancellationToken);
|
||||||
|
else
|
||||||
|
await _workflowTemplateRepository.EditWorkflowAsync(auditUserDetails, workflow,
|
||||||
|
cancellationToken);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
public async Task DeleteTemplate(AuditUserDetails auditUserDetails, GeneralIdRef templateId, CancellationToken cancellationToken)
|
||||||
|
{
|
||||||
|
await AlterWorkflowTemplateAsync(auditUserDetails, templateId, async version =>
|
||||||
|
{
|
||||||
|
version.Deleted = true;
|
||||||
|
return version;
|
||||||
|
}, cancellationToken);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
@ -59,17 +59,7 @@ public class WorkflowProcessor : IWorkflowProcessor
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
WorkflowVersion workflowVersion;
|
WorkflowVersion workflowVersion = _workflowConverter.DeserialiseFromDatabase(activityInstance.WorkflowVersion);
|
||||||
try
|
|
||||||
{
|
|
||||||
workflowVersion = _workflowConverter.DeserialiseFromDatabase(activityInstance.WorkflowVersion);
|
|
||||||
}
|
|
||||||
catch (Exception e)
|
|
||||||
{
|
|
||||||
_logger.LogError("{DateTime}: Failed to Deserialise Json {messageId} - {messageId}", _clock.GetNow, activityId, e.ToString());
|
|
||||||
throw;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
var hasCompletableTask = false;
|
var hasCompletableTask = false;
|
||||||
|
|
||||||
|
|||||||
@ -83,15 +83,8 @@ public static class TaskExtensions
|
|||||||
else
|
else
|
||||||
{
|
{
|
||||||
// Deserialize JSON into the target type (handles lists, objects, primitives)
|
// Deserialize JSON into the target type (handles lists, objects, primitives)
|
||||||
try
|
|
||||||
{
|
|
||||||
value = JsonSerializer.Deserialize(je.GetRawText(), targetType, jsonSerializerOptions);
|
value = JsonSerializer.Deserialize(je.GetRawText(), targetType, jsonSerializerOptions);
|
||||||
}
|
}
|
||||||
catch (Exception e)
|
|
||||||
{
|
|
||||||
throw;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
prop.SetValue(obj, value);
|
prop.SetValue(obj, value);
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user