Skip to content

Commit

Permalink
feat: remove old check repute url, replace with request to INR VOL-5804
Browse files Browse the repository at this point in the history
  • Loading branch information
ilindsay committed Mar 3, 2025
1 parent 7cd8ce8 commit 25551b9
Show file tree
Hide file tree
Showing 12 changed files with 322 additions and 276 deletions.
13 changes: 13 additions & 0 deletions app/api/module/Api/data/nr/checkGoodReputeRequestTemplate.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<?xml version="1.0" encoding="UTF-8"?>
<CheckGoodRepute_Request xmlns="https://webgate.ec.testa.eu/move-hub/erru/3.4">
<Header version="3.4" technicalId="afbacb8a-b313-4daa-881b-7b7a65204b69"
workflowId="446940dc-eb68-4462-9424-4893ce051fdb" sentAt="2016-01-01T00:00:00Z"
timeoutValue="2016-01-01T00:00:20Z" from="UK" to="ZZ"/>
<Body businessCaseId="CGR Request Example" originatingAuthority="UK Competent Authority" requestPurpose="Other"
requestSource="Other">
<SearchedTransportManager>
<TransportManagerNameDetails familyName="Creighton-Ward" firstName="Penelope" dateOfBirth="1939-12-24"/>
<TransportManagerCertificateDetails certificateNumber="CPC004" certificateIssueDate="2012-01-31" certificateIssueCountry="UK"/>
</SearchedTransportManager>
</Body>
</CheckGoodRepute_Request>
61 changes: 61 additions & 0 deletions app/api/module/Api/data/nr/checkGoodReputeResponseTemplate.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
<?xml version="1.0" encoding="UTF-8"?>
<CheckGoodRepute_Response xmlns="https://webgate.ec.testa.eu/move-hub/erru/3.4">
<Header version="3.4"
technicalId="f148c54c-488f-42bc-bae1-8eb09e8f7a3f"
workflowId="446940dc-eb68-4462-9424-4893ce051fdb"
sentAt="2016-01-01T00:00:05Z"
from="EU"
to="IE"/>
<Body businessCaseId="CGR Notification Example"
originatingAuthority="UK Competent Authority">
<SearchedTransportManager>
<TransportManagerNameDetails familyName="Creighton-Ward"
firstName="Penelope"
dateOfBirth="1939-12-24"
familyNameSearchKey="CRAGTANWAD"
firstNameSearchKey="PANALAP"/>
<TransportManagerCertificateDetails certificateNumber="CPC004"
certificateIssueDate="2012-01-31"
certificateIssueCountry="UK"/>
</SearchedTransportManager>
<MemberState memberStateCode="AT"
statusCode="NotFound"/>
<MemberState memberStateCode="BE"
statusCode="NotFound"/>
<!-- Multiple other countries -->
<MemberState memberStateCode="UK"
statusCode="Found">
<TransportManagerDetails respondingAuthority=" UK Competent Authority "
searchMethod="CPC">
<TransportManagerNameDetails familyName="Creighton-Ward"
firstName="Penelope"
dateOfBirth="1939-12-24"
placeOfBirth="London"/>
<TransportManagerAddressDetails address="Address Line 1"
postCode="W1"
city="London"
country="UK"/>
<TransportManagerCertificateDetails certificateNumber="CPC004"
certificateIssueDate="2012-01-31"
certificateIssueCountry="UK"
certificateValidity="Invalid">
<Fitness fitnessStatus="Unfit"
unfitStartDate="2015-12-09"
unfitEndDate="2016-06-09"/>
</TransportManagerCertificateDetails>
<TransportUndertakings totalManagedUndertakings="1"
totalManagedVehicles="7">
<TransportUndertaking transportUndertakingName="International Rescue "
numberOfVehicles="7"
communityLicenceNumber="CL-IR-000001-001"
communityLicenceStatus="Active">
<TransportUndertakingAddress address="Tracy Villa"
postCode="SP1"
city="Tracy Island"
country="UK"/>
</TransportUndertaking>
</TransportUndertakings>
</TransportManagerDetails>
</MemberState>
</Body>
</CheckGoodRepute_Response>
4 changes: 2 additions & 2 deletions app/api/module/Api/src/Domain/QueryHandler/Nr/ReputeUrl.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,9 @@ public function handleQuery(QueryInterface $query)
/* @var $transportManager TransportManagerEntity */
$transportManager = $repo->fetchUsingId($query);

if (!$transportManager->hasReputeCheckData()) {
//if (!$transportManager->hasReputeCheckData()) {
return ['reputeUrl' => null];
}
//}

$person = $transportManager->getHomeCd()->getPerson();

Expand Down
16 changes: 7 additions & 9 deletions app/api/module/Api/src/Entity/Tm/TransportManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -362,11 +362,9 @@ public function getMostRecentQualification()
}

/**
* Returns whether the entity has all the necessary date for a repute check
*
* return bool
* Does the entity have all address data for a repute check
*/
public function hasReputeCheckData()
public function hasReputeCheckAddress(): bool
{
// mandatory fields
$fields = [
Expand All @@ -384,14 +382,14 @@ public function hasReputeCheckData()
}
}

//qualifications array collection
if ($this->qualifications->isEmpty()) {
return false;
}

return true;
}

public function hasQualifications(): bool
{
return !$this->qualifications->isEmpty();
}

/**
* Return extra properties when serialzed
*
Expand Down
65 changes: 65 additions & 0 deletions app/api/module/Api/src/Service/Nr/AbstractXmlRequest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
<?php

declare(strict_types=1);

namespace Dvsa\Olcs\Api\Service\Nr;

use Dvsa\Olcs\Api\Domain\Util\DateTime\DateTime as DateTimeExtended;
use Olcs\XmlTools\Xml\XmlNodeBuilder;

class AbstractXmlRequest
{
public const AUTHORITY_TC = 'Traffic Commissioner';

private readonly string $responseDateTime;

private readonly string $timeoutDateTime;

private readonly string $technicalId;

protected string $authority;

public function __construct(protected readonly XmlNodeBuilder $xmlBuilder, private readonly string $erruVersion)
{
$dateTime = new DateTimeExtended();
$this->responseDateTime = $dateTime->format(\DateTime::ATOM);
$this->timeoutDateTime = $dateTime->add(new \DateInterval('PT10S'))->format(\DateTime::ATOM);
$this->technicalId = $this->generateGuid();
$this->authority = self::AUTHORITY_TC;
}

protected function getHeader(string $workflowId, string $memberStateCode): array
{
//if member state was GB, we need to make this UK
$filteredMemberStateCode = ($memberStateCode === 'GB' ? 'UK' : $memberStateCode);

return [
'name' => 'Header',
'attributes' => [
'version' => $this->erruVersion,
'technicalId' => $this->technicalId,
'workflowId' => $workflowId,
'sentAt' => $this->responseDateTime,
'timeoutValue' => $this->timeoutDateTime,
'from' => 'UK',
'to' => $filteredMemberStateCode
],
];
}

protected function generateGuid(): string
{
// com_create_guid is unavailable on our environments
return sprintf(
'%04X%04X-%04X-%04X-%04X-%04X%04X%04X',
mt_rand(0, 65535),
mt_rand(0, 65535),
mt_rand(0, 65535),
mt_rand(16384, 20479),
mt_rand(32768, 49151),
mt_rand(0, 65535),
mt_rand(0, 65535),
mt_rand(0, 65535)
);
}
}
64 changes: 64 additions & 0 deletions app/api/module/Api/src/Service/Nr/CheckGoodRepute.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
<?php

declare(strict_types=1);

namespace Dvsa\Olcs\Api\Service\Nr;

use Dvsa\Olcs\Api\Domain\Exception\ForbiddenException;
use Dvsa\Olcs\Api\Entity\Tm\TransportManager;

class CheckGoodRepute extends AbstractXmlRequest
{
public function create(TransportManager $transportManager): string
{
//must have address information as a minimum
if (!$transportManager->hasReputeCheckAddress()) {
throw new ForbiddenException('No Tm address information available for repute check');
}

$xmlData = [
'Header' => $this->getHeader($this->generateGuid(), 'ZZ'),
'Body' => $this->getBody($transportManager)
];

$this->xmlBuilder->setData($xmlData);
return $this->xmlBuilder->buildTemplate();
}

/**
* Fetches array of information for the xml body
*/
private function getBody(TransportManager $transportManager): array
{
return [
'name' => 'Body',
'attributes' => [
'businessCaseId' => $this->generateGuid(),
'originatingAuthority' => $this->authority,
'requestPurpose' => 'Other',
'requestSource' => 'Other',
],
'nodes' => [
0 => [
'name' => 'SearchedTransportManager',
'nodes' => [
0 => [
'name' => 'TransportUndertakingAddress',
'attributes' => [
'address' => 'address',
'postcode' => 'postcode',
'city' => 'city',
'country' => 'UK',
],
],
],
],
],
];
}

private function getTransportManagerDetails(TransportManager $transportManager): array
{

}
}
32 changes: 32 additions & 0 deletions app/api/module/Api/src/Service/Nr/CheckGoodReputeFactory.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
<?php

namespace Dvsa\Olcs\Api\Service\Nr;

use Olcs\XmlTools\Xml\XmlNodeBuilder;
use Laminas\ServiceManager\Factory\FactoryInterface;
use Psr\Container\ContainerInterface;

class CheckGoodReputeFactory implements FactoryInterface
{
public const XML_NS_MSG = 'No config specified for xml ns';
public const XML_VERSION_MSG = 'No config specified for erru version';
public const ROOT_ELEMENT = 'CheckGoodRepute_Request';

public function __invoke(ContainerInterface $container, $requestedName, array $options = null): CheckGoodRepute
{
$config = $container->get('config');
if (!isset($config['nr']['compliance_episode']['xmlNs'])) {
throw new \RuntimeException(self::XML_NS_MSG);
}

if (!isset($config['nr']['compliance_episode']['erruVersion'])) {
throw new \RuntimeException(self::XML_VERSION_MSG);
}

$ns = $config['nr']['compliance_episode']['xmlNs'];
$erruVersion = $config['nr']['compliance_episode']['erruVersion'];

$xmlBuilder = new XmlNodeBuilder(self::ROOT_ELEMENT, $ns . $erruVersion, []);
return new CheckGoodRepute($xmlBuilder, $erruVersion);
}
}
Loading

0 comments on commit 25551b9

Please sign in to comment.