Server.php 8.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133
  1. <?php
  2. /*
  3. * GetCapabilities
  4. * DescribeProcess
  5. * Execute
  6. */
  7. Lib::loadClass('Api_WpsV1_ServerBase');
  8. Lib::loadClass('Api_WfsException');
  9. Lib::loadClass('Api_WfsGeomTypeConverter');
  10. Lib::loadClass('Api_WfsNs');
  11. Lib::loadClass('Core_XmlWriter');
  12. Lib::loadClass('DBG');
  13. Lib::loadClass('Api_WpsV1_GetCapabilities');
  14. Lib::loadClass('Api_WpsV1_DescribeProcess');
  15. Lib::loadClass('Core_AclBase');
  16. Lib::loadClass('Type_ApiRequest');
  17. class Api_WpsV1_Server extends Api_WpsV1_ServerBase {
  18. public function run(Type_ApiRequest $request) {
  19. $document = '';
  20. if ('WPS' != V::geti('service', '', $request->query)) {
  21. throw new Api_WfsException("Only WPS Service is allowed");
  22. }
  23. $req = V::geti('request', '', $request->query);
  24. if (!empty($req)) {
  25. $methodName = "{$req}Action";
  26. if (!method_exists($this, $methodName)) {
  27. throw new Api_WfsException("Not Implemented " . htmlspecialchars($req), 501);
  28. }
  29. $this->DBG("WpsServer->{$methodName}() ...", __LINE__);
  30. $document = $this->$methodName($urlQuery);
  31. }
  32. else {
  33. $this->DBG("WpsServer->parseXMLRequest() ...", __LINE__);
  34. $document = $this->parseXMLRequest();
  35. header('Content-type: application/xml');
  36. echo '<?xml version="1.0" encoding="UTF-8"?>';
  37. echo $document; exit;// TODO: return $document;
  38. }
  39. IF(V::get('DBG','',$_GET)){echo'<pre style="max-height:200px;overflow:auto;border:1px solid red;text-align:left;">$document (' . __CLASS__ . '::' . __FUNCTION__ . ':' . __LINE__ . '): ';print_r($document);echo'</pre>';}
  40. if ('raw' == V::get('outputFormat', '', $request->query)) {
  41. header('Content-type: text/plain; charset=utf-8');
  42. echo $document;
  43. } else {
  44. header('Content-type: application/xml');
  45. echo $document;
  46. }
  47. }
  48. public function parseXMLRequest() {
  49. $data = array();
  50. $reqContent = Request::getRequestBody();
  51. if (empty($reqContent)) {
  52. throw new Exception("Empty request");
  53. }
  54. $parserXml = xml_parser_create();
  55. xml_parser_set_option($parserXml, XML_OPTION_CASE_FOLDING, 0);
  56. xml_parser_set_option($parserXml, XML_OPTION_SKIP_WHITE, 1);
  57. if (0 == xml_parse_into_struct($parserXml, $reqContent, $tags)) {
  58. throw new Exception("Error parsing xml");
  59. }
  60. xml_parser_free($parserXml);
  61. if (empty($tags)) {
  62. throw new Exception("Empty structure from request");
  63. }
  64. $rootTagName = V::get('tag', '', $tags[0]);
  65. if ('Transaction' == $rootTagName) return $this->_parseTransactionXmlStruct($reqContent, $tags);
  66. throw new Api_WfsException("Not implemented '{$rootTagName}' #L." . __LINE__, 501);
  67. }
  68. function describeProcessAction() {
  69. $identifier = V::geti('identifier', '', $_REQUEST);
  70. if (empty($identifier)) throw new HttpException("Missing identifier", 400);
  71. if ('JTS:Aarea' === $identifier) return self::exampleDescribeProcess_JTS_Area();
  72. if ('vec:Feature' === $identifier) return self::exampleDescribeProcess_vec_Feature();
  73. $wpsServerUrl = $this->getBaseUri();
  74. Api_WpsV1_DescribeProcess::sendDescribeProcessXml($wpsServerUrl, $identifier);
  75. }
  76. static function exampleDescribeProcess_JTS_Area() {
  77. header('Content-type: application/xml; charset=utf-8');
  78. echo '<?xml version="1.0" encoding="UTF-8"?><wps:ProcessDescriptions xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:ows="http://www.opengis.net/ows/1.1" xmlns:wps="http://www.opengis.net/wps/1.0.0" xmlns:xlink="http://www.w3.org/1999/xlink" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xml:lang="en" service="WPS" version="1.0.0" xsi:schemaLocation="http://www.opengis.net/wps/1.0.0 http://schemas.opengis.net/wps/1.0.0/wpsAll.xsd"><ProcessDescription wps:processVersion="1.0.0" statusSupported="true" storeSupported="true"><ows:Identifier>JTS:area</ows:Identifier><ows:Title>Area</ows:Title><ows:Abstract>Returns the area of a geometry, in the units of the geometry. Assumes a Cartesian plane, so this process is only recommended for non-geographic CRSes.</ows:Abstract><DataInputs><Input maxOccurs="1" minOccurs="1"><ows:Identifier>geom</ows:Identifier><ows:Title>geom</ows:Title><ows:Abstract>Input geometry</ows:Abstract><ComplexData><Default><Format><MimeType>text/xml; subtype=gml/3.1.1</MimeType></Format></Default><Supported><Format><MimeType>text/xml; subtype=gml/3.1.1</MimeType></Format><Format><MimeType>text/xml; subtype=gml/2.1.2</MimeType></Format><Format><MimeType>application/wkt</MimeType></Format><Format><MimeType>application/json</MimeType></Format><Format><MimeType>application/gml-3.1.1</MimeType></Format><Format><MimeType>application/gml-2.1.2</MimeType></Format></Supported></ComplexData></Input></DataInputs><ProcessOutputs><Output><ows:Identifier>result</ows:Identifier><ows:Title>result</ows:Title><LiteralOutput><ows:DataType>double</ows:DataType></LiteralOutput></Output></ProcessOutputs></ProcessDescription></wps:ProcessDescriptions>';
  79. exit;
  80. }
  81. static function exampleDescribeProcess_vec_Feature() {
  82. header('Content-type: application/xml; charset=utf-8');
  83. echo '<?xml version="1.0" encoding="UTF-8"?><wps:ProcessDescriptions xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:ows="http://www.opengis.net/ows/1.1" xmlns:wps="http://www.opengis.net/wps/1.0.0" xmlns:xlink="http://www.w3.org/1999/xlink" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xml:lang="en" service="WPS" version="1.0.0" xsi:schemaLocation="http://www.opengis.net/wps/1.0.0 http://schemas.opengis.net/wps/1.0.0/wpsAll.xsd"><ProcessDescription wps:processVersion="1.0.0" statusSupported="true" storeSupported="true"><ows:Identifier>vec:Feature</ows:Identifier><ows:Title>Feature from Geometry</ows:Title><ows:Abstract>Converts a geometry into a feature collection.</ows:Abstract><DataInputs><Input maxOccurs="1" minOccurs="1"><ows:Identifier>geometry</ows:Identifier><ows:Title>geometry</ows:Title><ows:Abstract>Input geometry</ows:Abstract><ComplexData><Default><Format><MimeType>text/xml; subtype=gml/3.1.1</MimeType></Format></Default><Supported><Format><MimeType>text/xml; subtype=gml/3.1.1</MimeType></Format><Format><MimeType>text/xml; subtype=gml/2.1.2</MimeType></Format><Format><MimeType>application/wkt</MimeType></Format><Format><MimeType>application/json</MimeType></Format><Format><MimeType>application/gml-3.1.1</MimeType></Format><Format><MimeType>application/gml-2.1.2</MimeType></Format></Supported></ComplexData></Input><Input maxOccurs="1" minOccurs="1"><ows:Identifier>crs</ows:Identifier><ows:Title>crs</ows:Title><ows:Abstract>Coordinate reference system of the input geometry (if not provided in the geometry)</ows:Abstract><LiteralData><ows:AnyValue/></LiteralData></Input><Input maxOccurs="1" minOccurs="1"><ows:Identifier>typeName</ows:Identifier><ows:Title>typeName</ows:Title><ows:Abstract>Feauturetype name for the feature collection</ows:Abstract><LiteralData><ows:AnyValue/></LiteralData></Input></DataInputs><ProcessOutputs><Output><ows:Identifier>result</ows:Identifier><ows:Title>result</ows:Title><ComplexOutput><Default><Format><MimeType>text/xml; subtype=wfs-collection/1.0</MimeType></Format></Default><Supported><Format><MimeType>text/xml; subtype=wfs-collection/1.0</MimeType></Format><Format><MimeType>text/xml; subtype=wfs-collection/1.1</MimeType></Format><Format><MimeType>application/json</MimeType></Format><Format><MimeType>application/wfs-collection-1.0</MimeType></Format><Format><MimeType>application/wfs-collection-1.1</MimeType></Format><Format><MimeType>application/zip</MimeType></Format></Supported></ComplexOutput></Output></ProcessOutputs></ProcessDescription></wps:ProcessDescriptions>';
  84. exit;
  85. }
  86. public function getCapabilitiesAction() {
  87. $wpsServerUrl = $this->getBaseUri();
  88. $serviceTitle = "Web Processing Service";
  89. $serviceDescription = "Web Processing Service";
  90. $idDefaultDB = DB::getPDO()->getZasobId();
  91. $aclList = array_filter($this->_usrAcl->getTablesAcl(), function ($acl) use ($idDefaultDB) {
  92. // // $dataSourceName = 'default_db';// TODO: getSourceName
  93. // // $tblName = $tblAcl->getName();
  94. // // try {
  95. // // $acl = $this->getAclFromTypeName($typeName = "p5_{$dataSourceName}:{$tblName}");
  96. // // } catch (Exception $e) {
  97. // // // echo "Error for table({$tblName}): " . $e->getMessage() . "\n";
  98. // // }
  99. // // if (!$acl) {
  100. // // // TODO: error log msg
  101. // // return false;
  102. // // }
  103. return ($acl instanceof Core_AclBase && $idDefaultDB == $acl->getDB()); // hide non default_db tables
  104. });
  105. switch (V::get('outputFormat', 'xml', $_GET)) {
  106. case 'csv': {
  107. Api_WpsV1_GetCapabilities::sendGetCapabilitiesCsv($wpsServerUrl, $serviceTitle, $serviceDescription, $aclList);
  108. } break;
  109. case 'xml': {
  110. Api_WpsV1_GetCapabilities::sendGetCapabilitiesXml($wpsServerUrl, $serviceTitle, $serviceDescription, $aclList);
  111. } break;
  112. default: throw new Api_WfsException("Not Implemented outputFormat", 501); // , null, 'NotImplemented', 'request');
  113. }
  114. exit;
  115. }
  116. }