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('Geoserver Service false',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("## CONFIG ##"); $this->output->writeln("geoserver_path_shapes: $path"); $this->output->writeln("geoserver_host: $host"); $this->output->writeln("geoserver_port: $port"); $this->output->writeln("geoserver_user: $user"); $this->output->writeln("geoserver_pass: $pass"); $geoserver = $this->getContainer()->get('geoserver.api'); $rest = $geoserver->getUrlRest(); $this->output->writeln(""); $this->output->writeln("## URLS ##"); $this->output->writeln("REST: $rest"); 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: OK"); } else { $this->output->writeln("## Style $style: Not found ##"); } } $file_name = "onu_stats_demo"; $dir = "$path/demo"; $this->output->writeln(""); $this->output->writeln("## TEST SERVICE ##"); 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}: OK"); } else { $this->output->writeln("File {$file_name}.{$ext}: Not found"); } } $workspace = "demo"; $this->output->writeln("Create workspace demo"); $geoserver->createWorkspace($workspace); $this->output->writeln("Update shapes in demo"); $geoserver->updateShape($workspace); $styles = array(); foreach(array("onuRxPower","onuRxPowerLabel","onuTxPower","onuTxPowerLabel","onuStatus") as $k => $style) { $styles[] = ""; } $stylesXml = "".implode("",$styles).""; $rest = "layers/{$file_name}.xml"; $this->output->writeln("Set styles on shape demo"); $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("## $url ##"); $this->output->writeln("Fin"); // 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" } }