Merge branch 'master' of ssh://git.indexdata.com/home/git/private/mkdru
authorJason Skomorowski <jason@indexdata.com>
Wed, 9 Feb 2011 17:56:37 +0000 (18:56 +0100)
committerJason Skomorowski <jason@indexdata.com>
Wed, 9 Feb 2011 17:56:37 +0000 (18:56 +0100)
mkdru.client.js
mkdru.info
mkdru.install
mkdru.module

index 88c09d5..dae3fa7 100644 (file)
@@ -33,7 +33,8 @@ var mkdru = {
     query:'',
     recid:null
   },
-  state: {}
+  state: {},
+  realm: ''
 };
 
 
@@ -305,7 +306,7 @@ $(document).ready(function () {
 
   mkdru.pz2 = new pz2( { "onshow": mkdru.pz2Show,
               "showtime": 500, //each timer (show, stat, term, bytarget) can be specified this way
-              "pazpar2path": mkdru.pazpar2path,
+              "pazpar2path": mkdru.pazpar2Path,
               "oninit": mkdru.pz2Init,
               "onstat": mkdru.pz2Status,
               "onterm": mkdru.pz2Term,
@@ -325,14 +326,49 @@ $(document).ready(function () {
   if (typeof(Drupal.settings.mkdru.query) !== "undefined") {
     mkdru.state.query = Drupal.settings.mkdru.query
   }
-
+  //not running against SP? init, otherwise authenticate
   if (mkdru.useSessions) {
     mkdru.pz2.init();
+  } else {
+    //runnin against SP
+    var user = Drupal.settings.mkdru.sp_user;
+    var pass = Drupal.settings.mkdru.sp_pass;
+    var params = {};
+    params['command'] = 'auth';
+    if (user && pass) {
+      params['action'] = 'login';
+      params['username'] = user;
+      params['password'] = pass;
+    } else {
+      params['action'] = 'ipauth';
+    }
+    var authReq = new pzHttpRequest(mkdru.pazpar2Path, 
+      function (err) {
+        alert("Authentication against metasearch gateway failed: " +err);
+      }
+    );
+    authReq.get(params,
+      function (data) {
+        var s = data.getElementsByTagName('status');          
+        if (s.length && Element_getTextContent(s[0]) == "OK") {
+          mkdru.realm = data.getElementsByTagName('realm');
+          mkdru.pz2Init();
+        } else {
+          alert("Malformed response when authenticating against the metasearch"
+            + " gateway");
+        }
+      }
+    );
   }
-  else if (mkdru.state.recid) {
-    mkdru.pz2.record(mkdru.state.recid);
-  }
-  else if (mkdru.state.query) {
-    mkdru.search();
-  }
+  //i'm not sure how this can work, does it assume the results set is active?
+  //what if no search has been executed?
+  //if (mkdru.state.recid) {
+  //  mkdru.pz2.record(mkdru.state.recid);
+  //}
+  //'mkdru.onInit/ deals with the following properly 
+  /// -- waiting for Pz2/SP to init first
+  //else if (mkdru.state.query) {
+  //  mkdru.search();
+  //}
 });
index a5c816f..8502d14 100644 (file)
@@ -1,3 +1,4 @@
 name = Pazpar2 metasearch integration
 description = Metasearching of Z39.50, SRU and SOLR targets via Index Data's Pazpar2 and associated tool stack.
 core = 6.x
+version = 6.x-1.0
index cdbf86b..e136c59 100644 (file)
@@ -55,6 +55,16 @@ function mkdru_schema() {
         'unsigned' => TRUE,
         'not null' => TRUE,
       ),
+      'sp_user' => array(
+        'type' => 'text',
+        'not null' => FALSE,
+        'description' => t('Service Proxy username')
+      ),
+      'sp_pass' => array(
+        'type' => 'text',
+        'not null' => FALSE,
+        'description' => t('Service Proxy password')
+      ),
     ),
     'primary key' => array('nid', 'vid'),
     'unique keys' => array('vid' => array('vid')),
@@ -82,3 +92,10 @@ function mkdru_uninstall() {
   // Delete variables
   variable_del('pz2_js_path');
 }
+
+function mkdru_update_6100() {
+  $ret = array();
+  db_add_field($ret, 'mkdru', 'sp_user', array('type' => 'varchar', 'length' => 32, 'not null' => FALSE, 'default' => '') );
+  db_add_field($ret, 'mkdru', 'sp_pass', array('type' => 'varchar', 'length' => 32, 'not null' => FALSE, 'default' => '') );
+  return $ret;
+}
index cb20ab0..0c9e36b 100644 (file)
@@ -117,6 +117,22 @@ function mkdru_form(&$node, $form_state) {
     '#required' => TRUE,
     '#default_value' => isset($node->mkdru->pz2_path) ? $node->mkdru->pz2_path : '/pazpar2/search.pz2',
   );
+  $form['search_settings']['sp_user'] = array(
+    '#type' => 'textfield',
+    '#title' => t('Service Proxy username (optional)'),
+    '#description' => t('Service-Proxy username'),
+    '#required' => FALSE,
+    '#default_value' => isset($node->mkdru->sp_user) ? 
+      $node->mkdru->sp_user : '',
+  );
+  $form['search_settings']['sp_pass'] = array(
+    '#type' => 'textfield',
+    '#title' => t('Service Proxy password (optional)'),
+    '#description' => t('Service-Proxy password'),
+    '#required' => FALSE,
+    '#default_value' => isset($node->mkdru->sp_pass) ? 
+      $node->mkdru->sp_pass : '',
+  );
   $form['search_settings']['use_sessions'] = array(
     '#type' => 'checkbox',
     '#title' => t('Session handling'),
@@ -177,8 +193,9 @@ function mkdru_validate($node) {
 * Implementation of hook_insert().
 */
 function mkdru_insert($node) {
-  db_query("INSERT INTO {mkdru} (nid, vid, pz2_path, use_sessions, source_max, author_max, subject_max) VALUES (%d, %d, '%s', %d, %d, %d, %d)",
-    $node->nid, $node->vid, $node->pz2_path, $node->use_sessions, $node->source_max, $node->author_max, $node->subject_max);
+  db_query("INSERT INTO {mkdru} (nid, vid, pz2_path, use_sessions, source_max, author_max, subject_max, sp_user, sp_pass) ".
+  "VALUES (%d, %d, '%s', %d, %d, %d, %d, '%s', '%s')",
+    $node->nid, $node->vid, $node->pz2_path, $node->use_sessions, $node->source_max, $node->author_max, $node->subject_max, $node->sp_user, $node->sp_pass);
 }
 
 /**
@@ -190,7 +207,7 @@ function mkdru_update($node) {
     mkdru_insert($node);
   }
   else {
-    db_query("UPDATE {mkdru} SET pz2_path = '%s', use_sessions = %d, source_max = %d, author_max = %d, subject_max = %d WHERE vid = %d", $node->pz2_path, $node->use_sessions, $node->source_max, $node->author_max, $node->subject_max, $node->vid);
+    db_query("UPDATE {mkdru} SET pz2_path = '%s', use_sessions = %d, source_max = %d, author_max = %d, subject_max = %d, sp_user = '%s', sp_pass = '%s' WHERE vid = %d", $node->pz2_path, $node->use_sessions, $node->source_max, $node->author_max, $node->subject_max, $node->sp_user, $node->sp_pass, $node->vid);
   }
 }