-
Notifications
You must be signed in to change notification settings - Fork 11
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #502 from oat-sa/release-3.1.0
Release 3.1.0
- Loading branch information
Showing
32 changed files
with
1,470 additions
and
308 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 |
---|---|---|
|
@@ -20,7 +20,7 @@ | |
* | ||
* @author Absar Gilani & Rashid - PCG Team - {[email protected]} | ||
*/ | ||
class taoQtiTest_actions_RestQtiTests extends tao_actions_CommonRestModule | ||
class taoQtiTest_actions_RestQtiTests extends tao_actions_RestController | ||
{ | ||
private static $accepted_types = array( | ||
'application/zip', | ||
|
@@ -29,6 +29,11 @@ class taoQtiTest_actions_RestQtiTests extends tao_actions_CommonRestModule | |
'application/x-compressed' | ||
); | ||
|
||
public function index() | ||
{ | ||
$this->returnFailure(new \common_exception_NotImplemented('This API does not support this call.')); | ||
} | ||
|
||
public function __construct() | ||
{ | ||
parent::__construct(); | ||
|
@@ -37,57 +42,35 @@ public function __construct() | |
} | ||
|
||
/** | ||
* | ||
* Uploads and Import a QTI Test Package containing one or more QTI Test definitions. | ||
* | ||
* @param array file description | ||
* @return common_report_Report An import report. | ||
* @throws common_exception_InvalidArgumentType | ||
* Import file entry point by using $this->service | ||
* Check POST method & get valid uploaded file | ||
*/ | ||
protected function importQtiPackage($file) | ||
public function import() | ||
{ | ||
if ($this->getRequestMethod() != Request::HTTP_POST) { | ||
throw new \common_exception_NotImplemented('Only post method is accepted to import Qti package.'); | ||
} | ||
$file = tao_helpers_Http::getUploadedFile("qtiPackage"); | ||
$mimeType = tao_helpers_File::getMimeType($file['tmp_name']); | ||
if (!in_array($mimeType, self::$accepted_types)) { | ||
return new common_report_Report(common_report_Report::TYPE_ERROR, __("Incorrect File Type")); | ||
} | ||
return $this->service->importQtiTest($file['tmp_name']); | ||
} | ||
|
||
/** | ||
* Requires qtiPackage as a parameter | ||
*/ | ||
protected function getParametersRequirements() | ||
{ | ||
return array( | ||
"post" => array( | ||
"qtiPackage" | ||
) | ||
); | ||
} | ||
|
||
/** | ||
* This code snippet import QTI Package | ||
* | ||
* @author Rashid Mumtaz & Absar - PCG Team - {[email protected] & [email protected]} | ||
* @return returnSuccess and returnFailure | ||
*/ | ||
protected function post() | ||
{ | ||
$data = $this->importQtiPackage(tao_helpers_Http::getUploadedFile("qtiPackage")); | ||
if ($data->getType() === common_report_Report::TYPE_ERROR) { | ||
$e = new common_exception_Error($data->getMessage()); | ||
return $this->returnFailure($e); | ||
$this->returnFailure(new common_exception_BadRequest()); | ||
} else { | ||
foreach ($data as $r) { | ||
$values = $r->getData(); | ||
$testid = $values->rdfsResource->getUri(); | ||
foreach ($values->items as $item) { | ||
$itemsid[] = $item->getUri(); | ||
$report = $this->service->importQtiTest($file['tmp_name']); | ||
if ($report->getType() === common_report_Report::TYPE_SUCCESS) { | ||
$data = array(); | ||
foreach ($report as $r) { | ||
$values = $r->getData(); | ||
$testid = $values->rdfsResource->getUri(); | ||
foreach ($values->items as $item) { | ||
$itemsid[] = $item->getUri(); | ||
} | ||
$data[] = array( | ||
'testId' => $testid, | ||
'testItems' => $itemsid); | ||
} | ||
$data = array( | ||
'testId' => $testid, | ||
'testItems' => $itemsid); | ||
return $this->returnSuccess($data); | ||
} else { | ||
return $this->returnFailure(new common_exception_InvalidArgumentType($report->getMessage())); | ||
} | ||
} | ||
} | ||
|
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 |
---|---|---|
|
@@ -20,6 +20,7 @@ | |
* @author Jean-Sébastien Conan <[email protected]> | ||
*/ | ||
|
||
use oat\taoQtiTest\models\runner\QtiRunnerRequiredException; | ||
use oat\taoQtiTest\models\runner\QtiRunnerService; | ||
use oat\taoQtiTest\models\runner\QtiRunnerServiceContext; | ||
use oat\taoQtiTest\models\runner\QtiRunnerClosedException; | ||
|
@@ -453,12 +454,19 @@ public function submitItem() | |
|
||
if ($displayFeedback == true) { | ||
//FIXME there is here a performance issue, at the end we need the defitions only once, not at each storage | ||
$response['feedbacks'] = $this->runnerService->getFeedbacks($serviceContext, $itemRef); | ||
$response['feedbacks'] = $this->runnerService->getFeedbacks($serviceContext, $itemRef); | ||
$response['itemSession'] = $this->runnerService->getItemSession($serviceContext); | ||
} | ||
|
||
$this->runnerService->persist($serviceContext); | ||
|
||
} catch (QtiRunnerRequiredException $e) { | ||
// we need to restart timer | ||
$this->runnerService->startTimer($this->getServiceContext()); | ||
|
||
$response = $this->getErrorResponse($e); | ||
$code = $this->getErrorCode($e); | ||
|
||
} catch (common_Exception $e) { | ||
$response = $this->getErrorResponse($e); | ||
$code = $this->getErrorCode($e); | ||
|
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
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
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,164 @@ | ||
{ | ||
"swagger": "2.0", | ||
"info": { | ||
"version": "1.0.0", | ||
"title": "QTI Test REST API", | ||
"description": "#### The QTI Test REST API\nAn API for the QTI Test specific actions. For generic CRUD actions on tests please see the taoTest Rest API\n" | ||
}, | ||
"schemes": [ | ||
"https", | ||
"http" | ||
], | ||
"produces": [ | ||
"application/json" | ||
], | ||
"basePath": "/", | ||
"tags": [ | ||
{ | ||
"name": "test", | ||
"description": "Operations about tests" | ||
} | ||
], | ||
"paths": { | ||
"/taoQtiTest/RestQtiTests/import": { | ||
"post": { | ||
"description": "Import a QTI test package into the TAO platform.\n\nAvailable since Tao 3.1.\n", | ||
"tags": [ | ||
"test" | ||
], | ||
"responses": { | ||
"200": { | ||
"description": "Request was correctly handled, tests were imported", | ||
"schema": { | ||
"title": "response", | ||
"format": "json", | ||
"type": "object", | ||
"required": [ | ||
"success", | ||
"version", | ||
"data" | ||
], | ||
"properties": { | ||
"success": { | ||
"type": "boolean", | ||
"description": "True on success" | ||
}, | ||
"version": { | ||
"type": "string", | ||
"description": "Tao version" | ||
}, | ||
"data": { | ||
"$ref": "#/definitions/data" | ||
} | ||
} | ||
}, | ||
"examples": { | ||
"application/json": { | ||
"success": true, | ||
"data": [ | ||
{ | ||
"testId": "http://tao.local/mytao.rdf#xxxxxxxxxxxxx", | ||
"testItems": [ | ||
"http://tao.local/mytao.rdf#xxxxxxxxxxxxx", | ||
"http://tao.local/mytao.rdf#xxxxxxxxxxxxx" | ||
] | ||
} | ||
], | ||
"version": "3.1.0" | ||
} | ||
} | ||
}, | ||
"400": { | ||
"description": "Missing or invalid QTI test package", | ||
"examples": { | ||
"application/json": { | ||
"success": false, | ||
"errorCode": 0, | ||
"errorMsg": "At least one mandatory parameter was required but found missing in your request", | ||
"version": "3.1.0" | ||
} | ||
}, | ||
"schema": { | ||
"$ref": "#/definitions/errorModel" | ||
} | ||
}, | ||
"401": { | ||
"description": "You are not authorized to access this functionality" | ||
}, | ||
"500": { | ||
"description": "Internal error (should not occur)" | ||
} | ||
}, | ||
"parameters": [ | ||
{ | ||
"name": "qtiPackage", | ||
"in": "formData", | ||
"description": "A QTI 2.1 package", | ||
"type": "file", | ||
"required": true | ||
} | ||
] | ||
} | ||
} | ||
}, | ||
"definitions": { | ||
"errorModel": { | ||
"type": "object", | ||
"description": "contain error", | ||
"required": [ | ||
"success", | ||
"version", | ||
"errorCode", | ||
"errorMsg" | ||
], | ||
"properties": { | ||
"success": { | ||
"type": "boolean", | ||
"description": "False on failure", | ||
"default": false | ||
}, | ||
"version": { | ||
"type": "string", | ||
"description": "Tao version" | ||
}, | ||
"errorCode": { | ||
"type": "integer", | ||
"description": "Error code" | ||
}, | ||
"errorMsg": { | ||
"type": "string", | ||
"description": "Error description" | ||
} | ||
} | ||
}, | ||
"data": { | ||
"description": "output user data", | ||
"type": "array", | ||
"items": { | ||
"$ref": "#/definitions/test" | ||
} | ||
}, | ||
"test": { | ||
"type": "object", | ||
"required": [ | ||
"testId", | ||
"testItems" | ||
], | ||
"properties": { | ||
"testId": { | ||
"type": "string" | ||
}, | ||
"testItems": { | ||
"type": "array", | ||
"items": { | ||
"type": "string" | ||
} | ||
} | ||
} | ||
} | ||
}, | ||
"externalDocs": { | ||
"description": "taoQtiTest on Github", | ||
"url": "https://github.com/oat-sa/extension-tao-testqti" | ||
} | ||
} |
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 |
---|---|---|
|
@@ -20,9 +20,10 @@ | |
*/ | ||
|
||
use oat\taoQtiItem\helpers\QtiFile; | ||
|
||
use qtism\data\storage\FileResolver; | ||
use qtism\common\ResolutionException; | ||
use qtism\common\Resolver; | ||
use oat\taoQtiItem\model\qti\Service; | ||
use oat\generis\model\OntologyAwareTrait; | ||
|
||
/** | ||
* The ItemResolver class implements the logic to resolve TAO Item URIs to | ||
|
@@ -31,8 +32,18 @@ | |
* @author Jérôme Bogaerts <[email protected]> | ||
* | ||
*/ | ||
class taoQtiTest_helpers_ItemResolver extends FileResolver { | ||
class taoQtiTest_helpers_ItemResolver implements Resolver { | ||
|
||
use OntologyAwareTrait; | ||
|
||
/** | ||
* @var Service | ||
*/ | ||
private $service; | ||
|
||
public function __construct(Service $itemService) { | ||
$this->service = $itemService; | ||
} | ||
/** | ||
* Resolve the given TAO Item URI in the path to | ||
* the related QTI-XML file. | ||
|
@@ -54,9 +65,8 @@ public function resolve($url) { | |
// where it is supposed to be located. | ||
|
||
// strip xinclude, we don't need that at the moment. | ||
$file = QtiFile::getQtiFilePath(new core_kernel_classes_Resource($url)); | ||
$raw = $this->service->getXmlByRdfItem($this->getResource($url)); | ||
$tmpfile = sys_get_temp_dir() . '/' . md5($url) . '.xml'; | ||
$raw = file_get_contents($file); | ||
$raw = preg_replace("/<xi:include(?:.*)>/u", '', $raw); | ||
|
||
file_put_contents($tmpfile, $raw); | ||
|
Oops, something went wrong.