Skip to content

Commit e1eb43c

Browse files
authored
Merge pull request #122 from OS2Forms/release/3.15.6
Release/3.15.6
2 parents c643903 + 8d92335 commit e1eb43c

File tree

5 files changed

+43
-39
lines changed

5 files changed

+43
-39
lines changed

CHANGELOG.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,11 @@ before starting to add changes. Use example [placed in the end of the page](#exa
1111

1212
## [Unreleased]
1313

14+
## [3.15.6] 2024-07-16
15+
16+
- [#120](https://github.com/OS2Forms/os2forms/pull/120)
17+
S2FRMS-100 / OS-74 - changing address fetch API
18+
1419
## [3.15.5] 2024-07-12
1520

1621
- [#111](https://github.com/OS2Forms/os2forms/pull/111)
@@ -22,6 +27,7 @@ before starting to add changes. Use example [placed in the end of the page](#exa
2227
Encrypts all elements if encryption enabled.
2328
- [#114](https://github.com/OS2Forms/os2forms/pull/114)
2429
Encrypted computed elements.
30+
- [OS-74] Updating DAWA matrikula select with Datafordeler select
2531

2632
## [3.15.3] 2024-06-25
2733

modules/os2forms_dawa/src/Element/DawaElementAddressMatrikula.php

Lines changed: 10 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -114,22 +114,19 @@ private static function getMatrikulaOptions($addressValue, array $element) {
114114
$addressAccessId = $address->getAccessAddressId();
115115

116116
// Find matrikula list from the houseid (husnummer):
117-
$matrikulaIdList = $datafordelerLookup->getMatrikulaIds($addressAccessId);
117+
$matrikulaId = $datafordelerLookup->getMatrikulaId($addressAccessId);
118118

119-
// Find Matrikula entry from matrikulas ID.
120-
if (!empty($matrikulaIdList)) {
121-
foreach ($matrikulaIdList as $matrikulaId) {
122-
$matrikula = $datafordelerLookup->getMatrikulaEntry($matrikulaId);
119+
// Find Matrikula entries from matrikulas ID.
120+
if ($matrikulaId) {
121+
$matrikulaEnties = $datafordelerLookup->getMatrikulaEntries($matrikulaId);
122+
foreach ($matrikulaEnties as $matrikula) {
123+
$matrikulaOption = $matrikula->getMatrikulaNumber() . ' ' . $matrikula->getOwnershipName();
123124

124-
if ($matrikula) {
125-
$matrikulaOption = $matrikula->getMatrikulaNumber() . ' ' . $matrikula->getOwnershipName();
126-
127-
if (isset($element['#remove_code']) && !$element['#remove_code']) {
128-
$matrikulaOption .= ' (' . $matrikula->getOwnerLicenseCode() . ')';
129-
}
130-
131-
$options[$matrikulaOption] = $matrikulaOption;
125+
if (isset($element['#remove_code']) && !$element['#remove_code']) {
126+
$matrikulaOption .= ' (' . $matrikula->getOwnerLicenseCode() . ')';
132127
}
128+
129+
$options[$matrikulaOption] = $matrikulaOption;
133130
}
134131
}
135132
}

modules/os2forms_dawa/src/Entity/DatafordelerMatrikula.php

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -41,13 +41,9 @@ class DatafordelerMatrikula {
4141
* Address properties as JSON metadata.
4242
*/
4343
public function __construct(array $json) {
44-
if (isset($json['features']) && is_array($json['features'])) {
45-
$jordstykke = $json['features'][0]['properties']['jordstykke'][0];
46-
47-
$this->ownerLicenseCode = $jordstykke['properties']['ejerlavskode'];
48-
$this->ownershipName = $jordstykke['properties']['ejerlavsnavn'];
49-
$this->matrikulaNumber = $jordstykke['properties']['matrikelnummer'];
50-
}
44+
$this->ownerLicenseCode = $json['properties']['ejerlavskode'];
45+
$this->ownershipName = $json['properties']['ejerlavsnavn'];
46+
$this->matrikulaNumber = $json['properties']['matrikelnummer'];
5147
}
5248

5349
/**

modules/os2forms_dawa/src/Plugin/os2web/DataLookup/DatafordelerDataLookup.php

Lines changed: 18 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
namespace Drupal\os2forms_dawa\Plugin\os2web\DataLookup;
44

5+
use Drupal\Component\Utility\NestedArray;
56
use Drupal\Core\Form\FormStateInterface;
67
use Drupal\Core\Plugin\ContainerFactoryPluginInterface;
78
use Drupal\os2forms_dawa\Entity\DatafordelerMatrikula;
@@ -49,31 +50,30 @@ public static function create(ContainerInterface $container, array $configuratio
4950
/**
5051
* {@inheritdoc}
5152
*/
52-
public function getMatrikulaIds(string $addressAccessId) : array {
53-
$url = "https://services.datafordeler.dk/BBR/BBRPublic/1/rest/grund";
53+
public function getMatrikulaId(string $addressAccessId) : ?string {
54+
$url = "https://services.datafordeler.dk/DAR/DAR/3.0.0/rest/husnummerTilJordstykke";
5455

55-
$configuration = $this->getConfiguration();
5656
$json = $this->httpClient->request('GET', $url, [
5757
'query' => [
58-
'husnummer' => $addressAccessId,
59-
'status' => 7,
60-
'username' => $configuration['username'],
61-
'password' => $configuration['password'],
58+
'husnummerid' => $addressAccessId,
6259
],
6360
])->getBody();
6461

6562
$jsonDecoded = json_decode($json, TRUE);
6663
if (is_array($jsonDecoded)) {
67-
return $jsonDecoded[0]['jordstykkeList'];
64+
if (NestedArray::keyExists($jsonDecoded, ['gældendeJordstykke', 'jordstykkeLokalId'])) {
65+
return NestedArray::getValue($jsonDecoded, ['gældendeJordstykke', 'jordstykkeLokalId']);
66+
}
6867
}
6968

70-
return [];
69+
return NULL;
7170
}
7271

7372
/**
7473
* {@inheritdoc}
7574
*/
76-
public function getMatrikulaEntry(string $matrikulaId) : ?DatafordelerMatrikula {
75+
public function getMatrikulaEntries(string $matrikulaId) : array {
76+
$matrikulaEntries = [];
7777
$url = "https://services.datafordeler.dk/Matriklen2/Matrikel/2.0.0/rest/SamletFastEjendom";
7878

7979
$configuration = $this->getConfiguration();
@@ -86,11 +86,17 @@ public function getMatrikulaEntry(string $matrikulaId) : ?DatafordelerMatrikula
8686
])->getBody();
8787

8888
$jsonDecoded = json_decode($json, TRUE);
89+
8990
if (is_array($jsonDecoded)) {
90-
return new DatafordelerMatrikula($jsonDecoded);
91+
if (NestedArray::keyExists($jsonDecoded, ['features', 0, 'properties', 'jordstykke'])) {
92+
$jordstykker = NestedArray::getValue($jsonDecoded, ['features', 0, 'properties', 'jordstykke']);
93+
foreach ($jordstykker as $jordstyk) {
94+
$matrikulaEntries[] = new DatafordelerMatrikula($jordstyk);
95+
}
96+
}
9197
}
9298

93-
return NULL;
99+
return $matrikulaEntries;
94100
}
95101

96102
/**

modules/os2forms_dawa/src/Plugin/os2web/DataLookup/DatafordelerDataLookupInterface.php

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

33
namespace Drupal\os2forms_dawa\Plugin\os2web\DataLookup;
44

5-
use Drupal\os2forms_dawa\Entity\DatafordelerMatrikula;
65
use Drupal\os2web_datalookup\Plugin\os2web\DataLookup\DataLookupInterface;
76

87
/**
@@ -20,20 +19,20 @@ interface DatafordelerDataLookupInterface extends DataLookupInterface {
2019
* @param string $addressAccessId
2120
* Address to make search against.
2221
*
23-
* @return array
22+
* @return string|null
2423
* List if IDs.
2524
*/
26-
public function getMatrikulaIds(string $addressAccessId) : array;
25+
public function getMatrikulaId(string $addressAccessId) : ?string;
2726

2827
/**
29-
* Returns matrikule entry that is found byt this ID.
28+
* Returns matrikula entries that is found byt this ID.
3029
*
3130
* @param string $matrikulaId
3231
* Id to make search against.
3332
*
34-
* @return \Drupal\os2forms_dawa\Entity\DatafordelerMatrikula|null
35-
* Matrikula entry or NULL.
33+
* @return array
34+
* Matrikula entries list.
3635
*/
37-
public function getMatrikulaEntry(string $matrikulaId) : ?DatafordelerMatrikula;
36+
public function getMatrikulaEntries(string $matrikulaId) : array;
3837

3938
}

0 commit comments

Comments
 (0)