Lines
100.00%
27 / 27
Methods
100.00%
3 / 3
Classes
100.00%
1 / 1
| Name | Lines | Methods | CRAP | ||||
|---|---|---|---|---|---|---|---|
| readResponse | 100.00% | 16 / 16 | 100.00% | 1 / 1 | 3 | ||
| validateProcessStatus | 100.00% | 8 / 8 | 100.00% | 1 / 1 | 2 | ||
| [BO\Zmsbackend\Api\BaseController] __invoke | 100.00% | 3 / 3 | 100.00% | 1 / 1 | 1 | ||
| 12 | class WorkstationProcessGet extends \BO\Zmsbackend\Api\BaseController | |
| 13 | { | |
| 14 | /** | |
| 15 | * @SuppressWarnings(Param) | |
| 16 | * @return \Psr\Http\Message\ResponseInterface | |
| 17 | */ | |
| 18 | #[\Override] | |
| 19 | public function readResponse( | |
| 20 | \Psr\Http\Message\RequestInterface $request, | |
| 21 | \Psr\Http\Message\ResponseInterface $response, | |
| 22 | array $args | |
| 23 | ) { | |
| 24 | $workstation = (new \BO\Zmsbackend\Helper\User($request))->checkPermissions(); | |
| 25 | $query = new \BO\Zmsbackend\Process\Service\Process(); | |
| 26 | $processId = $args['id']; | |
| 27 | ||
| 28 | $process = $query->readEntity($processId, (new \BO\Zmsbackend\Helper\NoAuth())); | |
| 29 | ||
| 30 | if (! $process || ! $process->hasId()) { | |
| 31 | $exception = new \BO\Zmsbackend\Process\Exception\ProcessNotFound(); | |
| 32 | $exception->data = ['processId' => $processId]; | |
| 33 | throw $exception; | |
| 34 | } | |
| 35 | ||
| 36 | $this->validateProcessStatus($process); | |
| 37 | ||
| 38 | $cluster = (new \BO\Zmsbackend\Cluster\Service\Cluster())->readByScopeId(scopeId: $workstation->scope['id'], resolveReferences: 1); | |
| 39 | $workstation->validateProcessScopeAccess($workstation->getScopeList($cluster), $process); | |
| 40 | ||
| 41 | $message = \BO\Zmsbackend\Api\Response\Message::create($request); | |
| 42 | $message->data = $process; | |
| 43 | ||
| 44 | $response = Render::withLastModified($response, time(), '0'); | |
| 45 | $response = Render::withJson($response, $message->setUpdatedMetaData(), $message->getStatuscode()); | |
| 46 | return $response; | |
| 47 | } | |
| 48 | ||
| 49 | /** | |
| 50 | * @return void | |
| 51 | */ | |
| 52 | protected function validateProcessStatus(\BO\Zmsentities\Process $process) | |
| 53 | { | |
| 54 | $blockedStatuses = ['reserved', 'preconfirmed', 'deleted', 'called', 'processing']; | |
| 55 | ||
| 56 | if (in_array($process->getStatus(), $blockedStatuses)) { | |
| 57 | $exception = new \BO\Zmsbackend\Process\Exception\ProcessNotCallable(); | |
| 58 | $exception->data = [ | |
| 59 | 'processId' => $process->getId(), | |
| 60 | 'status' => $process->getStatus() | |
| 61 | ]; | |
| 62 | throw $exception; | |
| 63 | } | |
| 64 | } | |
| 65 | } |
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 | } |