Skip to content

Commit

Permalink
chore: merged develop to feat/REL-1723/update-flysystem
Browse files Browse the repository at this point in the history
  • Loading branch information
augustas committed Oct 15, 2024
2 parents fe80c4d + e8dcffb commit 946878d
Show file tree
Hide file tree
Showing 19 changed files with 237 additions and 91 deletions.
104 changes: 78 additions & 26 deletions actions/class.RestQtiTests.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,11 +35,20 @@
class taoQtiTest_actions_RestQtiTests extends AbstractRestQti
{
public const PARAM_PACKAGE_NAME = 'qtiPackage';

private const PARAM_TEST_URI = 'testUri';

private const ITEM_CLASS_URI = 'itemClassUri';

/**
* @deprecated Use taoQtiTest_actions_RestQtiTests::OVERWRITE_TEST_URI instead with the URI of the test to be
* replaced
*/
private const OVERWRITE_TEST = 'overwriteTest';

private const OVERWRITE_TEST_URI = 'overwriteTestUri';
private const PACKAGE_LABEL = 'packageLabel';

/**
* @throws common_exception_NotImplemented
*/
Expand Down Expand Up @@ -99,7 +108,9 @@ public function import()
$this->isItemMustExistEnabled(),
$this->isItemMustBeOverwrittenEnabled(),
$this->isOverwriteTest(),
$this->getItemClassUri()
$this->getItemClassUri(),
$this->getOverwriteTestUri(),
$this->getPackageLabel()
);

if ($report->getType() === common_report_Report::TYPE_SUCCESS) {
Expand All @@ -117,16 +128,26 @@ public function import()
}
return $this->returnSuccess($data);
} else {
throw new \common_exception_RestApi($report->getMessage());
throw new common_exception_RestApi($report->getMessage());
}
} catch (\common_exception_RestApi $e) {
} catch (common_exception_RestApi $e) {
return $this->returnFailure($e);
}
}

protected function getItemClassUri(): ?string
/**
* @throws common_exception_RestApi
*/
protected function getItemClassUri(): string
{
return $this->getPostParameter(self::ITEM_CLASS_URI);
$itemClassUri = $this->getPostParameter(self::ITEM_CLASS_URI, TaoOntology::CLASS_URI_ITEM);
$itemClass = $this->getClass($itemClassUri);

if (!$itemClass->exists()) {
throw new common_exception_RestApi('Class does not exist. Please use valid ' . self::ITEM_CLASS_URI);
}

return $itemClassUri;
}

/**
Expand All @@ -141,7 +162,7 @@ protected function isOverwriteTest(): bool
}

if (!in_array($isOverwriteTest, ['true', 'false'])) {
throw new \common_exception_RestApi(
throw new common_exception_RestApi(
'isOverwriteTest parameter should be boolean (true or false).'
);
}
Expand Down Expand Up @@ -176,7 +197,9 @@ public function importDeferred()
$this->isItemMustExistEnabled(),
$this->isItemMustBeOverwrittenEnabled(),
$this->isOverwriteTest(),
$this->getItemClassUri()
$this->getItemClassUri(),
$this->getOverwriteTestUri(),
$this->getPackageLabel()
);

$result = [
Expand All @@ -191,7 +214,7 @@ public function importDeferred()
}

return $this->returnSuccess($result);
} catch (\common_exception_RestApi $e) {
} catch (common_exception_RestApi $e) {
return $this->returnFailure($e);
}
}
Expand Down Expand Up @@ -254,27 +277,22 @@ protected function addExtraReturnData(EntityInterface $taskLogEntity)
* If parent class parameter is an uri of valid test class, new class will be created under it
* If not parent class parameter is provided, class will be created under root class
* Comment parameter is not mandatory, used to describe new created class
*
* @return \core_kernel_classes_Class
*/
public function createClass()
public function createClass(): void
{
try {
$class = $this->createSubClass(new \core_kernel_classes_Class(TaoOntology::CLASS_URI_TEST));
$class = $this->createSubClass(new core_kernel_classes_Class(TaoOntology::CLASS_URI_TEST));

$result = [
$this->returnSuccess([
'message' => __('Class successfully created.'),
'class-uri' => $class->getUri(),
];

$this->returnSuccess($result);
} catch (\common_exception_ClassAlreadyExists $e) {
$result = [
]);
} catch (common_exception_ClassAlreadyExists $e) {
$this->returnSuccess([
'message' => $e->getMessage(),
'class-uri' => $e->getClass()->getUri(),
];
$this->returnSuccess($result);
} catch (\Exception $e) {
]);
} catch (Exception $e) {
$this->returnFailure($e);
}
}
Expand All @@ -295,20 +313,54 @@ private function getUploadedPackageData()
$mimeType = tao_helpers_File::getMimeType($fileData['tmp_name']);

if (!in_array($mimeType, self::$accepted_types)) {
throw new \common_exception_RestApi(__('Wrong file mime type'));
throw new common_exception_RestApi(__('Wrong file mime type'));
}

return $fileData;
}

/**
* @return string|null
* @throws common_exception_RestApi
*/
private function getOverwriteTestUri(): ?string
{
$overwriteTestUri = $this->getPostParameter(self::OVERWRITE_TEST_URI);

if ($overwriteTestUri !== null && !is_string($overwriteTestUri)) {
throw new common_exception_RestApi(
sprintf('%s parameter should be string', self::OVERWRITE_TEST_URI)
);
}

return $overwriteTestUri;
}

/**
* @return string|null
* @throws common_exception_RestApi
*/
private function getPackageLabel(): ?string
{
$packageLabel = $this->getPostParameter(self::PACKAGE_LABEL);

if ($packageLabel !== null && !is_string($packageLabel)) {
throw new common_exception_RestApi(
sprintf('%s parameter should be string', self::PACKAGE_LABEL)
);
}

return $packageLabel;
}

/**
* Get class instance to import test
* @throws \common_exception_RestApi
* @return \core_kernel_classes_Class
*
* @throws common_exception_RestApi
*/
private function getTestClass()
private function getTestClass(): core_kernel_classes_Class
{
return $this->getClassFromRequest(new \core_kernel_classes_Class(TaoOntology::CLASS_URI_TEST));
return $this->getClassFromRequest(new core_kernel_classes_Class(TaoOntology::CLASS_URI_TEST));
}

/**
Expand Down
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@
"oat-sa/oatbox-extension-installer": "~1.1||dev-master",
"qtism/qtism": ">=0.28.3",
"oat-sa/generis": "dev-feat/REL-1723/update-flysystem-lib",
"oat-sa/tao-core": ">=54.14.7",
"oat-sa/tao-core": ">=54.21.0",
"oat-sa/extension-tao-item" : ">=12.1.0",
"oat-sa/extension-tao-itemqti" : ">=30.12.0",
"oat-sa/extension-tao-test" : ">=16.0.0",
Expand Down
32 changes: 30 additions & 2 deletions doc/swagger.json
Original file line number Diff line number Diff line change
Expand Up @@ -214,7 +214,21 @@
{
"name": "overwriteTest",
"in": "formData",
"description": "Flag that indicates if already existed tests and all related items are removed in a case they have the same title and class as uploaded tests. Can be used to replace existing test and avoid creating a new one with the same title and class. 'true' value counts as true, 'false' as false",
"description": "Deprecated: use `overwriteTestUri` parameter with the URI of the test to be replaced. Flag that indicates if already existed tests and all related items are removed in a case they have the same title and class as uploaded tests. Can be used to replace existing test and avoid creating a new one with the same title and class. 'true' value counts as true, 'false' as false",
"type": "string",
"required": false
},
{
"name": "overwriteTestUri",
"in": "formData",
"description": "Test URI, that can be used to replace existing test and avoid creating a new one with the same title and class",
"type": "string",
"required": false
},
{
"name": "packageLabel",
"in": "formData",
"description": "Label for items folder and test label, which will be used instead of QTI test title",
"type": "string",
"required": false
},
Expand Down Expand Up @@ -353,7 +367,21 @@
{
"name": "overwriteTest",
"in": "formData",
"description": "Flag that indicates if already existed tests and all related items are removed in a case they have the same title and class as uploaded tests. Can be used to replace existing test and avoid creating a new one with the same title and class. 'true' value counts as true, 'false' as false",
"description": "Deprecated: use `overwriteTestUri` parameter with the URI of the test to be replaced. Flag that indicates if already existed tests and all related items are removed in a case they have the same title and class as uploaded tests. Can be used to replace existing test and avoid creating a new one with the same title and class. 'true' value counts as true, 'false' as false",
"type": "string",
"required": false
},
{
"name": "overwriteTestUri",
"in": "formData",
"description": "Test URI, that can be used to replace existing test and avoid creating a new one with the same title and class",
"type": "string",
"required": false
},
{
"name": "packageLabel",
"in": "formData",
"description": "Label for items folder and test label, which will be used instead of QTI test title",
"type": "string",
"required": false
},
Expand Down
1 change: 1 addition & 0 deletions manifest.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
<?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
Expand Down
9 changes: 8 additions & 1 deletion models/classes/QtiCategoryPresetProvider.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) 2017 (original work) Open Assessment Technologies SA;
* Copyright (c) 2024 (original work) Open Assessment Technologies SA;
*/

namespace oat\taoQtiTest\models;
Expand Down Expand Up @@ -216,6 +216,13 @@ public function registerPresets(TestCategoryPresetProvider $presetService)
'order' => 700,
'pluginId' => 'zoom'
]),
TestCategoryPreset::fromArray([
'id' => 'printable',
'label' => __('Print Out'),
'qtiCategory' => 'x-tao-printable',
'description' => __('Allow a Test Taker to print out the item.'),
'order' => 700,
]),
TestCategoryPreset::fromArray([
'id' => 'apiptts',
'label' => __('APIP Text To Speech'),
Expand Down
37 changes: 35 additions & 2 deletions models/classes/class.CrudQtiTestsService.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
*
*/

use oat\oatbox\log\LoggerAwareTrait;
use oat\tao\model\TaoOntology;

/**
Expand All @@ -32,6 +33,8 @@
*/
class taoQtiTest_models_classes_CrudQtiTestsService extends tao_models_classes_CrudService
{
use LoggerAwareTrait;

/** (non-PHPdoc)
* @see tao_models_classes_CrudSservice::getClassService()
*/
Expand Down Expand Up @@ -67,7 +70,9 @@ public function importQtiTest(
$itemMustExist = false,
$itemMustBeOverwritten = false,
bool $overwriteTest = false,
?string $itemClassUri = null
?string $itemClassUri = null,
?string $overwriteTestUri = null,
?string $packageLabel = null
) {
try {
//The zip extraction is a long process that can exceed the 30s timeout
Expand All @@ -91,11 +96,39 @@ public function importQtiTest(
$importer->enableItemMustBeOverwritten();
}

$report = $importer->importMultipleTests($class, $uploadedFile, $overwriteTest, $itemClassUri);
$report = $importer->importMultipleTests(
$class,
$uploadedFile,
$overwriteTest,
$itemClassUri,
[],
$overwriteTestUri,
$packageLabel
);
helpers_TimeOutHelper::reset();

return $report;
} catch (common_exception_UserReadableException $e) {
$this->logException($e);

return new common_report_Report(common_report_Report::TYPE_ERROR, __($e->getUserMessage()));
} catch (Throwable $exception) {
$this->logException($exception);

return new common_report_Report(common_report_Report::TYPE_ERROR, __('QTI test import failed'));
}
}

private function logException(Throwable $exception): void
{
$this->logError(
sprintf(
'QTI test import failed: %s. File: %s, Line: %s. Stack trace: %s',
$exception->getMessage(),
$exception->getFile(),
$exception->getLine(),
$exception->getTraceAsString()
)
);
}
}
Loading

0 comments on commit 946878d

Please sign in to comment.