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