|
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\CommandHandler; |
|
20
|
|
|
|
|
21
|
|
|
use Broadway\CommandHandling\CommandHandler; |
|
22
|
|
|
use Broadway\Repository\AggregateNotFoundException; |
|
23
|
|
|
use Broadway\Repository\RepositoryInterface; |
|
24
|
|
|
use Surfnet\Stepup\Configuration\InstitutionConfiguration; |
|
25
|
|
|
use Surfnet\Stepup\Configuration\Value\InstitutionConfigurationId; |
|
26
|
|
|
use Surfnet\Stepup\Configuration\Value\Institution; |
|
27
|
|
|
use Surfnet\Stepup\Configuration\Value\Location; |
|
28
|
|
|
use Surfnet\Stepup\Configuration\Value\RaLocationId; |
|
29
|
|
|
use Surfnet\Stepup\Configuration\Value\RaLocationName; |
|
30
|
|
|
use Surfnet\Stepup\Configuration\Value\ContactInformation; |
|
31
|
|
|
use Surfnet\Stepup\Configuration\Value\ShowRaaContactInformationOption; |
|
32
|
|
|
use Surfnet\Stepup\Configuration\Value\UseRaLocationsOption; |
|
33
|
|
|
use Surfnet\StepupMiddleware\CommandHandlingBundle\Configuration\Command\AddRaLocationCommand; |
|
34
|
|
|
use Surfnet\StepupMiddleware\CommandHandlingBundle\Configuration\Command\ChangeRaLocationCommand; |
|
35
|
|
|
use Surfnet\StepupMiddleware\CommandHandlingBundle\Configuration\Command\ReconfigureInstitutionConfigurationOptionsCommand; |
|
|
|
|
|
|
36
|
|
|
use Surfnet\StepupMiddleware\CommandHandlingBundle\Configuration\Command\CreateInstitutionConfigurationCommand; |
|
37
|
|
|
use Surfnet\StepupMiddleware\CommandHandlingBundle\Configuration\Command\RemoveInstitutionConfigurationByUnnormalizedIdCommand; |
|
|
|
|
|
|
38
|
|
|
use Surfnet\StepupMiddleware\CommandHandlingBundle\Configuration\Command\RemoveRaLocationCommand; |
|
39
|
|
|
|
|
40
|
|
|
/** |
|
41
|
|
|
* @SuppressWarnings(PHPMD.CouplingBetweenObjects) Value objects |
|
42
|
|
|
*/ |
|
43
|
|
|
class InstitutionConfigurationCommandHandler extends CommandHandler |
|
44
|
|
|
{ |
|
45
|
|
|
/** |
|
46
|
|
|
* @var RepositoryInterface |
|
47
|
|
|
*/ |
|
48
|
|
|
private $repository; |
|
49
|
|
|
|
|
50
|
|
|
public function __construct(RepositoryInterface $repository) |
|
51
|
|
|
{ |
|
52
|
|
|
$this->repository = $repository; |
|
53
|
|
|
} |
|
54
|
|
|
|
|
55
|
|
View Code Duplication |
public function handleCreateInstitutionConfigurationCommand(CreateInstitutionConfigurationCommand $command) |
|
|
|
|
|
|
56
|
|
|
{ |
|
57
|
|
|
$institution = new Institution($command->institution); |
|
58
|
|
|
$institutionConfigurationId = InstitutionConfigurationId::normalizedFrom($institution); |
|
59
|
|
|
|
|
60
|
|
|
try { |
|
61
|
|
|
/** @var InstitutionConfiguration $institutionConfiguration */ |
|
62
|
|
|
$institutionConfiguration = $this->repository->load( |
|
63
|
|
|
$institutionConfigurationId->getInstitutionConfigurationId() |
|
64
|
|
|
); |
|
65
|
|
|
|
|
66
|
|
|
$institutionConfiguration->rebuild(); |
|
67
|
|
|
|
|
68
|
|
|
} catch (AggregateNotFoundException $exception) { |
|
69
|
|
|
$institutionConfiguration = InstitutionConfiguration::create($institutionConfigurationId, $institution); |
|
70
|
|
|
} |
|
71
|
|
|
|
|
72
|
|
|
$this->repository->save($institutionConfiguration); |
|
73
|
|
|
} |
|
74
|
|
|
|
|
75
|
|
|
public function handleReconfigureInstitutionConfigurationOptionsCommand( |
|
76
|
|
|
ReconfigureInstitutionConfigurationOptionsCommand $command |
|
77
|
|
|
) { |
|
78
|
|
|
$institution = new Institution($command->institution); |
|
79
|
|
|
|
|
80
|
|
|
$institutionConfiguration = $this->loadInstitutionConfigurationFor($institution); |
|
|
|
|
|
|
81
|
|
|
$institutionConfiguration->configureUseRaLocationsOption( |
|
82
|
|
|
new UseRaLocationsOption($command->useRaLocationsOption) |
|
83
|
|
|
); |
|
84
|
|
|
$institutionConfiguration->configureShowRaaContactInformationOption( |
|
85
|
|
|
new ShowRaaContactInformationOption($command->showRaaContactInformationOption) |
|
86
|
|
|
); |
|
87
|
|
|
|
|
88
|
|
|
$this->repository->save($institutionConfiguration); |
|
89
|
|
|
} |
|
90
|
|
|
|
|
91
|
|
View Code Duplication |
public function handleAddRaLocationCommand(AddRaLocationCommand $command) |
|
|
|
|
|
|
92
|
|
|
{ |
|
93
|
|
|
$institution = new Institution($command->institution); |
|
94
|
|
|
|
|
95
|
|
|
$institutionConfiguration = $this->loadInstitutionConfigurationFor($institution); |
|
|
|
|
|
|
96
|
|
|
$institutionConfiguration->addRaLocation( |
|
97
|
|
|
new RaLocationId($command->raLocationId), |
|
98
|
|
|
new RaLocationName($command->raLocationName), |
|
99
|
|
|
new Location($command->location), |
|
100
|
|
|
new ContactInformation($command->contactInformation) |
|
101
|
|
|
); |
|
102
|
|
|
|
|
103
|
|
|
$this->repository->save($institutionConfiguration); |
|
104
|
|
|
} |
|
105
|
|
|
|
|
106
|
|
View Code Duplication |
public function handleChangeRaLocationCommand(ChangeRaLocationCommand $command) |
|
|
|
|
|
|
107
|
|
|
{ |
|
108
|
|
|
$institution = new Institution($command->institution); |
|
109
|
|
|
|
|
110
|
|
|
$institutionConfiguration = $this->loadInstitutionConfigurationFor($institution); |
|
|
|
|
|
|
111
|
|
|
$institutionConfiguration->changeRaLocation( |
|
112
|
|
|
new RaLocationId($command->raLocationId), |
|
113
|
|
|
new RaLocationName($command->raLocationName), |
|
114
|
|
|
new Location($command->location), |
|
115
|
|
|
new ContactInformation($command->contactInformation) |
|
116
|
|
|
); |
|
117
|
|
|
|
|
118
|
|
|
$this->repository->save($institutionConfiguration); |
|
119
|
|
|
} |
|
120
|
|
|
|
|
121
|
|
|
public function handleRemoveRaLocationCommand(RemoveRaLocationCommand $command) |
|
122
|
|
|
{ |
|
123
|
|
|
$institution = new Institution($command->institution); |
|
124
|
|
|
|
|
125
|
|
|
$institutionConfiguration = $this->loadInstitutionConfigurationFor($institution); |
|
|
|
|
|
|
126
|
|
|
$institutionConfiguration->removeRaLocation(new RaLocationId($command->raLocationId)); |
|
127
|
|
|
|
|
128
|
|
|
$this->repository->save($institutionConfiguration); |
|
129
|
|
|
} |
|
130
|
|
|
|
|
131
|
|
|
public function handleRemoveInstitutionConfigurationByUnnormalizedIdCommand( |
|
132
|
|
|
RemoveInstitutionConfigurationByUnnormalizedIdCommand $command |
|
133
|
|
|
) { |
|
134
|
|
|
$institution = new Institution($command->institution); |
|
135
|
|
|
|
|
136
|
|
|
$institutionConfigurationId = InstitutionConfigurationId::from($institution); |
|
|
|
|
|
|
137
|
|
|
$institutionConfiguration = $this->repository->load( |
|
138
|
|
|
$institutionConfigurationId->getInstitutionConfigurationId() |
|
139
|
|
|
); |
|
140
|
|
|
$institutionConfiguration->destroy(); |
|
141
|
|
|
|
|
142
|
|
|
$this->repository->save($institutionConfiguration); |
|
143
|
|
|
} |
|
144
|
|
|
|
|
145
|
|
|
/** |
|
146
|
|
|
* @deprecated Should be used until existing institution configurations have been migrated to using normalized ids |
|
147
|
|
|
* |
|
148
|
|
|
* @param Institution $institution |
|
149
|
|
|
* @return InstitutionConfiguration |
|
150
|
|
|
*/ |
|
151
|
|
View Code Duplication |
private function loadInstitutionConfigurationFor(Institution $institution) |
|
|
|
|
|
|
152
|
|
|
{ |
|
153
|
|
|
try { |
|
154
|
|
|
$institutionConfigurationId = InstitutionConfigurationId::normalizedFrom($institution); |
|
155
|
|
|
$institutionConfiguration = $this->repository->load( |
|
156
|
|
|
$institutionConfigurationId->getInstitutionConfigurationId() |
|
157
|
|
|
); |
|
158
|
|
|
} catch (AggregateNotFoundException $exception) { |
|
159
|
|
|
$institutionConfigurationId = InstitutionConfigurationId::from($institution); |
|
|
|
|
|
|
160
|
|
|
$institutionConfiguration = $this->repository->load( |
|
161
|
|
|
$institutionConfigurationId->getInstitutionConfigurationId() |
|
162
|
|
|
); |
|
163
|
|
|
} |
|
164
|
|
|
|
|
165
|
|
|
return $institutionConfiguration; |
|
166
|
|
|
} |
|
167
|
|
|
} |
|
168
|
|
|
|
Overly long lines are hard to read on any screen. Most code styles therefor impose a maximum limit on the number of characters in a line.