Skip to content

Commit

Permalink
Merge branch 'develop' into release/3.16.0
Browse files Browse the repository at this point in the history
  • Loading branch information
stankut authored Jul 18, 2024
2 parents bbdbba2 + e1eb43c commit 3e02eee
Show file tree
Hide file tree
Showing 51 changed files with 2,200 additions and 71 deletions.
26 changes: 25 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,28 @@ before starting to add changes. Use example [placed in the end of the page](#exa
- Reduntand dependency removing - webform_scheduled_tasks
- Drupal 10 compability fixes

## [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)
Adding child select autopopulate fields

## [3.15.4] 2024-07-08

- [#117](https://github.com/OS2Forms/os2forms/pull/117)
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

- [OS-74] Replacing DAWA matrikula select with Datafordeler select

## [3.15.2] 2024-05-27

- [#108](https://github.com/OS2Forms/os2forms/pull/108)
Expand Down Expand Up @@ -244,7 +266,9 @@ before starting to add changes. Use example [placed in the end of the page](#exa
- Security in case of vulnerabilities.
```

[Unreleased]: https://github.com/OS2Forms/os2forms/compare/3.15.2...HEAD
[Unreleased]: https://github.com/OS2Forms/os2forms/compare/3.15.4...HEAD
[3.15.4]: https://github.com/OS2Forms/os2forms/compare/3.15.3...3.15.4
[3.15.3]: https://github.com/OS2Forms/os2forms/compare/3.15.2...3.15.3
[3.15.2]: https://github.com/OS2Forms/os2forms/compare/3.15.1...3.15.2
[3.15.1]: https://github.com/OS2Forms/os2forms/compare/3.15.0...3.15.1
[3.15.0]: https://github.com/OS2Forms/os2forms/compare/3.14.1...3.15.0
Expand Down
3 changes: 2 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,8 @@
"2733781 - Add Export to Word Support": "https://www.drupal.org/files/issues/2019-11-22/2733781-47.patch"
},
"drupal/webform": {
"Unlock possibility of using Entity print module export to Word": "https://www.drupal.org/files/issues/2020-02-29/3096552-6.patch"
"Unlock possibility of using Entity print module export to Word": "https://www.drupal.org/files/issues/2020-02-29/3096552-6.patch",
"Webform computed element post save alter": "https://www.drupal.org/files/issues/2024-06-25/webform_computed_post_save_field_alter.patch"
},
"drupal/coc_forms_auto_export": {
"3240592 - Problem with phpseclib requirement in 2.x (https://www.drupal.org/project/coc_forms_auto_export/issues/3240592)": "https://www.drupal.org/files/issues/2021-10-04/requirement-namespace-3240592-1.patch",
Expand Down
41 changes: 22 additions & 19 deletions modules/os2forms_dawa/src/Element/DawaElementAddressMatrikula.php
Original file line number Diff line number Diff line change
Expand Up @@ -94,9 +94,14 @@ public static function getCompositeElements(array $element) {
* Array of matrikula options key and the values are identical.
*/
private static function getMatrikulaOptions($addressValue, array $element) {
$options = [];

/** @var \Drupal\os2forms_dawa\Service\DawaService $dawaService */
$dawaService = \Drupal::service('os2forms_dawa.service');

/** @var \Drupal\os2forms_dawa\Plugin\os2web\DataLookup\DatafordelerDataLookupInterface $datafordelerLookup */
$datafordelerLookup = \Drupal::service('plugin.manager.os2web_datalookup')->createInstance('datafordeler_data_lookup');

// Getting address.
$addressParams = new ParameterBag();
$addressParams->set('q', $addressValue);
Expand All @@ -106,29 +111,27 @@ private static function getMatrikulaOptions($addressValue, array $element) {
$address = $dawaService->getSingleAddress($addressParams);

if ($address) {
// Getting matrikula options.
$matrikulaParams = new ParameterBag();
// Getting municipality code from address.
if ($municipality_code = $address->getMunicipalityCode()) {
$matrikulaParams->set('limit_by_municipality', $municipality_code);
}
// Getting property nr from address.
if ($property_nr = $address->getPropertyNumber()) {
$matrikulaParams->set('limit_by_property', $property_nr);
}
// If the matrikula option must not have the code.
if (isset($element['#remove_code'])) {
$matrikulaParams->set('remove_code', $element['#remove_code']);
}
$addressAccessId = $address->getAccessAddressId();

// Get the options.
$matrikulaOptions = $dawaService->getMatrikulaMatches($matrikulaParams);
// Find matrikula list from the houseid (husnummer):
$matrikulaId = $datafordelerLookup->getMatrikulaId($addressAccessId);

// Use values as keys.
return array_combine($matrikulaOptions, $matrikulaOptions);
// Find Matrikula entries from matrikulas ID.
if ($matrikulaId) {
$matrikulaEnties = $datafordelerLookup->getMatrikulaEntries($matrikulaId);
foreach ($matrikulaEnties as $matrikula) {
$matrikulaOption = $matrikula->getMatrikulaNumber() . ' ' . $matrikula->getOwnershipName();

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

$options[$matrikulaOption] = $matrikulaOption;
}
}
}

return [];
return $options;
}

/**
Expand Down
79 changes: 79 additions & 0 deletions modules/os2forms_dawa/src/Entity/DatafordelerMatrikula.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
<?php

namespace Drupal\os2forms_dawa\Entity;

/**
* Class DatafordelerMatrikula.
*
* Wrapper class for Datafordeler matrikula object that easies
* the matrikula property access.
*/
class DatafordelerMatrikula {

/**
* Owner licence code / ejerlavskode.
*
* @var string
*/
protected string $ownerLicenseCode;

/**
* Ownership name / ejerlavsnavn.
*
* @var string
*/
protected string $ownershipName;


/**
* Matrikula number / matrikelnummer.
*
* @var string
*/
protected string $matrikulaNumber;

/**
* DawaAddress constructor.
*
* Fills the property from the provided JSON metadata.
*
* @param array $json
* Address properties as JSON metadata.
*/
public function __construct(array $json) {
$this->ownerLicenseCode = $json['properties']['ejerlavskode'];
$this->ownershipName = $json['properties']['ejerlavsnavn'];
$this->matrikulaNumber = $json['properties']['matrikelnummer'];
}

/**
* Returns owner licence code.
*
* @return string
* Owners licence code.
*/
public function getOwnerLicenseCode(): string {
return $this->ownerLicenseCode;
}

/**
* Returns ownership name.
*
* @return string
* ownership name.
*/
public function getOwnershipName(): string {
return $this->ownershipName;
}

/**
* Returns makrikula number.
*
* @return string
* Matrikula number
*/
public function getMatrikulaNumber(): string {
return $this->matrikulaNumber;
}

}
18 changes: 18 additions & 0 deletions modules/os2forms_dawa/src/Entity/DawaAddress.php
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,13 @@ class DawaAddress {
*/
protected $longitude;

/**
* Address access ID.
*
* @var string
*/
protected $accessAddressId;

/**
* DawaAddress constructor.
*
Expand All @@ -61,6 +68,7 @@ public function __construct(array $json) {
$this->propertyNumber = $json['adgangsadresse']['esrejendomsnr'];
$this->longitude = $json['adgangsadresse']['adgangspunkt']['koordinater'][0];
$this->latitude = $json['adgangsadresse']['adgangspunkt']['koordinater'][1];
$this->accessAddressId = $json['adgangsadresse']['id'];
}
}

Expand Down Expand Up @@ -114,4 +122,14 @@ public function getLongitude() {
return $this->longitude;
}

/**
* Gets Address access ID.
*
* @return string
* Address access ID.
*/
public function getAccessAddressId() {
return $this->accessAddressId;
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,144 @@
<?php

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;
use Drupal\os2web_datalookup\Plugin\os2web\DataLookup\DataLookupBase;
use GuzzleHttp\ClientInterface;
use Symfony\Component\DependencyInjection\ContainerInterface;

/**
* Defines a plugin for Datafordeler Data.
*
* @DataLookup(
* id = "datafordeler_data_lookup",
* label = @Translation("Datafordeler Address Lookup"),
* )
*/
class DatafordelerDataLookup extends DataLookupBase implements DatafordelerDataLookupInterface, ContainerFactoryPluginInterface {

/**
* The HTTP client to fetch the feed data with.
*
* @var \GuzzleHttp\ClientInterface
*/
protected $httpClient;

/**
* {@inheritdoc}
*/
public function __construct(array $configuration, $plugin_id, $plugin_definition, ClientInterface $httpClient) {
$this->httpClient = $httpClient;
parent::__construct($configuration, $plugin_id, $plugin_definition);
}

/**
* {@inheritdoc}
*/
public static function create(ContainerInterface $container, array $configuration, $plugin_id, $plugin_definition) {
return new static(
$configuration,
$plugin_id,
$plugin_definition,
$container->get('http_client'),
);
}

/**
* {@inheritdoc}
*/
public function getMatrikulaId(string $addressAccessId) : ?string {
$url = "https://services.datafordeler.dk/DAR/DAR/3.0.0/rest/husnummerTilJordstykke";

$json = $this->httpClient->request('GET', $url, [
'query' => [
'husnummerid' => $addressAccessId,
],
])->getBody();

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

return NULL;
}

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

$configuration = $this->getConfiguration();
$json = $this->httpClient->request('GET', $url, [
'query' => [
'jordstykkeid' => $matrikulaId,
'username' => $configuration['username'],
'password' => $configuration['password'],
],
])->getBody();

$jsonDecoded = json_decode($json, TRUE);

if (is_array($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 $matrikulaEntries;
}

/**
* {@inheritdoc}
*/
public function defaultConfiguration() {
return [
'username' => '',
'password' => '',
] + parent::defaultConfiguration();
}

/**
* {@inheritdoc}
*/
public function buildConfigurationForm(array $form, FormStateInterface $form_state) {
$form['username'] = [
'#type' => 'textfield',
'#title' => $this->t('Username for service calls'),
'#default_value' => $this->configuration['username'],
'#required' => TRUE,
'#description' => $this->t('Username required for performing API requests'),
];
$form['password'] = [
'#type' => 'textfield',
'#title' => $this->t('Password for service calls'),
'#default_value' => $this->configuration['password'],
'#required' => TRUE,
'#description' => $this->t('Password required for performing API requests'),
];

return $form;
}

/**
* {@inheritdoc}
*/
public function submitConfigurationForm(array &$form, FormStateInterface $form_state) {
$configuration = $this->getConfiguration();
$configuration['username'] = $form_state->getValue('username');
$configuration['password'] = $form_state->getValue('password');
$this->setConfiguration($configuration);
}

}
Loading

0 comments on commit 3e02eee

Please sign in to comment.