1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/** |
4
|
|
|
* Copyright 2016 SURFnet B.V. |
5
|
|
|
* |
6
|
|
|
* Licensed under the Apache License, Version 2.0 (the "License"); |
7
|
|
|
* you may not use this file except in compliance with the License. |
8
|
|
|
* You may obtain a copy of the License at |
9
|
|
|
* |
10
|
|
|
* http://www.apache.org/licenses/LICENSE-2.0 |
11
|
|
|
* |
12
|
|
|
* Unless required by applicable law or agreed to in writing, software |
13
|
|
|
* distributed under the License is distributed on an "AS IS" BASIS, |
14
|
|
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
15
|
|
|
* See the License for the specific language governing permissions and |
16
|
|
|
* limitations under the License. |
17
|
|
|
*/ |
18
|
|
|
|
19
|
|
|
namespace Surfnet\StepupMiddleware\CommandHandlingBundle\Configuration\Processor; |
20
|
|
|
|
21
|
|
|
use Broadway\Processor\Processor; |
22
|
|
|
use Rhumsaa\Uuid\Uuid; |
23
|
|
|
use Surfnet\Stepup\Configuration\Value\Institution; |
24
|
|
|
use Surfnet\Stepup\Identity\Event\IdentityCreatedEvent; |
25
|
|
|
use Surfnet\Stepup\Identity\Event\InstitutionsAddedToWhitelistEvent; |
26
|
|
|
use Surfnet\Stepup\Identity\Event\WhitelistCreatedEvent; |
27
|
|
|
use Surfnet\Stepup\Identity\Event\WhitelistReplacedEvent; |
28
|
|
|
use Surfnet\StepupMiddleware\ApiBundle\Configuration\Repository\ConfiguredInstitutionRepository; |
29
|
|
|
use Surfnet\StepupMiddleware\CommandHandlingBundle\Configuration\Command\CreateInstitutionConfigurationCommand; |
30
|
|
|
use Surfnet\StepupMiddleware\CommandHandlingBundle\Pipeline\Pipeline; |
31
|
|
|
|
32
|
|
|
final class InstitutionConfigurationProcessor extends Processor |
33
|
|
|
{ |
34
|
|
|
/** |
35
|
|
|
* @var ConfiguredInstitutionRepository |
36
|
|
|
*/ |
37
|
|
|
private $configuredInstitutionRepository; |
38
|
|
|
|
39
|
|
|
/** |
40
|
|
|
* @var Pipeline |
41
|
|
|
*/ |
42
|
|
|
private $pipeline; |
43
|
|
|
|
44
|
|
|
public function __construct(ConfiguredInstitutionRepository $configuredInstitutionRepository, Pipeline $pipeline) |
|
|
|
|
45
|
|
|
{ |
46
|
|
|
$this->configuredInstitutionRepository = $configuredInstitutionRepository; |
47
|
|
|
$this->pipeline = $pipeline; |
48
|
|
|
} |
49
|
|
|
|
50
|
|
|
public function applyIdentityCreatedEvent(IdentityCreatedEvent $event) |
51
|
|
|
{ |
52
|
|
|
$institution = new Institution($event->identityInstitution->getInstitution()); |
53
|
|
|
|
54
|
|
|
if ($this->configuredInstitutionRepository->hasConfigurationFor($institution)) { |
55
|
|
|
return; |
56
|
|
|
} |
57
|
|
|
|
58
|
|
|
$this->createConfigurationFor($institution); |
59
|
|
|
} |
60
|
|
|
|
61
|
|
View Code Duplication |
public function applyWhitelistCreatedEvent(WhitelistCreatedEvent $event) |
|
|
|
|
62
|
|
|
{ |
63
|
|
|
foreach ($event->whitelistedInstitutions as $whitelistedInstitution) { |
64
|
|
|
$institution = new Institution($whitelistedInstitution->getInstitution()); |
65
|
|
|
|
66
|
|
|
if ($this->configuredInstitutionRepository->hasConfigurationFor($institution)) { |
67
|
|
|
continue; |
68
|
|
|
} |
69
|
|
|
|
70
|
|
|
$this->createConfigurationFor($institution); |
71
|
|
|
} |
72
|
|
|
} |
73
|
|
|
|
74
|
|
View Code Duplication |
public function applyWhitelistReplacedEvent(WhitelistReplacedEvent $event) |
|
|
|
|
75
|
|
|
{ |
76
|
|
|
foreach ($event->whitelistedInstitutions as $whitelistedInstitution) { |
77
|
|
|
$institution = new Institution($whitelistedInstitution->getInstitution()); |
78
|
|
|
|
79
|
|
|
if ($this->configuredInstitutionRepository->hasConfigurationFor($institution)) { |
80
|
|
|
continue; |
81
|
|
|
} |
82
|
|
|
|
83
|
|
|
$this->createConfigurationFor($institution); |
84
|
|
|
} |
85
|
|
|
} |
86
|
|
|
|
87
|
|
|
public function applyInstitutionsAddedToWhitelistEvent(InstitutionsAddedToWhitelistEvent $event) |
88
|
|
|
{ |
89
|
|
|
foreach ($event->addedInstitutions as $addedInstitution) { |
90
|
|
|
$institution = new Institution($addedInstitution->getInstitution()); |
91
|
|
|
|
92
|
|
|
if ($this->configuredInstitutionRepository->hasConfigurationFor($institution)) { |
93
|
|
|
continue; |
94
|
|
|
} |
95
|
|
|
|
96
|
|
|
$this->createConfigurationFor($institution); |
97
|
|
|
} |
98
|
|
|
} |
99
|
|
|
|
100
|
|
|
/** |
101
|
|
|
* @param Institution $institution |
102
|
|
|
*/ |
103
|
|
View Code Duplication |
private function createConfigurationFor(Institution $institution) |
|
|
|
|
104
|
|
|
{ |
105
|
|
|
$command = new CreateInstitutionConfigurationCommand(); |
106
|
|
|
$command->UUID = (string) Uuid::uuid4(); |
107
|
|
|
$command->institution = $institution; |
|
|
|
|
108
|
|
|
|
109
|
|
|
$this->pipeline->process($command); |
110
|
|
|
} |
111
|
|
|
} |
112
|
|
|
|
Very long variable names usually make code harder to read. It is therefore recommended not to make variable names too verbose.