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.Core.Extensions;
|
||||
using e_suite.Database.Core.Models;
|
||||
using e_suite.Database.Core.Tables.Workflow;
|
||||
using e_suite.Utilities.Pagination;
|
||||
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; }
|
||||
}
|
||||
|
||||
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
|
||||
{
|
||||
Task<PaginatedData<GetWorkflowTemplate>> GetWorkflowTemplatesAsync(Paging paging, CancellationToken cancellationToken);
|
||||
@ -97,4 +15,5 @@ public interface IWorkflowTemplateManager
|
||||
Task PostTemplateVersion(AuditUserDetails auditUserDetails, CreateWorkflowTemplateVersion template, CancellationToken cancellationToken);
|
||||
Task DeleteTemplateVersion(AuditUserDetails auditUserDetails, IGeneralIdRef templateId, 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 AddWorkflow(AuditUserDetails auditUserDetails, Database.Core.Tables.Workflow.Workflow workflow, 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);
|
||||
}
|
||||
|
||||
/// <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>
|
||||
/// Get a list of workflow templates
|
||||
/// </summary>
|
||||
|
||||
@ -30,7 +30,7 @@ public class WorkflowTemplateRepository : RepositoryBase, IWorkflowTemplateRepos
|
||||
{
|
||||
await DatabaseDbContext.SaveChangesAsync(auditUserDetails, cancellationToken);
|
||||
}
|
||||
|
||||
|
||||
public async Task AddWorkflow(AuditUserDetails auditUserDetails, Database.Core.Tables.Workflow.Workflow workflow, CancellationToken cancellationToken)
|
||||
{
|
||||
DatabaseDbContext.Workflows.Add(workflow);
|
||||
@ -46,4 +46,9 @@ public class WorkflowTemplateRepository : RepositoryBase, IWorkflowTemplateRepos
|
||||
DatabaseDbContext.WorkflowVersions.Add(workflowVersion);
|
||||
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.
|
||||
//Workflow.Core.WorkflowVersion? workflowTemplate = _workflowConverter.DeserialiseFromDatabase(dbWorkflowTemplate);
|
||||
//if (workflowTemplate is null)
|
||||
//{
|
||||
// throw new InvalidDataException("The workflow template is not valid");
|
||||
//}
|
||||
Workflow.Core.WorkflowVersion? workflowTemplate = _workflowConverter.DeserialiseFromDatabase(dbWorkflowTemplate);
|
||||
if (workflowTemplate is null)
|
||||
{
|
||||
throw new InvalidDataException("The workflow template is not valid");
|
||||
}
|
||||
|
||||
await _workflowTemplateRepository.AddWorkflowVersion(auditUserDetails, dbWorkflowTemplate, cancellationToken);
|
||||
|
||||
|
||||
}
|
||||
);
|
||||
}
|
||||
@ -203,7 +201,7 @@ public class WorkflowTemplateManager : IWorkflowTemplateManager
|
||||
var workflowVersion =
|
||||
await _workflowTemplateRepository.GetWorkflowVersions()
|
||||
.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);
|
||||
if (newVersion != workflowVersion)
|
||||
@ -269,4 +267,36 @@ public class WorkflowTemplateManager : IWorkflowTemplateManager
|
||||
|
||||
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,18 +59,8 @@ public class WorkflowProcessor : IWorkflowProcessor
|
||||
return;
|
||||
}
|
||||
|
||||
WorkflowVersion 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;
|
||||
}
|
||||
WorkflowVersion workflowVersion = _workflowConverter.DeserialiseFromDatabase(activityInstance.WorkflowVersion);
|
||||
|
||||
|
||||
var hasCompletableTask = false;
|
||||
|
||||
await _activityRepository.TransactionAsync(async () =>
|
||||
|
||||
@ -83,14 +83,7 @@ public static class TaskExtensions
|
||||
else
|
||||
{
|
||||
// Deserialize JSON into the target type (handles lists, objects, primitives)
|
||||
try
|
||||
{
|
||||
value = JsonSerializer.Deserialize(je.GetRawText(), targetType, jsonSerializerOptions);
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
throw;
|
||||
}
|
||||
value = JsonSerializer.Deserialize(je.GetRawText(), targetType, jsonSerializerOptions);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Loading…
Reference in New Issue
Block a user