refs #759. Adding listener Trace
testing/ogcore-api/pipeline/head This commit looks good Details

develop-jenkins
Manuel Aranda Rosales 2024-10-03 20:20:37 +02:00
parent 179f36ebef
commit c14002e220
5 changed files with 70 additions and 10 deletions

View File

@ -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:

View File

@ -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()) {

View File

@ -0,0 +1,46 @@
<?php
namespace App\Service;
use App\Entity\CommandTask;
use App\Entity\Trace;
use App\Model\TraceStatus;
use Doctrine\ORM\EntityManagerInterface;
readonly class CreateTraceService
{
public function __construct(
private EntityManagerInterface $entityManager
)
{
}
public function __invoke(CommandTask $commandTask): void
{
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);
}
}
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();
}
}

View File

@ -149,8 +149,7 @@ class UDSClient
}
$remoteCalendar = $organizationalUnit->getRemoteCalendar();
$aux = $remoteCalendar->isAvailable();
if (!$remoteCalendar || !$aux) {
if (!$remoteCalendar || !$remoteCalendar->isAvailable()) {
return 0;
}

View File

@ -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