[Mapbender-commits] r9815 - in trunk/mapbender/http: classes php

svn_mapbender at osgeo.org svn_mapbender at osgeo.org
Tue Nov 14 07:46:40 PST 2017


Author: armin11
Date: 2017-11-14 07:46:40 -0800 (Tue, 14 Nov 2017)
New Revision: 9815

Modified:
   trunk/mapbender/http/classes/class_owsMetadataUrl.php
   trunk/mapbender/http/php/mod_inspireAtomFeedISOMetadata.php
   trunk/mapbender/http/php/wfs.php
Log:
Enhancement of handling of unique resource identifier for inspire

Modified: trunk/mapbender/http/classes/class_owsMetadataUrl.php
===================================================================
--- trunk/mapbender/http/classes/class_owsMetadataUrl.php	2017-11-14 15:43:06 UTC (rev 9814)
+++ trunk/mapbender/http/classes/class_owsMetadataUrl.php	2017-11-14 15:46:40 UTC (rev 9815)
@@ -150,6 +150,7 @@
 		//add one entry foreach found element
 		$i = 0;
 		foreach ($this->urlArray as $url) {
+			//$e = new mb_exception($url);
 			//TODO: For wms:
 			//$xpathMetadataUrl->query('/mb:metadataurl/MetadataURL')->item(0)->setAttribute("type", $this->typeArray[$i]);
 			//$xpathMetadataUrl->query('/mb:metadataurl/MetadataURL/Format')->item(0)->nodeValue = $this->formatArray[$i];
@@ -161,27 +162,38 @@
 						case "1.1.0":
 							$xpathMetadataUrl->query('/mb:metadataurl/MetadataURL')->item(0)->setAttribute("type", $this->typeArray[$i]);
 							$xpathMetadataUrl->query('/mb:metadataurl/MetadataURL')->item(0)->setAttribute("format", $this->formatArray[$i]);
-							$xpathMetadataUrl->query('/mb:metadataurl/MetadataURL')->item(0)->setValue = $this->urlArray[$i];
+							$textNode = $metadataUrlDomObject->createTextNode($this->urlArray[$i]);
+							$xpathMetadataUrl->query('/mb:metadataurl/MetadataURL')->item(0)->nodeValue = "";
+							$xpathMetadataUrl->query('/mb:metadataurl/MetadataURL')->item(0)->appendChild($textNode);
+
+
+//$e = new mb_exception("class_owsMetadataUrl: 1.1.0: value: ".$this->urlArray[$i]);
+
 							break;
 						case "1.0.0":
 							$xpathMetadataUrl->query('/mb:metadataurl/MetadataURL')->item(0)->setAttribute("type", $this->typeArray[$i]);
 							$xpathMetadataUrl->query('/mb:metadataurl/MetadataURL')->item(0)->setAttribute("format", $this->formatArray[$i]);
-							$xpathMetadataUrl->query('/mb:metadataurl/MetadataURL')->item(0)->setValue = $this->urlArray[$i];
+							$textNode = $metadataUrlDomObject->createTextNode($this->urlArray[$i]);
+							$xpathMetadataUrl->query('/mb:metadataurl/MetadataURL')->item(0)->nodeValue = "";
+							$xpathMetadataUrl->query('/mb:metadataurl/MetadataURL')->item(0)->appendChild($textNode);
 							break;
 						case "2.0.0":			
 							$xpathMetadataUrl->query('/mb:metadataurl/MetadataURL')->item(0)->setAttribute("xmlns:xlink", "http://www.w3.org/1999/xlink");
-							$xpathMetadataUrl->query('/mb:metadataurl/MetadataURL')->item(0)->setAttribute("xlink:href", $url);
+							$xpathMetadataUrl->query('/mb:metadataurl/MetadataURL')->item(0)->setAttribute("xlink:href", $this->urlArray[$i]);
 							break;
 						case "2.0.2":
 							$xpathMetadataUrl->query('/mb:metadataurl/MetadataURL')->item(0)->setAttribute("xmlns:xlink", "http://www.w3.org/1999/xlink");
-							$xpathMetadataUrl->query('/mb:metadataurl/MetadataURL')->item(0)->setAttribute("xlink:href", $url);
+							$xpathMetadataUrl->query('/mb:metadataurl/MetadataURL')->item(0)->setAttribute("xlink:href", $this->urlArray[$i]);
 							break;
 					}
 					break;
 				case 'wms':
 					$xpathMetadataUrl->query('/mb:metadataurl/MetadataURL')->item(0)->setAttribute("type", $this->typeArray[$i]);
-					$xpathMetadataUrl->query('/mb:metadataurl/MetadataURL/Format')->item(0)->setValue = $this->formatArray[$i];
-					$xpathMetadataUrl->query('/mb:metadataurl/MetadataURL/OnlineResource')->item(0)->setAttribute("xlink:href", $url);
+					$textNode = $metadataUrlDomObject->createTextNode($this->formatArray[$i]);
+					$xpathMetadataUrl->query('/mb:metadataurl/MetadataURL/Format')->item(0)->nodeValue = "";
+					$xpathMetadataUrl->query('/mb:metadataurl/MetadataURL/Format')->item(0)->nodeValue->appendChild($textNode);
+
+					$xpathMetadataUrl->query('/mb:metadataurl/MetadataURL/OnlineResource')->item(0)->setAttribute("xlink:href", $this->urlArray[$i]);
 					break;
 			}
 			//clone node and add if afterwards

Modified: trunk/mapbender/http/php/mod_inspireAtomFeedISOMetadata.php
===================================================================
--- trunk/mapbender/http/php/mod_inspireAtomFeedISOMetadata.php	2017-11-14 15:43:06 UTC (rev 9814)
+++ trunk/mapbender/http/php/mod_inspireAtomFeedISOMetadata.php	2017-11-14 15:46:40 UTC (rev 9815)
@@ -180,7 +180,7 @@
 		//check if entries are filled
 		//read information from metadata table
 		$sql = <<<SQL
-			select mb_metadata.title, mb_metadata.abstract, mb_metadata.ref_system, mb_metadata.datasetid, mb_metadata.origin from mb_metadata where mb_metadata.uuid = $1;
+			select mb_metadata.title, mb_metadata.abstract, mb_metadata.ref_system, mb_metadata.datasetid, mb_metadata.datasetid_codespace, mb_metadata.origin from mb_metadata where mb_metadata.uuid = $1;
 SQL;
 		$v = array($recordId);
 		$t = array('s');
@@ -260,6 +260,7 @@
 		$mapbenderMetadata['datasetId'] = $mbMetadata['datasetid'];
 		$mapbenderMetadata['mdOrigin'] = $mbMetadata['origin'];
 		$mapbenderMetadata['serviceUuid'] = $mbMetadata['uuid'];
+		$mapbenderMetadata['metadataId'] = $mbMetadata['metadata_id'];
 		$mapbenderMetadata['serviceTimestamp'] = strtotime($mbMetadata['wms_timestamp']);
 		$mapbenderMetadata['serviceTimestampCreate'] = strtotime($mbMetadata['wms_timestamp_create']);
 		//$mapbenderMetadata['serviceTimestamp'] = date("Y-m-d",strtotime($mb_metadata['lastchanged']));
@@ -267,7 +268,7 @@
 		//$mapbenderMetadata['serviceTimestampCreate'] = date("Y-m-d",strtotime($mb_metadata['lastchanged']));
 		$mapbenderMetadata['serviceDepartment'] = $mbMetadata['responsible_party'];
 		$mapbenderMetadata['serviceDepartmentMail'] = "kontakt at geoportal.rlp.de";
-		//$mapbenderMetadata['serviceGroupId'] = $mbMetadata['fkey_mb_group_id'];
+		$mapbenderMetadata['serviceGroupId'] = $mbMetadata['fkey_mb_group_id'];
 		$mapbenderMetadata['serviceOwnerId'] = $mbMetadata['fkey_mb_user_id'];
 		//TODO!
 		$mapbenderMetadata['serviceAccessConstraints'] = "Please ask the contact point!";
@@ -326,7 +327,7 @@
 		//check if entries are filled
 		//read information from metadata table
 		$sql = <<<SQL
-			select mb_metadata.title, mb_metadata.abstract, mb_metadata.ref_system, mb_metadata.datasetid, mb_metadata.origin from mb_metadata where mb_metadata.uuid = $1;
+			select mb_metadata.title, mb_metadata.abstract, mb_metadata.ref_system, mb_metadata.datasetid_codespace , mb_metadata.datasetid, mb_metadata.origin from mb_metadata where mb_metadata.uuid = $1;
 SQL;
 		$v = array($recordId);
 		$t = array('s');
@@ -406,7 +407,7 @@
 		//check if entries are filled
 		//read information from metadata table
 		$sql = <<<SQL
-			select mb_metadata.title, mb_metadata.abstract, mb_metadata.ref_system, mb_metadata.datasetid, mb_metadata.origin from mb_metadata where mb_metadata.uuid = $1;
+			select mb_metadata.title, mb_metadata.abstract, mb_metadata.ref_system, mb_metadata.datasetid, mb_metadata.datasetid_codespace, mb_metadata.origin from mb_metadata where mb_metadata.uuid = $1;
 SQL;
 		$v = array($recordId);
 		$t = array('s');
@@ -467,8 +468,36 @@
 		break;
 	}
 	
+	//infos about the registrating department, check first if a special metadata point of contact is defined in the service table
+        switch ($generateFrom) {
+		case "wmslayer":
+			$type = "wms";
+			$serviceId = $mapbenderMetadata['serviceId'];
+			$ownerId =$mapbenderMetadata['serviceOwnerId'];
+			break;
+		case "wfs":
+			$type = "wfs";
+			$serviceId = $mapbenderMetadata['serviceId'];
+			$ownerId =$mapbenderMetadata['serviceOwnerId'];
+			break;
+		case "dataurl":
+			$type = "wms";
+			$serviceId = $mapbenderMetadata['serviceId'];
+			$ownerId =$mapbenderMetadata['serviceOwnerId'];
+			break;
+		case "metadata":
+			$type = "metadata";
+			$serviceId = $mapbenderMetadata['metadataId'];
+			$ownerId =$mapbenderMetadata['serviceOwnerId'];
+			break;
+
+	}
+	$departmentMetadata = $admin->getOrgaInfoFromRegistry($type, $serviceId, $ownerId);
+	$userMetadata['mb_user_email'] = $departmentMetadata['mb_user_email'];
+
+
 	//infos about the registrating department, check first if a special metadata point of contact is defined in the service table - function from mod_showMetadata - TODO: should be defined in admin class
-	if (!isset($mapbenderMetadata['serviceGroupId']) or is_null($mapbenderMetadata['serviceGroupId']) or $mapbenderMetadata['serviceGroupId'] == 0){
+	/*if (!isset($mapbenderMetadata['serviceGroupId']) or is_null($mapbenderMetadata['serviceGroupId']) or $mapbenderMetadata['serviceGroupId'] == 0){
 		$e = new mb_exception("mod_inspireAtomFeedISOMetadata.php: fkey_mb_group_id not found!");
 		//Get information about owning user of the relation mb_user_mb_group - alternatively the defined fkey_mb_group_id from the service must be used!
 		$sqlDep = "SELECT mb_group_name, mb_group_title, mb_group_id, mb_group_logo_path, mb_group_address, mb_group_email, mb_group_postcode, mb_group_city, mb_group_voicetelephone, mb_group_facsimiletelephone FROM mb_group AS a, mb_user AS b, mb_user_mb_group AS c WHERE b.mb_user_id = $1  AND b.mb_user_id = c.fkey_mb_user_id AND c.fkey_mb_group_id = a.mb_group_id AND c.mb_user_mb_group_type=2 LIMIT 1";
@@ -492,7 +521,7 @@
 	$t = array('i');
 	$res = db_prep_query($sql,$v,$t);
 	$userMetadata = db_fetch_array($res);
-
+*/
 	//check if resource is freely available to anonymous user - which are all users who search thru metadata catalogues:
 	//$hasPermission=$admin->getLayerPermission($mapbenderMetadata['serviceId'],$mapbenderMetadata['layer_name'],PUBLIC_USER);
 	$hasPermission = true;//Is always true for ATOM Service Feeds!
@@ -947,7 +976,7 @@
 	//Resource Constraints B 8
 	//do a right mapping for fees and accessconstraints to inspire MD Constraints!
 	$resourceConstraints=$iso19139->createElement("gmd:resourceConstraints");
-	$MD_LegalConstraints=$iso19139->createElement("gmd:MD_Constraints");
+	$MD_LegalConstraints=$iso19139->createElement("gmd:MD_LegalConstraints");
 	$useLimitation=$iso19139->createElement("gmd:useLimitation");
 	$useLimitation_cs=$iso19139->createElement("gco:CharacterString");
 	
@@ -1167,29 +1196,25 @@
 		//$mapbenderMetadata['mdRefSystem'] = $mbMetadata['ref_sytem'];
 		//$mapbenderMetadata['datasetId'] = $mbMetadata['datasetid'];
 		//$mapbenderMetadata['mdOrigin'] = $mbMetadata['origin'];
+	$uniqueResourceIdentifierCodespace = $admin->getIdentifierCodespaceFromRegistry($departmentMetadata, $mbMetadata);
+
 	switch ($mapbenderMetadata['mdOrigin']) {
 		case 'capabilities':
 			$operatesOn=$iso19139->createElement("srv:operatesOn");
 			$operatesOn->setAttribute("xlink:href", $mapbenderPath."php/mod_dataISOMetadata.php?outputFormat=iso19139&id=".$recordId);
-			$operatesOn->setAttribute("uuidref", $mapbenderMetadata['datasetId']);
+			$operatesOn->setAttribute("uuidref", $uniqueResourceIdentifierCodespace.$mapbenderMetadata['datasetId']);
 			$SV_ServiceIdentification->appendChild($operatesOn);
 		break;
 		case 'metador':
 			$operatesOn=$iso19139->createElement("srv:operatesOn");
-			if (defined('METADATA_DEFAULT_CODESPACE')) {
-				$operatesOn->setAttribute("xlink:href", $mapbenderPath."php/mod_dataISOMetadata.php?outputFormat=iso19139&id=".$recordId);
-				$operatesOn->setAttribute("uuidref", METADATA_DEFAULT_CODESPACE."#".$recordId);
-			} else {
-				$operatesOn->setAttribute("xlink:href", $mapbenderPath."php/mod_dataISOMetadata.php?outputFormat=iso19139&id=".$recordId);
-				$operatesOn->setAttribute("uuidref", "http://www.mapbender.org#".$recordId);
-			}
-					
+			$operatesOn->setAttribute("xlink:href", $mapbenderPath."php/mod_dataISOMetadata.php?outputFormat=iso19139&id=".$recordId.'#spatial_dataset_'.md5($recordId));
+			$operatesOn->setAttribute("uuidref", $uniqueResourceIdentifierCodespace.$recordId);
 			$SV_ServiceIdentification->appendChild($operatesOn);
 		break;
 		case 'external':
 			$operatesOn=$iso19139->createElement("srv:operatesOn");
 			$operatesOn->setAttribute("xlink:href", $mapbenderPath."php/mod_dataISOMetadata.php?outputFormat=iso19139&id=".$recordId);
-			$operatesOn->setAttribute("uuidref", $recordId);
+			$operatesOn->setAttribute("uuidref", $uniqueResourceIdentifierCodespace.$recordId);
 			$SV_ServiceIdentification->appendChild($operatesOn);
 		break;
 		default:

Modified: trunk/mapbender/http/php/wfs.php
===================================================================
--- trunk/mapbender/http/php/wfs.php	2017-11-14 15:43:06 UTC (rev 9814)
+++ trunk/mapbender/http/php/wfs.php	2017-11-14 15:46:40 UTC (rev 9815)
@@ -330,12 +330,15 @@
 	$element->setAttribute("xlink:href", $wfs_row['wfs_getfeature']);
 }
 
+//get wfs id and owner of the wfs from database
+
+
 //Add MetadataUrl entries from mapbender database
 //Creating Metadata nodes
 //read out all metadata entries for specific featuretype
 $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_featuretype_id = $featuretypeId ) as relation ON 
 mb_metadata.metadata_id = relation.fkey_metadata_id WHERE mb_metadata.origin IN ('capabilities','external','metador','upload')
@@ -348,20 +351,17 @@
 $datasetId = array();
 //
 $k = 0;
-while ($row_metadata = db_fetch_array($res_metadata)) {
+//infos about the registrating department, check first if a special metadata point of contact is defined in the service table
+$departmentMetadata = $admin->getOrgaInfoFromRegistry("wfs", $wfs_row["wfs_id"], $wfs_row["wfs_owner"]);
+
+while ($row_metadata = db_fetch_array($res_metadata)) {	
+	$uniqueResourceIdentifierCodespace = $admin->getIdentifierCodespaceFromRegistry($departmentMetadata, $row_metadata);
+	//First generate all dataset ids because they are needed in the inspire extensions
 	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[$k] = METADATA_DEFAULT_CODESPACE."#".$row_metadata["uuid"];
-		} else {
-			if (defined("METADATA_DEFAULT_CODESPACE") && METADATA_DEFAULT_CODESPACE != '') {
-				$datasetId[$k] = METADATA_DEFAULT_CODESPACE."#".$row_metadata["uuid"];
-			} else {
-				$datasetId[$k] = "http://www.mapbender.org"."#".$row_metadata["uuid"];
-			}
-		}
+		//this column is empty, if metador was used and the identifier for dataset id is equal to the identifier of the metadata fileidentifier
+		$datasetId[$k] = $uniqueResourceIdentifierCodespace.$row_metadata["uuid"];
 	} else {
-		$datasetId[$k] = $row_metadata["datasetid"]; //really datasetid or only second part?
+		$datasetId[$k] = $uniqueResourceIdentifierCodespace.$row_metadata["datasetid"];
 	}
 	//push entries into xml structure	
 	//check for kind of link - push the right one into the link field	
@@ -407,10 +407,13 @@
 }
 $k = 0;
 if (is_array($metadataUrl) && count($metadataUrl) > 0) {
+$e = new mb_exception(gettype($metadataUrl)." - count - ".count($metadataUrl)." url[0]: ".$metadataUrl[0]);
+$e = new mb_exception($version);
+$e = new mb_exception($service);
 	$metadataUrlObject = new OwsMetadataUrl();
 	//$e = new mb_exception('version: '.$version);
 	$metadata_part = $metadataUrlObject->getOwsRepresentation($metadataUrl, $linkType, $format, 'wfs', $version);
-	//$e = new mb_exception($metadata_part);
+$e = new mb_exception($metadata_part);
 }
 
 //insert metadata url elements into capabilities - either delete existing entries and recreate them or put them after ows:WGS84BoundingBox (WFS 2.0), wfs .....
@@ -533,23 +536,36 @@
 	*/
 	foreach ($datasetId as $singleDatasetId) {
 		//$e = new mb_exception("datasetid: ".$singleDatasetId);
-		//try to explode with # or / afterwards
-		if (strpos($singleDatasetId, '#') !== false && count(explode('#', $singleDatasetId) == 2) ) {
-			//$e = new mb_exception("found inspire dataset id");
-			//build id part
-			$inspire_dls_SpatialDataSetIdentifier = $doc->createElement("inspire_dls:SpatialDataSetIdentifier");
-			$inspire_common_Code = $doc->createElement("inspire_common:Code");
-			$inspire_common_Namespace = $doc->createElement("inspire_common:Namespace");
-			$inspire_common_CodeText = $doc->createTextNode(explode('#', $singleDatasetId)[1]);
-			$inspire_common_NamespaceText = $doc->createTextNode(explode('#', $singleDatasetId)[0]);
-			$inspire_common_Namespace->appendChild($inspire_common_NamespaceText);
-			$inspire_common_Code->appendChild($inspire_common_CodeText);
-			$inspire_dls_SpatialDataSetIdentifier->appendChild($inspire_common_Code);
-			$inspire_dls_SpatialDataSetIdentifier->appendChild($inspire_common_Namespace);
-			$inspire_dls_ExtendedCapabilities->appendChild($inspire_dls_SpatialDataSetIdentifier);
+		//try to extract local identifier from complete unique resource identifier 
+		//now try to check if a single slash is available and if the md_identifier is a url
+		$parsedUrl = parse_url($singleDatasetId);
+		if (($parsedUrl['scheme'] == 'http' || $parsedUrl['scheme'] == 'https') && strpos($parsedUrl['path'],'/') !== false) {
+			$explodedUrl = explode('/', $singleDatasetId);
+			$codeText = $explodedUrl[count($explodedUrl) - 1];
+			$namespaceText = rtrim($singleDatasetId, $codeText);	
+		} else {
+			//check old way with # as separator
+			if (strpos($singleDatasetId, '#') !== false && count(explode('#', $singleDatasetId) == 2) ) {
+				$codeText = explode('#', $singleDatasetId)[1];
+				$namespaceText = explode('#', $singleDatasetId)[0];
+			} else {
+				$codeText = $singleDatasetId;
+				$namespaceText = "";
+			}
 		}
+		$inspire_dls_SpatialDataSetIdentifier = $doc->createElement("inspire_dls:SpatialDataSetIdentifier");
+		$inspire_common_Code = $doc->createElement("inspire_common:Code");
+		$inspire_common_Namespace = $doc->createElement("inspire_common:Namespace");
+
+		$inspire_common_CodeText = $doc->createTextNode($codeText);
+		$inspire_common_NamespaceText = $doc->createTextNode($namespaceText);
+
+		$inspire_common_Namespace->appendChild($inspire_common_NamespaceText);
+		$inspire_common_Code->appendChild($inspire_common_CodeText);
+		$inspire_dls_SpatialDataSetIdentifier->appendChild($inspire_common_Code);
+		$inspire_dls_SpatialDataSetIdentifier->appendChild($inspire_common_Namespace);
+		$inspire_dls_ExtendedCapabilities->appendChild($inspire_dls_SpatialDataSetIdentifier);
 	}
-
 }
 
 header("Content-type: application/xhtml+xml; charset=UTF-8");



More information about the Mapbender_commits mailing list