Browse Source

Fixes to WS entry point

Stephen Ficklin 7 years ago
parent
commit
9338ade6a2

+ 49 - 0
tripal_ws/includes/TripalWebService/TripalVocabService_v0_1.inc

@@ -23,6 +23,7 @@ class TripalVocabService_v0_1 extends TripalWebService {
    */
   public function handleRequest() {
 
+    $this->resource->addContextItem('vocab', $this->getServicePath());
     $this->resource->addContextItem('ApiDocumentation', 'hydra:ApiDocumentation');
     $this->resource->addContextItem('supportedClass', 'hydra:supportedClass');
     $this->resource->setType('ApiDocumentation');
@@ -37,5 +38,53 @@ class TripalVocabService_v0_1 extends TripalWebService {
         $this->resource->addProperty('supportedClass', $supported);
       }
     }
+
+    // Add in the generic supported classes.
+    $entry_class = new TripalWebServiceResource($this->base_path);
+    $entry_class->addContextItem('vocab', $this->getServicePath());
+    $entry_class->addContextItem('label', 'rdfs:label');
+    $entry_class->setID('vocab:EntryPoint');
+    $entry_class->setType('hydra:Class');
+    $entry_class->addProperty('label', 'Entry Point');
+    $entry_class->addContextItem('description', 'rdfs:comment');
+    $entry_class->addProperty('description', 'The main entry point or homepage of the API');
+    $entry_class->addContextItem('subClassOf', array(
+      "@id" => "rdfs:subClassOf",
+      "@type" => "@id"
+    ));
+    $entry_class->addProperty('subClassOf', NULL);
+    $entry_class->addContextItem('supportedOperation', 'hydra:supportedOperation');
+    $entry_class->addContextItem('supportedProperty', 'hydra:supportedProperty');
+
+
+    $operations = array();
+
+    $get_op = new TripalWebServiceResource($this->getServicePath());
+    $get_op->addContextItem('method', 'hydra:method');
+    $get_op->addProperty('method', 'GET');
+    $get_op->addContextItem('statusCodes', 'hydra:statusCodes');
+    $get_op->addProperty('statusCodes', array());
+    $get_op->addContextItem('label', 'rdfs:label');
+    $get_op->addProperty('label', "The APIs main entry point.");
+    $get_op->addContextItem('description', 'rdfs:comment');
+    $get_op->addProperty('description', NULL);
+    $get_op->addContextItem('expects', array(
+      "@id" => "hydra:expects",
+      "@type" => "@id"
+    ));
+    $get_op->addProperty('expects', NULL);
+    $get_op->addContextItem('returns', array(
+      "@id" => "hydra:returns",
+      "@type" => "@id"
+    ));
+    $get_op->addProperty('returns', "vocab:EntryPoint");
+    $get_op->setID('_:entry_point');
+    $get_op->setType('hydra:Operation');
+
+    $operations[] = $get_op;
+    $entry_class->addProperty('supportedOperation', $operations);
+
+
+    $this->resource->addProperty('supportedClass', $entry_class);
   }
 }

+ 1 - 0
tripal_ws/includes/TripalWebServiceResource.inc

@@ -181,6 +181,7 @@ class TripalWebServiceResource {
       if ($vocab == '_') {
         return $id;
       }
+      return $id;
     }
     else {
       return $this->service_path . '/' . $id;

+ 15 - 17
tripal_ws/tripal_ws.module

@@ -196,19 +196,28 @@ function tripal_ws_list_services() {
 
   // Create the parent resource which is a collection.
   $resource = new TripalWebServiceResource($base_path);
-  $resource->addContextItem('entrypoint', 'hydra:entrypoint');
-  $resource->setType('entrypoint');
 
-  // Now add the member to the collection
+  // Add the vocabulary to the context.
+  tripal_load_include_web_service_class('TripalVocabService_v0_1');
+  $service = new TripalVocabService_v0_1($base_path);
+  $resource->addContextItem('vocab', $service->getServicePath());
+  $resource->addContextItem('EntryPoint', 'vocab:EntryPoint');
+  $resource->setType('EntryPoint');
+
+  // Now add the services as properties.
   foreach ($services as $service_class) {
     tripal_load_include_web_service_class($service_class);
+    if ($service_class == 'TripalVocabService_v0_1') {
+      continue;
+    }
     $service = new $service_class($base_path);
-    $version = $service->getVersion();
-    $resource->addContextItem($service_class::$type, '');
+    $resource->addContextItem($service_class::$type, array(
+      '@id' => 'vocab:EntryPoint/' . $service_class::$type,
+      '@type' => '@id',
+    ));
     $resource->addProperty($service_class::$type, $service->getServicePath());
   }
 
-  // For discoverability add the document webservice.
   $service->setResource($resource);
   $response = $service->getResponse();
   print drupal_json_encode($response);
@@ -252,17 +261,6 @@ function tripal_ws_services() {
   print drupal_json_encode($response);
 }
 
-/**
- *
- * @param $entities
- * @param $type
- */
-function tripal_ws_entity_load($entities, $type) {
-  foreach ($entities as $entity) {
-
-  }
-}
-
 /**
  *
  * @param $site_id