* @package taoDelivery */ class DeliveryServerService extends ConfigurableService { /** @deprecated */ const CONFIG_ID = 'taoDelivery/deliveryServer'; const SERVICE_ID = 'taoDelivery/deliveryServer'; public static function singleton() { return ServiceManager::getServiceManager()->get(self::SERVICE_ID); } /** * Return the states a delivey execution can be resumed from * @return string[] */ public function getResumableStates() { return [ DeliveryExecution::STATE_ACTIVE ,DeliveryExecution::STATE_PAUSED ]; } /** * Get resumable (active) deliveries. * @param User $user User instance. If not given then all deliveries will be returned regardless of user URI. * @return \oat\taoDelivery\model\execution\DeliveryExecution [] */ public function getResumableDeliveries(User $user) { $deliveryExecutionService = ServiceProxy::singleton(); $resumable = []; foreach ($this->getResumableStates() as $state) { foreach ($deliveryExecutionService->getDeliveryExecutionsByStatus($user->getIdentifier(), $state) as $execution) { $delivery = $execution->getDelivery(); if ($delivery->exists()) { $resumable[] = $execution; } } } return $resumable; } /** * Initialize the result server for a given execution * * @param $compiledDelivery * @param string $executionIdentifier */ public function initResultServer($compiledDelivery, $executionIdentifier, $userUri) { $this->getServiceManager()->get(\oat\taoResultServer\models\classes\ResultServerService::SERVICE_ID) ->initResultServer($compiledDelivery, $executionIdentifier, $userUri); } /** * Returns the container for the delivery execution * * @param DeliveryExecution $deliveryExecution * @return ExecutionContainer * @throws common_Exception */ public function getDeliveryContainer(DeliveryExecution $deliveryExecution) { $runtimeService = $this->getServiceLocator()->get(RuntimeService::SERVICE_ID); $deliveryContainer = $runtimeService->getDeliveryContainer($deliveryExecution->getDelivery()->getUri()); return $deliveryContainer->getExecutionContainer($deliveryExecution); } /** * @param string $deliveryExecutionId id expectected, but still accepts delivery executions for backward compatibility */ public function getResultStoreWrapper($deliveryExecutionId): ResultStorageWrapper { if ($deliveryExecutionId instanceof DeliveryExecutionInterface) { $deliveryExecutionId = $deliveryExecutionId->getIdentifier(); } /** @var ResultServerService $resultService */ $resultService = $this->getServiceLocator()->get(ResultServerService::SERVICE_ID); return new ResultStorageWrapper($deliveryExecutionId, $resultService->getResultStorage()); } }