Преглед изворни кода

Se crea el comando geoserver:test para chequear la instalaciÃn de geoserver, los estilos, librerÃas y creaciÃn de layers.

Maxi Schvindt пре 7 година
родитељ
комит
fa020e7fb9
3 измењених фајлова са 136 додато и 1 уклоњено
  1. 134 0
      Command/GeoserverCommand.php
  2. 1 0
      Resources/stats_demo.json
  3. 1 1
      Services/GeoserverService.php

+ 134 - 0
Command/GeoserverCommand.php

@@ -0,0 +1,134 @@
+<?php
+
+namespace GeoserverBundle\Command;
+
+use Symfony\Bundle\FrameworkBundle\Command\ContainerAwareCommand;
+use Symfony\Component\Console\Input\InputInterface;
+use Symfony\Component\Console\Input\InputOption;
+use Symfony\Component\Console\Output\OutputInterface;
+use Symfony\Component\Process\Process;
+use Symfony\Component\Process\Exception\ProcessFailedException;
+
+class GeoserverCommand extends ContainerAwareCommand
+{
+
+    protected function configure()
+    {
+        $this
+                ->setName('geoserver:test')
+                ->setDescription('Geoserver test connection data')
+                ->setHelp('This command allows test geoserver')
+                ->setDefinition(array(
+                    
+                ))
+        ;
+    }
+
+    /**
+     * @param InputInterface $input
+     * @param OutputInterface $output
+     */
+    protected function execute(InputInterface $input, OutputInterface $output)
+    {
+        $this->output = $output;
+        
+        if(!$this->getContainer()->getParameter('geoserver_service')) {
+            $output->writeln(sprintf('<error>Geoserver Service false</error>',array()));
+            return;
+        }
+
+        $path = $this->getContainer()->getParameter('geoserver_path_shapes');
+        $host = $this->getContainer()->getParameter('geoserver_host');
+        $port = $this->getContainer()->getParameter('geoserver_port');
+        $user = $this->getContainer()->getParameter('geoserver_user');
+        $pass = $this->getContainer()->getParameter('geoserver_pass');
+
+        $this->output->writeln("<question>## CONFIG ##</question>");
+        $this->output->writeln("geoserver_path_shapes: <info>$path</info>");
+        $this->output->writeln("geoserver_host: <info>$host</info>");
+        $this->output->writeln("geoserver_port: <info>$port</info>");
+        $this->output->writeln("geoserver_user: <info>$user</info>");
+        $this->output->writeln("geoserver_pass: <info>$pass</info>");
+        
+        $geoserver = $this->getContainer()->get('geoserver.api');
+        $rest = $geoserver->getUrlRest();
+        
+        $this->output->writeln("");
+        $this->output->writeln("<question>## URLS ##</question>");
+        $this->output->writeln("REST: <info>$rest</info>");
+        foreach(array("onuRxPower","onuRxPowerLabel","onuTxPower","onuTxPowerLabel","onuStatus","ponRxPowerLabel") as $k => $style)  {
+            $data = $geoserver->existResource($rest."/styles/{$style}.json");
+            if($data) {
+                $this->output->writeln("Style $style: <info>OK</info>");
+            } else {
+                $this->output->writeln("## Style $style: <error>Not found</error> ##");
+            }
+        }
+        
+        
+        $file_name = "onu_stats_demo";
+        $dir = "$path/demo";
+        
+        $this->output->writeln("");
+        $this->output->writeln("<question>## TEST SERVICE ##</question>");
+        if(!is_dir($dir)) {
+            mkdir($dir, 0777, true);
+            chown($dir, "www-data");
+            chmod($dir, 0777);
+        }
+
+        $file = dirname(dirname(__FILE__))."/Resources/stats_demo.json";
+        if(file_exists($file)) {
+            copy($file, $dir."/".$file_name.".json");
+        }
+        
+        $process = new Process("ogr2ogr -f 'ESRI Shapefile' {$dir}/{$file_name}.shp {$dir}/{$file_name}.json");
+        $process->run();
+        if (!$process->isSuccessful()) {throw new ProcessFailedException($process);}
+        echo $process->getOutput();
+
+        $this->output->writeln("Demo $dir");
+        foreach(array("dbf","json","prj","shp","shx") as $k => $ext)  {
+
+            if(file_exists($dir."/".$file_name.".".$ext)) {
+                chown($dir."/".$file_name.".".$ext, "www-data");
+                $this->output->writeln("File {$file_name}.{$ext}: <info>OK</info>");
+            } else {
+                $this->output->writeln("File {$file_name}.{$ext}: <error>Not found</error>");
+            }
+        }
+
+        $workspace = "demo";
+        $this->output->writeln("<info>Create workspace demo</info>");
+        $geoserver->createWorkspace($workspace);
+        $this->output->writeln("<info>Update shapes in demo</info>");
+        $geoserver->updateShape($workspace);
+        
+        $styles = array();
+        foreach(array("onuRxPower","onuRxPowerLabel","onuTxPower","onuTxPowerLabel","onuStatus") as $k => $style) 
+        {   
+            $styles[] = "<style><name>{$style}</name><atom:link rel='alternate' href='{$rest}/styles/{$style}.xml' type='application/xml'/></style>";
+        }
+        
+        $stylesXml = "<layer><styles class='linked-hash-set'>".implode("",$styles)."</styles></layer>";
+        
+        $rest = "layers/{$file_name}.xml";
+        $this->output->writeln("<info>Set styles on shape demo</info>");
+        $geoserver->putData($rest, $stylesXml);
+        
+
+
+        $this->output->writeln("");
+        $url = $geoserver->getUrlWms("demo")."?service=WMS&version=1.1.0&request=GetMap&layers=demo:onu_stats_demo&styles=&bbox=-61.7008896,-33.1212889,-61.21277504,-32.01828173&width=339&height=768&srs=EPSG:4326&format=application/openlayers";
+        $this->output->writeln("<question>## $url ##</question>");
+
+        $this->output->writeln("<info>Fin</info>");
+
+    // curl -v -u admin:geoserver -XPUT -H "Content-type: text/plain" -d "file:/var/www/shapes/demo/" "http://geoserver.fd3.flowdat.com/geoserver/rest/workspaces/demo/datastores/shapefiles/external.shp?configure=all"
+
+
+
+
+    }
+
+}

Разлика између датотеке није приказан због своје велике величине
+ 1 - 0
Resources/stats_demo.json


+ 1 - 1
Services/GeoserverService.php

@@ -34,7 +34,7 @@ class GeoserverService
             $this->port = $this->serviceContainer->getParameter("geoserver_port");
             
             $this->pathShapes = $this->serviceContainer->getParameter("geoserver_path_shapes");
-            $this->url = "http://{$this->host}:{$this->port}/geoserver";
+            $this->url = "http://{$this->host}/geoserver";
         }
     }