Skip to content
Snippets Groups Projects
Commit 832c27f5 authored by efalcy's avatar efalcy
Browse files

dev #21332 1D touch: fill albums with data

parent 89031664
Branches
Tags 6.20
4 merge requests!780Master,!736Dev#21332 onedtouch harvest,!728Dev#21332 onedtouch harvest,!725Dev#21332 onedtouch harvest
......@@ -23,7 +23,7 @@
class Class_WebService_BibNumerique_OneDTouch_Album extends Class_WebService_BibNumerique_RessourceNumerique {
public function getBaseUrl(){
return Class_WebService_BibNumerique_OneDTouch::BASE_URL;
return Class_AdminVar::get('ONEDTOUCH_URL');
}
......@@ -42,10 +42,8 @@ class Class_WebService_BibNumerique_OneDTouch_Album extends Class_WebService_Bib
}
public function setOaiId($data) {
$result = split('=', $data);
$this->_id = ($result) ? $result[1] : '';
$this->setExternalURI($data);
$this->_id = $data;
}
}
?>
\ No newline at end of file
?>
......@@ -25,7 +25,7 @@ class Class_WebService_BibNumerique_OneDTouch_AlbumsReader extends Class_WebSer
protected $_page_number;
protected $_page_size;
protected $_ressourcesNumeriques;
protected $livres;
protected $albums;
protected $_logger;
......@@ -38,27 +38,31 @@ class Class_WebService_BibNumerique_OneDTouch_AlbumsReader extends Class_WebSer
public function parse($xml) {
$this->_total_count = $this->_page_number = 0;
$this->_page_size = 1;
$this->livres = [];
$this->albums = [];
$url = Class_AdminVar::get('ONEDTOUCH_URL');
$oaiws = new Class_WebService_OAI();
$oaiws->setMetadataPrefix('oai1dtouch_dc');
$listsize = ($this->_resumptionToken) ? $this->_resumptionToken->getListSize() : '100';
$this->getLogger()->info($listsize .' ressources dans la base');
$this->livres = $oaiws
$dc_parser= new Class_WebService_OneDTouchDCParser();
$this->albums = $oaiws
->setParser($dc_parser)
->setOAIHandler($url)
->setNumericResourceClass('Class_WebService_BibNumerique_OneDTouch_Album')
->getRecordsResourcesNumerique();
while ($oaiws->hasNextRecords())
$this->livres = array_merge($this->livres, $oaiws->getNextNumericResources());
$this->albums = array_merge($this->albums, $oaiws->getNextNumericResources());
$this->_total_count = sizeof($this->livres);
$this->_total_count = sizeof($this->albums);
$this->_page_number = 1;
$this->_page_size = $this->_total_count;
return $this;
}
public function endTitle($data) {
$this->enddc_title($data);
}
public function getTotalCount() {
return $this->_total_count;
......@@ -76,13 +80,13 @@ class Class_WebService_BibNumerique_OneDTouch_AlbumsReader extends Class_WebSer
public function setRecords($records) {
$this->livres=$records;
$this->albums=$records;
}
public function getRessourcesNumeriques() {
return $this->livres;
return $this->albums;
}
}
?>
\ No newline at end of file
?>
......@@ -47,16 +47,16 @@ class Class_WebService_DublinCoreParser {
public function parse($xml) {
$parser = Class_WebService_XMLParser::newInstance();
$parser->keepNameSpace();
$parser->setElementHandler($this);
$parser->parse($xml);
$this->parser = Class_WebService_XMLParser::newInstance();
$this->parser->keepNameSpace();
$this->parser->setElementHandler($this);
$this->parser->parse($xml);
return $this->_records;
}
public function startrecord($parser, $attributes) {
public function startRecord($attributes) {
$this->_record=[];
$this->ressource_numerique= $this->visitor->getNewRessourceNumerique();
$this->_records_ressources[]=$this->ressource_numerique;
......@@ -154,4 +154,4 @@ class Class_WebService_DublinCoreParser {
}
?>
\ No newline at end of file
?>
......@@ -50,6 +50,10 @@ class Class_WebService_OAI extends Class_WebService_Abstract {
}
public function __construct() {
$this->parser = new Class_WebService_DublinCoreParser();
}
public function setOAIHandler($oai_handler) {
$this->oai_handler = $oai_handler;
......@@ -123,6 +127,10 @@ class Class_WebService_OAI extends Class_WebService_Abstract {
return $this->getRecordsFromSet($set);
}
public function setParser($parser) {
$this->parser = $parser;
return $this;
}
public function getRecordsResourcesNumerique() {
$xml_data = $this->oaiAsks(self::ListRecords,
......@@ -142,19 +150,18 @@ class Class_WebService_OAI extends Class_WebService_Abstract {
public function parseListRecordsXML($xml_data) {
$parser = new Class_WebService_DublinCoreParser();
$parser->parse($xml_data);
$this->setListRecordsResumptionToken($parser->getResumptionToken());
return $parser->getRecords();
$this->parser->parse($xml_data);
$this->setListRecordsResumptionToken($this->parser->getResumptionToken());
return $this->parser->getRecords();
}
public function parseListRecordsRessourcesNumeriqueXML($xml_data) {
$parser = new Class_WebService_DublinCoreParser();
$parser->acceptVisitor($this);
$parser->parse($xml_data);
$this->setListRecordsResumptionToken($parser->getResumptionToken());
return $parser->getRecordsRessourceNumeriques();
$this->parser->acceptVisitor($this);
$this->parser->parse($xml_data);
$this->setListRecordsResumptionToken($this->parser->getResumptionToken());
return $this->parser->getRecordsRessourceNumeriques();
}
......@@ -208,4 +215,4 @@ class Class_WebService_OAI extends Class_WebService_Abstract {
}
}
?>
\ No newline at end of file
?>
......@@ -28,10 +28,47 @@
* les enregistrements suivants
*/
class Class_WebService_OneDTouchDCParser extends Class_WebService_DublinCoreParser{
protected function start_record($parser, $attributes) {
public function endId($data) {
$this->enddc_identifier($data);
}
protected function end_id($
public function endTitle($data) {
if ($this->parser->getParent()=='track')
return $this->current_track->setTitre($data);
$this->enddc_title($data);
}
public function endUrl($data) {
if ($this->parser->getParent() == 'track') {
return $this->current_track->setUrl($data);
}
$this->ressource_numerique->setExternalUri($data);
}
public function startTrack() {
$this->current_track= new Class_AlbumRessource();
$this->tracks[]=$this->current_track;
}
public function endLabel($data) {
$this->enddc_publisher($data);
}
public function endDescription($data) {
$this->enddc_description($data);
}
public function endCover_url($data) {
$this->ressource_numerique->addPoster($data);
}
public function endArtist($data) {
$this->enddc_creator($data);
}
public function endStyle($data) {
$this->enddc_subject($data);
}
}
?>
\ No newline at end of file
?>
......@@ -7,14 +7,14 @@
<ListRecords>
<record>
<header>
<identifier>oai:oai1dtouch.com:124
<identifier>oai:oai1dtouch.com:128
</identifier>
<datestamp>2015-02-09T08:47:27Z
</datestamp>
</header>
<metadata>
<oai1dtouch_dc xmlns="http://dev.1dtouch.com/OAI/2.0/oai1dtouch_dc/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://dev.1dtouch.com/OAI/2.0/oai1dtouch_dc/ http://dev.1dtouch.com/OAI/2.0/oai1dtouch_dc.xsd">
<id>124
<id>128
</id>
<icpn>3610159181474
</icpn>
......
......@@ -40,6 +40,15 @@ class OneDTouchTest extends Storm_Test_ModelTestCase {
->whenCalled('open_url')
->with('http://dev.1dtouch.com/oai?verb=ListRecords&resumptionToken=oai1dtouch_dc.f%282015-02-09T08%3A46%3A09Z%29.u%282015-02-09T08%3A47%3A27Z%29%3A133')
->answers($catalogue_xml_end)
->whenCalled('open_url')
->with('https://commondatastorage.googleapis.com/music-staging/cargo/medium_3610159181474.jpg')
->answers("image")
->whenCalled('open_url')
->with('https://commondatastorage.googleapis.com/music-staging/cargo/medium_3610159181993.jpg')
->answers("image")
->whenCalled('open_url')
->with('https://commondatastorage.googleapis.com/music-staging/cargo/medium_3610159198724.jpg')
->answers("image")
->beStrict();
$this->onLoaderOfModel('Class_Album')->whenCalled('deleteBy')->answers(true);
......@@ -64,6 +73,47 @@ class OneDTouchTest extends Storm_Test_ModelTestCase {
$this->assertEquals(4, count(Class_Album::findAll()));
}
public function getAlbums() {
return [
[
124,
'titre',
'WOLFEP026',
],
[
124,
'editeur',
'Wolf Music Recordings',
],
[
124,
'authors_names',
['Ishmael'],
],
[
124,
'matiere',
Class_CodifMatiere::findFirstBy(['libelle' => 'Dance'])->getId()
. ';' . Class_CodifMatiere::findFirstBy(['libelle' => 'House'])->getId()
. ';' . Class_CodifMatiere::findFirstBy(['libelle' => 'Deep'])->getId()
],
[
124,
'external_uri',
'http://music.1dtouch.com/albums/124',
],
];
}
/**
* @test
* @dataProvider getAlbums
*/
public function albumFieldsShouldBeAsExpected($id_origine, $field, $value) {
$album = Class_Album::findFirstBy(['id_origine' => $id_origine]);
$this->assertEquals($value, $album->callGetterByAttributeName($field));
}
}
?>
\ No newline at end of file
?>
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