## 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
46 lines
2.5 KiB
C#
46 lines
2.5 KiB
C#
using Big.Domain;
|
|
|
|
namespace Big.Application;
|
|
|
|
/// <summary>
|
|
/// Handles one acquired <c>RegistratieVerlopen</c> external-worker job (S-10a, ADR-0017): load the
|
|
/// registration the job correlates to and expire it to VERLOPEN — the 30-day document-wait timer fired
|
|
/// before the documents arrived, so the case is cancelled. Pure application logic over ports; it knows
|
|
/// nothing of Flowable. The polling loop that feeds it jobs lives in Infrastructure. Mirrors
|
|
/// <see cref="OpenZaakWorker"/>.
|
|
/// </summary>
|
|
public sealed class ExpireRegistrationWorker(IRegistrationStore store, IAclClient acl)
|
|
{
|
|
/// <summary>
|
|
/// Process the job. Idempotent and tolerant of races (§8.6, at-least-once delivery): a job whose
|
|
/// registration is already resolved — a redelivered expiry (VERLOPEN), or one withdrawn/decided
|
|
/// while it waited (INGETROKKEN/INGESCHREVEN/AFGEWEZEN) — is a no-op, so the job still completes
|
|
/// rather than throwing into a redelivery loop. Only a still-open registration is expired. An
|
|
/// unknown registration is an error: it throws, leaving the job un-completed for Flowable to redeliver.
|
|
/// </summary>
|
|
public async Task HandleAsync(RegistratieVerlopenJob job, CancellationToken ct = default)
|
|
{
|
|
ArgumentNullException.ThrowIfNull(job);
|
|
|
|
var registration = await store.GetAsync(job.RegistrationId, ct)
|
|
?? throw new InvalidOperationException(
|
|
$"No registration {job.RegistrationId} for RegistratieVerlopen job {job.JobId}.");
|
|
|
|
// Only a still-open registration lapses; an already-resolved one (expired, or withdrawn/decided
|
|
// while it waited) is left untouched so the job can complete without violating the aggregate.
|
|
if (registration.Status is not (RegistrationStatus.Ingediend or RegistrationStatus.InBehandeling))
|
|
return;
|
|
|
|
// Cancel the ZGW zaak before advancing the aggregate (mirrors the approval path): if the ACL
|
|
// call fails it throws, the aggregate stays open, and the job is redelivered (§8.6) — rather
|
|
// than leaving the aggregate VERLOPEN while the zaak stays open. The status guard above stops a
|
|
// redelivered job from cancelling the zaak twice (a second resultaat would be a 400). A
|
|
// registration expired before its zaak was opened has nothing to cancel.
|
|
if (registration.ZaakUrl is not null)
|
|
await acl.CancelZaakAsync(registration.ZaakUrl, ct);
|
|
|
|
registration.Expire();
|
|
await store.SaveAsync(registration, ct);
|
|
}
|
|
}
|