Browse Source

fleshed out logging so we log both errors and success and elminated some notices

9.x-1.0
Paul Pound 8 years ago
parent
commit
64da9e61f1
  1. 32
      includes/db.inc
  2. 7
      includes/form.inc
  3. 27
      includes/relais.inc
  4. 4
      includes/utilities.inc
  5. 2
      upei_roblib_ill.install
  6. 2
      upei_roblib_ill.module

32
includes/db.inc

@ -5,7 +5,9 @@
*/ */
function upei_roblib_ill_log_request($request, $respose) { function upei_roblib_ill_log_request($request, $response) {
$time_submitted = isset($request['RequestInfo']['DateSubmitted']) ? $request['RequestInfo']['DateSubmitted'] : '';
$relais_message = isset($response['ConfirmMessage']) ? $response['ConfirmMessage'] : $response['Problem']['Message'];
try { try {
db_insert('upei_roblib_ill_request') db_insert('upei_roblib_ill_request')
->fields(array( ->fields(array(
@ -15,19 +17,21 @@ function upei_roblib_ill_log_request($request, $respose) {
'patron_type' => $request['DeliveryAddress']['patron_type'], 'patron_type' => $request['DeliveryAddress']['patron_type'],
'patron_department' => $request['DeliveryAddress']['Department'], 'patron_department' => $request['DeliveryAddress']['Department'],
'patron_email' => $request['DeliveryAddress']['DeliveryAddress'], 'patron_email' => $request['DeliveryAddress']['DeliveryAddress'],
'notes' => $request['DeliveryAddress']['notes'], 'notes' => isset($request['DeliveryAddress']['notes']) ? $request['DeliveryAddress']['notes'] : '',
'genre' => $request['BibliographicInfo']['Genre'], 'genre' => isset($request['BibliographicInfo']['Genre']) ? $request['BibliographicInfo']['Genre'] : '',
'author' => $request['BibliographicInfo']['Author'], 'author' => isset($request['BibliographicInfo']['Author']) ? $request['BibliographicInfo']['Author'] : '',
'citation_date' => $request['BibliographicInfo']['Date'], 'citation_date' => isset($request['BibliographicInfo']['Date']) ? $request['BibliographicInfo']['Date'] : '',
'title' => $request['DeliveryAddress']['Title'], 'title' => isset($request['BibliographicInfo']['Title']) ? $request['BibliographicInfo']['Title'] : '',
'atitle' => $request['DeliveryAddress']['ArticleTitle'], 'atitle' => isset($request['BibliographicInfo']['ArticleTitle']) ? $request['BibliographicInfo']['ArticleTitle'] : '',
'issn' => $request['DeliveryAddress']['issn'], 'issn' => isset($request['BibliographicInfo']['ISSN'][0]) ? $request['BibliographicInfo']['ISSN'][0] : '',
'isbn' => $request['DeliveryAddress']['isbn'], 'isbn' => isset($request['BibliographicInfo']['ISBN'][0]) ? $request['BibliographicInfo']['ISBN'][0] : '',
'article_author' => $request['DeliveryAddress']['ArtigleAuthor'], 'article_author' => isset($request['BibliographicInfo']['ArticleAuthor']) ? $request['BibliographicInfo']['ArticleAuthor'] : '',
'volume' => $request['DeliveryAddress']['Volume'], 'volume' => isset($request['BibliographicInfo']['Volume']) ? $request['BibliographicInfo']['Volume'] : '',
'issue' => $request['DeliveryAddress']['Issue'], 'issue' => isset($request['BibliographicInfo']['Issue']) ? $request['BibliographicInfo']['Issue'] : '',
'pages_requested' => $request['DeliveryAddress']['PagesRequested'], 'pages_requested' => isset($request['BibliographicInfo']['PagesRequested']) ? $request['BibliographicInfo']['PagesRequested'] : '',
'time_submitted' => strtotime($request['RequestInfo']['DateSubmitted']), 'time_submitted' => strtotime($time_submitted),
'relais_request_id' => isset($response['RequestNumber']) ? $response['RequestNumber'] : '-1',
'relais_message' => $relais_message,
))->execute(); ))->execute();
} catch(Exception $e) { } catch(Exception $e) {
watchdog_exception('upei_roblib_ill', $e, 'Error logging ILL request.', array(), WATCHDOG_ERROR); watchdog_exception('upei_roblib_ill', $e, 'Error logging ILL request.', array(), WATCHDOG_ERROR);

7
includes/form.inc

@ -67,12 +67,7 @@ function upei_roblib_ill_form_submit($form, &$form_state) {
//process the form //process the form
drupal_set_message('completed form'); drupal_set_message('completed form');
$aid = upei_roblib_ill_authenticate($form_state['values']['campus_id']); $aid = upei_roblib_ill_authenticate($form_state['values']['campus_id']);
if (isset($aid)) { upei_roblib_ill_add_request($form_state, $aid);
upei_roblib_ill_add_request($form_state, $aid);
}
else {
drupal_set_message(t("Error authenticating with Relais"), 'error');
}
break; break;
} }

27
includes/relais.inc

@ -12,6 +12,7 @@
* A relais authentication id (token) * A relais authentication id (token)
*/ */
function upei_roblib_ill_add_request($form_state, $aid) { function upei_roblib_ill_add_request($form_state, $aid) {
module_load_include('inc', 'upei_roblib_ill', 'includes/db');
module_load_include('inc', 'upei_roblib_ill', 'includes/utilities'); module_load_include('inc', 'upei_roblib_ill', 'includes/utilities');
$url = variable_get('upei_roblib_ill_add_url', 'https://caul-cbua.relais-host.com/portal-service/request/add'); $url = variable_get('upei_roblib_ill_add_url', 'https://caul-cbua.relais-host.com/portal-service/request/add');
$relais_arr = array( $relais_arr = array(
@ -28,14 +29,16 @@ function upei_roblib_ill_add_request($form_state, $aid) {
'timeout' => 15, 'timeout' => 15,
'headers' => array('Content-Type' => 'application/json'), 'headers' => array('Content-Type' => 'application/json'),
); );
$result = null;// = drupal_http_request($url . '?aid=' . $aid, $options); if(!isset($aid) || is_array($aid)) {
upei_roblib_ill_log_request($relais_arr, $aid);
drupal_set_message(t('Error retrieving authentication token, @message', array('@message' => $aid['Problem']['Message'])), 'error');
return;
}
$result = drupal_http_request($url . '?aid=' . $aid, $options);
module_load_include('inc', 'upei_roblib_ill', 'includes/db'); module_load_include('inc', 'upei_roblib_ill', 'includes/db');
upei_roblib_ill_log_request($relais_arr, NULL); $response_json = $result->data;
$response_arr = json_decode($response_json, TRUE);
if ($result->code == '200') { if ($result->code == '200') {
$response_json = $result->data;
$response_arr = json_decode($response_json);
module_load_include('inc', 'upei_roblib_ill', 'includes/db');
upei_roblib_ill_log_request($relais_arr, $response_arr);
//TODO remove or improve the line below after testing //TODO remove or improve the line below after testing
drupal_set_message('submitted request to relais' . $response_json); drupal_set_message('submitted request to relais' . $response_json);
} }
@ -45,14 +48,15 @@ function upei_roblib_ill_add_request($form_state, $aid) {
'@message' => $result->message '@message' => $result->message
)), 'error'); )), 'error');
} }
upei_roblib_ill_log_request($relais_arr, $response_arr);
} }
/** /**
* Request an aid from Relais. * Request an aid from Relais.
* @param string $barcode * @param string $barcode
* A patron_id, campus_id or barcode to identify a user * A patron_id, campus_id or barcode to identify a user
* @return string/null * @return string/array
* Returns a Relais authentication id (token) or NULL on if authentication fails * Returns a Relais authentication id (token) or an array containing the Relais response error which should include the error message if authentication fails
*/ */
function upei_roblib_ill_authenticate($barcode) { function upei_roblib_ill_authenticate($barcode) {
$url = variable_get('upei_roblib_ill_auth_url', 'https://caul-cbua.relais-host.com/portal-service/user/authentication'); $url = variable_get('upei_roblib_ill_auth_url', 'https://caul-cbua.relais-host.com/portal-service/user/authentication');
@ -69,15 +73,14 @@ function upei_roblib_ill_authenticate($barcode) {
'headers' => array('Content-Type' => 'application/json'), 'headers' => array('Content-Type' => 'application/json'),
); );
$result = drupal_http_request($url, $options); $result = drupal_http_request($url, $options);
$response_data = json_decode($result->data, TRUE);
if ($result->code == '200') { if ($result->code == '200') {
$response_data = json_decode($result->data, TRUE);
if (isset($response_data['Problem'])) { if (isset($response_data['Problem'])) {
drupal_set_message(t('Error retrieving authentication token, @message', array('@message' => $response_data['Problem']['Message'])), 'error'); return $response_data;
return NULL;
} }
$aid = $response_data['AuthorizationId']; $aid = $response_data['AuthorizationId'];
} }
return isset($aid) ? $aid : NULL; return isset($aid) ? $aid : $response_data;
} }

4
includes/utilities.inc

@ -74,12 +74,12 @@ function upei_roblib_ill_request_info_array($values, $notes) {
if ($genre == 'book' || $genre == 'chapter') { if ($genre == 'book' || $genre == 'chapter') {
$requestInfo['ServiceType'] = 'L'; $requestInfo['ServiceType'] = 'L';
$requestInfo['ServiceLabel'] = "R"; $requestInfo['ServiceLabel'] = "R";
$requestInfo['RequestSource'] = "C"; //$requestInfo['RequestSource'] = "C";
} }
else { else {
$requestInfo['ServiceType'] = 'X'; $requestInfo['ServiceType'] = 'X';
$requestInfo['ServiceLabel'] = "R"; $requestInfo['ServiceLabel'] = "R";
$requestInfo['RequestSource'] = "C"; //$requestInfo['RequestSource'] = "C";
} }
return $requestInfo; return $requestInfo;
} }

2
upei_roblib_ill.install

@ -139,7 +139,7 @@ function upei_roblib_ill_schema() {
'length' => '30', 'length' => '30',
'not null' => FALSE, 'not null' => FALSE,
), ),
'relais_failure_message' => array( 'relais_message' => array(
'description' => 'If the ILL request failed we will store a reason.', 'description' => 'If the ILL request failed we will store a reason.',
'type' => 'varchar', 'type' => 'varchar',
'length' => '255', 'length' => '255',

2
upei_roblib_ill.module

@ -50,7 +50,7 @@ function upei_roblib_ill_views_api() {
function upei_roblib_ill_views_data() { function upei_roblib_ill_views_data() {
$data['upei_roblib_ill_request']['table']['group'] = t('UPEI Roblib ILL'); $data['upei_roblib_ill_request']['table']['group'] = t('UPEI Roblib ILL');
$data['upei_roblib_ill_request']['table']['base'] = array( $data['upei_roblib_ill_request']['table']['base'] = array(
'field' => 'id', 'field' => 'id',
'title' => t('UPEI Roblib ILL Request'), 'title' => t('UPEI Roblib ILL Request'),
'help' => t('Table for logging ILL Request'), 'help' => t('Table for logging ILL Request'),
'weight' => -10, 'weight' => -10,

Loading…
Cancel
Save