using FastEndpoints; using FrameworkBLL.WorkFlow; using GB5Shared.DTO.Framework.Login; using GB5Shared.DTO.Framework.ResponseStandard; using GB5Shared.DTO.WorkFlow; using GB5Shared.FastEndPoint; using GB5Shared.WorkFlow.WorkFlowEngine; using static FrameworkDAL.Constant.Constant; using static GB5Shared.DTO.WorkFlow.ContractsDTO; namespace FrameworkSL.Endpoints.WorkFlow { /// /// POST /WorkFlow/CheckApplicability /// /// Checks whether a workflow applies for the given document context /// WITHOUT starting a workflow instance. Used by front-end to decide /// whether to show a "Submit for Approval" button. /// /// Request body — : /// EntityId — MENTITY.ENTITYID /// OUId — Session OU (-1 = any) /// BizTransactionClassId — (-1 = any) /// BizTransactionId — (-1 = any) /// Facts — DTO field values evaluated against EVALCONDITION /// /// Response body — : /// IsEnabled — true when a workflow is applicable /// WorkFlowId — resolved workflow id (0 when none) /// IsFormBasedApproval — whether ISFORMBASEDAPPROVAL is set in config /// public class CheckWorkflowApplicability : BaseEndpoint> { private readonly IWorkFlowBLL _bll; public CheckWorkflowApplicability(IWorkFlowBLL bll) => _bll = bll; public override void Configure() { Post("/WorkFlow/CheckApplicability"); AllowAnonymous(); } public record CheckApplicabilityParameters( [property: FromHeader] string Login, [property: FromBody] WorkflowCheckContext Context ); protected override string? GetCacheKey( CheckApplicabilityParameters req, LoginDTO login) => null; protected override async Task> ExecuteAsync( CheckApplicabilityParameters req, LoginDTO login, CancellationToken ct) { try { if (req.Context.OUId == 0) req.Context.OUId = login.WorkOUId; var result = await _bll.CheckApplicability(req.Context, login); return await GB5Shared.ResponseStandard.Response .CreateSuccessResponse( Newtonsoft.Json.JsonConvert.SerializeObject(result), CacheKeyLevel.NotRequired, login); } catch (WorkflowEngineException ex) { return await GB5Shared.ResponseStandard.Response .CreateExceptionError(ex, CacheKeyLevel.NotRequired, login, ex.Message, 400); } catch (Exception ex) { return await GB5Shared.ResponseStandard.Response .CreateExceptionError(ex, CacheKeyLevel.NotRequired, login, ex.Message, 500); } } } }