瀏覽代碼

at the final hurdle for remote fields in data collections just need to get the field data to write to the file

Shawna Spoor 7 年之前
父節點
當前提交
ae8c6cb0bc

+ 216 - 107
tripal/includes/TripalEntityCollection.inc

@@ -131,6 +131,13 @@ class TripalEntityCollection {
     $bundle_name = "";
     if (count($this->bundles) > 1) {
       foreach ($this->bundles as $bundle) {
+        // If bundle name is not bio_data_# then it's an accession name from
+        // a remote site, so we need to handle it differently.
+        $bundle_name = $bundle->bundle_name;
+        if (strpos($bundle->bundle_name, 'bio_data_') !== 0) {
+          $ids[$bundle_name] = $this->getEntityIDs($bundle_name);
+          $fields[$bundle_name] = $this->getFields($bundle_name);
+        }
         $bundle_name = $bundle->bundle_name;
         $ids[$bundle_name] = $this->getEntityIDs($bundle_name);
         $fields[$bundle_name] = $this->getFields($bundle_name);
@@ -145,82 +152,9 @@ class TripalEntityCollection {
         $this->fields = $this->getFields($bundle_name);
       }
     }
-
     // Iterate through the fields and find out what download formats are
     // supported for this basket.
-    foreach ($this->fields as $field_group) {
-      foreach ($field_group as $field_id) {
-        // Check is $field_groups is an array because if it is that means we
-        // nested arrays we need to deal with.
-        if (is_array($field_id)) {
-          foreach ($field_id as $field) {
-            $field_info = field_info_field_by_id($field);
-            if (!$field_info) {
-              continue;
-            }
-            $field_name = $field_info['field_name'];
-            $field_type = $field_info['type'];
-            $field_module = $field_info['module'];
-            $instance = field_info_instance('TripalEntity', $field_name, $bundle_name);
-
-            $downloaders = array();
-
-            // TODO: replace this code with the new tripal_get_field_field_formatters()
-            // API function
-            // All fields should support the Tab and CSV downloaders.
-            tripal_load_include_downloader_class('TripalTabDownloader');
-            $this->downloaders['TripalTabDownloader'] = TripalTabDownloader::$label;
-            tripal_load_include_downloader_class('TripalCSVDownloader');
-            $this->downloaders['TripalCSVDownloader'] = TripalCSVDownloader::$label;
-
-            if (tripal_load_include_field_class($field_type)) {
-              $settings = $field_type::$default_instance_settings;
-              if (array_key_exists('download_formatters', $settings)) {
-                foreach ($settings['download_formatters'] as $class_name) {
-                  if (!array_key_exists($class_name, $this->downloaders)) {
-                    tripal_load_include_downloader_class($class_name);
-                    $this->downloaders[$class_name] = $class_name::$label;
-                  }
-                }
-              }
-            }
-          }
-        }
-        else {
-          $field = field_info_field_by_id($field_id);
-          if (!$field) {
-            continue;
-          }
-          $field_name = $field['field_name'];
-          $field_type = $field['type'];
-          $field_module = $field['module'];
-          $instance = field_info_instance('TripalEntity', $field_name, $bundle_name);
-
-          $downloaders = array();
-
-          // TODO: replace this code with the new tripal_get_field_field_formatters()
-          // API function
-
-          // All fields should support the Tab and CSV downloaders.
-          tripal_load_include_downloader_class('TripalTabDownloader');
-          $this->downloaders['TripalTabDownloader'] = TripalTabDownloader::$label;
-          tripal_load_include_downloader_class('TripalCSVDownloader');
-          $this->downloaders['TripalCSVDownloader'] = TripalCSVDownloader::$label;
-
-          if (tripal_load_include_field_class($field_type)) {
-            $settings = $field_type::$default_instance_settings;
-            if (array_key_exists('download_formatters', $settings)) {
-              foreach ($settings['download_formatters'] as $class_name) {
-                if (!array_key_exists($class_name, $this->downloaders)) {
-                  tripal_load_include_downloader_class($class_name);
-                  $this->downloaders[$class_name] = $class_name::$label;
-                }
-              }
-            }
-          }
-        }
-      }
-    }
+    $this->downloaders = $this->getDownloadFormattersList($this->fields);
   }
 
   /**
@@ -334,6 +268,116 @@ class TripalEntityCollection {
     return $result;
   }
 
+  /**
+   * Retrieves the site id for this specific bundle fo the collection.
+   *
+   * @return
+   *   A single site id.
+   */
+  public function getSiteId($bundle_name) {
+    $collection_id = $this->collection_id;
+    // Return the bundles from the collection_bundle table.
+    $result = db_select('tripal_collection_bundle')
+      ->fields('tripal_collection_bundle', array('site_id'))
+      ->condition('collection_id', $collection_id, '=')
+      ->condition('bundle_name', $bundle_name, '=')
+      ->execute()
+      ->fetchAssoc();
+
+    return $result;
+  }
+
+  /**
+   * Retrieves the list of appropriate download formatters for the basket.
+   *
+   * @return
+   *   An associative array where the key is the TripalFieldDownloader class
+   *   name and the value is the human-readable lable for the formatter.
+   */
+  public function getDownloadFormattersList($fields) {
+    $downloaders = array();
+    // Iterate through the fields and find out what download formats are
+    // supported for this basket.
+    foreach ($fields as $bundle_name => $field_group) {
+      foreach ($field_group as $field_id) {
+        // Check is $field_groups is an array because if it is that means we
+        // nested arrays we need to deal with.
+        if (is_array($field_id)) {
+          foreach ($field_id as $field) {
+            // If the $field is numeric it's a field id from the local site but
+            // if it is not then it's a remote field that needs to be handled differently.
+            if (!is_numeric($field)) {
+              // Need the site ID from the tripal_collection_bundle table.
+              $site_id = $this->getSiteId($bundle_name);
+              // Use the webservices call to pull the available downloaders list.
+              // Need to pull the vocab doc of the web services to know the download formats.
+              // Use the api call to get the vocab for the site which will need to be parsed 
+              // to find the accession and the download types available.
+              $site_vocab = tripal_web_services_vocab_request($site_id);
+              foreach ($site_vocab as $item) {
+                if (is_array($item)) {
+                  foreach ($item as $vocab_term) {
+                    if (!empty($vocab_term['supportedProperty'])) {
+                      $vocab_supported_properties = $vocab_term['supportedProperty'];
+                      if (is_array($vocab_supported_properties)) {
+                        foreach ($vocab_supported_properties as $property) {
+                          if ($property['property'] === $field) {
+                            if (in_array('tripal_formatters', $property)) {
+                              $download_types = $property['tripal_formatters'];
+
+                              foreach ($download_types as $download_type) {
+                                $this->downloaders[$download_type] = $download_type;
+                                continue 7;
+                              }
+                            }
+                          }
+                        }
+                      }
+                      else {
+                        if (in_array('tripal_formatters', $vocab_supported_properties)) {
+                          $download_types = $vocab_supported_properties['tripal_formatters'];
+                          foreach ($download_types as $download_type) {
+                            $this->downloaders[$download_type] = $download_type;
+                            continue 6;
+                          }
+                        }
+                      }
+                    }
+                  }
+                }
+              }
+            }
+            else {
+              $field_info = field_info_field_by_id($field);
+              if (!$field_info) {
+                continue;
+              }
+            }
+            $field_name = $field_info['field_name'];
+            $instance = field_info_instance('TripalEntity', $field_name, $bundle_name);
+            // API function
+            // All fields should support the Tab and CSV downloaders.
+            $downloaders = array();
+            $this->downloaders += tripal_get_field_field_formatters($field);
+          }
+        }
+        else {
+          $field = field_info_field_by_id($field_id);
+          if (!$field) {
+            continue;
+          }
+          $field_name = $field['field_name'];
+          $instance = field_info_instance('TripalEntity', $field_name, $bundle_name);
+          // API function
+          $downloaders = array();
+          $this->downloaders += tripal_get_field_field_formatters($field);
+        }
+      }
+    }
+    return $this->downloaders;
+  }
+
+
   /**
    * Retrieves the list of appropriate download formatters for the basket.
    *
@@ -365,6 +409,7 @@ class TripalEntityCollection {
     $unserialized_result = [];
     foreach ($result as $id_list) {
       $unserialized_id_list = unserialize($id_list->ids);
+  
       foreach ($id_list as $item) {
         $unserialized_result[] = $unserialized_id_list;
       }
@@ -588,55 +633,119 @@ class TripalEntityCollection {
           foreach ($field_id as $field) {
             // If the formatter is TripalTabDownloader or TripalCSVDownloader then
             // we always want to support the field.
-            if ($formatter == 'TripalTabDownloader' or $formatter == 'TripalCSVDownloader') {
+            if ($tripal_create_collection_files == 'TripalTabDownloader' or $formatter == 'TripalCSVDownloader') {
               if (!in_array($field, $supported_fields)) {
                 $supported_fields[] = $field;
               }
               continue;
             }
 
-            // Otherwise, find out if the formatter specified is supporte by the
-            // field and if so then add it to our list of supported fields.
-            $field_info = field_info_field_by_id($field);
-            $field_name = $field_info['field_name'];
-            $field_type = $field_info['type'];
-            if (tripal_load_include_field_class($field_type)) {
-              $settings = $field_type::$default_instance_settings;
-              if (array_key_exists('download_formatters', $settings)) {
-                if (in_array($formatter, $settings['download_formatters'])) {
-                  $supported_fields[] = $field;
+            // If the $field is numeric it's a field id from the local site but
+            // if it is not then it's a remote field that needs to be handled differently.
+            if (!is_numeric($field)) {
+              // Need the site ID from the tripal_collection_bundle table.
+              $collection_id = $this->collection_id;
+              // Return the bundles from the collection_bundle table.
+              $collections = db_select('tripal_collection_bundle')
+                ->fields('tripal_collection_bundle')
+                ->condition('collection_id', $collection_id, '=')
+                ->execute()
+                ->fetchAll();
+
+              // Now that we have all possible bundles we need to find the right one.
+              foreach ($collections as $collection) {
+                $fields = unserialize($collection->fields);
+                if (in_array($field, $fields)) {
+                  $site_id = $collection->site_id;
+                }
+              }
+              // Use the webservices call to pull the available downloaders list.
+              // Need to pull the vocab doc of the web services to know the download formats.
+              // Use the api call to get the vocab for the site which will need to be parsed 
+              // to find the accession and the download types available.
+              if (!empty($site_id)) {
+                $site_vocab = tripal_web_services_vocab_request($site_id);
+                foreach ($site_vocab as $item) {
+                  if (is_array($item)) {
+                    foreach ($item as $vocab_term) {
+                      if (!empty($vocab_term['supportedProperty'])) {
+                        $vocab_supported_properties = $vocab_term['supportedProperty'];
+                        if (is_array($vocab_supported_properties)) {
+                          foreach ($vocab_supported_properties as $property) {
+                            if ($property['property'] === $field) {
+                              if (in_array('tripal_formatters', $property)) {
+                                $download_types = $property['tripal_formatters'];
+                                foreach ($download_types as $download_type) {
+                                  if ($formatter == $download_type) {
+                                    $supported_fields[] = $field;
+                                    continue 5;
+                                  }
+                                }
+                              }
+                            }
+                          }
+                        }
+                        else {
+                          if (in_array('tripal_formatters', $vocab_supported_properties)) {
+                            $download_types = $vocab_supported_properties['tripal_formatters'];
+                            foreach ($download_types as $download_type) {
+                              if ($formatter == $download_type) {
+                                $supported_fields[] = $field;
+                                continue 3;
+                              }
+                            }
+                          }
+                        }
+                      }
+                    }
+                  }
                 }
               }
             }
-          }
-        }
-        else {
-          // If the formatter is TripalTabDownloader or TripalCSVDownloader then
-          // we always want to support the field.
-          if ($formatter == 'TripalTabDownloader' or $formatter == 'TripalCSVDownloader') {
-            if (!in_array($field_id, $supported_fields)) {
-              $supported_fields[] = $field_id;
-            }
-            continue;
-          }
+            else {
+              // Otherwise, find out if the formatter specified is supported by the
+              // field and if so then add it to our list of supported fields.
+              $field_info = field_info_field_by_id($field);
+              $field_name = $field_info['field_name'];
+              $field_type = $field_info['type'];
+              if (tripal_load_include_field_class($field_type)) {
+                $settings = $field_type::$default_instance_settings;
+                if (array_key_exists('download_formatters', $settings)) {
+                  if (in_array($formatter, $settings['download_formatters'])) {
+                    $supported_fields[] = $field;
+                  }
+                }
+              }
+              else {
+                // If the formatter is TripalTabDownloader or TripalCSVDownloader then
+                // we always want to support the field.
+                if ($formatter == 'TripalTabDownloader' or $formatter == 'TripalCSVDownloader') {
+                  if (!in_array($field_id, $supported_fields)) {
+                    $supported_fields[] = $field_id;
+                  }
+                  continue;
+                }
 
-          // Otherwise, find out if the formatter specified is supporte by the
-          // field and if so then add it to our list of supported fields.
-          $field = field_info_field_by_id($field_id);
-          $field_name = $field['field_name'];
-          $field_type = $field['type'];
-          if (tripal_load_include_field_class($field_type)) {
-            $settings = $field_type::$default_instance_settings;
-            if (array_key_exists('download_formatters', $settings)) {
-              if (in_array($formatter, $settings['download_formatters'])) {
-                $supported_fields[] = $field_id;
+                // Otherwise, find out if the formatter specified is supporte by the
+                // field and if so then add it to our list of supported fields.
+                $field = field_info_field_by_id($field_id);
+                $field_name = $field['field_name'];
+                $field_type = $field['type'];
+                if (tripal_load_include_field_class($field_type)) {
+                  $settings = $field_type::$default_instance_settings;
+                  if (array_key_exists('download_formatters', $settings)) {
+                    if (in_array($formatter, $settings['download_formatters'])) {
+                      $supported_fields[] = $field_id;
+                    }
+                  }
+                }
               }
             }
           }
         }
       }
     }
-
+    print_r($supported_fields);
     $downloader = new $formatter($this->bundles, $this->ids, $supported_fields, $outfile, $this->user->uid);
     $downloader->write();
 

+ 1 - 0
tripal/includes/TripalFieldDownloaders/TripalCSVDownloader.inc

@@ -15,6 +15,7 @@ class TripalCSVDownloader extends TripalFieldDownloader {
    * @see TripalFieldDownloader::format()
    */
   protected function formatEntity($entity) {
+    print_r($entity);
     $row = array();
     foreach ($this->fields as $field_id) {
       $field = field_info_field_by_id($field_id);

+ 41 - 34
tripal/includes/TripalFieldDownloaders/TripalFieldDownloader.inc

@@ -117,53 +117,60 @@ abstract class TripalFieldDownloader {
     // apart so that headers and content correspond.
     if (count($this->bundle_name) > 1) {
       foreach ($this->bundle_name as $bundle) {
-        $bundle_id = $bundle->bundle_name;
-        // Get the bundle display name so it makes sense to the end user.
-        $bundle_label = db_select('tripal_bundle', 'TB')
-          ->fields('TB', array('label'))
-          ->condition('TB.name', $bundle_id, '=')
-          ->execute()
-          ->fetchAssoc();
-        fwrite($fh, $bundle_label['label'] . "\r\n");
-
         // Set the single bundle name for getting the Header.
-        $this->bundle_name = $bundle_id;
-
+        $this->bundle_name = $bundle->bundle_name;
         $headers = $this->getHeader();
         if ($headers) {
           foreach ($headers as $line) {
             fwrite($fh, $line . "\r\n");
           }
         }
-        foreach ($this->entity_ids[$bundle_id] as $entity_id) {
-          if (is_array($entity_id)) {
-            foreach ($entity_id as $single_entity) {
-              if (is_array($single_entity)) {
-                foreach ($single_entity as $entity) {
-                  $result = tripal_load_entity('TripalEntity', array($entity), FALSE, $this->fields);
-                  $entity_info = $result[$entity];
-                  $lines = $this->formatEntity($entity_info);
+
+        // Determine if the entity is remote or local.
+        if (strpos($this->bundle_name, 'bio_data_') !== 0) {
+          // Because this is a remote field we need to construct a fake entity.
+          /*
+
+          $lines = $this->formatEntity($entity_info);
+          foreach ($lines as $line) {
+            fwrite($fh, $line . "\r\n");
+          }*/
+
+        }
+        else {
+          foreach ($this->entity_ids[$bundle_id] as $entity_id) {
+            if (is_array($entity_id)) {
+              foreach ($entity_id as $single_entity) {
+
+                if (is_array($single_entity)) {
+                  foreach ($single_entity as $entity) {
+                    // If the field is from a remote entity then we need to load the info through web services. 
+
+                    $result = tripal_load_entity('TripalEntity', array($entity), FALSE, $this->fields);
+                    $entity_info = $result[$entity];
+                    $lines = $this->formatEntity($entity_info);
+                    foreach ($lines as $line) {
+                      fwrite($fh, $line . "\r\n");
+                    }
+                  }
+                }
+                else {
+                  $result = tripal_load_entity('TripalEntity', array($single_entity), FALSE, $this->fields);
+                  $entity = $result[$single_entity];
+                  $lines = $this->formatEntity($entity);
                   foreach ($lines as $line) {
                     fwrite($fh, $line . "\r\n");
                   }
                 }
               }
-              else {
-                $result = tripal_load_entity('TripalEntity', array($single_entity), FALSE, $this->fields);
-                $entity = $result[$single_entity];
-                $lines = $this->formatEntity($entity);
-                foreach ($lines as $line) {
-                  fwrite($fh, $line . "\r\n");
-                }
-              }
             }
-          }
-          else {
-            $result = tripal_load_entity('TripalEntity', array($entity_id), FALSE, $this->fields);
-            $entity = $result[$entity_id];
-            $lines = $this->formatEntity($entity);
-            foreach ($lines as $line) {
-              fwrite($fh, $line . "\r\n");
+            else {
+              $result = tripal_load_entity('TripalEntity', array($entity_id), FALSE, $this->fields);
+              $entity = $result[$entity_id];
+              $lines = $this->formatEntity($entity);
+              foreach ($lines as $line) {
+                fwrite($fh, $line . "\r\n");
+              }
             }
           }
         }

+ 1 - 0
tripal/includes/TripalFieldDownloaders/TripalTabDownloader.inc

@@ -15,6 +15,7 @@ class TripalTabDownloader extends TripalFieldDownloader {
    * @see TripalFieldDownloader::format()
    */
   protected function formatEntity($entity) {
+    print_r($entity);
     $row = array();
     foreach ($this->fields as $field_id) {
       $field = field_info_field_by_id($field_id);

+ 29 - 0
tripal/tripal.install

@@ -391,6 +391,12 @@ function tripal_tripal_collection_bundle_schema() {
         'not null' => TRUE,
         'description' => 'An array of numeric field IDs.'
       ),
+      'site_id' => array(
+        'type' => 'int',
+        'size' => 'normal',
+        'not null' => FALSE,
+        'description' => 'The ID of the site from the Tripal Sites table.'
+      ),
     ),
     'indexes' => array(
       'collection_id' => array('collection_id')
@@ -1085,4 +1091,27 @@ function tripal_update_7308() {
     $error = $e->getMessage();
     throw new DrupalUpdateException('Could not add the tripal_collection table:' . $error);
   }
+}
+
+/**
+ * Add the site_id field to the tripal_collection_bundle table.
+ */
+function tripal_update_7309() {
+  $transaction = db_transaction();
+  try {
+    if (!db_field_exists('tripal_collection_bundle', 'site_id')) {
+       $field = array(
+        'type' => 'int',
+        'size' => 'normal',
+        'not null' => FALSE,
+        'description' => 'The ID of the site from the Tripal Sites table.',
+      );
+      db_add_field('tripal_collection_bundle', 'site_id', $field);
+    }
+  }
+  catch (\PDOException $e) {
+    $transaction->rollback();
+    $error = $e->getMessage();
+    throw new DrupalUpdateException('Could not add the tripal_collection table:' . $error);
+  }
 }

+ 22 - 22
tripal/views_handlers/tripal_views_handler_area_collections.inc

@@ -46,13 +46,13 @@ function tripal_views_handler_area_collections_form($form, $form_state, $view, $
 
   $form = array();
   $form['save_collection'] = array(
-   '#type' => 'fieldset',
-   '#title' => t('Save Results'),
-   '#collapsible' => TRUE,
-   '#collapsed' => TRUE,
-   '#description' => t('A data collection is a virtual container into which you can
-     save data.  You can place your search results into a data collection for
-     download or use with other tools on this site that support data collections.'),
+    '#type' => 'fieldset',
+    '#title' => t('Save Results'),
+    '#collapsible' => TRUE,
+    '#collapsed' => TRUE,
+    '#description' => t('A data collection is a virtual container into which you can
+      save data.  You can place your search results into a data collection for
+      download or use with other tools on this site that support data collections.'),
   );
   $form['save_collection']['bundle'] = array(
     '#type' => 'value',
@@ -67,22 +67,22 @@ function tripal_views_handler_area_collections_form($form, $form_state, $view, $
     '#value' => unserialize(serialize($query->query))
   );
   $form['save_collection']['summary'] = array(
-   '#type' => 'item',
-   '#title' => 'Results Summary',
-   '#markup' => t('There are @total_rows record(s) that can be added to a data collection.', array('@total_rows' => $view->total_rows)),
+    '#type' => 'item',
+    '#title' => 'Results Summary',
+    '#markup' => t('There are @total_rows record(s) that can be added to a data collection.', array('@total_rows' => $view->total_rows)),
   );
   $form['save_collection']['collection_name'] = array(
-   '#type' => 'textfield',
-   '#title' => t('Collection Name'),
-   '#description' => t('Please name this collection for future reference.'),
-   '#default_value' => $collection_name,
-   '#required' => TRUE,
+    '#type' => 'textfield',
+    '#title' => t('Collection Name'),
+    '#description' => t('Please name this collection for future reference.'),
+    '#default_value' => $collection_name,
+    '#required' => TRUE,
   );
   $form['save_collection']['collection_desc'] = array(
-   '#type' => 'textarea',
-   '#title' => t('Description'),
-   '#description' => t('Please provide a description about this data collection.'),
-   '#default_value' => $collection_name,
+    '#type' => 'textarea',
+    '#title' => t('Description'),
+    '#description' => t('Please provide a description about this data collection.'),
+    '#default_value' => $collection_name,
   );
 
   // Get the list of fields used in the view.
@@ -117,7 +117,7 @@ function tripal_views_handler_area_collections_form($form, $form_state, $view, $
         foreach ($instance_settings['download_formatters'] as $class_name) {
           if ($class_name != 'TripalTabDownloader' and $class_name != 'TripalCSVDownloader') {
             tripal_load_include_downloader_class($class_name);
-              $formatters[] = $class_name::$label;
+            $formatters[] = $class_name::$label;
           }
         }
       }
@@ -127,7 +127,7 @@ function tripal_views_handler_area_collections_form($form, $form_state, $view, $
     }
 
     // Add the field to those supported.
-    $field_ids[$instance['field_id']] =  $field_label;
+    $field_ids[$instance['field_id']] = $field_label;
 
     // Automatically check fields that are in the view and not excluded.
     if (array_key_exists($field_name, $view_fields)) {
@@ -218,4 +218,4 @@ function tripal_views_handler_area_collections_form_submit($form, $form_state) {
     'fields' => $selected_fids,
     'description'  => $description,
   ));
-}
+}

+ 112 - 1
tripal_ws/api/tripal_ws.api.inc

@@ -165,7 +165,6 @@ function tripal_add_site($name, $url, $version, $description) {
   return $write_to_db;
 }
 
-
 /**
  * Remove a site from the web services table.
  *
@@ -185,3 +184,115 @@ function tripal_remove_site($record_id) {
   }
   return FALSE;
 }
+
+/** 
+ * When passed a site_id from the tripal_sites table the full
+ * site's vocab service is returned in json format
+ *
+ *
+ */
+function tripal_web_services_vocab_request($site_id) {
+  // Get the site url from the tripal_sites table.
+  if ($site_id) {
+    $remote_site = db_select('tripal_sites', 'ts')
+      ->fields('ts')
+      ->condition('ts.id', $site_id)
+      ->execute()
+      ->fetchObject();
+  }
+  // Build the URL to the remote web services.
+  $ws_version = $remote_site->version;
+  $ws_url = $remote_site->url;
+  $ws_url = trim($ws_url, '/');
+  $ws_url .= '/web-services/vocab/' . $ws_version;
+
+  // Build and make the request.
+  $options = [];
+  $data = drupal_http_request($ws_url, $options);
+
+  if (!$data) {
+    tripal_report_error('tripal_ws', TRIPAL_ERROR,
+        t('Could not connect to the remote web service.'));
+    return FALSE;
+  }
+
+  // If the data object has an error then this is some sort of
+  // connection error (not a Tripal web servcies error).
+  if (property_exists($data, 'error')) {
+    tripal_report_error('tripal_ws', TRIPAL_ERROR,
+        'Web Services error on remote site: %error.',
+        array('%error' => $data->error));
+    return FALSE;
+  }
+
+  // We got a response, so convert it to a PHP array.
+  $data = drupal_json_decode($data->data);
+
+  // Check if there was a Tripal Web Services error.
+  if (array_key_exists('error', $data)) {
+    $error = '</pre>' . print_r($data['error'], TRUE) . '</pre>';
+    tripal_report_error('tripal_ws', TRIPAL_ERROR,
+        'Web Services error on remote site: %error.',
+        array('%error' => $error));
+    return FALSE;
+  }
+
+  return $data;
+}
+
+/**
+ * Makes a request to a remote Tripal web services site.
+ *
+ * @param $query
+ *   The query string. This string is added to the URL for the remote
+ *   website.
+ */
+function tripal_web_services_remote_request($remote_site, $query) {
+  $ctype = $query;
+  $qdata = '';
+  if (preg_match('/\?/', $query)) {
+    list($ctype, $qdata) = explode('?', $query);
+  }
+
+  // Build the URL to the remote web services.
+  $ws_version = $remote_site->version;
+  $ws_url = $remote_site->url;
+  $ws_url = trim($ws_url, '/');
+  $ws_url .= '/web-services/content/' . $ws_version . '/' . $ctype;
+
+  // Build the Query and make and substitions needed.
+  //dpm($ws_url . '?' . $query);
+  $options = array(
+    'data' => $qdata,
+  );
+  $data = drupal_http_request($ws_url, $options);
+
+  if (!$data) {
+    tripal_report_error('tripal_ws', TRIPAL_ERROR,
+        t('Could not connect to the remote web service.'));
+    return FALSE;
+  }
+
+  // If the data object has an error then this is some sort of
+  // connection error (not a Tripal web servcies error).
+  if (property_exists($data, 'error')) {
+    tripal_report_error('tripal_ws', TRIPAL_ERROR,
+        'Web Services error on remote site: %error.',
+        array('%error' => $data->error));
+    return FALSE;
+  }
+
+  // We got a response, so convert it to a PHP array.
+  $data = drupal_json_decode($data->data);
+
+  // Check if there was a Tripal Web Services error.
+  if (array_key_exists('error', $data)) {
+    $error = '</pre>' . print_r($data['error'], TRUE) . '</pre>';
+    tripal_report_error('tripal_ws', TRIPAL_ERROR,
+        'Web Services error on remote site: %error.',
+        array('%error' => $error));
+    return FALSE;
+  }
+
+  return $data;
+}