Skip to content

Commit 4b2ede5

Browse files
committed
DEVSUPP-160: Added import run entity to track import run success. Changed report fields that are imported after change in Anmeldelsesportalen
1 parent 6612210 commit 4b2ede5

8 files changed

Lines changed: 221 additions & 7 deletions

File tree

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' }

src/Command/ReportImportCommand.php

Lines changed: 25 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,10 @@
22

33
namespace App\Command;
44

5+
use App\Entity\ImportRun;
6+
use App\Entity\Report;
57
use App\Service\ReportImporter;
8+
use Doctrine\ORM\EntityManagerInterface;
69
use Symfony\Component\Console\Command\Command;
710
use Symfony\Component\Console\Input\InputInterface;
811
use Symfony\Component\Console\Output\OutputInterface;
@@ -11,12 +14,14 @@
1114
class ReportImportCommand extends Command
1215
{
1316
private $reportImporter;
17+
private $entityManager;
1418

15-
public function __construct(ReportImporter $reportImporter)
19+
public function __construct(ReportImporter $reportImporter, EntityManagerInterface $entityManager)
1620
{
1721
parent::__construct();
1822

1923
$this->reportImporter = $reportImporter;
24+
$this->entityManager = $entityManager;
2025
}
2126

2227
protected function configure()
@@ -29,6 +34,24 @@ protected function configure()
2934

3035
protected function execute(InputInterface $input, OutputInterface $output)
3136
{
32-
$this->reportImporter->import($input->getArgument('src'));
37+
$success = true;
38+
$errorMessage = null;
39+
40+
try {
41+
$this->reportImporter->import($input->getArgument('src'));
42+
} catch (\Exception $e) {
43+
$success = false;
44+
$errorMessage = $e->getMessage();
45+
$output->writeln($errorMessage);
46+
}
47+
48+
$importRun = new ImportRun();
49+
$importRun->setDatetime(new \DateTime());
50+
$importRun->setOutput($success ? 'OK' : $errorMessage);
51+
$importRun->setResult($success);
52+
$importRun->setType(Report::class);
53+
54+
$this->entityManager->persist($importRun);
55+
$this->entityManager->flush();
3356
}
3457
}

src/Command/SystemImportCommand.php

Lines changed: 25 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,10 @@
22

33
namespace App\Command;
44

5+
use App\Entity\ImportRun;
6+
use App\Entity\System;
57
use App\Service\SystemImporter;
8+
use Doctrine\ORM\EntityManagerInterface;
69
use Symfony\Component\Console\Command\Command;
710
use Symfony\Component\Console\Input\InputInterface;
811
use Symfony\Component\Console\Output\OutputInterface;
@@ -11,12 +14,14 @@
1114
class SystemImportCommand extends Command
1215
{
1316
private $systemImporter;
17+
private $entityManager;
1418

15-
public function __construct(SystemImporter $systemImporter)
19+
public function __construct(SystemImporter $systemImporter, EntityManagerInterface $entityManager)
1620
{
1721
parent::__construct();
1822

1923
$this->systemImporter = $systemImporter;
24+
$this->entityManager = $entityManager;
2025
}
2126

2227
protected function configure()
@@ -29,6 +34,24 @@ protected function configure()
2934

3035
protected function execute(InputInterface $input, OutputInterface $output)
3136
{
32-
$this->systemImporter->import($input->getArgument('src'));
37+
$success = true;
38+
$errorMessage = null;
39+
40+
try {
41+
$this->systemImporter->import($input->getArgument('src'));
42+
} catch (\Exception $e) {
43+
$success = false;
44+
$errorMessage = $e->getMessage();
45+
$output->writeln($errorMessage);
46+
}
47+
48+
$importRun = new ImportRun();
49+
$importRun->setDatetime(new \DateTime());
50+
$importRun->setOutput($success ? 'OK' : $errorMessage);
51+
$importRun->setResult($success);
52+
$importRun->setType(System::class);
53+
54+
$this->entityManager->persist($importRun);
55+
$this->entityManager->flush();
3356
}
3457
}

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/ReportImporter.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ public function import($src)
4545

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

48-
$report->setSysConfidentialInformation($this->convertBoolean($entry->{'Følsomme oplysninger'}));
48+
$report->setSysConfidentialInformation($this->convertBoolean($entry->{'Følsomme personoplysninger'}));
4949
$report->setSysAlternativeTitle($this->sanitizeText($entry->{'Systemnavn'}));
5050
$report->setSysOwner($this->sanitizeText($entry->{'Systemejerskab'}));
5151
$report->setSysPurpose($this->sanitizeText($entry->{'Formål'}));
@@ -63,15 +63,15 @@ public function import($src)
6363
$report->setSysAuditorStatement($this->sanitizeText($entry->{'Revisorerklæring/tilsyn'}));
6464
$report->setSysAuditorStatementLink($this->sanitizeText($entry->{'Link til revisorerklæring'}));
6565
$report->setSysUsage($this->sanitizeText($entry->{'Systembrug'}));
66-
$report->setSysRequestForInsight($this->sanitizeText($entry->{'Anmodning om indsigt'}));
66+
//@TODO: $report->setSysRequestForInsight($this->sanitizeText($entry->{'Anmodning om indsigt'}));
6767
$report->setSysDateUse($this->convertDate($entry->{'Ibrugtagning'}));
6868
$report->setSysStatus($this->sanitizeText($entry->{'Status'}));
6969
$report->setSysRemarks($this->sanitizeText($entry->{'Bemærkninger'}));
7070
$report->setSysObligationToInform($this->sanitizeText($entry->{'Oplysningspligten'}));
7171
$report->setSysLegalBasis($this->sanitizeText($entry->{'Retligt grundlag'}));
7272
$report->setSysConsent($this->sanitizeText($entry->{'Samtykke'}));
7373
$report->setSysImpactAnalysis($this->sanitizeText($entry->{'Konsekvensanalyse'}));
74-
$report->setSysImpactAnalysisLink($this->sanitizeText($entry->{'Link til konsekvensanalyse'}));
74+
//@TODO: $report->setSysImpactAnalysisLink($this->sanitizeText($entry->{'Link til konsekvensanalyse'}));
7575
$report->setSysAuthorizationProcedure($this->sanitizeText($entry->{'Autorisationsprocedure'}));
7676
$report->setSysInternalInformation($this->sanitizeText($entry->{'Indsigt - interne oplysninger'}));
7777
$report->setSysDataWorthSaving($this->sanitizeText($entry->{'Indeholder systemet bevaringsværdige data?'}));

translations/messages.da.yml

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,12 @@ list:
5252
system: Opret system
5353

5454
entity:
55+
import_run:
56+
id: ID
57+
type: Type
58+
datetime: Tidspunkt
59+
result: Result
60+
output: Output
5561
theme_category:
5662
sort_order: Vægt
5763
category: Kategori
@@ -179,6 +185,7 @@ entity:
179185
sys_data_to_science: Videregivelse af oplysninger til forskning
180186
sys_system_owner: Systemejer
181187
menu:
188+
import_runs: Import kørsler
182189
configuration: Konfiguration
183190
notes: Notater
184191
systemportal: Fra systemportalen
@@ -204,6 +211,7 @@ menu:
204211
groups: Grupper
205212
theme_category: Tema-Kategori
206213
exports: Eksport
214+
ImportRun: Import kørsler
207215
System: System
208216
Systems: Systemer
209217
User: Bruger

0 commit comments

Comments
 (0)