Skip to content

Commit 310235e

Browse files
authored
Merge pull request #6504 from ConductionNL/quality/arch-independence-3
refactor(zgw): controllers build ZGW helpers through factories and hold their contracts
2 parents ccd442e + 50cb228 commit 310235e

18 files changed

Lines changed: 589 additions & 25 deletions

‎lib/Controller/BrcController.php‎

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -29,10 +29,11 @@
2929

3030
namespace OCA\Dossiq\Controller;
3131

32+
use OCA\Dossiq\Kernel\Contracts\BrcCrossRegisterSyncInterface;
33+
use OCA\Dossiq\Kernel\Contracts\BrcDocumentLinkHandlerInterface;
3234
use OCA\Dossiq\Kernel\Contracts\SettingsServiceInterface;
3335
use OCA\Dossiq\Kernel\Contracts\ZgwServiceInterface;
34-
use OCA\Dossiq\Service\Zgw\BrcCrossRegisterSync;
35-
use OCA\Dossiq\Service\Zgw\BrcDocumentLinkHandler;
36+
use OCA\Dossiq\Service\Zgw\BrcHelperFactory;
3637
use OCP\AppFramework\Http;
3738
use OCP\AppFramework\Http\Attribute\AnonRateLimit;
3839
use OCP\AppFramework\Http\JSONResponse;
@@ -67,16 +68,16 @@ class BrcController extends ZgwController {
6768
/**
6869
* What the Besluiten API keeps in step in the Zaken and Documenten registers.
6970
*
70-
* @var BrcCrossRegisterSync
71+
* @var BrcCrossRegisterSyncInterface
7172
*/
72-
private readonly BrcCrossRegisterSync $sync;
73+
private readonly BrcCrossRegisterSyncInterface $sync;
7374

7475
/**
7576
* The besluitinformatieobject routes.
7677
*
77-
* @var BrcDocumentLinkHandler
78+
* @var BrcDocumentLinkHandlerInterface
7879
*/
79-
private readonly BrcDocumentLinkHandler $documentLinks;
80+
private readonly BrcDocumentLinkHandlerInterface $documentLinks;
8081

8182
/**
8283
* Constructor.
@@ -96,8 +97,9 @@ public function __construct(
9697
SettingsServiceInterface $settingsService,
9798
) {
9899
parent::__construct(appName: $appName, request: $request);
99-
$this->sync = new BrcCrossRegisterSync(zgwService: $zgwService, settingsService: $settingsService);
100-
$this->documentLinks = new BrcDocumentLinkHandler(zgwService: $zgwService, sync: $this->sync);
100+
$helpers = new BrcHelperFactory();
101+
$this->sync = $helpers->brcCrossRegisterSync(zgwService: $zgwService, settingsService: $settingsService);
102+
$this->documentLinks = $helpers->brcDocumentLinkHandler(zgwService: $zgwService, sync: $this->sync);
101103
}//end __construct()
102104

103105
/**

‎lib/Controller/DrcController.php‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@
3131

3232
use OCA\Dossiq\Kernel\Contracts\ZgwServiceInterface;
3333
use OCA\Dossiq\Service\Zgw\RelationSearch;
34-
use OCA\Dossiq\Service\Zgw\ZgwRuleResults;
34+
use OCA\Dossiq\Service\Zgw\ZtcHelperFactory;
3535
use OCA\Dossiq\Service\Zgw\ZgwSearchScope;
3636
use OCP\AppFramework\Http;
3737
use OCP\AppFramework\Http\Attribute\AnonRateLimit;
@@ -881,7 +881,7 @@ private function deleteStoredFiles(string $uuid): void {
881881
* @return JSONResponse
882882
*/
883883
private function relationCheckNotCompleted(string $uuid, string $cause): JSONResponse {
884-
$refusal = (new ZgwRuleResults(logger: $this->zgwService->getLogger()))
884+
$refusal = (new ZtcHelperFactory())->zgwRuleResults(logger: $this->zgwService->getLogger())
885885
->notVerified(rule: 'drc-008a', object: 'document ' . $uuid, cause: $cause);
886886

887887
return new JSONResponse(

‎lib/Controller/ZtcController.php‎

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -32,9 +32,7 @@
3232

3333
use OCA\Dossiq\Kernel\Contracts\ZgwServiceInterface;
3434
use OCA\Dossiq\Service\Zgw\ValidityDateFilter;
35-
use OCA\Dossiq\Service\Zgw\ZtcCrossReferenceEnricher;
36-
use OCA\Dossiq\Service\Zgw\ZtcTypeNameResolver;
37-
use OCA\Dossiq\Service\Zgw\ZtcUrlValidityFilter;
35+
use OCA\Dossiq\Service\Zgw\ZtcHelperFactory;
3836
use OCP\AppFramework\Http;
3937
use OCP\AppFramework\Http\Attribute\AnonRateLimit;
4038
use OCP\AppFramework\Http\JSONResponse;
@@ -202,7 +200,7 @@ public function create(string $resource): JSONResponse {
202200

203201
// Ztc-010m: For ZIOT, resolve informatieobjecttype by omschrijving if not a UUID/URL.
204202
if ($resource === 'zaaktype-informatieobjecttypen') {
205-
(new ZtcTypeNameResolver(zgwService: $this->zgwService))->resolveInformatieobjecttype(body: $body);
203+
(new ZtcHelperFactory())->ztcTypeNameResolver(zgwService: $this->zgwService)->resolveInformatieobjecttype(body: $body);
206204
}
207205

208206
$response = $this->zgwService->handleCreate(
@@ -407,7 +405,9 @@ public function destroy(string $resource, string $uuid): JSONResponse {
407405
private function enrichCrossReferences(string $resource, array $data): array {
408406
$baseUrl = $this->request->getServerProtocol() . '://' . $this->request->getServerHost() . '/index.php/apps/dossiq/api/zgw/catalogi/v1';
409407

410-
return (new ZtcCrossReferenceEnricher(zgwService: $this->zgwService))->enrich(resource: $resource, data: $data, baseUrl: $baseUrl);
408+
$enricher = (new ZtcHelperFactory())->ztcCrossReferenceEnricher(zgwService: $this->zgwService);
409+
410+
return $enricher->enrich(resource: $resource, data: $data, baseUrl: $baseUrl);
411411
}//end enrichCrossReferences()
412412

413413
/**
@@ -465,7 +465,7 @@ private function presented(string $resource, JSONResponse $response): JSONRespon
465465
* @return array The filtered response data.
466466
*/
467467
private function filterValidUrls(string $resource, array $data): array {
468-
return (new ZtcUrlValidityFilter(zgwService: $this->zgwService))->filter(
468+
return (new ZtcHelperFactory())->ztcUrlValidityFilter(zgwService: $this->zgwService)->filter(
469469
fieldConfigs: self::URL_FILTER_FIELDS[$resource] ?? [],
470470
data: $data,
471471
today: date('Y-m-d')
Lines changed: 93 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,93 @@
1+
<?php
2+
3+
/**
4+
* Contract of BrcCrossRegisterSync
5+
*
6+
* The public surface of BrcCrossRegisterSync that other components call, so they depend
7+
* on this contract instead of the implementation.
8+
*
9+
* @category Kernel
10+
* @package OCA\Dossiq\Kernel\Contracts
11+
* @author Conduction b.v. <info@conduction.nl>
12+
* @copyright 2026 Conduction B.V.
13+
* @license EUPL-1.2 https://joinup.ec.europa.eu/collection/eupl/eupl-text-eupl-12
14+
* @version GIT: <git_id>
15+
* @link https://github.com/ConductionNL/dossiq
16+
*
17+
* SPDX-FileCopyrightText: 2026 Conduction B.V. <info@conduction.nl>
18+
* SPDX-License-Identifier: EUPL-1.2
19+
*/
20+
21+
declare(strict_types=1);
22+
23+
namespace OCA\Dossiq\Kernel\Contracts;
24+
25+
/**
26+
* Contract of BrcCrossRegisterSync.
27+
*
28+
* @category Kernel
29+
* @package OCA\Dossiq\Kernel\Contracts
30+
* @author Conduction b.v. <info@conduction.nl>
31+
* @license EUPL-1.2 https://joinup.ec.europa.eu/collection/eupl/eupl-text-eupl-12
32+
* @link https://github.com/ConductionNL/dossiq
33+
*
34+
* @spec exclude Structural contract, no functional requirement.
35+
*/
36+
interface BrcCrossRegisterSyncInterface {
37+
38+
/**
39+
* Delete ObjectInformatieObjecten from DRC for a given besluit (brc-005b/009).
40+
*
41+
* @param string $decisionUrl The besluit URL to match OIOs against
42+
*
43+
* @return void
44+
* @SuppressWarnings(PHPMD.StaticAccess) ZgwSearchScope::fromMapping() is a named
45+
* constructor on a value object, not a service call. Injecting it would put a
46+
* collaborator in four controllers to answer one question about their own config.
47+
*
48+
* @spec openspec/specs/zgw-business-rules-compliance/spec.md
49+
*/
50+
public function deleteOiosForDecision(string $decisionUrl): void;
51+
52+
/**
53+
* Sync a zaak-besluit relation to ZRC (brc-006).
54+
*
55+
* Creates a "zaakbesluit" record linking the zaak to the besluit
56+
* in the ZRC register.
57+
*
58+
* @param string $caseUrl The zaak URL
59+
* @param string $decisionUrl The besluit URL
60+
*
61+
* @return void
62+
*
63+
* @spec openspec/specs/zgw-business-rules-compliance/spec.md
64+
*/
65+
public function syncCaseDecisionToZrc(string $caseUrl, string $decisionUrl): void;
66+
67+
/**
68+
* Create an ObjectInformatieObject in the DRC register (brc-005a).
69+
*
70+
* @param string $decisionUrl The besluit URL (full ZGW URL)
71+
* @param string $ioUrl The informatieobject URL (full ZGW URL)
72+
*
73+
* @return void
74+
*
75+
* @spec openspec/specs/zgw-business-rules-compliance/spec.md
76+
*/
77+
public function createOioInDrc(string $decisionUrl, string $ioUrl): void;
78+
79+
/**
80+
* Delete an OIO from DRC matching a specific besluit and informatieobject (brc-005b).
81+
*
82+
* @param string $decisionUrl The besluit URL
83+
* @param string $ioUrl The informatieobject URL
84+
*
85+
* @return void
86+
* @SuppressWarnings(PHPMD.StaticAccess) ZgwSearchScope::fromMapping() is a named
87+
* constructor on a value object, not a service call. Injecting it would put a
88+
* collaborator in four controllers to answer one question about their own config.
89+
*
90+
* @spec openspec/specs/zgw-business-rules-compliance/spec.md
91+
*/
92+
public function deleteOioByDecisionAndIo(string $decisionUrl, string $ioUrl): void;
93+
}//end interface
Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
1+
<?php
2+
3+
/**
4+
* Contract of BrcDocumentLinkHandler
5+
*
6+
* The public surface of BrcDocumentLinkHandler that other components call, so they depend
7+
* on this contract instead of the implementation.
8+
*
9+
* @category Kernel
10+
* @package OCA\Dossiq\Kernel\Contracts
11+
* @author Conduction b.v. <info@conduction.nl>
12+
* @copyright 2026 Conduction B.V.
13+
* @license EUPL-1.2 https://joinup.ec.europa.eu/collection/eupl/eupl-text-eupl-12
14+
* @version GIT: <git_id>
15+
* @link https://github.com/ConductionNL/dossiq
16+
*
17+
* SPDX-FileCopyrightText: 2026 Conduction B.V. <info@conduction.nl>
18+
* SPDX-License-Identifier: EUPL-1.2
19+
*/
20+
21+
declare(strict_types=1);
22+
23+
namespace OCA\Dossiq\Kernel\Contracts;
24+
25+
use OCP\AppFramework\Http\JSONResponse;
26+
use OCP\IRequest;
27+
28+
/**
29+
* Contract of BrcDocumentLinkHandler.
30+
*
31+
* @category Kernel
32+
* @package OCA\Dossiq\Kernel\Contracts
33+
* @author Conduction b.v. <info@conduction.nl>
34+
* @license EUPL-1.2 https://joinup.ec.europa.eu/collection/eupl/eupl-text-eupl-12
35+
* @link https://github.com/ConductionNL/dossiq
36+
*
37+
* @spec exclude Structural contract, no functional requirement.
38+
*/
39+
interface BrcDocumentLinkHandlerInterface {
40+
41+
/**
42+
* Create a BesluitInformatieObject with cross-register OIO sync (brc-005a).
43+
*
44+
* After creating the BIO, also creates an ObjectInformatieObject in the
45+
* DRC register with objectType=besluit.
46+
*
47+
* @param IRequest $request The incoming request
48+
*
49+
* @return JSONResponse
50+
*
51+
* @spec openspec/specs/zgw-business-rules-compliance/spec.md
52+
*/
53+
public function create(IRequest $request): JSONResponse;
54+
55+
/**
56+
* Delete a BesluitInformatieObject and its OIO in DRC (brc-005b).
57+
*
58+
* @param IRequest $request The incoming request
59+
* @param string $uuid The BIO UUID to delete
60+
*
61+
* @return JSONResponse
62+
*
63+
* @spec openspec/specs/zgw-business-rules-compliance/spec.md
64+
*/
65+
public function destroy(IRequest $request, string $uuid): JSONResponse;
66+
67+
/**
68+
* List BesluitInformatieObjecten as a plain array (per ZGW spec).
69+
*
70+
* Unlike paginated resources, besluitinformatieobjecten returns a flat array.
71+
*
72+
* @param IRequest $request The incoming request
73+
*
74+
* @return JSONResponse
75+
*
76+
* @spec openspec/specs/zgw-business-rules-compliance/spec.md
77+
*/
78+
public function index(IRequest $request): JSONResponse;
79+
}//end interface
Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
<?php
2+
3+
/**
4+
* Contract of ZgwRuleResults
5+
*
6+
* The public surface of ZgwRuleResults that other components call, so they depend
7+
* on this contract instead of the implementation.
8+
*
9+
* @category Kernel
10+
* @package OCA\Dossiq\Kernel\Contracts
11+
* @author Conduction b.v. <info@conduction.nl>
12+
* @copyright 2026 Conduction B.V.
13+
* @license EUPL-1.2 https://joinup.ec.europa.eu/collection/eupl/eupl-text-eupl-12
14+
* @version GIT: <git_id>
15+
* @link https://github.com/ConductionNL/dossiq
16+
*
17+
* SPDX-FileCopyrightText: 2026 Conduction B.V. <info@conduction.nl>
18+
* SPDX-License-Identifier: EUPL-1.2
19+
*/
20+
21+
declare(strict_types=1);
22+
23+
namespace OCA\Dossiq\Kernel\Contracts;
24+
25+
/**
26+
* Contract of ZgwRuleResults.
27+
*
28+
* @category Kernel
29+
* @package OCA\Dossiq\Kernel\Contracts
30+
* @author Conduction b.v. <info@conduction.nl>
31+
* @license EUPL-1.2 https://joinup.ec.europa.eu/collection/eupl/eupl-text-eupl-12
32+
* @link https://github.com/ConductionNL/dossiq
33+
*
34+
* @spec exclude Structural contract, no functional requirement.
35+
*/
36+
interface ZgwRuleResultsInterface {
37+
38+
/**
39+
* Refuse because a rule could not run its check, and log which rule and which object.
40+
*
41+
* A lookup that ran and found nothing is an answer. A lookup that could not
42+
* run is not, so the rule refuses instead of passing. The refusal carries no
43+
* field errors: nothing in the request is wrong.
44+
*
45+
* @param string $rule The rule, as the standard names it (drc-004).
46+
* @param string $object What the rule was checking.
47+
* @param string $cause Why the check could not run.
48+
*
49+
* @return array{valid: bool, status: int, detail: string, invalidParams: array, enrichedBody: array} With `code` set.
50+
*
51+
* @spec openspec/specs/zgw-business-rules-compliance/spec.md
52+
*/
53+
public function notVerified(string $rule, string $object, string $cause): array;
54+
}//end interface
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
<?php
2+
3+
/**
4+
* Contract of ZtcCrossReferenceEnricher
5+
*
6+
* The public surface of ZtcCrossReferenceEnricher that other components call, so they depend
7+
* on this contract instead of the implementation.
8+
*
9+
* @category Kernel
10+
* @package OCA\Dossiq\Kernel\Contracts
11+
* @author Conduction b.v. <info@conduction.nl>
12+
* @copyright 2026 Conduction B.V.
13+
* @license EUPL-1.2 https://joinup.ec.europa.eu/collection/eupl/eupl-text-eupl-12
14+
* @version GIT: <git_id>
15+
* @link https://github.com/ConductionNL/dossiq
16+
*
17+
* SPDX-FileCopyrightText: 2026 Conduction B.V. <info@conduction.nl>
18+
* SPDX-License-Identifier: EUPL-1.2
19+
*/
20+
21+
declare(strict_types=1);
22+
23+
namespace OCA\Dossiq\Kernel\Contracts;
24+
25+
/**
26+
* Contract of ZtcCrossReferenceEnricher.
27+
*
28+
* @category Kernel
29+
* @package OCA\Dossiq\Kernel\Contracts
30+
* @author Conduction b.v. <info@conduction.nl>
31+
* @license EUPL-1.2 https://joinup.ec.europa.eu/collection/eupl/eupl-text-eupl-12
32+
* @link https://github.com/ConductionNL/dossiq
33+
*
34+
* @spec exclude Structural contract, no functional requirement.
35+
*/
36+
interface ZtcCrossReferenceEnricherInterface {
37+
38+
/**
39+
* Fill a zaaktype's or besluittype's cross-reference lists.
40+
*
41+
* @param string $resource The ZGW resource (`zaaktypen`, `besluittypen`; others pass through)
42+
* @param array $data The outbound-mapped object
43+
* @param string $baseUrl The Catalogi API base URL
44+
*
45+
* @return array The enriched object
46+
*
47+
* @spec openspec/specs/zgw-business-rules-compliance/spec.md
48+
*/
49+
public function enrich(string $resource, array $data, string $baseUrl): array;
50+
}//end interface

0 commit comments

Comments
 (0)