Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: unique identifiers #2607

Merged
merged 3 commits into from
Nov 6, 2024
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions manifest.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
use oat\taoQtiItem\model\FeatureFlag\ServiceProvider\FeatureFlagQtiIdentifierServiceProvider;
// phpcs:ignore Generic.Files.LineLength
use oat\taoQtiItem\model\qti\CustomInteractionAsset\ServiceProvider\CustomInteractionAssetExtractorAllocatorServiceProvider;
use oat\taoQtiItem\model\qti\Identifier\ServiceProvider\QtiIdentifierServiceProvider;
use oat\taoQtiItem\model\qti\metadata\importer\MetaMetadataServiceProvider;
use oat\taoQtiItem\model\qti\ServiceProvider\IdentifierGenerationStrategyServiceProvider;
use oat\taoQtiItem\model\qti\ServiceProvider\ItemIdentifierValidatorServiceProvider;
Expand Down Expand Up @@ -212,5 +213,6 @@
FeatureFlagQtiIdentifierServiceProvider::class,
UniqueIdServiceProvider::class,
TranslationServiceProvider::class,
QtiIdentifierServiceProvider::class,
],
];
21 changes: 20 additions & 1 deletion model/Translation/ServiceProvider/TranslationServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,12 +28,14 @@
use oat\tao\model\TaoOntology;
use oat\tao\model\Translation\Service\ResourceLanguageRetriever;
use oat\tao\model\Translation\Service\TranslationCreationService;
use oat\tao\model\Translation\Service\TranslationUniqueIdSetter;
use oat\taoQtiItem\model\qti\Identifier\Service\QtiIdentifierSetter;
use oat\taoQtiItem\model\qti\Service;
use oat\taoQtiItem\model\Translation\Service\QtiLanguageRetriever;
use oat\taoQtiItem\model\Translation\Service\QtiLanguageSetter;
use Symfony\Component\DependencyInjection\Loader\Configurator\ContainerConfigurator;

use tao_models_classes_LanguageService;

use function Symfony\Component\DependencyInjection\Loader\Configurator\service;

class TranslationServiceProvider implements ContainerServiceProviderInterface
Expand Down Expand Up @@ -68,6 +70,16 @@ public function __invoke(ContainerConfigurator $configurator): void
service(tao_models_classes_LanguageService::class),
]);

$services
->get(TranslationUniqueIdSetter::class)
->call(
'addQtiIdentifierSetter',
[
service(QtiIdentifierSetter::class),
TaoOntology::CLASS_URI_ITEM,
]
);

$services
->get(TranslationCreationService::class)
->call(
Expand All @@ -76,6 +88,13 @@ public function __invoke(ContainerConfigurator $configurator): void
TaoOntology::CLASS_URI_ITEM,
service(QtiLanguageSetter::class),
]
)
->call(
'addPostCreation',
[
TaoOntology::CLASS_URI_ITEM,
service(TranslationUniqueIdSetter::class),
]
);
}
}
29 changes: 9 additions & 20 deletions model/UniqueId/Listener/ItemCreationListener.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,28 +30,29 @@
use oat\tao\model\IdentifierGenerator\Generator\IdentifierGeneratorInterface;
use oat\tao\model\resources\Event\InstanceCopiedEvent;
use oat\tao\model\TaoOntology;
use oat\tao\model\Translation\Service\AbstractQtiIdentifierSetter;
use oat\taoItems\model\event\ItemCreatedEvent;
use oat\taoItems\model\event\ItemDuplicatedEvent;
use oat\taoQtiItem\model\event\ItemImported;
use oat\taoQtiItem\model\qti\Service;
use oat\taoQtiItem\model\qti\Identifier\Service\QtiIdentifierSetter;

class ItemCreationListener
{
private FeatureFlagCheckerInterface $featureFlagChecker;
private Ontology $ontology;
private IdentifierGeneratorInterface $identifierGenerator;
private Service $qtiItemService;
private QtiIdentifierSetter $qtiIdentifierSetter;

public function __construct(
FeatureFlagCheckerInterface $featureFlagChecker,
Ontology $ontology,
IdentifierGeneratorInterface $identifierGenerator,
Service $qtiItemService
QtiIdentifierSetter $qtiIdentifierSetter
) {
$this->featureFlagChecker = $featureFlagChecker;
$this->ontology = $ontology;
$this->identifierGenerator = $identifierGenerator;
$this->qtiItemService = $qtiItemService;
$this->qtiIdentifierSetter = $qtiIdentifierSetter;
}

public function populateUniqueId(Event $event): void
Expand All @@ -76,28 +77,16 @@ public function populateUniqueId(Event $event): void
return;
}

$originalResourceUriProperty = $this->ontology->getProperty(
TaoOntology::PROPERTY_TRANSLATION_ORIGINAL_RESOURCE_URI
);

if (!empty($item->getOnePropertyValue($originalResourceUriProperty))) {
return;
}

$identifier = $this->identifierGenerator->generate([IdentifierGeneratorInterface::OPTION_RESOURCE => $item]);
$item->editPropertyValues(
$this->ontology->getProperty(TaoOntology::PROPERTY_UNIQUE_IDENTIFIER),
$identifier
);

$itemData = $this->qtiItemService->getDataItemByRdfItem($item);

if (!$itemData) {
return;
}

$itemData->setAttribute('identifier', $identifier);
$this->qtiItemService->saveDataItemToRdfItem($itemData, $item);
$this->qtiIdentifierSetter->set([
AbstractQtiIdentifierSetter::OPTION_RESOURCE => $item,
AbstractQtiIdentifierSetter::OPTION_IDENTIFIER => $identifier,
]);
}

private function getEventItem(Event $event): core_kernel_classes_Resource
Expand Down
69 changes: 0 additions & 69 deletions model/UniqueId/Modifier/UniqueIdFormModifier.php

This file was deleted.

81 changes: 0 additions & 81 deletions model/UniqueId/Service/QtiIdentifierSetter.php

This file was deleted.

53 changes: 2 additions & 51 deletions model/UniqueId/ServiceProvider/UniqueIdServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,17 +24,10 @@

use oat\generis\model\data\Ontology;
use oat\generis\model\DependencyInjection\ContainerServiceProviderInterface;
use oat\oatbox\log\LoggerService;
use oat\tao\model\featureFlag\FeatureFlagChecker;
use oat\tao\model\IdentifierGenerator\Generator\IdentifierGeneratorProxy;
use oat\tao\model\TaoOntology;
use oat\tao\model\Translation\Service\TranslationCreationService;
use oat\taoItems\model\Form\Modifier\FormModifierProxy;
use oat\taoQtiItem\model\qti\Service;
use oat\taoQtiItem\model\qti\Identifier\Service\QtiIdentifierSetter;
use oat\taoQtiItem\model\UniqueId\Listener\ItemCreationListener;
use oat\taoQtiItem\model\UniqueId\Modifier\UniqueIdFormModifier;
use oat\taoQtiItem\model\UniqueId\Service\QtiIdentifierRetriever;
use oat\taoQtiItem\model\UniqueId\Service\QtiIdentifierSetter;
use Symfony\Component\DependencyInjection\Loader\Configurator\ContainerConfigurator;

use function Symfony\Component\DependencyInjection\Loader\Configurator\service;
Expand All @@ -45,56 +38,14 @@ public function __invoke(ContainerConfigurator $configurator): void
{
$services = $configurator->services();

$services
->set(QtiIdentifierRetriever::class, QtiIdentifierRetriever::class)
->args([
service(Service::class),
service(LoggerService::SERVICE_ID),
]);

$services
->set(UniqueIdFormModifier::class, UniqueIdFormModifier::class)
->args([
service(Ontology::SERVICE_ID),
service(QtiIdentifierRetriever::class),
service(FeatureFlagChecker::class),
]);

$services
->get(FormModifierProxy::class)
->call(
'addModifier',
[
service(UniqueIdFormModifier::class),
]
);

$services
->set(ItemCreationListener::class, ItemCreationListener::class)
->public()
->args([
service(FeatureFlagChecker::class),
service(Ontology::SERVICE_ID),
service(IdentifierGeneratorProxy::class),
service(Service::class),
service(QtiIdentifierSetter::class),
]);

$services
->set(QtiIdentifierSetter::class, QtiIdentifierSetter::class)
->args([
service(Service::class),
service(LoggerService::SERVICE_ID),
service(Ontology::SERVICE_ID),
]);

$services
->get(TranslationCreationService::class)
->call(
'addPostCreation',
[
TaoOntology::CLASS_URI_ITEM,
service(QtiIdentifierSetter::class),
]
);
}
}
Loading