Skip to content

Commit 899d60e

Browse files
committed
Misc
1 parent 1d54a80 commit 899d60e

5 files changed

Lines changed: 38 additions & 41 deletions

File tree

modules/os2forms_fordelingskomponent_debug/src/Controller/Os2formsFordelingskomponentDebugForsendelseController.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -139,6 +139,11 @@ private function itemDetails(AnvenderForsendelse $item) {
139139
'#title' => $this->t('Request'),
140140
'#markup' => $this->renderYaml($item->request),
141141
],
142+
[
143+
'#type' => 'item',
144+
'#title' => $this->t('Response'),
145+
'#markup' => $this->renderYaml($item->response),
146+
],
142147
];
143148
}
144149

modules/os2forms_fordelingskomponent_debug/src/Controller/Os2formsFordelingskomponentDebugSftpController.php

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
use Drupal\Core\Url;
88
use Drupal\os2forms_fordelingskomponent\Helper\FordelingskomponentHelper;
99
use Symfony\Component\DependencyInjection\Attribute\Autowire;
10+
use Symfony\Component\HttpFoundation\Request;
1011
use Symfony\Component\HttpFoundation\Response;
1112
use Symfony\Component\Mime\MimeTypeGuesserInterface;
1213

@@ -25,7 +26,7 @@ public function __construct(
2526
/**
2627
* Builds the response.
2728
*/
28-
public function __invoke(?string $dir, ?string $filename = NULL): array|Response {
29+
public function __invoke(Request $request, ?string $dir, ?string $filename = NULL): array|Response {
2930
$sftp = $this->helper->sf2900()->sftp();
3031

3132
if (NULL !== $filename && preg_match('/\.[^.]+$/', $filename)) {
@@ -46,6 +47,10 @@ public function __invoke(?string $dir, ?string $filename = NULL): array|Response
4647
// Filter out . and ..
4748
$files = array_filter($files, static fn (string $name) => !preg_match('/^\.+$/', $name), ARRAY_FILTER_USE_KEY);
4849

50+
if ($filter = ($request->query->all()['filter'] ?? NULL)) {
51+
$files = array_filter($files, static fn (string $filename) => array_all($filter, fn (string $value) => str_contains($filename, $value)), ARRAY_FILTER_USE_KEY);
52+
}
53+
4954
$header = [
5055
'filepath' => $this->t('Path'),
5156
'atime' => $this->t('Last accessed at'),

src/Controller/Fordelingskomponent/FordelingskvitteringModtagController.php

Lines changed: 13 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,10 @@
66

77
use Drupal\Component\Datetime\TimeInterface;
88
use Drupal\Core\Logger\LoggerChannelInterface;
9-
use Drupal\os2forms_fordelingskomponent\Exception\SoapException;
109
use Drupal\os2forms_fordelingskomponent\Model\Fordelingskomponent\AnvenderKvittering;
1110
use Drupal\os2forms_fordelingskomponent\Repository\AnvenderForsendelseRepository;
1211
use Drupal\os2forms_fordelingskomponent\Repository\AnvenderKvitteringRepository;
12+
use ItkDev\Serviceplatformen\SF2900\EnumType\ForretningsValideringsKodeType;
1313
use ItkDev\Serviceplatformen\SF2900\StructType\FordelingskvitteringModtagAnvenderRequestType;
1414
use ItkDev\Serviceplatformen\SF2900\StructType\FordelingskvitteringModtagAnvenderResponseType;
1515
use Symfony\Component\DependencyInjection\Attribute\Autowire;
@@ -49,29 +49,27 @@ public function FordelingskvitteringModtag(
4949
distributionTransaktionsId: $context->getDistributionTransktionsID(),
5050
);
5151
if (NULL === $forsendelse) {
52-
throw new SoapException(sprintf('Forsendelse %s not found.', $context->getAnvenderTransaktionsID()));
52+
$this->logger->warning(sprintf('Kvittering: Forsendelse %s not found.', $context->getAnvenderTransaktionsID()));
5353
}
5454

55-
$forsendelse->deliveredAt = $this->time->getRequestTime();
56-
$this->forsendelseRepository->save($forsendelse);
57-
5855
$response = new FordelingskvitteringModtagAnvenderResponseType();
5956

60-
$kvittering = $this->kvitteringRepository->loadByAnvenderTransaktionsId(
57+
// We may receive multiple receipts.
58+
$kvittering = new AnvenderKvittering(
59+
id: NULL,
6160
anvenderTransaktionsId: $context->getAnvenderTransaktionsID(),
6261
distributionTransaktionsId: $context->getDistributionTransktionsID(),
62+
request: $request,
63+
response: $response,
6364
);
64-
if (NULL === $kvittering) {
65-
$kvittering = new AnvenderKvittering(
66-
anvenderTransaktionsId: $context->getAnvenderTransaktionsID(),
67-
distributionTransaktionsId: $context->getDistributionTransktionsID(),
68-
request: $request,
69-
response: $response,
70-
);
71-
}
72-
7365
$this->kvitteringRepository->save($kvittering);
7466

67+
// @todo Should we set a status code (rather than deliveredAt) on the forsendelse?
68+
if (NULL !== $forsendelse && $request->getForretningskvittering()->getForretningsValideringsKode() === ForretningsValideringsKodeType::VALUE_ACCEPTERET) {
69+
$forsendelse->deliveredAt = $this->time->getRequestTime();
70+
$this->forsendelseRepository->save($forsendelse);
71+
}
72+
7573
return $response;
7674
}
7775

src/Repository/AnvenderForsendelseRepository.php

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ final class AnvenderForsendelseRepository extends AbstractRepository {
2323
* @return \Drupal\os2forms_fordelingskomponent\Model\Fordelingskomponent\AnvenderForsendelse[]
2424
* The list of forsendelser.
2525
*/
26-
private function loadBy(array $conditions = []): array {
26+
private function loadBy(array $conditions = [], array $orderBy = ['created_at' => 'DESC']): array {
2727
$query = $this->database
2828
->select(self::TABLE, 't')
2929
->fields('t');
@@ -32,6 +32,10 @@ private function loadBy(array $conditions = []): array {
3232
$query->condition(...$condition);
3333
}
3434

35+
foreach ($orderBy as $field => $direction) {
36+
$query->orderBy($field, $direction);
37+
}
38+
3539
$statement = $query->execute();
3640
assert(NULL !== $statement);
3741
$result = $statement->fetchAll();

src/Repository/AnvenderKvitteringRepository.php

Lines changed: 9 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -47,21 +47,18 @@ private function loadBy(array $conditions = []): array {
4747

4848
/**
4949
* Load kvittering by transaktions-id.
50+
*
51+
* @return \Drupal\os2forms_fordelingskomponent\Model\Fordelingskomponent\AnvenderKvittering[]
5052
*/
51-
public function loadByAnvenderTransaktionsId(string $anvenderTransaktionsId, ?string $distributionTransaktionsId = NULL): ?AnvenderKvittering {
53+
public function loadByAnvenderTransaktionsId(string $anvenderTransaktionsId, ?string $distributionTransaktionsId = NULL): array {
5254
$criteria = [
5355
['anvender_transaktions_id', $anvenderTransaktionsId],
5456
];
5557
if (NULL !== $distributionTransaktionsId) {
5658
$criteria[] = ['distribution_transaktions_id', $distributionTransaktionsId];
5759
}
58-
$result = $this->loadBy($criteria);
5960

60-
if (1 !== count($result)) {
61-
return NULL;
62-
}
63-
64-
return reset($result);
61+
return $this->loadBy($criteria);
6562
}
6663

6764
/**
@@ -81,23 +78,11 @@ public function save(AnvenderKvittering $kvittering): bool {
8178
'created_at' => $kvittering->createdAt,
8279
'updated_at' => $kvittering->updatedAt,
8380
];
84-
if (NULL === $this->loadByAnvenderTransaktionsId(
85-
anvenderTransaktionsId: $kvittering->anvenderTransaktionsId,
86-
distributionTransaktionsId: $kvittering->distributionTransaktionsId,
87-
)) {
88-
$this->database
89-
->insert(self::TABLE)
90-
->fields($fields)
91-
->execute();
92-
}
93-
else {
94-
$this->database
95-
->update(self::TABLE)
96-
->condition('anvender_transaktions_id', $kvittering->anvenderTransaktionsId)
97-
->condition('distribution_transaktions_id', $kvittering->distributionTransaktionsId)
98-
->fields($fields)
99-
->execute();
100-
}
81+
82+
$this->database
83+
->insert(self::TABLE)
84+
->fields($fields)
85+
->execute();
10186

10287
return TRUE;
10388
}

0 commit comments

Comments
 (0)