Skip to content

Commit

Permalink
feat: Add test and units metadata to qti test sync
Browse files Browse the repository at this point in the history
  • Loading branch information
yaraslau-kavaliou committed Mar 21, 2024
1 parent 8cc0cee commit e5cc8e3
Show file tree
Hide file tree
Showing 5 changed files with 26 additions and 28 deletions.
2 changes: 1 addition & 1 deletion model/DataStore/DeliveryMetadataListener.php
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ public function whenDeliveryIsPublished(Event $event): void
$this->checkEventType($event);
$this->triggerSyncTask([
MetaDataDeliverySyncTask::DELIVERY_OR_TEST_ID_PARAM_NAME => $event->getDeliveryUri(),
MetaDataDeliverySyncTask::INCLUDE_METADATA_PARAM_NAME => true,
MetaDataDeliverySyncTask::INCLUDE_DELIVERY_METADATA_PARAM_NAME => true,
MetaDataDeliverySyncTask::MAX_TRIES_PARAM_NAME => $this->getOption('max_tries', 10),
MetaDataDeliverySyncTask::FILE_SYSTEM_ID_PARAM_NAME => self::FILE_SYSTEM_ID,
MetaDataDeliverySyncTask::IS_REMOVE_PARAM_NAME => false,
Expand Down
28 changes: 11 additions & 17 deletions model/DataStore/MetaDataDeliverySyncTask.php
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ class MetaDataDeliverySyncTask extends AbstractAction implements JsonSerializabl
{
use OntologyAwareTrait;

public const INCLUDE_METADATA_PARAM_NAME = 'includeMetadata';
public const INCLUDE_DELIVERY_METADATA_PARAM_NAME = 'includeMetadata';
public const DELIVERY_OR_TEST_ID_PARAM_NAME = 'deliveryOrTestId';
public const FILE_SYSTEM_ID_PARAM_NAME = 'fileSystemId';
public const TEST_URI_PARAM_NAME = 'testUri';
Expand All @@ -58,9 +58,7 @@ class MetaDataDeliverySyncTask extends AbstractAction implements JsonSerializabl
*/
public function __invoke($params)
{
if ($params[self::INCLUDE_METADATA_PARAM_NAME]) {
$params = $this->prepareData($params);
}
$params = $this->prepareMetaData($params);

$report = new Report(Report::TYPE_SUCCESS);

Expand Down Expand Up @@ -130,24 +128,20 @@ private function getPersistDataService(): PersistDataService
return $this->getServiceLocator()->get(PersistDataService::class);
}

/**
* @throws common_exception_Error
* @throws core_kernel_persistence_Exception
*/
private function prepareData($params)
private function prepareMetaData($params)
{
if (!isset($params['deliveryMetaData'], $params['testMetaData'], $params['testUri'], $params['itemMetaData'])) {
$compiler = $this->getMetaDataCompiler();
$compiler = $this->getMetaDataCompiler();
if ($params[self::INCLUDE_DELIVERY_METADATA_PARAM_NAME]) {
//DeliveryMetaData
$deliveryResource = $this->getResource($params[self::DELIVERY_OR_TEST_ID_PARAM_NAME]);
$params['deliveryMetaData'] = $this->getResourceJsonMetadataCompiler()->compile($deliveryResource);
//test MetaData
$test = $this->getTest($deliveryResource);
$params['testUri'] = $this->getTestUri($deliveryResource);
$params['testMetaData'] = $compiler->compile($test);
//Item MetaData
$params['itemMetaData'] = $this->getItemMetaData($test, $compiler);
$params[self::TEST_URI_PARAM_NAME] = $this->getTestUri($deliveryResource);
}
//test MetaData
$test = $this->getResource($params[self::TEST_URI_PARAM_NAME]);
$params['testMetaData'] = $compiler->compile($test);
//Item MetaData
$params['itemMetaData'] = $this->getItemMetaData($test, $compiler);

return $params;
}
Expand Down
4 changes: 1 addition & 3 deletions model/DataStore/PersistDataService.php
Original file line number Diff line number Diff line change
Expand Up @@ -133,9 +133,7 @@ private function moveExportedZipTest(string $folder, string $deliveryOrTestId, a
if (!empty($zipFiles)) {
foreach ($zipFiles as $zipFile) {
$zipFileName = $this->getZipFileName($deliveryOrTestId);
if ($params[MetaDataDeliverySyncTask::INCLUDE_METADATA_PARAM_NAME]) {
$this->getProcessDataService()->process($zipFile, $params);
}
$this->getProcessDataService()->process($zipFile, $params);

$contents = file_get_contents($zipFile);

Expand Down
18 changes: 12 additions & 6 deletions model/DataStore/ProcessDataService.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,12 @@

class ProcessDataService extends ConfigurableService
{
private const DELIVERY_META_DATA_JSON = 'deliveryMetaData.json';
private const TEST_META_DATA_JSON = 'testMetaData.json';
private const ITEM_META_DATA_JSON = 'itemMetaData.json';
private const METADATA_MAP = [
'deliveryMetaData',
'testMetaData',
'itemMetaData',
];

public const OPTION_ZIP_ARCHIVE_SERVICE = 'zipArchive';

public function process(string $zipFile, array $metaData): void
Expand All @@ -38,9 +41,12 @@ public function process(string $zipFile, array $metaData): void

$zipArchive->open($zipFile);

$this->saveMetaData($zipArchive, self::DELIVERY_META_DATA_JSON, json_encode($metaData['deliveryMetaData']));
$this->saveMetaData($zipArchive, self::TEST_META_DATA_JSON, json_encode($metaData['testMetaData']));
$this->saveMetaData($zipArchive, self::ITEM_META_DATA_JSON, json_encode($metaData['itemMetaData']));
foreach (self::METADATA_MAP as $metadataName) {
if (!empty($metaData[$metadataName])) {
$this->saveMetaData($zipArchive, $metadataName . '.json', json_encode($metaData[$metadataName]));
}

}

$zipArchive->close();
}
Expand Down
2 changes: 1 addition & 1 deletion test/unit/model/DataStore/MetaDataDeliverySyncTaskTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ public function testInvoke()
$param = [
MetaDataDeliverySyncTask::DELIVERY_OR_TEST_ID_PARAM_NAME => $mockDelivery->getUri(),
MetaDataDeliverySyncTask::MAX_TRIES_PARAM_NAME => 1,
MetaDataDeliverySyncTask::INCLUDE_METADATA_PARAM_NAME => true,
MetaDataDeliverySyncTask::INCLUDE_DELIVERY_METADATA_PARAM_NAME => true,
MetaDataDeliverySyncTask::FILE_SYSTEM_ID_PARAM_NAME => DeliveryMetadataListener::FILE_SYSTEM_ID,
MetaDataDeliverySyncTask::IS_REMOVE_PARAM_NAME => false,
'count' => 0
Expand Down

0 comments on commit e5cc8e3

Please sign in to comment.