Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactor/change tmp location to state storage #450

Open
wants to merge 10 commits into
base: develop
Choose a base branch
from
53 changes: 47 additions & 6 deletions actions/class.TestRunner.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
* 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) 2013 (original work) Open Assessment Technologies SA (under the project TAO-PRODUCT);
* Copyright (c) 2013-2016 (original work) Open Assessment Technologies SA (under the project TAO-PRODUCT);
*
*
*/
Expand All @@ -29,12 +29,15 @@
use qtism\common\enums\BaseType;
use qtism\common\enums\Cardinality;
use qtism\common\datatypes\String as QtismString;
use qtism\common\datatypes\files\FileManager;
use qtism\runtime\storage\binary\BinaryAssessmentTestSeeker;
use qtism\runtime\storage\common\AbstractStorage;
use qtism\data\SubmissionMode;
use qtism\data\NavigationMode;
use oat\taoQtiItem\helpers\QtiRunner;
use oat\taoQtiTest\models\TestSessionMetaData;
use oat\taoQtiTest\models\StateStorageQtiFileManager;

/**
* Runs a QTI Test.
*
Expand Down Expand Up @@ -73,6 +76,13 @@ class taoQtiTest_actions_TestRunner extends tao_actions_ServiceModule {
* @var AbstractStorage
*/
private $storage = null;

/**
* The service state storage of storage engine.
*
* @var FileManager
*/
private $serviceStateStorage = null;

/**
* The error that occured during the current request.
Expand Down Expand Up @@ -221,6 +231,23 @@ protected function getTestMeta() {
return $this->testMeta;
}

/**
* Return the State storage
* @return StateStorageQtiFileManager
* @throws common_exception_Error
*/
protected function getStateStorageQtiFileManager()
{
if (!$this->serviceStateStorage) {
$this->serviceStateStorage = new StateStorageQtiFileManager(
$this->getServiceCallId(),
\common_session_SessionManager::getSession()->getUserUri()
);
$this->serviceStateStorage->setServiceLocator($this->getServiceManager());
}
return $this->serviceStateStorage;
}

/**
* Print an error report into the response.
* After you have called this method, you must prevent other actions to be processed and must close the response.
Expand Down Expand Up @@ -257,12 +284,15 @@ protected function beforeAction($notifyError = true) {

// Initialize storage and test session.
$testResource = new core_kernel_classes_Resource($this->getRequestParameter('QtiTestDefinition'));

$sessionManager = new taoQtiTest_helpers_SessionManager($resultServer, $testResource);
$userUri = common_session_SessionManager::getSession()->getUserUri();
$seeker = new BinaryAssessmentTestSeeker($this->getTestDefinition());

$this->setStorage(new taoQtiTest_helpers_TestSessionStorage($sessionManager, $seeker, $userUri));

$storage = new taoQtiTest_helpers_TestSessionStorage($sessionManager, $seeker, $userUri);

$storage->setFileManager($this->getStateStorageQtiFileManager());
$this->setStorage($storage);
$this->retrieveTestSession();

// @TODO: use some storage to get the potential reason of the state (close/suspended)
Expand Down Expand Up @@ -340,7 +370,7 @@ protected function afterAction($withContext = true) {
}

common_Logger::i("Persisting QTI Assessment Test Session '${sessionId}'...");
$this->getStorage()->persist($testSession);
$this->getStorage()->persist($testSession);
}

/**
Expand Down Expand Up @@ -713,6 +743,7 @@ public function storeItemVariableSet()
}

$filler = new taoQtiCommon_helpers_PciVariableFiller($currentItem);
$filler->setFileManager($this->getStateStorageQtiFileManager());

if (is_array($jsonPayload)) {
foreach ($jsonPayload as $id => $response) {
Expand Down Expand Up @@ -860,6 +891,16 @@ protected function handleAssessmentTestSessionException(AssessmentTestSessionExc
case AssessmentTestSessionException::ASSESSMENT_ITEM_DURATION_OVERFLOW:
$this->onTimeout($e);
break;
default:
$msg = "An unexpected error occured in the QTI Test Runner: \n";
while ($e) {
$msg .= $e->getMessage();
if (($e = $e->getPrevious()) !== null) {
$msg .= "\nCaused by:\n";
}
}
common_Logger::e($msg);
break;
}
}
}
}
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@
},
"minimum-stability": "dev",
"require": {
"oat-sa/lib-tao-qti": "dev-master",
"oat-sa/lib-tao-qti": "dev-refactor/qtism-dependencies-to-feature-branch",
"oat-sa/oatbox-extension-installer": "dev-master"
},
"autoload": {
Expand Down
39 changes: 34 additions & 5 deletions helpers/class.TestSessionStorage.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,8 @@
use qtism\runtime\storage\common\StorageException;
use qtism\data\AssessmentTest;
use qtism\runtime\tests\AssessmentTestSession;
use qtism\runtime\storage\binary\QtiBinaryStreamAccessFsFile;
use qtism\runtime\storage\binary\QtiBinaryStreamAccess;
use qtism\common\datatypes\files\FileManager;

/**
* A QtiSm AssessmentTestSession Storage Service implementation for TAO.
Expand All @@ -52,7 +53,13 @@ class taoQtiTest_helpers_TestSessionStorage extends AbstractQtiBinaryStorage {
* @var string
*/
private $userUri;


/**
* File manager to pass to QtiBinaryStreamAccess
* @var FileManager
*/
protected $fileManager;

/**
* Create a new TestSessionStorage object.
*
Expand Down Expand Up @@ -159,8 +166,30 @@ public function exists($sessionId) {

return $storageService->has($userUri, $sessionId);
}

protected function createBinaryStreamAccess(IStream $stream) {
return new QtiBinaryStreamAccessFsFile($stream);

/**
* @throws StorageException
* @return FileManager
*/
public function getFileManager()
{
if (!isset($this->fileManager)) {
throw new StorageException('Missing file manager for test session storage.', StorageException::UNKNOWN);
}
return $this->fileManager;
}

/**
* @param FileManager $fileManager
*/
public function setFileManager(FileManager $fileManager)
{
$this->fileManager = $fileManager;
}


protected function createBinaryStreamAccess(IStream $stream)
{
return new QtiBinaryStreamAccess($stream, $this->getFileManager());
}
}
Loading