Просмотр исходного кода

added Ant acl reinstall, test DescribeFeatureType

Piotr Labudda 9 лет назад
Родитель
Сommit
afbea16940

+ 45 - 5
SE/schema/ant-object/default_db.TEST_PERMS/TestPermsAnt/build.xml

@@ -15,11 +15,51 @@
         <echo message="OUTPUT__START"/>
         <!-- <echo message="${wfs_output}"/> -->
         <echoxml>
-            <project default="foo">
-                <target name="foo">
-                    <echo>foo</echo>
-                </target>
-            </project>
+            <xsd:schema
+                xmlns:xsd="http://www.w3.org/2001/XMLSchema"
+                xmlns:gml="http://www.opengis.net/gml"
+                xmlns:p5="https://biuro.biall-net.pl/wfs"
+                xmlns:default_db="https://biuro.biall-net.pl/wfs/default_db"
+                xmlns:default_objects="https://biuro.biall-net.pl/wfs/default_objects"
+                xmlns:p5_objects="https://biuro.biall-net.pl/wfs/objects"
+                elementFormDefault="qualified"
+                targetNamespace="https://biuro.biall-net.pl/wfs/default_db"
+                version="1.0.0">
+                <xsd:import namespace="http://www.opengis.net/gml" schemaLocation="https://biuro.biall-net.pl/dev-pl/se-master/schema/gml/2.1.2/feature.xsd"/>
+                <!--typeName 'p5_default_db:TEST_PERMS'-->
+                <xsd:complexType name="TEST_PERMSType">
+                    <xsd:complexContent>
+                        <xsd:extension base="gml:AbstractFeatureType">
+                            <xsd:sequence>
+                                <xsd:element minOccurs="1" maxOccurs="1" name="ID" type="xsd:integer" nillable="true"/>
+                                <xsd:element minOccurs="0" maxOccurs="1" name="L_APPOITMENT_USER" type="xsd:string" nillable="true"/>
+                                <xsd:element minOccurs="0" maxOccurs="1" name="KATALOG_LINK" type="p5:www_link" nillable="true"/>
+                                <xsd:element minOccurs="0" maxOccurs="1" name="WWW" type="p5:www_link" nillable="true"/>
+                                <xsd:element minOccurs="0" maxOccurs="1" name="ADM_ADMIN_LEVEL" type="xsd:string" nillable="true"/>
+                                <xsd:element minOccurs="0" maxOccurs="1" name="ADM_PASSWD" type="xsd:string" nillable="true"/>
+                                <xsd:element minOccurs="0" maxOccurs="1" name="A_STATUS" type="xsd:string" nillable="true"/>
+                                <xsd:element minOccurs="0" maxOccurs="1" name="EMAIL" type="xsd:string" nillable="true"/>
+                                <xsd:element minOccurs="0" maxOccurs="1" name="ADM_NAME" type="xsd:string" nillable="true"/>
+                                <xsd:element minOccurs="0" maxOccurs="1" name="PARENT_ID" type="xsd:integer" nillable="true"/>
+                                <xsd:element minOccurs="0" maxOccurs="1" name="OPIS" type="xsd:string" nillable="true"/>
+                                <xsd:element minOccurs="0" maxOccurs="1" name="the_geom" type="gml:PolygonPropertyType" nillable="true"/>
+                                <xsd:element minOccurs="0" maxOccurs="1" name="A_ADM_COMPANY" type="xsd:string" nillable="true"/>
+                                <xsd:element minOccurs="0" maxOccurs="1" name="A_CLASSIFIED" type="xsd:string" nillable="true"/>
+                                <xsd:element minOccurs="0" maxOccurs="1" name="A_RECORD_CREATE_AUTHOR" type="xsd:string" nillable="true"/>
+                                <xsd:element minOccurs="0" maxOccurs="1" name="A_RECORD_CREATE_DATE" type="xsd:string" nillable="true"/>
+                                <xsd:element minOccurs="0" maxOccurs="1" name="A_RECORD_UPDATE_AUTHOR" type="xsd:string" nillable="true"/>
+                                <xsd:element minOccurs="0" maxOccurs="1" name="A_RECORD_UPDATE_DATE" type="xsd:string" nillable="true"/>
+                                <xsd:element minOccurs="0" maxOccurs="1" name="test_date" type="xsd:date" nillable="true"/>
+                                <xsd:element minOccurs="0" maxOccurs="1" name="test_datetime" type="xsd:dateTime" nillable="true"/>
+                                <xsd:element minOccurs="0" maxOccurs="1" name="test_price" type="p5:price" nillable="true"/>
+                                <xsd:element minOccurs="0" maxOccurs="1" name="test_time" type="xsd:string" nillable="true"/>
+                            </xsd:sequence>
+                            <xsd:attribute name="instance" type="default_db:instanceType"/>
+                        </xsd:extension>
+                    </xsd:complexContent>
+                </xsd:complexType>
+                <xsd:element name="TEST_PERMS" type="default_db:TEST_PERMSType" substitutionGroup="gml:_Feature"/>
+            </xsd:schema>
         </echoxml>
         <echo message="OUTPUT__END"/>
     </target>

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

@@ -1683,4 +1683,77 @@ jQuery(document).on('p5UIBtnAjax:Storage:addTableToZasoby:ajaxLoaded', function(
 		UI::dol();
 	}
 
+	public function objectReinstallAction() {
+		UI::gora();
+		UI::startContainer();
+		try {
+			$ns = V::get('namespace', '', $_GET);
+			if (empty($ns)) throw new Exception("Missing param namespace");
+			$exNs = explode('/', $ns);
+			if (1 == count($exNs)) throw new Exception("Wrong param namespace");
+			$name = array_pop($exNs);
+			$nsPrefix = implode('__x3A__', $exNs);
+			Lib::loadClass('Schema_SystemObjectStorageAcl');
+			$acl = new Schema_SystemObjectStorageAcl();
+			$items = $acl->getItems([
+				'f_name' => "={$name}",
+				'f_nsPrefix' => "={$nsPrefix}"
+			]);
+			if (empty($items)) throw new Exception("SystemObject '{$ns}' not found");
+			$item = reset($items);
+			if (empty($item)) throw new Exception("SystemObject '{$ns}' not found");
+			DBG::nicePrint($item, '$item');
+
+			switch ($item['_type']) {
+				case 'AntAcl': $this->reinstallAntAcl($item); break;
+				default: throw new Exception("TODO: Not Implemented type '{$item['_type']}'");
+			}
+		} catch (Exception $e) {
+			UI::alert('danger', "Error #" . $e->getCode() .  "|" . $e->getLine() .  ": " . $e->getMessage());
+		}
+		UI::endContainer();
+		UI::dol();
+	}
+
+	public function reinstallAntAcl($item) {
+		Lib::loadClass('AntAclBase');
+		$antAclPath = APP_PATH_SCHEMA . DS . 'ant-object' . DS . implode('.', explode('__x3A__', $item['nsPrefix'])) . DS . $item['name'];
+		DBG::nicePrint($antAclPath, '$antAclPath');
+		$antBin = APP_PATH_WWW . DS . 'stuff' . DS . 'dita-ot-2.3.3' . DS . 'bin' . DS . 'ant';
+		$cmd = "cd {$antAclPath} && {$antBin} DescribeFeatureType 2>&1";
+		V::exec($cmd, $out, $ret);
+		DBG::nicePrint($out, "DescribeFeatureType ret({$ret})");
+		$outputType = 'XML';
+		$html = []; $startRead = false;
+		foreach ($out as $line) {
+			// $line = "     [echo] OUTPUT__TYPE__XML"
+			if ('[echo]' == substr(trim($line), 0, 6)) {
+				$line = trim(substr(trim($line), 7));
+			}
+
+			if (!$startRead) {
+				if ('OUTPUT__TYPE__XML' == $line) $outputType = 'XML';
+				if ('OUTPUT__TYPE__HTML' == $line) $outputType = 'HTML';
+				if ('OUTPUT__START' == $line) {
+					$startRead = true;
+					continue;
+				}
+			} else {
+				if ('<!DOCTYPE' == substr($line, 0, strlen('<!DOCTYPE'))) continue;
+				if ('OUTPUT__END' == $line) {
+					break;
+				}
+				$html[]= $line;
+			}
+		}
+		if (empty($html)) UI::alert('danger', "Empty output!");
+		else {
+			if ('XML' == $outputType) {
+				echo UI::h('pre', [], htmlspecialchars(implode("\n", $html)));
+			} else if ('HTML' == $outputType) {
+				echo UI::h('div', ['class'=>"container", 'style'=>"padding:12px; border:1px solid #ddd"], $html);
+			}
+		}
+	}
+
 }

+ 22 - 121
SE/se-lib/Schema/SystemObjectStorageAcl.php

@@ -2,6 +2,7 @@
 
 Lib::loadClass('Core_AclSimpleSchemaBase');
 Lib::loadClass('ParseOgcFilter');
+Lib::loadClass('Router');
 
 class Schema_SystemObjectStorageAcl extends Core_AclSimpleSchemaBase {
 
@@ -17,6 +18,8 @@ class Schema_SystemObjectStorageAcl extends Core_AclSimpleSchemaBase {
       '_type' => [ '@type' => 'xsd:string' ],
       'isActive' => [ '@type' => 'xsd:integer' ], // installed
       'description' => [ '@type' => 'xsd:string' ],
+      'namespace' => [ '@type' => 'xsd:string' ],
+      'reinstallLink' => [ '@type' => 'p5:www_link' ],
       // 'A_RECORD_CREATE_AUTHOR' => [ '@type' => 'xsd:string' , '@label' => 'autor' ],
       // 'A_RECORD_CREATE_DATE' => [ '@type' => 'xsd:date' , '@label' => 'utworzono' ],
       // 'A_RECORD_UPDATE_AUTHOR' => [ '@type' => 'xsd:string' , '@label' => 'zaktualizował' ],
@@ -221,18 +224,20 @@ class Schema_SystemObjectStorageAcl extends Core_AclSimpleSchemaBase {
         // $acl = SchemaFactory::loadDefaultObject($clsName);
         // $namespace = $acl->getNamespace();
         // $name = $acl->getName();
+        $idDatabase = DB::getPDO($sourceName)->getZasobId();
         $sqlNsPrefix = "{$sourceName}__x3A__{$rootTableName}";
         $sqlName = $name;
         DB::getPDO()->execSql("
-          insert ignore into `{$this->_rootTableName}` (nsPrefix, idDatabase, _type, name, description, isActive)
+          insert into `{$this->_rootTableName}` (nsPrefix, idDatabase, _type, name, description, isActive)
             values (
               '{$sqlNsPrefix}'
-              , '0'
+              , '{$idDatabase}'
               , 'AntAcl'
               , '{$sqlName}'
               , ''
               , '1'
             )
+          on duplicate key update idDatabase = '{$idDatabase}'
         ");
       } catch (Exception $e) {
         UI::alert('danger', $e->getMessage());
@@ -275,6 +280,9 @@ class Schema_SystemObjectStorageAcl extends Core_AclSimpleSchemaBase {
           // TODO: check query by xpath or use different param prefix
           throw new Exception("Field '{$fieldName}' not found in '{$this->_namespace}'");
         }
+        if ('p5:www_link' == $xsdFields[$fieldName]) {
+          continue;
+        }
         $filterParams[$fieldName] = $v;
       }
     }
@@ -284,7 +292,11 @@ class Schema_SystemObjectStorageAcl extends Core_AclSimpleSchemaBase {
         if (is_array($value)) {
           DBG::log($value, 'array', "TODO SystemObject::_parseWhere array value for \$filterParams[{$fieldName}]");
         } else if (is_scalar($value)) {
-          $sqlWhere[] = "t.{$fieldName} like " . DB::getPDO()->quote("%{$value}%", PDO::PARAM_STR);
+          if ('=' == substr($value, 0, 1)) {
+            $sqlWhere[] = "t.{$fieldName} = " . DB::getPDO()->quote(substr($value, 1), PDO::PARAM_STR);
+          } else {
+            $sqlWhere[] = "t.{$fieldName} like " . DB::getPDO()->quote("%{$value}%", PDO::PARAM_STR);
+          }
         } else {
           DBG::log($value, 'array', "BUG SystemObject::_parseWhere unknown type for \$filterParams[{$fieldName}]");
         }
@@ -322,131 +334,20 @@ class Schema_SystemObjectStorageAcl extends Core_AclSimpleSchemaBase {
       ? "limit {$limit} offset {$offset}"
       : '';
 
-    return DB::getPDO()->fetchAll("
+    return array_map(array($this, 'buildFeatureFromSqlRow'), DB::getPDO()->fetchAll("
       select t.*
       from `{$this->_rootTableName}` t
       {$sqlWhere}
       {$sqlOrderBy}
       {$sqlLimit}
-    ");
-
-    $items = $this->_getAllItems();
-
-    $aliasMap = array();
-    foreach ($this->_simpleSchema['root'] as $key => $field) {
-      if ('@' === substr($key, 0, 1)) continue;
-      $aliasMap[ $key ] = $key;// (!empty($field['@alias'])) ? $field['@alias'] : $key;
-    }
-    // TODO: if (!array_key_exists($currSortCol, $aliasMap)) throw new Exception("field name not allowed to sort");
-    $currSortCol = (array_key_exists($currSortCol, $aliasMap)) ? $aliasMap[$currSortCol] : null;
-
-    if (!empty($currSortCol) && ('asc' == $currSortFlip || 'desc' == $currSortFlip)) {
-      usort($items, function ($itemA, $itemB) use ($currSortCol, $currSortFlip) {
-        $a = strtolower(V::get($currSortCol, '', $itemA));
-        $b = strtolower(V::get($currSortCol, '', $itemB));
-
-        if ($a == $b) return 0;
-        else if ('asc' == $currSortFlip)  return ($a < $b) ? -1 : 1;
-        else if ('desc' == $currSortFlip) return ($a > $b) ? -1 : 1;
-        throw new Exception("BUG - Wrong sort param - order dir");
-      });
-    }
-
-    $limit = V::get('limit', 0, $params);
-    $limit = ($limit < 0) ? 0 : $limit;
-    $offset = V::get('limitstart', 0, $params);
-    $offset = ($offset < 0) ? 0 : $offset;
-    return array_slice($items, $offset, ($limit > 0) ? $limit : null, $preserve_keys = true);
-  }
-
-  public function _generateUniqueKeyFromNamespace($namespace) {
-    return str_replace('/', '__x3A__', $namespace);
+    "));
   }
 
-  public function _getAllItems($params = []) {
-    static $_cacheAllItems = null;
-    if (null !== $_cacheAllItems) return $_cacheAllItems;
-    $idMainDatabase = DB::getPDO()->getZasobId();
-    $listFromZasoby = array_map(
-      function ($row) {
-        $row['ID'] = $row['id_zasob'];
-        if (false !== strpos($row['tabela'], '/')) {
-          $ns = Core_AclHelper::parseNamespaceUrl($row['tabela']);
-          $row['namespace'] = "{$row['tabela']}";
-          $row['typeName'] = "{$ns['prefix']}:{$ns['name']}";
-          $row['nazwa'] = $ns['name'];
-        } else {
-          $row['namespace'] = "default_db/{$row['tabela']}";
-          $row['typeName'] = "default_db:{$row['tabela']}";
-          // $row['ID'] = $this->_generateUniqueKeyFromNamespace($row['namespace']);
-        }
-        return $row;
-      }
-      , DB::getPDO()->fetchAll("
-        select z.ID as id_zasob
-          , z.`DESC` as tabela
-          , IF(z.`DESC_PL` != '', z.`DESC_PL`, z.`DESC`) as nazwa
-          , z.`OPIS` as opis
-          , z.A_RECORD_CREATE_AUTHOR as `autor`
-          , z.A_RECORD_CREATE_DATE as `utworzono`
-          , z.A_RECORD_UPDATE_AUTHOR as `zaktualizował`
-          , z.A_RECORD_UPDATE_DATE as `zaktualizowano`
-        from `CRM_LISTA_ZASOBOW` z
-        where z.PARENT_ID = {$idMainDatabase}
-          and z.`TYPE` = 'TABELA'
-          and z.`A_STATUS` not in('DELETED', 'OFF_HARD', 'OFF_SOFT')
-      ")
-    );
-    $notRawTables = array_filter(
-      array_map(
-        function ($item) {
-          return $item['typeName'];
-        }
-        , $listFromZasoby
-      )
-      , function ($typeName) {
-        return 'default_db:' !== substr($typeName, 0, strlen('default_db:'));
-      }
-    );
-    $_cacheAllItems = array_filter(
-      array_merge(
-        $listFromZasoby
-        , array_map(
-          function ($typeName) {
-            list($prefix, $objectName) = explode(':', $typeName);
-            $namespace = str_replace([':', '__x3A__'], '/', $typeName);
-            $id = 0;
-            if ('objects' == $prefix) {
-        			$id = SchemaFactory::loadDefaultObject($objectName)->getID();
-        		} else if ('default_objects' == $prefix) {
-              $id = SchemaFactory::loadDefaultObject($objectName)->getID();
-        		} else if ('default_db__x3A__' == substr($prefix, 0, 17)) {
-        			$rootTableName = strtolower(substr($prefix, 17));
-        			$id = SchemaFactory::loadTableObject($rootTableName, $objectName)->getID();
-        		}
-            if (!$id) $id = $this->_generateUniqueKeyFromNamespace($namespace);
-            return [
-              'ID' => $id,
-              'id_zasob' => $id,
-              'namespace' => $namespace,
-              'typeName' => $typeName,
-              'tabela' => '', // TODO: $acl->getRootTableName(),
-              'nazwa' => substr($typeName, strrpos($typeName, ':') + 1),
-              'opis' => '...',
-              'autor' => '',
-              'utworzono' => '',
-              'zaktualizował' => '',
-              'zaktualizowano' => ''
-            ];
-          }
-          , array_filter(Core_AclHelper::getAclList(), function ($typeName) use ($notRawTables) { return !in_array($typeName, $notRawTables); })
-        )
-      )
-      , function ($item) use ($params) {
-        return true;
-      }
-    );
-    return $_cacheAllItems;
+  public function buildFeatureFromSqlRow($item) {
+    $namespace = str_replace('__x3A__', '/', $item['nsPrefix']) . '/' . $item['name'];
+    $item['namespace'] = $namespace;
+    $item['reinstallLink'] = Router::getRoute('Storage')->getLink('objectReinstall', [ 'namespace' => $namespace ]);
+    return $item;
   }
 
 }