Преглед изворни кода

Continuing to fix web services to work with new data structures. Added filters for publishing records>

Stephen Ficklin пре 8 година
родитељ
комит
1d6edea07c

+ 5 - 1
tripal/includes/tripal.jobs.inc

@@ -236,6 +236,7 @@ function tripal_jobs_report() {
  * @ingroup tripal_jobs
  */
 function tripal_jobs_view($job_id) {
+
   // get the job record
   $sql =
     "SELECT TJ.job_id,TJ.uid,TJ.job_name,TJ.modulename,TJ.progress,
@@ -277,7 +278,10 @@ function tripal_jobs_view($job_id) {
   // generate the list of arguments for display
   $arguments = '';
   foreach ($job->arguments as $key => $value) {
-     $arguments .= "$key: $value<br>";
+    if (is_array($value)) {
+      $value = print_r($value,TRUE);
+    }
+    $arguments .= "$key: $value<br>";
   }
 
   // build the links

+ 19 - 16
tripal/tripal.module

@@ -92,22 +92,6 @@ function tripal_menu() {
     'file' => 'system.admin.inc',
     'file path' => drupal_get_path('module', 'system'),
   );
-  $items['admin/tripal/tripal_jobs'] = array(
-    'title' => 'Jobs',
-    'description' => t('Provides tools for managing jobs submitted to Tripal.  In some
-        cases, long-running tasks are too slow to complete within a single
-        browser session.  The Tripal jobs system allows long-running tasks
-        to be submitted to a queue that can be executed manually by the
-        site admin or automatically using a module such as the ') .
-        l('Tripal Daemon', 'https://www.drupal.org/project/tripal_daemon', array('attributes' => array('target' => '_blank'))) .
-        ' extension module.',
-    'page callback' => 'tripal_jobs_admin_view',
-    'access arguments' => array('administer tripal'),
-    'type' => MENU_NORMAL_ITEM,
-    'weight' => 0,
-    'file' => 'includes/tripal.jobs.inc',
-    'file path' => drupal_get_path('module', 'tripal'),
-  );
 
   $items['admin/tripal/storage'] = array(
     'title' => 'Data Storage',
@@ -191,6 +175,21 @@ function tripal_menu() {
 */
 
   // Jobs Management
+  $items['admin/tripal/tripal_jobs'] = array(
+    'title' => 'Jobs',
+    'description' => t('Provides tools for managing jobs submitted to Tripal.  In some
+        cases, long-running tasks are too slow to complete within a single
+        browser session.  The Tripal jobs system allows long-running tasks
+        to be submitted to a queue that can be executed manually by the
+        site admin or automatically using a module such as the ') .
+    l('Tripal Daemon', 'https://www.drupal.org/project/tripal_daemon', array('attributes' => array('target' => '_blank'))) .
+    ' extension module.',
+    'page callback' => 'tripal_jobs_admin_view',
+    'access arguments' => array('administer tripal'),
+    'type' => MENU_NORMAL_ITEM,
+    'weight' => 0,
+    'file' => 'includes/tripal.jobs.inc',
+  );
   $items['admin/tripal/tripal_jobs/help'] = array(
     'title' => 'Help',
     'description' => t('Help for the tripal job management system'),
@@ -207,6 +206,7 @@ function tripal_menu() {
     'page arguments' => array(4),
     'access arguments' => array('administer tripal'),
     'type' => MENU_CALLBACK,
+    'file' => 'includes/tripal.jobs.inc',
   );
   $items['admin/tripal/tripal_jobs/rerun/%'] = array(
     'title' => 'Jobs',
@@ -215,6 +215,7 @@ function tripal_menu() {
     'page arguments' => array(4),
     'access arguments' => array('administer tripal'),
     'type' => MENU_CALLBACK,
+    'file' => 'includes/tripal.jobs.inc',
   );
   $items['admin/tripal/tripal_jobs/view/%'] = array(
     'title' => 'Jobs Details',
@@ -223,6 +224,7 @@ function tripal_menu() {
     'page arguments' => array(4),
     'access arguments' => array('administer tripal'),
     'type' => MENU_CALLBACK,
+    'file' => 'includes/tripal.jobs.inc',
   );
   $items['admin/tripal/tripal_jobs/views/jobs/enable'] = array(
     'title' => 'Enable Jobs Administrative View',
@@ -230,6 +232,7 @@ function tripal_menu() {
     'page arguments' => array('tripal_admin_jobs', 'admin/tripal/tripal_jobs'),
     'access arguments' => array('administer tripal'),
     'type' => MENU_CALLBACK,
+    'file' => 'includes/tripal.jobs.inc',
   );
 
   /*

+ 19 - 1
tripal_chado/api/tripal_chado.api.inc

@@ -65,7 +65,9 @@ function tripal_chado_publish_records($values, $job_id = NULL) {
     return FALSE;
   }
 
+  // Get the incoming arguments from the $values array.
   $bundle_name = $values['bundle_name'];
+  $filters = array_key_exists('filters', $values) ? $values['filters'] : array();
   $sync_node = array_key_exists('sync_node', $values) ? $values['sync_node'] : '';
 
   // Load the bundle entity so we can get information about which Chado
@@ -120,7 +122,7 @@ function tripal_chado_publish_records($values, $job_id = NULL) {
   }
 
   // If the type column is in the base table then add in the SQL for that.
-  if (!type_linker_table and $type_column) {
+  if (!$type_linker_table and $type_column) {
     $where .= "AND T.$type_column = :cvterm_id";
     $args[':cvterm_id'] = $cvterm_id;
   }
@@ -132,11 +134,27 @@ function tripal_chado_publish_records($values, $job_id = NULL) {
     return FALSE;
   }
 
+  // Now add in any additional filters
+  $fields = field_info_field_map();
+  foreach ($fields as $field_name => $details) {
+    if (array_key_exists('TripalEntity', $details['bundles']) and
+        in_array($bundle_name, $details['bundles']['TripalEntity']) and
+        in_array($field_name, array_keys($filters))){
+      $instance = field_info_instance('TripalEntity', $field_name, $bundle_name);
+      $chado_table = $instance['settings']['chado_table'];
+      $chado_column = $instance['settings']['chado_column'];
+      if ($chado_table == $table) {
+        $where .= " AND T.$chado_column = :$field_name";
+        $args[":$field_name"] = $filters[$field_name];
+      }
+    }
+  }
   // First get the count
   $sql = "SELECT count(*) as num_records " . $from . $where;
   $result = chado_query($sql, $args);
   $count = $result->fetchField();
 
+
   // calculate the interval for updates
   $interval = intval($count / 1000);
   if ($interval < 1) {

+ 9 - 8
tripal_chado/api/tripal_chado.query.api.inc

@@ -13,14 +13,15 @@
  * @params tablename: the name of the chado table you want to select the max rank from
  *    this table must contain a rank column of type integer
  * @params where_options: array(
- *                          <column_name> => array(
- *                            'type' => <type of column: INT/STRING>,
- *                            'value' => <the value you want to filter on>,
- *                            'exact' => <if TRUE use =; if FALSE use ~>,
- *                          )
- *        )
- *     where options should include the id and type for that table to correctly
- *     group a set of records together where the only difference are the value and rank
+ *   <column_name> => array(
+ *     'type' => <type of column: INT/STRING>,
+ *     'value' => <the value you want to filter on>,
+ *     'exact' => <if TRUE use =; if FALSE use ~>,
+ *    )
+ *  )
+ *  where options should include the id and type for that table to correctly
+ *  group a set of records together where the only difference are the value and rank
+ *
  * @return the maximum rank
  *
  * @ingroup tripal_chado_api

+ 1 - 1
tripal_chado/includes/tripal_chado.field_storage.inc

@@ -399,7 +399,7 @@ function tripal_chado_field_storage_expand_field($item_name, $value) {
  * Implements hook_field_storage_query().
  */
 function tripal_chado_field_storage_query($query) {
-//print_r($query->fieldConditions);
+
   // The conditions and order bys are reorganized into a filters array for the
   // chado_select_record function()
   $filters = array();

+ 15 - 2
tripal_chado/includes/tripal_chado.publish.inc

@@ -10,6 +10,7 @@ function tripal_chado_publish_form($form, &$form_state) {
     $bundle_name = $form_state['values']['bundle_name'];
   }
 
+  // Build the list of available TripalEntity content types.
   $bundles = db_select('tripal_bundle', 'tb')
     ->fields('tb')
     ->orderBy('label', 'ASC')
@@ -56,7 +57,15 @@ function tripal_chado_publish_form($form, &$form_state) {
           in_array($bundle_name, $details['bundles']['TripalEntity'])) {
         $field = field_info_field($field_name);
         $instance = field_info_instance('TripalEntity', $field_name, $bundle_name);
-
+        $base_table = $instance['settings']['base_table'];
+        $chado_table = $instance['settings']['chado_table'];
+        $chado_field = $instance['settings']['chado_field'];
+
+        // For now, only handle filtering by fields that are mapped directly
+        // to the base table.
+        if ($base_table != $chado_table) {
+          continue;
+        }
 
         // Create a default element for this field.  This code
         // is adapted from the field_multiple-value_form() function.
@@ -143,6 +152,7 @@ function tripal_chado_publish_form_submit($form, &$form_state) {
     foreach ($fields as $field_name => $details) {
       if (array_key_exists('TripalEntity', $details['bundles']) and
           in_array($bundle_name, $details['bundles']['TripalEntity']) and
+          array_key_exists($field_name, $form_state['values']) and
           array_key_exists('value', $form_state['values'][$field_name][$langcode][0])) {
         $value = $form_state['values'][$field_name][$langcode][0]['value'];
         if ($value) {
@@ -151,7 +161,10 @@ function tripal_chado_publish_form_submit($form, &$form_state) {
       }
     }
     $args = array(
-      array('bundle_name' => $bundle_name, 'filters' => $filters),
+      array(
+        'bundle_name' => $bundle_name,
+        'filters' => $filters,
+      ),
     );
     $includes = array(
       module_load_include('inc', 'tripal_chado', 'includes/tripal_chado.publish'),

+ 24 - 28
tripal_ws/includes/tripal_ws.rest_v0.1.inc

@@ -527,13 +527,11 @@ function tripal_ws_services_v0_1_get_content_add_fields($entity, $bundle, $api_u
 
   // Get information about the fields attached to this bundle and sort them
   // in the order they were set for the display.
-  // TODO: should we allow for custom ordering of fields for web services
-  // or use the default display ordering?
   $instances = field_info_instances('TripalEntity', $bundle->name);
 
   uasort($instances, function($a, $b) {
-    $a_weight = (is_array($a) && isset($a['display']['default']['weight'])) ? $a['display']['default']['weight'] : 0;
-    $b_weight = (is_array($b) && isset($b['display']['default']['weight'])) ? $b['display']['default']['weight'] : 0;
+    $a_weight = (is_array($a) && isset($a['widget']['weight'])) ? $a['widget']['weight'] : 0;
+    $b_weight = (is_array($b) && isset($b['widget']['weight'])) ? $b['widget']['weight'] : 0;
 
     if ($a_weight == $b_weight) {
       return 0;
@@ -563,27 +561,25 @@ function tripal_ws_services_v0_1_get_content_add_fields($entity, $bundle, $api_u
     // term from the vocabulary that the field is assigned. But in the
     // case that the field is not assigned a term, we must use the field name.
     $field_name = $instance['field_name'];
-    $field_settings = $field['settings'];
-    $key = $field_name;
-    $key_adj = strtolower(preg_replace('/ /', '_', $key));
-    if (array_key_exists('semantic_web', $field_settings) and $field_settings['semantic_web']) {
-      list($vocabulary, $accession) = explode(':', $field_settings['semantic_web']);
-      $term = tripal_get_term_details($vocabulary, $accession);
-      if ($term) {
-        $key = $term['name'];
-        $key_adj = strtolower(preg_replace('/ /', '_', $key));
-        $response['@context'][$key_adj] = array(
-          '@id' => $term['url'],
-        );
-      }
+    $vocabulary = $instance['settings']['term_vocabulary'];
+    $accession = $instance['settings']['term_accession'];
+    $term = tripal_get_term_details($vocabulary, $accession);
+    $term = tripal_get_term_details($vocabulary, $accession);
+    if ($term) {
+      $key = $term['name'];
+      $key_adj = strtolower(preg_replace('/ /', '_', $key));
+      $response['@context'][$key_adj] = $term['url'];
     }
 
     // If this field should not be attached by default then just add a link
     // so that the caller can get the information separately.
     $instance_settings = $instance['settings'];
-    if (array_key_exists('auto_attach', $instance_settings) and
+    if (array_key_exists('auto_attach', $instance['settings']) and
         $instance_settings['auto_attach'] != TRUE) {
-      $response['@context'][$key_adj]['@type'] = '@id';
+      $response['@context'][$key_adj] = array(
+        '@id' => $response['@context'][$key_adj],
+        '@type' => '@id'
+      );
       $response[$key_adj] = url($api_url . '/content/' . $ctype . '/' . $entity->id . '/' . urlencode($key), array('absolute' => TRUE));
       continue;
     }
@@ -593,8 +589,8 @@ function tripal_ws_services_v0_1_get_content_add_fields($entity, $bundle, $api_u
   }
 
   // Lastly, add in the terms used into the @context section.
-  $response['@context']['label'] = 'rdfs:label';
-  $response['@context']['itemPage'] = 'schema:itemPage';
+  $response['@context']['label'] = 'https://www.w3.org/TR/rdf-schema/#ch_label';
+  $response['@context']['itemPage'] = 'https://schema.org/ItemPage';
 
   //   $response['operation'][] = array(
   //     '@type' => 'hydra:DeleteResourceOperation',
@@ -655,7 +651,7 @@ function tripal_ws_services_v0_1_get_content($api_url, &$response, $ws_path, $ct
   $response['@context']['hydra'] = 'http://www.w3.org/ns/hydra/core#';
 
   // If we have an argument in the 4th element (3rd index) then the user
-  // is requesting to epxand the details of a field that was not
+  // is requesting to expand the details of a field that was not
   // initially attached to the enity.
   $field_arg = '';
   if (array_key_exists(3, $ws_path)) {
@@ -781,7 +777,7 @@ function tripal_ws_services_v0_1_get_content_add_field($key, $entity, $field, $i
       }
     }
 
-    // Recurse through the values array and set the entity elemtns
+    // Recurse through the values array and set the entity elemetns
     // and add the fields to the context.
     tripal_ws_services_v0_1_get_content_add_field_context($items[$i], $response, $api_url);
 
@@ -813,13 +809,13 @@ function tripal_ws_services_v0_1_get_content_add_field($key, $entity, $field, $i
   // If we have more than one value then set the response to be a collection.
   if (count($values) > 1) {
 
-  // If this is the field page then the Collection is added directly to the
+    // If this is the field page then the Collection is added directly to the
     // response, otherwise, it's added under the field $key.
     if ($is_field_page) {
-    $response['@type'] = 'Collection';
-        $response['totalItems'] = count($values);
-        $response['label'] = $instance['label'];
-        $response['member'] = $values;
+      $response['@type'] = 'Collection';
+      $response['totalItems'] = count($values);
+      $response['label'] = $instance['label'];
+      $response['member'] = $values;
     }
     else {
       $response[$key] = array(