Skip to content

Commit

Permalink
Refactored the rolf risks functionality, improved the entities and ad…
Browse files Browse the repository at this point in the history
…ded the migrations to clean up the db tables.
  • Loading branch information
ruslanbaidan committed Apr 18, 2024
1 parent e0801d2 commit e5ad0a9
Show file tree
Hide file tree
Showing 39 changed files with 712 additions and 794 deletions.
73 changes: 44 additions & 29 deletions config/module.config.php
Original file line number Diff line number Diff line change
Expand Up @@ -137,16 +137,14 @@
Service\GuideService::class => Service\GuideServiceFactory::class,
Service\GuideItemService::class => Service\GuideItemServiceFactory::class,
Service\HistoricalService::class => Service\HistoricalServiceFactory::class,
Service\RolfRiskService::class => Service\RolfRiskServiceFactory::class,
Service\RolfTagService::class => Service\RolfTagServiceFactory::class,
Service\ReferentialService::class => Service\ReferentialServiceFactory::class,
Service\DeliveriesModelsService::class => Service\DeliveriesModelsServiceFactory::class,
/* Services. */
Service\AmvService::class => AutowireFactory::class,
Service\AnrService::class => AutowireFactory::class,
Service\UserRoleService::class => AutowireFactory::class,
Service\UserProfileService::class => AutowireFactory::class,
Service\AuthenticationService::class => AutowireFactory::class,
Service\AnrInstanceMetadataFieldService::class => AutowireFactory::class,
Service\AssetService::class => AutowireFactory::class,
Service\ConfigService::class => ReflectionBasedAbstractFactory::class,
Service\InstanceService::class => AutowireFactory::class,
Expand All @@ -171,7 +169,9 @@
Service\VulnerabilityService::class => AutowireFactory::class,
Service\OperationalRiskScaleService::class => AutowireFactory::class,
Service\OperationalRiskScaleCommentService::class => AutowireFactory::class,
Service\AnrInstanceMetadataFieldService::class => AutowireFactory::class,
Service\RolfRiskService::class => AutowireFactory::class,
Service\RolfTagService::class => AutowireFactory::class,
Service\ReferentialService::class => AutowireFactory::class,
Service\SoaScaleCommentService::class => AutowireFactory::class,
/* Export services. */
Service\Export\AssetExportService::class => AutowireFactory::class,
Expand All @@ -180,9 +180,6 @@

// TODO: Entities are created in a generic way. Should be removed.
ModelEntity\DeliveriesModels::class => ServiceModelEntity\DeliveriesModelsServiceModelEntity::class,
ModelEntity\Referential::class => ServiceModelEntity\ReferentialServiceModelEntity::class,
ModelEntity\RolfRisk::class => ServiceModelEntity\RolfRiskServiceModelEntity::class,
ModelEntity\RolfTag::class => ServiceModelEntity\RolfTagServiceModelEntity::class,
ModelEntity\GuideItem::class => ServiceModelEntity\GuideItemServiceModelEntity::class,
ModelEntity\Guide::class => ServiceModelEntity\GuideServiceModelEntity::class,
ModelEntity\Historical::class => ServiceModelEntity\HistoricalServiceModelEntity::class,
Expand All @@ -192,40 +189,40 @@
DeprecatedTable\QuestionChoiceTable::class => AutowireFactory::class,
DeprecatedTable\GuideTable::class => AutowireFactory::class,
DeprecatedTable\GuideItemTable::class => AutowireFactory::class,
DeprecatedTable\ReferentialTable::class => AutowireFactory::class,
DeprecatedTable\HistoricalTable::class => AutowireFactory::class,
DeprecatedTable\RolfTagTable::class => AutowireFactory::class,
DeprecatedTable\RolfRiskTable::class => AutowireFactory::class,
DeprecatedTable\DeliveriesModelsTable::class => AutowireFactory::class,
Table\InstanceRiskTable::class => Table\Factory\CoreEntityManagerFactory::class,
Table\InstanceRiskOpTable::class => Table\Factory\CoreEntityManagerFactory::class,
Table\ScaleTable::class => Table\Factory\CoreEntityManagerFactory::class,
Table\ScaleCommentTable::class => Table\Factory\CoreEntityManagerFactory::class,
Table\ScaleImpactTypeTable::class => Table\Factory\CoreEntityManagerFactory::class,
Table\AnrInstanceMetadataFieldTable::class => Table\Factory\CoreEntityManagerFactory::class,
Table\AnrTable::class => Table\Factory\CoreEntityManagerFactory::class,
Table\AmvTable::class => Table\Factory\CoreEntityManagerFactory::class,
Table\AssetTable::class => Table\Factory\CoreEntityManagerFactory::class,
Table\InstanceTable::class => Table\Factory\CoreEntityManagerFactory::class,
Table\InstanceConsequenceTable::class => Table\Factory\CoreEntityManagerFactory::class,
Table\InstanceRiskTable::class => Table\Factory\CoreEntityManagerFactory::class,
Table\InstanceRiskOpTable::class => Table\Factory\CoreEntityManagerFactory::class,
Table\ModelTable::class => Table\Factory\CoreEntityManagerFactory::class,
Table\MonarcObjectTable::class => Table\Factory\CoreEntityManagerFactory::class,
Table\MeasureTable::class => Table\Factory\CoreEntityManagerFactory::class,
Table\MeasureMeasureTable::class => Table\Factory\CoreEntityManagerFactory::class,
Table\InstanceTable::class => Table\Factory\CoreEntityManagerFactory::class,
Table\ObjectCategoryTable::class => Table\Factory\CoreEntityManagerFactory::class,
Table\ObjectObjectTable::class => Table\Factory\CoreEntityManagerFactory::class,
Table\ThemeTable::class => Table\Factory\CoreEntityManagerFactory::class,
Table\AssetTable::class => Table\Factory\CoreEntityManagerFactory::class,
Table\AmvTable::class => Table\Factory\CoreEntityManagerFactory::class,
Table\ThreatTable::class => Table\Factory\CoreEntityManagerFactory::class,
Table\VulnerabilityTable::class => Table\Factory\CoreEntityManagerFactory::class,
Table\OperationalRiskScaleTable::class => Table\Factory\CoreEntityManagerFactory::class,
Table\OperationalRiskScaleTypeTable::class => Table\Factory\CoreEntityManagerFactory::class,
Table\OperationalRiskScaleCommentTable::class => Table\Factory\CoreEntityManagerFactory::class,
Table\OperationalInstanceRiskScaleTable::class => Table\Factory\CoreEntityManagerFactory::class,
Table\AnrInstanceMetadataFieldTable::class => Table\Factory\CoreEntityManagerFactory::class,
Table\PasswordTokenTable::class => Table\Factory\ClientEntityManagerFactory::class,
Table\ReferentialTable::class => Table\Factory\CoreEntityManagerFactory::class,
Table\RolfTagTable::class => Table\Factory\CoreEntityManagerFactory::class,
Table\RolfRiskTable::class => Table\Factory\CoreEntityManagerFactory::class,
Table\ScaleTable::class => Table\Factory\CoreEntityManagerFactory::class,
Table\ScaleCommentTable::class => Table\Factory\CoreEntityManagerFactory::class,
Table\ScaleImpactTypeTable::class => Table\Factory\CoreEntityManagerFactory::class,
Table\SoaCategoryTable::class => Table\Factory\CoreEntityManagerFactory::class,
Table\SoaScaleCommentTable::class => Table\Factory\CoreEntityManagerFactory::class,
Table\ThemeTable::class => Table\Factory\CoreEntityManagerFactory::class,
Table\ThreatTable::class => Table\Factory\CoreEntityManagerFactory::class,
Table\UserTable::class => Table\Factory\ClientEntityManagerFactory::class,
Table\UserTokenTable::class => Table\Factory\ClientEntityManagerFactory::class,
Table\PasswordTokenTable::class => Table\Factory\ClientEntityManagerFactory::class,
Table\VulnerabilityTable::class => Table\Factory\CoreEntityManagerFactory::class,

/* Authentication */
StorageAuthentication::class => ReflectionBasedAbstractFactory::class,
Expand All @@ -239,7 +236,7 @@
InputValidator\User\PostUserDataInputValidator::class => ReflectionBasedAbstractFactory::class,
InputValidator\Model\PostModelDataInputValidator::class => ReflectionBasedAbstractFactory::class,
InputValidator\Asset\PostAssetDataInputValidator::class => static function (
Containerinterface $container,
Containerinterface $container
) {
return new InputValidator\Asset\PostAssetDataInputValidator(
$container->get('config'),
Expand All @@ -257,7 +254,7 @@
);
},
InputValidator\Vulnerability\PostVulnerabilityDataInputValidator::class => static function (
Containerinterface $container,
Containerinterface $container
) {
return new InputValidator\Vulnerability\PostVulnerabilityDataInputValidator(
$container->get('config'),
Expand Down Expand Up @@ -290,17 +287,17 @@
InputValidator\Scale\UpdateScalesDataInputValidator::class => ReflectionBasedAbstractFactory::class,
InputValidator\MeasureMeasure\PostMeasureMeasureDataInputValidator::class =>
ReflectionBasedAbstractFactory::class,
InputValidator\Measure\PostMeasureDataInputValidator::class => static function (
Containerinterface $container,
InputValidator\Measure\PostMeasureDataInputValidator::class => static function (
Containerinterface $container
) {
return new InputValidator\Measure\PostMeasureDataInputValidator(
$container->get('config'),
$container->get(InputValidator\InputValidationTranslator::class),
$container->get(Table\MeasureTable::class)
);
},
InputValidator\Measure\UpdateMeasureDataInputValidator::class => static function (
Containerinterface $container,
InputValidator\Measure\UpdateMeasureDataInputValidator::class => static function (
Containerinterface $container
) {
return new InputValidator\Measure\UpdateMeasureDataInputValidator(
$container->get('config'),
Expand All @@ -312,6 +309,24 @@
ReflectionBasedAbstractFactory::class,
InputValidator\Referential\PostReferentialDataInputValidator::class =>
ReflectionBasedAbstractFactory::class,
InputValidator\RolfTag\PostRolfTagDataInputValidator::class => static function (
Containerinterface $container
) {
return new InputValidator\RolfTag\PostRolfTagDataInputValidator(
$container->get('config'),
$container->get(InputValidator\InputValidationTranslator::class),
$container->get(Table\RolfTagTable::class)
);
},
InputValidator\RolfRisk\PostRolfRiskDataInputValidator::class => static function (
Containerinterface $container
) {
return new InputValidator\RolfRisk\PostRolfRiskDataInputValidator(
$container->get('config'),
$container->get(InputValidator\InputValidationTranslator::class),
$container->get(Table\RolfRiskTable::class)
);
},

ScalesCacheHelper::class => AutowireFactory::class,
],
Expand Down
35 changes: 35 additions & 0 deletions migrations/db/20230901112005_fix_positions_cleanup_db.php
Original file line number Diff line number Diff line change
Expand Up @@ -207,6 +207,8 @@ public function change()
->renameColumn('father_id', 'master_measure_id')
->renameColumn('child_id', 'linked_measure_id')
->dropForeignKey(['master_measure_id', 'linked_measure_id'])
->removeColumn('creator')
->removeColumn('created_at')
->removeColumn('updater')
->removeColumn('updated_at')
->update();
Expand Down Expand Up @@ -310,5 +312,38 @@ public function change()
->removeIndex(['anr_id', 'code'])
->removeColumn('anr_id')
->save();
$this->table('rolf_tags')
->dropForeignKey('anr_id')
->removeIndex(['anr_id', 'code'])
->removeColumn('anr_id')
->save();
$this->table('rolf_tags')->addIndex(['code'], ['unique' => true])->save();
$this->table('rolf_risks')
->dropForeignKey('anr_id')
->removeIndex(['anr_id', 'code'])
->removeColumn('anr_id')
->save();
$this->table('rolf_risks')->addIndex(['code'], ['unique' => true])->save();
$this->table('rolf_risks_tags')
->removeColumn('creator')
->removeColumn('created_at')
->removeColumn('updater')
->removeColumn('updated_at')
->save();
$this->table('measures_amvs')
->removeColumn('creator')
->removeColumn('created_at')
->removeColumn('updater')
->removeColumn('updated_at')
->save();
$this->table('measures_rolf_risks')
->dropForeignKey('anr_id')
->removeIndex(['anr_id'])
->removeColumn('anr_id')
->removeColumn('creator')
->removeColumn('created_at')
->removeColumn('updater')
->removeColumn('updated_at')
->save();
}
}
14 changes: 1 addition & 13 deletions src/Entity/AmvSuperClass.php
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<?php declare(strict_types=1);
/**
* @link https://github.com/monarc-project for the canonical source repository
* @copyright Copyright (c) 2016-2022 SMILE GIE Securitymadein.lu - Licensed under GNU Affero GPL v3
* @copyright Copyright (c) 2016-2024 Luxembourg House of Cybersecurity LHC.lu - Licensed under GNU Affero GPL v3
* @license MONARC is licensed under GNU Affero General Public License version 3
*/

Expand Down Expand Up @@ -209,18 +209,6 @@ public function getMeasures()
return $this->measures;
}

/**
* @param MeasureSuperClass[] $measures
*/
public function setMeasures(iterable $measures): self
{
foreach ($measures as $measure) {
$this->addMeasure($measure);
}

return $this;
}

public function addMeasure(MeasureSuperClass $measure): self
{
if (!$this->measures->contains($measure)) {
Expand Down
2 changes: 0 additions & 2 deletions src/Entity/MeasureMeasureSuperClass.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,6 @@
*/
class MeasureMeasureSuperClass
{
use CreateEntityTrait;

/**
* @var int
*
Expand Down
20 changes: 10 additions & 10 deletions src/Entity/MeasureSuperClass.php
Original file line number Diff line number Diff line change
Expand Up @@ -65,8 +65,8 @@ class MeasureSuperClass
*
* @ORM\ManyToMany(targetEntity="Amv", inversedBy="measures", cascade={"persist"})
* @ORM\JoinTable(name="measures_amvs",
* inverseJoinColumns={@ORM\JoinColumn(name="amv_id", referencedColumnName="uuid")},
* joinColumns={@ORM\JoinColumn(name="measure_id", referencedColumnName="uuid"),},
* inverseJoinColumns={@ORM\JoinColumn(name="amv_id", referencedColumnName="uuid")},
* joinColumns={@ORM\JoinColumn(name="measure_id", referencedColumnName="uuid")},
* )
*/
protected $amvs;
Expand All @@ -76,8 +76,8 @@ class MeasureSuperClass
*
* @ORM\ManyToMany(targetEntity="RolfRisk", inversedBy="measures", cascade={"persist"})
* @ORM\JoinTable(name="measures_rolf_risks",
* inverseJoinColumns={@ORM\JoinColumn(name="rolf_risk_id", referencedColumnName="id")},
* joinColumns={@ORM\JoinColumn(name="measure_id", referencedColumnName="uuid"),},
* inverseJoinColumns={@ORM\JoinColumn(name="rolf_risk_id", referencedColumnName="id")},
* joinColumns={@ORM\JoinColumn(name="measure_id", referencedColumnName="uuid")},
* )
*/
protected $rolfRisks;
Expand All @@ -87,8 +87,8 @@ class MeasureSuperClass
*
* @ORM\ManyToMany(targetEntity="Measure")
* @ORM\JoinTable(name="measures_measures",
* joinColumns={@ORM\JoinColumn(name="master_measure_id", referencedColumnName="uuid")},
* inverseJoinColumns={@ORM\JoinColumn(name="linked_measure_id", referencedColumnName="uuid")}
* joinColumns={@ORM\JoinColumn(name="master_measure_id", referencedColumnName="uuid")},
* inverseJoinColumns={@ORM\JoinColumn(name="linked_measure_id", referencedColumnName="uuid")}
* )
*/
protected $linkedMeasures;
Expand Down Expand Up @@ -238,11 +238,11 @@ public function addRolfRisk(RolfRiskSuperClass $rolfRisk): self
return $this;
}

public function removeOpRisk(RolfRiskSuperClass $riskInput): self
public function removeRolfRisk(RolfRiskSuperClass $rolfRisk): self
{
if ($this->rolfRisks->contains($riskInput)) {
$this->rolfRisks->removeElement($riskInput);
$riskInput->removeMeasure($this);
if ($this->rolfRisks->contains($rolfRisk)) {
$this->rolfRisks->removeElement($rolfRisk);
$rolfRisk->removeMeasure($this);
}

return $this;
Expand Down
8 changes: 3 additions & 5 deletions src/Entity/RolfRisk.php
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<?php
<?php declare(strict_types=1);
/**
* @link https://github.com/monarc-project for the canonical source repository
* @copyright Copyright (c) 2016-2020 SMILE GIE Securitymadein.lu - Licensed under GNU Affero GPL v3
* @copyright Copyright (c) 2016-2024 Luxembourg House of Cybersecurity LHC.lu - Licensed under GNU Affero GPL v3
* @license MONARC is licensed under GNU Affero General Public License version 3
*/

Expand All @@ -10,10 +10,8 @@
use Doctrine\ORM\Mapping as ORM;

/**
* RolfRisk
*
* @ORM\Table(name="rolf_risks", indexes={
* @ORM\Index(name="anr", columns={"anr_id"})
* @ORM\Index(name="code", columns={"code"})
* })
* @ORM\Entity
*/
Expand Down
Loading

0 comments on commit e5ad0a9

Please sign in to comment.