فهرست منبع

added WpsHelper with process list

Piotr Labudda 8 سال پیش
والد
کامیت
3a9acd8ae4
4فایلهای تغییر یافته به همراه103 افزوده شده و 63 حذف شده
  1. 74 0
      SE/se-lib/Api/WpsHelper.php
  2. 22 15
      SE/se-lib/Api/WpsV1/GetCapabilities.php
  3. 5 46
      SE/se-lib/Api/WpsV1/Server.php
  4. 2 2
      SE/se-lib/Type/WpsProcess.php

+ 74 - 0
SE/se-lib/Api/WpsHelper.php

@@ -0,0 +1,74 @@
+<?php
+
+class Api_WpsHelper {
+
+	static function getUserWpsProcessList($userLogin = null) {
+		// TODO: $userLogin
+		$defaultWpsProcessList = self::getDefaultWpsProcessList();
+		if (array_key_exists($identifier, $defaultWpsProcessList)) return Type_WpsProcess::build( $defaultWpsProcessList[$identifier] );
+
+		$wpsProcessList = [];
+		// TODO: fetch from DB - `CRM_#CACHE_ACL_FUNCTIONS` or object like UrlActions
+
+		$wpsProcessList = array_merge($defaultWpsProcessList, $wpsProcessList);
+		return array_map(function ($wpsProcess, $identifier) {
+			return (object)[ 'identifier' => $identifier, 'title' => $wpsProcess['title'], 'description' => $wpsProcess['description'] ];
+		}, $wpsProcessList, array_keys($wpsProcessList));
+		return $wpsProcessList;
+	}
+
+	static function getUserWpsProcess($identifier, $userLogin = null) {
+		// TODO: $userLogin
+		$defaultWpsProcessList = self::getDefaultWpsProcessList();
+		if (array_key_exists($identifier, $defaultWpsProcessList)) return Type_WpsProcess::build( $defaultWpsProcessList[$identifier] );
+
+		// TODO: fetch from DB - `CRM_#CACHE_ACL_FUNCTIONS` or object like UrlActions
+
+		throw new Exception("Forbidden - wps function not exists or access denied", 403);
+	}
+
+	static function getDefaultWpsProcessList() {
+		$defaultWpsProcessList = [];
+
+		{
+			$selectFeatureBase = [
+				'dataInputs' => [
+					[
+						'maxOccurs' => "1",
+						'minOccurs' => "1",
+						'identifier' => 'typeName',
+						'title' => "Feature typeName",
+						'description' => "Feature typeName eg. default_db/PROBLEMS",
+						'type' => 'literal',
+					],
+					[
+						'maxOccurs' => "unbounded",
+						'minOccurs' => "1",
+						'identifier' => 'primaryKey',
+						'title' => "Feature primaryKey",
+						'description' => "Feature primaryKey",
+						'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" ], // TODO: result type - like Insert Wfs Transaction result - list of: Success (primaryKey = 123), ...
+				'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" ],
+				]
+			];
+			$defaultWpsProcessList['p5:selectFeature']   = array_merge([ 'title' => "Select feature", 'descriptin' => "Select feature (set attribute @selected to true)" ], $selectFeatureBase);
+			$defaultWpsProcessList['p5:unselectFeature'] = array_merge([ 'title' => "Unselect feature", 'descriptin' => "Unselect feature (set attribute @selected to false)" ], $selectFeatureBase);
+		}
+
+		array_walk($defaultWpsProcessList, function (&$wpsFunction, $identifier) {
+			$wpsFunction['identifier'] = $identifier;
+		});
+		return $defaultWpsProcessList;
+	}
+
+}

+ 22 - 15
SE/se-lib/Api/WpsV1/GetCapabilities.php

@@ -8,7 +8,7 @@ Lib::loadClass('Core_XmlWriter');
 
 class Api_WpsV1_GetCapabilities { // TODO: ...
 
-	static function sendGetCapabilitiesCsv($wpsServerUrl, $serviceTitle, $serviceDescription, $aclList) {
+	static function sendGetCapabilitiesCsv($wpsServerUrl, $serviceTitle, $serviceDescription, $wpsProcessList) {
 		throw new Api_WfsException("Not Implemented sendGetCapabilitiesCsv for Wps version 1.0.0", 501);
 		header('Content-Type: text/csv; charset=utf-8');
 		$csvLineSepartor = "\n";
@@ -45,7 +45,7 @@ class Api_WpsV1_GetCapabilities { // TODO: ...
 				"9.838674658246807", // LatLongBoundingBox - maxx
 				"41.31378404137082", // LatLongBoundingBox - maxy
 			]);
-		}, $aclList));
+		}, $wpsProcessList));
 		echo $csvLineSepartor;
 
 		echo implode($csvLineSepartor, array_map(function ($typeName) use ($csvText, $csvValueSepartor) {
@@ -66,7 +66,7 @@ class Api_WpsV1_GetCapabilities { // TODO: ...
 		exit;
 	}
 
-	static function sendGetCapabilitiesXml($wpsServerUrl, $serviceTitle, $serviceDescription, $aclList) {
+	static function sendGetCapabilitiesXml($wpsServerUrl, $serviceTitle, $serviceDescription, $wpsProcessList) {
 		header('Content-type: application/xml; charset=utf-8');
 		$xmlWriter = new Core_XmlWriter();
 		if (!$xmlWriter) throw new HttpException("Error no XMLWriter", 404);
@@ -191,18 +191,25 @@ class Api_WpsV1_GetCapabilities { // TODO: ...
 		// 		</wps:Supported>
 		// 	</wps:Languages>
 		// </wps:Capabilities>
-		$xmlWriter->h('wps:ProcessOfferings', [ // TODO:? for version 1.0.0 ?
-			[ 'wps:Process', [ 'wps:processVersion' => "1.0.0" ], [
-				[ 'ows:Identifier', "buffer" ],
-				[ 'ows:Title', "Buffer a polygon feature" ],
-				[ 'ows:Abstract', "Buffer the polygon coordinates found in one GML stream by a given buffer distance, and output the results in GML." ],
-			] ],
-			[ 'wps:Process', [ 'wps:processVersion' => "1.0.0" ], [
-				[ 'ows:Identifier', "JTS:area" ],
-				[ 'ows:Title', "Area" ],
-				[ '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." ],
-			] ]
-		]);
+		$xmlWriter->h('wps:ProcessOfferings', array_map(function ($wpsProcess) {
+			return [ 'wps:Process', [ 'wps:processVersion' => $wpsProcess->version ], [
+				[ 'ows:Identifier', $wpsProcess->identifier ],
+				[ 'ows:Title', $wpsProcess->title ],
+				[ 'ows:Abstract', $wpsProcess->description ],
+			] ];
+		}, $wpsProcessList));
+		// $xmlWriter->h('wps:ProcessOfferings', [
+		// 	[ 'wps:Process', [ 'wps:processVersion' => "1.0.0" ], [
+		// 		[ 'ows:Identifier', "buffer" ],
+		// 		[ 'ows:Title', "Buffer a polygon feature" ],
+		// 		[ 'ows:Abstract', "Buffer the polygon coordinates found in one GML stream by a given buffer distance, and output the results in GML." ],
+		// 	] ],
+		// 	[ 'wps:Process', [ 'wps:processVersion' => "1.0.0" ], [
+		// 		[ 'ows:Identifier', "JTS:area" ],
+		// 		[ 'ows:Title', "Area" ],
+		// 		[ '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." ],
+		// 	] ]
+		// ]);
 
 		$xmlWriter->h('wps:Languages', [
 			[ 'wps:Default', [

+ 5 - 46
SE/se-lib/Api/WpsV1/Server.php

@@ -17,6 +17,7 @@ Lib::loadClass('Api_WpsV1_DescribeProcess');
 Lib::loadClass('Core_AclBase');
 Lib::loadClass('Type_ApiRequest');
 Lib::loadClass('Type_WpsProcess');
+Lib::loadClass('Api_WpsHelper');
 
 class Api_WpsV1_Server extends Api_WpsV1_ServerBase {
 
@@ -84,40 +85,11 @@ class Api_WpsV1_Server extends Api_WpsV1_ServerBase {
 		if ('vec:Feature' === $identifier) return self::exampleDescribeProcess_vec_Feature();
 
 		$wpsServerUrl = $this->getBaseUri();
-		$wpsProcess = $this->_getWpsProcess($identifier); // TODO: get from WPS Process Factory/Helper
+		$wpsProcess = Api_WpsHelper::getUserWpsProcess($identifier);
 		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>';
@@ -135,27 +107,14 @@ class Api_WpsV1_Server extends Api_WpsV1_ServerBase {
 		$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
-		});
+		$wpsProcessList = Api_WpsHelper::getUserWpsProcessList();
 
 		switch (V::get('outputFormat', 'xml', $_GET)) {
 			case 'csv': {
-				Api_WpsV1_GetCapabilities::sendGetCapabilitiesCsv($wpsServerUrl, $serviceTitle, $serviceDescription, $aclList);
+				Api_WpsV1_GetCapabilities::sendGetCapabilitiesCsv($wpsServerUrl, $serviceTitle, $serviceDescription, $wpsProcessList);
 			} break;
 			case 'xml': {
-				Api_WpsV1_GetCapabilities::sendGetCapabilitiesXml($wpsServerUrl, $serviceTitle, $serviceDescription, $aclList);
+				Api_WpsV1_GetCapabilities::sendGetCapabilitiesXml($wpsServerUrl, $serviceTitle, $serviceDescription, $wpsProcessList);
 			} break;
 			default: throw new Api_WfsException("Not Implemented outputFormat", 501); // , null, 'NotImplemented', 'request');
 		}

+ 2 - 2
SE/se-lib/Type/WpsProcess.php

@@ -16,8 +16,8 @@ class Type_WpsProcess {
 	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->title = $conf['title'];
+		$wpsProcess->description = $conf['description'];
 		$wpsProcess->maxOccurs = $conf['maxOccurs'];
 		$wpsProcess->minOccurs = $conf['minOccurs'];
 		$wpsProcess->dataInputs = array_map(function ($input) {