Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
100.00% |
24 / 24 |
|
100.00% |
2 / 2 |
CRAP | |
100.00% |
1 / 1 |
| WorkstationProcessGet | |
100.00% |
24 / 24 |
|
100.00% |
2 / 2 |
5 | |
100.00% |
1 / 1 |
| readResponse | |
100.00% |
16 / 16 |
|
100.00% |
1 / 1 |
3 | |||
| validateProcessStatus | |
100.00% |
8 / 8 |
|
100.00% |
1 / 1 |
2 | |||
| 1 | <?php |
| 2 | |
| 3 | /** |
| 4 | * @package ZMS API |
| 5 | * @copyright BerlinOnline Stadtportal GmbH & Co. KG |
| 6 | **/ |
| 7 | |
| 8 | namespace BO\Zmsapi; |
| 9 | |
| 10 | use BO\Slim\Render; |
| 11 | use BO\Zmsdb\Process; |
| 12 | |
| 13 | class WorkstationProcessGet extends BaseController |
| 14 | { |
| 15 | /** |
| 16 | * @SuppressWarnings(Param) |
| 17 | * @return String |
| 18 | */ |
| 19 | public function readResponse( |
| 20 | \Psr\Http\Message\RequestInterface $request, |
| 21 | \Psr\Http\Message\ResponseInterface $response, |
| 22 | array $args |
| 23 | ) { |
| 24 | $workstation = (new Helper\User($request))->checkRights(); |
| 25 | $query = new Process(); |
| 26 | $processId = $args['id']; |
| 27 | |
| 28 | $process = $query->readEntity($processId, (new \BO\Zmsdb\Helper\NoAuth())); |
| 29 | |
| 30 | if (! $process || ! $process->hasId()) { |
| 31 | $exception = new Exception\Process\ProcessNotFound(); |
| 32 | $exception->data = ['processId' => $processId]; |
| 33 | throw $exception; |
| 34 | } |
| 35 | |
| 36 | $this->validateProcessStatus($process); |
| 37 | |
| 38 | $cluster = (new \BO\Zmsdb\Cluster())->readByScopeId(scopeId: $workstation->scope['id'], resolveReferences: 1); |
| 39 | $workstation->validateProcessScopeAccess($workstation->getScopeList($cluster), $process); |
| 40 | |
| 41 | $message = 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 | protected function validateProcessStatus($process) |
| 50 | { |
| 51 | $blockedStatuses = ['reserved', 'preconfirmed', 'deleted', 'called', 'processing']; |
| 52 | |
| 53 | if (in_array($process->getStatus(), $blockedStatuses)) { |
| 54 | $exception = new Exception\Process\ProcessNotCallable(); |
| 55 | $exception->data = [ |
| 56 | 'processId' => $process->getId(), |
| 57 | 'status' => $process->getStatus() |
| 58 | ]; |
| 59 | throw $exception; |
| 60 | } |
| 61 | } |
| 62 | } |