Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
Total | |
100.00% |
21 / 21 |
|
100.00% |
2 / 2 |
CRAP | |
100.00% |
1 / 1 |
StoreTraceData | |
100.00% |
21 / 21 |
|
100.00% |
2 / 2 |
4 | |
100.00% |
1 / 1 |
process | |
100.00% |
20 / 20 |
|
100.00% |
1 / 1 |
3 | |||
getRequiredFields | |
100.00% |
1 / 1 |
|
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) 2017-2022 (original work) Open Assessment Technologies SA ; |
19 | */ |
20 | |
21 | namespace oat\taoQtiTest\models\runner\synchronisation\action; |
22 | |
23 | use common_Exception; |
24 | use common_exception_Error; |
25 | use common_exception_InconsistentData; |
26 | use common_Logger; |
27 | use Exception; |
28 | use oat\taoQtiTest\model\Service\StoreTraceVariablesCommand; |
29 | use oat\taoQtiTest\model\Service\StoreTraceVariablesService; |
30 | use oat\taoQtiTest\models\runner\synchronisation\TestRunnerAction; |
31 | |
32 | class StoreTraceData extends TestRunnerAction |
33 | { |
34 | /** |
35 | * Process the storeTraceData action. |
36 | * |
37 | * Validate required fields. |
38 | * Store trace data through runner service. |
39 | * Trigger TraceVariableStored event. |
40 | * |
41 | * @throws common_Exception |
42 | * @throws common_exception_Error |
43 | * @throws common_exception_InconsistentData |
44 | */ |
45 | public function process(): array |
46 | { |
47 | $this->validate(); |
48 | |
49 | try { |
50 | $traceVariables = json_decode( |
51 | html_entity_decode($this->getRequestParameter('traceData')), |
52 | true |
53 | ); |
54 | |
55 | $command = new StoreTraceVariablesCommand( |
56 | $this->getServiceContext(), |
57 | $traceVariables, |
58 | $this->getRequestParameter('itemDefinition') ?: null |
59 | ); |
60 | |
61 | /** @var StoreTraceVariablesService $storeTraceVariables */ |
62 | $storeTraceVariables = $this->getPsrContainer()->get(StoreTraceVariablesService::class); |
63 | |
64 | $response = $storeTraceVariables($command); |
65 | |
66 | common_Logger::d('Stored ' . count($traceVariables) . ' trace variables'); |
67 | |
68 | return $response->toArray(); |
69 | } catch (Exception $e) { |
70 | common_Logger::e( |
71 | $e->getMessage(), |
72 | ['deliveryExecutionId' => $this->getServiceContext()->getTestExecutionUri()] |
73 | ); |
74 | return $this->getErrorResponse($e); |
75 | } |
76 | } |
77 | |
78 | protected function getRequiredFields(): array |
79 | { |
80 | return array_merge(parent::getRequiredFields(), ['traceData']); |
81 | } |
82 | } |