Skip to content
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
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,11 @@ before starting to add changes. Use example [placed in the end of the page](#exa

## [Unreleased]

## [3.15.6] 2024-07-16

- [#120](https://github.com/OS2Forms/os2forms/pull/120)
S2FRMS-100 / OS-74 - changing address fetch API

## [3.15.5] 2024-07-12

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

## [3.15.3] 2024-06-25

Expand Down
23 changes: 10 additions & 13 deletions modules/os2forms_dawa/src/Element/DawaElementAddressMatrikula.php
Original file line number Diff line number Diff line change
Expand Up @@ -114,22 +114,19 @@ private static function getMatrikulaOptions($addressValue, array $element) {
$addressAccessId = $address->getAccessAddressId();

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

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

if ($matrikula) {
$matrikulaOption = $matrikula->getMatrikulaNumber() . ' ' . $matrikula->getOwnershipName();

if (isset($element['#remove_code']) && !$element['#remove_code']) {
$matrikulaOption .= ' (' . $matrikula->getOwnerLicenseCode() . ')';
}

$options[$matrikulaOption] = $matrikulaOption;
if (isset($element['#remove_code']) && !$element['#remove_code']) {
$matrikulaOption .= ' (' . $matrikula->getOwnerLicenseCode() . ')';
}

$options[$matrikulaOption] = $matrikulaOption;
}
}
}
Expand Down
10 changes: 3 additions & 7 deletions modules/os2forms_dawa/src/Entity/DatafordelerMatrikula.php
Original file line number Diff line number Diff line change
Expand Up @@ -41,13 +41,9 @@ class DatafordelerMatrikula {
* Address properties as JSON metadata.
*/
public function __construct(array $json) {
if (isset($json['features']) && is_array($json['features'])) {
$jordstykke = $json['features'][0]['properties']['jordstykke'][0];

$this->ownerLicenseCode = $jordstykke['properties']['ejerlavskode'];
$this->ownershipName = $jordstykke['properties']['ejerlavsnavn'];
$this->matrikulaNumber = $jordstykke['properties']['matrikelnummer'];
}
$this->ownerLicenseCode = $json['properties']['ejerlavskode'];
$this->ownershipName = $json['properties']['ejerlavsnavn'];
$this->matrikulaNumber = $json['properties']['matrikelnummer'];
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

namespace Drupal\os2forms_dawa\Plugin\os2web\DataLookup;

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

$configuration = $this->getConfiguration();
$json = $this->httpClient->request('GET', $url, [
'query' => [
'husnummer' => $addressAccessId,
'status' => 7,
'username' => $configuration['username'],
'password' => $configuration['password'],
'husnummerid' => $addressAccessId,
],
])->getBody();

$jsonDecoded = json_decode($json, TRUE);
if (is_array($jsonDecoded)) {
return $jsonDecoded[0]['jordstykkeList'];
if (NestedArray::keyExists($jsonDecoded, ['gældendeJordstykke', 'jordstykkeLokalId'])) {
return NestedArray::getValue($jsonDecoded, ['gældendeJordstykke', 'jordstykkeLokalId']);
}
}

return [];
return NULL;
}

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

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

$jsonDecoded = json_decode($json, TRUE);

if (is_array($jsonDecoded)) {
return new DatafordelerMatrikula($jsonDecoded);
if (NestedArray::keyExists($jsonDecoded, ['features', 0, 'properties', 'jordstykke'])) {
$jordstykker = NestedArray::getValue($jsonDecoded, ['features', 0, 'properties', 'jordstykke']);
foreach ($jordstykker as $jordstyk) {
$matrikulaEntries[] = new DatafordelerMatrikula($jordstyk);
}
}
}

return NULL;
return $matrikulaEntries;
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

namespace Drupal\os2forms_dawa\Plugin\os2web\DataLookup;

use Drupal\os2forms_dawa\Entity\DatafordelerMatrikula;
use Drupal\os2web_datalookup\Plugin\os2web\DataLookup\DataLookupInterface;

/**
Expand All @@ -20,20 +19,20 @@ interface DatafordelerDataLookupInterface extends DataLookupInterface {
* @param string $addressAccessId
* Address to make search against.
*
* @return array
* @return string|null
* List if IDs.
*/
public function getMatrikulaIds(string $addressAccessId) : array;
public function getMatrikulaId(string $addressAccessId) : ?string;

/**
* Returns matrikule entry that is found byt this ID.
* Returns matrikula entries that is found byt this ID.
*
* @param string $matrikulaId
* Id to make search against.
*
* @return \Drupal\os2forms_dawa\Entity\DatafordelerMatrikula|null
* Matrikula entry or NULL.
* @return array
* Matrikula entries list.
*/
public function getMatrikulaEntry(string $matrikulaId) : ?DatafordelerMatrikula;
public function getMatrikulaEntries(string $matrikulaId) : array;

}