Skip to content
Snippets Groups Projects
Commit e6ada77f authored by Patrick Barroca's avatar Patrick Barroca :grin:
Browse files

hotline #92524 : pmb fix periodic item hols and availability queries

parent 5180bde1
Branches
Tags 5.28
2 merge requests!3384Hotline,!3382hotline #92524 : pmb fix periodic item hols and availability queries
Pipeline #9256 passed with stage
in 45 minutes and 10 seconds
- ticket #92524 : SIGB PMB : Correction des requêtes de disponibilité et de réservation des exemplaires de périodiques
\ No newline at end of file
...@@ -108,6 +108,11 @@ function getBlocsParams($id_bib, $type, $valeurs) { ...@@ -108,6 +108,11 @@ function getBlocsParams($id_bib, $type, $valeurs) {
if (in_array($clef, [COM_PMB, COM_VSMART, COM_MICROBIB, COM_BIBLIXNET, COM_WATERBEAR])) if (in_array($clef, [COM_PMB, COM_VSMART, COM_MICROBIB, COM_BIBLIXNET, COM_WATERBEAR]))
$champs_params[0] = ['url_serveur']; $champs_params[0] = ['url_serveur'];
if (COM_PMB == $clef)
$champs_params[0][] = ['exp_bulletin_is_exp_notice' => function($id, $valeur) {
return getOuiNon($id, $valeur);
}];
if (in_array($clef, [COM_CARTHAME])) if (in_array($clef, [COM_CARTHAME]))
$champs_params[0] = ['url_serveur', 'key','sigb_field_name']; $champs_params[0] = ['url_serveur', 'key','sigb_field_name'];
......
...@@ -21,19 +21,25 @@ ...@@ -21,19 +21,25 @@
class Class_WebService_SIGB_PMB { class Class_WebService_SIGB_PMB {
protected static $service; protected static $services = [];
public static function getService($params) { public static function getService($params) {
if (!isset(self::$service)) { $key = md5(serialize($params));
$instance = new self(); if (isset(static::$services[$key]))
self::$service = Class_WebService_SIGB_PMB_Service::getService($params['url_serveur']); return static::$services[$key];
}
return self::$service; $service = Class_WebService_SIGB_PMB_Service::getService($params['url_serveur']);
if (isset($params['exp_bulletin_is_exp_notice'])
&& '1' == $params['exp_bulletin_is_exp_notice'])
$service->bePeriodicIdWithoutBull();
return static::$services[$key] = $service;
} }
public static function setService($service) { public static function resetServices() {
self::$service = $service; static::$services = [];
} }
} }
\ No newline at end of file
...@@ -30,6 +30,7 @@ class Class_Webservice_SIGB_PMB_Service extends Class_WebService_SIGB_AbstractSe ...@@ -30,6 +30,7 @@ class Class_Webservice_SIGB_PMB_Service extends Class_WebService_SIGB_AbstractSe
protected protected
$_json_web_client, $_json_web_client,
$_pmb_url, $_pmb_url,
$_periodic_id_without_bull = false,
$_user; $_user;
...@@ -63,6 +64,12 @@ class Class_Webservice_SIGB_PMB_Service extends Class_WebService_SIGB_AbstractSe ...@@ -63,6 +64,12 @@ class Class_Webservice_SIGB_PMB_Service extends Class_WebService_SIGB_AbstractSe
} }
public function bePeriodicIdWithoutBull() {
$this->_periodic_id_without_bull = true;
return $this;
}
public function providesAuthentication() { public function providesAuthentication() {
return true; return true;
} }
...@@ -84,20 +91,27 @@ class Class_Webservice_SIGB_PMB_Service extends Class_WebService_SIGB_AbstractSe ...@@ -84,20 +91,27 @@ class Class_Webservice_SIGB_PMB_Service extends Class_WebService_SIGB_AbstractSe
public function reserverExemplaire($user, $exemplaire, $code_annexe) { public function reserverExemplaire($user, $exemplaire, $code_annexe) {
$session_token = $this->openSessionForUser($user); $session_token = $this->openSessionForUser($user);
$json = $this->httpPost('pmbesOPACEmpr_add_resa', [$session_token, $json = $this->httpPost('pmbesOPACEmpr_add_resa',
$exemplaire->getIdOrigine()]); [$session_token, $this->_sanitizeRecordId($exemplaire->getIdOrigine())]);
$result = (array) $this->_getJsonData($json, 'result'); $result = (array) $this->_getJsonData($json, 'result');
if (!$result) if (!$result)
return $this->_error($this->_('Réservation impossible : le service de réservation PMB via webservice est indisponible')); return $this->_error($this->_('Réservation impossible : le service de réservation PMB via webservice est indisponible'));
if(isset($result['error'])) if(isset($result['error']))
return $this->_error($this->_('Réservation impossible : Vous avez déjà réservé cette exemplaire')); return $this->_error($this->_('Réservation impossible : Vous avez déjà réservé cet exemplaire'));
return $this->_success(); return $this->_success();
} }
protected function _sanitizeRecordId($id) {
return $this->_periodic_id_without_bull
? preg_replace('/^(.*)-bull$/', '$1', $id)
: $id;
}
public function supprimerReservation($user, $reservation_id) { public function supprimerReservation($user, $reservation_id) {
$session_token = $this->openSessionForUser($user); $session_token = $this->openSessionForUser($user);
$json = $this->httpPost('pmbesOPACEmpr_delete_resa', [$session_token, $json = $this->httpPost('pmbesOPACEmpr_delete_resa', [$session_token,
...@@ -164,9 +178,11 @@ class Class_Webservice_SIGB_PMB_Service extends Class_WebService_SIGB_AbstractSe ...@@ -164,9 +178,11 @@ class Class_Webservice_SIGB_PMB_Service extends Class_WebService_SIGB_AbstractSe
} }
public function getExemplaire($notice_id, $code_barre){ public function getExemplaire($notice_id, $code_barre) {
$json = $this->httpPost('pmbesItems_fetch_notice_items', [$notice_id]); $json = $this->httpPost('pmbesItems_fetch_notice_items',
[$this->_sanitizeRecordId($notice_id)]);
$items = $this->_getItemsFromJson($json); $items = $this->_getItemsFromJson($json);
return $this->_getItemByBarCode($items, $code_barre); return $this->_getItemByBarCode($items, $code_barre);
} }
......
...@@ -48,10 +48,12 @@ class NoticeAjaxControllerPMBRecordTest extends AbstractControllerTestCase { ...@@ -48,10 +48,12 @@ class NoticeAjaxControllerPMBRecordTest extends AbstractControllerTestCase {
$config['exemplaires']['grouper'] = '1'; $config['exemplaires']['grouper'] = '1';
Class_Profil::getCurrentProfil()->setCfgNotice($config); Class_Profil::getCurrentProfil()->setCfgNotice($config);
$this->fixture('Class_IntBib', $comm_params = ['url_serveur' => 'http://mon-pmb.net/ws/connector_out.php?source_id=2'];
['id' => 31, $int_bib = $this->fixture('Class_IntBib',
'libelle' => 'PMB library', ['id' => 31,
'comm_sigb' => Class_IntBib::COM_PMB]); 'libelle' => 'PMB library',
'comm_sigb' => Class_IntBib::COM_PMB,
'comm_params' => $comm_params]);
$this->fixture('Class_Bib', $this->fixture('Class_Bib',
['id' => 3, ['id' => 3,
...@@ -78,7 +80,7 @@ class NoticeAjaxControllerPMBRecordTest extends AbstractControllerTestCase { ...@@ -78,7 +80,7 @@ class NoticeAjaxControllerPMBRecordTest extends AbstractControllerTestCase {
->answers('') ->answers('')
->beStrict(); ->beStrict();
$this->_service = Class_WebService_SIGB_PMB::getService(['url_serveur' => 'http://mon-pmb.net/ws/connector_out.php?source_id=2']); $this->_service = Class_WebService_SIGB_PMB::getService($int_bib->getModeComm());
$this->_service->setJsonWebClient($this->http_client); $this->_service->setJsonWebClient($this->http_client);
$this->dispatch('/opac/noticeajax/exemplaires/id_notice/2', true); $this->dispatch('/opac/noticeajax/exemplaires/id_notice/2', true);
...@@ -86,7 +88,7 @@ class NoticeAjaxControllerPMBRecordTest extends AbstractControllerTestCase { ...@@ -86,7 +88,7 @@ class NoticeAjaxControllerPMBRecordTest extends AbstractControllerTestCase {
public function tearDown() { public function tearDown() {
Class_WebService_SIGB_PMB::setService(null); Class_WebService_SIGB_PMB::resetServices();
parent::tearDown(); parent::tearDown();
} }
......
...@@ -67,20 +67,21 @@ abstract class PMBTestCase extends ModelTestCase { ...@@ -67,20 +67,21 @@ abstract class PMBTestCase extends ModelTestCase {
->beStrict(); ->beStrict();
$this->_service = Class_WebService_SIGB_PMB::getService(['url_serveur' => 'http://cedre.proxience.net/ws/connector_out.php?source_id=2']); $this->_service = Class_WebService_SIGB_PMB::getService(['url_serveur' => 'http://cedre.proxience.net/ws/connector_out.php?source_id=2',
'exp_bulletin_is_exp_notice' => '1']);
$this->_service->setJsonWebClient($this->_json_web_client); $this->_service->setJsonWebClient($this->_json_web_client);
} }
public function tearDown() { public function tearDown() {
Class_WebService_SIGB_PMB::setService(null); Class_WebService_SIGB_PMB::resetServices();
parent::tearDown(); parent::tearDown();
} }
} }
class PMBServiceTest extends PMBTestCase { class PMBSimpleServiceTest extends PMBTestCase {
protected protected
$_paul, $_paul,
$_le_kiosque, $_le_kiosque,
...@@ -233,6 +234,59 @@ class PMBServiceTest extends PMBTestCase { ...@@ -233,6 +234,59 @@ class PMBServiceTest extends PMBTestCase {
class PMBPeriodicServiceTest extends ModelTestCase {
public function tearDown() {
Class_WebService_SIGB_PMB::resetServices();
parent::tearDown();
}
/** @test */
public function periodicItemShouldQueryWithoutDashBull() {
$service = Class_WebService_SIGB_PMB::getService(['url_serveur' => 'http://cedre.proxience.net/ws/connector_out.php?source_id=2',
'exp_bulletin_is_exp_notice' => '1']);
$service->setJsonWebClient($client = $this->mock()->whenCalled('httpPost')->answers(''));
$service->getExemplaire('18390-bull', '000159');
$this->assertEquals(['18390'], $client->getAttributesForLastCallOn('httpPost')[1]);
}
/** @test */
public function periodicItemHoldShouldQueryWithoutDashBull() {
$service = Class_WebService_SIGB_PMB::getService(['url_serveur' => 'http://cedre.proxience.net/ws/connector_out.php?source_id=2',
'exp_bulletin_is_exp_notice' => '1']);
$service->setJsonWebClient($client = $this->mock()->whenCalled('httpPost')->answers(''));
$service->reserverExemplaire((new Class_Entity),
(new Class_Entity)->setIdOrigine('18390-bull'),
'');
$this->assertEquals([null, '18390'], $client->getAttributesForLastCallOn('httpPost')[1]);
}
/** @test */
public function periodicItemShouldQueryWithDashBull() {
$service = Class_WebService_SIGB_PMB::getService(['url_serveur' => 'http://cedre.proxience.net/ws/connector_out.php?source_id=2']);
$service->setJsonWebClient($client = $this->mock()->whenCalled('httpPost')->answers(''));
$service->getExemplaire('18390-bull', '000159');
$this->assertEquals(['18390-bull'], $client->getAttributesForLastCallOn('httpPost')[1]);
}
/** @test */
public function periodicItemHoldShouldQueryWithDashBull() {
$service = Class_WebService_SIGB_PMB::getService(['url_serveur' => 'http://cedre.proxience.net/ws/connector_out.php?source_id=2']);
$service->setJsonWebClient($client = $this->mock()->whenCalled('httpPost')->answers(''));
$service->reserverExemplaire((new Class_Entity),
(new Class_Entity)->setIdOrigine('18390-bull'),
'');
$this->assertEquals([null, '18390-bull'], $client->getAttributesForLastCallOn('httpPost')[1]);
}
}
/** @see http://forge.afi-sa.fr/issues/102712 */ /** @see http://forge.afi-sa.fr/issues/102712 */
class PMBNotPreviouslyConnectedTest extends PMBTestCase { class PMBNotPreviouslyConnectedTest extends PMBTestCase {
protected $_patron; protected $_patron;
......
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