Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use new opencast api exceptions from API plugin #405

Open
wants to merge 7 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions .github/workflows/config.json
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
{
"main-moodle": "MOODLE_405_STABLE",
"main-php": "8.3",
"main-oc": "16.6",
"ocs": ["16.6", "15.11"],
"main-oc": "16.7",
"ocs": [],
"main-db": "mariadb",
"moodle-php": {
"MOODLE_405_STABLE": ["8.1", "8.2"]
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/config_all.json
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
{
"main-moodle": "MOODLE_405_STABLE",
"main-php": "8.3",
"main-oc": "16.6",
"ocs": ["16.6", "15.11"],
"main-oc": "16.7",
"ocs": [],
"main-db": "mariadb",
"moodle-php": {
"MOODLE_401_STABLE": ["7.4", "8.0", "8.1"],
Expand Down
3 changes: 2 additions & 1 deletion .github/workflows/moodle-ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,5 +12,6 @@ jobs:
with:
requires-tool-plugin: true
requires-mod-plugin: true
branch-tool-plugin: oc-16-support
branch-tool-plugin: issue-56
branch-mod-plugin: main
branch-opencast-docker-default: 16.7
4 changes: 2 additions & 2 deletions block_opencast.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
*/

use block_opencast\local\apibridge;
use block_opencast\opencast_connection_exception;
use tool_opencast\exception\opencast_api_response_exception;
use tool_opencast\local\settings_api;
use tool_opencast\seriesmapping;

Expand Down Expand Up @@ -133,7 +133,7 @@ public function get_content() {
$apibridge = apibridge::get_instance($instance->id);
$videos[$instance->id] = $apibridge->get_block_videos($COURSE->id);
}
} catch (opencast_connection_exception $e) {
} catch (opencast_api_response_exception $e) {
$videos[$instance->id] = new stdClass();
$videos[$instance->id]->error = $e->getMessage();
}
Expand Down
6 changes: 3 additions & 3 deletions classes/local/addvideo_form.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@

namespace block_opencast\local;

use block_opencast\opencast_connection_exception;
use tool_opencast\exception\opencast_api_response_exception;
use block_opencast_renderer;
use coding_exception;
use core\notification;
Expand Down Expand Up @@ -102,7 +102,7 @@ public function definition() {
foreach ($seriesrecords as $series) {
$seriesoption[$series->identifier] = $series->title;
}
} catch (opencast_connection_exception $e) {
} catch (opencast_api_response_exception $e) {
notification::warning($e->getMessage());
foreach ($seriesrecords as $series) {
$seriesoption[$series->series] = $series->series;
Expand All @@ -119,7 +119,7 @@ public function definition() {
foreach ($seriesrecords as $series) {
$seriesoption[$series->identifier] = $series->title;
}
} catch (opencast_connection_exception $e) {
} catch (opencast_api_response_exception $e) {
notification::warning($e->getMessage());
$seriesoption[$this->_customdata['series']] = $this->_customdata['series'];
}
Expand Down
150 changes: 71 additions & 79 deletions classes/local/apibridge.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
defined('MOODLE_INTERNAL') || die();

use block_opencast\groupaccess;
use block_opencast\opencast_connection_exception;
use tool_opencast\exception\opencast_api_response_exception;
use block_opencast\task\process_duplicated_event_visibility_change;
use block_opencast_apibridge_testable;
use block_opencast_renderer;
Expand Down Expand Up @@ -142,12 +142,18 @@ public function check_api_configuration() {
* @return OcIngest
* @throws dml_exception
* @throws moodle_exception
* @throws opencast_connection_exception
* @throws opencast_api_response_exception
*/
private function get_ingest_api() {
$this->api = api::get_instance($this->ocinstanceid, [], [], true);
if (!property_exists($this->api->opencastapi, 'ingest')) {
throw new opencast_connection_exception('ingest_endpoint_notfound', 'block_opencast');
throw new opencast_api_response_exception(
[
'reason' => 'exception_request_ingest_endpoint_notfound',
'code' => 404,
],
false
);
}
return $this->api->opencastapi->ingest;
}
Expand All @@ -158,19 +164,18 @@ private function get_ingest_api() {
* @return string Newly created mediapackage
* @throws dml_exception
* @throws moodle_exception
* @throws opencast_connection_exception
* @throws opencast_api_response_exception
*/
public function ingest_create_media_package() {
$ingestapi = $this->get_ingest_api();
$response = $ingestapi->createMediaPackage();
$code = $response['code'];
$mediapackage = $response['body'];
if ($code === 0) {
throw new opencast_connection_exception('connection_failure', 'block_opencast');
} else if ($code != 200) {
throw new opencast_connection_exception('unexpected_api_response', 'block_opencast');

if ($code != 200) {
throw new opencast_api_response_exception($response);
}

$mediapackage = $response['body'];
return $mediapackage;
}

Expand All @@ -182,20 +187,18 @@ public function ingest_create_media_package() {
* @return string
* @throws dml_exception
* @throws moodle_exception
* @throws opencast_connection_exception
* @throws opencast_api_response_exception
*/
public function ingest_add_catalog($mediapackage, $flavor, $file) {
$ingestapi = $this->get_ingest_api();
$response = $ingestapi->addCatalog($mediapackage, $flavor, $file);
$code = $response['code'];
$newmediapackage = $response['body'];

if ($code === 0) {
throw new opencast_connection_exception('connection_failure', 'block_opencast');
} else if ($code != 200) {
throw new opencast_connection_exception('unexpected_api_response', 'block_opencast');
if ($code != 200) {
throw new opencast_api_response_exception($response);
}

$newmediapackage = $response['body'];
return $newmediapackage;
}

Expand All @@ -207,20 +210,18 @@ public function ingest_add_catalog($mediapackage, $flavor, $file) {
* @return string
* @throws dml_exception
* @throws moodle_exception
* @throws opencast_connection_exception
* @throws opencast_api_response_exception
*/
public function ingest_add_track($mediapackage, $flavor, $file) {
$ingestapi = $this->get_ingest_api();
$response = $ingestapi->addTrack($mediapackage, $flavor, $this->get_upload_filestream($file));
$code = $response['code'];
$newmediapackage = $response['body'];

if ($code === 0) {
throw new opencast_connection_exception('connection_failure', 'block_opencast');
} else if ($code != 200) {
throw new opencast_connection_exception('unexpected_api_response', 'block_opencast');
if ($code != 200) {
throw new opencast_api_response_exception($response);
}

$newmediapackage = $response['body'];
return $newmediapackage;
}

Expand All @@ -232,20 +233,18 @@ public function ingest_add_track($mediapackage, $flavor, $file) {
* @return string
* @throws dml_exception
* @throws moodle_exception
* @throws opencast_connection_exception
* @throws opencast_api_response_exception
*/
public function ingest_add_attachment($mediapackage, $flavor, $file) {
$ingestapi = $this->get_ingest_api();
$response = $ingestapi->addAttachment($mediapackage, $flavor, $file);
$code = $response['code'];
$newmediapackage = $response['body'];

if ($code === 0) {
throw new opencast_connection_exception('connection_failure', 'block_opencast');
} else if ($code != 200) {
throw new opencast_connection_exception('unexpected_api_response', 'block_opencast');
if ($code != 200) {
throw new opencast_api_response_exception($response);
}

$newmediapackage = $response['body'];
return $newmediapackage;
}

Expand All @@ -257,7 +256,7 @@ public function ingest_add_attachment($mediapackage, $flavor, $file) {
* @return string Workflow instance that was started
* @throws dml_exception
* @throws moodle_exception
* @throws opencast_connection_exception
* @throws opencast_api_response_exception
*/
public function ingest($mediapackage, $uploadworkflow = '', $workflowconfiguration = []) {
$ingestapi = $this->get_ingest_api();
Expand All @@ -275,14 +274,12 @@ public function ingest($mediapackage, $uploadworkflow = '', $workflowconfigurati
}

$code = $response['code'];
$workflow = $response['body'];

if ($code === 0) {
throw new opencast_connection_exception('connection_failure', 'block_opencast');
} else if ($code != 200) {
throw new opencast_connection_exception('unexpected_api_response', 'block_opencast');
if ($code != 200) {
throw new opencast_api_response_exception($response);
}

$workflow = $response['body'];
return $workflow;
}

Expand Down Expand Up @@ -356,10 +353,8 @@ public function get_block_videos($courseid, $withmetadata = false) {
$response = $this->api->opencastapi->eventsApi->getBySeries($s->series, $params);
$code = $response['code'];

if ($code === 0) {
throw new opencast_connection_exception('connection_failure', 'block_opencast');
} else if ($code != 200) {
throw new opencast_connection_exception('unexpected_api_response', 'block_opencast');
if ($code != 200) {
throw new opencast_api_response_exception($response);
}

$videos = $response['body'];
Expand Down Expand Up @@ -773,10 +768,8 @@ public function get_multiple_series_by_identifier($allseries) {
$response = $this->api->opencastapi->seriesApi->getAll($params);
$code = $response['code'];

if ($code === 0) {
throw new opencast_connection_exception('connection_failure', 'block_opencast');
} else if ($code != 200) {
throw new opencast_connection_exception('unexpected_api_response', 'block_opencast');
if ($code != 200) {
throw new opencast_api_response_exception($response);
}

$series = $response['body'];
Expand Down Expand Up @@ -1836,34 +1829,33 @@ public function get_existing_workflows($tags = [], $onlynames = true, $withconfi

$response = $this->api->opencastapi->workflowsApi->getAllDefinitions($queryparams);
$code = $response['code'];
if ($code === 200) {
$returnedworkflows = $response['body'];

// Lookup and filter workflow definitions by tags.
if (count($tags) > 1) {
$returnedworkflows = array_filter($returnedworkflows, function ($wd) use ($tags) {
return !empty(array_intersect($wd->tags, $tags));
});
}

if (!$onlynames) {
return $returnedworkflows;
}
if ($code != 200) {
throw new opencast_api_response_exception($response);
}

foreach ($returnedworkflows as $workflow) {
$returnedworkflows = $response['body'];

if (object_property_exists($workflow, 'title') && !empty($workflow->title)) {
$workflows[$workflow->identifier] = $workflow->title;
} else {
$workflows[$workflow->identifier] = $workflow->identifier;
}
// Lookup and filter workflow definitions by tags.
if (count($tags) > 1) {
$returnedworkflows = array_filter($returnedworkflows, function ($wd) use ($tags) {
return !empty(array_intersect($wd->tags, $tags));
});
}

if (!$onlynames) {
return $returnedworkflows;
}

foreach ($returnedworkflows as $workflow) {

if (object_property_exists($workflow, 'title') && !empty($workflow->title)) {
$workflows[$workflow->identifier] = $workflow->title;
} else {
$workflows[$workflow->identifier] = $workflow->identifier;
}
return $workflows;
} else if ($code == 0) {
throw new opencast_connection_exception('connection_failure', 'block_opencast');
} else {
throw new opencast_connection_exception('unexpected_api_response', 'block_opencast', '', null, $code);
}
return $workflows;
}

/**
Expand Down Expand Up @@ -2851,16 +2843,16 @@ public function get_lti_consumersecret() {
* @return string event's mediapackage
* @throws dml_exception
* @throws moodle_exception
* @throws opencast_connection_exception
* @throws opencast_api_response_exception
*/
public function get_event_media_package($eventid) {
$response = $this->api->opencastrestclient->performGet("/api/episode/{$eventid}");
$code = $response['code'];
if ($code === 0) {
throw new opencast_connection_exception('connection_failure', 'block_opencast');
} else if ($code != 200) {
throw new opencast_connection_exception('unexpected_api_response', 'block_opencast');

if ($code != 200) {
throw new opencast_api_response_exception($response);
}

$mediapackage = $response['body'];
return $mediapackage;
}
Expand Down Expand Up @@ -2948,16 +2940,17 @@ public function set_duplicated_event_visibility($duplicatedeventid, $sourceevent
* Get the opencast version.
*
* @return string semantic version number of the opencast server.
* @throws opencast_api_response_exception
*/
public function get_opencast_version() {
$response = $this->api->opencastapi->sysinfo->getVersion();
$code = $response['code'];
$versionobject = $response['body'];
if ($code === 0) {
throw new opencast_connection_exception('connection_failure', 'block_opencast');
} else if ($code != 200) {
throw new opencast_connection_exception('unexpected_api_response', 'block_opencast');

if ($code != 200) {
throw new opencast_api_response_exception($response);
}

$versionobject = $response['body'];
return $versionobject->version;
}

Expand All @@ -2971,15 +2964,14 @@ public function get_opencast_version() {
* @param boolean $overwrite whether to overwrite the existing one.
*
* @return boolean true, if the track is added.
* @throws opencast_connection_exception
* @throws opencast_api_response_exception
*/
public function event_add_track($identifier, $flavor, $file, $overwrite = true) {
$response = $this->api->opencastapi->eventsApi->addTrack($identifier, $flavor, $file, $overwrite);
$code = $response['code'];
if ($code === 0) {
throw new opencast_connection_exception('connection_failure', 'block_opencast');
} else if ($code != 200) {
throw new opencast_connection_exception('unexpected_api_response', 'block_opencast');

if ($code != 200) {
throw new opencast_api_response_exception($response);
}
return true;
}
Expand Down
Loading
Loading