Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
Total | |
0.00% |
0 / 42 |
|
0.00% |
0 / 3 |
CRAP | |
0.00% |
0 / 1 |
CompileDelivery | |
0.00% |
0 / 42 |
|
0.00% |
0 / 3 |
110 | |
0.00% |
0 / 1 |
__invoke | |
0.00% |
0 / 25 |
|
0.00% |
0 / 1 |
56 | |||
jsonSerialize | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
createTask | |
0.00% |
0 / 16 |
|
0.00% |
0 / 1 |
6 |
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) 2016 (original work) Open Assessment Technologies SA; |
19 | * |
20 | * |
21 | */ |
22 | |
23 | namespace oat\taoDeliveryRdf\model\tasks; |
24 | |
25 | use common_report_Report as Report; |
26 | use oat\generis\model\OntologyAwareTrait; |
27 | use oat\oatbox\extension\AbstractAction; |
28 | use oat\oatbox\service\ServiceManager; |
29 | use oat\tao\model\taskQueue\QueueDispatcher; |
30 | use oat\tao\model\taskQueue\Task\TaskAwareInterface; |
31 | use oat\tao\model\taskQueue\Task\TaskAwareTrait; |
32 | use oat\tao\model\taskQueue\Task\TaskInterface; |
33 | use oat\taoDeliveryRdf\model\DeliveryAssemblyService; |
34 | use oat\taoDeliveryRdf\model\DeliveryFactory; |
35 | |
36 | /** |
37 | * Class CompileDelivery |
38 | * |
39 | * Action to compile delivery by test uri |
40 | * |
41 | * @package oat\taoQtiTest\models\tasks |
42 | * @author Aleh Hutnikau, <hutnikau@1pt.com> |
43 | */ |
44 | class CompileDelivery extends AbstractAction implements \JsonSerializable, TaskAwareInterface |
45 | { |
46 | use TaskAwareTrait; |
47 | use OntologyAwareTrait; |
48 | |
49 | /** |
50 | * @param $params |
51 | * @throws \common_exception_MissingParameter |
52 | * @return Report |
53 | */ |
54 | public function __invoke($params) |
55 | { |
56 | if (!isset($params['test'])) { |
57 | throw new \common_exception_MissingParameter('Missing parameter `test` in ' . self::class); |
58 | } |
59 | |
60 | if (isset($params['deliveryClass'])) { |
61 | $deliveryClass = $this->getClass($params['deliveryClass']); |
62 | if (!$deliveryClass->exists()) { |
63 | $deliveryClass = $this->getClass(DeliveryAssemblyService::CLASS_URI); |
64 | } |
65 | } else { |
66 | $deliveryClass = $this->getClass(DeliveryAssemblyService::CLASS_URI); |
67 | } |
68 | |
69 | $test = $this->getResource($params['test']); |
70 | $label = 'Delivery of ' . $test->getLabel(); |
71 | |
72 | $deliveryResource = \core_kernel_classes_ResourceFactory::create($deliveryClass); |
73 | |
74 | if (isset($params['initialProperties'])) { |
75 | // Setting "Sync to remote..." if enabled |
76 | /** @var DeliveryFactory $deliveryFactoryResources */ |
77 | $deliveryFactoryResources = $this->getServiceManager()->get(DeliveryFactory::SERVICE_ID); |
78 | |
79 | $deliveryResource = $deliveryFactoryResources->setInitialProperties( |
80 | $params['initialProperties'], |
81 | $deliveryResource |
82 | ); |
83 | } |
84 | |
85 | /** @var TaskInterface $task */ |
86 | $task = $this->getTask(); |
87 | if (!is_null($task)) { |
88 | $deliveryCompileTaskProperty = $this->getProperty(DeliveryFactory::PROPERTY_DELIVERY_COMPILE_TASK); |
89 | $deliveryResource->setPropertyValue($deliveryCompileTaskProperty, $task->getId()); |
90 | } |
91 | |
92 | /** @var DeliveryFactory $deliveryFactory */ |
93 | $deliveryFactory = $this->getServiceLocator()->get(DeliveryFactory::SERVICE_ID); |
94 | |
95 | $report = $deliveryFactory->create($deliveryClass, $test, $label, $deliveryResource); |
96 | if ($report->getType() === \common_report_Report::TYPE_ERROR) { |
97 | $deliveryResource->delete(true); |
98 | } |
99 | |
100 | return $report; |
101 | } |
102 | |
103 | /** |
104 | * @return string |
105 | */ |
106 | public function jsonSerialize() |
107 | { |
108 | return __CLASS__; |
109 | } |
110 | |
111 | /** |
112 | * Create a task to compile a delivery into a delivery class |
113 | * |
114 | * @param \core_kernel_classes_Resource $test Test resource to be compiled |
115 | * @param \core_kernel_classes_Class $deliveryClass Delivery class where the test is compiled to |
116 | * @param array $initialProperties |
117 | * @return TaskInterface |
118 | */ |
119 | public static function createTask( |
120 | \core_kernel_classes_Resource $test, |
121 | \core_kernel_classes_Class $deliveryClass, |
122 | array $initialProperties = [] |
123 | ) { |
124 | $action = new self(); |
125 | /** @var QueueDispatcher $queueDispatcher */ |
126 | $queueDispatcher = ServiceManager::getServiceManager()->get(QueueDispatcher::SERVICE_ID); |
127 | |
128 | $parameters = [ |
129 | 'test' => $test->getUri(), |
130 | 'initialProperties' => $initialProperties |
131 | ]; |
132 | |
133 | if (!is_null($deliveryClass)) { |
134 | $parameters['deliveryClass'] = $deliveryClass->getUri(); |
135 | } |
136 | |
137 | return $queueDispatcher->createTask( |
138 | $action, |
139 | $parameters, |
140 | __('Publishing of <b>%s</b>', htmlspecialchars($test->getLabel())), |
141 | null, |
142 | true |
143 | ); |
144 | } |
145 | } |