|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
/** |
|
4
|
|
|
* Copyright 2014 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\StepupRa\RaBundle\Service; |
|
20
|
|
|
|
|
21
|
|
|
use Psr\Log\LoggerInterface; |
|
22
|
|
|
use Surfnet\StepupMiddlewareClient\Configuration\Dto\RaLocationSearchQuery; |
|
23
|
|
|
use Surfnet\StepupMiddlewareClientBundle\Configuration\Command\AddRaLocationCommand as MiddlewareCreateLocationCommand; |
|
24
|
|
|
use Surfnet\StepupMiddlewareClientBundle\Configuration\Command\ChangeRaLocationCommand as MiddlewareChangeRaLocationCommand; |
|
|
|
|
|
|
25
|
|
|
use Surfnet\StepupMiddlewareClientBundle\Configuration\Command\RemoveRaLocationCommand as MiddlewareRemoveRaLocationCommand; |
|
|
|
|
|
|
26
|
|
|
use Surfnet\StepupMiddlewareClientBundle\Configuration\Dto\RaLocationCollection; |
|
27
|
|
|
use Surfnet\StepupMiddlewareClientBundle\Configuration\Service\RaLocationService as ApiRaLocationService; |
|
28
|
|
|
use Surfnet\StepupMiddlewareClientBundle\Uuid\Uuid; |
|
29
|
|
|
use Surfnet\StepupRa\RaBundle\Command\ChangeRaLocationCommand; |
|
30
|
|
|
use Surfnet\StepupRa\RaBundle\Command\CreateRaLocationCommand; |
|
31
|
|
|
use Surfnet\StepupRa\RaBundle\Command\RemoveRaLocationCommand; |
|
32
|
|
|
use Surfnet\StepupRa\RaBundle\Command\SearchRaLocationsCommand; |
|
33
|
|
|
|
|
34
|
|
|
class RaLocationService |
|
35
|
|
|
{ |
|
36
|
|
|
/** |
|
37
|
|
|
* @var \Surfnet\StepupMiddlewareClientBundle\Configuration\Service\RaLocationService |
|
38
|
|
|
*/ |
|
39
|
|
|
private $apiRaLocationService; |
|
40
|
|
|
|
|
41
|
|
|
/** |
|
42
|
|
|
* @var \Surfnet\StepupRa\RaBundle\Service\CommandService |
|
43
|
|
|
*/ |
|
44
|
|
|
private $commandService; |
|
45
|
|
|
|
|
46
|
|
|
/** |
|
47
|
|
|
* @var \Psr\Log\LoggerInterface |
|
48
|
|
|
*/ |
|
49
|
|
|
private $logger; |
|
50
|
|
|
|
|
51
|
|
|
public function __construct( |
|
52
|
|
|
ApiRaLocationService $apiRaLocationService, |
|
53
|
|
|
CommandService $commandService, |
|
54
|
|
|
LoggerInterface $logger |
|
55
|
|
|
) { |
|
56
|
|
|
$this->apiRaLocationService = $apiRaLocationService; |
|
57
|
|
|
$this->commandService = $commandService; |
|
58
|
|
|
$this->logger = $logger; |
|
59
|
|
|
} |
|
60
|
|
|
|
|
61
|
|
|
/** |
|
62
|
|
|
* @param string $id |
|
63
|
|
|
* @return null|\Surfnet\StepupMiddlewareClientBundle\Configuration\Dto\RaLocation |
|
64
|
|
|
*/ |
|
65
|
|
|
public function find($id) |
|
66
|
|
|
{ |
|
67
|
|
|
return $this->apiRaLocationService->get($id); |
|
68
|
|
|
} |
|
69
|
|
|
|
|
70
|
|
|
/** |
|
71
|
|
|
* @param SearchRaLocationsCommand $command |
|
72
|
|
|
* @return RaLocationCollection |
|
73
|
|
|
*/ |
|
74
|
|
|
public function search(SearchRaLocationsCommand $command) |
|
75
|
|
|
{ |
|
76
|
|
|
$query = new RaLocationSearchQuery($command->institution); |
|
77
|
|
|
|
|
78
|
|
|
if ($command->orderBy) { |
|
79
|
|
|
$query->setOrderBy($command->orderBy); |
|
80
|
|
|
} |
|
81
|
|
|
|
|
82
|
|
|
if ($command->orderDirection) { |
|
83
|
|
|
$query->setOrderDirection($command->orderDirection); |
|
84
|
|
|
} |
|
85
|
|
|
|
|
86
|
|
|
return $this->apiRaLocationService->search($query); |
|
87
|
|
|
} |
|
88
|
|
|
|
|
89
|
|
View Code Duplication |
public function create(CreateRaLocationCommand $command) |
|
|
|
|
|
|
90
|
|
|
{ |
|
91
|
|
|
$middlewareCommand = new MiddlewareCreateLocationCommand(); |
|
92
|
|
|
$middlewareCommand->id = Uuid::generate(); |
|
93
|
|
|
$middlewareCommand->name = $command->name; |
|
94
|
|
|
$middlewareCommand->institution = $command->institution; |
|
95
|
|
|
$middlewareCommand->contactInformation = $command->contactInformation; |
|
96
|
|
|
$middlewareCommand->location = $command->location; |
|
97
|
|
|
|
|
98
|
|
|
$result = $this->commandService->execute($middlewareCommand); |
|
99
|
|
|
|
|
100
|
|
|
if (!$result->isSuccessful()) { |
|
101
|
|
|
$this->logger->critical(sprintf( |
|
102
|
|
|
'Creation of RA location "%s" for institution "%s" by user "%s" failed: "%s"', |
|
103
|
|
|
$middlewareCommand->name, |
|
104
|
|
|
$middlewareCommand->institution, |
|
105
|
|
|
$command->currentUserId, |
|
106
|
|
|
implode(", ", $result->getErrors()) |
|
|
|
|
|
|
107
|
|
|
)); |
|
108
|
|
|
} |
|
109
|
|
|
|
|
110
|
|
|
return $result->isSuccessful(); |
|
111
|
|
|
} |
|
112
|
|
|
|
|
113
|
|
View Code Duplication |
public function change(ChangeRaLocationCommand $command) |
|
|
|
|
|
|
114
|
|
|
{ |
|
115
|
|
|
$middlewareCommand = new MiddlewareChangeRaLocationCommand(); |
|
116
|
|
|
$middlewareCommand->id = $command->id; |
|
117
|
|
|
$middlewareCommand->name = $command->name; |
|
118
|
|
|
$middlewareCommand->institution = $command->institution; |
|
119
|
|
|
$middlewareCommand->contactInformation = $command->contactInformation; |
|
120
|
|
|
$middlewareCommand->location = $command->location; |
|
121
|
|
|
|
|
122
|
|
|
$result = $this->commandService->execute($middlewareCommand); |
|
123
|
|
|
|
|
124
|
|
|
if (!$result->isSuccessful()) { |
|
125
|
|
|
$this->logger->critical(sprintf( |
|
126
|
|
|
'Changing of RA location "%s" for institution "%s" by user "%s" failed: "%s"', |
|
127
|
|
|
$middlewareCommand->name, |
|
128
|
|
|
$middlewareCommand->institution, |
|
129
|
|
|
$command->currentUserId, |
|
130
|
|
|
implode(", ", $result->getErrors()) |
|
|
|
|
|
|
131
|
|
|
)); |
|
132
|
|
|
} |
|
133
|
|
|
|
|
134
|
|
|
return $result->isSuccessful(); |
|
135
|
|
|
} |
|
136
|
|
|
|
|
137
|
|
|
/** |
|
138
|
|
|
* @param RemoveRaLocationCommand $command |
|
139
|
|
|
* @return bool |
|
140
|
|
|
*/ |
|
141
|
|
View Code Duplication |
public function remove(RemoveRaLocationCommand $command) |
|
|
|
|
|
|
142
|
|
|
{ |
|
143
|
|
|
$middlewareCommand = new MiddlewareRemoveRaLocationCommand(); |
|
144
|
|
|
$middlewareCommand->institution = $command->institution; |
|
145
|
|
|
$middlewareCommand->raLocationId = $command->locationId; |
|
146
|
|
|
$result = $this->commandService->execute($middlewareCommand); |
|
147
|
|
|
|
|
148
|
|
|
if (!$result->isSuccessful()) { |
|
149
|
|
|
$this->logger->critical(sprintf( |
|
150
|
|
|
'Removal of RA location "%s" of institution "%s" by user "%s" failed: "%s"', |
|
151
|
|
|
$middlewareCommand->raLocationId, |
|
152
|
|
|
$middlewareCommand->institution, |
|
153
|
|
|
$command->currentUserId, |
|
154
|
|
|
implode(", ", $result->getErrors()) |
|
|
|
|
|
|
155
|
|
|
)); |
|
156
|
|
|
} |
|
157
|
|
|
|
|
158
|
|
|
return $result->isSuccessful(); |
|
159
|
|
|
} |
|
160
|
|
|
} |
|
161
|
|
|
|
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.