HerregistratieReminderJob (Quartz IJob) fires HerregistratieReminderSweep on a
daily cron wired in Big.Api (overridable via Quartz__Cron), and logs how many
reminders went out. Quartz.NET is used for this time-triggered fleet sweep,
distinct from the queue-draining pumps (ADR-0022). GET /registrations/{id} now
returns herregistratieVoor + herregistratieReminderVerstuurd. The scheduling
shell is excluded from mutation, mirroring the pumps.
refs #18
230 lines
9.9 KiB
C#
230 lines
9.9 KiB
C#
using Big.Application;
|
|
using Big.Domain;
|
|
using Big.Infrastructure;
|
|
|
|
namespace Acceptance.Support;
|
|
|
|
/// <summary>An in-memory Workflow Client for the domain acceptance scenario: it records which
|
|
/// registration a process was started for and returns a fixed instance id. The acceptance test
|
|
/// drives the use case without a running Flowable (live verification is the verify-domain check).</summary>
|
|
public sealed class InMemoryWorkflowClient : IWorkflowClient
|
|
{
|
|
public const string StartedProcessInstanceId = "proc-acc-1";
|
|
|
|
public RegistrationId? StartedFor { get; private set; }
|
|
public DiplomaOrigin? StartedWithOrigin { get; private set; }
|
|
public string? WithdrawnProcessInstanceId { get; private set; }
|
|
public string? CompletedDocumentWaitFor { get; private set; }
|
|
|
|
public Task<string> StartRegistrationProcessAsync(
|
|
RegistrationId registrationId, DiplomaOrigin diplomaOrigin, CancellationToken ct = default)
|
|
{
|
|
StartedFor = registrationId;
|
|
StartedWithOrigin = diplomaOrigin;
|
|
return Task.FromResult(StartedProcessInstanceId);
|
|
}
|
|
|
|
public Task WithdrawProcessAsync(string processInstanceId, CancellationToken ct = default)
|
|
{
|
|
WithdrawnProcessInstanceId = processInstanceId;
|
|
return Task.CompletedTask;
|
|
}
|
|
|
|
public Task CompleteDocumentWaitAsync(string processInstanceId, CancellationToken ct = default)
|
|
{
|
|
CompletedDocumentWaitFor = processInstanceId;
|
|
return Task.CompletedTask;
|
|
}
|
|
}
|
|
|
|
/// <summary>An in-memory ACL stand-in: records the bsn it opened a zaak for and returns a fixed URL,
|
|
/// so the scenario verifies the domain crosses the ACL boundary (§8.1) without a running OpenZaak.</summary>
|
|
public sealed class InMemoryAclClient : IAclClient
|
|
{
|
|
public static readonly Uri OpenedZaakUrl = new("http://openzaak/zaken/api/v1/zaken/acc-zaak");
|
|
|
|
public string? OpenedForBsn { get; private set; }
|
|
public string? OpenedWithReference { get; private set; }
|
|
public Uri? ApprovedZaakUrl { get; private set; }
|
|
|
|
public Task<Uri> OpenZaakAsync(string bsn, string reference, CancellationToken ct = default)
|
|
{
|
|
OpenedForBsn = bsn;
|
|
OpenedWithReference = reference;
|
|
return Task.FromResult(OpenedZaakUrl);
|
|
}
|
|
|
|
public Task ApproveZaakAsync(Uri zaakUrl, CancellationToken ct = default)
|
|
{
|
|
ApprovedZaakUrl = zaakUrl;
|
|
return Task.CompletedTask;
|
|
}
|
|
|
|
public Uri? CancelledZaakUrl { get; private set; }
|
|
|
|
public Task CancelZaakAsync(Uri zaakUrl, CancellationToken ct = default)
|
|
{
|
|
CancelledZaakUrl = zaakUrl;
|
|
return Task.CompletedTask;
|
|
}
|
|
|
|
public (Uri ZaakUrl, string FileName)? StoredDiploma { get; private set; }
|
|
|
|
public Task<Uri> StoreDiplomaAsync(Uri zaakUrl, byte[] content, string fileName, string contentType, CancellationToken ct = default)
|
|
{
|
|
StoredDiploma = (zaakUrl, fileName);
|
|
return Task.FromResult(new Uri("http://openzaak/documenten/api/v1/enkelvoudiginformatieobjecten/acc-doc"));
|
|
}
|
|
}
|
|
|
|
/// <summary>An in-memory user-task client for the beoordeling acceptance scenario: it holds one open
|
|
/// Beoordelen task per registration and records the besluit each is completed with.</summary>
|
|
public sealed class InMemoryUserTaskClient : IUserTaskClient
|
|
{
|
|
private readonly List<BeoordelingTask> _open = [];
|
|
|
|
public (string TaskId, BeoordelingsBesluit Besluit)? Completed { get; private set; }
|
|
|
|
public void Open(RegistrationId registrationId) => _open.Add(new BeoordelingTask($"task-{registrationId}", registrationId));
|
|
|
|
public Task<IReadOnlyList<BeoordelingTask>> GetOpenBeoordelingenAsync(CancellationToken ct = default)
|
|
=> Task.FromResult<IReadOnlyList<BeoordelingTask>>(_open);
|
|
|
|
public Task ClaimAsync(string taskId, string behandelaar, CancellationToken ct = default) => Task.CompletedTask;
|
|
|
|
public Task CompleteBeoordelingAsync(string taskId, BeoordelingsBesluit besluit, CancellationToken ct = default)
|
|
{
|
|
Completed = (taskId, besluit);
|
|
_open.RemoveAll(t => t.TaskId == taskId);
|
|
return Task.CompletedTask;
|
|
}
|
|
}
|
|
|
|
/// <summary>An in-memory Flowable stand-in for the beoordeling-escalation scenario (S-14): it models
|
|
/// one Beoordelen task per process instance — its candidate group and whether it is still open — and
|
|
/// the escalation jobs the non-interrupting 14-day boundary timer parks. It drives the escalation
|
|
/// worker's behaviour without a running Flowable; the timer firing live is the verify-domain check.</summary>
|
|
public sealed class InMemoryEscalatieClient : IBeoordelingEscalatieClient
|
|
{
|
|
private sealed class ParkedTask
|
|
{
|
|
public string CandidateGroup { get; set; } = "behandelaar";
|
|
public bool IsOpen { get; set; } = true;
|
|
}
|
|
|
|
private readonly Dictionary<string, ParkedTask> _tasks = [];
|
|
private readonly List<EscalatieJob> _parked = [];
|
|
private int _seq;
|
|
|
|
/// <summary>A registration parks at Beoordelen, claimable by the behandelaar group.</summary>
|
|
public string ParkBeoordeling()
|
|
{
|
|
var pid = $"pi-{++_seq}";
|
|
_tasks[pid] = new ParkedTask();
|
|
return pid;
|
|
}
|
|
|
|
/// <summary>The behandelaar completes the beoordeling before the timer fires: the task closes.</summary>
|
|
public void CompleteBeoordeling(string processInstanceId) => _tasks[processInstanceId].IsOpen = false;
|
|
|
|
/// <summary>The 14-day boundary timer fires: a non-interrupting token parks an escalation job.</summary>
|
|
public void FireEscalationTimer(string processInstanceId)
|
|
=> _parked.Add(new EscalatieJob($"job-{++_seq}", processInstanceId));
|
|
|
|
/// <summary>The candidate group that may currently pick the task up.</summary>
|
|
public string CandidateGroupFor(string processInstanceId) => _tasks[processInstanceId].CandidateGroup;
|
|
|
|
public Task<IReadOnlyList<EscalatieJob>> AcquireBeoordelingEscalatieJobsAsync(int maxJobs, CancellationToken ct = default)
|
|
=> Task.FromResult<IReadOnlyList<EscalatieJob>>(_parked.Take(maxJobs).ToList());
|
|
|
|
public Task ReassignBeoordelingToTeamleadAsync(string processInstanceId, CancellationToken ct = default)
|
|
{
|
|
// No-op if the behandelaar already completed it — the timer/completion race (§8.6).
|
|
var task = _tasks[processInstanceId];
|
|
if (task.IsOpen)
|
|
task.CandidateGroup = "teamlead";
|
|
return Task.CompletedTask;
|
|
}
|
|
|
|
public Task CompleteBeoordelingEscalatieJobAsync(string jobId, CancellationToken ct = default)
|
|
{
|
|
_parked.RemoveAll(j => j.JobId == jobId);
|
|
return Task.CompletedTask;
|
|
}
|
|
}
|
|
|
|
/// <summary>An in-memory Flowable stand-in for the document-timeout scenario (S-10a): it models one
|
|
/// WachtOpDocumenten wait per process instance — whether it is still open and the registration it
|
|
/// correlates to — and the RegistratieVerlopen jobs the interrupting 30-day boundary timer parks. It
|
|
/// drives the timeout worker's behaviour without a running Flowable; the timer firing live is the
|
|
/// verify-domain check.</summary>
|
|
public sealed class InMemoryDocumentTimeoutClient : IRegistratieVerlopenClient
|
|
{
|
|
private sealed class Wait
|
|
{
|
|
public required RegistrationId RegistrationId { get; init; }
|
|
public bool IsWaiting { get; set; } = true;
|
|
}
|
|
|
|
private readonly Dictionary<string, Wait> _waits = [];
|
|
private readonly List<RegistratieVerlopenJob> _parked = [];
|
|
private int _seq;
|
|
|
|
/// <summary>A registration parks at WachtOpDocumenten, waiting for the citizen's documents.</summary>
|
|
public string ParkWaitingForDocuments(RegistrationId registrationId)
|
|
{
|
|
var pid = $"pi-{++_seq}";
|
|
_waits[pid] = new Wait { RegistrationId = registrationId };
|
|
return pid;
|
|
}
|
|
|
|
/// <summary>The documents arrive before the timer fires: the wait task closes, so the interrupting
|
|
/// timer no longer fires (mirrors the Workflow Client completing WachtOpDocumenten).</summary>
|
|
public void ReceiveDocuments(string processInstanceId) => _waits[processInstanceId].IsWaiting = false;
|
|
|
|
/// <summary>The 30-day interrupting boundary timer fires: if still waiting, it cancels the wait and
|
|
/// parks a RegistratieVerlopen job carrying the correlated registration id. A no-op if the documents
|
|
/// already arrived (the wait/timer race, §8.6).</summary>
|
|
public void FireDocumentTimer(string processInstanceId)
|
|
{
|
|
var wait = _waits[processInstanceId];
|
|
if (!wait.IsWaiting)
|
|
return;
|
|
wait.IsWaiting = false;
|
|
_parked.Add(new RegistratieVerlopenJob($"job-{++_seq}", wait.RegistrationId));
|
|
}
|
|
|
|
public Task<IReadOnlyList<RegistratieVerlopenJob>> AcquireRegistratieVerlopenJobsAsync(int maxJobs, CancellationToken ct = default)
|
|
=> Task.FromResult<IReadOnlyList<RegistratieVerlopenJob>>(_parked.Take(maxJobs).ToList());
|
|
|
|
public Task CompleteRegistratieVerlopenJobAsync(string jobId, CancellationToken ct = default)
|
|
{
|
|
_parked.RemoveAll(j => j.JobId == jobId);
|
|
return Task.CompletedTask;
|
|
}
|
|
}
|
|
|
|
/// <summary>An in-memory registration store for the domain acceptance scenario.</summary>
|
|
public sealed class InMemoryRegistrationStore : IRegistrationStore
|
|
{
|
|
private readonly Dictionary<RegistrationId, Registration> _byId = [];
|
|
|
|
public Task SaveAsync(Registration registration, CancellationToken ct = default)
|
|
{
|
|
_byId[registration.Id] = registration;
|
|
return Task.CompletedTask;
|
|
}
|
|
|
|
public Task<Registration?> GetAsync(RegistrationId id, CancellationToken ct = default)
|
|
=> Task.FromResult(_byId.GetValueOrDefault(id));
|
|
|
|
public Task<Registration?> FindOpenByBsnAsync(string bsn, CancellationToken ct = default)
|
|
=> Task.FromResult(_byId.Values.FirstOrDefault(r =>
|
|
r.Bsn == bsn && r.Status is RegistrationStatus.Ingediend or RegistrationStatus.InBehandeling));
|
|
|
|
public Task<IReadOnlyList<Registration>> FindDueForHerregistratieReminderAsync(
|
|
DateTimeOffset asOf, CancellationToken ct = default)
|
|
=> Task.FromResult<IReadOnlyList<Registration>>(
|
|
_byId.Values.Where(r => r.HerregistratieReminderDue(asOf)).ToList());
|
|
}
|