Skip to content

Commit

Permalink
Merge pull request #502 from oat-sa/release-3.1.0
Browse files Browse the repository at this point in the history
Release 3.1.0
  • Loading branch information
ssipasseuth authored Jul 4, 2016
2 parents 98c031f + 13e548f commit 3d555d4
Show file tree
Hide file tree
Showing 32 changed files with 1,470 additions and 308 deletions.
73 changes: 28 additions & 45 deletions actions/class.RestQtiTests.php
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand All @@ -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();
Expand All @@ -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()));
}
}
}
Expand Down
10 changes: 9 additions & 1 deletion actions/class.Runner.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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);
Expand Down
17 changes: 12 additions & 5 deletions actions/class.TestRunner.php
Original file line number Diff line number Diff line change
Expand Up @@ -841,14 +841,21 @@ protected function retrieveTestSession() {
/**
* Retrieve the QTI Test Definition meta-data array stored
* into the private compilation directory.
*
*
* @return array
*/
protected function retrieveTestMeta() {
protected function retrieveTestMeta()
{
$directories = $this->getCompilationDirectory();
$privateDirectoryPath = $directories['private']->getPath();
$meta = include($privateDirectoryPath . TAOQTITEST_COMPILED_META_FILENAME);

/** @var tao_models_classes_service_StorageDirectory $privateDirectory */
$privateDirectory = $directories['private'];
$stream = $privateDirectory->readStream(TAOQTITEST_COMPILED_META_FILENAME);
$data = $stream->getContents();
$stream->close();

$data = str_replace('<?php', '', $data);
$data = str_replace('?>', '', $data);
$meta = eval($data);
$this->setTestMeta($meta);
}

Expand Down
5 changes: 5 additions & 0 deletions config/default/testRunner.conf.php
Original file line number Diff line number Diff line change
Expand Up @@ -254,4 +254,9 @@
'params' => []
],
],
/*
* Enable Allow/Disallow Skipping feature.
* @type boolean
*/
'enable-allow-skipping' => false
);
164 changes: 164 additions & 0 deletions doc/rest.json
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"
}
}
20 changes: 15 additions & 5 deletions helpers/class.ItemResolver.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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.
Expand All @@ -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);
Expand Down
Loading

0 comments on commit 3d555d4

Please sign in to comment.