From c14002e220c6211b2287ee6d4b1064bfffda910f Mon Sep 17 00:00:00 2001 From: Manuel Aranda Date: Thu, 3 Oct 2024 20:20:37 +0200 Subject: [PATCH] refs #759. Adding listener Trace --- config/services/api_platform.yaml | 14 +++++- src/Dto/Output/OrganizationalUnitOutput.php | 4 +- src/Service/CreateTraceService.php | 46 ++++++++++++++++++++ src/Service/UDS/UDSClient.php | 3 +- src/State/Processor/CommandTaskProcessor.php | 13 +++--- 5 files changed, 70 insertions(+), 10 deletions(-) create mode 100644 src/Service/CreateTraceService.php diff --git a/config/services/api_platform.yaml b/config/services/api_platform.yaml index 8b1dc40..e4111f6 100644 --- a/config/services/api_platform.yaml +++ b/config/services/api_platform.yaml @@ -32,7 +32,7 @@ services: api_platform.filter.command.search: parent: 'api_platform.doctrine.orm.search_filter' - arguments: [ { 'id': 'exact', 'name': 'exact'} ] + arguments: [ { 'id': 'exact', 'name': 'partial'} ] tags: [ 'api_platform.filter' ] api_platform.filter.command.boolean: @@ -139,6 +139,18 @@ services: arguments: [ { 'id': 'exact', 'name': 'partial', } ] tags: [ 'api_platform.filter' ] + api_platform.filter.trace.search: + parent: 'api_platform.doctrine.orm.search_filter' + arguments: [ { 'id': 'exact', 'command.id': 'exact', 'client.id': 'exact' } ] + tags: [ 'api_platform.filter' ] + + api_platform.filter.trace.order: + parent: 'api_platform.doctrine.orm.order_filter' + arguments: + $properties: { 'id': ~, 'command': ~ } + $orderParameterName: 'order' + tags: [ 'api_platform.filter' ] + api_platform.filter.user.order: parent: 'api_platform.doctrine.orm.order_filter' arguments: diff --git a/src/Dto/Output/OrganizationalUnitOutput.php b/src/Dto/Output/OrganizationalUnitOutput.php index 98a5dc9..7be1acc 100644 --- a/src/Dto/Output/OrganizationalUnitOutput.php +++ b/src/Dto/Output/OrganizationalUnitOutput.php @@ -59,7 +59,7 @@ final class OrganizationalUnitOutput extends AbstractOutput public ?bool $remotePc = null; #[Groups(['organizational-unit:read'])] - public ?bool $reserved = null; + public ?bool $available = null; #[Groups(['organizational-unit:read'])] public \DateTime $createdAt; @@ -80,7 +80,7 @@ final class OrganizationalUnitOutput extends AbstractOutput $this->capacity = $organizationalUnit->getCapacity(); $this->type = $organizationalUnit->getType(); $this->remotePc = $organizationalUnit->isRemotePc(); - $this->reserved = $organizationalUnit->isReserved(); + $this->available = $organizationalUnit->getRemoteCalendar() && $organizationalUnit->getRemoteCalendar()->isAvailable(); $this->networkSettings = $organizationalUnit->getNetworkSettings() ? new NetworkSettingsOutput($organizationalUnit->getNetworkSettings()) : null; $this->remoteCalendar = $organizationalUnit->getRemoteCalendar() ? new RemoteCalendarOutput($organizationalUnit->getRemoteCalendar()) : null; if ($organizationalUnit->getParent()) { diff --git a/src/Service/CreateTraceService.php b/src/Service/CreateTraceService.php new file mode 100644 index 0000000..cb747d1 --- /dev/null +++ b/src/Service/CreateTraceService.php @@ -0,0 +1,46 @@ +getCommands() as $command) { + foreach ($commandTask->getClients() as $client) { + $trace = new Trace(); + $trace->setClient($client); + $trace->setCommand($command); + $trace->setStatus(TraceStatus::PENDING); + $trace->setExecutedAt($commandTask->getDatetime()); + $this->entityManager->persist($trace); + } + } + + foreach ($commandTask->getCommandGroups() as $commandGroup) { + foreach ($commandTask->getCommands() as $command) { + foreach ($commandTask->getClients() as $client) { + $trace = new Trace(); + $trace->setClient($client); + $trace->setCommand($command); + $trace->setStatus(TraceStatus::PENDING); + $trace->setExecutedAt($commandTask->getDatetime()); + $this->entityManager->persist($trace); + } + } + } + + $this->entityManager->flush(); + } +} \ No newline at end of file diff --git a/src/Service/UDS/UDSClient.php b/src/Service/UDS/UDSClient.php index 95ee9c6..071cc56 100644 --- a/src/Service/UDS/UDSClient.php +++ b/src/Service/UDS/UDSClient.php @@ -149,8 +149,7 @@ class UDSClient } $remoteCalendar = $organizationalUnit->getRemoteCalendar(); - $aux = $remoteCalendar->isAvailable(); - if (!$remoteCalendar || !$aux) { + if (!$remoteCalendar || !$remoteCalendar->isAvailable()) { return 0; } diff --git a/src/State/Processor/CommandTaskProcessor.php b/src/State/Processor/CommandTaskProcessor.php index bad348b..fe39109 100644 --- a/src/State/Processor/CommandTaskProcessor.php +++ b/src/State/Processor/CommandTaskProcessor.php @@ -12,12 +12,14 @@ use ApiPlatform\Validator\ValidatorInterface; use App\Dto\Input\CommandTaskInput; use App\Dto\Output\CommandTaskOutput; use App\Repository\CommandTaskRepository; +use App\Service\CreateTraceService; readonly class CommandTaskProcessor implements ProcessorInterface { public function __construct( private CommandTaskRepository $commandTaskRepository, - private ValidatorInterface $validator + private ValidatorInterface $validator, + private CreateTraceService $createTraceService ) { } @@ -51,11 +53,12 @@ readonly class CommandTaskProcessor implements ProcessorInterface $entity = $this->commandTaskRepository->findOneByUuid($uriVariables['uuid']); } - $command = $data->createOrUpdateEntity($entity); - $this->validator->validate($command); - $this->commandTaskRepository->save($command); + $task = $data->createOrUpdateEntity($entity); + $this->validator->validate($task); + $this->commandTaskRepository->save($task); + $this->createTraceService->__invoke($task); - return new CommandTaskOutput($command); + return new CommandTaskOutput($task); } private function processDelete($data, Operation $operation, array $uriVariables = [], array $context = []): null