-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
57 changed files
with
4,238 additions
and
15 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,103 @@ | ||
<?php | ||
|
||
/** | ||
* This program is free software; you can redistribute it and/or | ||
* modify it under the terms of the GNU General Public License | ||
* as published by the Free Software Foundation; under version 2 | ||
* of the License (non-upgradable). | ||
* | ||
* This program is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
* GNU General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU General Public License | ||
* along with this program; if not, write to the Free Software | ||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. | ||
* | ||
* Copyright (c) 2020 (original work) Open Assessment Technologies SA ; | ||
*/ | ||
|
||
declare(strict_types=1); | ||
|
||
namespace oat\taoQtiTestPreviewer\controller; | ||
|
||
use common_exception_UserReadableException; | ||
use InvalidArgumentException; | ||
use oat\tao\model\http\HttpJsonResponseTrait; | ||
use oat\taoQtiTestPreviewer\models\test\service\TestPreviewer as TestPreviewerService; | ||
use oat\taoQtiTestPreviewer\models\test\TestPreviewRequest; | ||
use oat\taoQtiTestPreviewer\models\testConfiguration\service\TestPreviewerConfigurationService; | ||
use tao_actions_ServiceModule; | ||
use Throwable; | ||
|
||
class TestPreviewer extends tao_actions_ServiceModule | ||
{ | ||
use HttpJsonResponseTrait; | ||
|
||
public function init() | ||
{ | ||
try { | ||
$requestParams = $this->getPsrRequest()->getQueryParams(); | ||
|
||
if (empty($requestParams['testUri'])) { | ||
throw new InvalidArgumentException('Required `testUri` param is missing '); | ||
} | ||
|
||
$response = $this->getTestPreviewerService() | ||
->createPreview(new TestPreviewRequest($requestParams['testUri'])); | ||
|
||
$this->setNoCacheHeaders(); | ||
|
||
$this->setSuccessJsonResponse( | ||
[ | ||
'success' => true, | ||
'testData' => [], | ||
'testContext' => [], | ||
'testMap' => $response->getMap()->getMap(), | ||
] | ||
); | ||
} catch (Throwable $exception) { | ||
$message = $exception instanceof common_exception_UserReadableException | ||
? $exception->getUserMessage() | ||
: $exception->getMessage(); | ||
|
||
$this->setErrorJsonResponse($message); | ||
} | ||
} | ||
|
||
public function configuration(): void | ||
{ | ||
try { | ||
$this->setNoCacheHeaders(); | ||
|
||
$this->setSuccessJsonResponse( | ||
$this->getTestPreviewerConfigurationService()->getConfiguration() | ||
); | ||
} catch (Throwable $exception) { | ||
$message = $exception instanceof common_exception_UserReadableException | ||
? $exception->getUserMessage() | ||
: $exception->getMessage(); | ||
|
||
$this->setErrorJsonResponse($message); | ||
} | ||
} | ||
|
||
private function setNoCacheHeaders(): void | ||
{ | ||
$this->getResponseFormatter() | ||
->addHeader('Cache-Control', 'no-cache, no-store, must-revalidate') | ||
->addHeader('Pragma', 'no-cache') | ||
->addHeader('Expires', '0'); | ||
} | ||
|
||
private function getTestPreviewerConfigurationService(): TestPreviewerConfigurationService | ||
{ | ||
return $this->getServiceLocator()->get(TestPreviewerConfigurationService::class); | ||
} | ||
|
||
private function getTestPreviewerService(): TestPreviewerService | ||
{ | ||
return $this->getServiceLocator()->get(TestPreviewerService::class); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,280 @@ | ||
openapi: 3.0.1 | ||
info: | ||
title: taoTestPreview API | ||
description: Stands for TAO test Previewer API. | ||
version: 1.0.0 | ||
servers: | ||
- url: '{server}' | ||
variables: | ||
server: | ||
default: https://community.docker.localhost/ | ||
security: | ||
- cookieAuth: [] | ||
paths: | ||
/taoQtiTestPreviewer/TestPreviewer/init: | ||
get: | ||
parameters: | ||
- in: query | ||
name: testUri | ||
schema: | ||
type: string | ||
required: true | ||
example: 'https%3A%2F%2Fcommunity.docker.localhost%2Fontologies%2Ftao.rdf%23i5efb42fced1ce7064796c08b38ee176' | ||
description: Url encoded test identifier | ||
|
||
summary: Returns a test map | ||
responses: | ||
'200': | ||
$ref: '#/components/responses/InitResponse' | ||
'400': | ||
$ref: '#/components/responses/BadResponse' | ||
|
||
/taoQtiTestPreviewer/TestPreviewer/configuration: | ||
get: | ||
responses: | ||
'200': | ||
$ref: '#/components/responses/ConfigurationResponse' | ||
summary: Returns current active configuration for testRunner | ||
|
||
|
||
components: | ||
securitySchemes: | ||
cookieAuth: | ||
type: apiKey | ||
in: cookie | ||
name: tao_community | ||
|
||
responses: | ||
InitResponse: | ||
description: Good response | ||
content: | ||
application/json: | ||
schema: | ||
$ref: '#/components/schemas/TestInit' | ||
|
||
ConfigurationResponse: | ||
description: Response with a prepared configuration of testRunner | ||
content: | ||
application/json: | ||
schema: | ||
$ref: '#/components/schemas/Configuration' | ||
|
||
BadResponse: | ||
description: If something went wrong | ||
content: | ||
application/json: | ||
schema: | ||
$ref: '#/components/schemas/ErrorResponse' | ||
schemas: | ||
TestInit: | ||
properties: | ||
success: | ||
type: boolean | ||
example: true | ||
data: | ||
type: object | ||
properties: | ||
success: | ||
type: boolean | ||
example: true | ||
testData: | ||
$ref: '#/components/schemas/TestData' | ||
testContext: | ||
$ref: '#/components/schemas/TestContext' | ||
testMap: | ||
$ref: '#/components/schemas/TestMap' | ||
toolStates: | ||
description: the current tools states | ||
type: array | ||
items: | ||
type: integer | ||
lastStoreId: | ||
description: Checks the storeId request parameter and returns the last store id if set, false otherwise | ||
type: string | ||
messages: | ||
type: array | ||
items: | ||
type: integer | ||
|
||
TestData: | ||
description: test definition data | ||
deprecated: true | ||
type: object | ||
properties: | ||
title: | ||
type: string | ||
identifier: | ||
type: string | ||
className: | ||
type: string | ||
toolName: | ||
type: string | ||
exclusivelyLinear: | ||
type: boolean | ||
hasTimeLimits: | ||
type: boolean | ||
states: | ||
type: object | ||
itemStates: | ||
type: object | ||
config: | ||
type: object | ||
|
||
TestContext: | ||
description: test context object | ||
type: object | ||
|
||
TestMap: | ||
description: the map of the test items | ||
properties: | ||
scope: | ||
type: string | ||
example: test | ||
parts: | ||
type: object | ||
additionalProperties: | ||
$ref: '#/components/schemas/TestPartElement' | ||
title: | ||
type: string | ||
example: My awsame MathTest | ||
identifier: | ||
type: string | ||
className: | ||
type: string | ||
toolName: | ||
type: string | ||
example: tao | ||
exclusivelyLinear: | ||
type: boolean | ||
example: false | ||
hasTimeLimits: | ||
type: boolean | ||
stats: | ||
$ref: '#/components/schemas/StatsBlock' | ||
|
||
ItemElement: | ||
allOf: | ||
- $ref: '#/components/schemas/EntryBaseElement' | ||
- type: object | ||
properties: | ||
occurrence: | ||
type: integer | ||
example: 0 | ||
remainingAttempts: | ||
type: integer | ||
example: -1 | ||
answered: | ||
type: boolean | ||
example: false | ||
flagged: | ||
type: boolean | ||
example: false | ||
viewed: | ||
type: boolean | ||
example: false | ||
categories: | ||
type: array | ||
items: | ||
type: string | ||
example: | ||
- x-tao-option-reviewScreen | ||
- x-tao-option-markReview | ||
uri: | ||
type: string | ||
example: 'https:\/\/community.docker.localhost\/ontologies\/tao.rdf#i5efb4307b48d370fb46778476db6eb9' | ||
informational: | ||
type: boolean | ||
example: false | ||
|
||
SectionElement: | ||
allOf: | ||
- $ref: '#/components/schemas/EntryBaseElement' | ||
- type: object | ||
properties: | ||
isCatAdaptive: | ||
type: boolean | ||
example: false | ||
timeConstraint: | ||
example: null | ||
items: | ||
type: object | ||
additionalProperties: | ||
$ref: '#/components/schemas/ItemElement' | ||
stats: | ||
$ref: '#/components/schemas/StatsBlock' | ||
|
||
TestPartElement: | ||
allOf: | ||
- $ref: '#/components/schemas/EntryBaseElement' | ||
- type: object | ||
properties: | ||
isLinear: | ||
type: boolean | ||
timeConstraint: | ||
example: null | ||
sections: | ||
type: object | ||
additionalProperties: | ||
$ref: '#/components/schemas/SectionElement' | ||
|
||
EntryBaseElement: | ||
properties: | ||
id: | ||
type: string | ||
example: i-4 | ||
label: | ||
type: string | ||
example: Showcase label | ||
position: | ||
type: integer | ||
example: 20 | ||
|
||
ErrorResponse: | ||
properties: | ||
success: | ||
type: boolean | ||
example: false | ||
code: | ||
type: integer | ||
example: 400 | ||
message: | ||
type: string | ||
example: Internal error occured | ||
|
||
StatsBlock: | ||
properties: | ||
questions: | ||
type: integer | ||
example: 11 | ||
answered: | ||
type: integer | ||
example: 0 | ||
flagged: | ||
type: integer | ||
example: 3 | ||
viewed: | ||
type: integer | ||
example: 5 | ||
total: | ||
type: integer | ||
example: 99 | ||
questionsViewed: | ||
type: integer | ||
example: 19 | ||
|
||
Configuration: | ||
properties: | ||
success: | ||
type: boolean | ||
example: true | ||
data: | ||
type: object | ||
properties: | ||
providers: | ||
type: array | ||
items: | ||
type: object | ||
options: | ||
type: array | ||
items: | ||
type: object |
Oops, something went wrong.