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

svn_mapbender at osgeo.org svn_mapbender at osgeo.org
Mon Sep 30 21:22:59 PDT 2019


Author: armin11
Date: 2019-09-30 21:22:58 -0700 (Mon, 30 Sep 2019)
New Revision: 10274

Modified:
   trunk/mapbender/http/php/mod_featuretypeISOMetadata.php
Log:
Fix for dataset service coupling and enhancement to generate metadata for mapbenders linkedDataProxy with ogc api features (draft)

Modified: trunk/mapbender/http/php/mod_featuretypeISOMetadata.php
===================================================================
--- trunk/mapbender/http/php/mod_featuretypeISOMetadata.php	2019-09-30 12:22:03 UTC (rev 10273)
+++ trunk/mapbender/http/php/mod_featuretypeISOMetadata.php	2019-10-01 04:22:58 UTC (rev 10274)
@@ -18,8 +18,11 @@
 // along with this program; if not, write to the Free Software
 // Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
 
-//Script to generate a conformant ISO19139 service metadata record for a wms layer which is registrated in the mapbender database. It works as a webservice
-//The record will be fulfill the demands of the INSPIRE metadata regulation from 03.12.2008 and the iso19139
+/*Script to generate a conformant ISO19139 service metadata record for a wfs featuretype/wfs which is registrated in the mapbender database. It works as a webservice. The contact/orga, license, and conformity parts of the metadata generated otf from the mapbender registry. The xml structure will be read from a xml template file and the relevant elements are exchanged via xpath. Some metadata is exchanged after the xml will be initially generated via dom.
+The uuid of the registrated featuretype is used as fileidentifier of the metadata record.  
+The record will be fulfill the demands of the INSPIRE metadata regulation from 03.12.2008 and the iso19139:2005.
+New 2019-09-30: Also metadata for mapbenders LinkedDataProxy (OGC API Features Interface) is generated.
+*/
 require_once(dirname(__FILE__) . "/../../core/globalSettings.php");
 require_once(dirname(__FILE__) . "/../classes/class_connector.php");
 require_once(dirname(__FILE__) . "/../classes/class_administration.php");
@@ -28,10 +31,13 @@
 require_once(dirname(__FILE__) . "/../classes/class_XmlBuilder.php");
 require_once(dirname(__FILE__)."/../classes/class_owsConstraints.php");
 require_once(dirname(__FILE__)."/../classes/class_qualityReport.php");
+/*
 
+*/
 $con = db_connect(DBSERVER,OWNER,PW);
 db_select_db(DB,$con);
-
+global $serviceType;
+global $serviceTypeTitle;
 if (DEFINED("MAPBENDER_PATH") && MAPBENDER_PATH !== "") {
 	$mapbenderServiceUrl = MAPBENDER_PATH."/php/wfs.php?INSPIRE=1&FEATURETYPE_ID=";
 } else {
@@ -39,7 +45,8 @@
 }
 
 $admin = new administration();
-
+$serviceType = "wfs";
+$serviceTypeTitle = "OGC WFS Interface";
 //define the view or table to use as input for metadata generation if this is wished. If not, the data will be directly read from the database tables
 $wmsView = "search_wfs_view";
 $wmsView = '';
@@ -62,6 +69,13 @@
 	$testMatch = NULL;
 }
 
+if ($_REQUEST['SERVICETYPE'] == "wfs" || $_REQUEST['SERVICETYPE'] == "ogcapifeatures") {
+    $serviceType = $_REQUEST['SERVICETYPE'];
+    if ($serviceType == 'ogcapifeatures') {
+        $serviceTypeTitle = "OGC API Features (Draft)";
+    }
+}
+
 if ($_REQUEST['OUTPUTFORMAT'] == "iso19139" || $_REQUEST['OUTPUTFORMAT'] == "rdf" || $_REQUEST['OUTPUTFORMAT'] == 'html') {
 	//Initialize XML document
 	$iso19139Doc = new DOMDocument('1.0');
@@ -109,6 +123,8 @@
     	global $wmsView;
 	global $mapbenderServiceUrl;
 	global $admin;
+        global $serviceType;
+        global $serviceTypeTitle;
 	//read out relevant information from mapbender database:
 	if ($wmsView != '') {
 		$sql = "SELECT * ";
@@ -147,13 +163,20 @@
 		$userMetadata['mb_user_email'] = $departmentMetadata['mb_user_email'];
 	}
 	//TODO: check if resource is freely available to anonymous user - which are all users who search thru metadata catalogues:
-	//$hasPermission=$admin->getLayerPermission($mbMeta['wfs_id'],$mbMeta['layer_name'],PUBLIC_USER); ##################
-
-    
+	//$hasPermission=$admin->getLayerPermission($mbMeta['wfs_id'],$mbMeta['layer_name'],PUBLIC_USER); ##################  
     $iso19139 = $xmlBuilder->getDoc();
     $MD_Metadata = $iso19139->documentElement;
-        
-    $xmlBuilder->addValue($MD_Metadata, './gmd:fileIdentifier/gco:CharacterString', isset($mbMeta['uuid']) ? $mbMeta['uuid']: "no id found");
+    //how to generate fileidentifier 
+    switch ($serviceType) {
+        case "wfs": 
+            $fileIdentifier = isset($mbMeta['uuid']) ? $mbMeta['uuid']: "no id found";
+	    break;
+	case "ogcapifeatures":
+	    $uuidHash = md5($mbMeta['uuid']."ogcapifeatures");
+            $fileIdentifier = substr($uuidHash, 0, 8)."-".substr($uuidHash, 7, 4)."-".substr($uuidHash, 11, 4)."-".substr($uuidHash, 15, 4)."-".substr($uuidHash, 19, 12);
+	    break;
+    }
+    $xmlBuilder->addValue($MD_Metadata, './gmd:fileIdentifier/gco:CharacterString', $fileIdentifier);
     
     $xmlBuilder->addValue($MD_Metadata, './gmd:language/gmd:LanguageCode',
             isset($mbMeta['metadata_language']) ? $mbMeta['metadata_language'] : 'ger');
@@ -203,7 +226,7 @@
             isset($mbMeta['wfs_uuid']) ? $mbMeta['wfs_uuid'] : "wfs uuid not given");
     $xmlBuilder->addValue($MD_Metadata,
             './gmd:identificationInfo/srv:SV_ServiceIdentification/gmd:citation/gmd:CI_Citation/gmd:title/gco:CharacterString',
-            isset($mbMeta['wfs_title']) ? $mbMeta['wfs_title']." - ".$mbMeta['layer_title'] : "title not given");
+            isset($mbMeta['wfs_title']) ? $mbMeta['wfs_title']." - ".$mbMeta['featuretype_title']." - ".$serviceTypeTitle : "title not given");
 
     $pos = 0;
 	//Create date elements B5.2-5.4 - format will be only a date - no dateTime given
@@ -358,7 +381,7 @@
 	$i=0;
 	$sql = <<<SQL
 
-SELECT metadata_id, uuid, link, linktype, md_format, origin, datasetid FROM mb_metadata 
+SELECT metadata_id, uuid, link, linktype, md_format, origin, datasetid, datasetid_codespace FROM mb_metadata 
 INNER JOIN (SELECT * from ows_relation_metadata 
 WHERE fkey_featuretype_id = $recordId ) as relation ON 
 mb_metadata.metadata_id = relation.fkey_metadata_id WHERE mb_metadata.origin IN ('capabilities','external','metador')
@@ -397,43 +420,40 @@
 	/*INSPIRE demands a href for the metadata record!*/
 	/*TODO: Exchange HTTP_HOST with other baseurl*/
     $pos = 0;
-	while ($row_metadata = db_fetch_array($res_metadataurl)) {
-
-		$uniqueResourceIdentifierCodespace = $admin->getIdentifierCodespaceFromRegistry($departmentMetadata, $row_metadata);
-
-        	switch ($row_metadata['origin']) {
-            	case 'capabilities':
-               		$pos++;
-                	$xmlBuilder->addValue($MD_Metadata,
+    while ($row_metadata = db_fetch_array($res_metadataurl)) {
+	$uniqueResourceIdentifierCodespace = $admin->getIdentifierCodespaceFromRegistry($departmentMetadata, $row_metadata);
+        switch ($row_metadata['origin']) {
+            case 'capabilities':
+               	$pos++;
+                $xmlBuilder->addValue($MD_Metadata,
                         	'./gmd:identificationInfo/srv:SV_ServiceIdentification/srv:operatesOn['.$pos.']/@xlink:href',
                         	"http://" . $_SERVER['HTTP_HOST'] . "/mapbender/php/mod_dataISOMetadata.php?outputFormat=iso19139&id=" . $row_metadata['uuid']);
-                	$xmlBuilder->addValue($MD_Metadata,
+                $xmlBuilder->addValue($MD_Metadata,
                         	'./gmd:identificationInfo/srv:SV_ServiceIdentification/srv:operatesOn['.$pos.']/@uuidref',
                         	$uniqueResourceIdentifierCodespace.$row_metadata['datasetid']);
-                	break;
-            	case 'metador':
-                	$pos++;
-                	$xmlBuilder->addValue($MD_Metadata,
+                break;
+            case 'metador':
+                $pos++;
+                $xmlBuilder->addValue($MD_Metadata,
                         	'./gmd:identificationInfo/srv:SV_ServiceIdentification/srv:operatesOn['.$pos.']/@xlink:href',
                         	"http://" . $_SERVER['HTTP_HOST'] . "/mapbender/php/mod_dataISOMetadata.php?outputFormat=iso19139&id=" . $row_metadata['uuid'].'#spatial_dataset_'.md5($row_metadata['uuid']));
-                	$xmlBuilder->addValue($MD_Metadata,
+                $xmlBuilder->addValue($MD_Metadata,
                         	'./gmd:identificationInfo/srv:SV_ServiceIdentification/srv:operatesOn['.$pos.']/@uuidref',
                        		$uniqueResourceIdentifierCodespace.$row_metadata['uuid']);
-                	break;
-            	case 'external':
-                	$pos++;
-                	$xmlBuilder->addValue($MD_Metadata,
+                break;
+            case 'external':
+                $pos++;
+                $xmlBuilder->addValue($MD_Metadata,
                         	'./gmd:identificationInfo/srv:SV_ServiceIdentification/srv:operatesOn['.$pos.']/@xlink:href',
                         	"http://" . $_SERVER['HTTP_HOST'] . "/mapbender/php/mod_dataISOMetadata.php?outputFormat=iso19139&id=" . $row_metadata['uuid']);
-                	$xmlBuilder->addValue($MD_Metadata,
+                $xmlBuilder->addValue($MD_Metadata,
                         	'./gmd:identificationInfo/srv:SV_ServiceIdentification/srv:operatesOn['.$pos.']/@uuidref',
-                        	$uniqueResourceIdentifierCodespace.$row_metadata['datasetid']);
-                	break;
-            	default:
-                	break;
-        	}
-    	}
-
+                $uniqueResourceIdentifierCodespace.$row_metadata['datasetid']);
+                break;
+            default:
+                break;
+        }
+    }
     $xmlBuilder->addValue($MD_Metadata,
             './gmd:distributionInfo/gmd:MD_Distribution/gmd:distributionFormat/gmd:MD_Format/gmd:name/@gco:nilReason',
             'missing');
@@ -441,11 +461,23 @@
             './gmd:distributionInfo/gmd:MD_Distribution/gmd:distributionFormat/gmd:MD_Format/gmd:version/@gco:nilReason',
             'missing');
     
-	//Check if anonymous user has rights to access this featyretype - if not ? which resource should be advertised? TODO
+    //Check if anonymous user has rights to access this featuretype - if not ? which resource should be advertised? TODO
+    //initialize url to give back as point of access
     $url = '';
+    //$e = new mb_exception($serviceType);
+    switch ($serviceType) {
+        case "wfs":
+	    $url = $mapbenderServiceUrl.$mbMeta['featuretype_id']."&REQUEST=GetCapabilities&SERVICE=WFS&VERSION=".$mbMeta['wfs_version'];
+	    $protocol = "OGC:WFS-".$mbMeta['wfs_version']."-http-get-feature";
+            break;
+	case "ogcapifeatures":
+            $url = "http://localhost/spatial-objects/".$mbMeta['wfs_id']."/collections/".$mbMeta['featuretype_name'];
+	    $protocol = "OGC:API:Features";
+            break;
+    }   
 	//GetCapabilities is always available
 	//if ($hasPermission) {
-		$url = $mapbenderServiceUrl.$mbMeta['featuretype_id']."&REQUEST=GetCapabilities&SERVICE=WFS&VERSION=".$mbMeta['wfs_version'];
+		//$url = $mapbenderServiceUrl.$mbMeta['featuretype_id']."&REQUEST=GetCapabilities&SERVICE=WFS&VERSION=".$mbMeta['wfs_version'];
 	/*} else {
 		$url = "https://".$_SERVER['HTTP_HOST']."/registry/wfs/".$mbMeta['featuretype_id']."?REQUEST=GetCapabilities&SERVICE=WFS&VERSION=".$version;
 	}*/
@@ -458,7 +490,7 @@
 
     $xmlBuilder->addValue($MD_Metadata,
             './gmd:distributionInfo/gmd:MD_Distribution/gmd:transferOptions/gmd:MD_DigitalTransferOptions/gmd:onLine/gmd:CI_OnlineResource/gmd:protocol/gco:CharacterString',
-            "OGC:WFS-".$mbMeta['wfs_version']."-http-get-feature");
+            $protocol);
  
     $xmlBuilder->addValue($MD_Metadata,
             './gmd:distributionInfo/gmd:MD_Distribution/gmd:transferOptions/gmd:MD_DigitalTransferOptions/gmd:onLine/gmd:CI_OnlineResource/gmd:name/gco:CharacterString',
@@ -495,6 +527,9 @@
             'true');
     
     return $xmlBuilder->getDoc()->saveXML();
+
+    //TODO exchange specifications from inspire_legislation.json afterwards like it is done in mod_layerISOMetadata.php
+    //
 }
 
 //function to give away the xml data



More information about the Mapbender_commits mailing list