Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
Total | |
95.00% |
19 / 20 |
|
66.67% |
2 / 3 |
CRAP | |
0.00% |
0 / 1 |
ContainerRuntime | |
95.00% |
19 / 20 |
|
66.67% |
2 / 3 |
7 | |
0.00% |
0 / 1 |
getDeliveryContainer | |
90.91% |
10 / 11 |
|
0.00% |
0 / 1 |
3.01 | |||
getRuntime | |
100.00% |
8 / 8 |
|
100.00% |
1 / 1 |
3 | |||
getCache | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 |
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) 2015 (original work) Open Assessment Technologies SA (under the project TAO-PRODUCT); |
19 | * |
20 | */ |
21 | |
22 | namespace oat\taoDeliveryRdf\model; |
23 | |
24 | use oat\taoDelivery\model\container\LegacyRuntime; |
25 | use oat\generis\model\OntologyAwareTrait; |
26 | use oat\taoDelivery\model\container\delivery\DeliveryContainerRegistry; |
27 | use tao_models_classes_service_ServiceCall; |
28 | use oat\oatbox\cache\SimpleCache; |
29 | use Psr\SimpleCache\CacheInterface; |
30 | |
31 | /** |
32 | * Service to select the correct container based on delivery |
33 | * |
34 | * @access public |
35 | * @author Joel Bout, <joel@taotesting.com> |
36 | * @package taoDelivery |
37 | */ |
38 | class ContainerRuntime extends LegacyRuntime |
39 | { |
40 | use OntologyAwareTrait; |
41 | |
42 | public const PROPERTY_RUNTIME = 'http://www.tao.lu/Ontologies/TAODelivery.rdf#AssembledDeliveryRuntime'; |
43 | public const PROPERTY_CONTAINER = 'http://www.tao.lu/Ontologies/TAODelivery.rdf#AssembledDeliveryContainer'; |
44 | |
45 | public const CACHE_PREFIX = 'container:'; |
46 | |
47 | public function getDeliveryContainer($deliveryId) |
48 | { |
49 | $containerJson = $this->getCache()->get(self::CACHE_PREFIX . $deliveryId); |
50 | if (is_null($containerJson)) { |
51 | $delivery = $this->getResource($deliveryId); |
52 | $containerJson = (string)$delivery->getOnePropertyValue($this->getProperty(self::PROPERTY_CONTAINER)); |
53 | $this->getCache()->set(self::CACHE_PREFIX . $deliveryId, $containerJson); |
54 | } |
55 | if (!empty($containerJson)) { |
56 | $registry = $this->getServiceLocator()->get(DeliveryContainerRegistry::class); |
57 | $this->propagate($registry); |
58 | $container = $registry->fromJson($containerJson); |
59 | return $container; |
60 | } else { |
61 | return parent::getDeliveryContainer($deliveryId); |
62 | } |
63 | } |
64 | |
65 | /** |
66 | * (non-PHPdoc) |
67 | * @see \oat\taoDelivery\model\RuntimeService::getRuntime() |
68 | */ |
69 | public function getRuntime($deliveryId) |
70 | { |
71 | $delivery = $this->getResource($deliveryId); |
72 | $runtimeResource = $delivery->getOnePropertyValue($this->getProperty(self::PROPERTY_RUNTIME)); |
73 | if ($runtimeResource === null) { |
74 | throw new \common_exception_NoContent('Unable to load runtime associated for delivery ' . $deliveryId . |
75 | ' Delivery probably deleted.'); |
76 | } |
77 | return ($runtimeResource instanceof \core_kernel_classes_Resource) |
78 | ? tao_models_classes_service_ServiceCall::fromResource($runtimeResource) |
79 | : tao_models_classes_service_ServiceCall::fromString((string)$runtimeResource); |
80 | } |
81 | |
82 | private function getCache(): CacheInterface |
83 | { |
84 | return $this->getServiceLocator()->get(SimpleCache::SERVICE_ID); |
85 | } |
86 | } |