SubmitRegistration creates the aggregate, persists it, starts the registratie process via the Workflow Client, records the instance id and upserts. OpenZaakWorker loads the correlated registration, opens a zaak via the ACL, attaches it and saves; an unknown registration throws (job redelivered), and an already-opened zaak short- circuits without opening a second one (§8.6). Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
37 lines
1.7 KiB
C#
37 lines
1.7 KiB
C#
using Big.Domain;
|
|
|
|
namespace Big.Application;
|
|
|
|
/// <summary>
|
|
/// Handles one acquired <c>OpenZaakAanmaken</c> external-worker job (ADR-0009): load the registration
|
|
/// the job correlates to, open a zaak for it via the ACL (§8.1), attach the zaak to the aggregate, and
|
|
/// return the zaak URL so the caller can complete the Flowable job. Pure application logic over ports —
|
|
/// it knows nothing of Flowable; the polling loop that feeds it jobs lives in Infrastructure.
|
|
/// </summary>
|
|
public sealed class OpenZaakWorker(IRegistrationStore store, IAclClient acl)
|
|
{
|
|
/// <summary>
|
|
/// Process the job and return the URL of the (existing or newly opened) zaak. Idempotent: if the
|
|
/// registration already has a zaak — a job redelivered after its completion was lost — it returns
|
|
/// that zaak without opening a second one (§8.6, at-least-once delivery). An unknown registration
|
|
/// is an error: it throws, leaving the job un-completed for Flowable to redeliver.
|
|
/// </summary>
|
|
public async Task<Uri> HandleAsync(OpenZaakJob job, CancellationToken ct = default)
|
|
{
|
|
ArgumentNullException.ThrowIfNull(job);
|
|
|
|
var registration = await store.GetAsync(job.RegistrationId, ct)
|
|
?? throw new InvalidOperationException(
|
|
$"No registration {job.RegistrationId} for OpenZaakAanmaken job {job.JobId}.");
|
|
|
|
// A redelivered job whose zaak was already opened completes without opening a second one.
|
|
if (registration.ZaakUrl is not null)
|
|
return registration.ZaakUrl;
|
|
|
|
var zaakUrl = await acl.OpenZaakAsync(registration.Bsn, ct);
|
|
registration.AttachZaak(zaakUrl);
|
|
await store.SaveAsync(registration, ct);
|
|
return zaakUrl;
|
|
}
|
|
}
|