Skip to content

Commit

Permalink
FIxed the recommendations validation without comment, and creation/up…
Browse files Browse the repository at this point in the history
…date of the custom operational risks.
  • Loading branch information
ruslanbaidan committed Oct 21, 2024
1 parent d4514e5 commit 6b72c3e
Show file tree
Hide file tree
Showing 5 changed files with 53 additions and 25 deletions.
1 change: 0 additions & 1 deletion src/Controller/ApiAnrAmvsController.php
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,6 @@ public function get($id)
return $this->getPreparedJsonResponse($this->anrAmvService->getAmvData($anr, $id));
}


/**
* @param array $data
*/
Expand Down
14 changes: 12 additions & 2 deletions src/Service/AnrInstanceRiskOpService.php
Original file line number Diff line number Diff line change
Expand Up @@ -150,8 +150,18 @@ public function createSpecificOperationalInstanceRisk(Entity\Anr $anr, array $da
->setObject($instance->getObject())
->setIsSpecific(true)
->setRiskCacheCode($rolfRisk->getCode())
->setRiskCacheLabels($rolfRisk->getLabels())
->setRiskCacheDescriptions($rolfRisk->getDescriptions())
->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),
])
->setCreator($this->connectedUser->getEmail());

$operationalRiskScaleTypes = $this->operationalRiskScaleTypeTable->findByAnrAndScaleType(
Expand Down
2 changes: 1 addition & 1 deletion src/Service/AnrModelService.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ public function getModelsListOfClient(): array
foreach ($this->clientTable->findFirstClient()->getClientModels() as $clientModel) {
$modelIds[] = $clientModel->getModelId();
}
foreach ($this->modelTable->fundGenericsAndSpecificsByIds($modelIds) as $model) {
foreach ($this->modelTable->findGenericsAndSpecificsByIds($modelIds) as $model) {
$result[] = array_merge(['id' => $model->getId()], $model->getLabels());
}

Expand Down
2 changes: 1 addition & 1 deletion src/Service/AnrRecommendationHistoryService.php
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ public function createFromRecommendationRisk(

$recommendationHistory = (new RecommendationHistory())
->setAnr($anr)
->setImplComment($data['comment'])
->setImplComment((string)$data['comment'])
->setIsFinal($isFinal)
->setRecoCode($recommendation->getCode())
->setRecoDescription($recommendation->getDescription())
Expand Down
59 changes: 39 additions & 20 deletions src/Service/AnrRolfRiskService.php
Original file line number Diff line number Diff line change
Expand Up @@ -153,26 +153,20 @@ public function update(Entity\Anr $anr, int $id, array $data): Entity\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 ($rolfTag->getObjects() 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);
/* If there is no tag linked, search directly by the rolf risk. */
if ($rolfRisk->getTags()->isEmpty()) {
/** @var Entity\InstanceRiskOp[] $instancesRisksOp */
$instancesRisksOp = $this->instanceRiskOpTable->findByRolfRisk($rolfRisk);
$this->updateOperationalRisksCacheValues($instancesRisksOp, $rolfRisk);
} else {
/* If the labels or descriptions changed the operational risks labels have to be updated as well. */
foreach ($rolfRisk->getTags() as $rolfTag) {
foreach ($rolfTag->getObjects() as $monarcObject) {
$instancesRisksOp = $this->instanceRiskOpTable->findByObjectAndRolfRisk(
$monarcObject,
$rolfRisk
);
$this->updateOperationalRisksCacheValues($instancesRisksOp, $rolfRisk);
}
}
}
Expand Down Expand Up @@ -222,6 +216,31 @@ public function linkMeasuresToRisks(
$this->measureTable->flush();
}

/**
* @param Entity\InstanceRiskOp[] $instanceRisksOp
*/
private function updateOperationalRisksCacheValues(array $instanceRisksOp, Entity\RolfRisk $rolfRisk): void
{
foreach ($instanceRisksOp 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),
])
->setUpdater($this->connectedUser->getEmail());

$this->instanceRiskOpTable->save($instanceRiskOp, false);
}
}

private function removeRolfRisk(Entity\Anr $anr, Entity\RolfRisk $rolfRisk, bool $saveInDb = true): void
{
foreach ($this->instanceRiskOpTable->findByAnrAndRolfRisk($anr, $rolfRisk) as $instanceRiskOp) {
Expand Down

0 comments on commit 6b72c3e

Please sign in to comment.