Skip to content

Commit cd47330

Browse files
committed
Workflow API update and enhancements
fixes #34
1 parent 214d5c7 commit cd47330

File tree

5 files changed

+90
-87
lines changed

5 files changed

+90
-87
lines changed

Diff for: .gitignore

+2-1
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,5 @@
22
/vendor
33
.phpunit.result.cache
44
.DS_Store
5-
.gitignore
5+
.gitignore
6+
.lmsupdatenotes

Diff for: CHANGELOG.md

+4-1
Original file line numberDiff line numberDiff line change
@@ -52,4 +52,7 @@
5252
- Fix for unauthorized access when extracting the Opencast API Version.
5353

5454
# 1.9.0
55-
- Allow passing additonal options to Guzzle #30
55+
- Allow passing additional options to Guzzle [#30]
56+
- WorkflowApi endpoint methods got updated
57+
- `withconfigurationpaneljson` parameter has been added to `/api/workflow-definitions` endpoints. [#34]
58+
- `@deprecated` removal of OcWorkflowsApi::geAll() method!

Diff for: src/OpencastApi/Rest/OcWorkflowsApi.php

+28-65
Original file line numberDiff line numberDiff line change
@@ -14,55 +14,13 @@ public function __construct($restClient)
1414

1515
## [Section 1]: General API endpoints.
1616

17-
/**
18-
* Returns a list of workflow instances.
19-
*
20-
* @param array $params (optional) The list of query params to pass which can contain the followings:
21-
* [
22-
* 'withoperations' => '{Whether the workflow operations should be included in the response}',
23-
* 'withconfiguration' => '{Whether the workflow configuration should be included in the response}',
24-
* 'sort' => '{an assiciative array for sorting e.g. ['event_identifier' => 'DESC']}',
25-
* 'limit' => '{the maximum number of results to return}',
26-
* 'offset' => '{the index of the first result to return}',
27-
* 'filter' => '{an assiciative array for filtering e.g. ['state' => '{Workflow instances that are in this state}']}',
28-
* ]
29-
*
30-
* @return array the response result ['code' => 200, 'body' => '{A (potentially empty) list of workflow instances}']
31-
* @deprecated since v1.3 because this endpoint is removed from Opencast Verison 12.x, we will no longer support it here.
32-
*/
33-
public function getAll($params = [])
34-
{
35-
$uri = self::URI;
36-
37-
$query = [];
38-
if (isset($params['filter']) && is_array($params['filter']) && !empty($params['filter'])) {
39-
$query['filter'] = $this->convertArrayToFiltering($params['filter']);
40-
}
41-
if (isset($params['sort']) && is_array($params['sort']) && !empty($params['sort'])) {
42-
$query['sort'] = $this->convertArrayToSorting($params['sort']);
43-
}
44-
45-
$acceptableParams = [
46-
'sort', 'limit', 'offset', 'filter', 'withoperations', 'withconfiguration'
47-
];
48-
49-
foreach ($params as $param_name => $param_value) {
50-
if (in_array($param_name, $acceptableParams) && !array_key_exists($param_name, $query)) {
51-
$query[$param_name] = $param_value;
52-
}
53-
}
54-
55-
$options = $this->restClient->getQueryParams($query);
56-
return $this->restClient->performGet($uri, $options);
57-
}
58-
5917
/**
6018
* Returns a single workflow instance.
61-
*
62-
* @param string $workflowInstanceId The workflow instance id
19+
*
20+
* @param string $workflowInstanceId The workflow instance id
6321
* @param boolean $withoperations (optional) Whether the workflow operations should be included in the response (Default value=false)
6422
* @param boolean $withconfiguration (optional) Whether the workflow configuration should be included in the response (Default value=false)
65-
*
23+
*
6624
* @return array the response result ['code' => 200, 'body' => '{ The workflow instance}']
6725
*/
6826
public function get($workflowInstanceId, $withoperations = false, $withconfiguration = false)
@@ -76,20 +34,20 @@ public function get($workflowInstanceId, $withoperations = false, $withconfigura
7634
if (is_bool($withconfiguration)) {
7735
$query['withconfiguration'] = $withconfiguration;
7836
}
79-
37+
8038
$options = $this->restClient->getQueryParams($query);
8139
return $this->restClient->performGet($uri, $options);
8240
}
8341

8442
/**
8543
* Creates (runs) a workflow instance agianst an event.
86-
*
44+
*
8745
* @param string $eventIdentifier The event identifier this workflow should run against
8846
* @param string $definitionIdentifier The identifier of the workflow definition to use
8947
* @param string|array $configuration (optional) The optional configuration for this workflow
9048
* @param boolean $withoperations (optional) Whether the workflow operations should be included in the response (Default value=false)
9149
* @param boolean $withconfiguration (optional) Whether the workflow configuration should be included in the response (Default value=false)
92-
*
50+
*
9351
* @return array the response result ['code' => 201, 'body' => '{A new workflow is created and its identifier as Object is returned}', 'location' => 'The url']
9452
*/
9553
public function run($eventIdentifier, $definitionIdentifier, $configuration = [], $withoperations = false, $withconfiguration = false)
@@ -120,13 +78,13 @@ public function run($eventIdentifier, $definitionIdentifier, $configuration = []
12078

12179
/**
12280
* Updates a workflow instance.
123-
*
124-
* @param string $workflowInstanceId The workflow instance id
81+
*
82+
* @param string $workflowInstanceId The workflow instance id
12583
* @param string $state (optional) The optional state transition for this workflow
12684
* @param string|array $configuration (optional) The optional configuration for this workflow
12785
* @param bool $withoperations (optional) Whether the workflow operations should be included in the response (Default value=false)
12886
* @param bool $withconfiguration (optional) Whether the workflow configuration should be included in the response (Default value=false)
129-
*
87+
*
13088
* @return array the response result ['code' => 200, 'reason' => 'OK'] (updated)
13189
*/
13290
public function update($workflowInstanceId, $state = '', $configuration = [], $withoperations = false, $withconfiguration = false)
@@ -157,9 +115,9 @@ public function update($workflowInstanceId, $state = '', $configuration = [], $w
157115

158116
/**
159117
* Deletes a workflow instance.
160-
*
161-
* @param string $workflowInstanceId The workflow instance id
162-
*
118+
*
119+
* @param string $workflowInstanceId The workflow instance id
120+
*
163121
* @return array the response result ['code' => 204, 'reason' => 'No Content'] (deleted)
164122
*/
165123
public function delete($workflowInstanceId)
@@ -170,22 +128,23 @@ public function delete($workflowInstanceId)
170128

171129
## End of [Section 1]: General API endpoints.
172130

173-
## [Section 2]: Workflow definitions.
131+
## [Section 2]: Workflow definitions API endpoints.
174132

175133
/**
176134
* Returns a list of workflow definitions.
177-
*
135+
*
178136
* @param array $params (optional) The list of query params to pass which can contain the followings:
179137
* [
180138
* 'withoperations' => '{(boolean) Whether the workflow operations should be included in the response}',
181139
* 'withconfigurationpanel' => '{(boolean) Whether the workflow configuration panel should be included in the response}',
140+
* 'withconfigurationpaneljson' => '{(boolean) Whether the workflow configuration panel in JSON should be included in the response [this is a must for Opencast 17]
182141
* 'sort' => '{an assiciative array for sorting e.g. ['title' => 'DESC']}',
183142
* 'limit' => '{the maximum number of results to return}',
184143
* 'offset' => '{the index of the first result to return}',
185144
* 'filter' => '{an assiciative array for filtering e.g. ['tag' => '{Workflow definitions where the tag is included}']}',
186-
* ]
187-
*
188-
* @return array the response result ['code' => 200, 'body' => '{A (potentially empty) list of workflow definitions}']
145+
* ]
146+
*
147+
* @return array the response result ['code' => 200, 'body' => '{A (potentially empty) list of workflow definitions}']
189148
*/
190149
public function getAllDefinitions($params = [])
191150
{
@@ -200,7 +159,7 @@ public function getAllDefinitions($params = [])
200159
}
201160

202161
$acceptableParams = [
203-
'sort', 'limit', 'offset', 'filter', 'withoperations', 'withconfigurationpanel'
162+
'sort', 'limit', 'offset', 'filter', 'withoperations', 'withconfigurationpanel', 'withconfigurationpaneljson'
204163
];
205164

206165
foreach ($params as $param_name => $param_value) {
@@ -215,14 +174,15 @@ public function getAllDefinitions($params = [])
215174

216175
/**
217176
* Returns a single workflow definition.
218-
*
177+
*
219178
* @param string $workflowDefinitionId the identifier of the workflow definition.
220179
* @param boolean $withoperations (optional) Whether the workflow operations should be included in the response (Default value=false)
221180
* @param boolean $withconfigurationpanel (optional) Whether the workflow configuration should be included in the response (Default value=false)
222-
*
181+
* @param boolean $withconfigurationpaneljson (optional) Whether the workflow configuration panel in JSON should be included in the response (Default value=false)
182+
*
223183
* @return array the response result ['code' => 200, 'body' => '{ The workflow definition is returned as JSON object}']
224184
*/
225-
public function getDefinition($workflowDefinitionId, $withoperations = false, $withconfigurationpanel = false)
185+
public function getDefinition($workflowDefinitionId, $withoperations = false, $withconfigurationpanel = false, $withconfigurationpaneljson = false)
226186
{
227187
$uri = self::URI_SECTION_2 . "/{$workflowDefinitionId}";
228188

@@ -233,11 +193,14 @@ public function getDefinition($workflowDefinitionId, $withoperations = false, $w
233193
if (is_bool($withconfigurationpanel)) {
234194
$query['withconfigurationpanel'] = $withconfigurationpanel;
235195
}
236-
196+
if (is_bool($withconfigurationpaneljson)) {
197+
$query['withconfigurationpaneljson'] = $withconfigurationpaneljson;
198+
}
199+
237200
$options = $this->restClient->getQueryParams($query);
238201
return $this->restClient->performGet($uri, $options);
239202
}
240203

241204
## End of [Section 2]: Workflow definitions.
242205
}
243-
?>
206+
?>

Diff for: tests/DataProvider/WorkflowsApiDataProvider.php

+8-7
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,20 @@
1-
<?php
1+
<?php
22
namespace Tests\DataProvider;
33

44
class WorkflowsApiDataProvider {
5-
6-
public static function getAllCases(): array
5+
6+
public static function getAllDefinitionsCases(): array
77
{
88
return [
99
[[]],
1010
[['withoperations' => true]],
11-
[['withconfiguration' => true]],
12-
[['sort' => ['workflow_definition_identifier' => 'DESC']]],
11+
[['withconfigurationpanel' => true]],
12+
[['withconfigurationpaneljson' => true]],
13+
[['sort' => ['identifier' => 'DESC']]],
1314
[['limit' => 2]],
1415
[['offset' => 1]],
15-
[['filter' => ['workflow_definition_identifier' => 'fast']]],
16+
[['filter' => ['tag' => 'schedule']]],
1617
];
1718
}
1819
}
19-
?>
20+
?>

Diff for: tests/Unit/OcWorkflowsApiTest.php

+48-13
Original file line numberDiff line numberDiff line change
@@ -17,19 +17,6 @@ protected function setUp(): void
1717
$this->ocEventsApi = $ocRestApi->eventsApi;
1818
}
1919

20-
/**
21-
* @test
22-
* @dataProvider \Tests\DataProvider\WorkflowsApiDataProvider::getAllCases()
23-
*/
24-
public function get_all_workflows($params): void
25-
{
26-
$this->markTestSkipped('Depricated Endpoint (removed from Opencast v12.x)');
27-
$response = $this->ocWorkflowsApi->getAll($params);
28-
29-
$this->assertSame(200, $response['code'], 'Failure to get workflows list');
30-
}
31-
32-
3320
/**
3421
* @test
3522
*/
@@ -98,5 +85,53 @@ public function get_definition_run_update_delete_workflow(): void
9885
$this->assertSame(204, $response6['code'], 'Failure to delete a workflow');
9986
sleep(1);
10087
}
88+
89+
/**
90+
* @test
91+
* @dataProvider \Tests\DataProvider\WorkflowsApiDataProvider::getAllDefinitionsCases()
92+
*/
93+
public function get_all_definitions($params): void
94+
{
95+
$response = $this->ocWorkflowsApi->getAllDefinitions($params);
96+
$this->assertSame(200, $response['code'], 'Failure to get workflows list');
97+
}
98+
99+
/**
100+
* @test
101+
* This test is meant to check the integrity of the response body, to make sure it contains the correct properties.
102+
*/
103+
public function get_single_definition_with_parameters(): void
104+
{
105+
$response = $this->ocWorkflowsApi->getDefinition(
106+
'fast',
107+
true,
108+
true,
109+
true
110+
);
111+
$this->assertSame(200, $response['code'], 'Failure to get "fast" workflow');
112+
$bodyArray = json_decode(json_encode($response['body']), true);
113+
$this->assertNotEmpty($bodyArray, 'Response body array is empty');
114+
115+
// Check for operations
116+
$this->assertArrayHasKey('operations', $bodyArray, 'No configuration_panel is defined');
117+
118+
// Check for config panel
119+
$this->assertArrayHasKey('configuration_panel', $bodyArray, 'No configuration_panel is defined');
120+
121+
// Check for config panel json
122+
$this->assertArrayHasKey('configuration_panel_json', $bodyArray, 'No configuration_panel_json is defined');
123+
124+
// Check for title
125+
$this->assertArrayHasKey('title', $bodyArray, 'No configuration_panel_json is defined');
126+
127+
// Check for tags
128+
$this->assertArrayHasKey('tags', $bodyArray, 'No configuration_panel_json is defined');
129+
130+
// Check for description
131+
$this->assertArrayHasKey('description', $bodyArray, 'No configuration_panel_json is defined');
132+
133+
// Check for identifier
134+
$this->assertArrayHasKey('identifier', $bodyArray, 'No configuration_panel_json is defined');
135+
}
101136
}
102137
?>

0 commit comments

Comments
 (0)