|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
/** |
|
4
|
|
|
* Copyright 2019 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\StepupRa\RaBundle\Service; |
|
20
|
|
|
|
|
21
|
|
|
use Psr\Log\LoggerInterface; |
|
22
|
|
|
use Surfnet\StepupMiddlewareClient\Identity\Dto\RaListingSearchQuery; |
|
23
|
|
|
use Surfnet\StepupMiddlewareClientBundle\Identity\Dto\RaListing; |
|
24
|
|
|
use Surfnet\StepupMiddlewareClientBundle\Identity\Dto\RaListingCollection; |
|
25
|
|
|
use Surfnet\StepupMiddlewareClientBundle\Identity\Service\RaListingService as ApiRaListingService; |
|
26
|
|
|
use Surfnet\StepupRa\RaBundle\Command\SearchRaListingCommand; |
|
27
|
|
|
use Surfnet\StepupRa\RaBundle\Exception\InvalidArgumentException; |
|
28
|
|
|
|
|
29
|
|
|
final class RaListingService |
|
30
|
|
|
{ |
|
31
|
|
|
/** |
|
32
|
|
|
* @var ApiRaListingService |
|
33
|
|
|
*/ |
|
34
|
|
|
private $apiRaListingService; |
|
35
|
|
|
|
|
36
|
|
|
/** |
|
37
|
|
|
* @var LoggerInterface |
|
38
|
|
|
*/ |
|
39
|
|
|
private $logger; |
|
40
|
|
|
|
|
41
|
|
|
public function __construct(ApiRaListingService $raListingService, LoggerInterface $logger) |
|
42
|
|
|
{ |
|
43
|
|
|
$this->apiRaListingService = $raListingService; |
|
44
|
|
|
$this->logger = $logger; |
|
45
|
|
|
} |
|
46
|
|
|
|
|
47
|
|
|
/** |
|
48
|
|
|
* @SuppressWarnings(PHPMD.CyclomaticComplexity) -- The command to query mapping in search exceed the |
|
49
|
|
|
* @SuppressWarnings(PHPMD.NPathComplexity) CyclomaticComplexity and NPathComplexity threshold. |
|
50
|
|
|
* |
|
51
|
|
|
* @param SearchRaListingCommand $command |
|
52
|
|
|
* @return RaListingCollection |
|
53
|
|
|
*/ |
|
54
|
|
|
public function search(SearchRaListingCommand $command) |
|
55
|
|
|
{ |
|
56
|
|
|
$query = new RaListingSearchQuery($command->actorId, $command->pageNumber); |
|
57
|
|
|
|
|
58
|
|
|
if ($command->name) { |
|
59
|
|
|
$query->setName($command->name); |
|
60
|
|
|
} |
|
61
|
|
|
|
|
62
|
|
|
if ($command->email) { |
|
63
|
|
|
$query->setEmail($command->email); |
|
64
|
|
|
} |
|
65
|
|
|
|
|
66
|
|
|
if ($command->institution) { |
|
67
|
|
|
$query->setInstitution($command->institution); |
|
68
|
|
|
} |
|
69
|
|
|
|
|
70
|
|
|
if ($command->roleAtInstitution && $command->roleAtInstitution->hasRole()) { |
|
71
|
|
|
$query->setRole($command->roleAtInstitution->getRole()); |
|
72
|
|
|
} |
|
73
|
|
|
|
|
74
|
|
|
if ($command->roleAtInstitution && $command->roleAtInstitution->hasInstitution()) { |
|
75
|
|
|
$query->setRaInstitution($command->roleAtInstitution->getInstitution()); |
|
76
|
|
|
} |
|
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->apiRaListingService->search($query); |
|
87
|
|
|
} |
|
88
|
|
|
|
|
89
|
|
|
/** |
|
90
|
|
|
* @param string $identityId |
|
91
|
|
|
* @param string $institution |
|
92
|
|
|
* @param string $actorId |
|
93
|
|
|
* @return null|RaListing |
|
94
|
|
|
*/ |
|
95
|
|
|
public function get($identityId, $institution, $actorId) |
|
96
|
|
|
{ |
|
97
|
|
|
if (!is_string($identityId)) { |
|
98
|
|
|
throw InvalidArgumentException::invalidType('string', 'identityId', $identityId); |
|
99
|
|
|
} |
|
100
|
|
|
|
|
101
|
|
|
if (!is_string($institution)) { |
|
102
|
|
|
throw InvalidArgumentException::invalidType('string', 'institution', $institution); |
|
103
|
|
|
} |
|
104
|
|
|
|
|
105
|
|
|
if (!is_string($actorId)) { |
|
106
|
|
|
throw InvalidArgumentException::invalidType('string', 'actorId', $actorId); |
|
107
|
|
|
} |
|
108
|
|
|
|
|
109
|
|
|
return $this->apiRaListingService->get($identityId, $institution, $actorId); |
|
110
|
|
|
} |
|
111
|
|
|
} |
|
112
|
|
|
|