Skip to content

Commit

Permalink
Finished all of the importing scenarios.
Browse files Browse the repository at this point in the history
  • Loading branch information
ruslanbaidan committed Jul 23, 2024
1 parent 727e1c8 commit d893f51
Show file tree
Hide file tree
Showing 61 changed files with 2,228 additions and 2,968 deletions.
21 changes: 10 additions & 11 deletions config/module.config.php
Original file line number Diff line number Diff line change
Expand Up @@ -1575,18 +1575,7 @@
Export\Service\InstanceExportService::class => AutowireFactory::class,
/* Import services. */
Import\Service\ObjectImportService::class => AutowireFactory::class,
Import\Service\AssetImportService::class => AutowireFactory::class,
Import\Service\InstanceImportService::class => AutowireFactory::class,
Import\Processor\AssetImportProcessor::class => AutowireFactory::class,
Import\Processor\InformationRiskImportProcessor::class => AutowireFactory::class,
Import\Processor\ObjectCategoryImportProcessor::class => AutowireFactory::class,
Import\Processor\ObjectImportProcessor::class => AutowireFactory::class,
Import\Processor\OperationalRisksImportProcessor::class => AutowireFactory::class,
Import\Processor\RecommendationImportProcessor::class => AutowireFactory::class,
Import\Processor\ReferentialImportProcessor::class => AutowireFactory::class,
Import\Processor\RolfTagImportProcessor::class => AutowireFactory::class,
Import\Processor\ThreatImportProcessor::class => AutowireFactory::class,
Import\Processor\VulnerabilityImportProcessor::class => AutowireFactory::class,

// Helpers
Import\Helper\ImportCacheHelper::class => AutowireFactory::class,
Expand Down Expand Up @@ -1718,6 +1707,10 @@
Service\AnrInstanceService::class => Service\AnrInstanceService::class,
Import\Processor\ObjectCategoryImportProcessor::class =>
Import\Processor\ObjectCategoryImportProcessor::class,
Import\Processor\InformationRiskImportProcessor::class =>
Import\Processor\InformationRiskImportProcessor::class,
Import\Processor\OperationalRiskImportProcessor::class =>
Import\Processor\OperationalRiskImportProcessor::class,
],
'proxies_target_dir' => $dataPath . '/LazyServices/Proxy',
'write_proxy_files' => $env === 'production',
Expand All @@ -1732,6 +1725,12 @@
Import\Processor\ObjectCategoryImportProcessor::class => [
LazyServiceFactory::class,
],
Import\Processor\InformationRiskImportProcessor::class => [
LazyServiceFactory::class,
],
Import\Processor\OperationalRiskImportProcessor::class => [
LazyServiceFactory::class,
],
],
],

Expand Down
4 changes: 1 addition & 3 deletions src/Controller/ApiAnrObjectsController.php
Original file line number Diff line number Diff line change
Expand Up @@ -71,12 +71,10 @@ public function get($id)
*/
public function create($data)
{
// TODO: Validate the 3 import + 1 MOSP cases and 1 manual ...

/** @var Anr $anr */
$anr = $this->getRequest()->getAttribute('anr');
if (!empty($data['mosp'])) {
$monarcObject = $this->objectImportService->importFromArray($data, $anr);
$monarcObject = $this->objectImportService->importFromArray($anr, $data);

return $monarcObject !== null
? $this->getSuccessfulJsonResponse(['id' => $monarcObject->getUuid()])
Expand Down
1 change: 0 additions & 1 deletion src/Controller/ApiAnrRecordsImportController.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@

namespace Monarc\FrontOffice\Controller;

use Laminas\View\Model\JsonModel;
use Monarc\Core\Controller\Handler\AbstractRestfulControllerRequestHandler;
use Monarc\Core\Controller\Handler\ControllerRequestResponseHandlerTrait;
use Monarc\Core\Exception\Exception;
Expand Down
32 changes: 32 additions & 0 deletions src/Entity/InstanceRisk.php
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,19 @@ class InstanceRisk extends InstanceRiskSuperClass
*/
protected $instanceRiskOwner;

/**
* IMPORTANT! The field has to be always at the last place in the class due to the double fields' relation issue!
* Because when a nullable relation of AMV is set, the anr value is saved as NULL as well.
*
* @var Anr
*
* @ORM\ManyToOne(targetEntity="Anr")
* @ORM\JoinColumns({
* @ORM\JoinColumn(name="anr_id", referencedColumnName="id", nullable=true, onDelete="CASCADE")
* })
*/
protected $anr;

/**
* @var string
*
Expand Down Expand Up @@ -126,6 +139,25 @@ public function getRecommendationRisks()
return $this->recommendationRisks;
}


public function addRecommendationRisk(RecommendationRisk $recommendationRisk): self
{
if (!$this->recommendationRisks->contains($recommendationRisk)) {
$this->recommendationRisks->add($recommendationRisk);
}

return $this;
}

public function removeRecommendationRisk(RecommendationRisk $recommendationRisk): self
{
if ($this->recommendationRisks->contains($recommendationRisk)) {
$this->recommendationRisks->removeElement($recommendationRisk);
}

return $this;
}

public function getInstanceRiskOwner(): ?InstanceRiskOwner
{
return $this->instanceRiskOwner;
Expand Down
18 changes: 18 additions & 0 deletions src/Entity/InstanceRiskOp.php
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,24 @@ public function getRecommendationRisks()
return $this->recommendationRisks;
}

public function addRecommendationRisk(RecommendationRisk $recommendationRisk): self
{
if (!$this->recommendationRisks->contains($recommendationRisk)) {
$this->recommendationRisks->add($recommendationRisk);
}

return $this;
}

public function removeRecommendationRisk(RecommendationRisk $recommendationRisk): self
{
if ($this->recommendationRisks->contains($recommendationRisk)) {
$this->recommendationRisks->removeElement($recommendationRisk);
}

return $this;
}

public function getInstanceRiskOwner(): ?InstanceRiskOwner
{
return $this->instanceRiskOwner;
Expand Down
20 changes: 20 additions & 0 deletions src/Entity/Measure.php
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,13 @@ class Measure extends MeasureSuperClass
*/
protected $linkedMeasures;

/**
* @var Soa|null
*
* @ORM\OneToOne(targetEntity="Soa", mappedBy="measure")
*/
protected $soa;

public function getId()
{
return $this->id;
Expand All @@ -109,4 +116,17 @@ public function setAnr(Anr $anr): self

return $this;
}

public function getSoa()
{
return $this->soa;
}

public function setSoa(Soa $soa): self
{
$this->soa = $soa;
$soa->setMeasure($this);

return $this;
}
}
57 changes: 38 additions & 19 deletions src/Entity/RecommendationRisk.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,23 +30,13 @@ class RecommendationRisk
*/
protected $id;

/**
* @var Anr
*
* @ORM\ManyToOne(targetEntity="Anr")
* @ORM\JoinColumns({
* @ORM\JoinColumn(name="anr_id", referencedColumnName="id", nullable=false)
* })
*/
protected $anr;

/**
* @var Recommendation
*
* @ORM\ManyToOne(targetEntity="Recommendation", fetch="EAGER")
* @ORM\ManyToOne(targetEntity="Recommendation")
* @ORM\JoinColumns({
* @ORM\JoinColumn(name="recommandation_id", referencedColumnName="uuid", nullable=true),
* @ORM\JoinColumn(name="anr_id", referencedColumnName="anr_id", nullable=true)
* @ORM\JoinColumn(name="recommandation_id", referencedColumnName="uuid"),
* @ORM\JoinColumn(name="anr_id", referencedColumnName="anr_id")
* })
*/
protected $recommendation;
Expand Down Expand Up @@ -87,7 +77,7 @@ class RecommendationRisk
* @ORM\ManyToOne(targetEntity="MonarcObject")
* @ORM\JoinColumns({
* @ORM\JoinColumn(name="object_global_id", referencedColumnName="uuid", nullable=true),
* @ORM\JoinColumn(name="anr_id", referencedColumnName="anr_id", nullable=true)
* @ORM\JoinColumn(name="anr_id", referencedColumnName="anr_id")
* })
*/
protected $globalObject;
Expand All @@ -98,7 +88,7 @@ class RecommendationRisk
* @ORM\ManyToOne(targetEntity="Asset")
* @ORM\JoinColumns({
* @ORM\JoinColumn(name="asset_id", referencedColumnName="uuid", nullable=true),
* @ORM\JoinColumn(name="anr_id", referencedColumnName="anr_id", nullable=true)
* @ORM\JoinColumn(name="anr_id", referencedColumnName="anr_id")
* })
*/
protected $asset;
Expand All @@ -109,7 +99,7 @@ class RecommendationRisk
* @ORM\ManyToOne(targetEntity="Threat")
* @ORM\JoinColumns({
* @ORM\JoinColumn(name="threat_id", referencedColumnName="uuid", nullable=true),
* @ORM\JoinColumn(name="anr_id", referencedColumnName="anr_id", nullable=true)
* @ORM\JoinColumn(name="anr_id", referencedColumnName="anr_id")
* })
*/
protected $threat;
Expand All @@ -120,11 +110,24 @@ class RecommendationRisk
* @ORM\ManyToOne(targetEntity="Vulnerability")
* @ORM\JoinColumns({
* @ORM\JoinColumn(name="vulnerability_id", referencedColumnName="uuid", nullable=true),
* @ORM\JoinColumn(name="anr_id", referencedColumnName="anr_id", nullable=true)
* @ORM\JoinColumn(name="anr_id", referencedColumnName="anr_id")
* })
*/
protected $vulnerability;

/**
* IMPORTANT! The field has to be always at the last place in the class due to the double fields' relation issue!
* Because when a nullable relation of AMV is set, the anr value is saved as NULL as well.
*
* @var Anr
*
* @ORM\ManyToOne(targetEntity="Anr")
* @ORM\JoinColumns({
* @ORM\JoinColumn(name="anr_id", referencedColumnName="id", nullable=false)
* })
*/
protected $anr;

/**
* @var string
*
Expand Down Expand Up @@ -169,7 +172,15 @@ public function getInstanceRisk(): ?InstanceRisk

public function setInstanceRisk(?InstanceRisk $instanceRisk): self
{
$this->instanceRisk = $instanceRisk;
if ($instanceRisk === null) {
if ($this->instanceRisk !== null) {
$this->instanceRisk->removeRecommendationRisk($this);
$this->instanceRisk = null;
}
} else {
$this->instanceRisk = $instanceRisk;
$instanceRisk->addRecommendationRisk($this);
}

return $this;
}
Expand All @@ -181,7 +192,15 @@ public function getInstanceRiskOp(): ?InstanceRiskOp

public function setInstanceRiskOp(?InstanceRiskOp $instanceRiskOp)
{
$this->instanceRiskOp = $instanceRiskOp;
if ($instanceRiskOp === null) {
if ($this->instanceRiskOp !== null) {
$this->instanceRiskOp->removeRecommendationRisk($this);
$this->instanceRiskOp = null;
}
} else {
$this->instanceRiskOp = $instanceRiskOp;
$instanceRiskOp->addRecommendationRisk($this);
}

return $this;
}
Expand Down
6 changes: 3 additions & 3 deletions src/Entity/RecommendationSet.php
Original file line number Diff line number Diff line change
Expand Up @@ -137,11 +137,11 @@ public function getLabel(): string
public static function getCustomImportLabelByLanguageCode(string $languageCode): string
{
switch ($languageCode) {
case 'FR':
case 'fr':
return 'Recommandations importées';
case 'DE':
case 'de':
return 'Importierte empfehlungen';
case 'NL':
case 'nl':
return 'Geïmporteerde aanbevelingen';
default:
return 'Imported recommendations';
Expand Down
10 changes: 1 addition & 9 deletions src/Export/Service/Traits/AssetExportTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,19 +7,11 @@

namespace Monarc\FrontOffice\Export\Service\Traits;

use JetBrains\PhpStorm\ArrayShape;
use Monarc\FrontOffice\Entity;

trait AssetExportTrait
{
#[ArrayShape([
'uuid' => "string",
'code' => "string",
'label' => "string",
'description' => "string",
'type' => "int",
'status' => "int"
])] private function prepareAssetData(
private function prepareAssetData(
Entity\Asset $asset,
int $languageIndex,
bool $includeCompleteData = true
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,9 @@ private function prepareInformationInstanceRiskData(
'commentAfter' => $withControls ? $instanceRisk->getCommentAfter() : '',
'cacheMaxRisk' => $withEval ? $instanceRisk->getCacheMaxRisk() : -1,
'cacheTargetedRisk' => $withEval ? $instanceRisk->getCacheTargetedRisk() : -1,
'riskConfidentiality' => $withEval ? $instanceRisk->getRiskConfidentiality() : -1,
'riskIntegrity' => $withEval ? $instanceRisk->getRiskIntegrity() : -1,
'riskAvailability' => $withEval ? $instanceRisk->getRiskAvailability() : -1,
'context' => $withEval ? $instanceRisk->getContext() : '',
'riskOwner' => $withEval ? $instanceRisk->getInstanceRiskOwner()?->getName() : '',
'recommendations' => $recommendationsData,
Expand Down
10 changes: 1 addition & 9 deletions src/Export/Service/Traits/InformationRiskExportTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@

namespace Monarc\FrontOffice\Export\Service\Traits;

use JetBrains\PhpStorm\ArrayShape;
use Monarc\FrontOffice\Entity;

trait InformationRiskExportTrait
Expand All @@ -17,14 +16,7 @@ trait InformationRiskExportTrait
use ThreatExportTrait;
use VulnerabilityExportTrait;

#[ArrayShape([
'uuid' => "string",
'asset' => "array",
'threat' => "array",
'vulnerability' => "array",
'measures' => "array",
'status' => "int"
])] private function prepareInformationRiskData(
private function prepareInformationRiskData(
Entity\Amv $amv,
bool $withEval = false,
bool $withControls = true,
Expand Down
10 changes: 1 addition & 9 deletions src/Export/Service/Traits/InstanceConsequenceExportTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,21 +7,13 @@

namespace Monarc\FrontOffice\Export\Service\Traits;

use JetBrains\PhpStorm\ArrayShape;
use Monarc\FrontOffice\Entity;

trait InstanceConsequenceExportTrait
{
use ScaleImpactTypeExportTrait;

#[ArrayShape([
'id' => "int",
'confidentiality' => "int",
'integrity' => "int",
'availability' => "int",
'isHidden' => "bool",
'scaleImpactType' => "array"
])] private function prepareInstanceConsequenceData(
private function prepareInstanceConsequenceData(
Entity\InstanceConsequence $instanceConsequence,
int $languageIndex
): array {
Expand Down
2 changes: 1 addition & 1 deletion src/Export/Service/Traits/InstanceExportTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ private function prepareInstanceMetadataData(Entity\Instance $instance): array
foreach ($instance->getInstanceMetadata() as $instanceMetadata) {
$result[] = [
'anrInstanceMetadataField' => [
'label' => $instanceMetadata->getAnrInstanceMetadataField()->getLbel(),
'label' => $instanceMetadata->getAnrInstanceMetadataField()->getLabel(),
],
'comment' => $instanceMetadata->getComment(),
];
Expand Down
Loading

0 comments on commit d893f51

Please sign in to comment.