Kaynağa Gözat

added Type_WpsProcess

Piotr Labudda 8 yıl önce
ebeveyn
işleme
c95f607894

+ 12 - 31
SE/se-lib/Api/WpsV1/DescribeProcess.php

@@ -5,10 +5,11 @@ Lib::loadClass('Api_WfsNs');
 Lib::loadClass('Request');
 Lib::loadClass('Request');
 Lib::loadClass('Core_AclHelper');
 Lib::loadClass('Core_AclHelper');
 Lib::loadClass('Core_XmlWriter');
 Lib::loadClass('Core_XmlWriter');
+Lib::loadClass('Type_WpsProcess');
 
 
 class Api_WpsV1_DescribeProcess {
 class Api_WpsV1_DescribeProcess {
 
 
-	static function sendDescribeProcessXml($wpsServerUrl, $identifier) {
+	static function sendDescribeProcessXml($wpsServerUrl, Type_WpsProcess $wpsProcess) {
 		header('Content-type: application/xml; charset=utf-8');
 		header('Content-type: application/xml; charset=utf-8');
 
 
 		$xmlWriter = new Core_XmlWriter();
 		$xmlWriter = new Core_XmlWriter();
@@ -32,7 +33,6 @@ class Api_WpsV1_DescribeProcess {
 		// $schemaLocations = [];
 		// $schemaLocations = [];
 		//$schemaLocations[] = 'http://www.opengis.net/wfs http://webgis.regione.sardegna.it:80/geoserver/schemas/wfs/1.0.0/WFS-capabilities.xsd';// @from http://webgis.regione.sardegna.it/geoserver/ows?service=WFS&request=GetCapabilities
 		//$schemaLocations[] = 'http://www.opengis.net/wfs http://webgis.regione.sardegna.it:80/geoserver/schemas/wfs/1.0.0/WFS-capabilities.xsd';// @from http://webgis.regione.sardegna.it/geoserver/ows?service=WFS&request=GetCapabilities
 		// if (!empty($schemaLocations)) $xmlWriter->writeAttribute('xsi:schemaLocation', implode(' ', $schemaLocations));
 		// if (!empty($schemaLocations)) $xmlWriter->writeAttribute('xsi:schemaLocation', implode(' ', $schemaLocations));
-		$wpsProcess = self::getWpsProcess($identifier);
 		$xmlWriter->h('ProcessDescription', [
 		$xmlWriter->h('ProcessDescription', [
 			[ 'ows:Identifier', $wpsProcess->identifier ],
 			[ 'ows:Identifier', $wpsProcess->identifier ],
 			[ 'ows:Title', $wpsProcess->title ],
 			[ 'ows:Title', $wpsProcess->title ],
@@ -63,10 +63,10 @@ class Api_WpsV1_DescribeProcess {
 					[ 'ows:Title', "result" ],
 					[ 'ows:Title', "result" ],
 					[ 'ComplexOutput', [
 					[ 'ComplexOutput', [
 						[ 'Default', [
 						[ 'Default', [
-							[ 'Format', [ [ 'MimeType', $wpsProcess->defaultOutput ] ] ],
+							[ 'Format', self::convertOutputToWpsFormatXml($wpsProcess->defaultOutput) ],
 						] ],
 						] ],
 						[ 'Supported', array_map(function ($output) {
 						[ 'Supported', array_map(function ($output) {
-							return [ 'Format', [ [ 'MimeType', $output ] ] ];
+							return [ 'Format', self::convertOutputToWpsFormatXml($output) ];
 						}, $wpsProcess->supportedOutput) ],
 						}, $wpsProcess->supportedOutput) ],
 						// [ 'Supported', [
 						// [ 'Supported', [
 						// 	[ 'Format', [ [ 'MimeType', "text/xml; subtype=wfs-collection/1.0" ] ] ],
 						// 	[ 'Format', [ [ 'MimeType', "text/xml; subtype=wfs-collection/1.0" ] ] ],
@@ -86,33 +86,14 @@ class Api_WpsV1_DescribeProcess {
 		exit;
 		exit;
 	}
 	}
 
 
-	static function getWpsProcess($identifier) { // TODO: get from WPS Process Factory // @return Type_WpsProcess
-		$wpsProcess = (object)[
-			'identifier' => $identifier,
-			'title' => "Title({$identifier})",
-			'description' => "Desc($identifier)",
-			'maxOccurs' => "1",
-			'minOccurs' => "1",
-			'dataInputs' => [
-				(object)[
-					'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 convertOutputToWpsFormatXml($output) {
+		// 'MimeType' => text/xml, 'Encoding' => base64, 'Schema' => http://foo.bar/gml/3.1.0/polygon.xsd
+		// return <MimeType>text/xml</MimeType><Encoding>base64</Encoding><Schema>http://foo.bar/gml/3.1.0/polygon.xsd</Schema>
+		return array_merge(
+			(!empty($output['MimeType'])) ? [ [ 'MimeType', $output['MimeType'] ] ] : [],
+			(!empty($output['Encoding'])) ? [ [ 'Encoding', $output['Encoding'] ] ] : [],
+			(!empty($output['Schema']))   ? [ [ 'Schema',   $output['Schema'] ] ]   : []
+		);
 	}
 	}
 
 
 }
 }

+ 33 - 1
SE/se-lib/Api/WpsV1/Server.php

@@ -16,6 +16,7 @@ Lib::loadClass('Api_WpsV1_GetCapabilities');
 Lib::loadClass('Api_WpsV1_DescribeProcess');
 Lib::loadClass('Api_WpsV1_DescribeProcess');
 Lib::loadClass('Core_AclBase');
 Lib::loadClass('Core_AclBase');
 Lib::loadClass('Type_ApiRequest');
 Lib::loadClass('Type_ApiRequest');
+Lib::loadClass('Type_WpsProcess');
 
 
 class Api_WpsV1_Server extends Api_WpsV1_ServerBase {
 class Api_WpsV1_Server extends Api_WpsV1_ServerBase {
 
 
@@ -83,7 +84,38 @@ class Api_WpsV1_Server extends Api_WpsV1_ServerBase {
 		if ('vec:Feature' === $identifier) return self::exampleDescribeProcess_vec_Feature();
 		if ('vec:Feature' === $identifier) return self::exampleDescribeProcess_vec_Feature();
 
 
 		$wpsServerUrl = $this->getBaseUri();
 		$wpsServerUrl = $this->getBaseUri();
-		Api_WpsV1_DescribeProcess::sendDescribeProcessXml($wpsServerUrl, $identifier);
+		$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() {
 	static function exampleDescribeProcess_JTS_Area() {

+ 60 - 0
SE/se-lib/Type/WpsProcess.php

@@ -0,0 +1,60 @@
+<?php
+
+class Type_WpsProcess {
+
+	var $_data = [];
+
+	// Type_WpsProcessOutput: [ 'MimeType' => text/xml, 'Encoding' => base64, 'Schema' => http://foo.bar/gml/3.1.0/polygon.xsd ]
+	// supportedOutput: [ Type_WpsProcessOutput, ... ]
+	// 	[ '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" ],
+
+	static function build($conf) { // @return Type_WpsProcess
+		$wpsProcess = new Type_WpsProcess();
+		$wpsProcess->identifier = $conf['identifier'];
+		$wpsProcess->title = "Title({$conf['identifier']})";
+		$wpsProcess->description = "Desc({$conf['identifier']})";
+		$wpsProcess->maxOccurs = $conf['maxOccurs'];
+		$wpsProcess->minOccurs = $conf['minOccurs'];
+		$wpsProcess->dataInputs = array_map(function ($input) {
+			// 		'identifier' => $identifier,
+			// 		'title' => $title,
+			// 		'description' => $description,
+			// 		'type' => 'literal',
+			return (object)$input;
+		}, $conf['dataInputs']);
+		$wpsProcess->defaultOutput = $conf['defaultOutput'];
+		$wpsProcess->supportedOutput = $conf['supportedOutput'];
+		return $wpsProcess;
+	}
+
+	function __isset($name) {
+		return (array_key_exists($name, $this->_data));
+	}
+
+	function __get($name) {
+		if (array_key_exists($name, $this->_data)) {
+			return $this->_data[$name];
+		}
+		return null;
+	}
+
+	function __set($name, $value) {
+		$this->_data[$name] = $value;
+	}
+
+	function toArray() {
+		return $this->_data;
+	}
+
+	function __toString() {
+		return str_replace('"', '',
+			str_replace([ '{', '}', '":', ',"' ], [ '{ ', ' }', ': ', ', ' ], json_encode($this->_data))
+		);
+	}
+
+}