Browse Source

Fixed a few bugs in web services related to querying

Stephen Ficklin 8 years ago
parent
commit
64f6012f93

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

@@ -164,7 +164,7 @@ function tripal_chado_publish_records($values, $job_id = NULL) {
   // Perform the query.
   $sql = $select . $from . $where;
   $records = chado_query($sql, $args);
-  //$transaction  = db_transaction();
+  $transaction = db_transaction();
 
   print "\nNOTE: publishing records is performed using a database transaction. \n" .
       "If the load fails or is terminated prematurely then the entire set of \n" .

+ 0 - 1
tripal_chado/includes/ChadoDatabaseConnection.inc

@@ -48,7 +48,6 @@ class ChadoDatabaseConnection extends DatabaseConnection_pgsql {
 
   public function prefixTables($sql) {
     $sql = str_replace($this->prefixSearch, $this->prefixReplace, $sql);
-    //print_r($sql);
     return $sql;
   }
 

+ 2 - 2
tripal_chado/includes/TripalFields/sbo__relationship/sbo__relationship.inc

@@ -375,8 +375,8 @@ class sbo__relationship extends ChadoField {
         // Add the clause to the value array.
         $rel_type_clean = lcfirst(preg_replace('/_/', ' ', $rel_type));
         $entity->{$field_name}['und'][$i]['value']['SIO:000493'] = 'This ' .
-          $subject_type . ', ' . $subject_name . ' ' . $verb . ' '  . $rel_type_clean . ' the '  .
-          $object_type . ', ' . $object_name . '.';
+          $subject_type . ', ' . $subject_name . ', ' . $verb . ' '  . $rel_type_clean . ' the '  .
+          $object_type . ' ' . $object_name . '.';
 
         $entity->{$field_name}['und'][$i]['chado-' . $field_table . '__' . $pkey] = $relationship->$pkey;
         $entity->{$field_name}['und'][$i]['chado-' . $field_table . '__' . $subject_id_key] = $relationship->$subject_id_key->$subject_pkey;

+ 4 - 7
tripal_chado/includes/loaders/tripal_cv.owl_loader.php

@@ -453,14 +453,12 @@ function tripal_owl_handle_class(OWLStanza $stanza, $vocabs) {
     'db_id' => $db->db_id,
     'accession' => $accession
   );
-  print_r($values);
   $dbxref = tripal_insert_dbxref($values);
 
   $cvterm_name = $stanza->getChild('rdfs:label');
   if ($cvterm_name) {
   $cvterm_name = $stanza->getValue();
   }
-  print_r($cvterm_name);
 
   $definition = $stanza->getChild('obo:IAO_0000115');
   if ($definition) {
@@ -468,12 +466,11 @@ function tripal_owl_handle_class(OWLStanza $stanza, $vocabs) {
   }
 
   $term = array (
-  'id' => $db->name . ':' . $dbxref->accession,
-  'name' => $db->name,
-  'cv_name' => $stanza->getValue(),
-  'definition' =>  $stanza->getValue(),
+    'id' => $db->name . ':' . $dbxref->accession,
+    'name' => $db->name,
+    'cv_name' => $stanza->getValue(),
+    'definition' =>  $stanza->getValue(),
   );
-  print_r($term);
 
   $options = array ();
   if ($vocabs['this'] != $db->name) {

+ 23 - 0
tripal_chado/includes/tripal_chado.field_storage.inc

@@ -438,6 +438,7 @@ function tripal_chado_field_storage_query($query) {
   $cquery = chado_db_select($data_table, 'base');
   $cquery->fields('base', array($pkey));
 
+
   // Iterate through all the conditions and add to the filters array
   // a chado_select_record compatible set of filters.
   foreach ($query->fieldConditions as $index => $condition) {
@@ -473,6 +474,26 @@ function tripal_chado_field_storage_query($query) {
         $field_obj = new $field_type($field, $instance);
         $field_obj->query($cquery, $condition);
       }
+      // If there is no ChadoField class for this field then add the
+      // condition as is.
+      else {
+        $alias = $field['field_name'];
+        $chado_table = $instance['settings']['chado_table'];
+        $base_table = $instance['settings']['base_table'];
+        $bschema = chado_get_schema($base_table);
+        $bpkey = $bschema['primary key'][0];
+
+        if ($chado_table == $base_table) {
+          // Get the base table column that is associated with the term
+          // passed as $condition['column'].
+          $base_field = tripal_get_chado_semweb_column($chado_table, $condition['column']);
+          $cquery->condition('base.' . $base_field , $condition['value'], $condition['operator']);
+        }
+        if ($chado_table != $base_table) {
+          // TODO: I don't think we'll get here but just in case here's a
+          // note to handle it.
+        }
+      }
     }
   } // end foreach ($query->fieldConditions as $index => $condition) {
 
@@ -485,6 +506,8 @@ function tripal_chado_field_storage_query($query) {
   if (array_key_exists('start', $query->range)) {
     $cquery->range($query->range['start'], $query->range['length']);
   }
+  // Make sure we only get records of the correct entity type
+  $cquery->condition('TE.bundle', $query->entityConditions['bundle']['value']);
 
   // Now set any ordering.
   foreach ($query->order as $index => $sort) {

+ 0 - 1
tripal_chado/tripal_chado.drush.inc

@@ -117,7 +117,6 @@ function tripal_chado_drush_command() {
     ),
   );
 
-
   return $items;
 }
 

+ 15 - 1
tripal_ws/includes/tripal_ws.rest_v0.1.inc

@@ -11,7 +11,6 @@ function tripal_ws_services_v0_1($api_url, $ws_path, $params) {
   $response = array();
   $version = 'v0.1';
 
-
   // Set some defaults for the response.
   $response['@context'] =  array();
 
@@ -140,6 +139,8 @@ function tripal_ws_services_v0_1_get_vocabs($api_url, &$response) {
   $response['@context']['member'] = 'hydra:member';
   $response['@context']['label'] = 'rdfs:label';
   $response['@context']['description'] = 'hydra:description';
+
+  tripal_ws_services_v0_1_write_context($response, $ctype);
 }
 
 /**
@@ -200,6 +201,8 @@ function tripal_ws_services_v0_1_get_vocab($api_url, &$response, $ws_path, $voca
   $response['@context']['comment'] = 'rdfs:comment';
   $response['@context']['itemPage'] = 'schema:itemPage';
 
+  tripal_ws_services_v0_1_write_context($response, $ctype);
+
 }
 
 /**
@@ -234,6 +237,8 @@ function tripal_ws_services_v0_1_get_term($api_url, &$response, $ws_path, $vocab
   // Lastly, add in the terms used into the @context section.
   $response['@context']['label'] = 'rdfs:label';
   $response['@context']['itemPage'] = 'schema:itemPage';
+
+  tripal_ws_services_v0_1_write_context($response, $ctype);
 }
 /**
  * Provides a collection (list) of all of the content types.
@@ -294,6 +299,8 @@ function tripal_ws_services_v0_1_get_content_types($api_url, &$response) {
   $response['@context']['member'] = 'hydra:member';
   $response['@context']['label'] = 'rdfs:label';
   $response['@context']['description'] = 'hydra:description';
+
+  tripal_ws_services_v0_1_write_context($response, $ctype);
 }
 
 /**
@@ -347,6 +354,7 @@ function tripal_ws_services_v0_1_get_content_type($api_url, &$response, $ws_path
       }
     }
   }
+
   // Convert the filters to their field names
   $new_params = array();
   $order = array();
@@ -412,6 +420,7 @@ function tripal_ws_services_v0_1_get_content_type($api_url, &$response, $ws_path
       }
       $new_params[$field_name]['value'] = $value;
       $new_params[$field_name]['op'] = $op;
+      $new_params[$field_name]['column'] = $column_name;
     }
     else {
       throw new Exception("The filter term, '$key', is not available for use.");
@@ -424,6 +433,7 @@ function tripal_ws_services_v0_1_get_content_type($api_url, &$response, $ws_path
   $query->entityCondition('bundle', $bundle->name);
   foreach($new_params as $field_name => $details) {
     $value = $details['value'];
+    $column_name = $details['column'];
     switch ($details['op']) {
       case 'eq':
         $op = '=';
@@ -553,6 +563,8 @@ function tripal_ws_services_v0_1_get_content_type($api_url, &$response, $ws_path
 //       )
 //     )
 //   );
+
+  tripal_ws_services_v0_1_write_context($response, $ctype);
 }
 
 /**
@@ -964,6 +976,8 @@ function tripal_ws_services_v0_1_handle_doc_service($api_url, &$response) {
     "@type" => "@id",
   );
   $response['@context']['description'] = 'hydra:description';
+
+  tripal_ws_services_v0_1_write_context($response, $ctype);
 }
 
 /**