Browse Source

added root Ant Acl DescribeFeatureType in WFS (require admin and &root=1 in GET)

Piotr Labudda 9 years ago
parent
commit
c1bdaf98fb
3 changed files with 160 additions and 25 deletions
  1. 119 18
      SE/se-lib/AntAclBase.php
  2. 31 5
      SE/se-lib/Api/WfsServerBase.php
  3. 10 2
      SE/se-lib/Route/Storage.php

+ 119 - 18
SE/se-lib/AntAclBase.php

@@ -1,34 +1,135 @@
 <?php
 
 /**
- * SE/schema/ant-object/default_db.{rootTableName}/{name}/build.xml
- */
+* SE/schema/ant-object/default_db.{rootTableName}/{name}/build.xml
+*/
 class AntAclBase extends Core_AclBase {
 
-  public $_zasobID = '';
-  public $_rootTableName = '';
-
   public function __construct($zasobID = 0) {
     $this->_zasobID = $zasobID;
+    $this->_name = '';
+    $this->_namespace = '';
+    $this->_rootTableName = '';
+    $this->_primaryKey = '';
+    $this->_fields = [];
   }
   public function getName() { return $this->_name; }
-  public function getNamespace() { return 'default_db/' . $this->getName(); }
-  public function getSourceName() { return 'default_db'; }
+  public function getNamespace() { return $this->_namespace; }
+  public function getSourceName() { return 'default_db'; } // TODO: ?
   public function getRootTableName() { $this->_rootTableName; }
+  public function getPrimaryKeyField() { $this->_primaryKey; }
+  public function getRealFieldListByIdZasob() {
+    $cols = array();
+    $fakeZasobId = 1000000;
+    foreach ($this->getFields() as $field) {
+      $idZasobField = ($field['idZasob']) ? $field['idZasob'] : $fakeZasobId++;
+      $cols[$idZasobField] = $field['fieldNamespace'];
+    }
+    return $cols;
+  }
+  public function getXsdFieldType($fieldName) {
+    $field = $this->_getField($fieldName);
+    return $field['xsdType'];
+  }
+  public function getXsdMaxOccurs($fieldName) {
+    $field = $this->_getField($fieldName);
+    return $field['maxOccurs'];
+  }
+  public function getXsdMinOccurs($fieldName) {
+    $field = $this->_getField($fieldName);
+    return $field['minOccurs'];
+  }
+  public function getAttributesFromZasoby() {
+    return [];// TODO: ...
+  }
+
+  public function isEnumerationField($fieldName) {
+    return false; // TODO: ...
+  }
+
+  public function canWriteField($fieldName) {
+    return false; // TODO: return $this->getPerms($fieldName)->canWrite()
+  }
+  public function canCreateField($fieldName) {
+    return false; // TODO: return $this->getPerms($fieldName)->canCreate()
+  }
+  public function canReadField($fieldName) {
+    return true; // TODO: return $this->getPerms($fieldName)->canRead()
+  }
+
+  public function getFields() {
+    if (empty($this->_fields)) {
+      // TODO: fetch fields from DB
+      // Lib::loadClass('SchemaFactory');
+      // $objectStorage = SchemaFactory::loadDefaultObject('SystemObject');
+      // $item = $objectStorage->getItem($namespace, [
+      // 	'propertyName' => '*,field'
+      // ]);
+    }
+    return $this->_fields;
+  }
+  public function _getField($fieldName) {
+    foreach ($this->getFields() as $field) {
+      if ($fieldName === $field['fieldNamespace']) return $field;
+    }
+    throw new Exception("Field not found '{$this->_namespace}/{$fieldName}'");
+  }
 
   public static function buildInstance($idZasob, $conf = []) {
     static $_cache;
-		if (!$_cache) $_cache = array();
-		if (array_key_exists($idZasob, $_cache)) {
-			return $_cache[$idZasob];
-		}
-
-		if (empty($conf)) throw new Exception("Brak danych konfiguracyjnych do obiektu ant nr {$idZasob}");
-    DBG::nicePrint($conf, 'AntAclBase::buildInstance $conf');
-    $_cache[$idZasob] = new AntAclBase($idZasob);
-    // TODO: define field by conf
-    // TODO: $this->_rootTableName - from namespace
-    // TODO: need file path
+    if (!$_cache) $_cache = array();
+    if (array_key_exists($idZasob, $_cache)) {
+      return $_cache[$idZasob];
+    }
+
+    if (empty($conf)) {
+      throw new Exception("Brak danych konfiguracyjnych do obiektu ant nr {$idZasob}");
+
+      // TODO: fetch conf by $idZasob (or find $namespace first)
+      // Lib::loadClass('SchemaFactory');
+      // $objectStorage = SchemaFactory::loadDefaultObject('SystemObject');
+      // $item = $objectStorage->getItem($namespace, [
+      // 	'propertyName' => '*,field'
+      // ]);
+    }
+    DBG::log($conf, 'array', 'AntAclBase::buildInstance $conf');
+    $acl = new AntAclBase($idZasob);
+    $acl->_name = $conf['name'];
+    $acl->_rootTableName = $conf['_rootTableName'];
+    $acl->_namespace = $conf['namespace'];
+    $acl->_fields = $conf['field']; // TODO: lazyLoading - use getFields() in all functions
+    $acl->_primaryKey = $conf['primaryKey'];
+
+    //   'idZasob' => '25872',
+    //   'idDatabase' => '36',
+    //   'namespace' => 'default_db/CRM_PROCES/CRM_PROCES',
+    //   '_rootTableName' => 'CRM_PROCES',
+    //   '_type' => 'AntAcl',
+    //   'isActive' => '1',
+    //   'isStructInstalled' => '1',
+    //   'description' => '',
+    //   'name' => 'CRM_PROCES',
+    //   'nsPrefix' => 'default_db__x3A__CRM_PROCES',
+    //   'typeName' => 'default_db__x3A__CRM_PROCES:CRM_PROCES',
+    //   'reinstallLink' => 'https://biuro.biall-net.pl/dev-pl/se-master/index.php?_route=Storage&_task=objectReinstall&namespace=default_db/CRM_PROCES/CRM_PROCES',
+    //   'field' => [
+    //     0 => [
+    //       'namespace' => 'default_db/CRM_PROCES/CRM_PROCES/ID',
+    //       'fieldNamespace' => 'ID',
+    //       'idZasob' => NULL,
+    //       'idDatabase' => '36',
+    //       '_rootTableName' => 'CRM_PROCES',
+    //       'objectNamespace' => 'default_db/CRM_PROCES/CRM_PROCES',
+    //       'xsdType' => 'xsd:int',
+    //       'xsdRestrictions' => '[]',
+    //       'appInfo' => '[]',
+    //       'minOccurs' => '0',
+    //       'maxOccurs' => '1',
+    //       'isActive' => '1',
+    //       'description' => '',
+    //     ),
+
+    $_cache[$idZasob] = $acl;
     return $_cache[$idZasob];
   }
 

+ 31 - 5
SE/se-lib/Api/WfsServerBase.php

@@ -32,6 +32,26 @@ class Api_WfsServerBase {
 	 * @param string $typeName - 'p5_default_db:TEST_PERMS'
 	*/
 	public function getAclFromTypeName($typeName) {
+		if ('1' == V::get('root', '', $_GET) && User::isAdmin()) {// TODO: check byt CRM_CONFIG where key = 'root_access_acl__{$usrLogin}' and val = '{$namespace}'
+			$namespace = Api_WfsNs::namespaceFromTypeName($typeName);
+			DBG::log("getAclFromTypeName({$typeName}): ns='{$namespace}'");
+			Lib::loadClass('SchemaFactory');
+			$objectStorage = SchemaFactory::loadDefaultObject('SystemObject');
+			$item = $objectStorage->getItem($namespace, [
+				'propertyName' => '*,field'
+			]);
+			DBG::log($item, 'array', "acl item");
+			if (!$item['isStructInstalled']) throw new Api_WfsException("WARNING: acl '{$namespace}' has not struct installed - reinstall acl in Storage tool");
+			if (!$item['idZasob']) throw new Api_WfsException("WARNING: acl '{$namespace}' in not installed in Zasoby - add to Zasoby in Storage tool");
+			switch ($item['_type']) {
+				case 'AntAcl': {
+					Lib::loadClass('AntAclBase');
+					return AntAclBase::buildInstance($item['idZasob'], $item);
+				} break;
+				default: throw new Api_WfsException("WARNING: Not implemented '{$namespace}' type '{$item['_type']}'");
+			}
+		}
+
 		$typeEx = explode(':', $typeName);
 		$sourceName = $typeEx[0];
 		$objName = $typeEx[1];
@@ -1396,7 +1416,7 @@ if($DBG){echo 'L.' . __LINE__ . ' $validateConvertedTransactionXsdString:';print
 
 		$xmlWriter = new Core_XMLWriter();
 		if (!$xmlWriter) throw new HttpException("Error no XMLWriter", 404);
-		$xmlWriter->openUri('php://output');
+		$xmlWriter->openMemory();// openUri('php://output');
 		$xmlWriter->setIndent(true);
 		$xmlWriter->startDocument('1.0','UTF-8');
 		$xmlWriter->startElement('xsd:schema');
@@ -1419,8 +1439,6 @@ if($DBG){echo 'L.' . __LINE__ . ' $validateConvertedTransactionXsdString:';print
 			list($nsPrefix, $objectName) = $typeNameEx;
 			$typeName = "{$nsPrefix}:{$objectName}";
 			$xmlWriter->writeComment("typeName '{$typeName}'");
-			$acl = $this->getAclFromTypeName($typeName);
-
 			$acl = $this->getAclFromTypeName($typeName);
 			$aclNamespaceUri = Api_WfsNs::getNsUri($acl->getSourceName());
 			if (!array_key_exists($aclNamespaceUri, $nsMap)) $nsMap[$aclNamespaceUri] = $acl->getSourceName();
@@ -1542,8 +1560,15 @@ if($DBG){echo 'L.' . __LINE__ . ' $validateConvertedTransactionXsdString:';print
 				$fldList = $this->_getFieldListFromAcl($acl);
 				foreach ($fldList as $fldName) {
 					$xmlWriter->startElement('xsd:element');
-					$xmlWriter->writeAttribute('minOccurs', ($pKeyField == $fldName) ? '1' : '0'); // TODO: get minOccurs from $acl->xsd()
-					$xmlWriter->writeAttribute('maxOccurs', '1');
+					// TODO: get minOccurs from $acl->xsd()
+					$xmlWriter->writeAttribute('minOccurs', (method_exists($acl, 'getXsdMinOccurs'))
+						? $acl->getXsdMinOccurs($fldName)
+						: (($pKeyField == $fldName) ? '1' : '0')
+					);
+					$xmlWriter->writeAttribute('maxOccurs', (method_exists($acl, 'getXsdMaxOccurs'))
+						? $acl->getXsdMaxOccurs($fldName)
+						: '1'
+					);
 					$fldType = $acl->getXsdFieldType($fldName);
 					if (!$simple && $acl->isEnumerationField($fldName)) {
 						$fldType = $acl->getSourceName() . ":{$fldName}Type";
@@ -1637,6 +1662,7 @@ if($DBG){echo 'L.' . __LINE__ . ' $validateConvertedTransactionXsdString:';print
 		}
 		$xmlWriter->endElement(); // 'xsd:schema'
 		$xmlWriter->endDocument();
+		echo $xmlWriter->outputMemory($flush = true);
 	}
 
 	public function _getTableAclList() {// Use only Tables from default_db

+ 10 - 2
SE/se-lib/Route/Storage.php

@@ -561,7 +561,7 @@ jQuery(document).on('p5UIBtnAjax:Storage:checkObjectInstallAjax:ajaxLoaded', fun
 
 			{
 				echo UI::h('style', ['type' => "text/css"], "
-					.p5UI__dropdown-content { padding:8px; background-color: #f6f6f6; box-shadow: 0px 8px 16px 0px rgba(0,0,0,0.2) }
+					.p5UI__dropdown-content { min-width:300px; padding:8px; background-color: #f6f6f6; box-shadow: 0px 8px 16px 0px rgba(0,0,0,0.2) }
 					.p5UI__dropdown-content a { display:block; color:#000; padding:8px; text-decoration:none }
 					.p5UI__dropdown-content a:hover { background-color:#ebebeb }
 				");
@@ -593,7 +593,8 @@ jQuery(document).on('p5UIBtnAjax:Storage:checkObjectInstallAjax:ajaxLoaded', fun
 					]),
 				'rows' => array_map(function ($item) use ($idStorage) {
 					$addToZasobyLink = $this->getLink('addAclObjectToZasoby', ['idStorage' => $idStorage, 'namespace' => $item['namespace']]);
-					$typeName = Api_WfsNs::typeName($item['namespace']);
+					// $typeName = Api_WfsNs::typeName($item['namespace']);
+					$typeName = $item['typeName'];
 					return [
 						'namespace' => '<span style="color:#888">' . substr($item['namespace'], 0, strlen($item['namespace']) - strlen($item['name'])) . '</span>' .
 							'<span>' . $item['name'] . '</span>',
@@ -622,7 +623,14 @@ jQuery(document).on('p5UIBtnAjax:Storage:checkObjectInstallAjax:ajaxLoaded', fun
 								UI::h('a', [ 'href' => Router::getRoute('ViewObject')->getLink('', ['namespace' => $item['namespace']]) ], "view object"),
 								// 'xsd' => UI::h('a', [ 'href' => $this->getLink('xsd', [ 'idStorage' => $idStorage ]) ], "xsd"),
 								UI::h('a', [ 'href' => "wfs-data.php/default_db/?SERVICE=WFS&VERSION=1.0.0&SRSNAME=EPSG:3003&REQUEST=DescribeFeatureType&TYPENAME={$typeName}" ], "wfs DescribeFeatureType"),
+								UI::h('a', [ 'href' => "wfs-data.php/default_db/?SERVICE=WFS&VERSION=1.0.0&SRSNAME=EPSG:3003&REQUEST=DescribeFeatureTypeAdvanced&TYPENAME={$typeName}" ], "wfs DescribeFeatureTypeAdvanced"),
 								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=DescribeFeatureType&TYPENAME={$typeName}&root=1" ], "wfs root DescribeFeatureType"),
+								UI::h('a', [ 'href' => "wfs-data.php/default_db/?SERVICE=WFS&VERSION=1.0.0&SRSNAME=EPSG:3003&REQUEST=DescribeFeatureTypeAdvanced&TYPENAME={$typeName}&root=1" ], "wfs root DescribeFeatureTypeAdvanced"),
+								UI::h('a', [ 'href' => "wfs-data.php/default_db/?SERVICE=WFS&VERSION=1.0.0&SRSNAME=EPSG:3003&REQUEST=GetFeature&TYPENAME={$typeName}&MAXFEATURES=10&root=1" ], "wfs root 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&root=1" ], "wfs root GetFeatureAdvanced (max: 10)"),
 							])
 						]),
 					];