[Mapbender-commits] r9853 - in trunk/mapbender: lib tools

svn_mapbender at osgeo.org svn_mapbender at osgeo.org
Wed Jan 31 08:44:25 PST 2018


Author: armin11
Date: 2018-01-31 08:44:25 -0800 (Wed, 31 Jan 2018)
New Revision: 9853

Modified:
   trunk/mapbender/lib/class_Monitor.php
   trunk/mapbender/tools/mod_monitorCapabilities_main.php
Log:
More bugfixes for wfs monitoring. Serverside should be ready to use now.

Modified: trunk/mapbender/lib/class_Monitor.php
===================================================================
--- trunk/mapbender/lib/class_Monitor.php	2018-01-30 19:33:31 UTC (rev 9852)
+++ trunk/mapbender/lib/class_Monitor.php	2018-01-31 16:44:25 UTC (rev 9853)
@@ -23,6 +23,7 @@
 require_once(dirname(__FILE__)."/../http/classes/class_mb_exception.php");
 require_once(dirname(__FILE__)."/../http/extensions/DifferenceEngine.php");
 require_once(dirname(__FILE__) . "/../http/classes/class_administration.php");
+require_once(dirname(__FILE__) . "/../http/classes/class_universal_wfs_factory.php");
 
 class Monitor {
 	/**
@@ -53,6 +54,7 @@
 	var $tmpDir = null;        
 	var $serviceType; //WMS|WFS
 	var $serviceId;
+	var $feature_content;
 	
 	function __construct($reportFile, $autoUpdate, $tmpDir, $serviceType="WMS") {
 		$this->tmpDir = $tmpDir;
@@ -129,7 +131,6 @@
 					$this->result = 1;
 					$this->comment = "Service is stable.";
 					//$e=new mb_exception("Compare ok - Docs ident");
-				
 				}
 				// capabilities files don't match
 				else {
@@ -152,7 +153,7 @@
 				}
 			}
 			/*
-			 * if the WMS is available,
+			 * if the SERVICE is available,
 			 * 1) get a map image
 			 * 2) update the local backup of the capabilities doc if necessary
 			 */
@@ -162,7 +163,80 @@
 						$this->mapURL = urldecode($this->getTagOutOfXML($this->reportFile,'getmapurl',$this->serviceType));
 						break;
 					case "WFS":
-
+						$wfsFactory = new UniversalWfsFactory();
+						$wfs = $wfsFactory->createFromDb($this->getTagOutOfXML($this->reportFile,'wfs_id',$this->serviceType));
+						$featureInfoArray = array();
+						foreach($wfs->featureTypeArray as $featureType) {
+							//$e = new mb_exception("ft name: ".$featureType->name);
+							//$e = new mb_exception("wfs version: ".$wfs->getVersion());
+							$featureInfo->featureTypeName = $featureType->name;
+							$feature = $wfs->getFeature($featureType->name, null, null, null, null, 1);
+							//*************************************************************************
+							//count features - part from http_auth/index.php - TODO - maybe included in wfs class
+							libxml_use_internal_errors(true);
+							try {
+								$featureCollectionXml = simplexml_load_string($feature);
+								if ($featureCollectionXml === false) {
+									foreach(libxml_get_errors() as $error) {
+        									//$err = new mb_exception("/lib/class_Monitor.php:".$error->message);
+    									}
+									throw new Exception("/lib/class_Monitor.php:".'Cannot parse featureCollection XML!');
+									//TODO give error message
+								}
+							}
+							catch (Exception $e) {
+    								//$err = new mb_exception("/lib/class_Monitor.php:".$e->getMessage());
+								//TODO give error message
+							}
+							if ($featureCollectionXml !== false) {
+								//$featureCollectionXml->registerXPathNamespace("gmd", "http://www.isotc211.org/2005/gmd");
+								$featureCollectionXml->registerXPathNamespace("ogc", "http://www.opengis.net/ogc");
+								if ($wfs->getVersion() == '2.0.0' || $wfs->getVersion() == '2.0.2') {
+									$featureCollectionXml->registerXPathNamespace("wfs", "http://www.opengis.net/wfs/2.0");
+								} else {
+									$featureCollectionXml->registerXPathNamespace("wfs", "http://www.opengis.net/wfs");
+								}
+								$featureCollectionXml->registerXPathNamespace("gco", "http://www.isotc211.org/2005/gco");
+								$featureCollectionXml->registerXPathNamespace("gml", "http://www.opengis.net/gml");
+								$featureCollectionXml->registerXPathNamespace("xlink", "http://www.w3.org/1999/xlink");
+								$featureCollectionXml->registerXPathNamespace("xsi", "http://www.w3.org/2001/XMLSchema-instance");
+								$featureCollectionXml->registerXPathNamespace("default", "");
+        							//preg_match('@version=(?P<version>\d\.\d\.\d)&@i', strtolower($url), $wfs->getVersion());
+       								if (!$wfs->getVersion()) {
+									$e = new mb_notice("/lib/class_Monitor.php: No version for wfs request given in reqParams!");
+								}
+								switch ($wfs->getVersion()) {
+									case "1.0.0":
+										//get # of features from counting features
+										$numberOfFeatures = $featureCollectionXml->xpath('//wfs:FeatureCollection/gml:featureMember');
+										$numberOfFeatures = count($numberOfFeatures);
+										break;
+									case "1.1.0":
+										//get # of features from counting features
+										$numberOfFeatures = $featureCollectionXml->xpath('//wfs:FeatureCollection/gml:featureMember');
+										$numberOfFeatures = count($numberOfFeatures);
+										break;
+									//for wfs 2.0 - don't count features
+									default:
+										//get # of features from attribut
+										$numberOfFeatures = $featureCollectionXml->xpath('//wfs:FeatureCollection/@numberReturned');
+										$numberOfFeatures = $numberOfFeatures[0];
+										break;
+								}
+								//$e = new mb_exception("/lib/class_Monitor.php: ".$numberOfFeatures." delivered features from wfs.");
+								if ($numberOfFeatures == "1") {
+									$featureInfo->getFeature = 1;
+								} else {
+									$featureInfo->getFeature = 0;
+								}	
+							} else {
+								$featureInfo->getFeature = -1;
+							}
+							$featureInfoArray[] = $featureInfo;
+								//*************************************************************************
+						}
+						$this->feature_content = json_encode($featureInfoArray);
+						//$e = new mb_exception("/lib/class_Monitor.php: feature_content: ".$this->feature_content);
 						break;
 				}
 			if (isset($auth)) {
@@ -330,6 +404,7 @@
 				$xml->wfs->comment=$this->comment;
 				$xml->wfs->getcapbegin=$this->timestamp_cap_begin;
 				$xml->wfs->getcapend=$this->timestamp_cap_end;
+				$xml->wfs->feature_content=$this->feature_content;
 				break;
 		}
 		$xml->asXML($this->reportFile);
@@ -366,6 +441,22 @@
 		return false;
 	}
 
+	/*
+	 * Checks if the getfeature url returns at minimum one feature
+	 */
+	function hasFeatures($url) {
+		if (func_num_args() == 2) { //new for HTTP Authentication
+        	    	$auth = func_get_arg(1);
+			$featureCollectionObject = new connector($url, $auth);
+		}
+		else {
+			$featureCollectionObject = new connector($url);
+		}
+		$featureCollection = $featureCollectionObject->file;
+		//parse gml content
+		
+	}
+
 	/**
 	 * Returns the objects out of the xml file
  	 */

Modified: trunk/mapbender/tools/mod_monitorCapabilities_main.php
===================================================================
--- trunk/mapbender/tools/mod_monitorCapabilities_main.php	2018-01-30 19:33:31 UTC (rev 9852)
+++ trunk/mapbender/tools/mod_monitorCapabilities_main.php	2018-01-31 16:44:25 UTC (rev 9853)
@@ -17,6 +17,7 @@
 require_once dirname(__FILE__) ."/../http/classes/class_administration.php";
 require_once dirname(__FILE__) ."/../tools/mod_monitorCapabilities_defineGetMapBbox.php";
 require_once dirname(__FILE__) ."/../http/classes/class_bbox.php";
+//require_once dirname(__FILE__) ."/../http/classes/class_universal_wfs_factory.php";
 //require_once(dirname(__FILE__)."/../http/classes/class_mb_exception.php");
 
 //do db close at the most reasonable point 
@@ -41,8 +42,8 @@
 	}
 	return $result;
 }
-
-//commandline
+// invocation *************************************************************************************
+// commandline
 if ($_SERVER["argc"] > 0) {
 	$cl = true;
 	if ($_SERVER["argc"] > 1 && $_SERVER["argv"][1] !== "") {
@@ -125,23 +126,28 @@
 
 	die;
 }
+// invocation *************************************************************************************
+
 $user_id_all = $userIdArray;
 echo $br ."Count of registrating users: " . count($user_id_all) . $br;
-$e = new mb_exception("mod_monitorCapabilities_main.php: count of group members: ".count($user_id_all));
+//$e = new mb_exception("mod_monitorCapabilities_main.php: count of group members: ".count($user_id_all));
+
+// loop for serviceType
+//define service types which should be monitored
+$serviceTypes = array('WMS','WFS');
+//for testing
+//$serviceTypes = array('WMS');
+foreach ($serviceTypes as $serviceType) {
+
 $time_array = array();
 
-
 //delete all temporary files (.xml and .png) from last monitoring
 array_map('unlink', glob(dirname(__FILE__)."/tmp/*.xml"));
 array_map('unlink', glob(dirname(__FILE__)."/tmp/*.png"));
-//define service types which should be monitored
-$serviceTypes = array('WMS','WFS');
-//for testing
-$serviceTypes = array('WMS');
 
 for ($iz = 0; $iz < count($user_id_all); $iz++) {
-    $e = new mb_exception("/tools/mod_monitorCapabilities_main.php: - initialize monitoring for userid: ".$user_id_all[$iz]);
-    foreach ($serviceTypes as $serviceType) {
+    //$e = new mb_exception("/tools/mod_monitorCapabilities_main.php: - initialize monitoring for userid: ".$user_id_all[$iz]);
+    //foreach ($serviceTypes as $serviceType) {
 	$userid = $user_id_all[$iz];
 	//get all owned services
 	switch ($serviceType) {
@@ -192,7 +198,6 @@
 		}
 		// for the case when there is no upload url - however - we need the 
 		// url to the capabilities file - depends on the service type
-
    		if (!$url || $url == "") {
 			$capabilities=$admin->checkURL($capabilities);
 			switch ($serviceType) {
@@ -208,8 +213,7 @@
 					$url = $capabilities . "REQUEST=GetCapabilities&" . 
 							"SERVICE=WFS&VERSION=" . $version;
 					break;
-			}
-					
+			}		
    		}
 		//$url is the url to the service which should be monitored in this cycle
 		//initialize monitoriung in db (set status=-2)
@@ -260,7 +264,6 @@
 		// Decode orig capabilities out of db cause they are converted before 
 		// saving them while upload
 		//$capDoc=$admin->char_decode($capDoc);
-
 		// do the next to exchange the update before by another behavior! - 
 		// look in class_monitor.php !
 		$currentFilename = strtolower($serviceType)."_monitor_report_" . $time . "_" . 
@@ -293,7 +296,15 @@
 				fwrite($report,"<getmapurl>".urlencode($getMapUrl)."</getmapurl>".$lb);
 				break;
 			case "WFS":
-				
+				//get list of featuretype names and other information
+				/*$wfsFactory = new UniversalWfsFactory();
+				$wfs = $wfsFactory->createFromDb($service_id_own[$k]);
+				foreach($wfs->featureTypeArray as $featureType) {
+					$e = new mb_exception("ft name: ".$featureType->name);
+					//$feature = $wfs->getFeature($featureType->name, null, null, null, null, 1);
+					//$e = new mb_exception($feature);
+				}*/
+				fwrite($report,"<feature_content></feature_content>".$lb);
 				break;
 		}
 		fwrite($report,"<status>-2</status>".$lb);
@@ -340,18 +351,18 @@
 	}
 	echo "Monitoring start cycle for user: ".$userid." has ended. " . 
 		"(Altogether: " . count($service_id_own) . " ".$serviceType." monitorings started).$br";
-    }
+    //}
 }
 //set time limit (mapbender.conf)
 set_time_limit(TIME_LIMIT);
 // wait until all monitoring processes are finished
 echo "please wait " . TIME_LIMIT . " seconds for the monitoring to finish...$br";
-
 sleep(TIME_LIMIT);
 //when time limit has ended: begin to collect results for every registrating user
 for ($iz = 0; $iz < count($user_id_all); $iz++) {
-    $e = new mb_exception("/tools/mod_monitorCapabilities.php - collect info from xml for user: ".$user_id_all[$iz]);
-    foreach ($serviceTypes as $serviceType) {
+    //$e = new mb_exception("/tools/mod_monitorCapabilities.php - collect info from xml for user: ".$user_id_all[$iz]);
+    //loop for serviceType - reinitialize all things from earlier serviceType
+    //foreach ($serviceTypes as $serviceType) {
 	// when time limit has ended: begin to collect results for every 
 	// registrating user
 	$problemOWS = array();//define array with id's of problematic wms
@@ -360,6 +371,7 @@
 	//get the old upload_id from the monitoring to identify it in the database
 	$time = $time_array[$userid];	
 	//get all owned services
+	
 	switch ($serviceType) {
 		case "WMS":
 			$service_id_own = $admin->getWmsByWmsOwner($userid);
@@ -367,7 +379,7 @@
 			break;
 		case "WFS":
 			$service_id_own = $admin->getWfsByWfsOwner($userid);
-			$tagsToReturn = array("status", "comment", "getcapdiff", "getcapbegin", "getcapend");
+			$tagsToReturn = array("status", "comment", "getcapdiff", "getcapbegin", "getcapend", "feature_content");
 			break;
 	}
 	for ($k = 0; $k < count($service_id_own); $k++) {
@@ -387,6 +399,7 @@
 				break;
 			case "WFS":
 				//TODO
+				$feature_content = $tags['feature_content'];
 				break;
 		}
 		switch ($serviceType) {
@@ -436,7 +449,7 @@
 				$v = array(
 					'0', 
 					intval($status), 
-					"feature_content - json", 
+					$feature_content, 
 					$status_comment, 
 					(string)intval($timestamp_end), 
 					"feature_urls - json", 
@@ -491,6 +504,7 @@
 			echo "\n ERROR: " . $error_msg;
 		}
 	}
-    }
+    //}
 }
+}
 ?>



More information about the Mapbender_commits mailing list