Skip to content
Snippets Groups Projects
Commit 4fa5334a authored by Ghislain Loas's avatar Ghislain Loas
Browse files

Merge branch 'hotline#64396_connecteur_le_kiosk' into 'hotline'

hotline #64396 : enhance lekiosk dashboard on http harvest diagnostic

See merge request !2708
parents 9f4b1b31 bfe4600b
3 merge requests!2723Master,!2721Hotline,!2708hotline #64396 : enhance lekiosk dashboard on http harvest diagnostic
Pipeline #4471 passed with stage
in 37 minutes and 3 seconds
- ticket #64396 : Connecteur Lekiosk : Amélioration du tableau de bord
\ No newline at end of file
......@@ -261,7 +261,7 @@ class Class_DigitalResource_Config extends Class_Entity {
public function renderHarvestDiagOn($view) {
return $view->tagNotice($this->_('Cette ressource ne prend pas en charge l\'affichage de l\'url de moissonnage'));
return '';
}
......
......@@ -137,11 +137,14 @@ class ZendAfi_View_Helper_DigitalResource_Dashboard_Harvest extends ZendAfi_View
protected function _getHarvestHtml($config) {
if ($html = $config->renderHarvestDiagOn($this->view))
return $html;
return ($url = $config->getHarvestUrl())
? ($this->_tag('h4',
$this->_('URL de moissonnage générée pour la première page'))
. $this->_tag('pre', $url))
: $config->renderHarvestDiagOn($this->view);
: $this->_tagNotice($this->_('Cette ressource ne prend pas en charge l\'affichage de l\'url de moissonnage'));
}
......
......@@ -101,4 +101,31 @@ class Lekiosk_Config extends Class_DigitalResource_Config {
&& $this->getAdminVar('HTTP_PASSWORD')
&& $this->getAdminVar('HARVEST_URL');
}
public function renderHarvestDiagOn($view) {
if (!$this->isHttpApiEnabled())
return '';
$service = $this->getServiceInstance();
$token_url = $service->getTokenUrl();
$catalogue_url = $service->getCatalogUrl(1);
$token_response = $service->getTokenResponse();
$token = $service->getTokenFrom($token_response);
$html = [$view->tag('p', $this->_('Ce moissonnage se compose de deux étapes:')),
$view->tag('h4', $this->_('Première étape: La récupération du token JWT avec le login et password fourni à l\'adresse:')),
$view->tag('pre', $token_url),
$view->tag('p', $this->_('Réponse reçue à la demande de token :')),
$view->tag('pre', $token_response),
$view->tag('p', $this->_('Token reçu :')),
$view->tag('pre', $token),
$view->tag('h4', $this->_('Deuxième étape: La récupération du catalogue avec le token reçu à l\'adresse:')),
$view->tag('pre', $catalogue_url),
$view->tag('p', $this->_('Réponse reçue à la demande du catalogue:')),
$view->tag('pre', $view->escape($service->getXmlWithToken($token))),
];
return implode($html);
}
}
......@@ -32,7 +32,7 @@ class Lekiosk_Service extends Class_DigitalResource_Service {
protected function loadPage($page_number = 1) {
$url = $this->_config->getHarvestUrl($page_number);
$url = $this->getCatalogUrl($page_number);
$xml = $this->_getXML($url);
$this->_parser = new Lekiosk_Service_Parser();
......@@ -70,16 +70,41 @@ class Lekiosk_Service extends Class_DigitalResource_Service {
}
protected function _getToken() {
public function getXmlWithToken($token) {
return $this->httpGet($this->getCatalogUrl(1),
['headers' => ['Authorization' => 'JWT '.$token]]);
}
public function getTokenUrl() {
return $this->_config->getAdminVar('HARVEST_URL') . '/login';
}
public function getCatalogUrl($page_number) {
return $this->_config->getHarvestUrl($page_number);
}
public function getTokenResponse() {
if(!$params = json_encode(['username' => $this->_config->getAdminVar('HTTP_LOGIN'),
'userpwd' => $this->_config->getAdminVar('HTTP_PASSWORD')]))
return;
$http_client = $this->getHttpClient();
if(!$response = $http_client
->postRawData($this->_config->getAdminVar('HARVEST_URL') . '/login',
$params,
'application/json'))
return $http_client->postRawData($this->getTokenUrl(),
$params,
'application/json');
}
protected function _getToken() {
return $this->getTokenFrom($this->getTokenResponse());
}
public function getTokenFrom($response) {
if(!$response)
return;
if(!$json = json_decode($response, true))
......
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