Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
0.00% |
0 / 43 |
|
0.00% |
0 / 7 |
CRAP | |
0.00% |
0 / 1 |
| PrepareDataService | |
0.00% |
0 / 43 |
|
0.00% |
0 / 7 |
156 | |
0.00% |
0 / 1 |
| getResourceSyncData | |
0.00% |
0 / 28 |
|
0.00% |
0 / 1 |
12 | |||
| getItemMetaData | |
0.00% |
0 / 6 |
|
0.00% |
0 / 1 |
6 | |||
| getTestUri | |
0.00% |
0 / 3 |
|
0.00% |
0 / 1 |
6 | |||
| getMetaDataCompiler | |
0.00% |
0 / 3 |
|
0.00% |
0 / 1 |
6 | |||
| getJsonMetadataCompiler | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
| getResourceJsonMetadataCompiler | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
| getFeatureFlagChecker | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
| 1 | <?php |
| 2 | |
| 3 | /** |
| 4 | * This program is free software; you can redistribute it and/or |
| 5 | * modify it under the terms of the GNU General Public License |
| 6 | * as published by the Free Software Foundation; under version 2 |
| 7 | * of the License (non-upgradable). |
| 8 | * |
| 9 | * This program is distributed in the hope that it will be useful, |
| 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 12 | * GNU General Public License for more details. |
| 13 | * |
| 14 | * You should have received a copy of the GNU General Public License |
| 15 | * along with this program; if not, write to the Free Software |
| 16 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. |
| 17 | * |
| 18 | * Copyright (c) 2024 (original work) Open Assessment Technologies SA; |
| 19 | */ |
| 20 | |
| 21 | declare(strict_types=1); |
| 22 | |
| 23 | namespace oat\taoDeliveryRdf\model\DataStore; |
| 24 | |
| 25 | use core_kernel_classes_Resource; |
| 26 | use core_kernel_persistence_Exception; |
| 27 | use oat\generis\model\OntologyAwareTrait; |
| 28 | use oat\oatbox\service\ConfigurableService; |
| 29 | use oat\tao\model\featureFlag\FeatureFlagChecker; |
| 30 | use oat\tao\model\featureFlag\FeatureFlagCheckerInterface; |
| 31 | use oat\tao\model\metadata\compiler\AdvancedJsonResourceMetadataCompiler; |
| 32 | use oat\tao\model\metadata\compiler\ResourceJsonMetadataCompiler; |
| 33 | use oat\tao\model\metadata\compiler\ResourceMetadataCompilerInterface; |
| 34 | use oat\taoDeliveryRdf\model\DeliveryAssemblyService; |
| 35 | use taoQtiTest_models_classes_QtiTestService; |
| 36 | |
| 37 | class PrepareDataService extends ConfigurableService |
| 38 | { |
| 39 | use OntologyAwareTrait; |
| 40 | |
| 41 | public function getResourceSyncData( |
| 42 | string $resourceId, |
| 43 | int $maxTries, |
| 44 | bool $includeDeliveryMetaData, |
| 45 | string $fileSystemId, |
| 46 | bool $isDelete = false, |
| 47 | ?string $firstTenantId = null |
| 48 | ): ResourceSyncDTO { |
| 49 | $compiler = $this->getMetaDataCompiler(); |
| 50 | $testUri = $resourceId; |
| 51 | $deliveryMetaData = []; |
| 52 | $testMetaData = []; |
| 53 | $itemMetaData = []; |
| 54 | $tenantId = null; |
| 55 | |
| 56 | if (!$isDelete) { |
| 57 | if ($includeDeliveryMetaData) { |
| 58 | $deliveryResource = $this->getResource($resourceId); |
| 59 | $deliveryMetaData = $this->getResourceJsonMetadataCompiler()->compile($deliveryResource); |
| 60 | $tenantId = $deliveryMetaData['tenant-id'] ?? null; |
| 61 | $testUri = $this->getTestUri($deliveryResource); |
| 62 | } |
| 63 | |
| 64 | $test = $this->getResource($testUri); |
| 65 | $testMetaData = $compiler->compile($test); |
| 66 | $testMetaData['first-tenant-id'] = $firstTenantId; |
| 67 | |
| 68 | $itemMetaData = $this->getItemMetaData($test, $compiler); |
| 69 | } |
| 70 | |
| 71 | return new ResourceSyncDTO( |
| 72 | $resourceId, |
| 73 | $fileSystemId, |
| 74 | $testUri, |
| 75 | $isDelete, |
| 76 | $tenantId, |
| 77 | $firstTenantId, |
| 78 | $maxTries, |
| 79 | $deliveryMetaData, |
| 80 | $testMetaData, |
| 81 | $itemMetaData |
| 82 | ); |
| 83 | } |
| 84 | |
| 85 | private function getItemMetaData( |
| 86 | core_kernel_classes_Resource $test, |
| 87 | ResourceMetadataCompilerInterface $compiler |
| 88 | ): array { |
| 89 | /** @var taoQtiTest_models_classes_QtiTestService $testService */ |
| 90 | $testService = $this->getServiceLocator()->get(taoQtiTest_models_classes_QtiTestService::class); |
| 91 | $items = $testService->getItems($test); |
| 92 | $itemMetaData = []; |
| 93 | foreach ($items as $item) { |
| 94 | $itemMetaData[] = $compiler->compile($item); |
| 95 | } |
| 96 | |
| 97 | return $itemMetaData; |
| 98 | } |
| 99 | |
| 100 | /** |
| 101 | * @throws core_kernel_persistence_Exception |
| 102 | */ |
| 103 | private function getTestUri(core_kernel_classes_Resource $deliveryResource): ?string |
| 104 | { |
| 105 | $testProperty = $this->getProperty(DeliveryAssemblyService::PROPERTY_ORIGIN); |
| 106 | $test = $deliveryResource->getOnePropertyValue($testProperty); |
| 107 | |
| 108 | return $test ? $test->getUri() : null; |
| 109 | } |
| 110 | |
| 111 | private function getMetaDataCompiler(): ResourceMetadataCompilerInterface |
| 112 | { |
| 113 | return $this->getFeatureFlagChecker()->isEnabled('FEATURE_FLAG_DATA_STORE_METADATA_V2') |
| 114 | ? $this->getJsonMetadataCompiler() |
| 115 | : $this->getResourceJsonMetadataCompiler(); |
| 116 | } |
| 117 | |
| 118 | private function getJsonMetadataCompiler(): ResourceMetadataCompilerInterface |
| 119 | { |
| 120 | return $this->getServiceManager()->getContainer()->get(AdvancedJsonResourceMetadataCompiler::class); |
| 121 | } |
| 122 | |
| 123 | private function getResourceJsonMetadataCompiler(): ResourceMetadataCompilerInterface |
| 124 | { |
| 125 | return $this->getServiceManager()->getContainer()->get(ResourceJsonMetadataCompiler::SERVICE_ID); |
| 126 | } |
| 127 | |
| 128 | private function getFeatureFlagChecker(): FeatureFlagCheckerInterface |
| 129 | { |
| 130 | return $this->getServiceManager()->getContainer()->get(FeatureFlagChecker::class); |
| 131 | } |
| 132 | } |