Skip to content

Commit

Permalink
Bugfix/inf 248 not send ags with outcome processing set to none (#2435)
Browse files Browse the repository at this point in the history
* bugfix: move event to proper delivery finish

* bugfix: code review fixes

* fix: code check

(cherry picked from commit d87be4b)
  • Loading branch information
Karol-Stelmaczonek committed Jan 8, 2024
1 parent b327c85 commit f7875c9
Show file tree
Hide file tree
Showing 5 changed files with 317 additions and 412 deletions.
5 changes: 2 additions & 3 deletions helpers/class.TestSession.php
Original file line number Diff line number Diff line change
Expand Up @@ -773,12 +773,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) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand All @@ -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
Expand Down
11 changes: 1 addition & 10 deletions models/classes/event/ResultTestVariablesTransmissionEvent.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -75,9 +71,4 @@ public function getTestUri(): string
{
return $this->testUri;
}

public function isManualScored(): bool
{
return $this->isManualScored;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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
{
Expand All @@ -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
Expand All @@ -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 */
Expand All @@ -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()
));
}
}
Loading

0 comments on commit f7875c9

Please sign in to comment.