Skip to content

Commit

Permalink
Fixed the amv response to display previous element, and recommendatio…
Browse files Browse the repository at this point in the history
…n response with the anr id.
  • Loading branch information
ruslanbaidan committed Sep 26, 2024
1 parent 17b2359 commit 9d9fed4
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 13 deletions.
12 changes: 10 additions & 2 deletions src/Service/AnrAmvService.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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 */
Expand Down Expand Up @@ -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([
Expand All @@ -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 [
Expand All @@ -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(),
Expand Down
5 changes: 4 additions & 1 deletion src/Service/AnrRecommendationSetService.php
Original file line number Diff line number Diff line change
Expand Up @@ -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(),
],
];
}
}
19 changes: 9 additions & 10 deletions src/Table/AmvTable.php
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down

0 comments on commit 9d9fed4

Please sign in to comment.