From fcd4831e22128bf572227e83ad8339c321d51659 Mon Sep 17 00:00:00 2001 From: Ruslan Baidan Date: Sat, 20 Apr 2024 19:31:38 +0200 Subject: [PATCH] Refactroed the Referential, Measure, SoaCategory functionality, other improvements. --- config/module.config.php | 49 ++-- ...0230901112005_fix_positions_cleanup_db.php | 61 ++++ .../ApiAdminPasswordsController.php | 6 +- src/Controller/ApiAdminUsersController.php | 4 +- .../ApiAdminUsersRolesController.php | 4 +- src/Controller/ApiAnrAssetsController.php | 29 +- .../ApiAnrMeasuresMeasuresController.php | 90 +++--- .../ApiAnrRecommendationsController.php | 14 +- .../ApiAnrReferentialsController.php | 100 ++++--- src/Controller/ApiAnrRolfRisksController.php | 119 ++++---- src/Controller/ApiAnrRolfTagsController.php | 91 +++++- src/Controller/ApiAnrThemesController.php | 4 +- src/Controller/ApiAnrThreatsController.php | 29 +- .../ApiAnrVulnerabilitiesController.php | 38 +-- .../ApiCoreReferentialsController.php | 37 +++ src/Controller/ApiModelsController.php | 4 +- src/Controller/ApiReferentialsController.php | 35 --- src/Controller/ApiSoaCategoryController.php | 104 ++++--- src/Entity/Anr.php | 7 +- src/Entity/Measure.php | 53 ++-- src/Entity/MeasureMeasure.php | 42 ++- src/Entity/Referential.php | 13 +- src/Entity/RolfRisk.php | 43 ++- src/Entity/RolfTag.php | 28 +- src/Entity/Snapshot.php | 5 +- src/Entity/SoaCategory.php | 22 +- src/Import/Helper/ImportCacheHelper.php | 13 +- src/Model/Table/MeasureMeasureTable.php | 50 ---- src/Model/Table/MeasureTable.php | 51 ---- src/Model/Table/ReferentialTable.php | 71 ----- src/Model/Table/RolfRiskTable.php | 48 ---- src/Model/Table/RolfTagTable.php | 76 ----- src/Model/Table/SoaCategoryTable.php | 51 ---- src/Service/AnrAmvService.php | 19 +- src/Service/AnrAssetService.php | 11 + src/Service/AnrInstanceRiskOpService.php | 7 +- src/Service/AnrMeasureMeasureService.php | 108 +++---- .../AnrMeasureMeasureServiceFactory.php | 27 -- src/Service/AnrMeasureService.php | 199 ++++++++++--- src/Service/AnrMeasureServiceFactory.php | 29 -- src/Service/AnrModelService.php | 12 +- src/Service/AnrRecommendationService.php | 9 +- src/Service/AnrReferentialService.php | 102 ++++--- src/Service/AnrReferentialServiceFactory.php | 27 -- src/Service/AnrRolfRiskService.php | 270 ++++++++++++++++-- src/Service/AnrRolfRiskServiceFactory.php | 30 -- src/Service/AnrRolfTagService.php | 109 ++++++- src/Service/AnrRolfTagServiceFactory.php | 26 -- src/Service/AnrService.php | 107 +++---- src/Service/AnrThreatService.php | 20 ++ src/Service/AnrVulnerabilityService.php | 11 + src/Service/SnapshotService.php | 34 +-- src/Service/SoaCategoryService.php | 115 ++++---- src/Service/SoaCategoryServiceFactory.php | 26 -- src/Stats/Service/StatsSettingsService.php | 2 +- src/Table/InstanceRiskOpTable.php | 15 + src/Table/MeasureMeasureTable.php | 39 +++ src/Table/MeasureTable.php | 20 ++ src/Table/RecommendationTable.php | 5 +- src/Table/ReferentialTable.php | 20 ++ src/Table/RolfRiskTable.php | 33 +++ src/Table/RolfTagTable.php | 33 +++ src/Table/SnapshotTable.php | 4 +- src/Table/SoaCategoryTable.php | 20 ++ .../PatchRecommendationDataInputValidator.php | 32 +++ .../PostRecommendationDataInputValidator.php | 32 +++ 66 files changed, 1721 insertions(+), 1223 deletions(-) create mode 100644 src/Controller/ApiCoreReferentialsController.php delete mode 100644 src/Controller/ApiReferentialsController.php delete mode 100644 src/Model/Table/MeasureMeasureTable.php delete mode 100755 src/Model/Table/MeasureTable.php delete mode 100644 src/Model/Table/ReferentialTable.php delete mode 100755 src/Model/Table/RolfRiskTable.php delete mode 100755 src/Model/Table/RolfTagTable.php delete mode 100755 src/Model/Table/SoaCategoryTable.php delete mode 100644 src/Service/AnrMeasureMeasureServiceFactory.php delete mode 100755 src/Service/AnrMeasureServiceFactory.php delete mode 100644 src/Service/AnrReferentialServiceFactory.php delete mode 100755 src/Service/AnrRolfRiskServiceFactory.php delete mode 100755 src/Service/AnrRolfTagServiceFactory.php delete mode 100755 src/Service/SoaCategoryServiceFactory.php create mode 100644 src/Table/MeasureMeasureTable.php create mode 100755 src/Table/MeasureTable.php create mode 100644 src/Table/ReferentialTable.php create mode 100755 src/Table/RolfRiskTable.php create mode 100755 src/Table/RolfTagTable.php create mode 100755 src/Table/SoaCategoryTable.php diff --git a/config/module.config.php b/config/module.config.php index 51a9ece0..a3670406 100755 --- a/config/module.config.php +++ b/config/module.config.php @@ -53,8 +53,7 @@ 'id' => '[0-9]+', ], 'defaults' => [ - 'controller' => PipeSpec::class, - 'middleware' => new PipeSpec(Controller\ApiAdminUsersRolesController::class), + 'controller' => Controller\ApiAdminUsersRolesController::class, ], ], ], @@ -67,8 +66,7 @@ 'id' => '[0-9]+', ], 'defaults' => [ - 'controller' => PipeSpec::class, - 'middleware' => new PipeSpec(Controller\ApiAdminUsersController::class), + 'controller' => Controller\ApiAdminUsersController::class, ], ], ], @@ -81,8 +79,7 @@ 'id' => '[0-9]+', ], 'defaults' => [ - 'controller' => PipeSpec::class, - 'middleware' => new PipeSpec(Controller\ApiAdminUsersController::class), + 'controller' => Controller\ApiAdminUsersController::class, 'action' => 'resetPassword', ], ], @@ -109,8 +106,7 @@ 'id' => '[0-9]+', ], 'defaults' => [ - 'controller' => PipeSpec::class, - 'middleware' => new PipeSpec(Controller\ApiModelsController::class), + 'controller' => Controller\ApiModelsController::class, ], ], ], @@ -120,7 +116,7 @@ 'options' => [ 'route' => '/api/referentials', 'defaults' => [ - 'controller' => Controller\ApiReferentialsController::class, + 'controller' => Controller\ApiCoreReferentialsController::class, ], ], ], @@ -165,8 +161,7 @@ 'route' => '/api/admin/passwords', 'constraints' => [], 'defaults' => [ - 'controller' => PipeSpec::class, - 'middleware' => new PipeSpec(Controller\ApiAdminPasswordsController::class), + 'controller' => Controller\ApiAdminPasswordsController::class, ], ], ], @@ -1382,7 +1377,7 @@ Controller\ApiAnrController::class => AutowireFactory::class, Controller\ApiConfigController::class => AutowireFactory::class, Controller\ApiClientsController::class => AutowireFactory::class, - Controller\ApiReferentialsController::class => AutowireFactory::class, + Controller\ApiCoreReferentialsController::class => AutowireFactory::class, Controller\ApiUserPasswordController::class => AutowireFactory::class, Controller\ApiUserTwoFAController::class => AutowireFactory::class, Controller\ApiUserRecoveryCodesController::class => AutowireFactory::class, @@ -1457,10 +1452,6 @@ DbCli::class => Service\Model\DbCliFactory::class, DeprecatedTable\InterviewTable::class => AutowireFactory::class, - DeprecatedTable\MeasureTable::class => AutowireFactory::class, - DeprecatedTable\MeasureMeasureTable::class => AutowireFactory::class, - DeprecatedTable\RolfRiskTable::class => AutowireFactory::class, - DeprecatedTable\RolfTagTable::class => AutowireFactory::class, DeprecatedTable\RecordActorTable::class => AutowireFactory::class, DeprecatedTable\RecordDataCategoryTable::class => AutowireFactory::class, DeprecatedTable\RecordInternationalTransferTable::class => AutowireFactory::class, @@ -1468,9 +1459,7 @@ DeprecatedTable\RecordProcessorTable::class => AutowireFactory::class, DeprecatedTable\RecordRecipientTable::class => AutowireFactory::class, DeprecatedTable\RecordTable::class => AutowireFactory::class, - DeprecatedTable\ReferentialTable::class => AutowireFactory::class, DeprecatedTable\SoaTable::class => AutowireFactory::class, - DeprecatedTable\SoaCategoryTable::class => AutowireFactory::class, DeprecatedTable\QuestionTable::class => AutowireFactory::class, DeprecatedTable\QuestionChoiceTable::class => AutowireFactory::class, Table\AnrTable::class => ClientEntityManagerFactory::class, @@ -1489,6 +1478,8 @@ Table\ScaleImpactTypeTable::class => ClientEntityManagerFactory::class, Table\ClientTable::class => ClientEntityManagerFactory::class, Table\MonarcObjectTable::class => ClientEntityManagerFactory::class, + Table\MeasureTable::class => ClientEntityManagerFactory::class, + Table\MeasureMeasureTable::class => ClientEntityManagerFactory::class, Table\ObjectCategoryTable::class => ClientEntityManagerFactory::class, Table\ObjectObjectTable::class => ClientEntityManagerFactory::class, Table\OperationalRiskScaleTable::class => ClientEntityManagerFactory::class, @@ -1499,6 +1490,10 @@ Table\RecommendationHistoryTable::class => ClientEntityManagerFactory::class, Table\RecommendationRiskTable::class => ClientEntityManagerFactory::class, Table\RecommendationSetTable::class => ClientEntityManagerFactory::class, + Table\RolfRiskTable::class => ClientEntityManagerFactory::class, + Table\RolfTagTable::class => ClientEntityManagerFactory::class, + Table\ReferentialTable::class => ClientEntityManagerFactory::class, + Table\SoaCategoryTable::class => ClientEntityManagerFactory::class, Table\SnapshotTable::class => ClientEntityManagerFactory::class, Table\SoaScaleCommentTable::class => ClientEntityManagerFactory::class, Table\ThemeTable::class => ClientEntityManagerFactory::class, @@ -1519,20 +1514,12 @@ Entity\RecordProcessor::class => ModelFactory\RecordProcessorServiceModelEntity::class, Entity\RecordRecipient::class => ModelFactory\RecordRecipientServiceModelEntity::class, Entity\Record::class => ModelFactory\RecordServiceModelEntity::class, - Entity\Referential::class => ModelFactory\ReferentialServiceModelEntity::class, - Entity\Measure::class => ModelFactory\MeasureServiceModelEntity::class, - Entity\MeasureMeasure::class => ModelFactory\MeasureMeasureServiceModelEntity::class, - Entity\RolfRisk::class => ModelFactory\RolfRiskServiceModelEntity::class, - Entity\RolfTag::class => ModelFactory\RolfTagServiceModelEntity::class, Entity\Soa::class => ModelFactory\SoaServiceModelEntity::class, - Entity\SoaCategory::class => ModelFactory\SoaCategoryServiceModelEntity::class, Entity\Question::class => ModelFactory\QuestionServiceModelEntity::class, Entity\QuestionChoice::class => ModelFactory\QuestionChoiceServiceModelEntity::class, // TODO: replace to autowiring. Service\AnrInterviewService::class => Service\AnrInterviewServiceFactory::class, - Service\AnrMeasureService::class => Service\AnrMeasureServiceFactory::class, - Service\AnrMeasureMeasureService::class => Service\AnrMeasureMeasureServiceFactory::class, Service\AnrRecordActorService::class => Service\AnrRecordActorServiceFactory::class, Service\AnrRecordDataCategoryService::class => Service\AnrRecordDataCategoryServiceFactory::class, Service\AnrRecordInternationalTransferService::class @@ -1541,13 +1528,15 @@ Service\AnrRecordProcessorService::class => Service\AnrRecordProcessorServiceFactory::class, Service\AnrRecordRecipientService::class => Service\AnrRecordRecipientServiceFactory::class, Service\AnrRecordService::class => Service\AnrRecordServiceFactory::class, - Service\AnrReferentialService::class => Service\AnrReferentialServiceFactory::class, Service\SoaService::class => Service\SoaServiceFactory::class, - Service\SoaCategoryService::class => Service\SoaCategoryServiceFactory::class, Service\AnrQuestionService::class => Service\AnrQuestionServiceFactory::class, Service\AnrQuestionChoiceService::class => Service\AnrQuestionChoiceServiceFactory::class, - Service\AnrRolfTagService::class => Service\AnrRolfTagServiceFactory::class, - Service\AnrRolfRiskService::class => Service\AnrRolfRiskServiceFactory::class, + Service\AnrMeasureService::class => AutowireFactory::class, + Service\AnrMeasureMeasureService::class => AutowireFactory::class, + Service\AnrReferentialService::class => AutowireFactory::class, + Service\SoaCategoryService::class => AutowireFactory::class, + Service\AnrRolfTagService::class => AutowireFactory::class, + Service\AnrRolfRiskService::class => AutowireFactory::class, Service\AnrRecommendationService::class => AutowireFactory::class, Service\AnrRecommendationHistoryService::class => AutowireFactory::class, Service\AnrRecommendationRiskService::class => AutowireFactory::class, diff --git a/migrations/db/20230901112005_fix_positions_cleanup_db.php b/migrations/db/20230901112005_fix_positions_cleanup_db.php index 17fef355..a6700fd4 100644 --- a/migrations/db/20230901112005_fix_positions_cleanup_db.php +++ b/migrations/db/20230901112005_fix_positions_cleanup_db.php @@ -207,6 +207,51 @@ public function change() $this->execute('UPDATE measures SET soacategory_id = ' . $soaCategoryIds[$anrId] . ' WHERE uuid = "' . $measureData['uuid'] . '" and anr_id = ' . $anrId); } + /* Correct MeasuresMeasures table structure. */ + $this->table('measures_measures') + ->addColumn('id', 'integer', ['signed' => false, 'after' => MysqlAdapter::FIRST]) + ->renameColumn('father_id', 'master_measure_id') + ->renameColumn('child_id', 'linked_measure_id') + ->dropForeignKey(['master_measure_id', 'linked_measure_id', 'anr_id']) + ->removeColumn('creator') + ->removeColumn('created_at') + ->removeColumn('updater') + ->removeColumn('updated_at') + ->update(); + $this->execute('SET @a = 0; UPDATE measures_measures SET id = @a := @a + 1 ORDER BY anr_id;'); + $this->table('measures_measures') + ->changePrimaryKey(['id']) + ->addIndex(['master_measure_id', 'linked_measure_id', 'anr_id'], ['unique' => true]) + ->update(); + $this->table('measures_measures') + ->changeColumn('id', 'integer', ['identity' => true, 'signed' => false]) + ->update(); + /* Remove unlinked measures links to measures. */ + $this->execute('DELETE FROM measures_measures WHERE anr_id NOT IN (SELECT id FROM anrs);'); + $voidMeasuresQuery = $this->query(' + SELECT id FROM measures_measures WHERE CONCAT(master_measure_id, anr_id) NOT IN + (SELECT CONCAT(uuid, anr_id) FROM measures) OR CONCAT(linked_measure_id, anr_id) + NOT IN (SELECT CONCAT(uuid, anr_id) FROM measures) + '); + $voidMeasuresIds = []; + foreach ($voidMeasuresQuery->fetchAll() as $voidMeasureData) { + $voidMeasuresIds[] = $voidMeasureData['id']; + } + $this->execute('DELETE FROM measures_measures WHERE id IN (' . implode(',', $voidMeasuresIds) . ');'); + $this->table('measures_measures') + ->addForeignKey(['anr_id'], 'anrs', ['id'], ['delete' => 'CASCADE']) + ->addForeignKey( + ['master_measure_id', 'anr_id'], + 'measures', + ['uuid', 'anr_id'], + ['delete' => 'CASCADE', 'update' => 'RESTRICT'] + )->addForeignKey( + ['linked_measure_id', 'anr_id'], + 'measures', + ['uuid', 'anr_id'], + ['delete' => 'CASCADE', 'update' => 'RESTRICT'] + )->update(); + $this->table('measures')->addForeignKey(['anr_id'], 'anrs', ['id'], ['delete' => 'CASCADE'])->update(); /* Rename column of owner_id to risk_owner_id. */ $this->table('instances_risks')->renameColumn('owner_id', 'risk_owner_id')->update(); @@ -368,6 +413,22 @@ public function change() ->addIndex(['anr_id', 'instance_risk_op_id', 'operational_risk_scale_type_id'], ['unique' => false]) ->update(); + /* Note: Temporary change fields types to avoid setting values from the code. Later will be dropped. */ + $this->table('operational_risks_scales_types') + ->changeColumn('label_translation_key', 'string', ['null' => false, 'default' => '', 'limit' => 255]) + ->update(); + $this->table('operational_risks_scales_comments') + ->changeColumn('comment_translation_key', 'string', ['null' => false, 'default' => '', 'limit' => 255]) + ->update(); + + /* Cleanup the table. */ + $this->table('rolf_risks_tags') + ->removeColumn('creator') + ->removeColumn('created_at') + ->removeColumn('updater') + ->removeColumn('updated_at') + ->update(); + /* TODO: Should be added to the next release migration, to perform this release in a safe mode. $this->table('anr_instance_metadata_fields')->removeColumn('label_translation_key')->update(); $this->table('instances_metadata')->removeColumn('comment_translation_key')->update(); diff --git a/src/Controller/ApiAdminPasswordsController.php b/src/Controller/ApiAdminPasswordsController.php index e6702e6b..bf3982c6 100755 --- a/src/Controller/ApiAdminPasswordsController.php +++ b/src/Controller/ApiAdminPasswordsController.php @@ -7,12 +7,12 @@ namespace Monarc\FrontOffice\Controller; -use Monarc\Core\Controller\Handler\AbstractRestfulControllerRequestHandler; +use Laminas\Mvc\Controller\AbstractRestfulController; use Monarc\Core\Controller\Handler\ControllerRequestResponseHandlerTrait; use Monarc\Core\Exception\Exception; use Monarc\Core\Service\PasswordService; -class ApiAdminPasswordsController extends AbstractRestfulControllerRequestHandler +class ApiAdminPasswordsController extends AbstractRestfulController { use ControllerRequestResponseHandlerTrait; @@ -32,7 +32,7 @@ public function create($data) if (!empty($data['email']) && empty($data['password'])) { try { $this->passwordService->passwordForgotten($data['email']); - } catch (\Exception $e) { + } catch (\Exception) { // Ignore the \Exception to avoid the data leak. } } diff --git a/src/Controller/ApiAdminUsersController.php b/src/Controller/ApiAdminUsersController.php index d710b3dd..2ff26d06 100755 --- a/src/Controller/ApiAdminUsersController.php +++ b/src/Controller/ApiAdminUsersController.php @@ -7,14 +7,14 @@ namespace Monarc\FrontOffice\Controller; -use Monarc\Core\Controller\Handler\AbstractRestfulControllerRequestHandler; +use Laminas\Mvc\Controller\AbstractRestfulController; use Monarc\Core\Controller\Handler\ControllerRequestResponseHandlerTrait; use Monarc\Core\InputFormatter\User\GetUsersInputFormatter; use Monarc\Core\Service\PasswordService; use Monarc\FrontOffice\Validator\InputValidator\User\PostUserDataInputValidator; use Monarc\FrontOffice\Service\UserService; -class ApiAdminUsersController extends AbstractRestfulControllerRequestHandler +class ApiAdminUsersController extends AbstractRestfulController { use ControllerRequestResponseHandlerTrait; diff --git a/src/Controller/ApiAdminUsersRolesController.php b/src/Controller/ApiAdminUsersRolesController.php index 2429d367..4ba5cccb 100755 --- a/src/Controller/ApiAdminUsersRolesController.php +++ b/src/Controller/ApiAdminUsersRolesController.php @@ -7,12 +7,12 @@ namespace Monarc\FrontOffice\Controller; -use Monarc\Core\Controller\Handler\AbstractRestfulControllerRequestHandler; +use Laminas\Mvc\Controller\AbstractRestfulController; use Monarc\Core\Controller\Handler\ControllerRequestResponseHandlerTrait; use Monarc\Core\Exception; use Monarc\FrontOffice\Service\UserRoleService; -class ApiAdminUsersRolesController extends AbstractRestfulControllerRequestHandler +class ApiAdminUsersRolesController extends AbstractRestfulController { use ControllerRequestResponseHandlerTrait; diff --git a/src/Controller/ApiAnrAssetsController.php b/src/Controller/ApiAnrAssetsController.php index 388d63d4..e15c6fa9 100755 --- a/src/Controller/ApiAnrAssetsController.php +++ b/src/Controller/ApiAnrAssetsController.php @@ -55,19 +55,26 @@ public function create($data) $anr = $this->getRequest()->getAttribute('anr'); $isBatchData = $this->isBatchData($data); - $this->validatePostParams($this->postAssetDataInputValidator->setAnr($anr), $data, $isBatchData); - - $assetsUuids = []; - $validatedData = $isBatchData - ? $this->postAssetDataInputValidator->getValidDataSets() - : [$this->postAssetDataInputValidator->getValidData()]; - $setsNum = \count($validatedData) - 1; - foreach ($validatedData as $setNum => $validatedDataRow) { - $assetsUuids[] = $this->anrAssetService->create($anr, $validatedDataRow, $setNum === $setsNum)->getUuid(); + $this->validatePostParams( + $this->postAssetDataInputValidator->setIncludeFilter(['anr' => $anr]), + $data, + $isBatchData + ); + + if ($isBatchData) { + return $this->getSuccessfulJsonResponse([ + 'id' => $this->anrAssetService->createList( + $anr, + $this->postAssetDataInputValidator->getValidDataSets() + ), + ]); } return $this->getSuccessfulJsonResponse([ - 'id' => \count($assetsUuids) === 1 && !$isBatchData ? current($assetsUuids) : $assetsUuids, + 'id' => $this->anrAssetService->create( + $anr, + $this->postAssetDataInputValidator->getValidData() + )->getUuid(), ]); } @@ -80,7 +87,7 @@ public function update($id, $data) /** @var Anr $anr */ $anr = $this->getRequest()->getAttribute('anr'); $this->validatePostParams( - $this->postAssetDataInputValidator->setExcludeFilter(['uuid' => $id])->setAnr($anr), + $this->postAssetDataInputValidator->setIncludeFilter(['anr' => $anr])->setExcludeFilter(['uuid' => $id]), $data ); diff --git a/src/Controller/ApiAnrMeasuresMeasuresController.php b/src/Controller/ApiAnrMeasuresMeasuresController.php index c2aa708d..68d7321a 100644 --- a/src/Controller/ApiAnrMeasuresMeasuresController.php +++ b/src/Controller/ApiAnrMeasuresMeasuresController.php @@ -1,74 +1,72 @@ -params()->fromRoute('anrid'); - if (empty($anrId)) { - throw new Exception('Anr id missing', 412); - } + /** @var Anr $anr */ + $anr = $this->getRequest()->getAttribute('anr'); + $measuresLinksData = $this->anrMeasureMeasureService->getList($anr); - $page = $this->params()->fromQuery('page'); - $limit = $this->params()->fromQuery('limit'); - $order = $this->params()->fromQuery('order'); - $filter = $this->params()->fromQuery('filter'); - $fatherId = $this->params()->fromQuery('fatherId'); - $childId = $this->params()->fromQuery('childId'); - $filterAnd = ['anr' => $anrId]; - - if ($fatherId) { - $filterAnd['father'] = $fatherId; - } - if ($childId) { - $filterAnd['child'] = $childId; - } + return $this->getPreparedJsonResponse([ + 'count' => \count($measuresLinksData), + 'measuresLinks' => $measuresLinksData, + ]); + } - $service = $this->getService(); + public function create($data) + { + $isBatchData = $this->isBatchData($data); + $this->validatePostParams($this->postMeasureMeasureDataInputValidator, $data, $isBatchData); - $entities = $service->getList($page, $limit, $order, $filter, $filterAnd); - if (count($this->dependencies)) { - foreach ($entities as $key => $entity) { - $this->formatDependencies($entities[$key], $this->dependencies); - } + /** @var Anr $anr */ + $anr = $this->getRequest()->getAttribute('anr'); + if ($this->isBatchData($data)) { + $this->anrMeasureMeasureService->createList( + $anr, + $this->postMeasureMeasureDataInputValidator->getValidDataSets() + ); + } else { + $this->anrMeasureMeasureService->create($anr, $this->postMeasureMeasureDataInputValidator->getValidData()); } - return $this->getPreparedJsonResponse([ - 'count' => $service->getFilteredCount($filter, $filterAnd), - $this->name => $entities - ]); + return $this->getSuccessfulJsonResponse(); } public function deleteList($data) { - if (empty($data)) { //we delete one measuremeasure - $anrId = (int)$this->params()->fromRoute('anrid'); - $fatherId = $this->params()->fromQuery('father'); - $childId = $this->params()->fromQuery('child'); - - $this->getService()->delete(['anr' => $anrId, 'father' => $fatherId, 'child' => $childId]); + $masterMeasureUuid = $this->params()->fromQuery('masterMeasureUuid'); + $linkedMeasureUuid = $this->params()->fromQuery('linkedMeasureUuid'); + $this->validatePostParams( + $this->postMeasureMeasureDataInputValidator, + compact('masterMeasureUuid', 'linkedMeasureUuid') + ); - return $this->getSuccessfulJsonResponse(); - } + /** @var Anr $anr */ + $anr = $this->getRequest()->getAttribute('anr'); + $this->anrMeasureMeasureService->delete($anr, $masterMeasureUuid, $linkedMeasureUuid); - return parent::deleteList($data); + return $this->getSuccessfulJsonResponse(); } } diff --git a/src/Controller/ApiAnrRecommendationsController.php b/src/Controller/ApiAnrRecommendationsController.php index 50b6382a..00de84c3 100755 --- a/src/Controller/ApiAnrRecommendationsController.php +++ b/src/Controller/ApiAnrRecommendationsController.php @@ -54,7 +54,11 @@ public function create($data) $anr = $this->getRequest()->getAttribute('anr'); $isBatchData = $this->isBatchData($data); - $this->validatePostParams($this->postRecommendationDataInputValidator, $data, $isBatchData); + $this->validatePostParams( + $this->postRecommendationDataInputValidator->setIncludeFilter(['anr' => $anr]), + $data, + $isBatchData + ); $result = $isBatchData ? $this->anrRecommendationService->createList( $anr, @@ -73,10 +77,16 @@ public function create($data) */ public function patch($id, $data) { - $this->validatePostParams($this->patchRecommendationDataInputValidator, $data); /** @var Anr $anr */ $anr = $this->getRequest()->getAttribute('anr'); + $this->validatePostParams( + $this->patchRecommendationDataInputValidator + ->setIncludeFilter(['anr' => $anr]) + ->setExcludeFilter(['uuid' => $id]), + $data + ); + $this->anrRecommendationService->patch($anr, $id, $this->patchRecommendationDataInputValidator->getValidData()); return $this->getSuccessfulJsonResponse(); diff --git a/src/Controller/ApiAnrReferentialsController.php b/src/Controller/ApiAnrReferentialsController.php index 8c44f1bf..703ecaff 100644 --- a/src/Controller/ApiAnrReferentialsController.php +++ b/src/Controller/ApiAnrReferentialsController.php @@ -1,84 +1,90 @@ -params()->fromRoute('anrid'); - if (empty($anrId)) { - throw new Exception('Anr id missing', 412); - } - $page = $this->params()->fromQuery('page'); - $limit = $this->params()->fromQuery('limit'); - $order = $this->params()->fromQuery('order'); - $filter = $this->params()->fromQuery('filter'); - $filterAnd = ['anr' => $anrId]; - - $service = $this->getService(); - - $entities = $service->getList($page, $limit, $order, $filter, $filterAnd); - foreach ($entities as $key => $entity) { - $this->formatDependencies($entities[$key], $this->dependencies); - } + $formatterParams = $this->getFormattedInputParams($this->getReferentialInputFormatter); return $this->getPreparedJsonResponse([ - 'count' => $service->getFilteredCount($filter, $filterAnd), - 'referentials' => $entities, + 'referentials' => $this->anrReferentialService->getList($formatterParams), ]); } + /** + * @param string $id + */ public function get($id) { - $anrId = (int)$this->params()->fromRoute('anrid'); - $entity = $this->getService()->getEntity(['anr' => $anrId, 'uuid' => $id]); + /** @var Anr $anr */ + $anr = $this->getRequest()->getAttribute('anr'); + + return $this->getPreparedJsonResponse($this->anrReferentialService->getReferentialData($anr, $id)); + } + + /** + * @param array $data + */ + public function create($data) + { + /** @var Anr $anr */ + $anr = $this->getRequest()->getAttribute('anr'); + $this->validatePostParams($this->postReferentialDataInputValidator, $data); - $this->formatDependencies($entity, $this->dependencies); - return $this->getPreparedJsonResponse($entity); + return $this->getSuccessfulJsonResponse([ + 'id' => $this->anrReferentialService->create( + $anr, + $this->postReferentialDataInputValidator->getValidData() + )->getUuid(), + ]); } + /** + * @param string $id + * @param array $data + */ public function update($id, $data) { - $anrId = (int)$this->params()->fromRoute('anrid'); - $newId = ['anr'=> $anrId, 'uuid' => $data['uuid']]; + /** @var Anr $anr */ + $anr = $this->getRequest()->getAttribute('anr'); + $this->validatePostParams($this->postReferentialDataInputValidator, $data); - if (empty($anrId)) { - throw new Exception('Anr id missing', 412); - } - $data['anr'] = $anrId; - - $this->getService()->update($newId, $data); + $this->anrReferentialService->update($anr, $id, $this->postReferentialDataInputValidator->getValidData()); return $this->getSuccessfulJsonResponse(); } + /** + * @param string $id + */ public function delete($id) { - $anrId = (int)$this->params()->fromRoute('anrid'); - $newId = ['anr'=> $anrId, 'uuid' => $id]; - - if (empty($anrId)) { - throw new Exception('Anr id missing', 412); - } - - $this->getService()->delete($newId); + /** @var Anr $anr */ + $anr = $this->getRequest()->getAttribute('anr'); + $this->anrReferentialService->delete($anr, $id); return $this->getSuccessfulJsonResponse(); } diff --git a/src/Controller/ApiAnrRolfRisksController.php b/src/Controller/ApiAnrRolfRisksController.php index 5e4e6441..f139629a 100755 --- a/src/Controller/ApiAnrRolfRisksController.php +++ b/src/Controller/ApiAnrRolfRisksController.php @@ -1,100 +1,109 @@ -getFormattedInputParams($this->rolfRisksInputFormatter); + + return $this->getPreparedJsonResponse([ + 'count' => $this->anrRolfRiskService->getCount($formattedParams), + 'risks' => $this->anrRolfRiskService->getList($formattedParams), + ]); } public function get($id) { - $entity = $this->getService()->getEntity($id); + /** @var Anr $anr */ + $anr = $this->getRequest()->getAttribute('anr'); - $this->formatDependencies($entity, $this->dependencies, Measure::class, ['referential']); - - return $this->getPreparedJsonResponse($entity); + return $this->getPreparedJsonResponse($this->anrRolfRiskService->getRolfRiskData($anr, (int)$id)); } /** - * @inheritdoc + * @param array $data */ - public function getList() + public function create($data) { - $page = $this->params()->fromQuery('page'); - $limit = $this->params()->fromQuery('limit'); - $order = $this->params()->fromQuery('order'); - $filter = $this->params()->fromQuery('filter'); - $tag = $this->params()->fromQuery('tag'); - $anr = $this->params()->fromRoute("anrid"); - - /** @var AnrRolfRiskService $service */ - $service = $this->getService(); - - $rolfRisks = $service->getListSpecific($page, $limit, $order, $filter, $tag, $anr); - foreach ($rolfRisks as $key => $rolfRisk) { - $this->formatDependencies($rolfRisks[$key], $this->dependencies, Measure::class, ['referential']); - - $rolfRisk['tags']->initialize(); - $rolfTags = $rolfRisk['tags']->getSnapshot(); - $rolfRisks[$key]['tags'] = []; - foreach ($rolfTags as $rolfTag) { - $rolfRisks[$key]['tags'][] = $rolfTag->getJsonArray(); - } + /** @var Anr $anr */ + $anr = $this->getRequest()->getAttribute('anr'); + $isBatchData = $this->isBatchData($data); + $this->validatePostParams($this->postRolfRiskDataInputValidator, $data, $isBatchData); + + if ($this->isBatchData($data)) { + return $this->getSuccessfulJsonResponse([ + 'id' => $this->anrRolfRiskService + ->createList($anr, $this->postRolfRiskDataInputValidator->getValidDataSets()), + ]); } - return $this->getPreparedJsonResponse([ - 'count' => $service->getFilteredSpecificCount($page, $limit, $order, $filter, $tag, $anr), - 'risks' => $rolfRisks, + return $this->getSuccessfulJsonResponse([ + 'id' => $this->anrRolfRiskService + ->create($anr, $this->postRolfRiskDataInputValidator->getValidData())->getId(), ]); } + /** + * @param array $data + */ public function update($id, $data) { - if (!empty($data['measures'])) { - $data['measures'] = $this->addAnrId($data['measures']); - } + /** @var Anr $anr */ + $anr = $this->getRequest()->getAttribute('anr'); + $this->validatePostParams($this->postRolfRiskDataInputValidator->setExcludeFilter(['id' => (int)$id]), $data); + + $this->anrRolfRiskService->update($anr, (int)$id, $this->postRolfRiskDataInputValidator->getValidData()); - return parent::update($id, $data); + return $this->getSuccessfulJsonResponse(); } - public function patch($id, $data) + public function patchList($data) { - if (!empty($data['measures'])) { - $data['measures'] = $this->addAnrId($data['measures']); - } + /** @var Anr $anr */ + $anr = $this->getRequest()->getAttribute('anr'); + $this->anrRolfRiskService->linkMeasuresToRisks($anr, $data['fromReferential'], $data['toReferential']); - return parent::patch($id, $data); + return $this->getSuccessfulJsonResponse(); } - - public function patchList($data) + public function delete($id) { - $service = $this->getService(); - $data['toReferential'] = $this->addAnrId($data['toReferential']); - $service->createLinkedRisks($data['fromReferential'], $data['toReferential']); + /** @var Anr $anr */ + $anr = $this->getRequest()->getAttribute('anr'); + $this->anrRolfRiskService->delete($anr, (int)$id); return $this->getSuccessfulJsonResponse(); } - public function create($data) + public function deleteList($data) { - if (!empty($data['measures'])) { - $data['measures'] = $this->addAnrId($data['measures']); - } + /** @var Anr $anr */ + $anr = $this->getRequest()->getAttribute('anr'); + $this->anrRolfRiskService->deleteList($anr, $data); - return parent::create($data); + return $this->getSuccessfulJsonResponse(); } } diff --git a/src/Controller/ApiAnrRolfTagsController.php b/src/Controller/ApiAnrRolfTagsController.php index ce992c0a..91f7cf9a 100755 --- a/src/Controller/ApiAnrRolfTagsController.php +++ b/src/Controller/ApiAnrRolfTagsController.php @@ -1,20 +1,99 @@ -getFormattedInputParams($this->getRolfTagsInputFormatter); + + return $this->getPreparedJsonResponse([ + 'count' => $this->anrRolfTagService->getCount($formattedParams), + 'tags' => $this->anrRolfTagService->getList($formattedParams), + ]); + } + + public function get($id) + { + /** @var Anr $anr */ + $anr = $this->getRequest()->getAttribute('anr'); + + return $this->getPreparedJsonResponse($this->anrRolfTagService->getRolfTagData($anr, (int)$id)); + } + + public function create($data) + { + /** @var Anr $anr */ + $anr = $this->getRequest()->getAttribute('anr'); + $isBatchData = $this->isBatchData($data); + $this->validatePostParams($this->postRolfTagDataInputValidator, $data, $isBatchData); + + if ($this->isBatchData($data)) { + return $this->getSuccessfulJsonResponse([ + 'id' => $this->anrRolfTagService + ->createList($anr, $this->postRolfTagDataInputValidator->getValidDataSets()), + ]); + } + + return $this->getSuccessfulJsonResponse([ + 'id' => $this->anrRolfTagService->create( + $anr, + $this->postRolfTagDataInputValidator->getValidData() + )->getId(), + ]); + } + + /** + * @param array $data + */ + public function update($id, $data) + { + /** @var Anr $anr */ + $anr = $this->getRequest()->getAttribute('anr'); + $this->validatePostParams($this->postRolfTagDataInputValidator->setExcludeFilter(['id' => (int)$id]), $data); + + $this->anrRolfTagService->update($anr, (int)$id, $this->postRolfTagDataInputValidator->getValidData()); + + return $this->getSuccessfulJsonResponse(); + } + + public function delete($id) + { + /** @var Anr $anr */ + $anr = $this->getRequest()->getAttribute('anr'); + $this->anrRolfTagService->delete($anr, (int)$id); + + return $this->getSuccessfulJsonResponse(); + } + + public function deleteList($data) + { + /** @var Anr $anr */ + $anr = $this->getRequest()->getAttribute('anr'); + $this->anrRolfTagService->deleteList($anr, $data); + + return $this->getSuccessfulJsonResponse(); } } diff --git a/src/Controller/ApiAnrThemesController.php b/src/Controller/ApiAnrThemesController.php index 26af45da..be68cf01 100755 --- a/src/Controller/ApiAnrThemesController.php +++ b/src/Controller/ApiAnrThemesController.php @@ -60,7 +60,7 @@ public function update($id, $data) /** @var Anr $anr */ $anr = $this->getRequest()->getAttribute('anr'); - $this->anrThemeService->update($anr, $id, $data); + $this->anrThemeService->update($anr, (int)$id, $data); return $this->getSuccessfulJsonResponse(); } @@ -69,7 +69,7 @@ public function delete($id) { /** @var Anr $anr */ $anr = $this->getRequest()->getAttribute('anr'); - $this->anrThemeService->delete($anr, $id); + $this->anrThemeService->delete($anr, (int)$id); return $this->getSuccessfulJsonResponse(); } diff --git a/src/Controller/ApiAnrThreatsController.php b/src/Controller/ApiAnrThreatsController.php index 84bf5cf3..849a3d59 100755 --- a/src/Controller/ApiAnrThreatsController.php +++ b/src/Controller/ApiAnrThreatsController.php @@ -55,19 +55,26 @@ public function create($data) $anr = $this->getRequest()->getAttribute('anr'); $isBatchData = $this->isBatchData($data); - $this->validatePostParams($this->postThreatDataInputValidator->setAnr($anr), $data, $isBatchData); - - $threatsUuids = []; - $validatedData = $isBatchData - ? $this->postThreatDataInputValidator->getValidDataSets() - : [$this->postThreatDataInputValidator->getValidData()]; - $setsNum = \count($validatedData) - 1; - foreach ($validatedData as $setNum => $validatedDataSet) { - $threatsUuids[] = $this->anrThreatService->create($anr, $validatedDataSet, $setsNum === $setNum)->getUuid(); + $this->validatePostParams( + $this->postThreatDataInputValidator->setIncludeFilter(['anr' => $anr]), + $data, + $isBatchData + ); + + if ($isBatchData) { + return $this->getSuccessfulJsonResponse([ + 'id' => $this->anrThreatService->createList( + $anr, + $this->postThreatDataInputValidator->getValidDataSets() + ), + ]); } return $this->getSuccessfulJsonResponse([ - 'id' => \count($threatsUuids) === 1 && !$isBatchData ? current($threatsUuids) : $threatsUuids, + 'id' => $this->anrThreatService->create( + $anr, + $this->postThreatDataInputValidator->getValidData() + )->getUuid(), ]); } @@ -81,7 +88,7 @@ public function update($id, $data) $anr = $this->getRequest()->getAttribute('anr'); $this->validatePostParams( - $this->postThreatDataInputValidator->setExcludeFilter(['uuid' => $id])->setAnr($anr), + $this->postThreatDataInputValidator->setIncludeFilter(['anr' => $anr])->setExcludeFilter(['uuid' => $id]), $data ); diff --git a/src/Controller/ApiAnrVulnerabilitiesController.php b/src/Controller/ApiAnrVulnerabilitiesController.php index 45e0e068..2863bd46 100755 --- a/src/Controller/ApiAnrVulnerabilitiesController.php +++ b/src/Controller/ApiAnrVulnerabilitiesController.php @@ -55,24 +55,26 @@ public function create($data) $anr = $this->getRequest()->getAttribute('anr'); $isBatchData = $this->isBatchData($data); - $this->validatePostParams($this->postVulnerabilityDataInputValidator->setAnr($anr), $data, $isBatchData); - - $vulnerabilitiesUuids = []; - $validatedData = $isBatchData - ? $this->postVulnerabilityDataInputValidator->getValidDataSets() - : [$this->postVulnerabilityDataInputValidator->getValidData()]; - $setsNum = \count($validatedData) - 1; - foreach ($validatedData as $setNum => $validatedDataRow) { - $vulnerabilitiesUuids[] = $this->anrVulnerabilityService->create( - $anr, - $validatedDataRow, - $setNum === $setsNum - )->getUuid(); + $this->validatePostParams( + $this->postVulnerabilityDataInputValidator->setIncludeFilter(['anr' => $anr]), + $data, + $isBatchData + ); + + if ($isBatchData) { + return $this->getSuccessfulJsonResponse([ + 'id' => $this->anrVulnerabilityService->createList( + $anr, + $this->postVulnerabilityDataInputValidator->getValidDataSets() + ), + ]); } - return $this->getPreparedJsonResponse([ - 'status' => 'ok', - 'id' => implode(', ', $vulnerabilitiesUuids), + return $this->getSuccessfulJsonResponse([ + 'id' => $this->anrVulnerabilityService->create( + $anr, + $this->postVulnerabilityDataInputValidator->getValidData() + )->getUuid(), ]); } @@ -86,7 +88,9 @@ public function update($id, $data) $anr = $this->getRequest()->getAttribute('anr'); $this->validatePostParams( - $this->postVulnerabilityDataInputValidator->setAnr($anr)->setExcludeFilter(['uuid' => $id]), + $this->postVulnerabilityDataInputValidator + ->setIncludeFilter(['anr' => $anr]) + ->setExcludeFilter(['uuid' => $id]), $data ); diff --git a/src/Controller/ApiCoreReferentialsController.php b/src/Controller/ApiCoreReferentialsController.php new file mode 100644 index 00000000..187e711f --- /dev/null +++ b/src/Controller/ApiCoreReferentialsController.php @@ -0,0 +1,37 @@ +referentialService->getList( + $this->getFormattedInputParams($this->getReferentialInputFormatter) + ); + + return new JsonModel([ + 'count' => \count($frameworks), + 'referentials' => $frameworks, + ]); + } +} diff --git a/src/Controller/ApiModelsController.php b/src/Controller/ApiModelsController.php index 874b1261..873dae32 100755 --- a/src/Controller/ApiModelsController.php +++ b/src/Controller/ApiModelsController.php @@ -7,11 +7,11 @@ namespace Monarc\FrontOffice\Controller; -use Monarc\Core\Controller\Handler\AbstractRestfulControllerRequestHandler; +use Laminas\Mvc\Controller\AbstractRestfulController; use Monarc\Core\Controller\Handler\ControllerRequestResponseHandlerTrait; use Monarc\FrontOffice\Service\AnrModelService; -class ApiModelsController extends AbstractRestfulControllerRequestHandler +class ApiModelsController extends AbstractRestfulController { use ControllerRequestResponseHandlerTrait; diff --git a/src/Controller/ApiReferentialsController.php b/src/Controller/ApiReferentialsController.php deleted file mode 100644 index 80f37090..00000000 --- a/src/Controller/ApiReferentialsController.php +++ /dev/null @@ -1,35 +0,0 @@ -params()->fromQuery('filter'); - $order = $this->params()->fromQuery('order'); - - $referential = $this->anrReferentialService->getCommonReferentials($filter, $order); - - return new JsonModel([ - 'count' => \count($referential), - 'referentials' => $referential, - ]); - } -} diff --git a/src/Controller/ApiSoaCategoryController.php b/src/Controller/ApiSoaCategoryController.php index 0319132a..3507698d 100755 --- a/src/Controller/ApiSoaCategoryController.php +++ b/src/Controller/ApiSoaCategoryController.php @@ -1,55 +1,85 @@ -params()->fromRoute('anrid'); - if (empty($anrId)) { - throw new Exception('Anr id missing', 412); - } - $page = $this->params()->fromQuery('page'); - $limit = $this->params()->fromQuery('limit'); - $order = $this->params()->fromQuery('order'); - $filter = $this->params()->fromQuery('filter'); - $status = $this->params()->fromQuery('status', 1); - $referential = $this->params()->fromQuery('referential'); - - $filterAnd = ['anr' => $anrId]; - if ($status === 'all') { - $filterAnd['status'] = (int)$status; - } - - if ($referential) { - $filterAnd['r.anr'] = $anrId; - $filterAnd['r.uuid'] = $referential; - } - - $service = $this->getService(); - - $entities = $service->getList($page, $limit, $order, $filter, $filterAnd); - foreach (['anr', 'referential'] as $key => $entity) { - $this->formatDependencies($entities[$key], $this->dependencies); - } - return $this->getPreparedJsonResponse([ - 'count' => $service->getFilteredCount($filter, $filterAnd), - 'categories' => $entities, + 'categories' => $this->soaCategoryService->getList( + $this->getFormattedInputParams($this->getSoaCategoriesInputFormatter) + ), + ]); + } + + public function get($id) + { + /** @var Anr $anr */ + $anr = $this->getRequest()->getAttribute('anr'); + + return $this->getPreparedJsonResponse($this->soaCategoryService->getSoaCategoryData($anr, (int)$id)); + } + + /** + * @param array $data + */ + public function create($data) + { + /** @var Anr $anr */ + $anr = $this->getRequest()->getAttribute('anr'); + $this->validatePostParams($this->postSoaCategoryDataInputValidator, $data); + + return $this->getSuccessfulJsonResponse([ + 'id' => $this->soaCategoryService->create( + $anr, + $this->postSoaCategoryDataInputValidator->getValidData() + )->getId(), ]); } + + /** + * @param array $data + */ + public function update($id, $data) + { + /** @var Anr $anr */ + $anr = $this->getRequest()->getAttribute('anr'); + $this->validatePostParams($this->postSoaCategoryDataInputValidator, $data); + + $this->soaCategoryService->update($anr, (int)$id, $this->postSoaCategoryDataInputValidator->getValidData()); + + return $this->getSuccessfulJsonResponse(); + } + + public function delete($id) + { + /** @var Anr $anr */ + $anr = $this->getRequest()->getAttribute('anr'); + + $this->soaCategoryService->delete($anr, (int)$id); + + return $this->getSuccessfulJsonResponse(); + } } diff --git a/src/Entity/Anr.php b/src/Entity/Anr.php index 4a1b97b1..b9761f3e 100755 --- a/src/Entity/Anr.php +++ b/src/Entity/Anr.php @@ -71,9 +71,9 @@ class Anr extends AnrSuperClass protected $recommendationSets; /** - * @var Snapshot + * @var Snapshot|null * - * @ORM\OneToMany(targetEntity="Snapshot", mappedBy="anr") + * @ORM\OneToOne(targetEntity="Snapshot", mappedBy="anr") */ protected $snapshot; @@ -394,7 +394,7 @@ public function addRecommendationSet(RecommendationSet $recommendationSet): self public function isAnrSnapshot(): bool { - return $this->snapshot === null; + return $this->snapshot !== null; } public function getSnapshot(): ?Snapshot @@ -405,6 +405,7 @@ public function getSnapshot(): ?Snapshot public function setSnapshot(Snapshot $snapshot): self { $this->snapshot = $snapshot; + $snapshot->setAnr($this); return $this; } diff --git a/src/Entity/Measure.php b/src/Entity/Measure.php index 1a17768d..1d25c377 100755 --- a/src/Entity/Measure.php +++ b/src/Entity/Measure.php @@ -1,7 +1,7 @@ -anr; } - /** - * @param Anr $anr - */ - public function setAnr($anr): self + public function setAnr(Anr $anr): self { $this->anr = $anr; diff --git a/src/Entity/Referential.php b/src/Entity/Referential.php index e8d31041..dcc6f33f 100644 --- a/src/Entity/Referential.php +++ b/src/Entity/Referential.php @@ -11,9 +11,7 @@ use Monarc\Core\Entity\ReferentialSuperClass; /** - * @ORM\Table(name="referentials", indexes={ - * @ORM\Index(name="anr", columns={"anr_id"}), - * }) + * @ORM\Table(name="referentials", indexes={@ORM\Index(name="anr", columns={"anr_id"})}) * @ORM\Entity */ class Referential extends ReferentialSuperClass @@ -23,9 +21,7 @@ class Referential extends ReferentialSuperClass * * @ORM\Id * @ORM\ManyToOne(targetEntity="Anr") - * @ORM\JoinColumns({ - * @ORM\JoinColumn(name="anr_id", referencedColumnName="id", nullable=false) - * }) + * @ORM\JoinColumns({@ORM\JoinColumn(name="anr_id", referencedColumnName="id", nullable=false)}) */ protected $anr; @@ -36,4 +32,9 @@ public function setAnr(Anr $anr): self return $this; } + + public function getAnr(): Anr + { + return $this->anr; + } } diff --git a/src/Entity/RolfRisk.php b/src/Entity/RolfRisk.php index 5cfeef13..ef658bcc 100755 --- a/src/Entity/RolfRisk.php +++ b/src/Entity/RolfRisk.php @@ -1,21 +1,58 @@ -anr; + } + + public function setAnr(Anr $anr): self + { + $this->anr = $anr; + + return $this; + } } diff --git a/src/Entity/RolfTag.php b/src/Entity/RolfTag.php index 9b1df999..939aa14a 100755 --- a/src/Entity/RolfTag.php +++ b/src/Entity/RolfTag.php @@ -1,7 +1,7 @@ -anr; + } + + public function setAnr(Anr $anr): self + { + $this->anr = $anr; + + return $this; + } } diff --git a/src/Entity/Snapshot.php b/src/Entity/Snapshot.php index 34ff9105..b4fde9ab 100755 --- a/src/Entity/Snapshot.php +++ b/src/Entity/Snapshot.php @@ -34,7 +34,7 @@ class Snapshot * * @var Anr * - * @ORM\OneToOne(targetEntity="Anr", cascade={"persist", "remove"}) + * @ORM\OneToOne(targetEntity="Anr", cascade={"remove"}) * @ORM\JoinColumns({ * @ORM\JoinColumn(name="anr_id", referencedColumnName="id", nullable=false, onDelete="CASCADE") * }) @@ -47,7 +47,7 @@ class Snapshot * * @var Anr * - * @ORM\ManyToOne(targetEntity="Anr", cascade={"persist"}) + * @ORM\ManyToOne(targetEntity="Anr") * @ORM\JoinColumns({ * @ORM\JoinColumn(name="anr_reference_id", referencedColumnName="id", nullable=false, onDelete="CASCADE") * }) @@ -74,7 +74,6 @@ public function getAnr(): Anr public function setAnr(Anr $anr): self { $this->anr = $anr; - $anr->setSnapshot($this); return $this; } diff --git a/src/Entity/SoaCategory.php b/src/Entity/SoaCategory.php index 548c9177..9c8a45bd 100755 --- a/src/Entity/SoaCategory.php +++ b/src/Entity/SoaCategory.php @@ -1,9 +1,9 @@ -anr; } - /** - * @param Anr $anr - */ - public function setAnr($anr): self + public function setAnr(Anr $anr): self { $this->anr = $anr; diff --git a/src/Import/Helper/ImportCacheHelper.php b/src/Import/Helper/ImportCacheHelper.php index 398e30a6..44fb45ec 100644 --- a/src/Import/Helper/ImportCacheHelper.php +++ b/src/Import/Helper/ImportCacheHelper.php @@ -7,30 +7,31 @@ namespace Monarc\FrontOffice\Import\Helper; -use Monarc\FrontOffice\Entity\Anr; -use Monarc\FrontOffice\Model\Table\SoaCategoryTable; -use Monarc\FrontOffice\Table\ThemeTable; +use Monarc\FrontOffice\Entity; +use Monarc\FrontOffice\Table; class ImportCacheHelper { private array $arrayCache = []; - public function __construct(private ThemeTable $themeTable, private SoaCategoryTable $soaCategoryTable) + public function __construct(private Table\ThemeTable $themeTable, private Table\SoaCategoryTable $soaCategoryTable) { } - public function prepareThemesCacheData(Anr $anr): void + public function prepareThemesCacheData(Entity\Anr $anr): void { if (!isset($this->arrayCache['themes_by_labels'])) { + /** @var Entity\Theme $theme */ foreach ($this->themeTable->findByAnr($anr) as $theme) { $this->addItemToArrayCache('themes_by_labels', $theme, $theme->getLabel($anr->getLanguage())); } } } - public function prepareSoaCategoriesCacheData(Anr $anr): void + public function prepareSoaCategoriesCacheData(Entity\Anr $anr): void { if (!isset($this->arrayCache['soa_categories_by_ref_and_label'])) { + /** @var Entity\SoaCategory $soaCategory */ foreach ($this->soaCategoryTable->findByAnr($anr) as $soaCategory) { $this->addItemToArrayCache( 'soa_categories_by_ref_and_label', diff --git a/src/Model/Table/MeasureMeasureTable.php b/src/Model/Table/MeasureMeasureTable.php deleted file mode 100644 index 2ed6a23a..00000000 --- a/src/Model/Table/MeasureMeasureTable.php +++ /dev/null @@ -1,50 +0,0 @@ -getRepository()->createQueryBuilder('mm') - ->where('mm.anr = :anr') - ->andWhere('mm.father = :father') - ->andWhere('mm.child = :child') - ->setParameter('anr', $anr) - ->setParameter('father', $fatherUuid) - ->setParameter('child', $childUuid) - ->setMaxResults(1) - ->getQuery() - ->getOneOrNullResult(AbstractQuery::HYDRATE_SIMPLEOBJECT) !== null; - } - - public function saveEntity(MeasureMeasure $measureMeasure, bool $flush = true): void - { - $em = $this->getDb()->getEntityManager(); - $em->persist($measureMeasure); - if ($flush) { - $em->flush(); - } - } -} diff --git a/src/Model/Table/MeasureTable.php b/src/Model/Table/MeasureTable.php deleted file mode 100755 index 159ffdd5..00000000 --- a/src/Model/Table/MeasureTable.php +++ /dev/null @@ -1,51 +0,0 @@ -entityClass = Measure::class; - } - - /** - * @return Measure[] - */ - public function findByAnr(Anr $anr): array - { - return $this->getRepository() - ->createQueryBuilder('m') - ->where('m.anr = :anr') - ->setParameter('anr', $anr) - ->getQuery() - ->getResult(); - } - - public function findByAnrAndUuid(AnrSuperClass $anr, string $uuid): ?Measure - { - return $this->getRepository() - ->createQueryBuilder('m') - ->where('m.anr = :anr') - ->setParameter('anr', $anr) - ->andWhere('m.uuid = :uuid') - ->setParameter('uuid', $uuid) - ->setMaxResults(1) - ->getQuery() - ->getOneOrNullResult(); - } -} diff --git a/src/Model/Table/ReferentialTable.php b/src/Model/Table/ReferentialTable.php deleted file mode 100644 index e397468e..00000000 --- a/src/Model/Table/ReferentialTable.php +++ /dev/null @@ -1,71 +0,0 @@ -getRepository() - ->createQueryBuilder('r') - ->where('r.anr = :anr') - ->setParameter('anr', $anr) - ->getQuery() - ->getResult(); - } - - /** - * @return Referential|null - * @throws NonUniqueResultException - */ - public function findByAnrAndUuid(Anr $anr, string $uuid): ?Referential - { - return $this->getRepository() - ->createQueryBuilder('r') - ->where('r.anr = :anr') - ->andWhere('r.uuid = :uuid') - ->setParameter('anr', $anr) - ->setParameter('uuid', $uuid) - ->getQuery() - ->getOneOrNullResult(); - } - - public function saveEntity(ReferentialSuperClass $referential, bool $flushAll = true): void - { - $em = $this->getDb()->getEntityManager(); - $em->persist($referential); - if ($flushAll) { - $em->flush(); - } - } - - public function deleteEntity(ReferentialSuperClass $referential, bool $flushAll = true): void - { - $em = $this->getDb()->getEntityManager(); - $em->remove($referential); - if ($flushAll) { - $em->flush(); - } - } -} diff --git a/src/Model/Table/RolfRiskTable.php b/src/Model/Table/RolfRiskTable.php deleted file mode 100755 index 8874628a..00000000 --- a/src/Model/Table/RolfRiskTable.php +++ /dev/null @@ -1,48 +0,0 @@ -entityClass = RolfRisk::class; - } - - /** - * @return RolfRisk[] - */ - public function findByAnr(Anr $anr): array - { - return $this->getRepository()->createQueryBuilder('rr') - ->where('rr.anr = :anr') - ->setParameter('anr', $anr) - ->getQuery() - ->getResult(); - } - - public function findByAnrAndCode(Anr $anr, string $code): ?RolfRisk - { - return $this->getRepository()->createQueryBuilder('rr') - ->where('rr.anr = :anr') - ->andWhere('rr.code = :code') - ->setParameter('anr', $anr) - ->setParameter('code', $code) - ->setMaxResults(1) - ->getQuery() - ->getOneOrNullResult(); - } -} diff --git a/src/Model/Table/RolfTagTable.php b/src/Model/Table/RolfTagTable.php deleted file mode 100755 index 8cea8327..00000000 --- a/src/Model/Table/RolfTagTable.php +++ /dev/null @@ -1,76 +0,0 @@ -entityClass = RolfTag::class; - } - - /** - * @return RolfTag[] - */ - public function findByAnr(Anr $anr): array - { - return $this->getRepository()->createQueryBuilder('rt') - ->where('rt.anr = :anr') - ->setParameter('anr', $anr) - ->getQuery() - ->getResult(); - } - - public function findByAnrAndCode(Anr $anr, string $code): ?RolfTag - { - return $this->getRepository()->createQueryBuilder('rt') - ->where('rt.anr = :anr') - ->setParameter('anr', $anr) - ->andWhere('rt.code = :code') - ->setParameter('code', $code) - ->setMaxResults(1) - ->getQuery() - ->getOneOrNullResult(); - } - - public function findByIdAndAnr(int $id, Anr $anr): RolfTag - { - /** @var RolfTag|null $rolfTag */ - $rolfTag = $this->getRepository()->createQueryBuilder('rt') - ->where('rt.id = :id') - ->andWhere('rt.anr = :anr') - ->setParameter('id', $id) - ->setParameter('anr', $anr) - ->setMaxResults(1) - ->getQuery() - ->getOneOrNullResult(); - if ($rolfTag === null) { - throw EntityNotFoundException::fromClassNameAndIdentifier(\get_class($this), [$id]); - } - - return $rolfTag; - } - - public function saveEntity(RolfTag $rolfTag, bool $flushAll = true): void - { - $em = $this->getDb()->getEntityManager(); - $em->persist($rolfTag); - if ($flushAll) { - $em->flush(); - } - } -} diff --git a/src/Model/Table/SoaCategoryTable.php b/src/Model/Table/SoaCategoryTable.php deleted file mode 100755 index 2230d4de..00000000 --- a/src/Model/Table/SoaCategoryTable.php +++ /dev/null @@ -1,51 +0,0 @@ -getRepository()->createQueryBuilder('sc') - ->select('sc', 'ref') - ->innerJoin('sc.referential', 'ref') - ->where('sc.anr = :anr') - ->setParameter('anr', $anr) - ->getQuery() - ->getResult(); - } - - public function saveEntity(SoaCategorySuperClass $soaCategory, bool $flushAll = true): void - { - $em = $this->getDb()->getEntityManager(); - $em->persist($soaCategory); - if ($flushAll) { - $em->flush(); - } - } -} diff --git a/src/Service/AnrAmvService.php b/src/Service/AnrAmvService.php index 9beafb6c..579e0579 100755 --- a/src/Service/AnrAmvService.php +++ b/src/Service/AnrAmvService.php @@ -17,7 +17,6 @@ use Monarc\Core\Service\Interfaces\PositionUpdatableServiceInterface; use Monarc\Core\Service\Traits\PositionUpdateTrait; use Monarc\FrontOffice\Entity; -use Monarc\FrontOffice\Model\Table as DeprecatedTable; use Monarc\FrontOffice\Table; class AnrAmvService implements PositionUpdatableServiceInterface @@ -33,8 +32,8 @@ public function __construct( private Table\ThemeTable $themeTable, private Table\VulnerabilityTable $vulnerabilityTable, private Table\InstanceRiskTable $instanceRiskTable, - private DeprecatedTable\MeasureTable $measureTable, - private DeprecatedTable\ReferentialTable $referentialTable, + private Table\MeasureTable $measureTable, + private Table\ReferentialTable $referentialTable, private AnrAssetService $anrAssetService, private AnrThreatService $anrThreatService, private AnrVulnerabilityService $anrVulnerabilityService, @@ -111,7 +110,9 @@ public function createAmvFromPreparedData( } foreach ($data['measures'] ?? [] as $measureUuid) { - $amv->addMeasure($this->measureTable->findByAnrAndUuid($anr, $measureUuid)); + /** @var Entity\Measure $measure */ + $measure = $this->measureTable->findByUuidAndAnr($measureUuid, $anr); + $amv->addMeasure($measure); } $this->updatePositions($amv, $this->amvTable, $data); @@ -138,8 +139,10 @@ public function update(Entity\Anr $anr, string $uuid, array $data): Entity\Amv $amv->removeMeasure($measure); } } - foreach ($data['measures'] as $measure) { - $amv->addMeasure($this->measureTable->findByAnrAndUuid($anr, $measure)); + foreach ($data['measures'] as $measureUuid) { + /** @var Entity\Measure $measure */ + $measure = $this->measureTable->findByUuidAndAnr($measureUuid, $anr); + $amv->addMeasure($measure); } $amv->setUpdater($this->connectedUser->getEmail()); @@ -231,7 +234,7 @@ public function createLinkedAmvs( string $destinationReferentialUuid ): void { /** @var Entity\Referential $referential */ - $referential = $this->referentialTable->findByAnrAndUuid($anr, $destinationReferentialUuid); + $referential = $this->referentialTable->findByUuidAndAnr($destinationReferentialUuid, $anr); foreach ($referential->getMeasures() as $destinationMeasure) { foreach ($destinationMeasure->getLinkedMeasures() as $measureLink) { if ($measureLink->getReferential()->getUuid() === $sourceReferentialUuid) { @@ -242,7 +245,7 @@ public function createLinkedAmvs( } } } - $this->measureTable->getDb()->flush(); + $this->measureTable->flush(); } public function delete(Entity\Anr $anr, string $uuid): void diff --git a/src/Service/AnrAssetService.php b/src/Service/AnrAssetService.php index ad39ccb9..04539744 100755 --- a/src/Service/AnrAssetService.php +++ b/src/Service/AnrAssetService.php @@ -72,6 +72,17 @@ public function create(Entity\Anr $anr, array $data, bool $saveInDb = true): Ent return $asset; } + public function createList(Entity\Anr $anr, array $data): array + { + $createdUuids = []; + foreach ($data as $row) { + $createdUuids[] = $this->create($anr, $row, false)->getUuid(); + } + $this->assetTable->flush(); + + return $createdUuids; + } + public function update(Entity\Anr $anr, string $uuid, array $data): Entity\Asset { /** @var Entity\Asset $asset */ diff --git a/src/Service/AnrInstanceRiskOpService.php b/src/Service/AnrInstanceRiskOpService.php index fa2911ec..8ec4d9fd 100644 --- a/src/Service/AnrInstanceRiskOpService.php +++ b/src/Service/AnrInstanceRiskOpService.php @@ -12,7 +12,6 @@ use Monarc\Core\Service as CoreService; use Monarc\Core\Service\Traits\OperationalRiskScaleVerificationTrait; use Monarc\FrontOffice\Entity; -use Monarc\FrontOffice\Model\Table as DeprecatedTable; use Monarc\FrontOffice\Service\Traits\RecommendationsPositionsUpdateTrait; use Monarc\FrontOffice\Table; @@ -30,8 +29,8 @@ public function __construct( private Table\InstanceRiskOpTable $instanceRiskOpTable, private Table\InstanceTable $instanceTable, private Table\OperationalInstanceRiskScaleTable $operationalInstanceRiskScaleTable, - private DeprecatedTable\RolfRiskTable $rolfRiskTable, - private DeprecatedTable\RolfTagTable $rolfTagTable, + private Table\RolfRiskTable $rolfRiskTable, + private Table\RolfTagTable $rolfTagTable, private Table\OperationalRiskScaleTable $operationalRiskScaleTable, private Table\OperationalRiskScaleTypeTable $operationalRiskScaleTypeTable, private Table\RecommendationTable $recommendationTable, @@ -128,7 +127,7 @@ public function createSpecificOperationalInstanceRisk(Entity\Anr $anr, array $da ->setLabels(['label' . $anr->getLanguage() => $data['label']]) ->setDescriptions(['description' . $anr->getLanguage() => $data['description'] ?? '']) ->setCreator($this->connectedUser->getFirstname() . ' ' . $this->connectedUser->getLastname()); - $this->rolfRiskTable->saveEntity($rolfRisk, true); + $this->rolfRiskTable->save($rolfRisk, true); } else { /** @var Entity\RolfRisk $rolfRisk */ $rolfRisk = $this->rolfRiskTable->findById((int)$data['risk']); diff --git a/src/Service/AnrMeasureMeasureService.php b/src/Service/AnrMeasureMeasureService.php index e3df9f49..06459700 100644 --- a/src/Service/AnrMeasureMeasureService.php +++ b/src/Service/AnrMeasureMeasureService.php @@ -1,75 +1,83 @@ -measureMeasureTable->findByAnr($anr) as $measureMeasure) { + $result[] = [ + 'masterMeasure' => array_merge([ + 'uuid' => $measureMeasure->getMasterMeasure()->getUuid(), + 'code' => $measureMeasure->getMasterMeasure()->getCode(), + ], $measureMeasure->getMasterMeasure()->getLabels()), + 'linkedMeasure' => array_merge([ + 'uuid' => $measureMeasure->getLinkedMeasure()->getUuid(), + 'code' => $measureMeasure->getLinkedMeasure()->getCode(), + ], $measureMeasure->getLinkedMeasure()->getLabels()), + ]; } - $anrTable = $this->get('anrTable'); - $measureMeasureTable = $this->get('table'); - $measuresMeasures = $measureMeasureTable->getEntityByFields([ - 'anr' => $data['anr'], - 'child' => $data['child']['uuid'], - 'father' => $data['father']['uuid'] - ]); + return $result; + } - if (!empty($measuresMeasures)) { // the linkk already exist - throw new Exception('This component already exist for this object', 412); + public function create(Entity\Anr $anr, array $data, bool $saveInDb = true): Entity\Measure + { + if ($data['masterMeasureUuid'] === $data['linkedMeasureUuid']) { + throw new Exception('It is not possible to link a control to itself', 412); } - $anr = $anrTable->getEntity($data['anr']); + /** @var Entity\Measure $masterMeasure */ + $masterMeasure = $this->measureTable->findByUuidAndAnr($data['masterMeasureUuid'], $anr); + /** @var Entity\Measure $linkedMeasure */ + $linkedMeasure = $this->measureTable->findByUuidAndAnr($data['linkedMeasureUuid'], $anr); - /** @var MeasureMeasure $measureMeasure */ - $measureMeasureClass = $this->get('entity'); - $measureMeasure = new $measureMeasureClass(); - $measureMeasure->setAnr($anr); - $measureMeasure->setFather($data['father']['uuid']); - $measureMeasure->setChild($data['child']['uuid']); - $measureMeasureTable->save($measureMeasure, false); - $measureMeasureReversed = clone $measureMeasure; - $measureMeasureReversed->setFather($data['child']['uuid']); - $measureMeasureReversed->setChild($data['father']['uuid']); - $measureMeasureTable->save($measureMeasureReversed); + $masterMeasure->addLinkedMeasure($linkedMeasure); + $this->measureTable->save($linkedMeasure, $saveInDb); + + return $masterMeasure; + } + + /** + * @return string[] + */ + public function createList(Entity\Anr $anr, array $data): array + { + $createdIds = []; + foreach ($data as $rowData) { + $createdIds[] = $this->create($anr, $rowData, false)->getUuid(); + } + $this->measureMeasureTable->flush(); - return null; + return $createdIds; } - public function delete($id) + public function delete(Entity\Anr $anr, string $masterMeasureUuid, string $linkedMeasureUuid): void { - $measureTable = $this->get('measureTable'); - $father = $measureTable->getEntity(['uuid' => $id['father'], 'anr' => $id['anr']]); - $child = $measureTable->getEntity(['uuid' => $id['child'], 'anr' => $id['anr']]); - $father->removeLinkedMeasure($child); + /** @var Entity\Measure $masterMeasure */ + $masterMeasure = $this->measureTable->findByUuidAndAnr($masterMeasureUuid, $anr); + /** @var Entity\Measure $linkedMeasure */ + $linkedMeasure = $this->measureTable->findByUuidAndAnr($linkedMeasureUuid, $anr); + $masterMeasure->removeLinkedMeasure($linkedMeasure); - $measureTable->save($father); + $this->measureTable->save($masterMeasure); } } diff --git a/src/Service/AnrMeasureMeasureServiceFactory.php b/src/Service/AnrMeasureMeasureServiceFactory.php deleted file mode 100644 index b3f0453c..00000000 --- a/src/Service/AnrMeasureMeasureServiceFactory.php +++ /dev/null @@ -1,27 +0,0 @@ - 'Monarc\FrontOffice\Entity\MeasureMeasure', - 'table' => 'Monarc\FrontOffice\Model\Table\MeasureMeasureTable', - 'anrTable' => AnrTable::class, - 'userAnrTable' => UserAnrTable::class, - 'measureTable' => 'Monarc\FrontOffice\Model\Table\MeasureTable', - ]; -} diff --git a/src/Service/AnrMeasureService.php b/src/Service/AnrMeasureService.php index f653d825..c56ac772 100755 --- a/src/Service/AnrMeasureService.php +++ b/src/Service/AnrMeasureService.php @@ -1,58 +1,165 @@ -connectedUser = $connectedUserService->getConnectedUser(); + } + + public function getList(FormattedInputParams $params): array + { + $result = []; + + /** @var Entity\Measure[] $measures */ + $measures = $this->measureTable->findByParams($params); + $includeLinks = $params->hasFilterFor('includeLinks') && $params->getFilterFor('includeLinks')['value']; + foreach ($measures as $measure) { + $result[] = $this->prepareMeasureDataResult($measure, $includeLinks); + } + + return $result; + } + + public function getCount(FormattedInputParams $params): int + { + return $this->measureTable->countByParams($params); + } + + public function getMeasureData(Entity\Anr $anr, string $uuid): array + { + /** @var Entity\Measure $measure */ + $measure = $this->measureTable->findByUuidAndAnr($uuid, $anr); + + return $this->prepareMeasureDataResult($measure); + } + + public function create(Entity\Anr $anr, array $data, bool $saveInDb = true): Entity\Measure + { + /** @var Entity\Referential $referential */ + $referential = $this->referentialTable->findByUuidAndAnr($data['referentialUuid'], $anr); + /** @var Entity\SoaCategory $soaCategory */ + $soaCategory = $this->soaCategoryTable->findByIdAndAnr($data['categoryId'], $anr); + + /** @var Entity\Measure $measure */ + $measure = (new Entity\Measure()) + ->setAnr($anr) + ->setCode($data['code']) + ->setLabels($data) + ->setReferential($referential) + ->setCategory($soaCategory) + ->setCreator($this->connectedUser->getEmail()); + + $this->measureTable->save($measure, $saveInDb); + + return $measure; + } + + public function createList(Entity\Anr $anr, array $data): array + { + $createdUuids = []; + foreach ($data as $row) { + $createdUuids[] = $this->create($anr, $row, false)->getUuid(); } - $table = $this->get('table'); - $SoaClass = $this->get('soaEntity'); - $SoaTable = $this->get('soaTable'); - $anrTable = $this->get('anrTable'); - $measure = $table->getEntity(['uuid' =>$uuid,'anr'=>$data['anr']]); - $anr = $anrTable->getEntity($data['anr']); - $SoaEntity = new $SoaClass(); - $SoaEntity->setMeasure($measure); - $SoaEntity->setAnr($anr); - $SoaTable->save($SoaEntity, $last); + $this->measureTable->flush(); + + return $createdUuids; + } + + public function update(Entity\Anr $anr, string $uuid, array $data): Entity\Measure + { + /** @var Entity\Measure $measure */ + $measure = $this->measureTable->findByUuidAndAnr($uuid, $anr); + $measure->setLabels($data) + ->setCode($data['code']) + ->setUpdater($this->connectedUser->getEmail()); + if ($measure->getCategory() === null || $measure->getCategory()->getId() !== $data['categoryId']) { + $previousLinkedCategory = $measure->getCategory(); + /** @var Entity\SoaCategory $soaCategory */ + $soaCategory = $this->soaCategoryTable->findByIdAndAnr($data['categoryId'], $anr); + $measure->setCategory($soaCategory); + if ($previousLinkedCategory !== null && $previousLinkedCategory->getMeasures()->isEmpty()) { + $this->soaCategoryTable->remove($previousLinkedCategory, false); + } + } + + $this->measureTable->save($measure); + + return $measure; + } + + public function delete(Entity\Anr $anr, string $uuid): void + { + /** @var Entity\Measure $measure */ + $measure = $this->measureTable->findByUuidAndAnr($uuid, $anr); + + $this->processMeasureRemoval($measure); + } + + public function deleteList(Entity\Anr $anr, array $data) + { + /** @var Entity\Measure[] $measures */ + $measures = $this->measureTable->findByUuidsAndAnr($data, $anr); + + foreach ($measures as $measure) { + $this->processMeasureRemoval($measure, false); + } + $this->measureTable->flush(); + } + + private function processMeasureRemoval(Entity\Measure $measure, bool $saveInDb = true): void + { + $previousLinkedCategory = $measure->getCategory(); + $measure->setCategory(null); + if ($previousLinkedCategory !== null && $previousLinkedCategory->getMeasures()->isEmpty()) { + $this->soaCategoryTable->remove($previousLinkedCategory, false); + } + + $this->measureTable->remove($measure, $saveInDb); + } + + private function prepareMeasureDataResult(Entity\Measure $measure, bool $includeLinks = false): array + { + $linkedMeasures = []; + if ($includeLinks) { + foreach ($measure->getLinkedMeasures() as $linkedMeasure) { + $linkedMeasures[] = array_merge([ + 'uuid' => $linkedMeasure->getUuid(), + 'code' => $linkedMeasure->getCode(), + ], $linkedMeasure->getLabels()); + } + } + + return array_merge([ + 'uuid' => $measure->getUuid(), + 'referential' => array_merge([ + 'uuid' => $measure->getReferential()->getUuid(), + ], $measure->getReferential()->getLabels()), + 'code' => $measure->getCode(), + 'category' => $measure->getCategory() === null + ? [] + : array_merge(['id' => $measure->getCategory()->getId()], $measure->getCategory()->getLabels()), + 'status' => $measure->getStatus(), + 'linkedMeasures' => $linkedMeasures, + ], $measure->getLabels()); } } diff --git a/src/Service/AnrMeasureServiceFactory.php b/src/Service/AnrMeasureServiceFactory.php deleted file mode 100755 index 2860f406..00000000 --- a/src/Service/AnrMeasureServiceFactory.php +++ /dev/null @@ -1,29 +0,0 @@ - 'Monarc\FrontOffice\Entity\Measure', - 'table' => 'Monarc\FrontOffice\Model\Table\MeasureTable', - 'anrTable' => AnrTable::class, - 'userAnrTable' => UserAnrTable::class, - 'soaEntity' => 'Monarc\FrontOffice\Entity\Soa', - 'soaTable' => 'Monarc\FrontOffice\Model\Table\SoaTable', - 'soaCategoryTable' => 'Monarc\FrontOffice\Model\Table\SoaCategoryTable', - ]; -} diff --git a/src/Service/AnrModelService.php b/src/Service/AnrModelService.php index 00a943c3..310b2637 100644 --- a/src/Service/AnrModelService.php +++ b/src/Service/AnrModelService.php @@ -22,9 +22,9 @@ public function __construct( private CoreTable\ThreatTable $coreThreatTable, private CoreTable\VulnerabilityTable $coreVulnerabilityTable, private CoreTable\ScaleImpactTypeTable $coreScaleImpactTypeTable, - private CoreDeprecatedTable\MeasureTable $coreMeasureTable, - private CoreDeprecatedTable\RolfRiskTable $coreRolfRiskTable, - private CoreDeprecatedTable\RolfTagTable $coreRolfTagTable, + private CoreTable\MeasureTable $coreMeasureTable, + private CoreTable\RolfRiskTable $coreRolfRiskTable, + private CoreTable\RolfTagTable $coreRolfTagTable, private CoreDeprecatedTable\QuestionTable $coreQuestionTable, private CoreDeprecatedTable\QuestionChoiceTable $coreQuestionChoiceTable, private ConfigService $configService @@ -65,15 +65,15 @@ public function getAvailableLanguages(int $modelId): array /* Validates measures, rolf tags, rolf risks, questions and questions choices. */ /** @var CoreEntity\Measure $measure */ - foreach ($this->coreMeasureTable->fetchAllObject() as $measure) { + foreach ($this->coreMeasureTable->findAll() as $measure) { $this->validateEntityLanguages($measure, $result); } /** @var CoreEntity\RolfRisk $rolfRisk */ - foreach ($this->coreRolfRiskTable->fetchAllObject() as $rolfRisk) { + foreach ($this->coreRolfRiskTable->findAll() as $rolfRisk) { $this->validateEntityLanguages($rolfRisk, $result); } /** @var CoreEntity\RolfTag $rolfTag */ - foreach ($this->coreRolfTagTable->fetchAllObject() as $rolfTag) { + foreach ($this->coreRolfTagTable->findAll() as $rolfTag) { $this->validateEntityLanguages($rolfTag, $result); } /** @var CoreEntity\Question $question */ diff --git a/src/Service/AnrRecommendationService.php b/src/Service/AnrRecommendationService.php index 70acf983..7ddd4364 100755 --- a/src/Service/AnrRecommendationService.php +++ b/src/Service/AnrRecommendationService.php @@ -105,13 +105,14 @@ public function create(Entity\Anr $anr, array $data, bool $saveInDb = true): Ent */ public function createList(Entity\Anr $anr, array $data): array { - $createdRecommendationsUuids = []; + $createdUuids = []; foreach ($data as $recommendationData) { - $object = $this->create($anr, $recommendationData, false); - $createdRecommendationsUuids[] = $object->getUuid(); + $createdUuids[] = $this->create($anr, $recommendationData, false)->getUuid(); + } + $this->recommendationTable->flush(); - return $createdRecommendationsUuids; + return $createdUuids; } public function patch(Entity\Anr $anr, string $uuid, array $data): Entity\Recommendation diff --git a/src/Service/AnrReferentialService.php b/src/Service/AnrReferentialService.php index 5a66cd54..19e8c436 100644 --- a/src/Service/AnrReferentialService.php +++ b/src/Service/AnrReferentialService.php @@ -1,57 +1,79 @@ -referentialTable->findByParams($params) as $referential) { + $result[] = $this->prepareReferentialDataResult($referential); + } + + return $result; + } + + public function getReferentialData(Anr $anr, string $uuid): array + { + /** @var Referential $referential */ + $referential = $this->referentialTable->findByUuidAndAnr($uuid, $anr); + + return $this->prepareReferentialDataResult($referential); + } + + public function create(Anr $anr, array $data, bool $saveInDb = true): Referential + { + /** @var Referential $referential */ + $referential = (new Referential())->setAnr($anr)->setLabels($data); + + $this->referentialTable->save($referential, $saveInDb); + + return $referential; + } + + public function update(Anr $anr, string $uuid, array $data): Referential { - $data = $this->get('table')->fetchAllFiltered( - array_keys($this->get('entity')->getJsonArray()), - 1, - 0, - $this->parseFrontendOrder($order), - $this->parseFrontendFilter($filter, $this->filterColumns), - $filterAnd - ); - - return array_slice($data, ($page - 1) * $limit, $limit, false); + /** @var Referential $referential */ + $referential = $this->referentialTable->findByUuidAndAnr($uuid, $anr); + + $referential->setLabels($data); + + $this->referentialTable->save($referential); + + return $referential; } - /** - * Fetches and returns the list of referentials from the common database. - * @param int $filter Keywords to search - * @return array An array of available referentials from the common database (knowledge base) - */ - public function getCommonReferentials($filter, $order) + public function delete(Anr $anr, string $uuid): void { + /** @var Referential $referential */ + $referential = $this->referentialTable->findByUuidAndAnr($uuid, $anr); - // Fetch the referentials from the common database - $selfCoreService = $this->get('selfCoreService'); - $referentials = $selfCoreService->getList(1, 25, $order, $filter, null); + $this->referentialTable->remove($referential); + } + + private function prepareReferentialDataResult(Referential $referential): array + { + $measures = []; + foreach ($referential->getMeasures() as $measure) { + $measures[] = ['uuid' => $measure->getUuid()]; + } - return $referentials; + return array_merge(['uuid' => $referential->getUuid()], $referential->getLabels(), ['measures' => $measures]); } } diff --git a/src/Service/AnrReferentialServiceFactory.php b/src/Service/AnrReferentialServiceFactory.php deleted file mode 100644 index 6c6f5754..00000000 --- a/src/Service/AnrReferentialServiceFactory.php +++ /dev/null @@ -1,27 +0,0 @@ - 'Monarc\FrontOffice\Model\Table\ReferentialTable', - 'entity' => 'Monarc\FrontOffice\Entity\Referential', - 'userAnrTable' => UserAnrTable::class, - 'selfCoreService' => 'Monarc\Core\Service\ReferentialService', - ]; -} diff --git a/src/Service/AnrRolfRiskService.php b/src/Service/AnrRolfRiskService.php index 1acc3ec6..83489da5 100755 --- a/src/Service/AnrRolfRiskService.php +++ b/src/Service/AnrRolfRiskService.php @@ -1,26 +1,262 @@ -connectedUser = $connectedUserService->getConnectedUser(); + } + + public function getList(FormattedInputParams $formattedInputParams): array + { + $rolfRiskData = []; + /** @var Entity\RolfRisk $rolfRisk */ + foreach ($this->rolfRiskTable->findByParams($formattedInputParams) as $rolfRisk) { + $rolfRiskData[] = $this->prepareRolfRiskData($rolfRisk); + } + + return $rolfRiskData; + } + + public function getCount(FormattedInputParams $formattedInputParams): int + { + return $this->rolfRiskTable->countByParams($formattedInputParams); + } + + public function getRolfRiskData(Entity\Anr $anr, int $id): array + { + /** @var Entity\RolfRisk $rolfRisk */ + $rolfRisk = $this->rolfRiskTable->findByIdAndAnr($id, $anr); + + return $this->prepareRolfRiskData($rolfRisk); + } + + public function create(Entity\Anr $anr, array $data, bool $saveInDb = true): Entity\RolfRisk + { + /** @var Entity\RolfRisk $rolfRisk */ + $rolfRisk = (new Entity\RolfRisk()) + ->setAnr($anr) + ->setCode($data['code']) + ->setLabels($data) + ->setDescriptions($data) + ->setCreator($this->connectedUser->getEmail()); + + if (!empty($data['measures'])) { + /** @var Entity\Measure $measure */ + foreach ($this->measureTable->findByUuidsAndAnr($data['measures'], $anr) as $measure) { + $rolfRisk->addMeasure($measure); + } + } + if (!empty($data['tags'])) { + /** @var Entity\RolfTag $tag */ + foreach ($this->rolfTagTable->findByIdsAndAnr($data['tags'], $anr) as $tag) { + $rolfRisk->addTag($tag); + /* Create operation instance risks for the linked rolf tag. */ + /** @var Entity\MonarcObject $monarcObject */ + foreach ($this->monarcObjectTable->findByAnrAndRolfTag($anr, $tag) as $monarcObject) { + foreach ($monarcObject->getInstances() as $instance) { + $this->anrInstanceRiskOpService->createInstanceRiskOpWithScales( + $instance, + $monarcObject, + $rolfRisk + ); + } + } + } + } + + $this->rolfRiskTable->save($rolfRisk, $saveInDb); + + return $rolfRisk; + } + + public function createList(Entity\Anr $anr, array $data): array + { + $createdRowsNum = []; + foreach ($data as $rowNum => $rowData) { + $this->create($anr, $rowData, false); + $createdRowsNum[] = $rowNum; + } + $this->rolfRiskTable->flush(); + + return $createdRowsNum; + } + + public function update(Entity\Anr $anr, int $id, array $data): Entity\RolfRisk + { + /** @var Entity\RolfRisk $rolfRisk */ + $rolfRisk = $this->rolfRiskTable->findByIdAndAnr($id, $anr); + + $rolfRisk->removeAllMeasures(); + if (!empty($data['measures'])) { + /** @var Entity\Measure $measure */ + foreach ($this->measureTable->findByUuidsAndAnr($data['measures'], $anr) as $measure) { + $rolfRisk->addMeasure($measure); + } + } + + $rolfTagIds = array_map('\intval', $data['tags']); + foreach ($rolfRisk->getTags() as $rolfTag) { + $rolfTagIdKey = \array_search($rolfTag->getId(), $rolfTagIds, true); + if ($rolfTagIdKey !== false) { + unset($rolfTagIds[$rolfTagIdKey]); + } else { + $rolfRisk->removeTag($rolfTag); + /* Set the related operational risks to specific. */ + foreach ($this->monarcObjectTable->findByAnrAndRolfTag($anr, $rolfTag) as $monarcObject) { + $instancesRisksOp = $this->instanceRiskOpTable->findByObjectAndRolfRisk($monarcObject, $rolfRisk); + foreach ($instancesRisksOp as $instanceRiskOp) { + $this->instanceRiskOpTable->save($instanceRiskOp->setIsSpecific(true), false); + } + } + } + } + if (!empty($rolfTagIds)) { + /** @var Entity\RolfTag $rolfTag */ + foreach ($this->rolfTagTable->findByIdsAndAnr($rolfTagIds, $anr) as $rolfTag) { + $rolfRisk->addTag($rolfTag); + /* Create operation instance risks for the linked rolf tag. */ + /** @var Entity\MonarcObject $monarcObject */ + foreach ($this->monarcObjectTable->findByAnrAndRolfTag($anr, $rolfTag) as $monarcObject) { + foreach ($monarcObject->getInstances() as $instance) { + $this->anrInstanceRiskOpService->createInstanceRiskOpWithScales( + $instance, + $monarcObject, + $rolfRisk + ); + } + } + } + } + + if ($rolfRisk->areLabelsDifferent($data) || $rolfRisk->areDescriptionsDifferent($data)) { + $rolfRisk->setLabels($data)->setDescriptions($data); + /* If the labels or descriptions changed the operational risks labels have to be updated as well. */ + foreach ($rolfRisk->getTags() as $rolfTag) { + foreach ($this->monarcObjectTable->findByAnrAndRolfTag($anr, $rolfTag) as $monarcObject) { + $instancesRisksOp = $this->instanceRiskOpTable->findByObjectAndRolfRisk($monarcObject, $rolfRisk); + foreach ($instancesRisksOp as $instanceRiskOp) { + $instanceRiskOp->setRiskCacheCode($rolfRisk->getCode()) + ->setRiskCacheLabels([ + 'riskCacheLabel1' => $rolfRisk->getLabel(1), + 'riskCacheLabel2' => $rolfRisk->getLabel(2), + 'riskCacheLabel3' => $rolfRisk->getLabel(3), + 'riskCacheLabel4' => $rolfRisk->getLabel(4), + ]) + ->setRiskCacheDescriptions([ + 'riskCacheDescription1' => $rolfRisk->getDescription(1), + 'riskCacheDescription2' => $rolfRisk->getDescription(2), + 'riskCacheDescription3' => $rolfRisk->getDescription(3), + 'riskCacheDescription4' => $rolfRisk->getDescription(4), + ]); + + $this->instanceRiskOpTable->save($instanceRiskOp, false); + } + } + } + } + + $this->rolfRiskTable->save($rolfRisk->setCode($data['code'])->setUpdater($this->connectedUser->getEmail())); + + return $rolfRisk; + } + + public function delete(Entity\Anr $anr, int $id): void + { + /** @var Entity\RolfRisk $rolfRisk */ + $rolfRisk = $this->rolfRiskTable->findByIdAndAnr($id, $anr); + $this->removeRolfRisk($anr, $rolfRisk); + } + + public function deleteList(Entity\Anr $anr, array $data): void + { + /** @var Entity\RolfRisk $rolfRisk */ + foreach ($this->rolfRiskTable->findByIdsAndAnr($data, $anr) as $rolfRisk) { + $this->removeRolfRisk($anr, $rolfRisk, false); + } + $this->rolfRiskTable->flush(); + } + + /** + * Performs the measures linking to the rolf risks when a new referential mapping is processed. + */ + public function linkMeasuresToRisks( + Entity\Anr $anr, + string $sourceReferentialUuid, + string $destinationReferentialUuid + ): void { + /** @var Entity\Referential $destinationReferential */ + $destinationReferential = $this->referentialTable->findByUuidAndAnr($destinationReferentialUuid, $anr); + foreach ($destinationReferential->getMeasures() as $destinationMeasure) { + foreach ($destinationMeasure->getLinkedMeasures() as $measureLink) { + if ($measureLink->getReferential()->getUuid() === $sourceReferentialUuid) { + foreach ($measureLink->getRolfRisks() as $rolfRisk) { + $destinationMeasure->addRolfRisk($rolfRisk); + } + $this->measureTable->save($destinationMeasure, false); + } + } + } + $this->measureTable->flush(); + } + + private function removeRolfRisk(Entity\Anr $anr, Entity\RolfRisk $rolfRisk, bool $saveInDb = true): void + { + foreach ($this->instanceRiskOpTable->findByAnrAndRolfRisk($anr, $rolfRisk) as $instanceRiskOp) { + $this->instanceRiskOpTable->save($instanceRiskOp->setIsSpecific(true), false); + } + + $this->rolfRiskTable->remove($rolfRisk, $saveInDb); + } + + private function prepareRolfRiskData(Entity\RolfRisk $rolfRisk): array + { + $tagsData = []; + foreach ($rolfRisk->getTags() as $tag) { + $tagsData[] = array_merge([ + 'id' => $tag->getId(), + 'code' => $tag->getCode(), + ], $tag->getLabels()); + } + $measuresData = []; + foreach ($rolfRisk->getMeasures() as $measure) { + $measuresData[] = array_merge([ + 'uuid' => $measure->getUuid(), + 'code' => $measure->getCode(), + 'referential' => [ + 'uuid' => $measure->getReferential()->getUuid(), + ], + ], $measure->getLabels()); + } + + return array_merge([ + 'id' => $rolfRisk->getId(), + 'code' => $rolfRisk->getCode(), + 'tags' => $tagsData, + 'measures' => $measuresData, + ], $rolfRisk->getLabels(), $rolfRisk->getDescriptions()); + } } diff --git a/src/Service/AnrRolfRiskServiceFactory.php b/src/Service/AnrRolfRiskServiceFactory.php deleted file mode 100755 index 85deab56..00000000 --- a/src/Service/AnrRolfRiskServiceFactory.php +++ /dev/null @@ -1,30 +0,0 @@ - RolfRisk::class, - 'table' => DeprecatedTable\RolfRiskTable::class, - 'anrTable' => Table\AnrTable::class, - 'tagTable' => DeprecatedTable\RolfTagTable::class, - 'rolfTagTable' => DeprecatedTable\RolfTagTable::class, - 'MonarcObjectTable' => Table\MonarcObjectTable::class, - 'measureTable' => DeprecatedTable\MeasureTable::class, - 'referentialTable' => DeprecatedTable\ReferentialTable::class, - 'instanceRiskOpTable' => Table\InstanceRiskOpTable::class, - 'userAnrTable' => Table\UserAnrTable::class, - 'instanceRiskOpService' => AnrInstanceRiskOpService::class, - ]; -} diff --git a/src/Service/AnrRolfTagService.php b/src/Service/AnrRolfTagService.php index 714ebed6..ebf51f8a 100755 --- a/src/Service/AnrRolfTagService.php +++ b/src/Service/AnrRolfTagService.php @@ -1,20 +1,107 @@ -connectedUser = $connectedUserService->getConnectedUser(); + } + + public function getList(FormattedInputParams $formattedInputParams): array + { + $result = []; + /** @var RolfTag $rolfTag */ + foreach ($this->rolfTagTable->findByParams($formattedInputParams) as $rolfTag) { + $result[] = $this->prepareRolfTagData($rolfTag); + } + + return $result; + } + + public function getCount(FormattedInputParams $formattedInputParams): int + { + return $this->rolfTagTable->countByParams($formattedInputParams); + } + + public function getRolfTagData(Anr $anr, int $id): array + { + /** @var RolfTag $rolfTag */ + $rolfTag = $this->rolfTagTable->findByIdAndAnr($id, $anr); + + return $this->prepareRolfTagData($rolfTag); + } + + public function create(Anr $anr, array $data, bool $saveInDb = true): RolfTag + { + /** @var RolfTag $rolfTag */ + $rolfTag = (new RolfTag()) + ->setAnr($anr) + ->setCode($data['code']) + ->setLabels($data) + ->setCreator($this->connectedUser->getEmail()); + + $this->rolfTagTable->save($rolfTag, $saveInDb); + + return $rolfTag; + } + + public function createList(Anr $anr, array $data): array + { + $createdRowsNumbers = []; + foreach ($data as $rowNum => $rowData) { + $this->create($anr, $rowData, false); + $createdRowsNumbers[] = $rowNum; + } + + return $createdRowsNumbers; + } + + public function update(Anr $anr, int $id, array $data): RolfTag + { + /** @var RolfTag $rolfTag */ + $rolfTag = $this->rolfTagTable->findByIdAndAnr($id, $anr); + + $rolfTag->setCode($data['code'])->setLabels($data)->setUpdater($this->connectedUser->getEmail()); + + $this->rolfTagTable->save($rolfTag); + + return $rolfTag; + } + + public function delete(Anr $anr, int $id): void + { + /** @var RolfTag $rolfTag */ + $rolfTag = $this->rolfTagTable->findByIdAndAnr($id, $anr); + + $this->rolfTagTable->remove($rolfTag); + } + + public function deleteList(Anr $anr, array $data): void + { + $this->rolfTagTable->removeList($this->rolfTagTable->findByIdsAndAnr($data, $anr)); + } + + private function prepareRolfTagData(RolfTag $rolfTag): array + { + return array_merge([ + 'id' => $rolfTag->getId(), + 'code' => $rolfTag->getCode(), + ], $rolfTag->getLabels()); + } } diff --git a/src/Service/AnrRolfTagServiceFactory.php b/src/Service/AnrRolfTagServiceFactory.php deleted file mode 100755 index 9a89a312..00000000 --- a/src/Service/AnrRolfTagServiceFactory.php +++ /dev/null @@ -1,26 +0,0 @@ - 'Monarc\FrontOffice\Entity\RolfTag', - 'table' => 'Monarc\FrontOffice\Model\Table\RolfTagTable', - 'anrTable' => AnrTable::class, - 'userAnrTable' => UserAnrTable::class, - ]; -} diff --git a/src/Service/AnrService.php b/src/Service/AnrService.php index 75aab3ac..ae668996 100755 --- a/src/Service/AnrService.php +++ b/src/Service/AnrService.php @@ -49,12 +49,11 @@ public function __construct( private Table\OperationalRiskScaleCommentTable $operationalRiskScaleCommentTable, private Table\RecommendationRiskTable $recommendationRiskTable, private Table\RecommendationHistoryTable $recommendationHistoryTable, - private DeprecatedTable\ReferentialTable $referentialTable, - private DeprecatedTable\SoaCategoryTable $soaCategoryTable, - private DeprecatedTable\MeasureTable $measureTable, - private DeprecatedTable\MeasureMeasureTable $measureMeasureTable, - private DeprecatedTable\RolfRiskTable $rolfRiskTable, - private DeprecatedTable\RolfTagTable $rolfTagTable, + private Table\ReferentialTable $referentialTable, + private Table\SoaCategoryTable $soaCategoryTable, + private Table\MeasureTable $measureTable, + private Table\RolfRiskTable $rolfRiskTable, + private Table\RolfTagTable $rolfTagTable, private DeprecatedTable\SoaTable $soaTable, private DeprecatedTable\QuestionTable $questionTable, private DeprecatedTable\QuestionChoiceTable $questionChoiceTable, @@ -75,9 +74,9 @@ public function __construct( private CoreTable\TranslationTable $coreTranslationTable, private CoreTable\SoaScaleCommentTable $coreSoaScaleCommentTable, private CoreTable\OperationalRiskScaleTable $coreOperationalRiskScaleTable, - private CoreDeprecatedTable\ReferentialTable $coreReferentialTable, - private CoreDeprecatedTable\RolfRiskTable $coreRolfRiskTable, - private CoreDeprecatedTable\RolfTagTable $coreRolfTagTable, + private CoreTable\ReferentialTable $coreReferentialTable, + private CoreTable\RolfRiskTable $coreRolfRiskTable, + private CoreTable\RolfTagTable $coreRolfTagTable, private CoreDeprecatedTable\QuestionTable $coreQuestionTable, private CoreDeprecatedTable\QuestionChoiceTable $coreQuestionChoiceTable, private AnrModelService $anrModelService, @@ -131,12 +130,15 @@ public function getList(): array public function getAnrData(Entity\Anr $anr): array { - $userAnr = $this->userAnrTable->findByAnrAndUser($anr, $this->connectedUser); - if ($userAnr === null && $anr->isAnrSnapshot()) { - throw new Exception('There is no access to the snapshot of the analysis.', 412); + $realAnrInUse = $anr; + if ($anr->isAnrSnapshot()) { + $realAnrInUse = $anr->getSnapshot()->getAnrReference(); } + $userAnr = $this->userAnrTable->findByAnrAndUser($realAnrInUse, $this->connectedUser); - $this->setCurrentAnrToConnectedUser($anr); + if ($realAnrInUse->getId() !== $this->connectedUser->getCurrentAnr()?->getId()) { + $this->setCurrentAnrToConnectedUser($realAnrInUse); + } return $this->getPreparedAnrData($anr, $userAnr, true); } @@ -166,7 +168,7 @@ public function createBasedOnModel(array $data): Entity\Anr public function duplicateAnr( CoreEntity\AnrSuperClass $sourceAnr, array $data = [], - string $snapshotMode = null + ?string $snapshotMode = null ): Entity\Anr { $isSourceCommon = $sourceAnr instanceof CoreEntity\Anr; if (!$isSourceCommon && $snapshotMode === null) { @@ -211,12 +213,18 @@ public function duplicateAnr( $vulnerabilitiesOldIdsToNewObjects = $this->duplicateVulnerabilities($sourceAnr, $newAnr, $isSourceCommon); /* Recreates Referential, SoaCategories, Measures and links from an existing anr, a snapshot or core. */ + $referentialsUuidsToCreate = !empty($data['referentials']) ? array_column($data['referentials'], 'uuid') : []; + if ($sourceAnr instanceof Entity\Anr) { + foreach ($sourceAnr->getReferentials() as $referential) { + $referentialsUuidsToCreate[] = $referential->getUuid(); + } + } $createdMeasuresUuidsToObjects = []; - if (!empty($data['referentials'])) { + if (!empty($referentialsUuidsToCreate)) { $createdMeasuresUuidsToObjects = $this->updateReferentialsFromSource( $newAnr, $sourceAnr instanceof Entity\Anr ? $sourceAnr : null, - array_column($data['referentials'], 'uuid'), + $referentialsUuidsToCreate, false ); } @@ -346,7 +354,7 @@ public function patch(Entity\Anr $anr, array $data): Entity\Anr } if (isset($data['referentials'])) { - $this->updateReferentialsFromSource($anr, null, array_column($data['referentials'], 'uuid'), true); + $this->updateReferentialsFromSource($anr, null, array_column($data['referentials'], 'uuid')); } $anr->setUpdater($this->connectedUser->getEmail()); @@ -478,7 +486,7 @@ private function updateReferentialsFromSource( } else { /* The operation of removal is not supported in the UI. */ $anr->removeReferential($referential); - $this->referentialTable->deleteEntity($referential, false); + $this->referentialTable->remove($referential, false); } } @@ -488,7 +496,7 @@ private function updateReferentialsFromSource( if ($sourceAnr === null) { $referentialFromSource = $this->coreReferentialTable->findByUuid($referentialUuid); } else { - $referentialFromSource = $this->referentialTable->findByAnrAndUuid($sourceAnr, $referentialUuid); + $referentialFromSource = $this->referentialTable->findByUuidAndAnr($referentialUuid, $sourceAnr); } /* Recreate the source's or core's referential in the analysis. */ @@ -499,17 +507,17 @@ private function updateReferentialsFromSource( ->setUuid($referentialFromSource->getUuid()) ->setCreator($this->connectedUser->getEmail()); - $this->referentialTable->saveEntity($referential, false); + $this->referentialTable->save($referential, false); $linkedReferentialUuids[] = $referential->getUuid(); $categoriesBySourceIds = []; - foreach ($referentialFromSource->getCategories() as $categoryFromCore) { + foreach ($referentialFromSource->getCategories() as $categoryFromSource) { $soaCategory = (new Entity\SoaCategory()) ->setAnr($anr) ->setReferential($referential) - ->setLabels($categoryFromCore->getLabels()); - $this->soaCategoryTable->saveEntity($soaCategory, false); - $categoriesBySourceIds[$categoryFromCore->getId()] = $soaCategory; + ->setLabels($categoryFromSource->getLabels()); + $this->soaCategoryTable->save($soaCategory, false); + $categoriesBySourceIds[$categoryFromSource->getId()] = $soaCategory; } /* Recreates the measures in the analysis. */ @@ -527,32 +535,26 @@ private function updateReferentialsFromSource( foreach ($measureFromSource->getLinkedMeasures() as $linkedMeasureFromSource) { /* Validate if the referential of the linked measure is already create, otherwise it will be linked later if the referential is added to the analysis. */ - if ( - !\in_array($linkedMeasureFromSource->getReferential()->getUuid(), $linkedReferentialUuids, true) - ) { + if (!\in_array( + $linkedMeasureFromSource->getReferential()->getUuid(), + $linkedReferentialUuids, + true + )) { continue; } + /* Validates if the linked measure from the common DB presented in the client's DB. */ $linkedMeasure = $createdMeasuresUuidsToObjects[$linkedMeasureFromSource->getUuid()] - ?? $this->measureTable->findByAnrAndUuid($anr, $linkedMeasureFromSource->getUuid()); + ?? $this->measureTable->findByUuidAndAnr($linkedMeasureFromSource->getUuid(), $anr); if ($linkedMeasure === null) { continue; } /* Recreates the bi-directional links that are defined on the BackOffice side / common DB. */ - $this->measureMeasureTable->saveEntity((new Entity\MeasureMeasure()) - ->setAnr($anr) - ->setFather($measure) - ->setChild($linkedMeasure) - ->setCreator($this->connectedUser->getEmail()), false); - $this->measureMeasureTable->saveEntity((new Entity\MeasureMeasure()) - ->setAnr($anr) - ->setFather($linkedMeasure) - ->setChild($measure) - ->setCreator($this->connectedUser->getEmail()), false); + $measure->addLinkedMeasure($linkedMeasure); } if ($recreateAmvRolfRiskAndSoaLinks) { - // Recreate links with AMVs (information risks) and rolf risks (operation) from source's controls. + /* Recreate links with AMVs (information risks) and rolf risks (operation) from source's controls */ foreach ($measureFromSource->getAmvs() as $amvFromSource) { $amv = $this->amvTable->findByAmvItemsUuidsAndAnr( $amvFromSource->getAsset()->getUuid(), @@ -578,7 +580,7 @@ private function updateReferentialsFromSource( $this->soaTable->saveEntity((new Entity\Soa())->setAnr($anr)->setMeasure($measure), false); } - $this->measureTable->saveEntity($measure, false); + $this->measureTable->save($measure, false); $createdMeasuresUuidsToObjects[$measure->getUuid()] = $measure; } } @@ -931,9 +933,11 @@ private function duplicateAmvs( private function duplicateRolfTags(CoreEntity\AnrSuperClass $sourceAnr, Entity\Anr $newAnr): array { $rolfTagsOldIdsToNewObjects = []; + + /** @var CoreEntity\RolfTagSuperClass $sourceRolfTags */ $sourceRolfTags = $sourceAnr instanceof Entity\Anr ? $this->rolfTagTable->findByAnr($sourceAnr) - : $this->coreRolfTagTable->fetchAllObject(); + : $this->coreRolfTagTable->findAll(); foreach ($sourceRolfTags as $sourceRolfTag) { $newRolfTag = (new Entity\RolfTag()) ->setAnr($newAnr) @@ -941,7 +945,7 @@ private function duplicateRolfTags(CoreEntity\AnrSuperClass $sourceAnr, Entity\A ->setCode($sourceRolfTag->getCode()) ->setCreator($this->connectedUser->getEmail()); - $this->rolfTagTable->saveEntity($newRolfTag, false); + $this->rolfTagTable->save($newRolfTag, false); $rolfTagsOldIdsToNewObjects[$sourceRolfTag->getId()] = $newRolfTag; } @@ -955,9 +959,10 @@ private function duplicateRolfRisks( array $createdMeasuresUuidsToObjects ): array { $rolfRisksOldIdsToNewObjects = []; + /** @var Entity\RolfRisk[] $sourceRolfRisks */ $sourceRolfRisks = $sourceAnr instanceof Entity\Anr ? $this->rolfRiskTable->findByAnr($sourceAnr) - : $this->coreRolfRiskTable->fetchAllObject(); + : $this->coreRolfRiskTable->findAll(); foreach ($sourceRolfRisks as $sourceRolfRisk) { $newRolfRisk = (new Entity\RolfRisk()) ->setAnr($newAnr) @@ -978,7 +983,7 @@ private function duplicateRolfRisks( } } - $this->rolfRiskTable->saveEntity($newRolfRisk, false); + $this->rolfRiskTable->save($newRolfRisk, false); $rolfRisksOldIdsToNewObjects[$sourceRolfRisk->getId()] = $newRolfRisk; } @@ -1256,7 +1261,7 @@ private function duplicateInstancesTreeRisksSequencesRecommendationsMetadataAndS $instancesOldIdsToNewObjects[$sourceInstance->getId()] = $newInstance; /* Recreate InstanceRisks. */ - $instanceRisksOldIdsToNewObjects = $this->duplicateInstanceRisks( + $instanceRisksOldIdsToNewObjects += $this->duplicateInstanceRisks( $sourceInstance, $newInstance, $amvsOldIdsToNewObjects, @@ -1266,7 +1271,7 @@ private function duplicateInstancesTreeRisksSequencesRecommendationsMetadataAndS ); /* Recreate OperationalInstanceRisks. */ - $instanceRisksOpOldIdsToNewObjects = $this->duplicateOperationalInstanceRisks( + $instanceRisksOpOldIdsToNewObjects += $this->duplicateOperationalInstanceRisks( $sourceInstance, $newInstance, $rolfRisksOldIdsToNewObjects, @@ -1291,16 +1296,16 @@ private function duplicateInstancesTreeRisksSequencesRecommendationsMetadataAndS } if (!$isSourceCommon) { - /* Recreate RecommendationsHistory and RecommendationRisks. */ - $this->duplicateRecommendationsHistory( + /* Recreate RecommendationRisks and RecommendationsHistory. */ + $this->duplicateRecommendationsRisks( $sourceAnr, - $newAnr, + $recommendationsUuidsToNewObjects, $instanceRisksOldIdsToNewObjects, $instanceRisksOpOldIdsToNewObjects ); - $this->duplicateRecommendationsRisks( + $this->duplicateRecommendationsHistory( $sourceAnr, - $recommendationsUuidsToNewObjects, + $newAnr, $instanceRisksOldIdsToNewObjects, $instanceRisksOpOldIdsToNewObjects ); diff --git a/src/Service/AnrThreatService.php b/src/Service/AnrThreatService.php index 5031043e..833c843b 100755 --- a/src/Service/AnrThreatService.php +++ b/src/Service/AnrThreatService.php @@ -89,6 +89,8 @@ public function create(Anr $anr, array $data, bool $saveInDb = true): Threat $threat->setTrend((int)$data['qualification']); } + $this->validateCia($threat); + if (!empty($data['theme'])) { /** @var Theme $theme */ $theme = $data['theme'] instanceof Theme @@ -103,6 +105,17 @@ public function create(Anr $anr, array $data, bool $saveInDb = true): Threat return $threat; } + public function createList(Anr $anr, array $data): array + { + $createdUuids = []; + foreach ($data as $row) { + $createdUuids[] = $this->create($anr, $row, false)->getUuid(); + } + $this->threatTable->flush(); + + return $createdUuids; + } + public function update(Anr $anr, string $uuid, array $data): Threat { /** @var Threat $threat */ @@ -223,4 +236,11 @@ private function prepareThreatDataResult(Threat $threat): array 'status' => $threat->getStatus(), ]); } + + private function validateCia(Threat $threat): void + { + if ($threat->getConfidentiality() === 0 && $threat->getAvailability() === 0 && $threat->getIntegrity() === 0) { + throw new \Exception(); + } + } } diff --git a/src/Service/AnrVulnerabilityService.php b/src/Service/AnrVulnerabilityService.php index 9a4c6806..210a57cd 100755 --- a/src/Service/AnrVulnerabilityService.php +++ b/src/Service/AnrVulnerabilityService.php @@ -75,6 +75,17 @@ public function create(Anr $anr, array $data, bool $saveInDb = true): Vulnerabil return $vulnerability; } + public function createList(Anr $anr, array $data): array + { + $createdUuids = []; + foreach ($data as $row) { + $createdUuids[] = $this->create($anr, $row, false)->getUuid(); + } + $this->vulnerabilityTable->flush(); + + return $createdUuids; + } + public function update(Anr $anr, string $uuid, array $data): Vulnerability { /** @var Vulnerability $vulnerability */ diff --git a/src/Service/SnapshotService.php b/src/Service/SnapshotService.php index 58b52954..9d43587f 100755 --- a/src/Service/SnapshotService.php +++ b/src/Service/SnapshotService.php @@ -1,14 +1,16 @@ snapshotTable = $snapshotTable; - $this->anrTable = $anrTable; - $this->anrService = $anrService; - $this->userAnrTable = $userAnrTable; + $this->connectedUser = $connectedUserService->getConnectedUser(); } public function getList(Anr $anr): array { $snapshotsList = []; - $snapshots = $this->snapshotTable->findByAnrAndOrderBy($anr, ['createdAt' => Criteria::DESC]); + $snapshots = $this->snapshotTable->findByAnrReferenceAndOrderBy($anr, ['createdAt' => Criteria::DESC]); foreach ($snapshots as $snapshot) { $snapshotsList[] = [ 'id' => $snapshot->getId(), @@ -49,9 +43,9 @@ public function getList(Anr $anr): array ], 'comment' => $snapshot->getComment(), 'createdAt' => [ - 'date' => $snapshot->getCreatedAt()->format('Y-m-d H:i:s'), + 'date' => $snapshot->getCreatedAt()->format('Y-m-d H:i:s.u'), ], - 'author' => $snapshot->getCreator(), + 'creator' => $snapshot->getCreator(), ]; } @@ -71,7 +65,7 @@ public function create(Anr $anr, array $data): Snapshot $snapshot = (new Snapshot()) ->setAnr($newAnr) ->setAnrReference($anr) - ->setCreator($newAnr->getCreator()) + ->setCreator($this->connectedUser->getFirstname() . ' ' . $this->connectedUser->getLastname()) ->setComment($data['comment']); $this->snapshotTable->save($snapshot); diff --git a/src/Service/SoaCategoryService.php b/src/Service/SoaCategoryService.php index 2b04c25a..44d24adf 100755 --- a/src/Service/SoaCategoryService.php +++ b/src/Service/SoaCategoryService.php @@ -1,76 +1,85 @@ -filterPatchFields($data); - parent::patch($id, $data); } - public function getList($page = 1, $limit = 25, $order = null, $filter = null, $filterAnd = null) + public function getList(FormattedInputParams $params): array { - [$filterJoin, $filterLeft, $filtersCol] = $this->get('entity')->getFiltersForService(); - - return $this->get('table')->fetchAllFiltered( - array_keys($this->get('entity')->getJsonArray()), - $page, - $limit, - $this->parseFrontendOrder($order), - $this->parseFrontendFilter($filter, $this->filterColumns), - $filterAnd, - $filterJoin, - $filterLeft - ); + $result = []; + /** @var Entity\SoaCategory $soaCategory */ + foreach ($this->soaCategoryTable->findByParams($params) as $soaCategory) { + $result[] = $this->prepareSoaCategoryDataResult($soaCategory); + } + + return $result; } - public function delete($id) + public function getSoaCategoryData(Entity\Anr $anr, int $id): array { - $table = $this->get('table'); - $categ = $table->getEntity($id); - foreach ($categ->measures as $measure) { - $measure->setCategory(null); - } + /** @var Entity\SoaCategory $soaCategory */ + $soaCategory = $this->soaCategoryTable->findByIdAndAnr($id, $anr); + + return $this->prepareSoaCategoryDataResult($soaCategory); + } - return parent::delete($id); + public function create(Entity\Anr $anr, array $data, bool $saveInDb = true): Entity\SoaCategory + { + /** @var Entity\Referential $referential */ + $referential = $this->referentialTable->findByUuidAndAnr($data['referential'], $anr); + + /** @var Entity\SoaCategory $soaCategory */ + $soaCategory = (new Entity\SoaCategory())->setAnr($anr)->setLabels($data)->setReferential($referential); + + $this->soaCategoryTable->save($soaCategory, $saveInDb); + + return $soaCategory; + } + + public function update(Entity\Anr $anr, int $id, array $data): Entity\SoaCategory + { + /** @var Entity\SoaCategory $soaCategory */ + $soaCategory = $this->soaCategoryTable->findByIdAndAnr($id, $anr); + + $this->soaCategoryTable->save($soaCategory->setLabels($data)); + + return $soaCategory; + } + + public function delete(Entity\Anr $anr, int $id): void + { + /** @var Entity\SoaCategory $soaCategory */ + $soaCategory = $this->soaCategoryTable->findByIdAndAnr($id, $anr); + + $this->soaCategoryTable->remove($soaCategory); + } + + private function prepareSoaCategoryDataResult(Entity\SoaCategory $soaCategory): array + { + return array_merge(['id' => $soaCategory->getId()], $soaCategory->getLabels()); } public function getOrCreateSoaCategory( ImportCacheHelper $importCacheHelper, - Anr $anr, - Referential $referential, + Entity\Anr $anr, + Entity\Referential $referential, string $labelValue - ): SoaCategory { + ): Entity\SoaCategory { $languageIndex = $anr->getLanguage(); $labelKey = 'label' . $languageIndex; @@ -82,14 +91,12 @@ public function getOrCreateSoaCategory( return $soaCategory; } - $soaCategory = (new SoaCategory()) + $soaCategory = (new Entity\SoaCategory()) ->setAnr($anr) ->setReferential($referential) ->setLabels([$labelKey => $labelValue]); - /** @var SoaCategoryTable $soaCategoryTable */ - $soaCategoryTable = $this->get('table'); - $soaCategoryTable->saveEntity($soaCategory, false); + $this->soaCategoryTable->save($soaCategory, false); $importCacheHelper->addItemToArrayCache('soa_categories_by_ref_and_label', $soaCategory, $cacheKey); diff --git a/src/Service/SoaCategoryServiceFactory.php b/src/Service/SoaCategoryServiceFactory.php deleted file mode 100755 index 5c4ec24e..00000000 --- a/src/Service/SoaCategoryServiceFactory.php +++ /dev/null @@ -1,26 +0,0 @@ - 'Monarc\FrontOffice\Entity\SoaCategory', - 'table' => 'Monarc\FrontOffice\Model\Table\SoaCategoryTable', - 'anrTable' => AnrTable::class, - 'userAnrTable' => UserAnrTable::class, - ]; -} diff --git a/src/Stats/Service/StatsSettingsService.php b/src/Stats/Service/StatsSettingsService.php index 8c55095f..e6340871 100644 --- a/src/Stats/Service/StatsSettingsService.php +++ b/src/Stats/Service/StatsSettingsService.php @@ -64,7 +64,7 @@ public function updateAnrsSettings(array $anrSettings): array $this->anrTable->save($anr, false); } - $this->anrTable->getDb()->flush(); + $this->anrTable->flush(); return $updatedAnrsSettings; } diff --git a/src/Table/InstanceRiskOpTable.php b/src/Table/InstanceRiskOpTable.php index c3ab8565..0e4cc4bd 100755 --- a/src/Table/InstanceRiskOpTable.php +++ b/src/Table/InstanceRiskOpTable.php @@ -40,6 +40,21 @@ public function findByAnrInstanceAndRolfRisk(Anr $anr, Instance $instance, RolfR ->getOneOrNullResult(); } + /** + * @return InstanceRiskOp[] + */ + public function findByAnrAndRolfRisk(Anr $anr, RolfRisk $rolfRisk): array + { + return $this->getRepository() + ->createQueryBuilder('oir') + ->where('oir.anr = :anr') + ->andWhere('oir.rolfRisk = :rolfRisk') + ->setParameter('anr', $anr) + ->setParameter('rolfRisk', $rolfRisk) + ->getQuery() + ->getResult(); + } + /** * @return InstanceRiskOp[] */ diff --git a/src/Table/MeasureMeasureTable.php b/src/Table/MeasureMeasureTable.php new file mode 100644 index 00000000..330ddbb3 --- /dev/null +++ b/src/Table/MeasureMeasureTable.php @@ -0,0 +1,39 @@ +getRepository()->createQueryBuilder('mm') + ->where('mm.anr = :anr') + ->andWhere('mm.masterMeasure = :masterMeasure') + ->andWhere('mm.linkedMeasure = :linkedMeasure') + ->setParameter('anr', $anr) + ->setParameter('masterMeasure', $masterMeasureUuid) + ->setParameter('linkedMeasure', $linkedMeasureUuid) + ->setMaxResults(1) + ->getQuery() + ->getOneOrNullResult(AbstractQuery::HYDRATE_SIMPLEOBJECT) !== null; + } +} diff --git a/src/Table/MeasureTable.php b/src/Table/MeasureTable.php new file mode 100755 index 00000000..215da4d9 --- /dev/null +++ b/src/Table/MeasureTable.php @@ -0,0 +1,20 @@ +getRepository()->createQueryBuilder('rr') + ->where('rr.anr = :anr') + ->andWhere('rr.code = :code') + ->setParameter('anr', $anr) + ->setParameter('code', $code) + ->setMaxResults(1) + ->getQuery() + ->getOneOrNullResult(); + } +} diff --git a/src/Table/RolfTagTable.php b/src/Table/RolfTagTable.php new file mode 100755 index 00000000..41114582 --- /dev/null +++ b/src/Table/RolfTagTable.php @@ -0,0 +1,33 @@ +getRepository()->createQueryBuilder('rt') + ->where('rt.anr = :anr') + ->setParameter('anr', $anr) + ->andWhere('rt.code = :code') + ->setParameter('code', $code) + ->setMaxResults(1) + ->getQuery() + ->getOneOrNullResult(); + } +} diff --git a/src/Table/SnapshotTable.php b/src/Table/SnapshotTable.php index 2327ad6c..40bc2051 100755 --- a/src/Table/SnapshotTable.php +++ b/src/Table/SnapshotTable.php @@ -30,10 +30,10 @@ public function findAll(): array /** * @return Snapshot[] */ - public function findByAnrAndOrderBy(Anr $anr, array $order): array + public function findByAnrReferenceAndOrderBy(Anr $anr, array $order): array { $queryBuilder = $this->getRepository()->createQueryBuilder('s') - ->where('s.anr = :anr') + ->where('s.anrReference = :anr') ->setParameter('anr', $anr); foreach ($order as $field => $direction) { diff --git a/src/Table/SoaCategoryTable.php b/src/Table/SoaCategoryTable.php new file mode 100755 index 00000000..d6cf3ef3 --- /dev/null +++ b/src/Table/SoaCategoryTable.php @@ -0,0 +1,20 @@ +initialData['recommendationSet']) && !empty($this->includeFilter['anr'])) { + $this->includeFilter['recommendationSet'] = [ + 'uuid' => $this->initialData['recommendationSet'], + 'anr' => $this->includeFilter['anr'], + ]; + } + return [ [ 'name' => 'recommendationSet', @@ -49,6 +73,14 @@ protected function getRules(): array 'max' => 100, ] ], + [ + 'name' => UniqueCode::class, + 'options' => [ + 'uniqueCodeValidationTable' => $this->recommendationTable, + 'includeFilter' => $this->includeFilter, + 'excludeFilter' => $this->excludeFilter, + ], + ], ], ], [ diff --git a/src/Validator/InputValidator/Recommendation/PostRecommendationDataInputValidator.php b/src/Validator/InputValidator/Recommendation/PostRecommendationDataInputValidator.php index d6d5e974..fb249e9c 100644 --- a/src/Validator/InputValidator/Recommendation/PostRecommendationDataInputValidator.php +++ b/src/Validator/InputValidator/Recommendation/PostRecommendationDataInputValidator.php @@ -13,13 +13,37 @@ use Laminas\Validator\InArray; use Laminas\Validator\StringLength; use Monarc\Core\Service\Interfaces\PositionUpdatableServiceInterface; +use Monarc\Core\Table\Interfaces\UniqueCodeTableInterface; +use Monarc\Core\Validator\FieldValidator\UniqueCode; use Monarc\Core\Validator\InputValidator\AbstractInputValidator; +use Monarc\Core\Validator\InputValidator\FilterFieldsValidationTrait; +use Monarc\Core\Validator\InputValidator\InputValidationTranslator; use Monarc\FrontOffice\Entity\Recommendation; +/** + * Note. For UniqueCode validator $excludeFilter/$includeFilter properties have to be set before calling isValid method. + */ class PostRecommendationDataInputValidator extends AbstractInputValidator { + use FilterFieldsValidationTrait; + + public function __construct( + array $config, + InputValidationTranslator $translator, + private UniqueCodeTableInterface $recommendationTable + ) { + parent::__construct($config, $translator); + } + protected function getRules(): array { + if (!empty($this->initialData['recommendationSet']) && !empty($this->includeFilter['anr'])) { + $this->includeFilter['recommendationSet'] = [ + 'uuid' => $this->initialData['recommendationSet'], + 'anr' => $this->includeFilter['anr'], + ]; + } + return [ [ 'name' => 'uuid', @@ -63,6 +87,14 @@ protected function getRules(): array 'max' => 100, ] ], + [ + 'name' => UniqueCode::class, + 'options' => [ + 'uniqueCodeValidationTable' => $this->recommendationTable, + 'includeFilter' => $this->includeFilter, + 'excludeFilter' => $this->excludeFilter, + ], + ], ], ], [