From d87be4b6df8b7262b3ccfa7bca846a046f33871f Mon Sep 17 00:00:00 2001 From: Karol-Stelmaczonek <118974926+Karol-Stelmaczonek@users.noreply.github.com> Date: Mon, 8 Jan 2024 14:03:51 +0100 Subject: [PATCH] Bugfix/inf 248 not send ags with outcome processing set to none (#2435) * bugfix: move event to proper delivery finish * bugfix: code review fixes * fix: code check --- helpers/class.TestSession.php | 5 +- ...corded.php => DeliveryExecutionFinish.php} | 13 ++-- .../ResultTestVariablesTransmissionEvent.php | 11 +-- .../ResultTransmissionEventHandler.php | 73 ++----------------- models/classes/runner/QtiRunnerService.php | 23 ++++++ 5 files changed, 40 insertions(+), 85 deletions(-) rename models/classes/event/{TestVariablesRecorded.php => DeliveryExecutionFinish.php} (79%) diff --git a/helpers/class.TestSession.php b/helpers/class.TestSession.php index 23bf7ed26..dda38eddf 100644 --- a/helpers/class.TestSession.php +++ b/helpers/class.TestSession.php @@ -819,12 +819,11 @@ private function triggerResultTestVariablesTransmissionEvent( $this->getSessionId(), $variables, $this->getSessionId(), - $testUri, - $this->isManualScored() + $testUri )); } - private function isManualScored(): bool + public function isManualScored(): bool { /** @var AssessmentItemRef $itemRef */ foreach ($this->getRoute()->getAssessmentItemRefs() as $itemRef) { diff --git a/models/classes/event/TestVariablesRecorded.php b/models/classes/event/DeliveryExecutionFinish.php similarity index 79% rename from models/classes/event/TestVariablesRecorded.php rename to models/classes/event/DeliveryExecutionFinish.php index 6f8c39e3c..03afd7836 100644 --- a/models/classes/event/TestVariablesRecorded.php +++ b/models/classes/event/DeliveryExecutionFinish.php @@ -23,19 +23,20 @@ namespace oat\taoQtiTest\models\event; use oat\oatbox\event\Event; +use oat\taoDelivery\model\execution\DeliveryExecution; -class TestVariablesRecorded implements Event +class DeliveryExecutionFinish implements Event { - private string $deliveryExecutionId; + private DeliveryExecution $deliveryExecution; private array $variables; private bool $isManualScored; public function __construct( - string $deliveryExecutionId, + DeliveryExecution $deliveryExecution, array $variables, bool $isManualScored ) { - $this->deliveryExecutionId = $deliveryExecutionId; + $this->deliveryExecution = $deliveryExecution; $this->variables = $variables; $this->isManualScored = $isManualScored; } @@ -45,9 +46,9 @@ public function getName(): string return self::class; } - public function getDeliveryExecutionId(): string + public function getDeliveryExecution(): DeliveryExecution { - return $this->deliveryExecutionId; + return $this->deliveryExecution; } public function getVariables(): array diff --git a/models/classes/event/ResultTestVariablesTransmissionEvent.php b/models/classes/event/ResultTestVariablesTransmissionEvent.php index 51ba39b1a..315f98d34 100644 --- a/models/classes/event/ResultTestVariablesTransmissionEvent.php +++ b/models/classes/event/ResultTestVariablesTransmissionEvent.php @@ -34,21 +34,17 @@ class ResultTestVariablesTransmissionEvent implements Event private $transmissionId; /** @var string */ private $testUri; - /** @var bool */ - private bool $isManualScored; public function __construct( string $deliveryExecutionId, array $variables, string $transmissionId, - string $testUri = '', - bool $isManualScored = null, + string $testUri = '' ) { $this->deliveryExecutionId = $deliveryExecutionId; $this->variables = $variables; $this->transmissionId = $transmissionId; $this->testUri = $testUri; - $this->isManualScored = $isManualScored; } public function getName(): string @@ -75,9 +71,4 @@ public function getTestUri(): string { return $this->testUri; } - - public function isManualScored(): bool - { - return $this->isManualScored; - } } diff --git a/models/classes/eventHandler/ResultTransmissionEventHandler/ResultTransmissionEventHandler.php b/models/classes/eventHandler/ResultTransmissionEventHandler/ResultTransmissionEventHandler.php index 4d86b28fa..b77dc2e5c 100644 --- a/models/classes/eventHandler/ResultTransmissionEventHandler/ResultTransmissionEventHandler.php +++ b/models/classes/eventHandler/ResultTransmissionEventHandler/ResultTransmissionEventHandler.php @@ -22,19 +22,13 @@ namespace oat\taoQtiTest\models\classes\eventHandler\ResultTransmissionEventHandler; -use common_exception_Error; -use oat\oatbox\event\EventManager; -use oat\oatbox\service\ServiceManager; use oat\oatbox\service\ServiceNotFoundException; use oat\tao\model\service\InjectionAwareService; use oat\taoDelivery\model\execution\DeliveryServerService; use oat\taoQtiTest\models\classes\event\ResultTestVariablesTransmissionEvent; use oat\taoQtiTest\models\event\ResultItemVariablesTransmissionEvent; -use oat\taoQtiTest\models\event\TestVariablesRecorded; use taoQtiCommon_helpers_ResultTransmitter; use oat\oatbox\service\exception\InvalidServiceManagerException; -use oat\taoResultServer\models\classes\implementation\ResultServerService; -use taoResultServer_models_classes_ReadableResultStorage as ReadableResultStorage; class ResultTransmissionEventHandler extends InjectionAwareService implements Api\ResultTransmissionEventHandlerInterface @@ -55,6 +49,7 @@ public function transmitResultItemVariable(ResultItemVariablesTransmissionEvent /** * @param ResultTestVariablesTransmissionEvent $event * @throws InvalidServiceManagerException + * @throws ServiceNotFoundException * @throws \taoQtiCommon_helpers_ResultTransmissionException */ public function transmitResultTestVariable(ResultTestVariablesTransmissionEvent $event): void @@ -64,14 +59,14 @@ public function transmitResultTestVariable(ResultTestVariablesTransmissionEvent $event->getTransmissionId(), $event->getTestUri() ); - - if (!$this->containsScoreTotal($event)) { - return; - } - - $this->triggerTestVariablesRecorded($event); } + /** + * @param $deliveryExecutionIdigcicd + * @return taoQtiCommon_helpers_ResultTransmitter + * @throws InvalidServiceManagerException + * @throws \oat\oatbox\service\ServiceNotFoundException + */ private function buildTransmitter($deliveryExecutionId): taoQtiCommon_helpers_ResultTransmitter { /** @var DeliveryServerService $deliveryServerService */ @@ -80,58 +75,4 @@ private function buildTransmitter($deliveryExecutionId): taoQtiCommon_helpers_Re return new taoQtiCommon_helpers_ResultTransmitter($resultStore); } - - public function getEventManager() - { - return $this->getServiceLocator()->get(EventManager::SERVICE_ID); - } - - public function getServiceLocator() - { - return ServiceManager::getServiceManager(); - } - - /** - * @return ReadableResultStorage - * @throws ServiceNotFoundException - * @throws common_exception_Error - */ - private function getResultsStorage(): ReadableResultStorage - { - $resultServerService = $this->getServiceLocator()->get(ResultServerService::SERVICE_ID); - $storage = $resultServerService->getResultStorage(); - - if (!$storage instanceof ReadableResultStorage) { - throw new common_exception_Error('Configured result storage is not writable.'); - } - - return $storage; - } - - private function containsScoreTotal(ResultTestVariablesTransmissionEvent $event): bool - { - $scoreTotal = array_filter( - $event->getVariables(), - function ($item) { - return $item->getIdentifier() === 'SCORE_TOTAL'; - } - ); - - return !empty($scoreTotal); - } - - /** - * @param ResultTestVariablesTransmissionEvent $event - * @return void - * @throws InvalidServiceManagerException - */ - private function triggerTestVariablesRecorded(ResultTestVariablesTransmissionEvent $event): void - { - $outcomeVariables = $this->getResultsStorage()->getDeliveryVariables($event->getDeliveryExecutionId()); - $this->getEventManager()->trigger(new TestVariablesRecorded( - $event->getDeliveryExecutionId(), - $outcomeVariables, - $event->isManualScored() - )); - } } diff --git a/models/classes/runner/QtiRunnerService.php b/models/classes/runner/QtiRunnerService.php index 7f2acf012..29754ca0b 100644 --- a/models/classes/runner/QtiRunnerService.php +++ b/models/classes/runner/QtiRunnerService.php @@ -46,6 +46,7 @@ use oat\taoDelivery\model\execution\DeliveryServerService; use oat\taoDelivery\model\execution\ServiceProxy as TaoDeliveryServiceProxy; use oat\taoDelivery\model\RuntimeService; +use oat\taoOutcomeRds\model\RdsResultStorage; use oat\taoQtiItem\model\portableElement\exception\PortableElementNotFoundException; use oat\taoQtiItem\model\portableElement\exception\PortableModelMissing; use oat\taoQtiItem\model\portableElement\PortableElementService; @@ -57,6 +58,7 @@ use oat\taoQtiTest\models\event\TestExitEvent; use oat\taoQtiTest\models\event\TestInitEvent; use oat\taoQtiTest\models\event\TestTimeoutEvent; +use oat\taoQtiTest\models\event\DeliveryExecutionFinish; use oat\taoQtiTest\models\ExtendedStateService; use oat\taoQtiTest\models\files\QtiFlysystemFileManager; use oat\taoQtiTest\models\render\UpdateItemContentReferencesService; @@ -68,6 +70,7 @@ use oat\taoQtiTest\models\runner\session\TestSession; use oat\taoQtiTest\models\runner\toolsStates\ToolsStateStorage; use oat\taoQtiTest\models\TestSessionService; +use oat\taoResultServer\models\classes\implementation\ResultServerService; use qtism\common\datatypes\QtiInteger; use qtism\common\datatypes\QtiString as QtismString; use qtism\common\enums\BaseType; @@ -1185,10 +1188,30 @@ public function finish(RunnerServiceContext $context, $finalState = DeliveryExec } $this->getServiceManager()->get(ExtendedStateService::SERVICE_ID)->clearEvents($executionUri); + /** @var TestSession $session */ + $session = $context->getTestSession(); + $this->triggerDeliveryExecutionFinish($deliveryExecution, $session->isManualScored()); return $result; } + private function getResultsStorage(): RdsResultStorage + { + return $this->getServiceLocator()->get(ResultServerService::SERVICE_ID)->getResultStorage(); + } + + private function triggerDeliveryExecutionFinish(DeliveryExecution $deliveryExecution, bool $isManualScored): void + { + $outcomeVariables = $this->getResultsStorage()->getDeliveryVariables($deliveryExecution->getIdentifier()); + $this->getServiceManager()->get(EventManager::SERVICE_ID)->trigger( + new DeliveryExecutionFinish( + $deliveryExecution, + $outcomeVariables, + $isManualScored + ) + ); + } + /** * Sets the test to paused state * @param RunnerServiceContext $context