diff --git a/config/packages/serializer/Centreon/Monitoring.Resource.yml b/config/packages/serializer/Centreon/Monitoring.Resource.yml index 27c68896b8a..d5bf0bead7d 100644 --- a/config/packages/serializer/Centreon/Monitoring.Resource.yml +++ b/config/packages/serializer/Centreon/Monitoring.Resource.yml @@ -33,11 +33,6 @@ Centreon\Domain\Monitoring\Resource: groups: - 'resource_main' - 'resource_parent' - detailsUrl: - type: string - groups: - - 'resource_main' - - 'resource_parent' icon: type: Centreon\Domain\Monitoring\Icon groups: @@ -64,6 +59,11 @@ Centreon\Domain\Monitoring\Resource: type: string groups: - 'resource_main' + detailsEndpoint: + type: string + groups: + - 'resource_main' + - 'resource_parent' acknowledgementEndpoint: type: string groups: diff --git a/src/Centreon/Application/Controller/MonitoringResourceController.php b/src/Centreon/Application/Controller/MonitoringResourceController.php index ad3f903d02a..ac9dd74261c 100644 --- a/src/Centreon/Application/Controller/MonitoringResourceController.php +++ b/src/Centreon/Application/Controller/MonitoringResourceController.php @@ -162,6 +162,28 @@ public function list( ->findResources($filter); foreach ($resources as $resource) { + // set paths to endpoints + $routeNameAcknowledgement = 'centreon_application_acknowledgement_addhostacknowledgement'; + $routeNameDowntime = 'monitoring.downtime.addHostDowntime'; + $routeNameDetails = 'centreon_application_monitoring_resource_details_host'; + + $parameters = [ + 'hostId' => $resource->getId(), + ]; + + if ($resource->getType() === Resource::TYPE_SERVICE && $resource->getParent()) { + $routeNameAcknowledgement = 'centreon_application_acknowledgement_addserviceacknowledgement'; + $routeNameDowntime = 'monitoring.downtime.addServiceDowntime'; + $routeNameDetails = 'centreon_application_monitoring_resource_details_service'; + + $parameters['hostId'] = $resource->getParent()->getId(); + $parameters['serviceId'] = $resource->getId(); + } + + $resource->setAcknowledgementEndpoint($this->router->generate($routeNameAcknowledgement, $parameters)); + $resource->setDowntimeEndpoint($this->router->generate($routeNameDowntime, $parameters)); + $resource->setDetailsEndpoint($this->router->generate($routeNameDetails, $parameters)); + if ($resource->getParent() != null) { $parameters = [ 'hostId' => $resource->getParent()->getId(), @@ -183,6 +205,14 @@ public function list( $parameters ) ); + + $resource->getParent() + ->setDetailsEndpoint($this->router->generate( + 'centreon_application_monitoring_resource_details_host', + [ + 'hostId' => $resource->getParent()->getId(), + ] + )); } } diff --git a/src/Centreon/Domain/Monitoring/Resource.php b/src/Centreon/Domain/Monitoring/Resource.php index a2eb992d405..a945d35ff04 100644 --- a/src/Centreon/Domain/Monitoring/Resource.php +++ b/src/Centreon/Domain/Monitoring/Resource.php @@ -62,11 +62,6 @@ class Resource */ private $name; - /** - * @var string|null - */ - private $detailsUrl; - /** * @var \Centreon\Domain\Monitoring\Icon|null */ @@ -102,6 +97,11 @@ class Resource */ private $acknowledgementEndpoint; + /** + * @var string|null + */ + private $detailsEndpoint; + /** * @var string|null */ @@ -261,25 +261,6 @@ public function setName(?string $name): self return $this; } - /** - * @return string|null - */ - public function getDetailsUrl(): ?string - { - return $this->detailsUrl; - } - - /** - * @param string|null $detailsUrl - * @return \Centreon\Domain\Monitoring\Resource - */ - public function setDetailsUrl(?string $detailsUrl): self - { - $this->detailsUrl = $detailsUrl ?: null; - - return $this; - } - /** * @return \Centreon\Domain\Monitoring\Icon|null */ @@ -413,6 +394,25 @@ public function setAcknowledgementEndpoint(string $acknowledgementEndpoint): sel return $this; } + /** + * @return string|null + */ + public function getDetailsEndpoint(): ?string + { + return $this->detailsEndpoint; + } + + /** + * @param string|null $detailsEndpoint + * @return \Centreon\Domain\Monitoring\Resource + */ + public function setDetailsEndpoint(?string $detailsEndpoint): self + { + $this->detailsEndpoint = $detailsEndpoint ?: null; + + return $this; + } + /** * @return string|null */ diff --git a/src/Centreon/Domain/Monitoring/ResourceService.php b/src/Centreon/Domain/Monitoring/ResourceService.php index 5ec93f7ea88..a0e4d08ce7f 100644 --- a/src/Centreon/Domain/Monitoring/ResourceService.php +++ b/src/Centreon/Domain/Monitoring/ResourceService.php @@ -54,24 +54,16 @@ class ResourceService extends AbstractCentreonService implements ResourceService */ private $accessGroupRepository; - /** - * @var UrlGeneratorInterface - */ - private $router; - /** * @param ResourceRepositoryInterface $resourceRepository * @param AccessGroupRepositoryInterface $accessGroupRepository - * @param UrlGeneratorInterface $router */ public function __construct( ResourceRepositoryInterface $resourceRepository, - AccessGroupRepositoryInterface $accessGroupRepository, - UrlGeneratorInterface $router + AccessGroupRepositoryInterface $accessGroupRepository ) { $this->resourceRepository = $resourceRepository; $this->accessGroupRepository = $accessGroupRepository; - $this->router = $router; } /** @@ -102,26 +94,6 @@ public function findResources(ResourceFilter $filter): array throw new ResourceException('Error while searching for resources', 0, $ex); } - // set paths to endpoints - foreach ($list as $resource) { - $routeNameAcknowledgement = 'centreon_application_acknowledgement_addhostacknowledgement'; - $routeNameDowntime = 'monitoring.downtime.addHostDowntime'; - $parameters = [ - 'hostId' => $resource->getId(), - ]; - - if ($resource->getType() === Resource::TYPE_SERVICE && $resource->getParent()) { - $routeNameAcknowledgement = 'centreon_application_acknowledgement_addserviceacknowledgement'; - $routeNameDowntime = 'monitoring.downtime.addServiceDowntime'; - - $parameters['hostId'] = $resource->getParent()->getId(); - $parameters['serviceId'] = $resource->getId(); - } - - $resource->setAcknowledgementEndpoint($this->router->generate($routeNameAcknowledgement, $parameters)); - $resource->setDowntimeEndpoint($this->router->generate($routeNameDowntime, $parameters)); - } - return $list; } diff --git a/src/Centreon/Infrastructure/Monitoring/ResourceRepositoryRDB.php b/src/Centreon/Infrastructure/Monitoring/ResourceRepositoryRDB.php index 6f092baf113..3debf9177ed 100644 --- a/src/Centreon/Infrastructure/Monitoring/ResourceRepositoryRDB.php +++ b/src/Centreon/Infrastructure/Monitoring/ResourceRepositoryRDB.php @@ -73,7 +73,6 @@ final class ResourceRepositoryRDB extends AbstractRepositoryDRB implements Resou 'status_code' => 'resource.status_code', 'status' => 'resource.status_name', 'action_url' => 'resource.action_url', - 'details_url' => 'resource.details_url', 'parent_name' => 'resource.parent_name', 'parent_status' => 'resource.parent_status_name', 'severity_level' => 'resource.severity_level', @@ -255,11 +254,10 @@ public function findResources(ResourceFilter $filter): array $collector = new StatementCollector(); $request = 'SELECT SQL_CALC_FOUND_ROWS ' - . 'resource.id, resource.type, resource.name, ' - . 'resource.details_url, resource.action_url, ' + . 'resource.id, resource.type, resource.name, resource.action_url, ' . 'resource.status_code, resource.status_name, ' // status . 'resource.icon_name, resource.icon_url, ' // icon - . 'resource.parent_id, resource.parent_name, resource.parent_details_url, ' // parent + . 'resource.parent_id, resource.parent_name, ' // parent . 'resource.parent_icon_name, resource.parent_icon_url, ' // parent icon . 'resource.parent_status_code, resource.parent_status_name, ' // parent status . 'resource.severity_level, resource.severity_url, resource.severity_name, ' // severity @@ -446,12 +444,10 @@ protected function prepareQueryForServiceResources(StatementCollector $collector sh.host_id AS `host_id`, s.description AS `name`, s.action_url AS `action_url`, - s.notes_url AS `details_url`, s.icon_image_alt AS `icon_name`, s.icon_image AS `icon_url`, sh.host_id AS `parent_id`, sh.name AS `parent_name`, - sh.notes_url AS `parent_details_url`, sh.icon_image_alt AS `parent_icon_name`, sh.icon_image AS `parent_icon_url`, sh.state AS `parent_status_code`, @@ -599,12 +595,10 @@ protected function prepareQueryForHostResources(StatementCollector $collector, R h.host_id AS `host_id`, h.name AS `name`, h.action_url AS `action_url`, - h.notes_url AS `details_url`, h.icon_image_alt AS `icon_name`, h.icon_image AS `icon_url`, NULL AS `parent_id`, NULL AS `parent_name`, - NULL AS `parent_details_url`, NULL AS `parent_icon_name`, NULL AS `parent_icon_url`, NULL AS `parent_status_code`, diff --git a/tests/php/Centreon/Domain/Monitoring/ResourceServiceTest.php b/tests/php/Centreon/Domain/Monitoring/ResourceServiceTest.php index efcba48e1e2..342c436ea12 100644 --- a/tests/php/Centreon/Domain/Monitoring/ResourceServiceTest.php +++ b/tests/php/Centreon/Domain/Monitoring/ResourceServiceTest.php @@ -26,8 +26,6 @@ use Centreon\Domain\Monitoring\Resource; use Centreon\Domain\Monitoring\ResourceFilter; use Centreon\Domain\Security\Interfaces\AccessGroupRepositoryInterface; -use Centreon\Domain\Monitoring\Interfaces\ResourceServiceInterface; -use Symfony\Component\Routing\Generator\UrlGeneratorInterface; use PHPUnit\Framework\TestCase; class ResourceServiceTest extends TestCase @@ -47,12 +45,8 @@ public function testFindResources() ->willReturn([$resource]); // values returned for the all next tests $accessGroup = $this->createMock(AccessGroupRepositoryInterface::class); - $router = $this->createMock(UrlGeneratorInterface::class); - $router->expects(self::any()) - ->method('generate') - ->willReturn('/api-endpoint'); - $resourceService = new ResourceService($repository, $accessGroup, $router); + $resourceService = new ResourceService($repository, $accessGroup); $resourcesFound = $resourceService->findResources(new ResourceFilter()); $this->assertCount(