|
@@ -130,7 +130,7 @@ function tripal_ws_services() {
|
|
|
function tripal_ws_entity_load($entities, $type) {
|
|
|
foreach ($entities as $entity) {
|
|
|
//if ($entiy->type = 'TripalEntity') {
|
|
|
- dpm($entity);
|
|
|
+ // dpm($entity);
|
|
|
//}
|
|
|
}
|
|
|
}
|
|
@@ -141,7 +141,7 @@ function tripal_ws_load_remote_entity($site_id, $api_version, $ctype, $id) {
|
|
|
$url = "https://dev.bioinfo.wsu.edu/~ccheng/tripal3/ws/v0.1/content/gene/12";
|
|
|
$json = file_get_contents($url);
|
|
|
$response = json_decode($json, TRUE);
|
|
|
- dpm($response);
|
|
|
+ //dpm($response);
|
|
|
|
|
|
// Set the title for this page to match the title provided.
|
|
|
drupal_set_title($response['label']);
|
|
@@ -161,28 +161,70 @@ function tripal_ws_load_remote_entity($site_id, $api_version, $ctype, $id) {
|
|
|
$entity->uid = 1;
|
|
|
$entity->status = 1;
|
|
|
|
|
|
- // Add fields.
|
|
|
- $entity->feature__name = array(
|
|
|
- 'und' => array(
|
|
|
- 0 => array(
|
|
|
- 'value' => $response['name'],
|
|
|
- ),
|
|
|
- ),
|
|
|
- );
|
|
|
- $entity->feature__organism_id = array(
|
|
|
- 'und' => array(
|
|
|
- 0 => array(
|
|
|
- 'value' => $response['organism'],
|
|
|
- ),
|
|
|
- ),
|
|
|
- );
|
|
|
- $sequences_json = file_get_contents($response['sequence']);
|
|
|
- $sequences = json_decode($sequences_json, TRUE);
|
|
|
- $entity->feature__residues = array();
|
|
|
- foreach ($sequences['member'] as $delta => $value) {
|
|
|
- $entity->feature__residues['und'][$delta]['value'] = $sequences['member'][$delta];
|
|
|
+ // Get the fields and create a list of those that are attached to the bundle.
|
|
|
+ $fields = field_info_fields();
|
|
|
+ $my_fields = array();
|
|
|
+ foreach ($fields as $field) {
|
|
|
+ if (isset($field['bundles']['TripalEntity'])) {
|
|
|
+ foreach ($field['bundles']['TripalEntity'] as $bundle_name) {
|
|
|
+ if ($bundle_name == 'bio_data_266') {
|
|
|
+ $my_fields[] = $field;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
}
|
|
|
- dpm($entity);
|
|
|
+
|
|
|
+ // For each field we know about that should be attached to our bundle,
|
|
|
+ // see if we can find a corresponding entry in the results returned from
|
|
|
+ // the web service call. If so, then add the field to our fake entity.
|
|
|
+ foreach ($my_fields as $field) {
|
|
|
+ // Get the semantic web term for this field.
|
|
|
+ $field_name = $field['field_name'];
|
|
|
+ $settings = $field['settings'];
|
|
|
+
|
|
|
+ // If the field does not have a semantic web mapping, then skip it.
|
|
|
+ if (!isset($settings['semantic_web'])) {
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+
|
|
|
+ // Convert the term into it's db and accession elements and look it up
|
|
|
+ // for more details.
|
|
|
+ list($vocabulary, $accession) = explode(':', $settings['semantic_web']);
|
|
|
+ $term = tripal_get_term_details($vocabulary, $accession);
|
|
|
+
|
|
|
+ // Convert the term to lowercase and remove spaces so we can compare
|
|
|
+ // correctly.
|
|
|
+ $term_name = strtolower(preg_replace('/ /', '_', $term['name']));
|
|
|
+
|
|
|
+ // TODO: check for the term in the response makes the assumption
|
|
|
+ // that the term is the same on both sides. This may not be true. The
|
|
|
+ // acutal vocab and accession for both terms should be compared.
|
|
|
+ if (isset($response[$term_name])) {
|
|
|
+
|
|
|
+ // If this field is of type '@id' then this links out to another
|
|
|
+ // URL where that information can be retrieved. We'll have to
|
|
|
+ // handle that separately.
|
|
|
+ if (isset($response['@context'][$term_name]['@type']) and
|
|
|
+ $response['@context'][$term_name]['@type'] == '@id') {
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+
|
|
|
+ // For all fields that are currently attached, add the field and
|
|
|
+ // value to the entity.
|
|
|
+ $f = array();
|
|
|
+ $f['und'][0]['value'] = $response[$term_name];
|
|
|
+ $entity->$field_name = $f;
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+// // For fields that are links rather than values then we
|
|
|
+// $sequences_json = file_get_contents($response['sequence']);
|
|
|
+// $sequences = json_decode($sequences_json, TRUE);
|
|
|
+// $entity->feature__residues = array();
|
|
|
+// foreach ($sequences['member'] as $delta => $value) {
|
|
|
+// $entity->feature__residues['und'][$delta]['value'] = $sequences['member'][$delta];
|
|
|
+// }
|
|
|
+// dpm($entity);
|
|
|
|
|
|
// Generate the View for this entity
|
|
|
$entities = array();
|