Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
100.00% |
10 / 10 |
|
100.00% |
3 / 3 |
CRAP | |
100.00% |
1 / 1 |
| ResultImportScheduler | |
100.00% |
10 / 10 |
|
100.00% |
3 / 3 |
3 | |
100.00% |
1 / 1 |
| __construct | |
100.00% |
2 / 2 |
|
100.00% |
1 / 1 |
1 | |||
| scheduleByRequest | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| schedule | |
100.00% |
7 / 7 |
|
100.00% |
1 / 1 |
1 | |||
| 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\models\Import\Task; |
| 24 | |
| 25 | use common_exception_MissingParameter; |
| 26 | use common_exception_NotFound; |
| 27 | use common_exception_ResourceNotFound; |
| 28 | use oat\tao\model\taskQueue\QueueDispatcher; |
| 29 | use oat\tao\model\taskQueue\Task\TaskInterface; |
| 30 | use oat\taoResultServer\models\Import\Exception\ImportResultException; |
| 31 | use oat\taoResultServer\models\Import\Factory\ImportResultInputFactory; |
| 32 | use oat\taoResultServer\models\Import\Input\ImportResultInput; |
| 33 | use Psr\Http\Message\ServerRequestInterface; |
| 34 | |
| 35 | class ResultImportScheduler |
| 36 | { |
| 37 | private QueueDispatcher $dispatcher; |
| 38 | private ImportResultInputFactory $importResultInputFactory; |
| 39 | |
| 40 | public function __construct(QueueDispatcher $dispatcher, ImportResultInputFactory $importResultInputFactory) |
| 41 | { |
| 42 | $this->dispatcher = $dispatcher; |
| 43 | $this->importResultInputFactory = $importResultInputFactory; |
| 44 | } |
| 45 | |
| 46 | /** |
| 47 | * @throws ImportResultException |
| 48 | * @throws common_exception_MissingParameter |
| 49 | * @throws common_exception_NotFound |
| 50 | * @throws common_exception_ResourceNotFound |
| 51 | */ |
| 52 | public function scheduleByRequest(ServerRequestInterface $request): TaskInterface |
| 53 | { |
| 54 | return $this->schedule($this->importResultInputFactory->createFromRequest($request)); |
| 55 | } |
| 56 | |
| 57 | public function schedule(ImportResultInput $input): TaskInterface |
| 58 | { |
| 59 | return $this->dispatcher->createTask( |
| 60 | new ImportResultTask(), |
| 61 | [ |
| 62 | ImportResultTask::PARAM_IMPORT_JSON => $input->jsonSerialize() |
| 63 | ], |
| 64 | 'Import Delivery Execution results' |
| 65 | ); |
| 66 | } |
| 67 | } |