1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/** |
4
|
|
|
* Copyright 2017 SURFnet bv |
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\MiddlewareBundle\Migrations\InstitutionConfiguration; |
20
|
|
|
|
21
|
|
|
use Rhumsaa\Uuid\Uuid; |
22
|
|
|
use Surfnet\Stepup\Configuration\Entity\RaLocation; |
23
|
|
|
use Surfnet\Stepup\Configuration\Value\Institution; |
24
|
|
|
use Surfnet\Stepup\Configuration\Value\ShowRaaContactInformationOption; |
25
|
|
|
use Surfnet\Stepup\Configuration\Value\UseRaLocationsOption; |
26
|
|
|
use Surfnet\StepupMiddleware\CommandHandlingBundle\Configuration\Command\AddRaLocationCommand; |
27
|
|
|
use Surfnet\StepupMiddleware\CommandHandlingBundle\Configuration\Command\CreateInstitutionConfigurationCommand; |
28
|
|
|
use Surfnet\StepupMiddleware\CommandHandlingBundle\Configuration\Command\ReconfigureInstitutionConfigurationOptionsCommand; |
|
|
|
|
29
|
|
|
use Surfnet\StepupMiddleware\CommandHandlingBundle\Configuration\Command\RemoveInstitutionConfigurationByUnnormalizedIdCommand; |
|
|
|
|
30
|
|
|
|
31
|
|
|
final class MappedInstitutionConfiguration |
32
|
|
|
{ |
33
|
|
|
/** |
34
|
|
|
* @var Institution |
35
|
|
|
*/ |
36
|
|
|
private $institution; |
37
|
|
|
/** |
38
|
|
|
* @var ShowRaaContactInformationOption |
39
|
|
|
*/ |
40
|
|
|
private $showRaaContactInformationOption; |
41
|
|
|
/** |
42
|
|
|
* @var UseRaLocationsOption |
43
|
|
|
*/ |
44
|
|
|
private $useRaLocationsOption; |
45
|
|
|
/** |
46
|
|
|
* @var array|RaLocation[] |
47
|
|
|
*/ |
48
|
|
|
private $raLocations; |
49
|
|
|
|
50
|
|
|
/** |
51
|
|
|
* @param Institution $institution |
52
|
|
|
* @param UseRaLocationsOption $useRaLocationsOption |
53
|
|
|
* @param ShowRaaContactInformationOption $showRaaContactInformationOption |
54
|
|
|
* @param RaLocation[] $raLocations |
55
|
|
|
*/ |
56
|
|
View Code Duplication |
public function __construct( |
|
|
|
|
57
|
|
|
Institution $institution, |
58
|
|
|
UseRaLocationsOption $useRaLocationsOption, |
59
|
|
|
ShowRaaContactInformationOption $showRaaContactInformationOption, |
|
|
|
|
60
|
|
|
array $raLocations |
61
|
|
|
) { |
62
|
|
|
$this->institution = $institution; |
63
|
|
|
$this->showRaaContactInformationOption = $showRaaContactInformationOption; |
64
|
|
|
$this->useRaLocationsOption = $useRaLocationsOption; |
65
|
|
|
$this->raLocations = $raLocations; |
66
|
|
|
} |
67
|
|
|
|
68
|
|
|
/** |
69
|
|
|
* @return RemoveInstitutionConfigurationByUnnormalizedIdCommand |
70
|
|
|
*/ |
71
|
|
View Code Duplication |
public function inferRemoveInstitutionConfigurationByIdCommand() |
|
|
|
|
72
|
|
|
{ |
73
|
|
|
$command = new RemoveInstitutionConfigurationByUnnormalizedIdCommand(); |
74
|
|
|
$command->UUID = (string) Uuid::uuid4(); |
75
|
|
|
$command->institution = $this->institution->getInstitution(); |
76
|
|
|
|
77
|
|
|
return $command; |
78
|
|
|
} |
79
|
|
|
|
80
|
|
|
/** |
81
|
|
|
* @return CreateInstitutionConfigurationCommand |
82
|
|
|
*/ |
83
|
|
View Code Duplication |
public function inferCreateInstitutionConfigurationCommand() |
|
|
|
|
84
|
|
|
{ |
85
|
|
|
$command = new CreateInstitutionConfigurationCommand(); |
86
|
|
|
$command->UUID = Uuid::uuid4(); |
|
|
|
|
87
|
|
|
$command->institution = $this->institution->getInstitution(); |
88
|
|
|
|
89
|
|
|
return $command; |
90
|
|
|
} |
91
|
|
|
|
92
|
|
|
/** |
93
|
|
|
* @return ReconfigureInstitutionConfigurationOptionsCommand |
94
|
|
|
*/ |
95
|
|
|
public function inferReconfigureInstitutionConfigurationCommand() |
96
|
|
|
{ |
97
|
|
|
$command = new ReconfigureInstitutionConfigurationOptionsCommand(); |
98
|
|
|
$command->UUID = (string) Uuid::uuid4(); |
99
|
|
|
$command->institution = $this->institution->getInstitution(); |
100
|
|
|
$command->useRaLocationsOption = $this->useRaLocationsOption->isEnabled(); |
101
|
|
|
$command->showRaaContactInformationOption = $this->showRaaContactInformationOption->isEnabled(); |
102
|
|
|
|
103
|
|
|
return $command; |
104
|
|
|
} |
105
|
|
|
|
106
|
|
|
/** |
107
|
|
|
* @return AddRaLocationCommand[] |
108
|
|
|
*/ |
109
|
|
|
public function inferAddRaLocationCommands() |
110
|
|
|
{ |
111
|
|
|
$commands = []; |
112
|
|
|
$institution = $this->institution->getInstitution(); |
113
|
|
|
|
114
|
|
|
foreach ($this->raLocations as $raLocation) { |
115
|
|
|
$command = new AddRaLocationCommand(); |
116
|
|
|
$command->UUID = (string) Uuid::uuid4(); |
117
|
|
|
$command->institution = $institution; |
118
|
|
|
$command->raLocationId = $raLocation->getId()->getRaLocationId(); |
119
|
|
|
$command->raLocationName = $raLocation->getName()->getRaLocationName(); |
120
|
|
|
$command->contactInformation = $raLocation->getContactInformation()->getContactInformation(); |
121
|
|
|
$command->location = $raLocation->getLocation()->getLocation(); |
122
|
|
|
|
123
|
|
|
$commands[] = $command; |
124
|
|
|
} |
125
|
|
|
|
126
|
|
|
return $commands; |
127
|
|
|
} |
128
|
|
|
} |
129
|
|
|
|
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.