ソースを参照

added default_objects to WFS

Piotr Labudda 9 年 前
コミット
18893fdf5b

+ 8 - 2
SE/se-lib/Api/WfsNs.php

@@ -10,15 +10,21 @@ class Api_WfsNs {
     $baseNsUri = self::getBaseWfsUri();
     $baseNsUri = self::getBaseWfsUri();
     $listNs["{$baseNsUri}"] = 'p5';
     $listNs["{$baseNsUri}"] = 'p5';
 		$listNs["{$baseNsUri}/default_db"] = 'p5_default_db';
 		$listNs["{$baseNsUri}/default_db"] = 'p5_default_db';
+		$listNs["{$baseNsUri}/default_objects"] = 'default_objects';
 		$listNs["{$baseNsUri}/objects"] = 'p5_objects';
 		$listNs["{$baseNsUri}/objects"] = 'p5_objects';
 		return $listNs;
 		return $listNs;
   }
   }
 
 
-  // @usage: Api_WfsNs::getNsList('default_db');
+  // @usage: Api_WfsNs::getNsUri('default_db');
   public static function getNsUri($nsPrefix) {
   public static function getNsUri($nsPrefix) {
     $listNs = self::getNsList();
     $listNs = self::getNsList();
     $nsMap = array_flip($listNs);
     $nsMap = array_flip($listNs);
-    return V::get($nsPrefix, null, $nsMap);
+    $nsUri = V::get($nsPrefix, null, $nsMap);
+    if (!$nsUri) {
+      if ('default_objects' == $nsPrefix) return V::get('p5_objects', null, $nsMap);
+      if ('default_db__x3A__' == substr($nsPrefix, 0, 17)) return $nsMap['p5_default_db'] . "/" . substr($nsPrefix, 17);
+    }
+    return $nsUri;
   }
   }
 
 
   // @usage: Api_WfsNs::getNsPrefix('https://biuro.biall-net.pl/wfs/default_db');
   // @usage: Api_WfsNs::getNsPrefix('https://biuro.biall-net.pl/wfs/default_db');

+ 44 - 51
SE/se-lib/Api/WfsServerBase.php

@@ -4,6 +4,7 @@ Lib::loadClass('Api_WfsException');
 Lib::loadClass('Api_WfsGeomTypeConverter');
 Lib::loadClass('Api_WfsGeomTypeConverter');
 Lib::loadClass('Api_WfsNs');
 Lib::loadClass('Api_WfsNs');
 Lib::loadClass('Request');
 Lib::loadClass('Request');
+Lib::loadClass('Core_AclHelper');
 
 
 class Api_WfsServerBase {
 class Api_WfsServerBase {
 
 
@@ -26,34 +27,17 @@ class Api_WfsServerBase {
 		return $this->_apiBaseUri;
 		return $this->_apiBaseUri;
 	}
 	}
 
 
-	public function isAllowedFeatureType($nsPrefix, $type) {
-		if ('p5_' != substr($nsPrefix, 0, 3)) return false;
-		if ('p5_default_db' == $nsPrefix) {
-			$typeName = "p5_default_db:{$type}";
-			try {
-				$acl = $this->getAclFromTypeName($typeName);
-			} catch (Exception $e) {
-				return false;
-			}
-			if ($acl) {
-				return true;
-			}
-		} else if ('p5_objects' == $nsPrefix) {
-			// TODO: generate class name like in: UserAcl->getObjectAcl($sourceName = $nsPrefix, $objName = $type)
-			$objClassName = "Schema_{$type}StorageAcl";
-			if (Lib::tryLoadClass($objClassName)) return true;
-		}
-		return false;
-	}
-
 	/**
 	/**
 	 * @param string $typeName - 'p5_default_db:TEST_PERMS'
 	 * @param string $typeName - 'p5_default_db:TEST_PERMS'
 	*/
 	*/
 	public function getAclFromTypeName($typeName) {
 	public function getAclFromTypeName($typeName) {
 		$typeEx = explode(':', $typeName);
 		$typeEx = explode(':', $typeName);
+		$sourceName = null;
 		if (2 != count($typeEx)) throw new Api_WfsException("Could not get acl for '{$typeName}' - syntax error");
 		if (2 != count($typeEx)) throw new Api_WfsException("Could not get acl for '{$typeName}' - syntax error");
-		if ('p5_' != substr($typeEx[0], 0, 3)) throw new Api_WfsException("Could not get acl for '{$typeName}' - prefix error");
-		$sourceName = substr($typeEx[0], 3);
+		if ('p5_' == substr($typeEx[0], 0, 3)) $sourceName = substr($typeEx[0], 3);
+		else if ('default_db__x3A__' == substr($typeEx[0], 0, 17)) $sourceName = 'default_db';
+		else if ('default_objects' == $typeEx[0]) $sourceName = 'default_objects';
+		if (!$sourceName) throw new Api_WfsException("Type not found '{$typeName}'", 404);
 		$objName = $typeEx[1];
 		$objName = $typeEx[1];
 		$acl = $this->_usrAcl->getObjectAcl($sourceName, $objName);
 		$acl = $this->_usrAcl->getObjectAcl($sourceName, $objName);
 		if (!$acl) throw new Api_WfsException("Could not get acl for '{$typeName}'");
 		if (!$acl) throw new Api_WfsException("Could not get acl for '{$typeName}'");
@@ -150,7 +134,20 @@ class Api_WfsServerBase {
 	}
 	}
 
 
 	public function _getCapabilities($wfsServerUrl, $serviceTitle, $serviceDescription) {
 	public function _getCapabilities($wfsServerUrl, $serviceTitle, $serviceDescription) {
-		echo '<?xml version="1.0" encoding="UTF-8"?>';
+		if (V::get('DBG_ACL', '', $_GET)) {
+			{
+				echo "Core_AclHelper::getAclList = [" . "\n";
+				foreach (Core_AclHelper::getAclList() as $typeName) {
+					echo "|\t{$typeName}" . "\n";
+				}
+				echo "]// .EOF Core_AclHelper::getAclList" . "\n";
+			}
+
+			$fullTblAclList = $this->_usrAcl->getTablesAcl();
+			print_r($fullTblAclList);
+			die("\n" . '.EOF - DBG_ACL');
+		}
+		echo '<?xml version="1.0" encoding="UTF-8"?>' . "\n";
 		?>
 		?>
 <WFS_Capabilities
 <WFS_Capabilities
 				  xmlns="http://www.opengis.net/wfs"
 				  xmlns="http://www.opengis.net/wfs"
@@ -170,12 +167,12 @@ class Api_WfsServerBase {
   </Service>
   </Service>
   <Capability>
   <Capability>
     <Request>
     <Request>
-		<?php $this->_printGetCapabilitiesXml($wfsServerUrl); ?>
-		<?php $this->_printDescribeFeatureTypeXml($wfsServerUrl); ?>
-		<?php $this->_printGetFeatureXml($wfsServerUrl); ?>
-		<?php $this->_printTransactionXml($wfsServerUrl); ?>
-		<?php $this->_printLockFeatureXml($wfsServerUrl); ?>
-		<?php $this->_printGetFeatureWithLockXml($wfsServerUrl); ?>
+<?php $this->_printGetCapabilitiesXml($wfsServerUrl); ?>
+<?php $this->_printDescribeFeatureTypeXml($wfsServerUrl); ?>
+<?php $this->_printGetFeatureXml($wfsServerUrl); ?>
+<?php $this->_printTransactionXml($wfsServerUrl); ?>
+<?php $this->_printLockFeatureXml($wfsServerUrl); ?>
+<?php $this->_printGetFeatureWithLockXml($wfsServerUrl); ?>
     </Request>
     </Request>
   </Capability>
   </Capability>
   <FeatureTypeList>
   <FeatureTypeList>
@@ -186,7 +183,7 @@ class Api_WfsServerBase {
       <Delete />
       <Delete />
       <Lock />
       <Lock />
     </Operations>
     </Operations>
-	<?php $this->_printFeatureTypeListXml(); ?>
+<?php $this->_printFeatureTypeListXml(); ?>
   </FeatureTypeList>
   </FeatureTypeList>
   <ogc:Filter_Capabilities>
   <ogc:Filter_Capabilities>
     <ogc:Spatial_Capabilities>
     <ogc:Spatial_Capabilities>
@@ -585,13 +582,13 @@ class Api_WfsServerBase {
 
 
 	public function _printFeatureTypeListXml() {
 	public function _printFeatureTypeListXml() {
 		$featureTypes = array();
 		$featureTypes = array();
-		$tblsAcl = $this->_getTableAclList();
-		foreach ($tblsAcl as $tblAcl) {
+		foreach ($this->_getTableAclList() as $tblAcl) {
 			$dataSourceName = 'default_db';// TODO: getSourceName
 			$dataSourceName = 'default_db';// TODO: getSourceName
 			$tblName = $tblAcl->getName();
 			$tblName = $tblAcl->getName();
 			$usrObjList[] = array($dataSourceName, $tblName);
 			$usrObjList[] = array($dataSourceName, $tblName);
 			$featureType = array();
 			$featureType = array();
 			$featureType['ns'] = "p5_{$dataSourceName}";
 			$featureType['ns'] = "p5_{$dataSourceName}";
+			$featureType['Name'] = $tblAcl->getName();
 			$featureType['Title'] = $tblAcl->getRawLabel();
 			$featureType['Title'] = $tblAcl->getRawLabel();
 			$featureType['Abstract'] = $tblAcl->getRawOpis();
 			$featureType['Abstract'] = $tblAcl->getRawOpis();
 			$featureType['Keywords'] = array();
 			$featureType['Keywords'] = array();
@@ -605,23 +602,21 @@ class Api_WfsServerBase {
 			$featureType['LatLongBoundingBox']['miny'] = "38.8575126897477";
 			$featureType['LatLongBoundingBox']['miny'] = "38.8575126897477";
 			$featureType['LatLongBoundingBox']['maxx'] = "9.838674658246807";
 			$featureType['LatLongBoundingBox']['maxx'] = "9.838674658246807";
 			$featureType['LatLongBoundingBox']['maxy'] = "41.31378404137082";
 			$featureType['LatLongBoundingBox']['maxy'] = "41.31378404137082";
-			$featureTypes[$tblName] = $featureType;
+			$featureTypes[] = $featureType;
 		}
 		}
 
 
-		function __generateObjectFeatureType($name) {
+		foreach (Core_AclHelper::getAclList() as $typeName) {
+			$exTypeName = explode(':', $typeName);
 			$featureType = array();
 			$featureType = array();
-			$featureType['ns'] = "p5_objects";
-			$featureType['Title'] = $name;
-			$featureType['Abstract'] = $name;
-			$featureType['Keywords'] = $name;
+			$featureType['ns'] = $exTypeName[0];
+			$featureType['Name'] = $exTypeName[1];
+			$featureType['Title'] = $exTypeName[1];
+			$featureType['Abstract'] = $exTypeName[1];
+			$featureType['Keywords'] = $exTypeName[1];
 			$featureType['SRS'] = "EPSG:4326";
 			$featureType['SRS'] = "EPSG:4326";
-			return $featureType;
+			$featureTypes[] = $featureType;
 		}
 		}
-		$featureTypes['AccessOwner'] = __generateObjectFeatureType("AccessOwner");
-		$featureTypes['AccessGroup'] = __generateObjectFeatureType("AccessGroup");
-		$featureTypes['File'] = __generateObjectFeatureType("Pliki");
-		$featureTypes['Korespondencja'] = __generateObjectFeatureType("Korespondencja");
-		$featureTypes['TestPerms'] = __generateObjectFeatureType("TestPerms");
+
 		/*
 		/*
 			<FeatureType>
 			<FeatureType>
 				<Name>ppr06:AMBITIPAESAGGIO</Name>
 				<Name>ppr06:AMBITIPAESAGGIO</Name>
@@ -633,9 +628,10 @@ class Api_WfsServerBase {
 			</FeatureType>
 			</FeatureType>
 		*/
 		*/
 		$featureTypesXml = '';
 		$featureTypesXml = '';
-		foreach ($featureTypes as $tblName => $feature) {
-			$featureTypesXml .= "    " . '<FeatureType>' . "\n";
-				$featureTypesXml .= "      " . '<Name>' . "{$feature['ns']}:{$tblName}" . '</Name>' . "\n";
+		foreach ($featureTypes as $feature) {
+			$nsUriFeature = Api_WfsNs::getNsUri($feature['ns']);
+			$featureTypesXml .= "    " . '<FeatureType xmlns:' . $feature['ns'] . '="' . $nsUriFeature . '">' . "\n";
+				$featureTypesXml .= "      " . '<Name>' . "{$feature['ns']}:{$feature['Name']}" . '</Name>' . "\n";
 				$featureTypesXml .= "      " . '<Title>' . "{$feature['Title']}" . '</Title>' . "\n";
 				$featureTypesXml .= "      " . '<Title>' . "{$feature['Title']}" . '</Title>' . "\n";
 				if (!empty($feature['Abstract'])) {
 				if (!empty($feature['Abstract'])) {
 					$featureTypesXml .= "      " . '<Abstract>' . "{$feature['Abstract']}" . '</Abstract>' . "\n";
 					$featureTypesXml .= "      " . '<Abstract>' . "{$feature['Abstract']}" . '</Abstract>' . "\n";
@@ -1392,9 +1388,6 @@ if($DBG){echo 'L.' . __LINE__ . ' $validateConvertedTransactionXsdString:';print
 
 
 			$typeName = "{$nsPrefix}:{$type}";
 			$typeName = "{$nsPrefix}:{$type}";
 			$acl = $this->getAclFromTypeName($typeName);
 			$acl = $this->getAclFromTypeName($typeName);
-			if (!$this->isAllowedFeatureType($nsPrefix, $type)) {
-				throw new Api_WfsException("Could not find type: " . htmlspecialchars($type));
-			}
 			$typeName = $type . 'Type';
 			$typeName = $type . 'Type';
 			$fldList = $this->_getFieldListFromAcl($acl);
 			$fldList = $this->_getFieldListFromAcl($acl);
 
 
@@ -1553,7 +1546,7 @@ if($DBG){echo 'L.' . __LINE__ . ' $validateConvertedTransactionXsdString:';print
 			try {
 			try {
 				$acl = $this->getAclFromTypeName($typeName = "p5_{$dataSourceName}:{$tblName}");
 				$acl = $this->getAclFromTypeName($typeName = "p5_{$dataSourceName}:{$tblName}");
 			} catch (Exception $e) {
 			} catch (Exception $e) {
-				// TODO: error log $e->getMessage();
+				// echo "Error for table({$tblName}): " . $e->getMessage() . "\n";
 			}
 			}
 			if (!$acl) {
 			if (!$acl) {
 				// TODO: error log msg
 				// TODO: error log msg

+ 6 - 5
SE/se-lib/Core/AclHelper.php

@@ -59,8 +59,10 @@ class Core_AclHelper {// Helper class for Acl
 					if (!$acl) throw new Exception("Could not get acl for '{$schemaNs}'");
 					if (!$acl) throw new Exception("Could not get acl for '{$schemaNs}'");
 					$acl->init($forceTblAclInit);
 					$acl->init($forceTblAclInit);
 					return $acl;
 					return $acl;
-				}
-				else throw new Exception("Nieznany namespace default_db: '{$schemaNs}'", 501);
+				} else if (2 == count($ns)) {
+
+          throw new Exception("TODO: default_db: '{$schemaNs}' ns:[ ".implode(", ", $ns)." ]", 501);
+				} else throw new Exception("Nieznany namespace default_db: '{$schemaNs}'", 501);
 			}
 			}
 			else if ('default_objects' == $sourceName || 'SystemObjects' == $sourceName || 'p5_objects' == $sourceName) {
 			else if ('default_objects' == $sourceName || 'SystemObjects' == $sourceName || 'p5_objects' == $sourceName) {
 				$sourceName = 'objects';
 				$sourceName = 'objects';
@@ -70,8 +72,7 @@ class Core_AclHelper {// Helper class for Acl
 					if (!$acl) throw new Exception("Could not get acl for '{$schemaNs}'");
 					if (!$acl) throw new Exception("Could not get acl for '{$schemaNs}'");
 					$acl->init($forceTblAclInit);
 					$acl->init($forceTblAclInit);
 					return $acl;
 					return $acl;
-				}
-				else throw new Exception("Nieznany namespace SystemObjects: '{$schemaNs}'", 501);
+				} else throw new Exception("Nieznany namespace SystemObjects: '{$schemaNs}'", 501);
 			}
 			}
 			else if ('zasob_' == substr($sourceName, 0, 6)) {
 			else if ('zasob_' == substr($sourceName, 0, 6)) {
 				$dbName = substr($sourceName, 6);
 				$dbName = substr($sourceName, 6);
@@ -226,7 +227,7 @@ class Core_AclHelper {// Helper class for Acl
     $aclList[] = 'default_objects:TestPerms';
     $aclList[] = 'default_objects:TestPerms';
 
 
     // TODO: read from Database
     // TODO: read from Database
-    $aclList[] = 'default_db__x3A__TEST_PERMS:TEST_PERMS';// uproszczona wersja: default_db:TEST_PERMS
+    // $aclList[] = 'default_db__x3A__TEST_PERMS:TEST_PERMS';// uproszczona wersja: default_db:TEST_PERMS
 
 
     return $aclList;
     return $aclList;
   }
   }

+ 2 - 1
SE/se-lib/TableAcl.php

@@ -994,7 +994,8 @@ class TableAcl extends Core_AclBase {
 				}
 				}
 				$dbName = DB::getPDO()->getDatabaseName();
 				$dbName = DB::getPDO()->getDatabaseName();
 				$tableName = $this->getName();
 				$tableName = $this->getName();
-				$geomType = DB::getPDO()->fetchValue("select DATA_TYPE
+				$geomType = DB::getPDO()->fetchValue("
+					select DATA_TYPE
 					from `information_schema`.`COLUMNS`
 					from `information_schema`.`COLUMNS`
 					where TABLE_SCHEMA='{$dbName}'
 					where TABLE_SCHEMA='{$dbName}'
 						and TABLE_NAME='{$tableName}'
 						and TABLE_NAME='{$tableName}'

+ 4 - 0
SE/se-lib/UserAcl.php

@@ -166,6 +166,10 @@ class UserAcl {
 			$objClassName = "Schema_{$objName}StorageAcl";
 			$objClassName = "Schema_{$objName}StorageAcl";
 			if (!Lib::tryLoadClass($objClassName)) throw new HttpException("Not implemented", 501);
 			if (!Lib::tryLoadClass($objClassName)) throw new HttpException("Not implemented", 501);
 			return new $objClassName();
 			return new $objClassName();
+		} else if ('default_objects' == $sourceName && !empty($objName)) {
+			$objClassName = "Schema_{$objName}StorageAcl";
+			if (!Lib::tryLoadClass($objClassName)) throw new HttpException("Not implemented", 501);
+			return new $objClassName();
 		} else throw new HttpException("Not Implemented", 501);
 		} else throw new HttpException("Not Implemented", 501);
 		return false;
 		return false;
 	}
 	}