## S-10c · Close the ZGW zaak on document-timeout expiry (closes #106) Completes the S-10a/S-10b boundary flagged in ADR-0017: when a registration's 30-day document term lapses, the domain now cancels the **ZGW zaak** as well as marking the aggregate `Verlopen`, so OpenZaak and the register no longer diverge. ### What it does On expiry the `ExpireRegistrationWorker` calls the ACL to set the zaak to a distinct, non-terminal **`Geannuleerd`** status with a **`Vervallen`** resultaat (vs the approval `Afgehandeld` + `Geregistreerd`), resolved **by omschrijving** in the ACL — the ACL-first ordering mirrors approval so a failed ZGW call leaves the job for redelivery rather than diverging the two. **Path:** Flowable P30D timer → `RegistratieVerlopen` job → domain `ExpireRegistrationWorker` → ACL `POST /annuleringen` → ZGW `resultaten` + `statussen` (Geannuleerd) → aggregate `Verlopen`. ### Layers touched (each red→green) - **ACL gateway** — `SetZaakToCancellationStatusAsync` (Geannuleerd + Vervallen by name); approval now resolves its `Geregistreerd` resultaat by name too (a second resultaattype now exists). - **ACL service/API** — `AclService.CancelZaakAsync` + `POST /annuleringen`. - **Domain** — `IAclClient.CancelZaakAsync` + client; expiry worker cancels the zaak before advancing to `Verlopen`, guarded against redelivery double-cancel. - **Seed** — non-terminal `Geannuleerd` statustype (volgnummer 2; `Afgehandeld` → 3) + `Vervallen` resultaattype, both idempotent by omschrijving and sharing the zaaktype's procestype. - **Verify/integration** — ACL↔OpenZaak integration test (live `Geannuleerd` + resultaat); `run-domain-check.sh` fires the real P30D timer and asserts the zaak reaches `Geannuleerd` end-to-end; BDD scenario asserts cancel-on-timeout vs untouched-when-in-time. - **Docs** — ADR-0019 (cancellation modelling decision), demo-script, BACKLOG. ### Design note (ADR-0019) ZGW allows only one eindstatus per zaaktype, so `Geannuleerd` is modelled as a **non-terminal** status (it records a cancellation status + resultaat but does not set `einddatum`). This follows the issue's explicit "distinct statustype + resultaat" outcome; the shared-eindstatus alternative is recorded in the ADR. ### Tests Unit + acceptance all green locally (Acl 38, Big 134, Acceptance 17, Bff 33, EventSubscriber 19). Integration + verify-stack run in CI (need live OpenZaak + selectielijst egress). 🤖 Generated with [Claude Code](https://claude.com/claude-code) Reviewed-on: #109
221 lines
9.4 KiB
C#
221 lines
9.4 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));
|
|
}
|