| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165 |
- <?php
- /*
- * GetCapabilities
- * DescribeProcess
- * Execute
- */
- Lib::loadClass('Api_WpsV1_ServerBase');
- Lib::loadClass('Api_WfsException');
- Lib::loadClass('Api_WfsGeomTypeConverter');
- Lib::loadClass('Api_WfsNs');
- Lib::loadClass('Core_XmlWriter');
- Lib::loadClass('DBG');
- Lib::loadClass('Api_WpsV1_GetCapabilities');
- Lib::loadClass('Api_WpsV1_DescribeProcess');
- Lib::loadClass('Core_AclBase');
- Lib::loadClass('Type_ApiRequest');
- Lib::loadClass('Type_WpsProcess');
- class Api_WpsV1_Server extends Api_WpsV1_ServerBase {
- public function run(Type_ApiRequest $request) {
- $document = '';
- if ('WPS' != V::geti('service', '', $request->query)) {
- throw new Api_WfsException("Only WPS Service is allowed");
- }
- $req = V::geti('request', '', $request->query);
- if (!empty($req)) {
- $methodName = "{$req}Action";
- if (!method_exists($this, $methodName)) {
- throw new Api_WfsException("Not Implemented " . htmlspecialchars($req), 501);
- }
- $this->DBG("WpsServer->{$methodName}() ...", __LINE__);
- $document = $this->$methodName($urlQuery);
- }
- else {
- $this->DBG("WpsServer->parseXMLRequest() ...", __LINE__);
- $document = $this->parseXMLRequest();
- header('Content-type: application/xml');
- echo '<?xml version="1.0" encoding="UTF-8"?>';
- echo $document; exit;// TODO: return $document;
- }
- 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>';}
- if ('raw' == V::get('outputFormat', '', $request->query)) {
- header('Content-type: text/plain; charset=utf-8');
- echo $document;
- } else {
- header('Content-type: application/xml');
- echo $document;
- }
- }
- public function parseXMLRequest() {
- $data = array();
- $reqContent = Request::getRequestBody();
- if (empty($reqContent)) {
- throw new Exception("Empty request");
- }
- $parserXml = xml_parser_create();
- xml_parser_set_option($parserXml, XML_OPTION_CASE_FOLDING, 0);
- xml_parser_set_option($parserXml, XML_OPTION_SKIP_WHITE, 1);
- if (0 == xml_parse_into_struct($parserXml, $reqContent, $tags)) {
- throw new Exception("Error parsing xml");
- }
- xml_parser_free($parserXml);
- if (empty($tags)) {
- throw new Exception("Empty structure from request");
- }
- $rootTagName = V::get('tag', '', $tags[0]);
- if ('Transaction' == $rootTagName) return $this->_parseTransactionXmlStruct($reqContent, $tags);
- throw new Api_WfsException("Not implemented '{$rootTagName}' #L." . __LINE__, 501);
- }
- function describeProcessAction() {
- $identifier = V::geti('identifier', '', $_REQUEST);
- if (empty($identifier)) throw new HttpException("Missing identifier", 400);
- if ('JTS:Aarea' === $identifier) return self::exampleDescribeProcess_JTS_Area();
- if ('vec:Feature' === $identifier) return self::exampleDescribeProcess_vec_Feature();
- $wpsServerUrl = $this->getBaseUri();
- $wpsProcess = $this->_getWpsProcess($identifier); // TODO: get from WPS Process Factory/Helper
- if (!$wpsProcess) throw new Api_WfsException("Forbidden", 403);
- Api_WpsV1_DescribeProcess::sendDescribeProcessXml($wpsServerUrl, $wpsProcess);
- }
- function _getWpsProcess($identifier) {
- $wpsProcess = Type_WpsProcess::build([
- 'identifier' => $identifier,
- 'title' => "Title({$identifier})",
- 'description' => "Desc($identifier)",
- 'maxOccurs' => "1",
- 'minOccurs' => "1",
- 'dataInputs' => [
- [
- 'identifier' => $identifier,
- 'title' => $title,
- 'description' => $description,
- 'type' => 'literal',
- ],
- ],
- // 'MimeType' => text/xml, 'Encoding' => base64, 'Schema' => http://foo.bar/gml/3.1.0/polygon.xsd
- 'defaultOutput' => [ 'MimeType' => "text/xml; subtype=wfs-collection/1.0" ],
- 'supportedOutput' => [
- [ 'MimeType' => "text/xml; subtype=wfs-collection/1.0" ],
- [ 'MimeType' => "text/xml; subtype=wfs-collection/1.1" ],
- [ 'MimeType' => "application/json" ],
- // [ 'MimeType' => "application/wfs-collection-1.0" ],
- // [ 'MimeType' => "application/wfs-collection-1.1" ],
- // [ 'MimeType' => "application/zip" ],
- ]
- ]);
- return $wpsProcess;
- }
- static function exampleDescribeProcess_JTS_Area() {
- header('Content-type: application/xml; charset=utf-8');
- 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>';
- exit;
- }
- static function exampleDescribeProcess_vec_Feature() {
- header('Content-type: application/xml; charset=utf-8');
- 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>';
- exit;
- }
- public function getCapabilitiesAction() {
- $wpsServerUrl = $this->getBaseUri();
- $serviceTitle = "Web Processing Service";
- $serviceDescription = "Web Processing Service";
- $idDefaultDB = DB::getPDO()->getZasobId();
- $aclList = array_filter($this->_usrAcl->getTablesAcl(), function ($acl) use ($idDefaultDB) {
- // // $dataSourceName = 'default_db';// TODO: getSourceName
- // // $tblName = $tblAcl->getName();
- // // try {
- // // $acl = $this->getAclFromTypeName($typeName = "p5_{$dataSourceName}:{$tblName}");
- // // } catch (Exception $e) {
- // // // echo "Error for table({$tblName}): " . $e->getMessage() . "\n";
- // // }
- // // if (!$acl) {
- // // // TODO: error log msg
- // // return false;
- // // }
- return ($acl instanceof Core_AclBase && $idDefaultDB == $acl->getDB()); // hide non default_db tables
- });
- switch (V::get('outputFormat', 'xml', $_GET)) {
- case 'csv': {
- Api_WpsV1_GetCapabilities::sendGetCapabilitiesCsv($wpsServerUrl, $serviceTitle, $serviceDescription, $aclList);
- } break;
- case 'xml': {
- Api_WpsV1_GetCapabilities::sendGetCapabilitiesXml($wpsServerUrl, $serviceTitle, $serviceDescription, $aclList);
- } break;
- default: throw new Api_WfsException("Not Implemented outputFormat", 501); // , null, 'NotImplemented', 'request');
- }
- exit;
- }
- }
|