Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
0.00% |
0 / 36 |
|
0.00% |
0 / 2 |
CRAP | |
0.00% |
0 / 1 |
| DeliveryExecutionResults | |
0.00% |
0 / 36 |
|
0.00% |
0 / 2 |
56 | |
0.00% |
0 / 1 |
| patch | |
0.00% |
0 / 35 |
|
0.00% |
0 / 1 |
42 | |||
| getResultImportScheduler | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
| 1 | <?php |
| 2 | |
| 3 | /** |
| 4 | * This program is free software; you can redistribute it and/or |
| 5 | * modify it under the terms of the GNU General Public License |
| 6 | * as published by the Free Software Foundation; under version 2 |
| 7 | * of the License (non-upgradable). |
| 8 | * |
| 9 | * This program is distributed in the hope that it will be useful, |
| 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 12 | * GNU General Public License for more details. |
| 13 | * |
| 14 | * You should have received a copy of the GNU General Public License |
| 15 | * along with this program; if not, write to the Free Software |
| 16 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. |
| 17 | * |
| 18 | * Copyright (c) 2023 (original work) Open Assessment Technologies SA. |
| 19 | */ |
| 20 | |
| 21 | declare(strict_types=1); |
| 22 | |
| 23 | namespace oat\taoResultServer\controller\rest; |
| 24 | |
| 25 | use common_exception_MissingParameter; |
| 26 | use common_exception_ResourceNotFound; |
| 27 | use oat\oatbox\event\EventManagerAwareTrait; |
| 28 | use oat\tao\model\http\HttpJsonResponseTrait; |
| 29 | use oat\taoResultServer\models\Import\Task\ResultImportScheduler; |
| 30 | use tao_actions_RestController; |
| 31 | use Throwable; |
| 32 | |
| 33 | class DeliveryExecutionResults extends tao_actions_RestController |
| 34 | { |
| 35 | use EventManagerAwareTrait; |
| 36 | use HttpJsonResponseTrait; |
| 37 | |
| 38 | private const Q_PARAM_TRIGGER_AGS_SEND = 'send_ags'; |
| 39 | |
| 40 | public function patch(): void |
| 41 | { |
| 42 | $queryParams = $this->getPsrRequest()->getQueryParams(); |
| 43 | |
| 44 | try { |
| 45 | $this->logInfo( |
| 46 | sprintf( |
| 47 | '[DeliveryExecutionResults] requested with params: %s', |
| 48 | var_export($queryParams, true) |
| 49 | ) |
| 50 | ); |
| 51 | |
| 52 | $task = $this->getResultImportScheduler()->scheduleByRequest($this->getPsrRequest()); |
| 53 | |
| 54 | $this->setSuccessJsonResponse( |
| 55 | [ |
| 56 | 'agsNotificationTriggered' => isset($queryParams[self::Q_PARAM_TRIGGER_AGS_SEND]) && |
| 57 | filter_var($queryParams[self::Q_PARAM_TRIGGER_AGS_SEND], FILTER_VALIDATE_BOOLEAN), |
| 58 | 'taskId' => $task->getId() |
| 59 | ] |
| 60 | ); |
| 61 | |
| 62 | $this->logInfo( |
| 63 | sprintf( |
| 64 | '[DeliveryExecutionResults] successfully scheduled with params [%s]', |
| 65 | var_export($queryParams, true) |
| 66 | ) |
| 67 | ); |
| 68 | } catch (common_exception_MissingParameter $e) { |
| 69 | $this->setErrorJsonResponse($e->getMessage()); |
| 70 | } catch (common_exception_ResourceNotFound $e) { |
| 71 | $this->setErrorJsonResponse($e->getMessage(), 0, [], 404); |
| 72 | } catch (Throwable $e) { |
| 73 | $this->setErrorJsonResponse(sprintf('Internal error: %s', $e->getMessage()), 0, [], 500); |
| 74 | } finally { |
| 75 | if (isset($e)) { |
| 76 | $this->logError( |
| 77 | sprintf( |
| 78 | '[DeliveryExecutionResults] Error "%s" requesting with params [%s]', |
| 79 | $e->__toString(), |
| 80 | var_export($queryParams, true) |
| 81 | ) |
| 82 | ); |
| 83 | } |
| 84 | } |
| 85 | } |
| 86 | |
| 87 | private function getResultImportScheduler(): ResultImportScheduler |
| 88 | { |
| 89 | return $this->getServiceManager()->getContainer()->get(ResultImportScheduler::class); |
| 90 | } |
| 91 | } |