Pārlūkot izejas kodu

updated Ant exec

Piotr Labudda 9 gadi atpakaļ
vecāks
revīzija
1359dc8960

+ 9 - 9
SE/schema/ant-url_action/default_db.in7_dziennik_koresp/test-get-wfs-xml/build.xml

@@ -1,35 +1,35 @@
 <?xml version="1.0" encoding="UTF-8"?>
-<project basedir="." name="example wfs GetFeature" default="http_fist_input">
+<project basedir="." name="example wfs GetFeature" default="http_first_input">
+
+    <!-- file:/SE/schema/ant-url_action/default_db.in7_dziennik_koresp/test-get-wfs-xml/build.xml -->
 
-    <!-- file:/SE/schema/ant-url_action/default_db.in7_dziennik_koresp/test-get-wfs-xml/build.xml -->    
-    
     <!-- sample URL which call this exact variables in this ANT build -->
     <!-- przykladowy URL ktory przekazuje parametry do tego ANT -->
     <!--https://biuro.biall-net.pl/SE/version-git/index.php?_route=UrlAction_Ant&_task=ant&
-        path=${default_db.in7_dziennik_koresp/test-get-wfs-xml} -  this is the place to keep ant build (directory name with build.xml)  
+        path=${default_db.in7_dziennik_koresp/test-get-wfs-xml} -  this is the place to keep ant build (directory name with build.xml)
         &namespace=p5_default_db:Rozdzielcza_test_bzyk_PE&featureID=123 - this is setting the <property name="url" value="${url}"/> - to point what is record/table to download
         <property name="uuid" value="${uuid}"/> it is automatically also set to enable uinque transaction and to allow to save data with user
         <property name="passwordBase64Basic" value="${passwordBase64Basic}"/> - this is also set - to enable communicate with API -
-        <property name="DwebRootUrl" value="${$webRootUrl}"/> - this is the place where script is localized to easyli to target user GUI by href to generated output      
+        <property name="DwebRootUrl" value="${$webRootUrl}"/> - this is the place where script is localized to easyli to target user GUI by href to generated output
     />
     -->
 
     <property name="uuid" value="${uuid}"/>
     <property name="passwordBase64Basic" value="${passwordBase64Basic}"/>
     <property name="url" value="${url}"/>
-    <property name="webRootUrl" value="${webRootUrl}"/> 
+    <property name="webRootUrl" value="${webRootUrl}"/>
 
-    <target name="http_fist_input">
+    <target name="http_first_input">
         <exec executable="curl" outputproperty="wfs_output" errorproperty="wfs_error" resultproperty="wfs_result">
             <arg line="-H 'Authorization: Basic ${passwordBase64Basic}' ${url}"/>
         </exec>
         <echo message="curl -H 'Authorization: Basic ${passwordBase64Basic}' '${url}'"/>
         <echo message="OUTPUT__START"/>
         <echo message="${wfs_output}"/>
-        
+
         <echo message="webRootUrl"></echo>
         <echo message="${webRootUrl}"></echo>
-        
+
         <echo message="OUTPUT__END"/>
 
         <echo message="RESULT__START"/>

+ 28 - 0
SE/se-lib/Core/AclHelper.php

@@ -176,6 +176,31 @@ class Core_AclHelper {// Helper class for Acl
 				$rowFunList[] = $rowFunction;
 			}
 		}
+
+    if (1) {// Druki
+      $parsedNs = self::parseNamespaceUrl($acl->getNamespace());
+      // array (
+      //   'name' => 'TEST_PERMS',
+      //   'prefix' => 'default_db',
+      //   'url' => 'https://biuro.biall-net.pl/wfs/default_db',
+      //   'sourceName' => 'default_db',
+      // ),
+      $typeName = "{$parsedNs['prefix']}:{$parsedNs['name']}";
+      DBG::log([
+        'msg' => "getMoreFunctionsCell Druki",
+        'namespace' => $acl->getNamespace(),
+        'typeName' => $typeName,
+        'primaryKey' => $id,
+        'parseNamespace' => $parsedNs,
+      ]);
+      $rowFunList[] = [
+        'href' => Request::getPathUri() . "index.php?_route=UrlAction_Ant&typeName={$typeName}&primaryKey={$id}",
+        'ico' => 'glyphicon glyphicon-file',
+        'label' => "Druki",
+        'title' => "Druki"
+      ];
+    }
+    DBG::log(['msg'=>"\$rowFunList", '$rowFunList'=>$rowFunList]);
 		return $rowFunList;
 	}
 
@@ -220,6 +245,9 @@ class Core_AclHelper {// Helper class for Acl
     return $aclList;
   }
 
+  public static function parseTypeName($typeName) {
+    return self::parseNamespaceUrl(str_replace(':', '/', $typeName));
+  }
   /**
    * Parse namespace url into parts.
    *

+ 80 - 28
SE/se-lib/Route/UrlAction/Ant.php

@@ -11,20 +11,33 @@ class Route_UrlAction_Ant extends Route_Ant {// @doc @see Route_Ant
 
   public function defaultAction() {
     UI::gora();
+    UI::menu();
+    UI::startContainer();
     UI::tag('h1', [], 'Ant');
     try {
       $taskList = $this->getAntUrlActionList();
-      DBG::nicePrint($taskList, 'ant-url_action');
 
-      $featureID = V::get('featureID', '', $_GET);
-      $typeName = V::get('typeName', '', $_GET);
-      // TODO: validate missing ...
+      // $featureID = V::get('featureID', '', $_GET);
+      $primaryKey = V::get('primaryKey', '', $_GET, 'word');
+      $typeName = V::get('typeName', '', $_GET, 'word');
+      if (empty($typeName)) throw new Exception("Missing typeName");
+      if (empty($primaryKey)) throw new Exception("Missing primaryKey");
+      $parsedInfo = Core_AclHelper::parseTypeName($typeName);
+      DBG::log($parsedInfo, '', "Ant parseTypeName({$typeName})");
+      $acl = ACL::getAclByNamespace("{$parsedInfo['url']}/{$parsedInfo['name']}");
+      $pkField = $acl->getPrimaryKeyField();
 
       UI::startTag('ul');
       foreach ($taskList as $path => $label) {
-        $link = "index.php?_route=UrlAction_Ant&_task=ant&path={$path}&typeName={$typeName}&featureID={$featureID}";
         echo UI::h('li', [], [
-          UI::h('a', ['href'=>$link], "Uruchom '{$label}'")
+          UI::h('a', [
+            'href' => $this->getLink('ant', [
+              'path' => $path,
+              'typeName' => $typeName,
+              'primaryKey' => $primaryKey,
+              'primaryKeyField' => $pkField
+            ])
+          ], "Uruchom '{$label}'")
         ]);
       }
       UI::endTag('ul');
@@ -32,6 +45,7 @@ class Route_UrlAction_Ant extends Route_Ant {// @doc @see Route_Ant
       UI::alert('danger', $e->getMessage());
       DBG::log($e);
     }
+    UI::endContainer();
     UI::dol();
   }
 
@@ -47,45 +61,82 @@ class Route_UrlAction_Ant extends Route_Ant {// @doc @see Route_Ant
 
   public function antAction() {
     UI::gora();
+    UI::startContainer();
     try {
-      echo UI::h('h1', [], "Ant action");
       $path = V::get('path', '', $_GET);
       if (!$path) throw new Exception("Missing Ant path!");
-      $primaryKey = V::get('primaryKey', '', $_GET);
-      $xpath = V::get('xpath', '', $_GET);
-
       $typeName = V::get('typeName', '', $_GET);
-      list($nsPrefix, $objectName) = explode(':', $typeName);// TODO: get wfs prefix from typeName
+      if (!$typeName) throw new Exception("Missing typeName");
+      $primaryKey = V::get('primaryKey', '', $_GET);
+      if (!$primaryKey) throw new Exception("Missing primaryKey");
+      $pkField = V::get('primaryKeyField', '', $_GET);
+      if (!$pkField) throw new Exception("Missing primaryKeyField");
+      // list($nsPrefix, $objectName) = explode(':', $typeName);// TODO: get wfs prefix from typeName
+      $parsedInfo = Core_AclHelper::parseTypeName($typeName);
+      DBG::log($parsedInfo, '', "Ant parseTypeName({$typeName})");
+      $nsPrefix = $parsedInfo['prefix'];
+      $objectName = $parsedInfo['name'];
 
       // TODO: validate missing ...
+      DBG::log($_GET, 'array', '$_GET');
       DBG::log([ 'msg'=>'$path', '$path'=>$path]);
       DBG::log([ 'msg'=>'$primaryKey', '$primaryKey'=>$primaryKey]);
       DBG::log([ 'msg'=>'$typeName', '$typeName'=>$typeName]);
 
       $taskList = $this->getAntUrlActionList();
       if (!array_key_exists($path, $taskList)) throw new Exception("Ant path not exists! '{$path}'");
+      echo UI::h('h3', [], [
+        "Druk",
+        '<br>',
+        UI::h('small', [], $taskList[$path])
+      ]);
 
       echo UI::h('hr');
 
       $webRootUrl = Request::getPathUri() . "schema/ant-url_action/{$path}";// TODO: security - only for test
-      $outputFunctionUrl = Request::getPathUri() . "index.php?_route=UrlAction_Ant&_task=output&path={$path}&file=";
+      $outputFunctionUrl = $this->getLink('output') . "&path={$path}&file=";
       DBG::log([ 'msg'=>'$webRootUrl', '$webRootUrl'=>$webRootUrl]);
       DBG::log([ 'msg'=>'$outputFunctionUrl', '$outputFunctionUrl'=>$outputFunctionUrl]);
-      $testUrl = Request::getPathUri() . "wfs-data.php/default_db/?SERVICE=WFS&VERSION=1.0.0&REQUEST=GetFeature&TYPENAME=".$typeName."&SRSNAME=EPSG:3003&featureID={$objectName}.{$primaryKey}";
+      $testUrl = Request::getPathUri() . "wfs-data.php/default_db/?SERVICE=WFS&VERSION=1.0.0&REQUEST=GetFeature&TYPENAME={$typeName}&SRSNAME=EPSG:3003&featureID={$objectName}.{$primaryKey}";
       $cryptedPass = base64_encode(User::getLogin() . ":" . Crypt::decrypt($_SESSION['ADM_PASS_HASH']));
-//      $cmd = "cd {$this->pathUrlActions}{$path} && {$this->antBin}  -DoutputFunctionUrl='{$outputFunctionUrl}' -DwebRootUrl='{$webRootUrl}' -Durl='{$testUrl}' -DpasswordBase64Basic=\"{$cryptedPass}\" -Duuid=\"".session_id()."\" -Dxpath=".$xpath." -Dxpath_value=".$primaryKey." -DtypeName=\"".$typeName."\"  2>&1";
-      $cmd = "{$this->pathUrlActions}{$path}/do_build.sh -DoutputFunctionUrl='{$outputFunctionUrl}' -DwebRootUrl='{$webRootUrl}' -Durl='{$testUrl}' -DpasswordBase64Basic=\"{$cryptedPass}\" -Duuid=\"".session_id()."\" -Dxpath=".$xpath." -Dxpath_value=".$primaryKey." -DtypeName=\"".$typeName."\" ";
+      $uniqID = session_id();// TODO: uniq id for every request
+      // $cmd = "{$this->pathUrlActions}{$path}/do_build.sh";
+      $cmd = "cd {$this->pathUrlActions}{$path} && ant -S";
+      $cmd .= " -DoutputFunctionUrl='{$outputFunctionUrl}'";
+      $cmd .= " -DwebRootUrl='{$webRootUrl}'";
+      $cmd .= " -Durl='{$testUrl}'";
+      $cmd .= " -DpasswordBase64Basic=\"{$cryptedPass}\"";
+      $cmd .= " -Duuid=\"{$uniqID}\"";
+      $cmd .= " -Dxpath={$pkField}";
+      $cmd .= " -Dxpath_value={$primaryKey}";
+      $cmd .= " -DtypeName=\"{$typeName}\"";
+      $cmd .= " 2>&1";
+
+      $pathCmd = [];
+      $pathCmd[] = '/opt/local/bin/ant';
+      $pathCmd[] = '/bin';
+      $pathCmd[] = '/usr/bin';
+      $pathCmd[] = '/usr/local/bin';
+      $pathCmd[] = '/opt/local/bin';
+      $pathCmd[] = '/sbin';
+      $pathCmd[] = '/usr/sbin';
+      $pathCmd[] = '/opt/local/sbin/skrypty';
+      $pathCmd[] = '/opt/local/var/macports/software';
+      $pathCmd[] = '/Applications/Server.app/Contents/ServerRoot/usr/bin';
+      $pathCmd[] = '/Applications/Server.app/Contents/ServerRoot/usr/sbin';
+      $cmd = 'export PATH=' . implode(':', $pathCmd) . "\n" .
+        'JAVA_HOME="/usr/bin/java"' . "\n" .
+        'MAVEN_OPTS="-Xms256m -Xmx512m"' . "\n" .
+        $cmd;
+      $useShellExec = true;
+      if ($useShellExec) $out = shell_exec($cmd);
+      else V::exec($cmd, $out, $ret);
+      DBG::log([ 'msg'=>"cmd and returns({$ret})", 'output'=>$out, 'cmd'=>str_replace(APP_PATH_ROOT, 'SE', $cmd) ]);
+      if (empty($out)) throw new Exception("Empty output");
+      if ($useShellExec) $out = explode("\n", $out);
 
-      DBG::log([ 'msg'=>"cmd", 'cmd'=>str_replace(APP_PATH_ROOT, 'SE', $cmd) ]);
-      //V::exec($cmd, $out, $ret); to nie dziala prawidlowo
-      putenv('PATH=/opt/local/bin/ant');
-      $out=shell_exec($cmd);
-      DBG::log([ 'msg'=>"cmd and returns({$ret})", 'output'=>$out ]);
       $html = []; $startRead = false;
-      
-      
-      echo "<hr>".$out."<hr>"; //do poprawy, chce ruszyc, bo lokalnie mi dziala
-     /* foreach ($out as $line) {
+      foreach ($out as $line) {
         if (!$startRead) {
           if ('OUTPUT__START' == $line) {
             $startRead = true;
@@ -99,15 +150,16 @@ class Route_UrlAction_Ant extends Route_Ant {// @doc @see Route_Ant
           $html[]= $line;
         }
       }
-      echo UI::h('h3', [], "output:");
       if (empty($html)) UI::alert('danger', "Empty output!");
-      // echo UI::h('pre', [], htmlspecialchars(implode("\n", $html)));
-      echo UI::h('div', ['class'=>"container", 'style'=>"padding:12px; border:1px solid #ddd"], $html);
-      */
+      else {
+        // echo UI::h('pre', [], htmlspecialchars(implode("\n", $html)));
+        echo UI::h('div', ['class'=>"container", 'style'=>"padding:12px; border:1px solid #ddd"], $html);
+      }
     } catch (Exception $e) {
       UI::alert('danger', $e->getMessage());
       DBG::log($e);
     }
+    UI::endContainer();
     UI::dol();
   }