Lines
100.00%
36 / 36
Methods
100.00%
2 / 2
Classes
100.00%
1 / 1
| Name | Lines | Methods | CRAP | ||||
|---|---|---|---|---|---|---|---|
| readResponse | 100.00% | 33 / 33 | 100.00% | 1 / 1 | 10 | ||
| [BO\Zmsbackend\Api\BaseController] __invoke | 100.00% | 3 / 3 | 100.00% | 1 / 1 | 1 | ||
| 18 | class ProcessReserve extends \BO\Zmsbackend\Api\BaseController | |
| 19 | { | |
| 20 | /** | |
| 21 | * @SuppressWarnings(Param) | |
| 22 | * @SuppressWarnings(Complexity) | |
| 23 | * @return \Psr\Http\Message\ResponseInterface | |
| 24 | */ | |
| 25 | #[\Override] | |
| 26 | public function readResponse( | |
| 27 | \Psr\Http\Message\RequestInterface $request, | |
| 28 | \Psr\Http\Message\ResponseInterface $response, | |
| 29 | array $args | |
| 30 | ) { | |
| 31 | $slotsRequired = Validator::param('slotsRequired')->isNumber()->getValue(); | |
| 32 | $slotType = Validator::param('slotType')->isString()->getValue(); | |
| 33 | $clientKey = Validator::param('clientkey')->isString()->getValue(); | |
| 34 | $resolveReferences = Validator::param('resolveReferences')->isNumber()->setDefault(0)->getValue(); | |
| 35 | $input = Validator::input()->isJson()->assertValid()->getValue(); | |
| 36 | $process = new \BO\Zmsentities\Process($input); | |
| 37 | if ($process->hasId()) { | |
| 38 | throw new \BO\Zmsbackend\Process\Exception\ProcessAlreadyExists(); | |
| 39 | } | |
| 40 | ||
| 41 | \BO\Zmsbackend\Connection\Select::setCriticalReadSession(); | |
| 42 | ||
| 43 | if ($slotType || $slotsRequired) { | |
| 44 | $workstation = (new \BO\Zmsbackend\Helper\User($request))->checkPermissions(); | |
| 45 | \BO\Zmsbackend\Helper\Matching::testCurrentScopeHasRequest($process); | |
| 46 | } elseif ($clientKey) { | |
| 47 | $apiClient = (new \BO\Zmsbackend\Apikey\Service\Apiclient())->readEntity($clientKey); | |
| 48 | if (!$apiClient || !isset($apiClient->accesslevel) || $apiClient->accesslevel == 'blocked') { | |
| 49 | throw new \BO\Zmsbackend\Process\Exception\ApiclientInvalid(); | |
| 50 | } | |
| 51 | $slotType = $apiClient->accesslevel; | |
| 52 | if ($apiClient->accesslevel != 'intern') { | |
| 53 | $slotsRequired = 0; | |
| 54 | $slotType = $apiClient->accesslevel; | |
| 55 | $process = (new \BO\Zmsbackend\Process\Service\Process())->readSlotCount($process); | |
| 56 | } | |
| 57 | $process->apiclient = $apiClient; | |
| 58 | } else { | |
| 59 | $slotsRequired = 0; | |
| 60 | $slotType = 'public'; | |
| 61 | $process = (new \BO\Zmsbackend\Process\Service\Process())->readSlotCount($process); | |
| 62 | } | |
| 63 | ||
| 64 | $userAccount = (isset($workstation)) ? $workstation->getUseraccount() : null; | |
| 65 | $process = (new \BO\Zmsbackend\Process\Service\ProcessStatusFree()) | |
| 66 | ->writeEntityReserved($process, \App::$now, $slotType, $slotsRequired, $resolveReferences, $userAccount); | |
| 67 | ||
| 68 | $message = \BO\Zmsbackend\Api\Response\Message::create($request); | |
| 69 | $message->data = $process; | |
| 70 | ||
| 71 | $response = Render::withLastModified($response, time(), '0'); | |
| 72 | $response = Render::withJson($response, $message->setUpdatedMetaData(), $message->getStatuscode()); | |
| 73 | return $response; | |
| 74 | } | |
| 75 | } |
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 | } |