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\RepositoryInterface; |
23
|
|
|
use Surfnet\Stepup\Configuration\InstitutionConfiguration; |
24
|
|
|
use Surfnet\Stepup\Configuration\Value\InstitutionConfigurationId; |
25
|
|
|
use Surfnet\Stepup\Configuration\Value\Institution; |
26
|
|
|
use Surfnet\Stepup\Configuration\Value\Location; |
27
|
|
|
use Surfnet\Stepup\Configuration\Value\RaLocationId; |
28
|
|
|
use Surfnet\Stepup\Configuration\Value\RaLocationName; |
29
|
|
|
use Surfnet\Stepup\Configuration\Value\ContactInformation; |
30
|
|
|
use Surfnet\Stepup\Configuration\Value\ShowRaaContactInformationOption; |
31
|
|
|
use Surfnet\Stepup\Configuration\Value\UseRaLocationsOption; |
32
|
|
|
use Surfnet\StepupMiddleware\CommandHandlingBundle\Configuration\Command\AddRaLocationCommand; |
33
|
|
|
use Surfnet\StepupMiddleware\CommandHandlingBundle\Configuration\Command\ChangeRaLocationCommand; |
34
|
|
|
use Surfnet\StepupMiddleware\CommandHandlingBundle\Configuration\Command\ReconfigureInstitutionConfigurationOptionsCommand; |
|
|
|
|
35
|
|
|
use Surfnet\StepupMiddleware\CommandHandlingBundle\Configuration\Command\CreateInstitutionConfigurationCommand; |
36
|
|
|
use Surfnet\StepupMiddleware\CommandHandlingBundle\Configuration\Command\RemoveInstitutionConfigurationByUnnormalizedIdCommand; |
|
|
|
|
37
|
|
|
use Surfnet\StepupMiddleware\CommandHandlingBundle\Configuration\Command\RemoveRaLocationCommand; |
38
|
|
|
|
39
|
|
|
/** |
40
|
|
|
* @SuppressWarnings(PHPMD.CouplingBetweenObjects) Value objects |
41
|
|
|
*/ |
42
|
|
|
class InstitutionConfigurationCommandHandler extends CommandHandler |
43
|
|
|
{ |
44
|
|
|
/** |
45
|
|
|
* @var RepositoryInterface |
46
|
|
|
*/ |
47
|
|
|
private $repository; |
48
|
|
|
|
49
|
|
|
public function __construct(RepositoryInterface $repository) |
50
|
|
|
{ |
51
|
|
|
$this->repository = $repository; |
52
|
|
|
} |
53
|
|
|
|
54
|
|
|
public function handleCreateInstitutionConfigurationCommand(CreateInstitutionConfigurationCommand $command) |
55
|
|
|
{ |
56
|
|
|
$institution = new Institution($command->institution); |
57
|
|
|
$institutionConfigurationId = InstitutionConfigurationId::from($institution); |
58
|
|
|
$institutionConfiguration = InstitutionConfiguration::create($institutionConfigurationId, $institution); |
59
|
|
|
|
60
|
|
|
$this->repository->save($institutionConfiguration); |
61
|
|
|
} |
62
|
|
|
|
63
|
|
|
public function handleReconfigureInstitutionConfigurationOptionsCommand( |
64
|
|
|
ReconfigureInstitutionConfigurationOptionsCommand $command |
65
|
|
|
) { |
66
|
|
|
$institution = new Institution($command->institution); |
67
|
|
|
$institutionConfigurationId = InstitutionConfigurationId::from($institution); |
68
|
|
|
|
69
|
|
|
$institutionConfiguration = $this->repository->load( |
70
|
|
|
$institutionConfigurationId->getInstitutionConfigurationId() |
71
|
|
|
); |
72
|
|
|
|
73
|
|
|
$institutionConfiguration->configureUseRaLocationsOption( |
74
|
|
|
new UseRaLocationsOption($command->useRaLocationsOption) |
75
|
|
|
); |
76
|
|
|
$institutionConfiguration->configureShowRaaContactInformationOption( |
77
|
|
|
new ShowRaaContactInformationOption($command->showRaaContactInformationOption) |
78
|
|
|
); |
79
|
|
|
|
80
|
|
|
$this->repository->save($institutionConfiguration); |
81
|
|
|
} |
82
|
|
|
|
83
|
|
View Code Duplication |
public function handleAddRaLocationCommand(AddRaLocationCommand $command) |
|
|
|
|
84
|
|
|
{ |
85
|
|
|
$institution = new Institution($command->institution); |
86
|
|
|
$institutionConfigurationId = InstitutionConfigurationId::from($institution); |
87
|
|
|
|
88
|
|
|
$institutionConfiguration = $this->repository->load( |
89
|
|
|
$institutionConfigurationId->getInstitutionConfigurationId() |
90
|
|
|
); |
91
|
|
|
|
92
|
|
|
$institutionConfiguration->addRaLocation( |
93
|
|
|
new RaLocationId($command->raLocationId), |
94
|
|
|
new RaLocationName($command->raLocationName), |
95
|
|
|
new Location($command->location), |
96
|
|
|
new ContactInformation($command->contactInformation) |
97
|
|
|
); |
98
|
|
|
|
99
|
|
|
$this->repository->save($institutionConfiguration); |
100
|
|
|
} |
101
|
|
|
|
102
|
|
View Code Duplication |
public function handleChangeRaLocationCommand(ChangeRaLocationCommand $command) |
|
|
|
|
103
|
|
|
{ |
104
|
|
|
$institution = new Institution($command->institution); |
105
|
|
|
$institutionConfigurationId = InstitutionConfigurationId::from($institution); |
106
|
|
|
|
107
|
|
|
$institutionConfiguration = $this->repository->load( |
108
|
|
|
$institutionConfigurationId->getInstitutionConfigurationId() |
109
|
|
|
); |
110
|
|
|
|
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
|
|
View Code Duplication |
public function handleRemoveRaLocationCommand(RemoveRaLocationCommand $command) |
|
|
|
|
122
|
|
|
{ |
123
|
|
|
$institution = new Institution($command->institution); |
124
|
|
|
$institutionConfigurationId = InstitutionConfigurationId::from($institution); |
125
|
|
|
|
126
|
|
|
$institutionConfiguration = $this->repository->load( |
127
|
|
|
$institutionConfigurationId->getInstitutionConfigurationId() |
128
|
|
|
); |
129
|
|
|
|
130
|
|
|
$institutionConfiguration->removeRaLocation(new RaLocationId($command->raLocationId)); |
131
|
|
|
|
132
|
|
|
$this->repository->save($institutionConfiguration); |
133
|
|
|
} |
134
|
|
|
|
135
|
|
View Code Duplication |
public function handleRemoveInstitutionConfigurationByUnnormalizedIdCommand( |
|
|
|
|
136
|
|
|
RemoveInstitutionConfigurationByUnnormalizedIdCommand $command |
137
|
|
|
) { |
138
|
|
|
$institution = new Institution($command->institution); |
139
|
|
|
$institutionConfigurationId = InstitutionConfigurationId::from($institution); |
140
|
|
|
|
141
|
|
|
/** @var InstitutionConfiguration $institutionConfiguration */ |
142
|
|
|
$institutionConfiguration = $this->repository->load( |
143
|
|
|
$institutionConfigurationId->getInstitutionConfigurationId() |
144
|
|
|
); |
145
|
|
|
|
146
|
|
|
$institutionConfiguration->destroy(); |
147
|
|
|
|
148
|
|
|
$this->repository->save($institutionConfiguration); |
149
|
|
|
} |
150
|
|
|
} |
151
|
|
|
|
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.