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

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 {
db_insert('upei_roblib_ill_request')
->fields(array(
@ -15,19 +17,21 @@ function upei_roblib_ill_log_request($request, $respose) {
'patron_type' => $request['DeliveryAddress']['patron_type'],
'patron_department' => $request['DeliveryAddress']['Department'],
'patron_email' => $request['DeliveryAddress']['DeliveryAddress'],
'notes' => $request['DeliveryAddress']['notes'],
'genre' => $request['BibliographicInfo']['Genre'],
'author' => $request['BibliographicInfo']['Author'],
'citation_date' => $request['BibliographicInfo']['Date'],
'title' => $request['DeliveryAddress']['Title'],
'atitle' => $request['DeliveryAddress']['ArticleTitle'],
'issn' => $request['DeliveryAddress']['issn'],
'isbn' => $request['DeliveryAddress']['isbn'],
'article_author' => $request['DeliveryAddress']['ArtigleAuthor'],
'volume' => $request['DeliveryAddress']['Volume'],
'issue' => $request['DeliveryAddress']['Issue'],
'pages_requested' => $request['DeliveryAddress']['PagesRequested'],
'time_submitted' => strtotime($request['RequestInfo']['DateSubmitted']),
'notes' => isset($request['DeliveryAddress']['notes']) ? $request['DeliveryAddress']['notes'] : '',
'genre' => isset($request['BibliographicInfo']['Genre']) ? $request['BibliographicInfo']['Genre'] : '',
'author' => isset($request['BibliographicInfo']['Author']) ? $request['BibliographicInfo']['Author'] : '',
'citation_date' => isset($request['BibliographicInfo']['Date']) ? $request['BibliographicInfo']['Date'] : '',
'title' => isset($request['BibliographicInfo']['Title']) ? $request['BibliographicInfo']['Title'] : '',
'atitle' => isset($request['BibliographicInfo']['ArticleTitle']) ? $request['BibliographicInfo']['ArticleTitle'] : '',
'issn' => isset($request['BibliographicInfo']['ISSN'][0]) ? $request['BibliographicInfo']['ISSN'][0] : '',
'isbn' => isset($request['BibliographicInfo']['ISBN'][0]) ? $request['BibliographicInfo']['ISBN'][0] : '',
'article_author' => isset($request['BibliographicInfo']['ArticleAuthor']) ? $request['BibliographicInfo']['ArticleAuthor'] : '',
'volume' => isset($request['BibliographicInfo']['Volume']) ? $request['BibliographicInfo']['Volume'] : '',
'issue' => isset($request['BibliographicInfo']['Issue']) ? $request['BibliographicInfo']['Issue'] : '',
'pages_requested' => isset($request['BibliographicInfo']['PagesRequested']) ? $request['BibliographicInfo']['PagesRequested'] : '',
'time_submitted' => strtotime($time_submitted),
'relais_request_id' => isset($response['RequestNumber']) ? $response['RequestNumber'] : '-1',
'relais_message' => $relais_message,
))->execute();
} catch(Exception $e) {
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
drupal_set_message('completed form');
$aid = upei_roblib_ill_authenticate($form_state['values']['campus_id']);
if (isset($aid)) {
upei_roblib_ill_add_request($form_state, $aid);
}
else {
drupal_set_message(t("Error authenticating with Relais"), 'error');
}
upei_roblib_ill_add_request($form_state, $aid);
break;
}

27
includes/relais.inc

@ -12,6 +12,7 @@
* A relais authentication id (token)
*/
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');
$url = variable_get('upei_roblib_ill_add_url', 'https://caul-cbua.relais-host.com/portal-service/request/add');
$relais_arr = array(
@ -28,14 +29,16 @@ function upei_roblib_ill_add_request($form_state, $aid) {
'timeout' => 15,
'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');
upei_roblib_ill_log_request($relais_arr, NULL);
$response_json = $result->data;
$response_arr = json_decode($response_json, TRUE);
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
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
)), 'error');
}
upei_roblib_ill_log_request($relais_arr, $response_arr);
}
/**
* Request an aid from Relais.
* @param string $barcode
* A patron_id, campus_id or barcode to identify a user
* @return string/null
* Returns a Relais authentication id (token) or NULL on if authentication fails
* @return string/array
* 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) {
$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'),
);
$result = drupal_http_request($url, $options);
$response_data = json_decode($result->data, TRUE);
if ($result->code == '200') {
$response_data = json_decode($result->data, TRUE);
if (isset($response_data['Problem'])) {
drupal_set_message(t('Error retrieving authentication token, @message', array('@message' => $response_data['Problem']['Message'])), 'error');
return NULL;
return $response_data;
}
$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') {
$requestInfo['ServiceType'] = 'L';
$requestInfo['ServiceLabel'] = "R";
$requestInfo['RequestSource'] = "C";
//$requestInfo['RequestSource'] = "C";
}
else {
$requestInfo['ServiceType'] = 'X';
$requestInfo['ServiceLabel'] = "R";
$requestInfo['RequestSource'] = "C";
//$requestInfo['RequestSource'] = "C";
}
return $requestInfo;
}

2
upei_roblib_ill.install

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

Loading…
Cancel
Save