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\ConfigureShowRaaContactInformationOptionCommand; |
|
|
|
|
35
|
|
|
use Surfnet\StepupMiddleware\CommandHandlingBundle\Configuration\Command\ConfigureUseRaLocationsOptionCommand; |
36
|
|
|
use Surfnet\StepupMiddleware\CommandHandlingBundle\Configuration\Command\CreateInstitutionConfigurationCommand; |
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 handleConfigureUseRaLocationsOptionCommand(ConfigureUseRaLocationsOptionCommand $command) |
64
|
|
|
{ |
65
|
|
|
$institution = new Institution($command->institution); |
66
|
|
|
$institutionConfigurationId = InstitutionConfigurationId::from($institution); |
67
|
|
|
|
68
|
|
|
$institutionConfiguration = $this->repository->load( |
69
|
|
|
$institutionConfigurationId->getInstitutionConfigurationId() |
70
|
|
|
); |
71
|
|
|
|
72
|
|
|
$institutionConfiguration->configureUseRaLocationsOption( |
73
|
|
|
new UseRaLocationsOption($command->useRaLocationsOption) |
74
|
|
|
); |
75
|
|
|
|
76
|
|
|
$this->repository->save($institutionConfiguration); |
77
|
|
|
} |
78
|
|
|
|
79
|
|
|
public function handleConfigureShowRaaContactInformationOptionCommand( |
80
|
|
|
ConfigureShowRaaContactInformationOptionCommand $command |
81
|
|
|
) { |
82
|
|
|
$institution = new Institution($command->institution); |
83
|
|
|
$institutionConfigurationId = InstitutionConfigurationId::from($institution); |
84
|
|
|
|
85
|
|
|
$institutionConfiguration = $this->repository->load( |
86
|
|
|
$institutionConfigurationId->getInstitutionConfigurationId() |
87
|
|
|
); |
88
|
|
|
|
89
|
|
|
$institutionConfiguration->configureShowRaaContactInformationOption( |
90
|
|
|
new ShowRaaContactInformationOption($command->showRaaContactInformationOption) |
91
|
|
|
); |
92
|
|
|
|
93
|
|
|
$this->repository->save($institutionConfiguration); |
94
|
|
|
} |
95
|
|
|
|
96
|
|
View Code Duplication |
public function handleAddRaLocationCommand(AddRaLocationCommand $command) |
|
|
|
|
97
|
|
|
{ |
98
|
|
|
$institution = new Institution($command->institution); |
99
|
|
|
$institutionConfigurationId = InstitutionConfigurationId::from($institution); |
100
|
|
|
|
101
|
|
|
$institutionConfiguration = $this->repository->load( |
102
|
|
|
$institutionConfigurationId->getInstitutionConfigurationId() |
103
|
|
|
); |
104
|
|
|
|
105
|
|
|
$institutionConfiguration->addRaLocation( |
106
|
|
|
new RaLocationId($command->raLocationId), |
107
|
|
|
new RaLocationName($command->raLocationName), |
108
|
|
|
new Location($command->location), |
109
|
|
|
new ContactInformation($command->contactInformation) |
110
|
|
|
); |
111
|
|
|
|
112
|
|
|
$this->repository->save($institutionConfiguration); |
113
|
|
|
} |
114
|
|
|
|
115
|
|
View Code Duplication |
public function handleChangeRaLocationCommand(ChangeRaLocationCommand $command) |
|
|
|
|
116
|
|
|
{ |
117
|
|
|
$institution = new Institution($command->institution); |
118
|
|
|
$institutionConfigurationId = InstitutionConfigurationId::from($institution); |
119
|
|
|
|
120
|
|
|
$institutionConfiguration = $this->repository->load( |
121
|
|
|
$institutionConfigurationId->getInstitutionConfigurationId() |
122
|
|
|
); |
123
|
|
|
|
124
|
|
|
$institutionConfiguration->changeRaLocation( |
125
|
|
|
new RaLocationId($command->raLocationId), |
126
|
|
|
new RaLocationName($command->raLocationName), |
127
|
|
|
new Location($command->location), |
128
|
|
|
new ContactInformation($command->contactInformation) |
129
|
|
|
); |
130
|
|
|
|
131
|
|
|
$this->repository->save($institutionConfiguration); |
132
|
|
|
} |
133
|
|
|
|
134
|
|
|
public function handleRemoveRaLocationCommand(RemoveRaLocationCommand $command) |
135
|
|
|
{ |
136
|
|
|
$institution = new Institution($command->institution); |
137
|
|
|
$institutionConfigurationId = InstitutionConfigurationId::from($institution); |
138
|
|
|
|
139
|
|
|
$institutionConfiguration = $this->repository->load( |
140
|
|
|
$institutionConfigurationId->getInstitutionConfigurationId() |
141
|
|
|
); |
142
|
|
|
|
143
|
|
|
$institutionConfiguration->removeRaLocation(new RaLocationId($command->raLocationId)); |
144
|
|
|
|
145
|
|
|
$this->repository->save($institutionConfiguration); |
146
|
|
|
} |
147
|
|
|
} |
148
|
|
|
|
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.