Skip to content

Commit 0a29c00

Browse files
committed
Updated stuff
1 parent c9bf867 commit 0a29c00

4 files changed

Lines changed: 101 additions & 13 deletions

File tree

modules/os2forms_fordelingskomponent_examples/config/install/webform.webform.os2forms_fdk_kp_sp241.yml

Lines changed: 67 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ status: open
33
dependencies:
44
module:
55
- os2forms
6-
- os2forms_permissions_by_term
6+
- os2forms_fordelingskomponent
77
- webform_encrypt
88
- webform_entity_print
99
- webform_revisions
@@ -88,18 +88,31 @@ third_party_settings:
8888
fuldmagt_fuldmagthaverspersonnummer:
8989
encrypt: true
9090
encrypt_profile: webform
91+
dokumenter_overslag:
92+
encrypt: true
93+
encrypt_profile: webform
94+
dokumenter_faktura:
95+
encrypt: true
96+
encrypt_profile: webform
97+
dokumenter_bilag:
98+
encrypt: true
99+
encrypt_profile: webform
100+
kvittering:
101+
encrypt: true
102+
encrypt_profile: webform
91103
weight: 0
92104
open: null
93105
close: null
94106
uid: 1
95107
template: false
96108
archive: false
97109
id: os2forms_fdk_kp_sp241
98-
title: 'Ansøgning om helbredstillæg (SP241)'
110+
title: "SP241 (eksempel): Ansøgning om helbredstillæg"
99111
description: ""
100112
categories:
101113
- KP
102114
- SP
115+
- Eksempel
103116
elements: |-
104117
ansoeger_fornavn:
105118
'#type': textfield
@@ -116,6 +129,7 @@ elements: |-
116129
'#type': textfield
117130
'#title': Personnummer
118131
'#required': true
132+
'#pattern': '\d{10}'
119133
ansoeger_telefonnummer:
120134
'#type': textfield
121135
'#title': Telefonnummer
@@ -133,9 +147,9 @@ elements: |-
133147
GRUPPE_E: 'Gruppe E'
134148
GRUPPE_N: 'Gruppe N'
135149
GRUPPE_S: 'Gruppe S'
136-
GRUPPE_BASIS: 'Basis'
150+
GRUPPE_BASIS: Basis
137151
'#states':
138-
visible:
152+
_visible:
139153
':input[name="sygeforsikring"]':
140154
checked: true
141155
required:
@@ -159,7 +173,7 @@ elements: |-
159173
'#type': textfield
160174
'#title': Navn
161175
'#states':
162-
visible:
176+
_visible:
163177
':input[name="fuldmagt"]':
164178
checked: true
165179
required:
@@ -168,13 +182,31 @@ elements: |-
168182
fuldmagt_fuldmagthaverspersonnummer:
169183
'#type': textfield
170184
'#title': Personnummer
185+
'#pattern': '\d{10}'
171186
'#states':
172-
visible:
187+
_visible:
173188
':input[name="fuldmagt"]':
174189
checked: true
175190
required:
176191
':input[name="fuldmagt"]':
177192
checked: true
193+
dokumenter_overslag:
194+
'#type': webform_document_file
195+
'#title': Overslag
196+
dokumenter_faktura:
197+
'#type': webform_document_file
198+
'#title': Faktura
199+
dokumenter_bilag:
200+
'#type': webform_document_file
201+
'#title': Bilag
202+
kvittering:
203+
'#type': os2forms_attachment
204+
'#title': kvittering
205+
'#export_type': pdf
206+
'#digital_signature': 0
207+
'#excluded_elements': { }
208+
'#exclude_empty': 0
209+
'#exclude_empty_checkbox': 0
178210
css: ""
179211
javascript: ""
180212
settings:
@@ -358,5 +390,33 @@ access:
358390
roles: {}
359391
users: {}
360392
permissions: {}
361-
handlers: {}
393+
handlers:
394+
fordelingskomponent_sf2900:
395+
id: os2forms_fordelingskomponent_sf2900
396+
handler_id: fordelingskomponent_sf2900
397+
label: "Fordelingskomponent (sf2900)"
398+
notes: ""
399+
status: true
400+
conditions: {}
401+
weight: 0
402+
settings:
403+
distribution_context:
404+
routing_modtager_aktoer: ""
405+
kle_emne: 32.03.12
406+
handling_facet: G01
407+
brugervendt_noegle: "@todo Skal skjules for “formular“"
408+
titel: "@todo Titel SP241"
409+
beskrivelse: "@todo Beskrivelse\r\n\r\nSe https://rimi-itk.github.io/digitaliseringskataloget.dk/digitaliseringskataloget.dk/sf1415/0.6/Integrationsbeskrivelse_SF1415.pdf#page=14 for at finde formulartype mm.\r\n\r\n”KP – Ekstern Test” er et Netcompany system og har CVR-nr 14814833."
410+
distribution_object:
411+
distribution_type: FORMULAR
412+
journalpost_message: ""
413+
attachment_element: kvittering
414+
formular_type: HelbredstillægAnsøgningFormular_1
415+
files:
416+
filspecifikation: HelbredstillægAnsøgningBilag_1
417+
recipient_it_system_look_up: 1
418+
recipient_it_system: ""
419+
recipient_authority: "14814833"
420+
xml_template: "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\r\n<SP241 xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\">\r\n <Header>\r\n <Myndighed>urn:oio:cvr-nr:{{ handler.settings.sender.sender_id }}</Myndighed>\r\n <ModtagetDato>2026-04-24</ModtagetDato>\r\n <KLE>{{ handler.settings.distribution_context.kle_emne }}</KLE>\r\n {% for file in files.dokumenter_overslag|default([]) %}\r\n <Dokumenter>\r\n <Dokumentnavn>{{ file.sftp_filename }}</Dokumentnavn>\r\n <Dokumenttype>Overslag</Dokumenttype>\r\n </Dokumenter>\r\n {% endfor %}\r\n {% for file in files.dokumenter_faktura|default([]) %}\r\n <Dokumenter>\r\n <Dokumentnavn>{{ file.sftp_filename }}</Dokumentnavn>\r\n <Dokumenttype>Faktura</Dokumenttype>\r\n </Dokumenter>\r\n {% endfor %}\r\n {% for file in files.dokumenter_bilag|default([]) %}\r\n <Dokumenter>\r\n <Dokumentnavn>{{ file.sftp_filename }}</Dokumentnavn>\r\n <Dokumenttype>Bilag</Dokumenttype>\r\n </Dokumenter>\r\n {% endfor %}\r\n </Header>\r\n <AnsoegerOplysninger>\r\n <Ansoeger>\r\n <Fornavn>{{ submission.data.ansoeger_fornavn }}</Fornavn>\r\n {% if submission.data.ansoeger_mellemnavn|default(false) %}\r\n <Mellemnavn>{{ submission.data.ansoeger_mellemnavn }}</Mellemnavn>\r\n {% endif %}\r\n <Efternavn>{{ submission.data.ansoeger_efternavn }}</Efternavn>\r\n <Personnummer>urn:oio:cpr:{{ submission.data.ansoeger_personnummer }}</Personnummer>\r\n </Ansoeger>\r\n </AnsoegerOplysninger>\r\n <Erklaering>Accepteret</Erklaering>\r\n <Underskriftsoplysninger>\r\n <Underskrift>Underskrift0</Underskrift>\r\n <Underskriftsdato>2026-04-26</Underskriftsdato>\r\n </Underskriftsoplysninger>\r\n</SP241>\r\n"
421+
xsd_url: "module://os2forms_fordelingskomponent/resources/SP/SF2900_XSD/SP241.xsd"
362422
variants: {}

src/Helper/FordelingskomponentHelper.php

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -419,12 +419,21 @@ public function sendDokument(
419419
elseif ($dokument instanceof DistributionFormular) {
420420
$files = $dokument->getFileGroups();
421421
$sftp = $sf2900->sftp();
422+
$recipientItSystem = NULL;
423+
if ($handlerSettings->distributionObject->files->recipientItSystemLookUp) {
424+
$routingInfo = $this->getRoutingInfo($handlerSettings);
425+
$system = $routingInfo->getSystemer()->getSystem();
426+
if (1 !== count($system)) {
427+
throw new \RuntimeException('Cannot find single recipient system');
428+
}
429+
$recipientItSystem = $system[0]->getSystemUUID();
430+
}
422431
foreach ($files as $items) {
423432
foreach ($items as $item) {
424433
/** @var \Drupal\file\Entity\File $file */
425434
$file = $item['file'];
426435
$sftp->putFile($file->getFileUri(), $file->getFilename(), $item['sftp_filename']);
427-
$triggerObject = $this->buildTriggerFile($file, $item['sftp_filename'], $handlerSettings, $transactionId);
436+
$triggerObject = $this->buildTriggerFile($file, $item['sftp_filename'], $handlerSettings, $transactionId, recipientItSystem: $recipientItSystem);
428437
$sftp->putContents($triggerObject, $item['sftp_filename'], $item['sftp_filename'] . '.trigger');
429438
}
430439
}
@@ -614,6 +623,7 @@ private function getTransactionContext(
614623
}
615624

616625
// @see https://rimi-itk.github.io/digitaliseringskataloget.dk/digitaliseringskataloget.dk/sf1415/0.6/Integrationsbeskrivelse_SF1415.pdf#page=16
626+
// @todo Generate classes from resources/ServiceContract-SFTP-20230926/xsd/SFTPTypes.xsd.
617627
private const string TRIGGER_FILE_TEMPLATE = <<<'XML'
618628
<?xml version="1.0"?>
619629
<ns2:Trigger xmlns:ns2="http://serviceplatformen.dk/xml/wsdl/soap11/SFTP/1/types">
@@ -643,7 +653,7 @@ private function getTransactionContext(
643653
*
644654
* @see https://rimi-itk.github.io/digitaliseringskataloget.dk/digitaliseringskataloget.dk/sf1415/0.6/Integrationsbeskrivelse_SF1415.pdf
645655
*/
646-
private function buildTriggerFile(File $file, string $sftpFilename, HandlerSettings $handlerSettings, string $transactionId): string {
656+
private function buildTriggerFile(File $file, string $sftpFilename, HandlerSettings $handlerSettings, string $transactionId, ?string $recipientItSystem = NULL): string {
647657
$dom = new \DOMDocument();
648658
$dom->loadXML(self::TRIGGER_FILE_TEMPLATE);
649659
$xpath = new \DOMXPath($dom);
@@ -677,8 +687,7 @@ private function buildTriggerFile(File $file, string $sftpFilename, HandlerSetti
677687
$senderAuthority = 'urn:oio:cvr-nr:' . $handlerSettings->sender->routingMyndighed;
678688
$timestamp = SF2900::formatDateTime(new \DateTimeImmutable());
679689

680-
// @todo Get this from a recipient lookup if not set.
681-
$recipientItSystem = trim((string) $handlerSettings->distributionObject->files->recipientItSystem);
690+
$recipientItSystem = trim((string) ($recipientItSystem ?? $handlerSettings->distributionObject->files->recipientItSystem));
682691
$recipientAuthority = 'urn:oio:cvr-nr:' . $handlerSettings->distributionObject->files->recipientAuthority;
683692

684693
$setValue('//FileContentDescriptor/SFTPDynamicRoutingInfo/InfRef', $infRef);
@@ -694,7 +703,10 @@ private function buildTriggerFile(File $file, string $sftpFilename, HandlerSetti
694703
}
695704
$setValue('//FileContentDescriptor/SFTPDynamicRoutingInfo/RecipientAuthority', $recipientAuthority);
696705

697-
return $dom->saveXML();
706+
$xml = $dom->saveXML();
707+
$this->xmlHelper->validateXml($xml, 'module://os2forms_fordelingskomponent/resources/ServiceContract-SFTP-20230926/xsd/SFTPTypes.xsd');
708+
709+
return $xml;
698710
}
699711

700712
}

src/Plugin/WebformHandler/WebformHandlerSF2900.php

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -252,6 +252,14 @@ private function buildConfigurationFormDistributionObject(): array {
252252
DistributionObjectSettings::DISTRIBUTION_TYPE_FORMULAR,
253253
], require: FALSE);
254254

255+
$section[DistributionObjectSettings::FILES][DistributionObjectFilesSettings::RECIPIENT_IT_SYSTEM_LOOK_UP] = [
256+
'#title' => $this->t('Look up %recipient_it_system based on distribution object routing', [
257+
'%recipient_it_system' => $this->t('Recipient IT system'),
258+
]),
259+
'#type' => 'checkbox',
260+
'#default_value' => $settings->files->recipientItSystemLookUp,
261+
];
262+
255263
$section[DistributionObjectSettings::FILES][DistributionObjectFilesSettings::RECIPIENT_IT_SYSTEM] = [
256264
'#title' => $this->t('Recipient IT system'),
257265
'#type' => 'textfield',
@@ -260,6 +268,11 @@ private function buildConfigurationFormDistributionObject(): array {
260268
],
261269
'#default_value' => $settings->files->recipientItSystem,
262270
'#description' => $this->t('Recipient IT system (UUID). Leave empty for implicit file routing.'),
271+
'#states' => [
272+
'visible' => [
273+
':input[name="settings[' . DistributionObjectSettings::NAME . '][' . DistributionObjectSettings::FILES . '][' . DistributionObjectFilesSettings::RECIPIENT_IT_SYSTEM_LOOK_UP . ']"]' => ['checked' => FALSE],
274+
],
275+
],
263276
];
264277

265278
$section[DistributionObjectSettings::FILES][DistributionObjectFilesSettings::RECIPIENT_AUTHORITY] = [
@@ -268,8 +281,8 @@ private function buildConfigurationFormDistributionObject(): array {
268281
'#attributes' => [
269282
'pattern' => DistributionObjectFilesSettings::RECIPIENT_AUTHORITY_PATTERN,
270283
],
271-
272284
'#default_value' => $settings->files->recipientAuthority,
285+
'#description' => $this->t('CVR for recipient'),
273286
];
274287
$setStates($section[DistributionObjectSettings::FILES][DistributionObjectFilesSettings::RECIPIENT_AUTHORITY], [
275288
DistributionObjectSettings::DISTRIBUTION_TYPE_FORMULAR,

src/Settings/DistributionObjectSettings/FilesSettings.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,9 @@ class FilesSettings extends AbstractSettings {
1717
public const string RECIPIENT_IT_SYSTEM = 'recipient_it_system';
1818
public ?string $recipientItSystem = NULL;
1919

20+
public const string RECIPIENT_IT_SYSTEM_LOOK_UP = 'recipient_it_system_look_up';
21+
public bool $recipientItSystemLookUp = TRUE;
22+
2023
public const string RECIPIENT_AUTHORITY_PATTERN = self::CVR_PATTERN;
2124
public const string RECIPIENT_AUTHORITY = 'recipient_authority';
2225
public ?string $recipientAuthority = '';

0 commit comments

Comments
 (0)