瀏覽代碼

added root=1 in api wfs get feature

Piotr Labudda 8 年之前
父節點
當前提交
31c24cc3e4

+ 13 - 12
SE/se-lib/Api/Wfs/GetFeature.php

@@ -13,6 +13,7 @@ class Api_Wfs_GetFeature {
 	public static function parseGetFeatureArgsFromRequest() {
 		$rawArgs = $_GET;// $_REQUEST; ($_POST values not allowed, only xml in post body)
 		$args = array();
+		$args['root'] = ('0' === User::get('ADM_ADMIN_LEVEL') && 1 === V::get('root', 0, $rawArgs, 'int')); // NOTE: require Admin perms
 		$args['xsd:type'] = null;// @from: TYPENAME, typeName (typename)
 		$args['typePrefix'] = null;// @from: TYPENAME, typeName (typename)
 		$args['typeName'] = null;// @from: TYPENAME, typeName (typename)
@@ -195,10 +196,10 @@ class Api_Wfs_GetFeature {
 		throw new Exception("Not imeplemented multiple ogc:Query"); // multiple ogc:Query require ogc:Query/@typeName
 	}
 
-	public static function convertOgcPropertyListToFeatureQueryCols(&$schemaCache, $ogcPropertyList, $acl) {
-		return self::convertOgcPropsRecurse($schemaCache, $ogcPropertyList, $acl, $dbgLoopNr = 0, $dbgXpath = $acl->getNamespace());
+	public static function convertOgcPropertyListToFeatureQueryCols(&$schemaCache, $ogcPropertyList, $acl, $isRoot = false) {
+		return self::convertOgcPropsRecurse($schemaCache, $ogcPropertyList, $acl, $isRoot, $dbgLoopNr = 0, $dbgXpath = $acl->getNamespace());
 	}
-	public static function convertOgcPropsRecurse(&$schemaCache, $ogcPropertyList, $aclOrSchema, $dbgLoopNr = 0, $dbgXpath = '') {
+	public static function convertOgcPropsRecurse(&$schemaCache, $ogcPropertyList, $aclOrSchema, $isRoot = false, $dbgLoopNr = 0, $dbgXpath = '') {
 		if ($dbgLoopNr > 10) {
 			DBG::log($ogcPropertyList, 'array', 'convertOgcPropsRecurse: LOOP LIMIT 10! - return []');
 			return [];
@@ -212,8 +213,8 @@ class Api_Wfs_GetFeature {
 
 		if (empty($ogcPropertyList)) {
 			$ogcPropertyList = array_values($acl->getFieldListByIdZasob());
-			$ogcPropertyList = array_filter($ogcPropertyList, function ($fieldName) use ($acl) {
-				return $acl->canReadField($fieldName);
+			$ogcPropertyList = array_filter($ogcPropertyList, function ($fieldName) use ($acl, $isRoot) {
+				return ($isRoot || $acl->canReadField($fieldName));
 			});
 		}
 
@@ -237,10 +238,10 @@ class Api_Wfs_GetFeature {
 			if (array_key_exists('*', $nestedFields)) {
 				$nestedParts = $nestedFields['*'];
 				unset($nestedFields['*']);
-				DBG::log($nestedParts, 'array', "convertOgcPropsRecurse: TODO: '*' in \$nestedFields - \$nestedParts ns({$dbgXpath})");
+				DBG::log($nestedParts, 'array', "convertOgcPropsRecurse: '*' in \$nestedFields - \$nestedParts ns({$dbgXpath})");
 				$canReadRefs = array_values($acl->getFieldListByIdZasob());
-				$canReadRefs = array_filter($canReadRefs, function ($fieldName) use ($acl) {
-					return (false !== strpos($fieldName, ":") && $acl->canReadField($fieldName));
+				$canReadRefs = array_filter($canReadRefs, function ($fieldName) use ($acl, $isRoot) {
+					return (false !== strpos($fieldName, ":") && ($isRoot || $acl->canReadField($fieldName)));
 				});
 				foreach ($canReadRefs as $refField) {
 					foreach ($nestedParts as $nestedPart) {
@@ -255,15 +256,15 @@ class Api_Wfs_GetFeature {
 		if (in_array('*', $aclFields)) {
 			$aclFields = array_filter($aclFields, function ($fieldName) { return ( '*' !== $fieldName); });
 			$allAclFields = array_values($acl->getFieldListByIdZasob());
-			$allAclFields = array_filter($allAclFields, function ($fieldName) use ($acl) {
-				return $acl->canReadField($fieldName);
+			$allAclFields = array_filter($allAclFields, function ($fieldName) use ($acl, $isRoot) {
+				return ($isRoot || $acl->canReadField($fieldName));
 			});
 			if ($allAclFields) $aclFields = array_unique(array_merge($aclFields, $allAclFields));
 		}
-		DBG::log([$aclFields, $nestedFields], 'array', "convertOgcPropsRecurse: splited to acl fields and nested fields ns({$dbgXpath})");
+		DBG::log([$aclFields, $nestedFields, $acl->getFieldListByIdZasob()], 'array', "convertOgcPropsRecurse: splited to acl fields and nested fields ns({$dbgXpath})");
 
 		foreach ($aclFields as $fieldName) {
-			if (!$acl->canReadField($fieldName)) throw new Exception("Access Denied to read field '{$fieldName}' from '" . $acl->getNamespace() . "'");
+			if (!$isRoot && !$acl->canReadField($fieldName)) throw new Exception("Access Denied to read field '{$fieldName}' from '" . $acl->getNamespace() . "'");
 		}
 
 		foreach ($aclFields as $fieldName) {

+ 1 - 1
SE/se-lib/Api/WfsDataServer.php

@@ -190,7 +190,7 @@ class Api_WfsDataServer extends Api_WfsServerBase {
 		DBG::log($args, 'array', "\$args");
 		$schemaCache = array();
 		try {
-			$searchParams['cols'] = Api_Wfs_GetFeature::convertOgcPropertyListToFeatureQueryCols($schemaCache, $args['filterFields'], $acl); // convert $args['filterFields'] to field list
+			$searchParams['cols'] = Api_Wfs_GetFeature::convertOgcPropertyListToFeatureQueryCols($schemaCache, $args['filterFields'], $acl, $isRoot = $args['root']); // convert $args['filterFields'] to field list
 		} catch (Exception $e) {
 			DBG::log($e);
 			throw $e;

+ 1 - 0
SE/se-lib/Route/Storage.php

@@ -230,6 +230,7 @@ class Route_Storage extends RouteBase {
 								UI::h('a', [ 'href' => "wfs-data.php/default_db/?SERVICE=WFS&VERSION=1.0.0&SRSNAME=EPSG:3003&REQUEST=GetFeature&TYPENAME={$typeName}&MAXFEATURES=10" ], "wfs GetFeature (max: 10)"),
 								UI::h('a', [ 'href' => "wfs-data.php/default_db/?SERVICE=WFS&VERSION=1.0.0&SRSNAME=EPSG:3003&REQUEST=GetFeatureAdvanced&TYPENAME={$typeName}&MAXFEATURES=10" ], "wfs GetFeatureAdvanced (max: 10)"),
 								UI::h('a', [ 'href' => "wfs-data.php/default_db/?SERVICE=WFS&VERSION=1.0.0&SRSNAME=EPSG:3003&REQUEST=GetFeature&TYPENAME={$typeName}&MAXFEATURES=3&resolve=all&resolveDepth=3" ], "wfs GetFeature (max: 3, resolveDepth: 3)"),
+								UI::h('a', [ 'href' => "index.php?_route=WfsJsRequestPanel&namespace={$item['namespace']}" ], "JavaScript WFS Panel"),
 							])
 						]),
 					];

+ 49 - 8
SE/se-lib/Route/WfsJsRequestPanel.php

@@ -7,6 +7,7 @@ Lib::loadClass('RouteBase');
 Lib::loadClass('P5');
 Lib::loadClass('Core_AclHelper');
 Lib::loadClass('ACL');
+Lib::loadClass('Api_WfsNs');
 
 class Route_WfsJsRequestPanel extends RouteBase {
 
@@ -195,9 +196,41 @@ class Route_WfsJsRequestPanel extends RouteBase {
 			// $securityLogger->pushHandler($stream);
 			// $securityLogger->addInfo('debug message / label', [ 'dbg-object' => [ 'x' => 'y', 'z' ] ]);
 
+			$namespace = V::get('namespace', '', $_GET);
+			$defaultTypeName = ($namespace)
+			?	Api_WfsNs::typeName($namespace)
+			:	$examples['Procesy']['lvl1']['typeName'];
+			$defaultNamespace = Api_WfsNs::namespaceFromTypeName($defaultTypeName);
+			$defaultRequestBody = ($namespace)
+			?	''
+			:	htmlspecialchars($examples['Procesy']['lvl1']['postBody']);
 			// 'wfsRequestFeatureTypeName' = 'default_db__x3A__CRM_PROCES:PROCES'
-			echo UI::h('input', [ 'id' => 'wfsRequestFeatureTypeName', 'class' => "form-control", 'value' => $examples['Procesy']['lvl1']['typeName'], 'title' => "Feature name" ]);
-			echo UI::h('textarea', [ 'id' => 'wfsRequestBody', 'style' => "width:100%; height:300px" ], htmlspecialchars($examples['Procesy']['lvl1']['postBody']));
+			echo UI::h('table', [ 'style' => "width:100%; margin:0", 'class' => "table" ], [
+				UI::h('tr', [], [
+					UI::h('td', [ 'style' => "padding:0; border:none" ], [
+						UI::h('input', [ 'id' => 'wfsRequestFeatureTypeName', 'class' => "form-control", 'value' => $defaultTypeName, 'title' => "Feature name" ]),
+					]),
+					UI::h('td', [ 'style' => "width:5%; line-height:18px; border:none" ], [
+						UI::h('a', [
+							'id' => "typeNameStorageStructLink",
+							'href' => "index.php?_route=Storage_AclStruct&namespace={$defaultNamespace}",
+						], "Struktura")
+					]),
+				])
+			]);
+			echo UI::h('label', [], [
+				" root ",
+				UI::h('input', [ 'type' => "checkbox", 'id' => 'wfsRequestParam.root', 'class' => "", 'value' => '1' ]),
+			]);
+			echo UI::h('label', [ 'style' => "margin-left:8px" ], [
+				" maxFeatures: ",
+				UI::h('input', [ 'type' => "number", 'id' => 'wfsRequestParam.maxFeatures', 'class' => "", 'value' => '3' ]),
+			]);
+			echo UI::h('label', [ 'style' => "margin-left:8px" ], [
+				" resolveDepth: ",
+				UI::h('input', [ 'type' => "number", 'id' => 'wfsRequestParam.resolveDepth', 'class' => "", 'value' => '' ]),
+			]);
+			echo UI::h('textarea', [ 'id' => 'wfsRequestBody', 'style' => "width:100%; height:300px" ], $defaultRequestBody);
 			echo UI::h('button', [ 'class' => "btn btn-primary", 'onClick' => "return sendWfsRequest(this)" ], "Wyslij");
 			echo UI::h('div', [ 'style' => "display:inline", 'id' => "wfs-example-btns" ]);
 			echo UI::h('details', [ 'style' => "padding:6px; background-color:#333; color:#fff", 'open' => "open" ], [
@@ -239,7 +272,9 @@ class Route_WfsJsRequestPanel extends RouteBase {
 				console.log('examples', examples)
 				function setWfsExample(groupName, label) {
 					console.log('groupName', groupName, 'label', label)
-					document.getElementById('wfsRequestFeatureTypeName').value = examples[groupName][label].typeName
+					var typeName = examples[groupName][label].typeName
+					document.getElementById('wfsRequestFeatureTypeName').value = typeName
+					document.getElementById('typeNameStorageStructLink').href = 'index.php?_route=Storage_AclStruct&namespace=' + typeName.replace('__x3A__', '/').replace(':', '/')
 					document.getElementById('wfsRequestBody').value = examples[groupName][label].postBody || ''
 					sendWfsRequest()
 				}
@@ -258,11 +293,17 @@ class Route_WfsJsRequestPanel extends RouteBase {
 					document.getElementById('wfsResponse').innerHTML = 'loading...'
 					var featureTypeName = document.getElementById('wfsRequestFeatureTypeName').value
 					var postBody = document.getElementById('wfsRequestBody').value.replace(/&lt;/g, '<').replace(/&gt;/g, '>')
-					console.log('wfsRequestBody:', postBody)
-					var wfsParams = Object.assign({
-						'maxFeatures': 3,
-					}, (!postBody) ? {} : { 'ogc:Filter': postBody }
-					)
+					var wfsParams = {
+						'maxFeatures': 3
+					}
+					if (document.getElementById('wfsRequestParam.root').checked) wfsParams['root'] = '1'
+					if (document.getElementById('wfsRequestParam.maxFeatures')) wfsParams['maxFeatures'] = parseInt(document.getElementById('wfsRequestParam.maxFeatures').value)
+					var resolveDepth = parseInt(document.getElementById('wfsRequestParam.resolveDepth').value)
+					if (resolveDepth > 0 && !isNaN(resolveDepth)) {
+						wfsParams['resolve'] = 'all'
+						wfsParams['resolveDepth'] = resolveDepth
+					}
+					if (postBody) wfsParams['ogc:Filter'] = postBody
 					console.log('p5WFS_GetFeature', featureTypeName, wfsParams)
 					p5WFS_GetFeature(featureTypeName, wfsParams).then(function (features) {
 						console.log('features', features)

+ 1 - 0
SE/static/p5WFS/GetFeature.js

@@ -129,6 +129,7 @@ function p5WFS_GetFeature(typeName, query) { // @returns Promise
 	if ('resolve' in query) link += '&resolve=' + query['resolve']
 	if ('resolveDepth' in query) link += '&resolveDepth=' + query['resolveDepth']
 	if ('xlink' in query) link += '&xlink=' + query['xlink'] // NOTE: replace '#' to '/'
+	if ('root' in query) link += '&root=' + query['root'] // NOTE: require admin perms (admin level 0)
 	var method = (postData) ? 'POST' : 'GET'
 
 	return window.fetch(link, Object.assign({