Skip to content
Snippets Groups Projects
Commit fab27231 authored by Henri-Damien LAURENT's avatar Henri-Damien LAURENT
Browse files

Merge branch 'hotline#183834_moissonnage_artevod_plante' into 'master'

hotline#183834 : ArteVOD : Better failure management for Film Reader

See merge request !4803
parents 2ac92969 01f47ad3
1 merge request!4803hotline#183834 : ArteVOD : Better failure management for Film Reader
Pipeline #24958 passed with stage
in 52 minutes and 20 seconds
- correctif #183834 : ArteVOD : Meilleure gestion d'erreurs dans les données exposées par ArteVOD
\ No newline at end of file
......@@ -31,11 +31,10 @@ class ArteVod_Service_Film
$this->setId($json['id'])
->setTitle($json['title'])
->setDescription($json['description'])
->addActors(isset($json['actors']) ?
$json['actors'] : [])
->addActors($json['actors'] ?? [])
->setDuration($json['duration'])
->addMedias(isset($json['medias']) ? $json['medias'] : [])
->addThemes($json['themes']);
->addMedias($json['medias'] ?? [])
->addThemes($json['themes'] ?? []);
if (isset($json['genres']))
$this->setGenres($json['genres']);
......@@ -55,19 +54,19 @@ class ArteVod_Service_Film
protected function _setCustomFields($json) {
$this->addPoster($json['posterUrl'])
->setDirectors($json['directors'])
->setDirectors($json['directors'] ?? [])
->setExternalUri($json['url']);
return $this;
}
protected function setDirectors($directors) {
protected function setDirectors(array $directors) {
$this->_directors = $directors;
return $this;
}
protected function addMedias($medias) {
protected function addMedias(array $medias) {
array_map([$this,'addMedia'],
$medias);
return $this;
......@@ -84,14 +83,14 @@ class ArteVod_Service_Film
}
protected function addThemes($themes) {
protected function addThemes(array $themes) {
array_map([$this, 'addTag'],
$themes);
return $this;
}
protected function setGenres($genre) {
protected function setGenres(array $genre) {
array_map([$this, 'addMatiere'],
$genre);
return $this;
......@@ -105,7 +104,7 @@ class ArteVod_Service_Film
public function fillAlbum(Class_Album $album) : self {
$this->setTypeDoc($album)
->setDuration($this->_duration.' mn')
->setTags($this->getTags());
->setTags($this->getTags() ?? []);
foreach ($this->_directors as $director)
$this->_fillDirectorIn($album, $director);
......@@ -131,7 +130,7 @@ class ArteVod_Service_Film
}
public function addActors($actors) {
public function addActors(array $actors) {
$this->_actors = $actors;
return $this;
}
......
......@@ -20,11 +20,17 @@
*/
class ArteVod_Service_FilmsReader {
protected $_films;
protected array $_films = [];
public function parse(string $json) {
if (FALSE !== strpos($json,'"content":null'))
return $this;
if (! is_array($objects = json_decode($json, true)))
return $this;
public function parse($json) {
$this->_films = array_map([$this, 'parseFilm'],
json_decode($json, true));
$objects);
return $this;
}
......
......@@ -30,11 +30,21 @@ class ArteVodFixtures {
public static function secondPage() {
return '[{"id":7002,"title":"Manon 20 ans","description":"<p>Envoyée en centre éducatif fermé après avoir poignardé sa mère, Manon a six mois pour faire ses preuves. Une minisérie à la puissance émotionnelle bouleversante, récompensée du Fipa d&#39;or, avec Alba Gaïa Bellugi et Marina Foïs.</p>","themes":[],"productionYear":null,"posterUrl":"https://vod.mediatheque-numerique.com/media/59/3a/593a5d947c887.jpeg","trailerUrl":null,"url":"https://vod.mediatheque-numerique.com/films/manon-20-ans","duration":10080,"audioLanguages":[],"directors":[],"actors":[],"publicationDate":"2017-06-09","genres":["Cinéma","Série TV"],"productionCountry":null,"codes":[],"medias":[{"type":"POSTER","url":"https://vod.mediatheque-numerique.com/media/59/3a/593a5d947c887.jpeg","modificationDate":"2017-06-09T10:34:28"}],"rate":null,"comments":[],"commentsLibrary":[],"bonus":[],"availableCountries":[{"type":"Country","code":"BE"},{"type":"Country","code":"BG"},{"type":"Country","code":"CH"},{"type":"Country","code":"CZ"},{"type":"Country","code":"CY"},{"type":"Country","code":"RO"},{"type":"Country","code":"GR"},{"type":"Country","code":"SK"},{"type":"Country","code":"SI"},{"type":"Country","code":"SE"},{"type":"Country","code":"FR"},{"type":"Country","code":"DK"},{"type":"Country","code":"HU"},{"type":"Country","code":"LT"},{"type":"Country","code":"PT"},{"type":"Country","code":"TR"},{"type":"Country","code":"LI"},{"type":"Country","code":"LV"},{"type":"Country","code":"PL"},{"type":"Country","code":"LU"},{"type":"Country","code":"EE"},{"type":"Country","code":"DE"},{"type":"Country","code":"IT"},{"type":"Country","code":"ES"},{"type":"Country","code":"HR"},{"type":"Country","code":"IS"},{"type":"Country","code":"AT"},{"type":"Country","code":"MT"},{"type":"Country","code":"IE"},{"type":"Country","code":"UK"},{"type":"Country","code":"FI"},{"type":"Country","code":"NL"},{"type":"Country","code":"NO"}],"targetAudiences":[]},{"id":7009,"title":"Squadra Criminale","description":"<p>Douze meurtres. Douze histoires de crimes...<br />\r\nCapitaine à la brigade criminelle de Turin, Valeria Ferro est une enquêtrice aussi tenace que talentueuse. Elle semble posséder un sixième sens pour reconstituer le puzzle complexe de chaque affaire tout en luttant contre les fantômes de son passé. Ceux-ci resurgissent violemment dans sa vie au moment où sa mère est libérée de prison.</p>","themes":[],"productionYear":null,"posterUrl":"https://vod.mediatheque-numerique.com/media/59/3a/593a6efba55d1.jpeg","trailerUrl":"https://media.universcine.com/cd/b5/cdb57adc-2a49-11e7-b234-bdefb096dc40.mp4","url":"https://vod.mediatheque-numerique.com/films/squadra-criminale","duration":35400,"audioLanguages":[],"directors":[],"actors":[],"publicationDate":"2017-06-09","genres":["Série TV"],"productionCountry":null,"codes":[],"medias":[{"type":"POSTER","url":"https://vod.mediatheque-numerique.com/media/59/3a/593a6efba55d1.jpeg","modificationDate":"2017-06-09T11:48:43"}],"rate":null,"comments":[],"commentsLibrary":[],"bonus":[],"availableCountries":[{"type":"Country","code":"NC"},{"type":"Country","code":"BE"},{"type":"Country","code":"PF"},{"type":"Country","code":"GP"},{"type":"Country","code":"WF"},{"type":"Country","code":"GF"},{"type":"Country","code":"CH"},{"type":"Country","code":"PM"},{"type":"Country","code":"YT"},{"type":"Country","code":"FR"},{"type":"Country","code":"MF"},{"type":"Country","code":"AD"},{"type":"Country","code":"RE"},{"type":"Country","code":"MQ"},{"type":"Country","code":"MC"}],"targetAudiences":[]}]';
return '[{"id":7002,"title":"Manon 20 ans","description":"<p>Envoyée en centre éducatif fermé après avoir poignardé sa mère, Manon a six mois pour faire ses preuves. Une minisérie à la puissance émotionnelle bouleversante, récompensée du Fipa d&#39;or, avec Alba Gaïa Bellugi et Marina Foïs.</p>","themes":[],"productionYear":null,"posterUrl":"https://vod.mediatheque-numerique.com/media/59/3a/593a5d947c887.jpeg","trailerUrl":null,"url":"https://vod.mediatheque-numerique.com/films/manon-20-ans","duration":10080,"audioLanguages":[],"actors":[],"publicationDate":"2017-06-09","genres":["Cinéma","Série TV"],"productionCountry":null,"codes":[],"medias":[{"type":"POSTER","url":"https://vod.mediatheque-numerique.com/media/59/3a/593a5d947c887.jpeg","modificationDate":"2017-06-09T10:34:28"}],"rate":null,"comments":[],"commentsLibrary":[],"bonus":[],"availableCountries":[{"type":"Country","code":"BE"},{"type":"Country","code":"BG"},{"type":"Country","code":"CH"},{"type":"Country","code":"CZ"},{"type":"Country","code":"CY"},{"type":"Country","code":"RO"},{"type":"Country","code":"GR"},{"type":"Country","code":"SK"},{"type":"Country","code":"SI"},{"type":"Country","code":"SE"},{"type":"Country","code":"FR"},{"type":"Country","code":"DK"},{"type":"Country","code":"HU"},{"type":"Country","code":"LT"},{"type":"Country","code":"PT"},{"type":"Country","code":"TR"},{"type":"Country","code":"LI"},{"type":"Country","code":"LV"},{"type":"Country","code":"PL"},{"type":"Country","code":"LU"},{"type":"Country","code":"EE"},{"type":"Country","code":"DE"},{"type":"Country","code":"IT"},{"type":"Country","code":"ES"},{"type":"Country","code":"HR"},{"type":"Country","code":"IS"},{"type":"Country","code":"AT"},{"type":"Country","code":"MT"},{"type":"Country","code":"IE"},{"type":"Country","code":"UK"},{"type":"Country","code":"FI"},{"type":"Country","code":"NL"},{"type":"Country","code":"NO"}],"targetAudiences":[]},{"id":7009,"title":"Squadra Criminale","description":"<p>Douze meurtres. Douze histoires de crimes...<br />\r\nCapitaine à la brigade criminelle de Turin, Valeria Ferro est une enquêtrice aussi tenace que talentueuse. Elle semble posséder un sixième sens pour reconstituer le puzzle complexe de chaque affaire tout en luttant contre les fantômes de son passé. Ceux-ci resurgissent violemment dans sa vie au moment où sa mère est libérée de prison.</p>","productionYear":null,"posterUrl":"https://vod.mediatheque-numerique.com/media/59/3a/593a6efba55d1.jpeg","trailerUrl":"https://media.universcine.com/cd/b5/cdb57adc-2a49-11e7-b234-bdefb096dc40.mp4","url":"https://vod.mediatheque-numerique.com/films/squadra-criminale","duration":35400,"audioLanguages":[],"publicationDate":"2017-06-09","genres":["Série TV"],"productionCountry":null,"codes":[],"medias":[{"type":"POSTER","url":"https://vod.mediatheque-numerique.com/media/59/3a/593a6efba55d1.jpeg","modificationDate":"2017-06-09T11:48:43"}],"rate":null,"comments":[],"commentsLibrary":[],"bonus":[],"availableCountries":[{"type":"Country","code":"NC"},{"type":"Country","code":"BE"},{"type":"Country","code":"PF"},{"type":"Country","code":"GP"},{"type":"Country","code":"WF"},{"type":"Country","code":"GF"},{"type":"Country","code":"CH"},{"type":"Country","code":"PM"},{"type":"Country","code":"YT"},{"type":"Country","code":"FR"},{"type":"Country","code":"MF"},{"type":"Country","code":"AD"},{"type":"Country","code":"RE"},{"type":"Country","code":"MQ"},{"type":"Country","code":"MC"}],"targetAudiences":[]}]';
}
public static function emptyPage() {
return '[]';
}
public static function nullContentPage() {
return '{"content":null}';
}
public static function brokenJsonPage() {
return '{"content":null';
}
}
......@@ -421,3 +421,35 @@ class ArteVodWebClientTest extends ModelTestCase {
Class_WebService_WaitingSimpleWebClient::class));
}
}
class ArteVodHarverstingNullContentPageTest extends ArteVodHarverstingTestCase {
public function setUp() {
parent::setUp();
foreach(['1' => ArteVodFixtures::nullContentPage(),
'2' => ArteVodFixtures::brokenJsonPage(),
'3' => ArteVodFixtures::emptyPage()]
as $page => $answer) {
$this->_web_client
->whenCalled('open_url')
->with('https://mednumv3-backapi.lab.arte.tv/api/v1/films?page_nb=' . $page . '&q_country=FR')
->answers($answer);
}
$this->_web_client
->whenCalled('setConfig')->with(['timeout' => 10])->answers($this->_web_client)
->beStrict();
$this->_service->harvest();
}
/** @test */
public function shouldHaveDeletedAllAlbum() {
$this->assertEquals(0, count(Class_Album::findAll()));
}
}
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment