Browse Source

Working on adding classes for Hydra WS

Stephen Ficklin 7 years ago
parent
commit
413c790536

+ 15 - 10
tripal_ws/includes/TripalWebService/TripalEntityService_v0_1.inc

@@ -946,10 +946,15 @@ class TripalEntityService_v0_1 extends TripalWebService {
       $supported = new TripalWebServiceResource($this->getServicePath());
       $supported->addContextItem('supportedOperation', 'hydra:supportedOperation');
       $supported->addContextItem('supportedProperty', 'hydra:supportedProperty');
-      $supported->setID(urlencode($bundle->label));
+      $supported->addContextItem('subClassOf', array(
+        "@id" => "rdfs:subClassOf",
+        "@type" => "@id"
+      ));
+      $supported->setID($this->getServicePath() . '/' . urlencode($bundle->label));
       $supported->setType('hydra:Class');
       $supported->addProperty('hydra:title', $bundle->label);
       $supported->addProperty('hydra:description', $description);
+      $supported->addProperty('subClassOf', 'hydra:Resource');
 
       // Add in the supported operations for this content type.
       $operations = array();
@@ -971,6 +976,7 @@ class TripalEntityService_v0_1 extends TripalWebService {
           "@id" => "hydra:returns",
           "@type" => "@id"
         ));
+
         $get_op->setID('_:' . preg_replace('/[^\w]/', '_', strtolower($bundle->label)) . '_retrieve');
         $get_op->setType('hydra:Operation');
         $get_op->addProperty('method', 'GET');
@@ -982,17 +988,12 @@ class TripalEntityService_v0_1 extends TripalWebService {
         }
         $get_op->addProperty('description', NULL);
         $get_op->addProperty('expects', NULL);
-        $get_op->addProperty('returns', $term->url);
-        $get_op->addProperty('statusCodes', array(
-          array(
-            'code' => 404,
-            'description' => 'The ' . $bundle->label . ' could not be found using the provided ID.'
-          ),
-        ));
+        $get_op->addProperty('returns', $this->getServicePath() . '/' . urlencode($bundle->label));
+        $get_op->addProperty('statusCodes', array());
         $operations[] = $get_op;
       }
 
-      // If the user can create this content type.
+      /* // If the user can create this content type.
       if (user_access('create ' . $bundle->name)) {
         // All content types allow GET (if the user has view permission).
         $create_op = new TripalWebServiceResource($this->getServicePath());
@@ -1108,9 +1109,13 @@ class TripalEntityService_v0_1 extends TripalWebService {
           ),
         ));
         $operations[] = $delete_op;
-      }
+      } */
 
       $supported->addProperty('supportedOperation', $operations);
+
+      // Add in the properties by examining the fields attached to the bundle.
+      $properties = array();
+      $supported->addProperty('supportedProperty', $properties);
       $supported_classes[] = $supported;
     }
 

+ 32 - 8
tripal_ws/includes/TripalWebService/TripalVocabService_v0_1.inc

@@ -63,10 +63,22 @@ class TripalVocabService_v0_1 extends TripalWebService {
       }
     }
 
-    // Now add the EntryPoint class.
+    // Add the EntryPoint class.
     $entry_point = $this->getEntryPointClass();
     $this->resource->addProperty('supportedClass', $entry_point);
 
+    // Add in the Collection class.
+    $collection = $this->getCollectionClass();
+    $this->resource->addProperty('supportedClass', $collection);
+  }
+
+  /**
+   * Generates the Collection class for the API documents.
+   *
+   * @return TripalWebServiceResource
+   *
+   */
+  private function getCollectionClass() {
     // Add the Collection class.
     $collection = new TripalWebServiceResource($this->getServicePath());
     $collection->addContextItem('supportedOperation', 'hydra:supportedOperation');
@@ -75,10 +87,11 @@ class TripalVocabService_v0_1 extends TripalWebService {
       "@id" => "hydra:property",
       "@type" => "@id"
     ));
-    $collection->setID('hydra:Collection');
+    $collection->setID('vocab:ContentCollection');
     $collection->setType('hydra:Class');
-    $collection->addProperty('hydra:title', 'Collection');
+    $collection->addProperty('hydra:title', 'Content Collection');
     $collection->addProperty('hydra:description', '');
+
     $vocab = tripal_get_vocabulary_details('hydra');
     $url = preg_replace('/{accession}/', 'member', $vocab['urlprefix']);
     $collection->addProperty('supportedProperty', array(
@@ -87,8 +100,10 @@ class TripalVocabService_v0_1 extends TripalWebService {
       "hydra:description" => "The members of this collection.",
       "required" => null,
       "readonly" => FALSE,
-      "writeonly" => FALSE
+      "writeonly" => FALSE,
     ));
+
+    $url = preg_replace('/{accession}/', 'totalItems', $vocab['urlprefix']);
     $collection->addProperty('supportedProperty', array(
       "property" => $url,
       "hydra:title" => "totalItems",
@@ -97,10 +112,19 @@ class TripalVocabService_v0_1 extends TripalWebService {
       "readonly" => FALSE,
       "writeonly" => FALSE
     ));
+    $url = preg_replace('/{accession}/', 'label', $vocab['urlprefix']);
+    $collection->addProperty('supportedProperty', array(
+      "property" => $url,
+      "hydra:title" => "label",
+      "hydra:description" => "The type of entities within the collection.",
+      "required" => null,
+      "readonly" => FALSE,
+      "writeonly" => FALSE
+    ));
 
     $collection_ops = array();
     $collection_op_get = new TripalWebServiceResource($this->base_path);
-    $collection_op_get->setID('_:collection_retrieve');
+    $collection_op_get->setID('_:content_collection_retrieve');
     $collection_op_get->setType('hydra:Operation');
     $collection_op_get->addContextItem('method', 'hydra:method');
     $collection_op_get->addContextItem('label', 'rdfs:label');
@@ -119,12 +143,12 @@ class TripalVocabService_v0_1 extends TripalWebService {
     $collection_op_get->addProperty('label', 'Retrieves members of the collection.');
     $collection_op_get->addProperty('description', null);
     $collection_op_get->addProperty('expects', null);
-    $collection_op_get->addProperty('returns', 'vocab:Collection');
+    $collection_op_get->addProperty('returns', 'vocab:ContentCollection');
     $collection_op_gets[] = $collection_op_get;
 
     $collection->addProperty('supportedOperation', $collection_op_gets);
 
-    $this->resource->addProperty('supportedClass', $collection);
+    return $collection;
   }
 
   /**
@@ -201,7 +225,7 @@ class TripalVocabService_v0_1 extends TripalWebService {
       $service_prop_prop_op_get->addProperty('description', NULL);
       $service_prop_prop_op_get->addProperty('method', 'GET');
       $service_prop_prop_op_get->addProperty('expects', null);
-      $service_prop_prop_op_get->addProperty('returns', 'hydra:Collection');
+      $service_prop_prop_op_get->addProperty('returns', 'vocab:ContentCollection');
       $service_prop_prop_op_get->addProperty('statusCodes', array());
       $service_prop_prop_ops[] = $service_prop_prop_op_get;