Lines
100.00%
27 / 27
Methods
100.00%
3 / 3
Classes
100.00%
1 / 1
| Name | Lines | Methods | CRAP | ||||
|---|---|---|---|---|---|---|---|
| readResponse | 100.00% | 19 / 19 | 100.00% | 1 / 1 | 3 | ||
| validateExternalUserId | 100.00% | 5 / 5 | 100.00% | 1 / 1 | 4 | ||
| [BO\Zmsbackend\Api\BaseController] __invoke | 100.00% | 3 / 3 | 100.00% | 1 / 1 | 1 | ||
| 18 | class ProcessGetByExternalUserId extends \BO\Zmsbackend\Api\BaseController | |
| 19 | { | |
| 20 | /** | |
| 21 | * @SuppressWarnings(Param) | |
| 22 | * @return \Psr\Http\Message\ResponseInterface | |
| 23 | */ | |
| 24 | #[\Override] | |
| 25 | public function readResponse( | |
| 26 | \Psr\Http\Message\RequestInterface $request, | |
| 27 | \Psr\Http\Message\ResponseInterface $response, | |
| 28 | array $args | |
| 29 | ) { | |
| 30 | (new \BO\Zmsbackend\Helper\User($request, 2))->checkPermissions(); | |
| 31 | ||
| 32 | ||
| 33 | $resolveReferences = (int) (Validator::param('resolveReferences')->isNumber()->setDefault(2)->getValue() ?? 2); | |
| 34 | $processId = (int) $args['id']; | |
| 35 | $externalUserId = $args['externalUserId']; | |
| 36 | ||
| 37 | $process = (new \BO\Zmsbackend\Process\Service\Process())->readEntity( | |
| 38 | $processId, | |
| 39 | new \BO\Zmsbackend\Helper\NoAuth(), | |
| 40 | $resolveReferences | |
| 41 | ); | |
| 42 | ||
| 43 | if (!$process || !$process->hasId()) { | |
| 44 | $exception = new \BO\Zmsbackend\Process\Exception\ProcessNotFound(); | |
| 45 | $exception->data = ['processId' => $processId]; | |
| 46 | throw $exception; | |
| 47 | } | |
| 48 | ||
| 49 | $this->validateExternalUserId($process, $externalUserId); | |
| 50 | ||
| 51 | $message = \BO\Zmsbackend\Api\Response\Message::create($request); | |
| 52 | $message->data = $process; | |
| 53 | ||
| 54 | $response = Render::withLastModified($response, time(), '0'); | |
| 55 | $response = Render::withJson($response, $message->setUpdatedMetaData(), $message->getStatuscode()); | |
| 56 | return $response; | |
| 57 | } | |
| 58 | ||
| 59 | protected function validateExternalUserId(\BO\Zmsentities\Process $process, string $externalUserId): void | |
| 60 | { | |
| 61 | $processExternalUserId = $process->getExternalUserId(); | |
| 62 | if ( | |
| 63 | $processExternalUserId === null | |
| 64 | || $processExternalUserId === '' | |
| 65 | || (string) $processExternalUserId !== $externalUserId | |
| 66 | ) { | |
| 67 | throw new \BO\Zmsbackend\Process\Exception\ExternalUserIdMatchFailed(); | |
| 68 | } | |
| 69 | } | |
| 70 | } |
Inherited from BO\Zmsbackend\Api\BaseController
| 20 | public function __invoke(RequestInterface $request, ResponseInterface $response, array $args) | |
| 21 | { | |
| 22 | $request = $this->initRequest($request); | |
| 23 | $noCacheResponse = \BO\Slim\Render::withLastModified($response, time(), '0'); | |
| 24 | return $this->readResponse($request, $noCacheResponse, $args); | |
| 25 | } |