[Mapbender-commits] r9818 - trunk/mapbender/http/php

svn_mapbender at osgeo.org svn_mapbender at osgeo.org
Mon Nov 20 05:20:57 PST 2017


Author: armin11
Date: 2017-11-20 05:20:57 -0800 (Mon, 20 Nov 2017)
New Revision: 9818

Modified:
   trunk/mapbender/http/php/wms.php
Log:
Fixes for AuthorityURL / Identifier handling of wms proxy for INSPIRE

Modified: trunk/mapbender/http/php/wms.php
===================================================================
--- trunk/mapbender/http/php/wms.php	2017-11-16 16:26:38 UTC (rev 9817)
+++ trunk/mapbender/http/php/wms.php	2017-11-20 13:20:57 UTC (rev 9818)
@@ -158,20 +158,52 @@
 	echo createExceptionXml("Layer not defined", "Unknown layer id " . $layerId);
 	die;
 }
+$AuthorityName = "defaultauthority";
+/*$metadata_codespace_sql = "SELECT metadata_id, datasetid, datasetid_codespace FROM mb_metadata WHERE metadata_id in (SELECT fkey_metadata_id FROM layer INNER JOIN ows_relation_metadata ON layer.layer_id = ows_relation_metadata.fkey_layer_id WHERE fkey_wms_id = $1)";
+$v = array($wms_row["wms_id"]);
+$t = array("i");
+$res_metadata_codespace_sql = db_prep_query($metadata_codespace_sql, $v, $t);
 
+$metadataNameSpaceArray = array();
+while ($row_metadata_codespace_sql = db_fetch_array($res_metadata_codespace_sql)) {
+    if (isset($row_metadata_codespace_sql['datasetid_codespace']) && $row_metadata_codespace_sql['datasetid_codespace'] !== '') {
+        $metadataNameSpaceArray[] = $row_metadata_codespace_sql['datasetid_codespace'];
+    }
+}
+$metadataNameSpaceArray = array_unique($metadataNameSpaceArray);
+*/
+
+//TODO: select all coupled metadata from table and make the namespace unique - one entry for each different namespace - AuthorityName will be name, name_1, name_2, name_3 for each found namespace !!!!!
+
 //infos about the registrating department, check first if a special metadata point of contact is defined in the service table
-$metadataContactGroup = $admin->getOrgaInfoFromRegistry("wms", $wms_row["wms_id"], $wms_row["wms_owner"]);
+/*$metadataContactGroup = $admin->getOrgaInfoFromRegistry("wms", $wms_row["wms_id"], $wms_row["wms_owner"]);
 
 $AuthorityName = $metadataContactGroup["mb_group_name"];
+
 //TODO: Problem - there is no single codespace if datasets have different ones !!!! - Find a generic solution  
 //$uniqueResourceIdentifierCodespace = $admin->getIdentifierCodespaceFromRegistry($departmentMetadata, $row_metadata);
+
 $metadataArray['datasetid_codespace'] = "";
-$AuthorityUrl = $admin->getIdentifierCodespaceFromRegistry($metadataContactGroup, $metadataArray);
 
-if ($AuthorityName == '') {
+$AuthorityUrlArray = array();
+$AuthorityNameArray = array();
+$countMetadataNameSpaceArray = 0;
+
+foreach ($metadataNameSpaceArray as $metadataNameSpace) {
+    $metadataArray['datasetid_codespace'] = $metadataNameSpace;
+    $AuthorityUrlArray[] = $admin->getIdentifierCodespaceFromRegistry($metadataContactGroup, $metadataArray);
+    if ($AuthorityName == '') {
 	$AuthorityName = "defaultauthority";
+    }
+    if ($countMetadataNameSpaceArray > 0) {
+	$AuthorityNameArray[] = $AuthorityName."_".$countMetadataNameSpaceArray;
+    } else {
+        $AuthorityNameArray[] = $AuthorityName;
+    }
+    $countMetadataNameSpaceArray++;
 }
 
+*/
 //Get Geometry Type if featuretype info was requested
 if ($resource == 'featuretype') {
 	$getTypeSql = "SELECT element_id, element_type from wfs_element WHERE fkey_featuretype_id = $1 AND element_type LIKE '%PropertyType';";
@@ -182,7 +214,7 @@
 	$resourceMetadata['featuretype_geomType'] = $featuretypeElements['element_type'];
 }
 
-$e = new mb_notice("mod_showMetadata: mb_group_name: ".$metadataContactGroup['mb_group_name']);
+//$e = new mb_notice("mod_showMetadata: mb_group_name: ".$metadataContactGroup['mb_group_name']);
 //
 // check if update sequence is valid
 //
@@ -851,13 +883,7 @@
 	}
 }
 
-//
-//
-//
-
-
-
-#SQL statement to get additional layer information from layer epsg	
+//SQL statement to get additional layer information from layer epsg	
 $epsg_sql = "SELECT layer_epsg.epsg, layer_epsg.minx, layer_epsg.miny, " . 
 	"layer_epsg.maxy, layer_epsg.maxx " . 
 	"FROM layer_epsg WHERE layer_epsg.fkey_layer_id = $1";
@@ -942,14 +968,18 @@
 
 //Create AuthorityUrl Node on root layer level
 //<AuthorityURL name="gcmd"><OnlineResource xlink:href="some_url" ... /></AuthorityURL>
-$AuthorityURL = $doc->createElement("AuthorityURL");
-$AuthorityURL = $layer->appendChild($AuthorityURL);
-$AuthorityURL->setAttribute('name', $AuthorityName);
-$AUOnlineResource = $doc->createElement("OnlineResource");
-$AUOnlineResource->setAttribute("xmlns:xlink", "http://www.w3.org/1999/xlink" );
-$AUOnlineResource->setAttribute("xlink:type", "simple");
-$AUOnlineResource->setAttribute("xlink:href", $AuthorityUrl);
-$AUOnlineResource = $AuthorityURL->appendChild($AUOnlineResource);
+//$indexAuthorityUrl = 0;
+/*foreach ($AuthorityUrlArray as $AuthorityUrl) {
+    $AuthorityURL = $doc->createElement("AuthorityURL");
+    $AuthorityURL = $layer->appendChild($AuthorityURL);
+    $AuthorityURL->setAttribute('name', $AuthorityNameArray[$indexAuthorityUrl]);
+    $AUOnlineResource = $doc->createElement("OnlineResource");
+    $AUOnlineResource->setAttribute("xmlns:xlink", "http://www.w3.org/1999/xlink" );
+    $AUOnlineResource->setAttribute("xlink:type", "simple");
+    $AUOnlineResource->setAttribute("xlink:href", $AuthorityUrl);
+    $AUOnlineResource = $AuthorityURL->appendChild($AUOnlineResource);
+    $indexAuthorityUrl++;
+}*/
 
 //fictive root layer created
 
@@ -970,6 +1000,7 @@
 
 //*************************************************
 function createLayerElement ($doc, $wmsId, $layerRow, $wmsRow, $AuthorityName, $mapbenderMetadataUrlUrl) {
+	$admin = new Administration();
 	#Creating single layer node
 	$layer = $doc->createElement("Layer");
     	if($layerRow['layer_queryable'] <> "" AND $layerRow['layer_queryable'] <> NULL) {
@@ -1141,13 +1172,26 @@
 		$boundingBox->setAttribute('maxx', $bbox['maxx']);
 		$boundingBox->setAttribute('maxy', $bbox['maxy']);
 	}
+	//switch wms version
+	$e = new mb_exception($wmsRow['wms_version']);
+	switch ($wmsRow['wms_version']) {
+		case "1.1.1":
+			$metadataUrlType = "TC211";
+			break;
+		case "1.3.0":
+			$metadataUrlType = "ISO19115:2003";
+			break;
+		default :
+			$metadataUrlType = "TC211";
+			break;	
+	}
 	//
 	//Creating Metadata and Identifier nodes
 	//read out all metadata entries for specific layer
 	$subLayerId = $layerRow['layer_id'];
 	$sql = <<<SQL
 
-SELECT metadata_id, uuid, link, linktype, md_format, origin, datasetid, md_proxy FROM mb_metadata 
+SELECT metadata_id, uuid, link, linktype, md_format, origin, datasetid, datasetid_codespace, md_proxy FROM mb_metadata 
 INNER JOIN (SELECT * from ows_relation_metadata 
 WHERE fkey_layer_id = $subLayerId ) as relation ON 
 mb_metadata.metadata_id = relation.fkey_metadata_id WHERE mb_metadata.origin IN ('capabilities','external','metador','upload')
@@ -1156,39 +1200,35 @@
 	//$e = new mb_exception("wms.php: layerid: ".$layerRow['layer_id']);
 	$i = 0;
 	$res_metadata = db_query($sql);
+	$namespaceArray = array();
+	$AuthorityURLArray = array();
+	$IdentifierArray = array();
+	$metadataURLArray = array();
 	while ($row_metadata = db_fetch_array($res_metadata)) {
+		$respOrga = $admin->getOrgaInfoFromRegistry('metadata', $row_metadata['metadata_id'], $wmsRow['wms_owner']);
+		$metadataArray['datasetid_codespace'] = $row_metadata["datasetid_codespace"];
+		$namespace = $admin->getIdentifierCodespaceFromRegistry($respOrga, $metadataArray);	
+		$namespaceArray[] = $namespace;
 		//check id datasetid is set, if not use metadataid
 		if ($row_metadata["datasetid"] == '' || !isset($row_metadata["datasetid"])) {
-			//this column is empty, if metador was used and the identifier for dataset id is equal to the identifier of the metadata fileidentifier. In this case we expand a standard codespace http://www.geoportal.rlp.de 
-			if (defined('METADATA_DEFAULT_CODESPACE')) {
-				//$datasetId = METADATA_DEFAULT_CODESPACE."#".$row_metadata["uuid"];
-				$datasetId = $row_metadata["uuid"];
-			} else {
-				if (defined("METADATA_DEFAULT_CODESPACE") && METADATA_DEFAULT_CODESPACE != '') {
-					//$datasetId = METADATA_DEFAULT_CODESPACE."#".$row_metadata["uuid"];
-					$datasetId = $row_metadata["uuid"];
-				} else {
-					//$datasetId = "http://www.mapbender.org"."#".$row_metadata["uuid"];
-					$datasetId = $row_metadata["uuid"];
-				}
-			}
+			$datasetId = $row_metadata["uuid"];
 		} else {
 			$datasetId = $row_metadata["datasetid"]; //really datasetid or only second part?
 		}
 		//create Identifier tags
 		$Identifier = $doc->createElement("Identifier");
-		$Identifier->setAttribute('authority', $AuthorityName);
-		//$Identifier->setAttribute('mist', $AuthorityName);
-		$Identifier = $layer->appendChild($Identifier);
+		$Identifier->setAttribute('authority', md5($namespace));
+		//$Identifier = $layer->appendChild($Identifier);
 		$IdentifierText = $doc->createTextNode($datasetId);
     		$IdentifierText = $Identifier->appendChild($IdentifierText);
+		$IdentifierArray[] = $Identifier;
 		//$e = new mb_exception("i: ".$i);
 		//push entries into xml structure	
 		//check for kind of link - push the right one into the link field	
 		switch ($row_metadata['origin']) {
 			case 'capabilities':
 				$metadataUrl = $doc->createElement("MetadataURL");
-				$metadataUrl = $layer->appendChild($metadataUrl);
+				//$metadataUrl = $layer->appendChild($metadataUrl);
 				$metadataUrl->setAttribute('type', $row_metadata['linktype']);
 				$format = $doc->createElement("Format");
     				$format = $metadataUrl->appendChild($format);
@@ -1206,8 +1246,8 @@
 			break;
 			case 'external':
 				$metadataUrl = $doc->createElement("MetadataURL");
-				$metadataUrl = $layer->appendChild($metadataUrl);
-				$metadataUrl->setAttribute('type', 'ISO19115:2003');
+				//$metadataUrl = $layer->appendChild($metadataUrl);
+				$metadataUrl->setAttribute('type', $metadataUrlType);
 				$format = $doc->createElement("Format");
     				$format = $metadataUrl->appendChild($format);
     				$formatText = $doc->createTextNode("text/xml");
@@ -1224,8 +1264,8 @@
 			break;
 			case 'upload':
 				$metadataUrl = $doc->createElement("MetadataURL");
-				$metadataUrl = $layer->appendChild($metadataUrl);
-				$metadataUrl->setAttribute('type', 'ISO19115:2003');
+				//$metadataUrl = $layer->appendChild($metadataUrl);
+				$metadataUrl->setAttribute('type', $metadataUrlType);
 				$format = $doc->createElement("Format");
     				$format = $metadataUrl->appendChild($format);
     				$formatText = $doc->createTextNode("text/xml");
@@ -1238,8 +1278,8 @@
 			break;
 			case 'metador':
 				$metadataUrl = $doc->createElement("MetadataURL");
-				$metadataUrl = $layer->appendChild($metadataUrl);
-				$metadataUrl->setAttribute('type', 'ISO19115:2003');
+				//$metadataUrl = $layer->appendChild($metadataUrl);
+				$metadataUrl->setAttribute('type', $metadataUrlType);
 				$format = $doc->createElement("Format");
     				$format = $metadataUrl->appendChild($format);
     				$formatText = $doc->createTextNode("text/xml");
@@ -1252,8 +1292,8 @@
 			break;
 			default:
 				$metadataUrl = $doc->createElement("MetadataURL");
-				$metadataUrl = $layer->appendChild($metadataUrl);
-				$metadataUrl->setAttribute('type', 'ISO19115:2003');
+				//$metadataUrl = $layer->appendChild($metadataUrl);
+				$metadataUrl->setAttribute('type', $metadataUrlType);
 				$format = $doc->createElement("Format");
     				$format = $metadataUrl->appendChild($format);
     				$formatText = $doc->createTextNode("text/xml");
@@ -1267,9 +1307,32 @@
 
 		}
 		$onlineResource->setAttribute("xlink:type", "simple");
+		$metadataURLArray[] = $metadataUrl;
 		//Add linkage to Capabilities
 		$i++;
 	}
+	$namespaceUnique = array_unique($namespaceArray);
+	foreach ($namespaceUnique as $namespace) {
+    		$AuthorityURL = $doc->createElement("AuthorityURL");
+    		//$AuthorityURL = $layer->appendChild($AuthorityURL);
+    		$AuthorityURL->setAttribute('name', md5($namespace));
+    		$AUOnlineResource = $doc->createElement("OnlineResource");
+    		$AUOnlineResource->setAttribute("xmlns:xlink", "http://www.w3.org/1999/xlink" );
+    		$AUOnlineResource->setAttribute("xlink:type", "simple");
+    		$AUOnlineResource->setAttribute("xlink:href", $namespace.$datasetId);
+    		$AUOnlineResource = $AuthorityURL->appendChild($AUOnlineResource);
+		$AuthorityURLArray[] = $AuthorityURL;
+	}
+
+	foreach ($AuthorityURLArray as $AuthorityURL) {
+			$AuthorityURL = $layer->appendChild($AuthorityURL);
+	}
+	foreach ($IdentifierArray as $Identifier) {
+			$Identifier = $layer->appendChild($Identifier);
+	}
+	foreach ($metadataURLArray as $metadataURL) {
+			$metadataURL = $layer->appendChild($metadataURL);
+	}
 	#Creating DataURL Node - use it from database if it will exist!	
 	$dataUrl = $doc->createElement("DataURL");
 	$dataUrl = $layer->appendChild($dataUrl);



More information about the Mapbender_commits mailing list