Browse Source

Fixing entity fields and web services

Stephen Ficklin 8 years ago
parent
commit
ddd09567b7

+ 2 - 0
tripal_chado/includes/TripalFields/sbo__database_cross_reference/sbo__database_cross_reference.inc

@@ -78,11 +78,13 @@ class sbo__database_cross_reference extends ChadoField {
     // Set some defaults for the empty record.
     $entity->{$field_name}['und'][0] = array(
       'value' => array(
+        /* sub elements that may be present in the values array
         // Database name
         'data:1056' => '',
         // Accession
         'data:2091' => '',
         'schema:url' => '',
+        */
       ),
       'chado-' . $field_table . '__' . $pkey => '',
       'chado-' . $field_table . '__' . $fkey_lcolumn => '',

+ 1 - 1
tripal_chado/includes/TripalFields/sbo__database_cross_reference/sbo__database_cross_reference_formatter.inc

@@ -27,7 +27,7 @@ class sbo__database_cross_reference_formatter extends ChadoFieldFormatter {
         continue;
       }
       $content = $item['value']['data:1056'] . ':' . $item['value']['data:2091'];
-      if ($item['value']['URL']) {
+      if ($item['value']['schema:url']) {
         $content = l($content, $item['value']['schema:url'], array('attributes' => array('target' => '_blank')));
       }
       $element[$delta] = array(

+ 4 - 4
tripal_chado/includes/TripalFields/sbo__relationship/sbo__relationship_formatter.inc

@@ -50,15 +50,15 @@ class sbo__relationship_formatter extends ChadoFieldFormatter {
       $phrase = preg_replace("/$subject_type/", "<b>$subject_type</b>", $phrase);
       $phrase = preg_replace("/$object_type/", "<b>$object_type</b>", $phrase);
 
-      if (array_key_exists('entity', $item['value']['object'])) {
-        list($entity_type, $object_entity_id) = explode(':', $item['value']['object']['entity']);
+      if (array_key_exists('entity', $item['value']['local:relationship_object'])) {
+        list($entity_type, $object_entity_id) = explode(':', $item['value']['local:relationship_object']['entity']);
         if ($object_entity_id != $entity->id) {
           $link = l($object_name, 'bio_data/' . $object_entity_id);
           $phrase = preg_replace("/$object_name/", $link, $phrase);
         }
       }
-      if (array_key_exists('entity', $item['value']['subject'])) {
-        list($entity_type, $subject_entity_id) = explode(':', $item['value']['subject']['entity']);
+      if (array_key_exists('entity', $item['value']['local:relationship_subject'])) {
+        list($entity_type, $subject_entity_id) = explode(':', $item['value']['local:relationship_subject']['entity']);
         if ($subject_entity_id != $entity->id) {
           $link = l($subject_name, 'bio_data/' . $subject_entity_id);
           $phrase = preg_replace("/$subject_name/", $link, $phrase);

+ 8 - 2
tripal_chado/tripal_chado.install

@@ -646,14 +646,14 @@ function tripal_chado_chado_bundle_schema() {
         'default' => '',
       ),
       'type_linker_table' => array(
-        'description' => 'The table in Chado that identifies the data type. This column should be used if the data type is not specified by a "type_id" (or similar) field in the data table. The linker table must have a foreign key to the data table.',
+        'description' => 'If a linker table (e.g. cvterm/prop) is needed to uniquely identify a content type then that table name is provided here.',
         'type' => 'varchar',
         'length' => 128,
         'not null' => FALSE,
         'default' => '',
       ),
       'type_column' => array(
-        'description' => 'The column in the data table that distinguishes the data types. This must be in a foreign key relationship to the cvterm table.',
+        'description' => 'The column in the data table or linker table that distinguishes the data type. This must be in a foreign key relationship to the cvterm table.',
         'type' => 'varchar',
         'length' => 128,
         'not null' => FALSE,
@@ -666,6 +666,12 @@ function tripal_chado_chado_bundle_schema() {
         'not null' => TRUE,
         'default' => '',
       ),
+      'type_value' => array(
+        'description' => 'If a property table is used for a linker, then the value that should be matched to identify this content type is stored here.',
+        'type' => 'text',
+        'not null' => FALSE,
+        'default' => '',
+      )
     ),
     'indexes' => array(
       'bundle_id' => array('bundle_id'),

+ 13 - 22
tripal_ws/includes/tripal_ws.rest_v0.1.inc

@@ -729,7 +729,7 @@ function tripal_ws_services_v0_1_get_content($api_url, &$response, $ws_path, $ct
 
   tripal_ws_services_v0_1_get_content_add_fields($entity, $bundle, $api_url, $response, $ws_path, $ctype, $entity_id, $params);
 
-  //tripal_ws_services_v0_1_write_context($response, $ctype);
+  tripal_ws_services_v0_1_write_context($response, $ctype);
 }
 
 /**
@@ -738,27 +738,18 @@ function tripal_ws_services_v0_1_get_content($api_url, &$response, $ws_path, $ct
  * @param $ctype
  */
 function tripal_ws_services_v0_1_write_context(&$response, $ctype) {
-  // We want to write the context to a file. Try to open the lock file. if we
-  // can't then just leave the context in the response.
-  $context_uri = file_build_uri("ws.v0_1.$ctype.context.jsonld");
-  $context_file = drupal_realpath($context_uri);
-  $context_URL = file_create_url($context_uri);
-  $lock_fp = fopen("$context_file.lock", "w");
-  if (flock($lock_fp, LOCK_EX|LOCK_NB)) {
-    $fp = fopen("$context_file", "w");
-    if ($fp) {
-      $context = array('@context' => $response['@context']);
-      fwrite($fp, json_encode($context));
-      fflush($fp);
-      // Release the lock.
-      flock($lock_fp, LOCK_UN);
-      // Close the files.
-      fclose($lock_fp);
-      fclose($fp);
-      // Change the context to point to the file
-      $response['@context'] = $context_URL;
-    }
-  }
+  // Save the response '@context' into a temporary file
+  $context = array('@context' => $response['@context']);
+  $file_name = drupal_tempnam(file_default_scheme() . '://', 'tws_context-') . '.json';
+  $context_file = file_save_data(json_encode($context), $file_name, FILE_EXISTS_REPLACE );
+
+  // Mark the file as temporary by setting it's status
+  $context_file->status = 0;
+  file_save($context_file);
+
+  // Return the response with the '@context' section replaced with the file URL.
+  $response['@context'] = file_create_url($context_file->uri);
+
 }
 
 /**