Skip to content
Snippets Groups Projects
Commit 7a3a4a6c authored by efalcy's avatar efalcy
Browse files

dev #73934 : retrocompatibility bibliondemand

parent 42dfc826
Branches
Tags
3 merge requests!2660Master,!2619Dev#73934 explo suivi bibliondemand,!2610dev #73934 : explo bibliondemand , cosmogrammme can handle bibliondemand xml file
Pipeline #3938 canceled with stage
in 8 minutes and 10 seconds
......@@ -62,25 +62,22 @@ abstract class Class_Cosmogramme_FileParser {
public function __construct($file, $position, $profil) {
$this->_buffer = '';
$this->_position = $position;
$this->_profil = $profil;
$fileSystem = $this->getFileSystem();
$this->_file_handle = @$fileSystem->fopen($file, 'rb');
if (!$this->_file_handle) {
$this->_errors[] = 'Impossible d\'ouvrit le fichier :' . $file;
return false;
}
;
if (false === ($this->_file_handle = @$fileSystem->fopen($file, 'rb')))
return;
$this->_position = $position;
$this->_goto($position);
$this->_buffer = '';
$this->_file_size = $fileSystem->filesize($file);
$this->_profil = $profil;
return true;
}
public function isValid() {
return empty($this->_errors);
return false !== $this->_file_handle;
}
......@@ -214,21 +211,21 @@ class Class_Cosmogramme_FileParser_Xml extends Class_Cosmogramme_FileParser {
public function __construct($file, $position, $profil) {
parent::__construct($file, $position, $profil);
if (!$this->isValid())
return;
$data = $profil->getAttributs();
$data = $this->_profil->getAttributs();
$attributs = unserialize($data);
$this->_checkErrors();
if (array_key_exists(5, $attributs)
&& array_key_exists('xml_balise_abonne', $attributs[5]))
$this->_xml_separator = $attributs[5]['xml_balise_abonne'];
}
protected function _checkErrors() {
$this->_xml_separator = $attributs[5]['xml_balise_abonne'];
if (!$this->_xml_separator) {
$this->_errors[] = 'La balise Xml qui sépare les enregistrements n\'est pas définie.';
}
public function isValid() {
return parent::isValid() && $this->_xml_separator;
}
protected function _next() {
$start_record = '<' . $this->_xml_separator . '>';
$end_record = '</' . $this->_xml_separator . '>';
......@@ -270,22 +267,12 @@ class Class_Cosmogramme_FileParser_Xml extends Class_Cosmogramme_FileParser {
class Class_Cosmogramme_FileParser_OaiDC extends Class_Cosmogramme_FileParser_Xml {
public function __construct($file, $position, $profil) {
$this->_xml_separator = 'record';
parent::__construct($file, $position, $profil);
$data = $profil->getAttributs();
$attributs = unserialize($data);
return new Class_Cosmogramme_FileParser_Record($data);
}
protected function _checkErrors() {
$this->_xml_separator = 'record';
}
}
class Class_Cosmogramme_FileParser_Csv extends Class_Cosmogramme_FileParser_Ascii {
protected $_separator = ',';
}
?>
\ No newline at end of file
}
\ No newline at end of file
......@@ -24,6 +24,8 @@ class Class_Cosmogramme_Integration_Record_Bibliondemand extends Class_Cosmogram
protected function _parseDatas($data) {
if (is_array($data))
return $data;
$parser = new Class_WebService_OAI_DublinCoreParser_Bibliondemand();
return $parser->parse($data)[0];
}
......
......@@ -54,12 +54,24 @@ abstract class AbstractRecordPhaseBibliondemandTestCase extends PhaseNoticeTestC
$this->fixture('Class_IntBib',
['id' => 3,
'nom_court' => 'Bibliondemand']);
$this->_prepareIntegration();
}
protected function _prepareIntegration() {
Class_Cosmogramme_Integration::find(999)
->setIdBib(3)
->setFichier('Bibliondemand.xml')
->setFichier('http://oai.bibliondemand.com/oaiserver.ashx?verb=ListRecords&metadataPrefix=oai_dc&set=CG62')
->save();
$xml = file_get_contents(__DIR__.'/Bibliondemand.xml');
$webclient = $this->mock();
$webclient->whenCalled('open_url')
->with('http://oai.bibliondemand.com/oaiserver.ashx?verb=ListRecords&metadataPrefix=oai_dc&set=CG62')
->answers($xml)
->beStrict();
Class_WebService_OAI::setDefaultHttpClient($webclient);
}
......@@ -206,7 +218,6 @@ class RecordPhaseBibliondemandSimpleTest extends AbstractRecordPhaseBibliondeman
class RecordPhaseBibliondemandUpdateTest extends AbstractRecordPhaseBibliondemandTestCase {
public function _prepareFixtures() {
parent::_prepareFixtures();
......@@ -216,7 +227,7 @@ class RecordPhaseBibliondemandUpdateTest extends AbstractRecordPhaseBibliondeman
->save();
$record = $this->fixture('Class_Notice',
$record = $this->fixture('Class_Notice',
['id' => 1,
'type_doc' => 16,
'alpha_titre' => 'PIERO SOFFICI',
......@@ -252,4 +263,29 @@ class RecordPhaseBibliondemandUpdateTest extends AbstractRecordPhaseBibliondeman
public function typeDocShouldStay16() {
$this->assertEquals(16, $this->_record->getTypeDoc());
}
}
class RecordPhaseBibliondemandSimpleFileTest extends RecordPhaseBibliondemandSimpleTest {
protected function _prepareIntegration() {
Class_Cosmogramme_Integration::find(999)
->setIdBib(3)
->setFichier('Bibliondemand.xml')
->save();
}
}
class RecordPhaseBibliondemandUpdateFileTest extends RecordPhaseBibliondemandUpdateTest {
protected function _prepareIntegration() {
Class_Cosmogramme_Integration::find(999)
->setIdBib(3)
->setFichier('Bibliondemand.xml')
->save();
}
}
\ 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