From 9d9fed494a9521de1f5e3edb4a8a0f0863338e26 Mon Sep 17 00:00:00 2001 From: Ruslan Baidan Date: Thu, 26 Sep 2024 19:47:14 +0200 Subject: [PATCH] Fixed the amv response to display previous element, and recommendation response with the anr id. --- src/Service/AnrAmvService.php | 12 ++++++++++-- src/Service/AnrRecommendationSetService.php | 5 ++++- src/Table/AmvTable.php | 19 +++++++++---------- 3 files changed, 23 insertions(+), 13 deletions(-) diff --git a/src/Service/AnrAmvService.php b/src/Service/AnrAmvService.php index 6bf73df8..d6985b30 100755 --- a/src/Service/AnrAmvService.php +++ b/src/Service/AnrAmvService.php @@ -64,7 +64,7 @@ public function getAmvData(Entity\Anr $anr, string $uuid): array /** @var Entity\Amv $amv */ $amv = $this->amvTable->findByUuidAndAnr($uuid, $anr); - return $this->prepareAmvDataResult($amv); + return $this->prepareAmvDataResult($amv, true); } public function create(Entity\Anr $anr, array $data, bool $saveInDb = true): Entity\Amv @@ -145,6 +145,8 @@ public function update(Entity\Anr $anr, string $uuid, array $data): Entity\Amv $amv->setUpdater($this->connectedUser->getEmail()); + $this->updatePositions($amv, $this->amvTable, $data); + $isThreatChanged = $this->isThreatChanged($data, $amv); if ($isThreatChanged) { /** @var Entity\Threat $threat */ @@ -385,7 +387,9 @@ private function prepareAmvDataResult(Entity\Amv $amv, bool $includePositionFiel if ($maxPositionByAsset === $amv->getPosition()) { $result['implicitPosition'] = 2; } else { - $previousAmv = $this->amvTable->findByAssetAndPosition($amv->getAsset(), $amv->getPosition() - 1); + /** @var Entity\Asset $asset */ + $asset = $amv->getAsset(); + $previousAmv = $this->amvTable->findByAssetAndPosition($asset, $amv->getPosition() - 1); if ($previousAmv !== null) { $result['implicitPosition'] = 3; $result['previous'] = array_merge([ @@ -404,6 +408,9 @@ private function getAmvRelationsData(Entity\Amv $amv): array { $asset = $amv->getAsset(); $threat = $amv->getThreat(); + $themeData = $threat->getTheme() !== null + ? array_merge(['id' => $threat->getTheme()->getId()], $threat->getTheme()->getLabels()) + : null; $vulnerability = $amv->getVulnerability(); return [ @@ -414,6 +421,7 @@ private function getAmvRelationsData(Entity\Amv $amv): array 'threat' => array_merge([ 'uuid' => $threat->getUuid(), 'code' => $threat->getCode(), + 'theme' => $themeData, ], $threat->getLabels()), 'vulnerability' => array_merge([ 'uuid' => $vulnerability->getUuid(), diff --git a/src/Service/AnrRecommendationSetService.php b/src/Service/AnrRecommendationSetService.php index a555a5d8..1c48deee 100644 --- a/src/Service/AnrRecommendationSetService.php +++ b/src/Service/AnrRecommendationSetService.php @@ -108,11 +108,14 @@ public function delete(Anr $anr, string $uuid): void $this->recommendationSetTable->remove($recommendationSet); } - private function getPreparedRecommendationSetData($recommendationSet): array + private function getPreparedRecommendationSetData(RecommendationSet $recommendationSet): array { return [ 'uuid' => $recommendationSet->getUuid(), 'label' => $recommendationSet->getLabel(), + 'anr' => [ + 'id' => $recommendationSet->getAnr()->getId(), + ], ]; } } diff --git a/src/Table/AmvTable.php b/src/Table/AmvTable.php index c5a40cbc..9f93516e 100755 --- a/src/Table/AmvTable.php +++ b/src/Table/AmvTable.php @@ -24,21 +24,20 @@ public function __construct(EntityManager $entityManager, string $entityName = A parent::__construct($entityManager, $entityName); } - /** - * @return Amv[] - */ - public function findByAnrAndAsset(Anr $anr, Asset $asset): array + public function findByAssetAndPosition(Asset $asset, int $position): ?Amv { - return $this->getRepository() - ->createQueryBuilder('amv') + return $this->getRepository()->createQueryBuilder('amv') ->innerJoin('amv.asset', 'a') ->where('amv.anr = :anr') - ->andWhere('a.uuid = :assetUuid') + ->andWhere('a.uuid = :asset_uuid') ->andWhere('a.anr = :anr') - ->setParameter('anr', $anr) - ->setParameter('assetUuid', $asset->getUuid()) + ->andWhere('amv.position = :position') + ->setParameter('anr', $asset->getAnr()) + ->setParameter('asset_uuid', $asset->getUuid()) + ->setParameter('position', $position) + ->setMaxResults(1) ->getQuery() - ->getResult(); + ->getOneOrNullResult(); } public function findByAmvItemsUuidsAndAnr(