TripalVocabService_v0_1.inc 6.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156
  1. <?php
  2. class TripalVocabService_v0_1 extends TripalWebService {
  3. /**
  4. * The human-readable label for this web service.
  5. */
  6. public static $label = 'Vocabulary';
  7. /**
  8. * A bit of text to describe what this service provides.
  9. */
  10. public static $description = 'Provides access to vocabulary terms that are in use by this site.';
  11. /**
  12. * A machine-readable type for this service. This name must be unique
  13. * among all Tripal web services and is used to form the URL to access
  14. * this service.
  15. */
  16. public static $type = 'vocab';
  17. /**
  18. * @see TripalWebService::handleRequest()
  19. */
  20. public function handleRequest() {
  21. $this->resource->addContextItem('vocab', $this->getServicePath() . '#');
  22. $this->resource->addContextItem('ApiDocumentation', 'hydra:ApiDocumentation');
  23. $this->resource->addContextItem('supportedClass', 'hydra:supportedClass');
  24. $this->resource->setType('ApiDocumentation');
  25. $this->resource->setID('vocab/' . $this->getVersion());
  26. // We need to list the content types as properties of the EntryPoint.
  27. $properties = array();
  28. // Iterate through all of the web services and get their documentation
  29. $services = tripal_get_web_services();
  30. foreach ($services as $service_class) {
  31. tripal_load_include_web_service_class($service_class);
  32. $service = new $service_class($this->base_path);
  33. $supported_classes = $service->getSupportedClasses();
  34. foreach ($supported_classes as $supported) {
  35. $this->resource->addProperty('supportedClass', $supported);
  36. }
  37. if ($service_class::$type != 'vocab') {
  38. $event_prop = new TripalWebServiceResource($this->getServicePath());
  39. $event_prop->addProperty('hydra:title', $service_class::$type);
  40. $event_prop->addProperty('hydra:description', $service_class::$description);
  41. $event_prop->addContextItem('required', 'hydra:reqiured');
  42. $event_prop->addProperty('required', NULL);
  43. $event_prop->addContextItem('readonly', 'hydra:readonly');
  44. $event_prop->addProperty('readonly', TRUE);
  45. $event_prop->addContextItem('writeonly', 'hydra:writeonly');
  46. $event_prop->addProperty('writeonly', FALSE);
  47. $event_prop->addContextItem('property', array(
  48. "@id" => "hydra:property",
  49. "@type" => "@id"
  50. ));
  51. //$event_prop->setID('');
  52. //$event_prop->setType('');
  53. $prop = new TripalWebServiceResource($this->getServicePath());
  54. $prop->setID('vocab:EntryPoint/' . $service_class::$type);
  55. $prop->setType('hydra:Link');
  56. $prop->addContextItem('label', 'rdfs:label');
  57. $prop->addProperty('label', $service_class::$label);
  58. $prop->addContextItem('description', 'rdfs:comment');
  59. $prop->addProperty('description', $service_class::$description);
  60. $prop->addContextItem('domain', array(
  61. "@id" => "rdfs:domain",
  62. "@type" => "@id"
  63. ));
  64. $prop->addProperty('domain', 'vocab:EntryPoint');
  65. $prop->addContextItem('range', array(
  66. "@id" => "rdfs:range",
  67. "@type" => "@id"
  68. ));
  69. $prop->addProperty('range', 'hydra:Collection');
  70. $prop_ops = array();
  71. $prop_op = new TripalWebServiceResource($this->getServicePath());
  72. $prop_op->setID('_:event_collectionretrieve');
  73. $prop_op->setType('hydra:Operation');
  74. $prop_op->addContextItem('method', 'hydra:method');
  75. $prop_op->addProperty('method', 'GET');
  76. $prop_op->addContextItem('label', 'rdfs:label');
  77. $prop_op->addProperty('label', 'Retrieves all ' . $service_class::$label . ' entities.');
  78. $prop_op->addContextItem('description', 'rdfs:comment');
  79. $prop_op->addProperty('description', NULL);
  80. $prop_op->addContextItem('expects', array(
  81. "@id" => "hydra:expects",
  82. "@type" => "@id"
  83. ));
  84. $prop_op->addProperty('expects', NULL);
  85. $prop_op->addContextItem('returns', array(
  86. "@id" => "hydra:returns",
  87. "@type" => "@id"
  88. ));
  89. $prop_op->addProperty('returns', 'hydra:Collection');
  90. $prop_op->addContextItem('statusCodes', 'hydra:statusCodes');
  91. $prop_op->addProperty('statusCodes', array());
  92. $prop_ops[] = $prop_op;
  93. $prop->addContextItem('supportedOperation', 'hydra:supportedOperation');
  94. $prop->addProperty('supportedOperation', $prop_ops);
  95. $event_prop->addProperty('property', $prop);
  96. $properties[] = $event_prop;
  97. }
  98. }
  99. // Add in the generic supported classes.
  100. $entry_class = new TripalWebServiceResource($this->base_path);
  101. $entry_class->addContextItem('label', 'rdfs:label');
  102. $entry_class->setID($this->getServicePath() . '#EntryPoint');
  103. $entry_class->setType('hydra:Class');
  104. $entry_class->addProperty('label', 'EntryPoint');
  105. $entry_class->addContextItem('description', 'rdfs:comment');
  106. $entry_class->addProperty('description', 'The main entry point or homepage of the API');
  107. $entry_class->addContextItem('subClassOf', array(
  108. "@id" => "rdfs:subClassOf",
  109. "@type" => "@id"
  110. ));
  111. $entry_class->addProperty('subClassOf', NULL);
  112. $entry_class->addContextItem('supportedOperation', 'hydra:supportedOperation');
  113. $entry_class->addContextItem('supportedProperty', 'hydra:supportedProperty');
  114. $operations = array();
  115. $get_op = new TripalWebServiceResource($this->getServicePath());
  116. $get_op->addContextItem('method', 'hydra:method');
  117. $get_op->addProperty('method', 'GET');
  118. $get_op->addContextItem('statusCodes', 'hydra:statusCodes');
  119. $get_op->addProperty('statusCodes', array());
  120. $get_op->addContextItem('label', 'rdfs:label');
  121. $get_op->addProperty('label', "The APIs main entry point.");
  122. $get_op->addContextItem('description', 'rdfs:comment');
  123. $get_op->addProperty('description', NULL);
  124. $get_op->addContextItem('expects', array(
  125. "@id" => "hydra:expects",
  126. "@type" => "@id"
  127. ));
  128. $get_op->addProperty('expects', NULL);
  129. $get_op->addContextItem('returns', array(
  130. "@id" => "hydra:returns",
  131. "@type" => "@id"
  132. ));
  133. $get_op->addProperty('returns', "vocab:EntryPoint");
  134. $get_op->setID('_:entry_point');
  135. $get_op->setType('hydra:Operation');
  136. $operations[] = $get_op;
  137. $entry_class->addProperty('supportedOperation', $operations);
  138. $entry_class->addProperty('supportedProperty', $properties);
  139. $this->resource->addProperty('supportedClass', $entry_class);
  140. }
  141. }