Skip to content

Commit

Permalink
[Task] Load chart data for custom reports (#681)
Browse files Browse the repository at this point in the history
* Added endpoint for chart data

* Apply php-cs-fixer changes

* Added custom exceptions

* Apply php-cs-fixer changes

* Updated exception handling, added IntParameter

* Apply php-cs-fixer changes

* Added schema

* Apply php-cs-fixer changes

* Added doctype comment again to make phpstan happy

* Apply php-cs-fixer changes

* Added pre_response events

* Apply php-cs-fixer changes

* Parameter order

* Naming

* Added phpdocs for exception

* Apply php-cs-fixer changes
  • Loading branch information
mcop1 authored Jan 15, 2025
1 parent f5715a3 commit 32bcee7
Show file tree
Hide file tree
Showing 28 changed files with 892 additions and 130 deletions.
7 changes: 6 additions & 1 deletion config/custom_reports.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -31,4 +31,9 @@ services:
#

Pimcore\Bundle\StudioBackendBundle\CustomReport\Service\CustomReportServiceInterface:
class: Pimcore\Bundle\StudioBackendBundle\CustomReport\Service\CustomReportService
class: Pimcore\Bundle\StudioBackendBundle\CustomReport\Service\CustomReportService

Pimcore\Bundle\StudioBackendBundle\CustomReport\Service\AdapterServiceInterface:
class: Pimcore\Bundle\StudioBackendBundle\CustomReport\Service\AdapterService
arguments:
$adapters: '@pimcore.custom_report.adapter.factories'
6 changes: 5 additions & 1 deletion doc/05_Additional_Custom_Attributes.md
Original file line number Diff line number Diff line change
Expand Up @@ -133,4 +133,8 @@ final class AssetEvent extends AbstractPreResponseEvent
- `pre_response.data_object_version`
- `pre_response.document_version`
- `pre_response.image_version`
- `pre_response.version`
- `pre_response.version`
- `pre_response.custom_report_chart_data`
- `pre_response.custom_report_report`
- `pre_response.custom_report_tree_config_node`
- `pre_response.custom_report_tree_node`
113 changes: 113 additions & 0 deletions src/CustomReport/Controller/Chart/GetController.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,113 @@
<?php
declare(strict_types=1);

/**
* Pimcore
*
* This source file is available under two different licenses:
* - GNU General Public License version 3 (GPLv3)
* - Pimcore Commercial License (PCL)
* Full copyright and license information is available in
* LICENSE.md which is distributed with this source code.
*
* @copyright Copyright (c) Pimcore GmbH (http://www.pimcore.org)
* @license http://www.pimcore.org/license GPLv3 and PCL
*/

namespace Pimcore\Bundle\StudioBackendBundle\CustomReport\Controller\Chart;

use Exception;
use OpenApi\Attributes\Get;
use Pimcore\Bundle\StudioBackendBundle\Asset\OpenApi\Attribute\Parameter\Path\NameParameter;
use Pimcore\Bundle\StudioBackendBundle\Controller\AbstractApiController;
use Pimcore\Bundle\StudioBackendBundle\CustomReport\MappedParameter\ChartDataParameter;
use Pimcore\Bundle\StudioBackendBundle\CustomReport\Schema\CustomReportChartData;
use Pimcore\Bundle\StudioBackendBundle\CustomReport\Service\CustomReportServiceInterface;
use Pimcore\Bundle\StudioBackendBundle\Exception\Api\DatabaseException;
use Pimcore\Bundle\StudioBackendBundle\Exception\Api\NotFoundException;
use Pimcore\Bundle\StudioBackendBundle\OpenApi\Attribute\Content\ItemsJson;
use Pimcore\Bundle\StudioBackendBundle\OpenApi\Attribute\Parameter\Query\FilterParameter;
use Pimcore\Bundle\StudioBackendBundle\OpenApi\Attribute\Parameter\Query\IntParameter;
use Pimcore\Bundle\StudioBackendBundle\OpenApi\Attribute\Parameter\Query\PageParameter;
use Pimcore\Bundle\StudioBackendBundle\OpenApi\Attribute\Parameter\Query\PageSizeParameter;
use Pimcore\Bundle\StudioBackendBundle\OpenApi\Attribute\Parameter\Query\SortOrderParameter;
use Pimcore\Bundle\StudioBackendBundle\OpenApi\Attribute\Parameter\Query\StringParameter;
use Pimcore\Bundle\StudioBackendBundle\OpenApi\Attribute\Response\DefaultResponses;
use Pimcore\Bundle\StudioBackendBundle\OpenApi\Attribute\Response\SuccessResponse;
use Pimcore\Bundle\StudioBackendBundle\OpenApi\Config\Tags;
use Pimcore\Bundle\StudioBackendBundle\Util\Constant\CustomReportPermissions;
use Pimcore\Bundle\StudioBackendBundle\Util\Constant\HttpResponseCodes;
use Symfony\Component\HttpFoundation\JsonResponse;
use Symfony\Component\HttpKernel\Attribute\MapQueryString;
use Symfony\Component\Routing\Attribute\Route;
use Symfony\Component\Security\Http\Attribute\IsGranted;
use Symfony\Component\Serializer\SerializerInterface;

/**
* @internal
*/
final class GetController extends AbstractApiController
{
public function __construct(
SerializerInterface $serializer,
private readonly CustomReportServiceInterface $customReportService
) {
parent::__construct($serializer);
}

/**
* @throws NotFoundException|DatabaseException
* @throws Exception
*/
#[Route('/custom-reports/chart/{name}',
name: 'pimcore_studio_api_custom_reports_chart',
methods: ['GET'])
]
#[IsGranted(CustomReportPermissions::REPORTS->value)]
#[Get(
path: self::PREFIX . '/custom-reports/chart/{name}',
operationId: 'custom_reports_chart',
summary: 'custom_reports_chart_summary',
tags: [Tags::CustomReports->value]
)]
#[NameParameter(
name: 'name',
description: 'custom_reports_chart_name_parameter',
example: 'Quality_Attributes'
)]
#[PageParameter]
#[PageSizeParameter]
#[SortOrderParameter]
#[StringParameter(
name: 'sortBy',
example: '',
description: 'custom_reports_chart_sort_by_parameter',
required: false
)]
#[FilterParameter('chart data')]
#[IntParameter(
name: 'reportOffset',
description: 'custom_reports_chart_report_offset_parameter',
required: false
)]
#[IntParameter(
name: 'reportLimit',
description: 'custom_reports_chart_report_limit_parameter',
required: false
)]
#[SuccessResponse(
description: 'custom_reports_chart_success_response',
content: new ItemsJson(CustomReportChartData::class)
)]
#[DefaultResponses([
HttpResponseCodes::NOT_FOUND,
])]
public function getChartData(
string $name,
#[MapQueryString] ChartDataParameter $chartDataParameter
): JsonResponse {
return $this->jsonResponse(
$this->customReportService->getChartData($name, $chartDataParameter)
);
}
}
2 changes: 1 addition & 1 deletion src/CustomReport/Controller/Config/TreeController.php
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ public function __construct(
#[PageParameter]
#[PageSizeParameter]
#[SuccessResponse(
description: 'custom_report_get_tree_success_response',
description: 'custom_reports_get_tree_success_response',
content: new ItemsJson(CustomReportTreeConfigNode::class)
)]
#[DefaultResponses([
Expand Down
23 changes: 6 additions & 17 deletions src/CustomReport/Controller/GetController.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@
use OpenApi\Attributes\JsonContent;
use Pimcore\Bundle\StudioBackendBundle\Asset\OpenApi\Attribute\Parameter\Path\NameParameter;
use Pimcore\Bundle\StudioBackendBundle\Controller\AbstractApiController;
use Pimcore\Bundle\StudioBackendBundle\CustomReport\Hydrator\CustomReportHydratorInterface;
use Pimcore\Bundle\StudioBackendBundle\CustomReport\Schema\CustomReportDetails;
use Pimcore\Bundle\StudioBackendBundle\CustomReport\Service\CustomReportServiceInterface;
use Pimcore\Bundle\StudioBackendBundle\Exception\Api\DatabaseException;
Expand All @@ -30,7 +29,6 @@
use Pimcore\Bundle\StudioBackendBundle\OpenApi\Attribute\Response\SuccessResponse;
use Pimcore\Bundle\StudioBackendBundle\OpenApi\Config\Tags;
use Pimcore\Bundle\StudioBackendBundle\Util\Constant\HttpResponseCodes;
use Pimcore\Bundle\StudioBackendBundle\Util\Trait\PaginatedResponseTrait;
use Symfony\Component\ExpressionLanguage\Expression;
use Symfony\Component\HttpFoundation\JsonResponse;
use Symfony\Component\Routing\Attribute\Route;
Expand All @@ -42,13 +40,9 @@
*/
final class GetController extends AbstractApiController
{
use PaginatedResponseTrait;

public function __construct(
SerializerInterface $serializer,
private readonly CustomReportServiceInterface $customReportService,
private readonly CustomReportHydratorInterface $customReportHydrator

private readonly CustomReportServiceInterface $customReportService
) {
parent::__construct($serializer);
}
Expand All @@ -68,32 +62,27 @@ public function __construct(
)]
#[Get(
path: self::PREFIX . '/custom-reports/report/{name}',
operationId: 'custom_report_get_by_name',
summary: 'custom_report_get_by_name_summary',
operationId: 'custom_reports_report',
summary: 'custom_reports_report_summary',
tags: [Tags::CustomReports->value]
)]
#[NameParameter(
name: 'name',
description: 'custom_report_get_by_name_name_parameter',
description: 'custom_reports_report_name_parameter',
example: 'Quality_Attributes'
)
]
#[SuccessResponse(
description: 'custom_report_get_by_name_success_response',
description: 'custom_reports_report_success_response',
content: new JsonContent(ref: CustomReportDetails::class)
)]
#[DefaultResponses([
HttpResponseCodes::NOT_FOUND,
])]
public function getByName(string $name): JsonResponse
{
$config = $this->customReportService->getCustomReportByName($name);
if (!$config) {
throw new NotFoundException('Custom report', $name, 'name');
}

return $this->jsonResponse(
$this->customReportHydrator->hydrateCustomReportDetails($config)
$this->customReportService->getCustomReportDetails($name)
);
}
}
2 changes: 1 addition & 1 deletion src/CustomReport/Controller/TreeController.php
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ public function __construct(
#[PageParameter]
#[PageSizeParameter]
#[SuccessResponse(
description: 'custom_report_collection_success_response',
description: 'custom_reports_collection_success_response',
content: new ItemsJson(CustomReportTreeNode::class)
)]
#[DefaultResponses([
Expand Down
39 changes: 39 additions & 0 deletions src/CustomReport/Event/ChartDataEvent.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
<?php
declare(strict_types=1);

/**
* Pimcore
*
* This source file is available under two different licenses:
* - GNU General Public License version 3 (GPLv3)
* - Pimcore Commercial License (PCL)
* Full copyright and license information is available in
* LICENSE.md which is distributed with this source code.
*
* @copyright Copyright (c) Pimcore GmbH (http://www.pimcore.org)
* @license http://www.pimcore.org/license GPLv3 and PCL
*/

namespace Pimcore\Bundle\StudioBackendBundle\CustomReport\Event;

use Pimcore\Bundle\StudioBackendBundle\CustomReport\Schema\CustomReportChartData;
use Pimcore\Bundle\StudioBackendBundle\Event\AbstractPreResponseEvent;

final class ChartDataEvent extends AbstractPreResponseEvent
{
public const EVENT_NAME = 'pre_response.custom_report_chart_data';

public function __construct(
private readonly CustomReportChartData $chartData
) {
parent::__construct($this->chartData);
}

/**
* Use this to get additional infos out of the response object
*/
public function getReport(): CustomReportChartData
{
return $this->chartData;
}
}
39 changes: 39 additions & 0 deletions src/CustomReport/Event/ReportEvent.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
<?php
declare(strict_types=1);

/**
* Pimcore
*
* This source file is available under two different licenses:
* - GNU General Public License version 3 (GPLv3)
* - Pimcore Commercial License (PCL)
* Full copyright and license information is available in
* LICENSE.md which is distributed with this source code.
*
* @copyright Copyright (c) Pimcore GmbH (http://www.pimcore.org)
* @license http://www.pimcore.org/license GPLv3 and PCL
*/

namespace Pimcore\Bundle\StudioBackendBundle\CustomReport\Event;

use Pimcore\Bundle\StudioBackendBundle\CustomReport\Schema\CustomReportDetails;
use Pimcore\Bundle\StudioBackendBundle\Event\AbstractPreResponseEvent;

final class ReportEvent extends AbstractPreResponseEvent
{
public const EVENT_NAME = 'pre_response.custom_report_report';

public function __construct(
private readonly CustomReportDetails $report
) {
parent::__construct($this->report);
}

/**
* Use this to get additional infos out of the response object
*/
public function getReport(): CustomReportDetails
{
return $this->report;
}
}
39 changes: 39 additions & 0 deletions src/CustomReport/Event/TreeConfigNodeEvent.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
<?php
declare(strict_types=1);

/**
* Pimcore
*
* This source file is available under two different licenses:
* - GNU General Public License version 3 (GPLv3)
* - Pimcore Commercial License (PCL)
* Full copyright and license information is available in
* LICENSE.md which is distributed with this source code.
*
* @copyright Copyright (c) Pimcore GmbH (http://www.pimcore.org)
* @license http://www.pimcore.org/license GPLv3 and PCL
*/

namespace Pimcore\Bundle\StudioBackendBundle\CustomReport\Event;

use Pimcore\Bundle\StudioBackendBundle\CustomReport\Schema\CustomReportTreeConfigNode;
use Pimcore\Bundle\StudioBackendBundle\Event\AbstractPreResponseEvent;

final class TreeConfigNodeEvent extends AbstractPreResponseEvent
{
public const EVENT_NAME = 'pre_response.custom_report_tree_config_node';

public function __construct(
private readonly CustomReportTreeConfigNode $treeConfigNode
) {
parent::__construct($this->treeConfigNode);
}

/**
* Use this to get additional infos out of the response object
*/
public function getTreeConfigNode(): CustomReportTreeConfigNode
{
return $this->treeConfigNode;
}
}
39 changes: 39 additions & 0 deletions src/CustomReport/Event/TreeNodeEvent.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
<?php
declare(strict_types=1);

/**
* Pimcore
*
* This source file is available under two different licenses:
* - GNU General Public License version 3 (GPLv3)
* - Pimcore Commercial License (PCL)
* Full copyright and license information is available in
* LICENSE.md which is distributed with this source code.
*
* @copyright Copyright (c) Pimcore GmbH (http://www.pimcore.org)
* @license http://www.pimcore.org/license GPLv3 and PCL
*/

namespace Pimcore\Bundle\StudioBackendBundle\CustomReport\Event;

use Pimcore\Bundle\StudioBackendBundle\CustomReport\Schema\CustomReportTreeNode;
use Pimcore\Bundle\StudioBackendBundle\Event\AbstractPreResponseEvent;

final class TreeNodeEvent extends AbstractPreResponseEvent
{
public const EVENT_NAME = 'pre_response.custom_report_tree_node';

public function __construct(
private readonly CustomReportTreeNode $treeNode
) {
parent::__construct($this->treeNode);
}

/**
* Use this to get additional infos out of the response object
*/
public function getTreeNode(): CustomReportTreeNode
{
return $this->treeNode;
}
}
Loading

0 comments on commit 32bcee7

Please sign in to comment.