Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
0.00% |
0 / 29 |
|
0.00% |
0 / 12 |
CRAP | |
0.00% |
0 / 1 |
| ServiceProxy | |
0.00% |
0 / 29 |
|
0.00% |
0 / 12 |
272 | |
0.00% |
0 / 1 |
| setImplementation | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
| getImplementation | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
| getUserExecutions | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
| getDeliveryExecutionsByStatus | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
| getActiveDeliveryExecutions | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
| getPausedDeliveryExecutions | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
| getFinishedDeliveryExecutions | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
| initDeliveryExecution | |
0.00% |
0 / 13 |
|
0.00% |
0 / 1 |
20 | |||
| getDeliveryExecution | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
| getExecutionsByDelivery | |
0.00% |
0 / 6 |
|
0.00% |
0 / 1 |
6 | |||
| implementsMonitoring | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
| deleteDeliveryExecutionData | |
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) 2013 (original work) Open Assessment Technologies SA (under the project TAO-PRODUCT); |
| 19 | * |
| 20 | */ |
| 21 | |
| 22 | namespace oat\taoDelivery\model\execution; |
| 23 | |
| 24 | use common_exception_NoImplementation; |
| 25 | use common_exception_NotFound; |
| 26 | use common_Logger; |
| 27 | use common_session_SessionManager; |
| 28 | use core_kernel_classes_Resource; |
| 29 | use core_kernel_users_GenerisUser; |
| 30 | use oat\taoDelivery\models\classes\execution\event\DeliveryExecutionCreated; |
| 31 | use oat\oatbox\service\ServiceManager; |
| 32 | use oat\oatbox\event\EventManager; |
| 33 | use oat\taoDelivery\model\execution\Delete\DeliveryExecutionDeleteRequest; |
| 34 | use tao_models_classes_Service; |
| 35 | |
| 36 | /** |
| 37 | * Service to manage the execution of deliveries |
| 38 | * |
| 39 | * @access public |
| 40 | * @author Joel Bout, <joel@taotesting.com> |
| 41 | * @package taoDelivery |
| 42 | |
| 43 | */ |
| 44 | class ServiceProxy extends tao_models_classes_Service implements DeliveryExecutionService |
| 45 | { |
| 46 | public const CONFIG_KEY = 'execution_service'; |
| 47 | |
| 48 | public function setImplementation(DeliveryExecutionService $implementation) |
| 49 | { |
| 50 | $this->getServiceLocator()->register(self::SERVICE_ID, $implementation); |
| 51 | } |
| 52 | |
| 53 | protected function getImplementation(): DeliveryExecutionService |
| 54 | { |
| 55 | /** @noinspection PhpIncompatibleReturnTypeInspection */ |
| 56 | return $this->getServiceLocator()->get(self::SERVICE_ID); |
| 57 | } |
| 58 | |
| 59 | /** |
| 60 | * (non-PHPdoc) |
| 61 | * @see DeliveryExecutionService::getUserExecutions() |
| 62 | */ |
| 63 | public function getUserExecutions(core_kernel_classes_Resource $assembly, $userUri) |
| 64 | { |
| 65 | return $this->getImplementation()->getUserExecutions($assembly, $userUri); |
| 66 | } |
| 67 | |
| 68 | /** |
| 69 | * (non-PHPdoc) |
| 70 | * @see DeliveryExecutionService::getDeliveryExecutionsByStatus() |
| 71 | */ |
| 72 | public function getDeliveryExecutionsByStatus($userUri, $status) |
| 73 | { |
| 74 | return $this->getImplementation()->getDeliveryExecutionsByStatus($userUri, $status); |
| 75 | } |
| 76 | |
| 77 | public function getActiveDeliveryExecutions($userUri) |
| 78 | { |
| 79 | return $this->getDeliveryExecutionsByStatus($userUri, DeliveryExecutionInterface::STATE_ACTIVE); |
| 80 | } |
| 81 | |
| 82 | public function getPausedDeliveryExecutions($userUri) |
| 83 | { |
| 84 | return $this->getDeliveryExecutionsByStatus($userUri, DeliveryExecutionInterface::STATE_PAUSED); |
| 85 | } |
| 86 | |
| 87 | public function getFinishedDeliveryExecutions($userUri) |
| 88 | { |
| 89 | return $this->getDeliveryExecutionsByStatus($userUri, DeliveryExecutionInterface::STATE_FINISHED); |
| 90 | } |
| 91 | |
| 92 | /** |
| 93 | * @deprecated |
| 94 | * (non-PHPdoc) |
| 95 | * @see DeliveryExecutionService::initDeliveryExecution() |
| 96 | * @throws \common_exception_Error |
| 97 | */ |
| 98 | public function initDeliveryExecution(core_kernel_classes_Resource $assembly, $user) |
| 99 | { |
| 100 | if (is_string($user)) { |
| 101 | common_Logger::w('Deprecated use of initDeliveryExecution()'); |
| 102 | $sessionUser = common_session_SessionManager::getSession()->getUser(); |
| 103 | if ($user == $sessionUser->getIdentifier()) { |
| 104 | $user = $sessionUser; |
| 105 | } else { |
| 106 | $generisUser = new core_kernel_classes_Resource($user); |
| 107 | if ($generisUser->exists()) { |
| 108 | $user = new core_kernel_users_GenerisUser($generisUser); |
| 109 | } else { |
| 110 | throw new common_exception_NotFound('Unable to find User "' . $user . '"'); |
| 111 | } |
| 112 | } |
| 113 | } |
| 114 | $deliveryExecution = $this->getImplementation()->initDeliveryExecution($assembly, $user->getIdentifier()); |
| 115 | $eventManager = ServiceManager::getServiceManager()->get(EventManager::SERVICE_ID); |
| 116 | $eventManager->trigger(new DeliveryExecutionCreated($deliveryExecution, $user)); |
| 117 | return $deliveryExecution; |
| 118 | } |
| 119 | |
| 120 | |
| 121 | /** |
| 122 | * (non-PHPdoc) |
| 123 | * @see DeliveryExecutionService::getDeliveryExecution() |
| 124 | */ |
| 125 | public function getDeliveryExecution($identifier) |
| 126 | { |
| 127 | return $this->getImplementation()->getDeliveryExecution($identifier); |
| 128 | } |
| 129 | |
| 130 | /** |
| 131 | * Implemented in the monitoring interface |
| 132 | * |
| 133 | * @param core_kernel_classes_Resource $compiled |
| 134 | * @return DeliveryExecution[] executions for a single compilation |
| 135 | * @throws \common_exception_Error |
| 136 | * @throws common_exception_NoImplementation |
| 137 | */ |
| 138 | public function getExecutionsByDelivery(core_kernel_classes_Resource $compiled) |
| 139 | { |
| 140 | if (!$this->implementsMonitoring()) { |
| 141 | throw new common_exception_NoImplementation( |
| 142 | get_class($this->getImplementation()) |
| 143 | . ' does not implement \oat\taoDelivery\model\execution\Monitoring' |
| 144 | ); |
| 145 | } |
| 146 | return $this->getImplementation()->getExecutionsByDelivery($compiled); |
| 147 | } |
| 148 | |
| 149 | /** |
| 150 | * Whenever or not the current implementation supports monitoring |
| 151 | * |
| 152 | * @return boolean |
| 153 | * @throws \common_exception_Error |
| 154 | */ |
| 155 | public function implementsMonitoring() |
| 156 | { |
| 157 | return $this->getImplementation() instanceof Monitoring; |
| 158 | } |
| 159 | |
| 160 | /** |
| 161 | * @inheritdoc |
| 162 | */ |
| 163 | public function deleteDeliveryExecutionData(DeliveryExecutionDeleteRequest $request) |
| 164 | { |
| 165 | return $this->getImplementation()->deleteDeliveryExecutionData($request); |
| 166 | } |
| 167 | } |