Browse Source

Fixed bugs with importer

Stephen Ficklin 11 years ago
parent
commit
9c54e77aa9

+ 5 - 7
tripal_pub/api/tripal_pub.api.inc

@@ -82,9 +82,7 @@ function tripal_get_remote_pubs($remote_db, $search_array, $num_to_retrieve, $pa
  *   for the record in the database.
  *
  * @return
- *   Returns the raw output wrapped in an HTML textarea element or an
- *   error message indicating if the database type is unsupported or the
- *   dbxref is invalid
+ *   Returns the publication array or FALSE if a problem occurs
  *
  * @ingroup tripal_pub_api
  */
@@ -97,7 +95,7 @@ function tripal_get_remote_pub($dbxref) {
     // check that the database is supported
     $supported_dbs = variable_get('tripal_pub_supported_dbs', array());
     if(!in_array($remote_db, $supported_dbs)) {
-      return "Unsupported database: $dbxref";
+      return FALSE;
     }
 
     $search = array(
@@ -114,9 +112,9 @@ function tripal_get_remote_pub($dbxref) {
     );
     $pubs = tripal_get_remote_pubs($remote_db, $search, 1, 0);
 
-    return $pubs[0]['raw'];
+    return $pubs['pubs'][0];
   }
-  return 'Invalid DB xref';
+  return FALSE;
 }
 
 /**
@@ -456,7 +454,7 @@ function tripal_publication_exists($pub_details) {
         'name' => 'tripal_pub',
       ),
     );
-    $pub_type = cvterm_retrieve($identifiers);
+    $pub_type = tripal_get_cvterm($identifiers);
   }
   else {
     tripal_report_error('tripal_pub', TRIPAL_ERROR, "chado_does_pub_exist(): The Publication Type is a " .

+ 10 - 1
tripal_pub/includes/importers/tripal_pub.AGL.inc

@@ -98,7 +98,7 @@ function tripal_pub_remote_validate_form_AGL($form, $form_state) {
 function tripal_pub_remote_search_AGL($search_array, $num_to_retrieve, $page) {
   // get some values from the serach array
   $num_criteria = $search_array['num_criteria'];
-  $days         = $search_array['days'];
+  $days         = array_key_exists('days', $search_array) ? $search_array['days'] : '';
 
   // set some defaults
   $search_array['limit'] = $num_to_retrieve;
@@ -447,7 +447,16 @@ function tripal_pub_AGL_range($yazc, $search_str, $start, $num_to_retrieve, $tot
 
   $pubs = array();
   for($i = $start; $i < $start + $num_to_retrieve; $i++) {
+    // retrieve the XML results
     $pub_xml = yaz_record($yazc, $i + 1, 'xml; charset=marc-8,utf-8');
+    
+    // the XML is encoded twice, one to convert UTF-8 characters to 
+    // unicode HTML entities and second with URL encoding. We must
+    // reverse the encoding
+    //$pub_xml = urldecode($pub_xml);
+    //$pub_xml = mb_convert_encoding($pub_xml, 'UTF-8', 'HTML-ENTITIES');
+    
+    // parse the pub XML
     $pub     = tripal_pub_AGL_parse_pubxml($pub_xml);
     $pubs[]  = $pub;
   }

+ 2 - 2
tripal_pub/includes/importers/tripal_pub.PMID.inc

@@ -620,7 +620,7 @@ function tripal_pub_PMID_parse_publication_type($xml, &$pub) {
             )
           );
           $options = array('case_insensitive_columns' => array('name'));
-          $pub_cvterm = cvterm_retrieve($identifiers, $options);
+          $pub_cvterm = tripal_get_cvterm($identifiers, $options);
           if (!$pub_cvterm) {
             // see if this we can find the name using a synonym
             $identifiers = array(
@@ -629,7 +629,7 @@ function tripal_pub_PMID_parse_publication_type($xml, &$pub) {
                 'cv_name' => 'tripal_pub'
               )
             );
-            $pub_cvterm = cvterm_retrieve($identifiers, $options);
+            $pub_cvterm = tripal_get_cvterm($identifiers, $options);
             if (!$pub_cvterm) {
               tripal_report_error('tripal_pubmed', TRIPAL_ERROR, 
                 'Cannot find a valid vocabulary term for the publication type: "%term".',

+ 19 - 1
tripal_pub/tripal_pub.module

@@ -137,7 +137,8 @@ function tripal_pub_menu() {
   );
 
   $items['admin/tripal/chado/tripal_pub/import/raw/%'] = array(
-    'page callback' => 'tripal_get_remote_pub',
+    'title' => t('Raw Data From Publication Import'),
+    'page callback' => 'tripal_get_remote_pub_raw_page',
     'page arguments' => array(6),
     'access arguments' => array('administer tripal pub'),
     'type ' => MENU_CALLBACK,
@@ -417,3 +418,20 @@ function tripal_pub_job_describe_args($callback, $args) {
   }
   return $new_args;
 }
+
+
+/** 
+ * A simple wrapper function to put <pre> tags around the raw results
+ * returned by the 
+ * @param unknown $dbxref
+ * @return string
+ */
+function tripal_get_remote_pub_raw_page($dbxref) {
+  $pub = tripal_get_remote_pub($dbxref);
+  if ($pub) {
+    $page = "<strong>Raw results for $dbxref:</strong><br><br>";
+    $page.= '<textarea cols=80 rows=20>' . $pub['raw'] . '</textarea>';
+    return $page;
+  }
+  return "Cound not find the requested publication ($dbxref)";
+}