Skip to content

Commit

Permalink
feat: Merge branch 'feat/aut-3590/add-metadata-check-on-import' into …
Browse files Browse the repository at this point in the history
…feat/AUT-3590/inject-metadata-into-resources
  • Loading branch information
bartlomiejmarszal committed Apr 16, 2024
2 parents 3e30b13 + 0bc78b6 commit 2ac9845
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 3 deletions.
17 changes: 15 additions & 2 deletions models/classes/class.QtiTestService.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,13 +29,14 @@
use oat\taoItems\model\Command\DeleteItemCommand;
use oat\taoQtiItem\model\qti\ImportService;
use oat\taoQtiItem\model\qti\metadata\importer\MetadataImporter;
use oat\taoQtiItem\model\qti\metadata\imsManifest\MetaMetadataExtractor;
use oat\taoQtiItem\model\qti\metadata\importer\MetaMetadataImportMapper;
use oat\taoQtiItem\model\qti\metadata\importer\PropertyDoesNotExistException;
use oat\taoQtiItem\model\qti\metadata\imsManifest\MetaMetadataExtractor;
use oat\taoQtiItem\model\qti\metadata\imsManifest\MetaMetadataValidator;
use oat\taoQtiItem\model\qti\metadata\MetadataGuardianResource;
use oat\taoQtiItem\model\qti\metadata\MetadataService;
use oat\taoQtiItem\model\qti\metadata\ontology\MappedMetadataInjector;
use oat\taoQtiItem\model\qti\metaMetadata\MetaMetadataService;
use oat\taoQtiItem\model\qti\metaMetadata\imsManifest\MetaMetadataException;
use oat\taoQtiItem\model\qti\Resource;
use oat\taoQtiItem\model\qti\Service;
use oat\taoQtiTest\models\cat\AdaptiveSectionInjectionException;
Expand All @@ -45,6 +46,7 @@
use oat\taoQtiTest\models\render\QtiPackageImportPreprocessing;
use oat\taoQtiTest\models\test\AssessmentTestXmlFactory;
use oat\taoTests\models\event\TestUpdatedEvent;
use PHP_CodeSniffer\Reporter;
use Psr\Container\ContainerInterface;
use qtism\common\utils\Format;
use qtism\data\AssessmentItemRef;
Expand Down Expand Up @@ -613,6 +615,7 @@ protected function importTest(
$testDefinition = new XmlDocument();

try {
$this->getMetaMetadataValidator()->validateClass($testClass, $metaMetadataValues);
$testDefinition->load($expectedTestFile, true);

// If any, assessmentSectionRefs will be resolved and included as part of the main test definition.
Expand Down Expand Up @@ -872,6 +875,11 @@ protected function importTest(
// phpcs:enable Generic.Files.LineLength
)
);
} catch (MetaMetadataException $e) {
$report = Reporter::createError(
sprintf('Import failed at validating metametadata with message: "%s"', $e->getMessage())
);
common_Logger::e($e->getMessage());
}
}

Expand Down Expand Up @@ -1521,4 +1529,9 @@ private function getMetaMetadataImporter(): MetaMetadataImportMapper
{
return $this->getServiceManager()->getContainer()->get(MetaMetadataImportMapper::class);
}

protected function getMetaMetadataValidator(): MetaMetadataValidator
{
return $this->getServiceManager()->getContainer()->get(MetaMetadataValidator::class);
}
}
2 changes: 1 addition & 1 deletion models/classes/metadata/ChecksumGenerator.php
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ public function getRangeChecksum(Property $property): string
}
asort($labels);
$checksum = implode('', $labels);
common_Logger::e(sprintf('ChecksumGenerator resource before sha1 : "%s"', $checksum));

return sha1(trim($checksum));
}
}

0 comments on commit 2ac9845

Please sign in to comment.