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