Skip to content

Commit

Permalink
Merge pull request #2495 from oat-sa/feat/ADF-1685/store-tests-items-…
Browse files Browse the repository at this point in the history
…uris

chore: remove unnecessary parameter
  • Loading branch information
shpran authored Aug 16, 2024
2 parents 539eb5f + a52922f commit 6a70e80
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 41 deletions.
50 changes: 10 additions & 40 deletions actions/class.RestQtiTests.php
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,6 @@ class taoQtiTest_actions_RestQtiTests extends AbstractRestQti
*/
private const OVERWRITE_TEST = 'overwriteTest';

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

Expand Down Expand Up @@ -136,17 +135,16 @@ public function import()
}
}

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

if ($subclassLabel) {
foreach ($this->getClass($itemClassUri)->getSubClasses() as $subclass) {
if ($subclass->getLabel() === $subclassLabel) {
$itemClassUri = $subclass->getUri();
}
}
if (!$itemClass->exists()) {
throw new common_exception_RestApi('Class does not exist. Please use valid ' . self::ITEM_CLASS_URI);
}

return $itemClassUri;
Expand All @@ -164,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 @@ -321,23 +319,6 @@ private function getUploadedPackageData()
return $fileData;
}

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

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

return $subclassLabel;
}

/**
* @return string|null
* @throws common_exception_RestApi
Expand Down Expand Up @@ -379,18 +360,7 @@ private function getPackageLabel(): ?string
*/
private function getTestClass(): core_kernel_classes_Class
{
$testClass = $this->getClassFromRequest(new core_kernel_classes_Class(TaoOntology::CLASS_URI_TEST));
$subclassLabel = $this->getSubclassLabel();

if ($subclassLabel) {
foreach ($testClass->getSubClasses() as $subClass) {
if ($subClass->getLabel() === $subclassLabel) {
$testClass = $subClass;
}
}
}

return $testClass;
return $this->getClassFromRequest(new core_kernel_classes_Class(TaoOntology::CLASS_URI_TEST));
}

/**
Expand Down
2 changes: 1 addition & 1 deletion models/classes/tasks/ImportQtiTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ public function __invoke($params)
$params[self::PARAM_ITEM_MUST_EXIST] ?? false,
$params[self::PARAM_ITEM_MUST_BE_OVERWRITTEN] ?? false,
$params[self::PARAM_OVERWRITE_TEST] ?? false,
$params[self::PARAM_ITEM_CLASS_URI] ?? false,
$params[self::PARAM_ITEM_CLASS_URI] ?? null,
$params[self::PARAM_OVERWRITE_TEST_URI] ?? null,
$params[self::PARAM_PACKAGE_LABEL] ?? null,
);
Expand Down

0 comments on commit 6a70e80

Please sign in to comment.