Browse Source

Fixes for WS

Stephen Ficklin 8 years ago
parent
commit
186e173eaa

+ 7 - 1
tripal/includes/TripalFieldQuery.inc

@@ -59,7 +59,13 @@ class TripalFieldQuery extends EntityFieldQuery {
     else {
       $results = call_user_func($this->queryCallback(), $this);
     }
-    return $results;
+
+    if ($this->count) {
+      return count(array_keys($results['TripalEntity']));
+    }
+    else {
+      return $results;
+    }
   }
 
 

+ 1 - 1
tripal_chado/includes/fields/chado_feature__residues.inc

@@ -320,7 +320,7 @@ class chado_feature__residues extends TripalField {
     ";
     $results = chado_query($sql, array(':feature_id' => $feature->feature_id));
     $coding_seq = '';
-    while ($CDS = $results->fetchObject) {
+    while ($CDS = $results->fetchObject()) {
       if ($CDS->residues) {
         $coding_seq .= $CDS->residues;
       }

+ 1 - 0
tripal_chado/includes/fields/chado_linker__dbxref.inc

@@ -365,6 +365,7 @@ class chado_linker__dbxref extends TripalField {
       $i = 0;
       foreach ($record->$linker_table as $index => $linker) {
         $dbxref = $linker->dbxref_id;
+        $URL = tripal_get_dbxref_url($dbxref);
         $entity->{$field_name}['und'][$i] = array(
           'value' => array(
             'vocabulary' => $dbxref->db_id->name,

+ 6 - 6
tripal_chado/includes/fields/chado_linker__featureloc.inc

@@ -367,12 +367,12 @@ class chado_linker__featureloc extends TripalField {
    * alignment of feature 3 with feature 2
    *
    * Features may align to more than one feature and are not matches. We do
-     * not want to include these, so we have to filter on the SO terms:
-     * match, or %_match
-     *
-     * @ingroup tripal_feature
-     */
-   private  function get_matched_alignments($feature) {
+   * not want to include these, so we have to filter on the SO terms:
+   * match, or %_match
+   *
+   * @ingroup tripal_feature
+   */
+   static public function get_matched_alignments($feature) {
 
      $sql = "
        SELECT

+ 5 - 29
tripal_chado/includes/fields/chado_linker__relationship.inc

@@ -710,20 +710,8 @@ class chado_linker__relationship extends TripalField {
 
         $entity->{$field_name}['und'][$i]['semantic_web'] = array(
           'type' => $rel_acc,
-          'subject' => array(
-            $relationship->subject_id->type_id->dbxref_id->db_id->name . ':' . $relationship->subject_id->type_id->dbxref_id->accession,
-            array(
-              'type' => '',
-              'name' => '',
-            ),
-          ),
-          'object' => array(
-            $relationship->object_id->type_id->dbxref_id->db_id->name . ':' . $relationship->sobject_id->type_id->dbxref_id->accession,
-            array(
-              'type' => '',
-              'name' => '',
-            ),
-          ),
+          'subject' => $relationship->subject_id->type_id->dbxref_id->db_id->name . ':' . $relationship->subject_id->type_id->dbxref_id->accession,
+          'object' => $relationship->object_id->type_id->dbxref_id->db_id->name . ':' . $relationship->object_id->type_id->dbxref_id->accession,
         );
 
         $entity->{$field_name}['und'][$i][$field_table . '__' . $pkey] = $relationship->$pkey;
@@ -784,20 +772,8 @@ class chado_linker__relationship extends TripalField {
 
         $entity->{$field_name}['und'][$i]['semantic_web'] = array(
           'type' => $rel_acc,
-          'subject' => array(
-            $relationship->subject_id->type_id->dbxref_id->db_id->name . ':' . $relationship->subject_id->type_id->dbxref_id->accession,
-            array(
-              'type' => '',
-              'name' => '',
-            ),
-          ),
-          'object' => array(
-            $relationship->object_id->type_id->dbxref_id->db_id->name . ':' . $relationship->sobject_id->type_id->dbxref_id->accession,
-            array(
-              'type' => '',
-              'name' => '',
-            ),
-          ),
+          'subject' => $relationship->subject_id->type_id->dbxref_id->db_id->name . ':' . $relationship->subject_id->type_id->dbxref_id->accession,
+          'object' => $relationship->object_id->type_id->dbxref_id->db_id->name . ':' . $relationship->object_id->type_id->dbxref_id->accession,
         );
 
 
@@ -829,7 +805,7 @@ class chado_linker__relationship extends TripalField {
    * @return
    *   The verb to use when creating a sentence of the relationship.
    */
-  private function get_rel_verb($rel_type) {
+  public static function get_rel_verb($rel_type) {
     $rel_type_clean = lcfirst(preg_replace('/_/', ' ', $rel_type));
     $verb = $rel_type_clean;
     switch ($rel_type_clean) {

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

@@ -410,6 +410,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()
@@ -435,7 +436,6 @@ function tripal_chado_field_storage_query($query) {
     $chado_column = $settings['chado_column'];
 
     // Set the value for this field search.
-    $value = NULL;
     $subfields = explode('.', $column);
     //print_r($subfields);
     if (count($subfields) > 1) {
@@ -559,6 +559,10 @@ function tripal_chado_field_storage_query($query) {
       $select->fields('CE', array('entity_id'));
       $select->fields('TE', array('bundle'));
       $select->condition('record_id', $record_ids);
+      // If a bundle is specified then make sure we match on the bundle.
+      if (array_key_exists('bundle', $query->entityConditions)) {
+        $select->condition('bundle', $query->entityConditions['bundle']);
+      }
       $results = $select->execute();
       while ($result = $results->fetchObject()) {
         $entity_ids[] = array($result->entity_id, 0, $result->bundle);

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

@@ -366,12 +366,13 @@ function tripal_ws_services_v0_1_get_content_type($api_url, &$response, $ws_path
     if (count($subkeys) > 0) {
       $key = array_shift($subkeys);
     }
+    $column_name = $key;
 
     // Map the values in the filters to their appropriate field names.
     if (array_key_exists($key, $field_mapping)) {
       $field_name = $field_mapping[$key];
       if (count($subkeys) > 0) {
-        $field_name .= '.' . implode('.', $subkeys);
+        $column_name .= '.' . implode('.', $subkeys);
       }
       $new_params[$field_name]['value'] = $value;
       $new_params[$field_name]['op'] = $op;
@@ -415,41 +416,47 @@ function tripal_ws_services_v0_1_get_content_type($api_url, &$response, $ws_path
       default:
         $op = '=';
     }
-    $query->fieldCondition($field_name, $field_name, $value, $op);
+    // We pass in the $column_name as an identifier for any sub fields
+    // that are present for the fields.
+    $query->fieldCondition($field_name, $column_name, $value, $op);
   }
 
   // Perform the query just as a count first to get the number of records.
   $cquery = clone $query;
   $cquery->count();
   $num_records = $cquery->execute();
+  if (!$num_records) {
+    $num_records = 0;
+  }
 
   // Add in the pager to the response.
   $response['totalItems'] = $num_records;
   $limit = array_key_exists('limit', $params) ? $params['limit'] : 25;
+  drupal_debug(array($num_records, $limit));
   $total_pages = ceil($num_records / $limit);
   $page = array_key_exists('page', $params) ? $params['page'] : 1;
-  $response['view'] = array(
-    '@id' => $URL . "?page=$page&limit=$limit",
-    '@type' => 'PartialCollectionView',
-    'first' => $URL . "?page=1&limit=$limit",
-    'last' => $URL . "?page=$total_pages&limit=$limit",
-  );
-  $prev = $page - 1;
-  $next = $page + 1;
-  if ($prev > 0) {
-    $response['view']['previous'] = $URL . "?page=$prev&limit=$limit";
-  }
-  if ($next < $total_pages) {
-    $response['view']['next'] = $URL . "?page=$next&limit=$limit";
+  if ($num_records > 0) {
+    $response['view'] = array(
+      '@id' => $URL . "?page=$page&limit=$limit",
+      '@type' => 'PartialCollectionView',
+      'first' => $URL . "?page=1&limit=$limit",
+      'last' => $URL . "?page=$total_pages&limit=$limit",
+    );
+    $prev = $page - 1;
+    $next = $page + 1;
+    if ($prev > 0) {
+      $response['view']['previous'] = $URL . "?page=$prev&limit=$limit";
+    }
+    if ($next < $total_pages) {
+      $response['view']['next'] = $URL . "?page=$next&limit=$limit";
+    }
   }
 
-  // Now perform teh query.
+  // Now perform the query.
   $start = ($page - 1) * $limit;
   $query->range($start, $limit);
   $results = $query->execute();
 
-
-
   // Iterate through the entities and add them to the list.
   $i = 0;
   foreach ($results['TripalEntity'] as $entity_id => $stub) {
@@ -459,16 +466,17 @@ function tripal_ws_services_v0_1_get_content_type($api_url, &$response, $ws_path
    // We don't need all of the attached fields for an entity so, we'll
    // not use the entity_load() function.  Instead just pull it from the
    // database table.
-   $entity = db_select('tripal_entity', 'TE')
-     ->fields('TE')
-     ->condition('TE.id', $entity_id)
-     ->execute()
-     ->fetchObject();
+   $query = db_select('tripal_entity', 'TE');
+   $query->join('tripal_term', 'TT', 'TE.term_id = TT.id');
+   $query->fields('TE');
+   $query->fields('TT', array('name'));
+   $query->condition('TE.id', $entity_id);
+   $entity = $query->execute()->fetchObject();
 
     //$entity = tripal_load_entity('TripalEntity', array($entity->id));
     $response['member'][] = array(
       '@id' => url($api_url . '/content/' . urlencode($ctype) . '/' .  $entity->id, array('absolute' => TRUE)),
-      '@type' => $ctype,
+      '@type' => $entity->name,
       'label' => $entity->title,
       'itemPage' => url('/bio_data/' . $entity->id, array('absolute' => TRUE)),
     );

+ 14 - 0
tripal_ws/tripal_ws.module

@@ -127,6 +127,11 @@ function tripal_ws_services() {
   print drupal_json_encode($response);
 }
 
+/**
+ *
+ * @param $entities
+ * @param $type
+ */
 function tripal_ws_entity_load($entities, $type) {
   foreach ($entities as $entity) {
     //if ($entiy->type = 'TripalEntity') {
@@ -135,6 +140,15 @@ function tripal_ws_entity_load($entities, $type) {
   }
 }
 
+/**
+ *
+ * @param $site_id
+ * @param $api_version
+ * @param $ctype
+ * @param $id
+ *
+ * @return
+ */
 function tripal_ws_load_remote_entity($site_id, $api_version, $ctype, $id) {
 
   // Get the content type on this site