Skip to content

Commit b35e710

Browse files
authored
Merge pull request #13 from aakb/feature/devsupp-160
DEVSUPP-160: Added import run entity to track import run success. Cha…
2 parents a435f92 + a25b6d4 commit b35e710

12 files changed

Lines changed: 277 additions & 25 deletions

config/packages/easy_admin.yaml

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ easy_admin:
2626
- { entity: 'User', icon: 'user', label: 'menu.users', permission: 'ROLE_ADMIN' }
2727
- { entity: 'Group', icon: 'users', label: 'menu.groups', permission: 'ROLE_ADMIN' }
2828
- { label: 'menu.exports', icon: 'file-excel-o', route: 'export_page', permission: 'ROLE_ADMIN' }
29+
- { entity: 'ImportRun', label: 'menu.import_runs', icon: 'file-import', route: 'list', permission: 'ROLE_ADMIN' }
2930
assets:
3031
css:
3132
- ckeditor_styles.css
@@ -244,3 +245,22 @@ easy_admin:
244245
fields:
245246
- name
246247
- { property: 'roles', type: 'choice', type_options: { multiple: true, choices: { 'ROLE_USER': 'ROLE_USER', 'ROLE_ADMIN': 'ROLE_ADMIN' } } }
248+
249+
ImportRun:
250+
disabled_actions: ['edit','delete']
251+
class: App\Entity\ImportRun
252+
list:
253+
item_permission: ['ROLE_ADMIN']
254+
fields:
255+
- { property: 'id', label: 'entity.import_run.id' }
256+
- { property: 'type', label: 'entity.import_run.type' }
257+
- { property: 'datetime', label: 'entity.import_run.datetime' }
258+
- { property: 'result', label: 'entity.import_run.result' }
259+
show:
260+
item_permission: ['ROLE_ADMIN']
261+
fields:
262+
- { property: 'id', label: 'entity.import_run.id' }
263+
- { property: 'type', label: 'entity.import_run.type' }
264+
- { property: 'datetime', label: 'entity.import_run.datetime' }
265+
- { property: 'result', label: 'entity.import_run.result' }
266+
- { property: 'output', label: 'entity.import_run.output' }
Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
<?php
2+
3+
namespace App\Command;
4+
5+
use App\Entity\ImportRun;
6+
use App\Service\BaseImporter;
7+
use Doctrine\ORM\EntityManagerInterface;
8+
use Symfony\Component\Console\Command\Command;
9+
use Symfony\Component\Console\Output\OutputInterface;
10+
11+
abstract class AbstractImportCommand extends Command
12+
{
13+
protected $entityManager;
14+
protected $importer;
15+
16+
public function __construct(BaseImporter $importer, EntityManagerInterface $entityManager)
17+
{
18+
parent::__construct();
19+
20+
$this->entityManager = $entityManager;
21+
$this->importer = $importer;
22+
}
23+
24+
/**
25+
* Run the importer.
26+
*
27+
* @param string $type
28+
* @param string $src
29+
* @param \Symfony\Component\Console\Output\OutputInterface $output
30+
* @throws \Exception
31+
*/
32+
protected function import(string $type, string $src, OutputInterface $output)
33+
{
34+
$success = true;
35+
$errorMessage = null;
36+
37+
try {
38+
$this->importer->import($src);
39+
} catch (\Exception $e) {
40+
$success = false;
41+
$errorMessage = $e->getMessage();
42+
$output->writeln($errorMessage);
43+
}
44+
45+
$this->recordImportRun($type, $success, $errorMessage);
46+
}
47+
48+
/**
49+
* Record import run.
50+
*
51+
* @param string $type
52+
* The type of the import
53+
* @param bool $success
54+
* Success of run
55+
* @param string|null $output
56+
* Output message or null
57+
* @throws \Exception
58+
*/
59+
protected function recordImportRun(string $type, bool $success, string $output = null) {
60+
$importRun = new ImportRun();
61+
$importRun->setDatetime(new \DateTime());
62+
$importRun->setOutput($output);
63+
$importRun->setResult($success);
64+
$importRun->setType($type);
65+
66+
$this->entityManager->persist($importRun);
67+
$this->entityManager->flush();
68+
}
69+
}

src/Command/ReportImportCommand.php

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2,21 +2,18 @@
22

33
namespace App\Command;
44

5+
use App\Entity\Report;
56
use App\Service\ReportImporter;
6-
use Symfony\Component\Console\Command\Command;
7+
use Doctrine\ORM\EntityManagerInterface;
78
use Symfony\Component\Console\Input\InputInterface;
89
use Symfony\Component\Console\Output\OutputInterface;
910
use Symfony\Component\Console\Input\InputArgument;
1011

11-
class ReportImportCommand extends Command
12+
class ReportImportCommand extends AbstractImportCommand
1213
{
13-
private $reportImporter;
14-
15-
public function __construct(ReportImporter $reportImporter)
14+
public function __construct(ReportImporter $reportImporter, EntityManagerInterface $entityManager)
1615
{
17-
parent::__construct();
18-
19-
$this->reportImporter = $reportImporter;
16+
parent::__construct($reportImporter, $entityManager);
2017
}
2118

2219
protected function configure()
@@ -29,6 +26,6 @@ protected function configure()
2926

3027
protected function execute(InputInterface $input, OutputInterface $output)
3128
{
32-
$this->reportImporter->import($input->getArgument('src'));
29+
$this->import(Report::class, $input->getArgument('src'), $output);
3330
}
3431
}

src/Command/SystemImportCommand.php

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2,21 +2,18 @@
22

33
namespace App\Command;
44

5+
use App\Entity\System;
56
use App\Service\SystemImporter;
6-
use Symfony\Component\Console\Command\Command;
7+
use Doctrine\ORM\EntityManagerInterface;
78
use Symfony\Component\Console\Input\InputInterface;
89
use Symfony\Component\Console\Output\OutputInterface;
910
use Symfony\Component\Console\Input\InputArgument;
1011

11-
class SystemImportCommand extends Command
12+
class SystemImportCommand extends AbstractImportCommand
1213
{
13-
private $systemImporter;
14-
15-
public function __construct(SystemImporter $systemImporter)
14+
public function __construct(SystemImporter $systemImporter, EntityManagerInterface $entityManager)
1615
{
17-
parent::__construct();
18-
19-
$this->systemImporter = $systemImporter;
16+
parent::__construct($systemImporter, $entityManager);
2017
}
2118

2219
protected function configure()
@@ -29,6 +26,6 @@ protected function configure()
2926

3027
protected function execute(InputInterface $input, OutputInterface $output)
3128
{
32-
$this->systemImporter->import($input->getArgument('src'));
29+
$this->import(System::class, $input->getArgument('src'), $output);
3330
}
3431
}

src/Entity/ImportRun.php

Lines changed: 91 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,91 @@
1+
<?php
2+
3+
namespace App\Entity;
4+
5+
use Doctrine\ORM\Mapping as ORM;
6+
7+
/**
8+
* @ORM\Entity(repositoryClass="App\Repository\ImportRunRepository")
9+
*/
10+
class ImportRun
11+
{
12+
/**
13+
* @ORM\Id()
14+
* @ORM\GeneratedValue()
15+
* @ORM\Column(type="integer")
16+
*/
17+
private $id;
18+
19+
/**
20+
* @ORM\Column(type="datetime")
21+
*/
22+
private $datetime;
23+
24+
/**
25+
* @ORM\Column(type="boolean")
26+
*/
27+
private $result;
28+
29+
/**
30+
* @ORM\Column(type="text", nullable=true)
31+
*/
32+
private $output;
33+
34+
/**
35+
* @ORM\Column(type="string", length=255)
36+
*/
37+
private $type;
38+
39+
public function getId(): ?int
40+
{
41+
return $this->id;
42+
}
43+
44+
public function getDatetime(): ?\DateTimeInterface
45+
{
46+
return $this->datetime;
47+
}
48+
49+
public function setDatetime(\DateTimeInterface $datetime): self
50+
{
51+
$this->datetime = $datetime;
52+
53+
return $this;
54+
}
55+
56+
public function getResult(): ?bool
57+
{
58+
return $this->result;
59+
}
60+
61+
public function setResult(bool $result): self
62+
{
63+
$this->result = $result;
64+
65+
return $this;
66+
}
67+
68+
public function getOutput(): ?string
69+
{
70+
return $this->output;
71+
}
72+
73+
public function setOutput(?string $output): self
74+
{
75+
$this->output = $output;
76+
77+
return $this;
78+
}
79+
80+
public function getType(): ?string
81+
{
82+
return $this->type;
83+
}
84+
85+
public function setType(string $type): self
86+
{
87+
$this->type = $type;
88+
89+
return $this;
90+
}
91+
}
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
<?php declare(strict_types=1);
2+
3+
namespace DoctrineMigrations;
4+
5+
use Doctrine\DBAL\Schema\Schema;
6+
use Doctrine\Migrations\AbstractMigration;
7+
8+
/**
9+
* Auto-generated Migration: Please modify to your needs!
10+
*/
11+
final class Version20200117090749 extends AbstractMigration
12+
{
13+
public function up(Schema $schema) : void
14+
{
15+
// this up() migration is auto-generated, please modify it to your needs
16+
$this->abortIf($this->connection->getDatabasePlatform()->getName() !== 'mysql', 'Migration can only be executed safely on \'mysql\'.');
17+
18+
$this->addSql('CREATE TABLE import_run (id INT AUTO_INCREMENT NOT NULL, datetime DATETIME NOT NULL, result TINYINT(1) NOT NULL, output LONGTEXT DEFAULT NULL, type VARCHAR(255) NOT NULL, PRIMARY KEY(id)) DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci ENGINE = InnoDB');
19+
}
20+
21+
public function down(Schema $schema) : void
22+
{
23+
// this down() migration is auto-generated, please modify it to your needs
24+
$this->abortIf($this->connection->getDatabasePlatform()->getName() !== 'mysql', 'Migration can only be executed safely on \'mysql\'.');
25+
26+
$this->addSql('DROP TABLE import_run');
27+
}
28+
}
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
<?php
2+
3+
namespace App\Repository;
4+
5+
use App\Entity\ImportRun;
6+
use Doctrine\Bundle\DoctrineBundle\Repository\ServiceEntityRepository;
7+
use Doctrine\Common\Persistence\ManagerRegistry;
8+
9+
/**
10+
* @method ImportRun|null find($id, $lockMode = null, $lockVersion = null)
11+
* @method ImportRun|null findOneBy(array $criteria, array $orderBy = null)
12+
* @method ImportRun[] findAll()
13+
* @method ImportRun[] findBy(array $criteria, array $orderBy = null, $limit = null, $offset = null)
14+
*/
15+
class ImportRunRepository extends ServiceEntityRepository
16+
{
17+
public function __construct(ManagerRegistry $registry)
18+
{
19+
parent::__construct($registry, ImportRun::class);
20+
}
21+
}

src/Service/BaseImporter.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
use App\Repository\SystemRepository;
88
use App\Repository\GroupRepository;
99

10-
class BaseImporter
10+
abstract class BaseImporter implements ImportInterface
1111
{
1212
protected $entityManager;
1313
protected $reportRepository;

src/Service/ImportInterface.php

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
<?php
2+
3+
4+
namespace App\Service;
5+
6+
interface ImportInterface
7+
{
8+
/**
9+
* Import the given source.
10+
*
11+
* @param string $src
12+
* Path to the source
13+
*/
14+
function import(string $src);
15+
}

src/Service/ReportImporter.php

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,10 @@
77

88
class ReportImporter extends BaseImporter
99
{
10-
public function import($src)
10+
/**
11+
* @inheritDoc
12+
*/
13+
public function import(string $src)
1114
{
1215
$systemURL = getenv('SYSTEM_URL');
1316

@@ -45,7 +48,7 @@ public function import($src)
4548

4649
$report->setSysLink($systemURL . '/' . $entry->{'Sti'} . '/DispForm.aspx?ID=' . $entry->{'Id'});
4750

48-
$report->setSysConfidentialInformation($this->convertBoolean($entry->{'Følsomme oplysninger'}));
51+
$report->setSysConfidentialInformation($this->convertBoolean($entry->{'Følsomme personoplysninger'}));
4952
$report->setSysAlternativeTitle($this->sanitizeText($entry->{'Systemnavn'}));
5053
$report->setSysOwner($this->sanitizeText($entry->{'Systemejerskab'}));
5154
$report->setSysPurpose($this->sanitizeText($entry->{'Formål'}));
@@ -63,15 +66,15 @@ public function import($src)
6366
$report->setSysAuditorStatement($this->sanitizeText($entry->{'Revisorerklæring/tilsyn'}));
6467
$report->setSysAuditorStatementLink($this->sanitizeText($entry->{'Link til revisorerklæring'}));
6568
$report->setSysUsage($this->sanitizeText($entry->{'Systembrug'}));
66-
$report->setSysRequestForInsight($this->sanitizeText($entry->{'Anmodning om indsigt'}));
69+
//@TODO: $report->setSysRequestForInsight($this->sanitizeText($entry->{'Anmodning om indsigt'}));
6770
$report->setSysDateUse($this->convertDate($entry->{'Ibrugtagning'}));
6871
$report->setSysStatus($this->sanitizeText($entry->{'Status'}));
6972
$report->setSysRemarks($this->sanitizeText($entry->{'Bemærkninger'}));
7073
$report->setSysObligationToInform($this->sanitizeText($entry->{'Oplysningspligten'}));
7174
$report->setSysLegalBasis($this->sanitizeText($entry->{'Retligt grundlag'}));
7275
$report->setSysConsent($this->sanitizeText($entry->{'Samtykke'}));
7376
$report->setSysImpactAnalysis($this->sanitizeText($entry->{'Konsekvensanalyse'}));
74-
$report->setSysImpactAnalysisLink($this->sanitizeText($entry->{'Link til konsekvensanalyse'}));
77+
//@TODO: $report->setSysImpactAnalysisLink($this->sanitizeText($entry->{'Link til konsekvensanalyse'}));
7578
$report->setSysAuthorizationProcedure($this->sanitizeText($entry->{'Autorisationsprocedure'}));
7679
$report->setSysInternalInformation($this->sanitizeText($entry->{'Indsigt - interne oplysninger'}));
7780
$report->setSysDataWorthSaving($this->sanitizeText($entry->{'Indeholder systemet bevaringsværdige data?'}));

0 commit comments

Comments
 (0)