[Mapbender-commits] r8596 - in trunk/mapbender: conf http/classes http/geoportal http/php

svn_mapbender at osgeo.org svn_mapbender at osgeo.org
Wed Apr 10 04:16:12 PDT 2013


Author: armin11
Date: 2013-04-10 04:16:12 -0700 (Wed, 10 Apr 2013)
New Revision: 8596

Added:
   trunk/mapbender/http/php/mod_validateInspire.php
Modified:
   trunk/mapbender/conf/mapbender.conf-dist
   trunk/mapbender/http/classes/class_connector.php
   trunk/mapbender/http/geoportal/mod_pullInspireMonitoring.php
   trunk/mapbender/http/php/mod_dataISOMetadata.php
   trunk/mapbender/http/php/mod_layerISOMetadata.php
Log:
Integrate new INSPIRE validation service. Export possibility for INSPIRE monitoring

Modified: trunk/mapbender/conf/mapbender.conf-dist
===================================================================
--- trunk/mapbender/conf/mapbender.conf-dist	2013-04-09 10:32:08 UTC (rev 8595)
+++ trunk/mapbender/conf/mapbender.conf-dist	2013-04-10 11:16:12 UTC (rev 8596)
@@ -203,6 +203,14 @@
 #---------------------------------------------
 #define("METADATA_DEFAULT_CODESPACE", "http://www.mapbender.org");
 
+#---------------------------------------------
+# External Validator
+#---------------------------------------------
+# This is an absolute URL to an external validation service
+#---------------------------------------------
+define("INSPIRE_VALIDATOR_URL", "http://inspire-geoportal.ec.europa.eu/GeoportalProxyWebServices/resources/INSPIREResourceTester");
+
+
 # --------------------------------------------
 # UPLOAD
 # --------------------------------------------

Modified: trunk/mapbender/http/classes/class_connector.php
===================================================================
--- trunk/mapbender/http/classes/class_connector.php	2013-04-09 10:32:08 UTC (rev 8595)
+++ trunk/mapbender/http/classes/class_connector.php	2013-04-10 11:16:12 UTC (rev 8596)
@@ -33,6 +33,7 @@
 	private $httpVersion = "1.0";
 	private $httpPostData;
 	private $httpContentType;
+	private $accept;
 	private $httpPostFieldsNumber;
 	private $curlSendCustomHeaders = true; //decide to send own headers or not
 	private $curlCookiesession = true;
@@ -164,6 +165,10 @@
 					$this->httpContentType = $value;
 				}
 				break;
+
+			case "accept":
+				$this->accept = $value;
+				break;	
 		}
 	}	
 	
@@ -179,7 +184,7 @@
 	
 	private function isValidHttpContentType ($value) {
 		$validHttpContentTypeArray = array("XML","TEXT/XML","APPLICATION/XML","MULTIPART/FORM-DATA");
-		if (in_array(mb_strtoupper($value), $validHttpContentTypeArray)) {
+		if (in_array(mb_strtoupper($value), $validHttpContentTypeArray) or strpos(mb_strtoupper($value), "MULTIPART/FORM-DATA") !== false) {
 			switch (mb_strtoupper($value)) {
 				case "XML":
 					$this->httpContentType = "application/xml";
@@ -260,20 +265,34 @@
 		}
 		
 		
-		
+		$useragent=CONNECTION_USERAGENT;
 		//if httpType is POST, set CURLOPT_POST and CURLOPT_POSTFIELDS  
 		//and set a usefull http header
 		if(strtoupper($this->httpType) == 'POST'){
-			$headers = array(
+			if (isset($this->accept) && $this->accept != "") {
+				$headers = array(
 					"POST ".$path." HTTP/1.1",
+					"Accept: ".$this->accept,
+					"User-Agent: ".$useragent,
+            			 	"Content-type: ".$this->httpContentType,
+           				"Cache-Control: no-cache",
+	           		 	"Pragma: no-cache",
+	           		 	"Content-length: ".strlen($this->httpPostData)
+				);
+			} else {
+				$headers = array(
+					"POST ".$path." HTTP/1.1",
+					"User-Agent: ".$useragent,
             			 	"Content-type: ".$this->httpContentType."; charset=".CHARSET,
            				"Cache-Control: no-cache",
 	           		 	"Pragma: no-cache",
 	           		 	"Content-length: ".strlen($this->httpPostData)
-			); 
+				);
+			}
 			$e = new mb_notice("connector: CURL POST: ".$this->httpPostData); 
 			$e = new mb_notice("connector: CURL POST length: ".strlen($this->httpPostData));
-			
+			$e = new mb_exception("connector: CURL headers: ".print_r($headers));
+			$e = new mb_notice("connector: CURL post fields: ".$this->httpPostFieldsNumber);
 			if ($this->curlSendCustomHeaders) {			
 				curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
 			}
@@ -282,9 +301,10 @@
 			} else {
 				curl_setopt($ch, CURLOPT_POST, 1);
 			}
-			curl_setopt($ch, CURLOPT_POSTFIELDS, $this->httpPostData);	
+			curl_setopt($ch, CURLOPT_POSTFIELDS, $this->httpPostData);
+			//curl_setopt($ch, CURLOPT_POSTFIELDS, "value=1");	
 		}
-		$useragent=CONNECTION_USERAGENT;
+		
 		//Build own headers for GET Requests - maybe needful?
 		if(strtoupper($this->httpType) == 'GET'){
 			$headers = array(

Modified: trunk/mapbender/http/geoportal/mod_pullInspireMonitoring.php
===================================================================
--- trunk/mapbender/http/geoportal/mod_pullInspireMonitoring.php	2013-04-09 10:32:08 UTC (rev 8595)
+++ trunk/mapbender/http/geoportal/mod_pullInspireMonitoring.php	2013-04-10 11:16:12 UTC (rev 8596)
@@ -195,11 +195,13 @@
 				if ($sqlTable['uuid'][$i] != $currentUuid) {
 					//new metadataset identified - initialize it
 					$currentUuid = $sqlTable['uuid'][$i];
+					//logit($currentUuid);
+					
 					$metadataIndex++;
-					$e = new mb_exception("index: ".$metadataIndex);
+					//$e = new mb_exception("index: ".$metadataIndex);
 					$inspireMonitoring['datasets'][$metadataIndex]->datasetid = $sqlTable['datasetid'][$i];
 					$inspireMonitoring['datasets'][$metadataIndex]->title = $sqlTable['title'][$i];
-
+					//logit($inspireMonitoring['datasets'][$metadataIndex]->title);
 					$inspireMonitoring['datasets'][$metadataIndex]->organization = $sqlTable['organization'][$i];
 					$inspireMonitoring['datasets'][$metadataIndex]->orgaEmail = $sqlTable['orgaEmail'][$i];
 					$inspireMonitoring['datasets'][$metadataIndex]->relevantArea = "";
@@ -224,9 +226,18 @@
 				}
 				if ($metadataIndex > -1) { //prohibit indexes which are not real - otherwise the json array will become an object
 					//build view service
-					$e = new mb_exception("resource type: ".$sqlTable['resource_type'][$i]." - uuid: ".$sqlTable['uuid'][$i]);
+					//$e = new mb_exception("resource type: ".$sqlTable['resource_type'][$i]." - uuid: ".$sqlTable['uuid'][$i]);
 					//build view services - but only once for each view service uuid (layer uuid)
 					if ($sqlTable['resource_type'][$i] == "layer") {
+						$inspireMonitoring['datasets'][$metadataIndex]->viewServiceId = $sqlTable['resource_uuid'][$i];
+						$inspireMonitoring['datasets'][$metadataIndex]->viewServiceId = $sqlTable['resource_uuid'][$i];
+						//get inspire categories					
+						$catString = $sqlTable['inspire_cat_monitoring'][$i];
+						$insCat .= $sqlTable['inspire_cat_monitoring'][$i];
+						if ($insCat != '') {
+							$insCat .= ",";
+						}
+						$inspireMonitoring['datasets'][$metadataIndex]->numberViewServices++;
 						if (!in_array($sqlTable['resource_uuid'][$i],$alreadyBuildVs)) {
 							//addview view service
 							$inspireMonitoring['services'][$serviceIndex]->id = $sqlTable['resource_uuid'][$i];
@@ -256,12 +267,6 @@
 							$inspireMonitoring['services'][$serviceIndex]->report = "";
 							//report
 							$inspireMonitoring['services'][$serviceIndex]->comment = "";
-							//get inspire categories					
-							$catString = $sqlTable['inspire_cat_monitoring'][$i];
-							$insCat .= $sqlTable['inspire_cat_monitoring'][$i];
-							if ($insCat != '') {
-								$insCat .= ",";
-							}
 							//increment amount of view services
 					
 							/*if ($sqlTable['inspire_download'][$i] == 1) {
@@ -269,16 +274,16 @@
 								//increment amount of view services
 								$output['aaData'][$metadataIndex]->numberDownloadServices++;
 							}*/
-							$inspireMonitoring['datasets'][$metadataIndex]->numberViewServices++;
+							//$inspireMonitoring['datasets'][$metadataIndex]->numberViewServices++;
 							$serviceIndex++;
 							//Add view service to dataset list
-							$inspireMonitoring['datasets'][$metadataIndex]->viewServiceId = $sqlTable['resource_uuid'][$i];
+							//$inspireMonitoring['datasets'][$metadataIndex]->viewServiceId = $sqlTable['resource_uuid'][$i];
 							$alreadyBuildVs[] = $sqlTable['resource_uuid'][$i];
 						}
 						
 						
 					}
-					$e = new mb_exception("generate downloadservice");
+					//$e = new mb_exception("generate downloadservice");
 					//if (!in_array($sqlTable['uuid'][$i],$alreadyBuildDls)) {
 						//initialize array of uuids which are already tested for downloadservices!
 						//the options are all the same for one single metadata uuid - therefor this has only to be done once for a uuid!
@@ -288,7 +293,7 @@
 						//get download options 
 						//Pull download options for specific dataset from mapbender database and show them
 						$downloadOptionsConnector = new connector("http://localhost".$_SERVER['SCRIPT_NAME']."/../../php/mod_getDownloadOptions.php?id=".$sqlTable['uuid'][$i]);
-						$e = new mb_exception("download options: ".$downloadOptionsConnector->file);
+						//$e = new mb_exception("download options: ".$downloadOptionsConnector->file);
 						$downloadOptions = json_decode($downloadOptionsConnector->file);
 						if (defined("MAPBENDER_PATH") && MAPBENDER_PATH != '') { 
 							$mapbenderUrl = MAPBENDER_PATH;
@@ -317,9 +322,9 @@
 									
 									if ($uuidTest) {
 										$mdPart = explode('-',$mdUuid);
-										$e = new mb_exception("is uuid");
+										//$e = new mb_exception("is uuid");
 									} else {
-										$e = new mb_exception("is not uuid");
+										//$e = new mb_exception("is not uuid");
 										$mdPart = array();
 										$mdPart[2] = substr($mdUuid,-12,-8);
 										$mdPart[3] = substr($mdUuid,-4);
@@ -384,7 +389,7 @@
 							}
 						}
 					//}
-					$e = new mb_exception("generate organization entry");
+					//$e = new mb_exception("generate organization entry");
 					if (!in_array($sqlTable['organization'][$i],$alreadyReadOrgas)) {
 						$alreadyReadOrgas[] = $sqlTable['organization'][$i];
 						$inspireMonitoring['organizations'][$orgaIndex]->id = $sqlTable['orgaId'][$i];
@@ -423,6 +428,7 @@
 					}
 					//reduce categories if there are double entries
 					$arrayInspireCategories = array_unique(explode(',',(rtrim($insCat,','))));
+					//$e = new mb_exception($insCat);
 					for ($j=0; $j < 34; $j++) {
 						$catId = $j+1;
 						if (in_array($catId,$arrayInspireCategories)) {
@@ -692,4 +698,17 @@
     }
     return FALSE;
 }
+
+//for debugging purposes only
+function logit($text){
+	 if($h = fopen("/tmp/pullInspireMonitoring.log","a")){
+				$content = $text .chr(13).chr(10);
+				if(!fwrite($h,$content)){
+					#exit;
+				}
+				fclose($h);
+			}
+	 	
+ }
+
 ?>

Modified: trunk/mapbender/http/php/mod_dataISOMetadata.php
===================================================================
--- trunk/mapbender/http/php/mod_dataISOMetadata.php	2013-04-09 10:32:08 UTC (rev 8595)
+++ trunk/mapbender/http/php/mod_dataISOMetadata.php	2013-04-10 11:16:12 UTC (rev 8596)
@@ -29,6 +29,7 @@
 require_once(dirname(__FILE__) . "/../classes/class_connector.php");
 require_once(dirname(__FILE__) . "/../classes/class_administration.php");
 require_once(dirname(__FILE__) . "/../classes/class_Uuid.php");
+require_once(dirname(__FILE__) . "/../php/mod_validateInspire.php");
 
 $con = db_connect(DBSERVER,OWNER,PW);
 db_select_db(DB,$con);
@@ -115,7 +116,7 @@
 						echo $mb_metadata['data'];
 						die();
 					} else {
-						validateInspireMetadataFromData($row['data']);
+						validateInspire($row['data']);
 						die();
 					}
 				} else {
@@ -135,7 +136,7 @@
 					echo $metadataXml;
 					die();
 				} else {
-					validateInspireMetadataFromData($metadataXml);
+					validateInspire($metadataXml);
 					die();
 				}
 				
@@ -149,7 +150,7 @@
 					echo $mb_metadata['data'];
 					die();
 				} else {
-					validateInspireMetadataFromData($row['data']);
+					validateInspire($row['data']);
 					die();
 				}
 			} else {
@@ -167,7 +168,7 @@
 					echo $mb_metadata['data'];
 					die();
 				} else {
-					validateInspireMetadataFromData($mb_metadata['data']);
+					validateInspire($mb_metadata['data']);
 					die();
 				}
 			} else {
@@ -1465,50 +1466,6 @@
 		die();
 	}
 
-	//function to validate against the inspire validation service
-	function validateInspireMetadataFromData($iso19139Xml){
-		$validatorUrl = 'http://inspire-geoportal.ec.europa.eu/INSPIREValidatorService/resources/validation/inspire';
-		#$validatorUrl2 = 'http://localhost/mapbender/x_geoportal/log_requests.php';
-		//send inspire xml to validator and push the result to requesting user
-		$validatorInterfaceObject = new connector();
-		$validatorInterfaceObject->set('httpType','POST');
-		#$validatorInterfaceObject->set('httpContentType','application/xml');
-		$validatorInterfaceObject->set('httpContentType','multipart/form-data'); # maybe given automatically
-		//first test with data from ram - doesn't function 
-		$fields = array(
-			'dataFile'=>urlencode($iso19139Xml)
-			);
-		//generate file identifier:
-		$fileId = guid();
-		//generate temporary file under tmp
-		 if($h = fopen(TMPDIR."/".$fileId."iso19139_validate_tmp.xml","w")){
-			if(!fwrite($h,$iso19139Xml)){
-				$e = new mb_exception("mod_layerISOMetadata: cannot write to file: ".TMPDIR."iso19139_validate_tmp.xml");
-			}
-		fclose($h);
-		}
-		//send file as post like described under http://www.tecbrat.com/?itemid=13&catid=1
-		$fields['dataFile']='@'.TMPDIR.'/'.$fileId.'iso19139_validate_tmp.xml';
-		#if we give a string with parameters
-		#foreach($fields as $key=>$value) { $fields_string .= $key.'='.$value.'&'; } 
-		#rtrim($fields_string,'&');
-		#$postData = $fields_string;
-		$postData = $fields;
-		#$e = new mb_exception("mod_layerISOMetadata: postData: ".$postData['dataFile']);
-		//number of post fields:
-		//curl_setopt($ch,CURLOPT_POST,count($fields));
-		$validatorInterfaceObject->set('httpPostFieldsNumber',count($postData));
-		$validatorInterfaceObject->set('curlSendCustomHeaders',false);
-		//$validatorInterfaceObject->set('httpPostData', $postData);
-		$validatorInterfaceObject->set('httpPostData', $postData); #give an array
-		$validatorInterfaceObject->load($validatorUrl);
-		header("Content-type: text/html; charset=UTF-8");
-		echo $validatorInterfaceObject->file;
-		//delete file in tmp 
-		//TODO - this normally done by a cronjob
-		die();
-	}
-
 function getEpsgByLayerId ($layer_id) { // from merge_layer.php
 	$epsg_list = "";
 	$sql = "SELECT DISTINCT epsg FROM layer_epsg WHERE fkey_layer_id = $1";

Modified: trunk/mapbender/http/php/mod_layerISOMetadata.php
===================================================================
--- trunk/mapbender/http/php/mod_layerISOMetadata.php	2013-04-09 10:32:08 UTC (rev 8595)
+++ trunk/mapbender/http/php/mod_layerISOMetadata.php	2013-04-10 11:16:12 UTC (rev 8596)
@@ -23,6 +23,7 @@
 require_once(dirname(__FILE__) . "/../../core/globalSettings.php");
 require_once(dirname(__FILE__) . "/../classes/class_connector.php");
 require_once(dirname(__FILE__) . "/../classes/class_administration.php");
+require_once(dirname(__FILE__) . "/../php/mod_validateInspire.php");
 
 $con = db_connect(DBSERVER,OWNER,PW);
 db_select_db(DB,$con);
@@ -929,51 +930,6 @@
 		die();
 	}
 
-	//function to validate against the inspire validation service
-	function validateInspireMetadata($iso19139Doc, $recordId){
-		$validatorUrl = 'http://inspire-geoportal.ec.europa.eu/INSPIREValidatorService/resources/validation/inspire';
-		//$validatorUrl2 = 'http://localhost/mapbender/x_geoportal/log_requests.php';
-		//send inspire xml to validator and push the result to requesting user
-		$validatorInterfaceObject = new connector();
-		$validatorInterfaceObject->set('httpType','POST');
-		//$validatorInterfaceObject->set('httpContentType','application/xml');
-		$validatorInterfaceObject->set('httpContentType','multipart/form-data'); // maybe given automatically
-		$xml = fillISO19139($iso19139Doc, $recordId);
-		//first test with data from ram - doesn't function 
-		$fields = array(
-			'dataFile'=>urlencode($xml)
-			);
-		//generate file identifier:
-		$fileId = guid();
-		//generate temporary file under tmp
-		 if($h = fopen(TMPDIR."/".$fileId."iso19139_validate_tmp.xml","w")){
-			if(!fwrite($h,$xml)){
-				$e = new mb_exception("mod_layerISOMetadata: cannot write to file: ".TMPDIR."iso19139_validate_tmp.xml");
-			}
-		fclose($h);
-		}
-		//send file as post like described under http://www.tecbrat.com/?itemid=13&catid=1
-		$fields['dataFile']='@'.TMPDIR.'/'.$fileId.'iso19139_validate_tmp.xml';
-		//if we give a string with parameters
-		//foreach($fields as $key=>$value) { $fields_string .= $key.'='.$value.'&'; } 
-		//rtrim($fields_string,'&');
-		//$postData = $fields_string;
-		$postData = $fields;
-		//$e = new mb_exception("mod_layerISOMetadata: postData: ".$postData['dataFile']);
-		//number of post fields:
-		//curl_setopt($ch,CURLOPT_POST,count($fields));
-		$validatorInterfaceObject->set('httpPostFieldsNumber',count($postData));
-		$validatorInterfaceObject->set('curlSendCustomHeaders',false);
-		//$validatorInterfaceObject->set('httpPostData', $postData);
-		$validatorInterfaceObject->set('httpPostData', $postData); //give an array
-		$validatorInterfaceObject->load($validatorUrl);
-		header("Content-type: text/html; charset=UTF-8");
-		echo $validatorInterfaceObject->file;
-		//delete file in tmp 
-		//TODO - this normally done by a cronjob
-		die();
-	}
-
 function getEpsgByLayerId ($layer_id) { // from merge_layer.php
 	$epsg_list = "";
 	$sql = "SELECT DISTINCT epsg FROM layer_epsg WHERE fkey_layer_id = $1";
@@ -1018,10 +974,10 @@
     }
 }
 
-
 //do all the other things which had to be done ;-)
 if ($_REQUEST['VALIDATE'] == "true"){
-	validateInspireMetadata($iso19139Doc, $recordId);
+	$xml = fillISO19139($iso19139Doc, $recordId);
+	validateInspire($xml);
 } else {
 	pushISO19139($iso19139Doc, $recordId); //throw it out to world!
 }

Added: trunk/mapbender/http/php/mod_validateInspire.php
===================================================================
--- trunk/mapbender/http/php/mod_validateInspire.php	                        (rev 0)
+++ trunk/mapbender/http/php/mod_validateInspire.php	2013-04-10 11:16:12 UTC (rev 8596)
@@ -0,0 +1,69 @@
+<?php
+//function to validate an resource against the inspire vaildator
+// Copyright (C) 2002 CCGIS 
+//
+// This program is free software; you can redistribute it and/or modify
+// it under the terms of the GNU General Public License as published by
+// the Free Software Foundation; either version 2, or (at your option)
+// any later version.
+//
+// This program is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+// GNU General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with this program; if not, write to the Free Software
+// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+//TODO - make a class of it - with url, and return mimetype as attributes
+require_once(dirname(__FILE__) . "/../../core/globalSettings.php");
+
+function validateInspire($xml) {
+	//$validatorUrl = 'http://localhost/mapbender_trunk/geoportal/log_requests.php';
+	//$validatorUrl = 'http://inspire-geoportal.ec.europa.eu/GeoportalProxyWebServices/resources/INSPIREResourceTester';
+	if (defined("INSPIRE_VALIDATOR_URL") && INSPIRE_VALIDATOR_URL != '') {
+		$validatorUrl = INSPIRE_VALIDATOR_URL;
+	} else {
+		echo "No validation service defined! Please check your mapbender.conf";
+		die();
+	}
+	$eol = "\r\n";
+	$data = '';
+	$mime_boundary=md5(time());
+	$data .= '--' . $mime_boundary . $eol;
+	$data .= 'Content-Disposition: form-data; name="resourceRepresentation"' .$eol.$eol;
+	//example
+	//$data .= "http://map1.naturschutz.rlp.de/service_lanis/mod_wms/wms_getmap.php?mapfile=naturschutzgebiet&REQUEST=GetCapabilities&VERSION=1.1.1&SERVICE=WMS";
+	$data .= $xml;
+	$data .= $eol;
+	$data .= '--' . $mime_boundary . $eol;
+	$data .= $eol; // finish with two eol's!!
+	$header = "";
+	$header .= 'Content-Type: multipart/form-data; boundary='.$mime_boundary.$eol;
+	$header .= 'Content-Length: '.strlen($data).$eol;
+	//$data = http_build_query($data);
+	//check proxy connections
+	if (defined("CONNECTION_PROXY") &&  CONNECTION_PROXY != "") {
+		$context_options = array (
+        			'http' => array (
+					'proxy' => "http://".CONNECTION_PROXY.":".CONNECTION_PORT,
+            				'method' => 'POST',
+            				'header' => $header,
+            				'content' => $data
+            				)
+        			);
+	} else {
+		$context_options = array (
+        			'http' => array (
+            				'method' => 'POST',
+            				'header' => $header,
+            				'content' => $data
+            				)
+        			);
+	}
+	$context = stream_context_create($context_options);
+	$response = @file_get_contents($validatorUrl, FILE_TEXT, $context);
+	header("Content-type: text/html; charset=UTF-8");
+	echo $response;
+}
+?>



More information about the Mapbender_commits mailing list