Skip to content
This repository was archived by the owner on Nov 27, 2023. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
composer.lock
vendor
1 change: 1 addition & 0 deletions .php-version
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
7.4
21 changes: 21 additions & 0 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,21 @@
}
],
"repositories": [
{
"//": "https://git.drupalcode.org/issue/webform_embed-3149360/-/tree/3149360-automated-drupal-9",
"type": "package",
"package": {
"name": "drupal/webform_embed",
"//": "@see https://github.com/OS2Forms/os2forms/blob/master/composer.json#L27",
"version": "1.x-dev",
"type": "drupal-module",
"source": {
"url": "https://git.drupalcode.org/issue/webform_embed-3149360.git",
"type": "git",
"reference": "3149360-automated-drupal-9"
}
}
},
{
"type": "composer",
"url": "https://packages.drupal.org/8"
Expand Down Expand Up @@ -49,5 +64,11 @@
"coding-standards-apply": [
"@coding-standards-apply/phpcs"
]
},
"config": {
"allow-plugins": {
"dealerdirect/phpcodesniffer-composer-installer": true,
"vaimo/composer-patches": true
}
}
}
2 changes: 2 additions & 0 deletions phpcs.xml.dist
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,9 @@
<description>The coding standard.</description>

<file>.</file>
<exclude-pattern>generated-sources/</exclude-pattern>
<exclude-pattern>vendor/</exclude-pattern>
<exclude-pattern>src/Client/</exclude-pattern>

<!-- Show progress of the run -->
<arg value="p"/>
Expand Down
12 changes: 10 additions & 2 deletions src/Commands/CreatePdf.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ class CreatePdf extends DrushCommands {
/**
* The os2forms_digital_post template manager.
*
* @var TemplateManager
* @var \Drupal\os2forms_digital_post\Manager\TemplateManager
*/
protected TemplateManager $templateManager;

Expand All @@ -27,6 +27,9 @@ class CreatePdf extends DrushCommands {
*/
protected $entityTypeManager;

/**
* Constructor.
*/
public function __construct(TemplateManager $templateManager, EntityTypeManagerInterface $entity_type_manager) {
parent::__construct();
$this->templateManager = $templateManager;
Expand All @@ -49,7 +52,11 @@ public function __construct(TemplateManager $templateManager, EntityTypeManagerI
* @throws \Drupal\Component\Plugin\Exception\InvalidPluginDefinitionException
* @throws \Drupal\Component\Plugin\Exception\PluginNotFoundException
*/
public function create($template, $options = ['submission_id' => 0, 'file_location' => '', 'file_name' => 'test.pdf']) {
public function create($template, array $options = [
'submission_id' => 0,
'file_location' => '',
'file_name' => 'test.pdf',
]) {
$elements[] = [];
$webformLabel = '';
$webform_submission = $this->entityTypeManager->getStorage('webform_submission')->load($options['submission_id']);
Expand Down Expand Up @@ -91,4 +98,5 @@ public function create($template, $options = ['submission_id' => 0, 'file_locati
file_put_contents($filePath, $pdf);
$this->output()->writeln(sprintf('Pdf written to %s', $filePath));
}

}
169 changes: 114 additions & 55 deletions src/Consumer/PrintServiceConsumer.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

namespace Drupal\os2forms_digital_post\Consumer;

use Drupal\Core\Config\ImmutableConfig;
use Drupal\Core\Config\ConfigFactoryInterface;
use Drupal\Core\Lock\LockBackendInterface;
use Drupal\Core\State\State;
Expand All @@ -17,27 +18,64 @@
use Drupal\os2forms_digital_post\Client\StructType\KontaktOplysningType;
use Drupal\os2forms_digital_post\Client\StructType\PrintAfsendBrevRequestType;
use Drupal\os2forms_digital_post\Client\StructType\SlutbrugerIdentitetType;
use Exception;
use ItkDev\Serviceplatformen\Certificate\AzureKeyVaultCertificateLocator;
use ItkDev\Serviceplatformen\Certificate\CertificateLocatorInterface;
use SoapFault;
use WsdlToPhp\PackageBase\AbstractSoapClientBase;
use GuzzleHttp\Client;
use Http\Factory\Guzzle\RequestFactory;
use ItkDev\AzureKeyVault\Authorisation\VaultToken;
use Http\Adapter\Guzzle6\Client as GuzzleAdapter;
use ItkDev\AzureKeyVault\KeyVault\VaultSecret;

/**
* Print service consumer.
*/
class PrintServiceConsumer {

private $config;
private $guzzleClient;
private $lock;
private $state;
/**
* The config.
*
* @var \Drupal\Core\Config\ImmutableConfig
*/
private ImmutableConfig $config;

/**
* The client.
*
* @var \GuzzleHttp\Client
*/
private Client $guzzleClient;

/**
* The lock.
*
* @var \Drupal\Core\Lock\LockBackendInterface
*/
private LockBackendInterface $lock;

/**
* The state.
*
* @var \Drupal\Core\State\State
*/
private State $state;

/**
* The UUID generator.
*
* @var UuidInterface
*/
private $uuid;

/**
* The lock name.
*
* @var string
*/
private $lockName = 'os2forms_digital_post_print_service';

/**
* Constructor.
*/
public function __construct(ConfigFactoryInterface $configFactory, Client $guzzleClient, LockBackendInterface $lock, State $state) {

$this->config = $configFactory->get('os2forms_digital_post');
Expand All @@ -47,25 +85,28 @@ public function __construct(ConfigFactoryInterface $configFactory, Client $guzzl
$this->uuid = \Drupal::service('uuid');
}

/**
* Afsend brev person.
*/
public function afsendBrevPerson(
string $kanalValg = null,
string $prioritet = null,
string $cprNummerIdentifikator = null,
string $personName = null,
string $coNavn = null,
string $streetName = null,
string $streetBuildingIdentifier = null,
string $floorIdentifier = null,
string $suiteIdentifier = null,
string $mailDeliverySublocationIdentifier = null,
string $postCodeIdentifier = null,
string $districtSubdivisionIdentifier = null,
string $postOfficeBoxIdentifier = null,
string $countryIdentificationCode = null,
string $filFormatNavn = null,
string $meddelelseIndholdData = null,
string $titelTekst = null,
string $brevDato = null
string $kanalValg = NULL,
string $prioritet = NULL,
string $cprNummerIdentifikator = NULL,
string $personName = NULL,
string $coNavn = NULL,
string $streetName = NULL,
string $streetBuildingIdentifier = NULL,
string $floorIdentifier = NULL,
string $suiteIdentifier = NULL,
string $mailDeliverySublocationIdentifier = NULL,
string $postCodeIdentifier = NULL,
string $districtSubdivisionIdentifier = NULL,
string $postOfficeBoxIdentifier = NULL,
string $countryIdentificationCode = NULL,
string $filFormatNavn = NULL,
string $meddelelseIndholdData = NULL,
string $titelTekst = NULL,
string $brevDato = NULL
) {

if (!$this->acquireLock()) {
Expand Down Expand Up @@ -94,12 +135,12 @@ public function afsendBrevPerson(
$postCodeIdentifier,
$districtSubdivisionIdentifier,
$postOfficeBoxIdentifier,
null,
null,
null,
null,
null,
null,
NULL,
NULL,
NULL,
NULL,
NULL,
NULL,
$countryIdentificationCodeType
);

Expand All @@ -114,10 +155,10 @@ public function afsendBrevPerson(
$forsendelsesModtager,
$filFormatNavn,
$meddelelseIndholdData,
null,
NULL,
$dokumentParametre,
null,
null,
NULL,
NULL,
$digitalPostParametre
);

Expand All @@ -140,21 +181,24 @@ public function afsendBrevPerson(
AbstractSoapClientBase::WSDL_LOCATION => $this->config->get('service_endpoint'),
]);


$response = $client->afsendBrev($request);

$this->releaseLock();

if (false === $response) {
if (FALSE === $response) {
$lastError = $client->getLastError();
/* @var $soapError SoapFault */
/** @var SoapFault $soapError */
$soapError = $lastError['Drupal\os2forms_digital_post\Client\ServiceType\Afsend::afsendBrev'];
throw new Exception($soapError->getMessage(), $soapError->getCode()); // Should maybe log this instead!
// Should maybe log this instead!
throw new \Exception($soapError->getMessage(), $soapError->getCode());
}

return $response->getResultat();
}

/**
* Get absolute path to certificate.
*/
private function getAzureKeyVaultCertificateLocator(
string $tenantId,
string $applicationId,
Expand Down Expand Up @@ -188,13 +232,16 @@ private function getAzureKeyVaultCertificateLocator(
);
}

/**
* Afsend digital post person.
*/
public function afsendDigitalPostPerson(
string $kanalValg = null,
string $prioritet = null,
string $cprNummerIdentifikator = null,
string $filFormatNavn = null,
string $meddelelseIndholdData = null,
string $titelTekst = null
string $kanalValg = NULL,
string $prioritet = NULL,
string $cprNummerIdentifikator = NULL,
string $filFormatNavn = NULL,
string $meddelelseIndholdData = NULL,
string $titelTekst = NULL
): bool {

if (!$this->acquireLock()) {
Expand All @@ -213,18 +260,18 @@ public function afsendDigitalPostPerson(
$forsendelsesModtager = new ForsendelseModtagerType($slutBrugerIdentitetType);

$dokumentParametre = new DokumentParametreType($titelTekst);
$digitalPostParametre = new DigitalPostParametreType(null, $this->config->get('digital_post_materiale_id'));
$digitalPostParametre = new DigitalPostParametreType(NULL, $this->config->get('digital_post_materiale_id'));

$forsendelse = new ForsendelseIType(
$this->generateAfsendelseIdentifikator(),
null,
NULL,
$forsendelsesModtager,
$filFormatNavn,
$meddelelseIndholdData,
null,
NULL,
$dokumentParametre,
null,
null,
NULL,
NULL,
$digitalPostParametre
);

Expand All @@ -247,21 +294,24 @@ public function afsendDigitalPostPerson(
AbstractSoapClientBase::WSDL_LOCATION => $this->config->get('service_endpoint'),
]);


$response = $client->afsendBrev($request);

$this->releaseLock();

if (false === $response) {
if (FALSE === $response) {
$lastError = $client->getLastError();
/* @var $soapError SoapFault */
/** @var SoapFault $soapError */
$soapError = $lastError['Drupal\os2forms_digital_post\Client\ServiceType\Afsend::afsendBrev'];
throw new \Exception($soapError->getMessage(), $soapError->getCode()); // Should maybe log this instead!
// Should maybe log this instead!
throw new \Exception($soapError->getMessage(), $soapError->getCode());
}

return $response->getResultat();
}

/**
* Generate afsendelse identifikator.
*/
protected function generateAfsendelseIdentifikator(): string {

$stateKey = 'os2forms_digital_post_last_letter_counter';
Expand All @@ -276,19 +326,28 @@ protected function generateAfsendelseIdentifikator(): string {

return $this->config->get('digital_post_system_id')
. $this->config->get('digital_post_afsender_system')
. $nextLetterNumber
;
. $nextLetterNumber;
}

/**
* Acquire lock.
*/
protected function acquireLock(): bool {
return $this->lock->acquire($this->lockName);
}

/**
* Release lock.
*/
protected function releaseLock() {
$this->lock->release($this->lockName);
}

/**
* Wait lock.
*/
protected function waitLock(): bool {
return $this->lock->wait($this->lockName);
}

}
3 changes: 3 additions & 0 deletions src/Exception/CprElementNotFoundInSubmissionException.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@

namespace Drupal\os2forms_digital_post\Exception;

/**
* Cpr Element Not Found In Submission Exception.
*/
class CprElementNotFoundInSubmissionException extends \Exception {

}
Loading