Skip to content

Commit

Permalink
improvements
Browse files Browse the repository at this point in the history
  • Loading branch information
ferishili committed Jun 13, 2024
1 parent fc1c4df commit e9a6a59
Show file tree
Hide file tree
Showing 6 changed files with 37 additions and 25 deletions.
12 changes: 5 additions & 7 deletions src/OpencastApi/Opencast.php
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,7 @@ class Opencast
'connect_timeout' => 0 // The API connection timeout. In seconds (default 0 to wait indefinitely) (optional)
'version' => null // The API Version. (Default null). (optional)
'handler' => null // The callable Handler or HandlerStack. (Default null). (optional)
'features' => null // A set of additional features [e.g. lucene search]. (Default null). (optional)
]
$engageConfig = [
Expand All @@ -91,6 +92,7 @@ class Opencast
'connect_timeout' => 0 // The API connection timeout. In seconds (default 0 to wait indefinitely) (optional)
'version' => null // The API Version. (Default null). (optional)
'handler' => null // The callable Handler or HandlerStack. (Default null). (optional)
'features' => null // A set of additional features [e.g. lucene search]. (Default null). (optional)
]
*/
/**
Expand Down Expand Up @@ -133,13 +135,6 @@ private function setEndpointProperties($config, $enableingest)
// NOTE: services must be instantiated before calling setIngest method!
$this->setIngestProperty($config);
}

// allow to disable lucene search present only up to oc 15, default is enabled
if (isset($config['features']['lucene'])
&& $config['features']['lucene'] == false
) {
$this->search->lucene = false;
}
}

private function excludeFilters()
Expand Down Expand Up @@ -178,6 +173,9 @@ private function setEngageRestClient($config, $engageConfig)
if (!isset($engageConfig['handler']) && isset($config['handler'])) {
$engageConfig['handler'] = $config['handler'];
}
if (!isset($engageConfig['features']) && isset($config['features'])) {
$engageConfig['features'] = $config['features'];
}
$this->engageRestClient = new OcRestClient($engageConfig);
}

Expand Down
22 changes: 20 additions & 2 deletions src/OpencastApi/Rest/OcRestClient.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,15 +17,17 @@ class OcRestClient extends Client
private $additionalHeaders = [];
private $noHeader = false;
private $origin;
private $features = [];
/*
$config = [
'url' => 'https://develop.opencast.org/', // The API url of the opencast instance (required)
'username' => 'admin', // The API username. (required)
'password' => 'opencast', // The API password. (required)
'timeout' => 0, // The API timeout. In seconds (default 0 to wait indefinitely). (optional)
'connect_timeout' => 0, // The API connection timeout. In seconds (default 0 to wait indefinitely) (optional)
'version' => null // The API Version. (Default null). (optional)
'handler' => null // The callable Handler or HandlerStack. (Default null). (optional)
'version' => null, // The API Version. (Default null). (optional)
'handler' => null, // The callable Handler or HandlerStack. (Default null). (optional)
'features' => null // A set of additional features [e.g. lucene search]. (Default null). (optional)
]
*/
public function __construct($config)
Expand All @@ -51,9 +53,25 @@ public function __construct($config)
if (isset($config['handler']) && is_callable($config['handler'])) {
$parentConstructorConfig['handler'] = $config['handler'];
}

if (isset($config['features'])) {
$this->features = $config['features'];
}

parent::__construct($parentConstructorConfig);
}

public function readFeatures($key = null) {
if (empty($key)) {
return $this->features;
}

if (isset($this->features[$key])) {
return $this->features[$key];
}
return false;
}

public function registerHeaderException($header, $path) {
$path = ltrim($path, '/');
if (!isset($this->headerExceptions[$header]) || !in_array($path, $this->headerExceptions[$header])) {
Expand Down
11 changes: 8 additions & 3 deletions src/OpencastApi/Rest/OcSearch.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,15 @@
class OcSearch extends OcRest
{
const URI = '/search';
public $lucene = true;
public $lucene = false; // By default false, main support for OC 16.

public function __construct($restClient)
{
$restClient->registerHeaderException('Accept', self::URI);
parent::__construct($restClient);
if ($restClient->readFeatures('lucene')) {
$this->lucene = true;
}
}


Expand Down Expand Up @@ -114,6 +117,8 @@ public function getEpisodes($params = [], $format = '')
/**
* Search a lucene query as object (JSON) by default or XML (text) on demand.
*
* INFO: This endpoint is removed in Opencast 16.
*
* @param array $params the params to pass to the call: it must cointain the following:
* $params = [
* 'q' => '{ The lucene query. }',
Expand All @@ -131,7 +136,7 @@ public function getEpisodes($params = [], $format = '')
public function getLucene($params = [], $format = '')
{
if (!$this->lucene) {
return false;
return ['code' => 410, 'reason' => 'Lucene search endpoint is not available!'];
}

$uri = self::URI . "/lucene.json";
Expand Down Expand Up @@ -271,4 +276,4 @@ public function getSeries($params = [], $format = '')
return $this->restClient->performGet($uri, $options);
}
}
?>
?>
2 changes: 1 addition & 1 deletion tests/DataProvider/SetupDataProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ public static function getConfig($version = ''): array
'username' => $username,
'password' => $password,
'timeout' => $timeout,
'version' => '1.9.0',
'version' => '1.11.0',
'connect_timeout' => $connectTimeout,
'features' => [
'lucene' => false
Expand Down
8 changes: 2 additions & 6 deletions tests/Unit/OcSearchTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -42,12 +42,8 @@ public function get_series($params, $format): void
*/
public function get_lucenes($params, $format): void
{
if ($this->ocSearch->lucene) {
$response = $this->ocSearch->getLucene($params, $format);
$this->assertSame(200, $response['code'], 'Failure to search lucene');
} else {
$this->assertTrue(true);
}
$response = $this->ocSearch->getLucene($params, $format);
$this->assertContains($response['code'], [200, 410], 'Failure to create an event');
}
}
?>
7 changes: 1 addition & 6 deletions tests/UnitMock/OcSearchTestMock.php
Original file line number Diff line number Diff line change
Expand Up @@ -40,12 +40,7 @@ public function get_lucenes(): void
{
$params = ['series' => true];
$response = $this->ocSearch->getLucene($params);

if ($this->ocSearch->lucene) {
$this->assertSame(200, $response['code'], 'Failure to search lucene');
} else {
$this->assertFalse($response);
}
$this->assertContains($response['code'], [200, 410], 'Failure to create an event');
}

/**
Expand Down

0 comments on commit e9a6a59

Please sign in to comment.