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

svn_mapbender at osgeo.org svn_mapbender at osgeo.org
Mon Sep 30 05:22:03 PDT 2019


Author: armin11
Date: 2019-09-30 05:22:03 -0700 (Mon, 30 Sep 2019)
New Revision: 10273

Modified:
   trunk/mapbender/http/php/mod_getDownloadOptions.php
Log:
Enhancement for showing ogc api features as download option

Modified: trunk/mapbender/http/php/mod_getDownloadOptions.php
===================================================================
--- trunk/mapbender/http/php/mod_getDownloadOptions.php	2019-09-27 09:25:38 UTC (rev 10272)
+++ trunk/mapbender/http/php/mod_getDownloadOptions.php	2019-09-30 12:22:03 UTC (rev 10273)
@@ -21,6 +21,10 @@
 //Script for pulling all download options for one or more metadataset which are identified by their fileidentifier
 require_once(dirname(__FILE__) . "/../../core/globalSettings.php");
 require_once(dirname(__FILE__) . "/../classes/class_Uuid.php");
+global $configObject;
+if (file_exists(dirname(__FILE__)."/../../conf/linkedDataProxy.json")) {
+     $configObject = json_decode(file_get_contents("../../conf/linkedDataProxy.json"));
+}
 
 //get language parameter out of mapbender session if it is set else set default language to de_DE
 $sessionLang = Mapbender::session()->get("mb_lang");
@@ -108,24 +112,43 @@
 $mapbenderServerUrl = $mapbenderPathArray['scheme']."://".$mapbenderPathArray['host'];
 
 function getDownloadOptions($idList, $webPath=false) {
+	global $configObject;
 	//define query to pull all download options - actually only the inspire download services based on atom feeds
-	$sql = "select service_id, service_uuid, resource_id, resource_type, datalink, NULL as datalink_text, title,format from (
-select service_id, resource_id, service_uuid, resource_type, fkey_datalink_id as datalink, title, format from (select fkey_wms_id as service_id, layer_id as resource_id, 'layer' as resource_type, layer.uuid as service_uuid, metadata_relation.title, format from layer inner join (select metadata_id, title, format, uuid, fkey_layer_id from mb_metadata inner join ows_relation_metadata on ows_relation_metadata.fkey_metadata_id = mb_metadata.metadata_id) ";
+	$sql = "select service_id, service_uuid, resource_id, resource_name, resource_type, datalink, NULL as datalink_text, title,format from (
+select service_id, resource_id, resource_name, service_uuid, resource_type, fkey_datalink_id as datalink, title, format from (select fkey_wms_id as service_id, layer_id as resource_id, layer_name as resource_name, 'layer' as resource_type, layer.uuid as service_uuid, metadata_relation.title, format from layer inner join (select metadata_id, title, format, uuid, fkey_layer_id from mb_metadata inner join ows_relation_metadata on ows_relation_metadata.fkey_metadata_id = mb_metadata.metadata_id) ";
 
 	$sql .= "as metadata_relation on metadata_relation.fkey_layer_id = layer.layer_id where layer.inspire_download = 1 and metadata_relation.uuid = $1) as layer_metadata LEFT OUTER JOIN ows_relation_data ON layer_metadata.resource_id = ows_relation_data.fkey_layer_id
 ) as inspire_layer inner join wms on inspire_layer.service_id = wms.wms_id ";
 
+	//for inspire atom feeds based on wfs ***************************************************************************
+	$sql .= "union select fkey_wfs_id as service_id, service_uuid, featuretype_id as resource_id, featuretype_name as resource_name, 'wfs' as resource_type, NULL ";
 
-	$sql .= "union select fkey_wfs_id as service_id, service_uuid, featuretype_id as resource_id, 'wfs' as resource_type, NULL ";
+	$sql .= "as datalink, NULL as datalink_text, title, 'GML' as format from (select wfs_featuretype.featuretype_id, wfs_featuretype.featuretype_name, wfs_featuretype.fkey_wfs_id, wfs.uuid as service_uuid, wfs_featuretype.inspire_download from wfs_featuretype inner join wfs on wfs_featuretype.fkey_wfs_id = wfs.wfs_id WHERE inspire_download = 1 ORDER BY featuretype_id) as featuretype_inspire inner join (select metadata_id, title, format, uuid, fkey_featuretype_id from mb_metadata inner join ows_relation_metadata on ";
 
-	$sql .= "as datalink, NULL as datalink_text, title, 'GML' as format from (select wfs_featuretype.featuretype_id ,wfs_featuretype.fkey_wfs_id, wfs.uuid as service_uuid, wfs_featuretype.inspire_download from wfs_featuretype inner join wfs on wfs_featuretype.fkey_wfs_id = wfs.wfs_id WHERE inspire_download = 1 ORDER BY featuretype_id) as featuretype_inspire inner join (select metadata_id, title, format, uuid, fkey_featuretype_id from mb_metadata inner join ows_relation_metadata on ";
-
 	$sql .= "ows_relation_metadata.fkey_metadata_id = mb_metadata.metadata_id) as metadata_relation on metadata_relation.fkey_featuretype_id = featuretype_inspire.featuretype_id and metadata_relation.uuid = $1 ";
+	//end for inspire atom feeds based on wfs ***************************************************************************
 
-	$sql .= "union select NULL as service_id, NULL as service_uuid, NULL as resource_id, 'metadata' as resource_type, NULL ";
+	//for inspire atom feeds based on links in metadata ***************************************************************************
+	$sql .= "union select NULL as service_id, NULL as service_uuid, NULL as resource_id, NULL as resource_name, 'metadata' as resource_type, NULL ";
 
-	$sql .= "as datalink, datalinks as datalink_text, title, format FROM mb_metadata WHERE mb_metadata.uuid = $1 and inspire_download = 1;";
+	$sql .= "as datalink, datalinks as datalink_text, title, format FROM mb_metadata WHERE mb_metadata.uuid = $1 and inspire_download = 1 ";
+	//end for inspire atom feeds based on links in metadata ***************************************************************************
 
+	//for wfs 2.0 linked data proxy **********************************************************************************
+	$sql .= " union select fkey_wfs_id as service_id, service_uuid, featuretype_id as resource_id, featuretype_name as resource_name, 'rest' as resource_type, NULL as datalink, NULL as datalink_text, title, 'GeoJSON,GML,HTML' as format from ";
+
+	$sql .= " (select wfs_featuretype.featuretype_id, wfs_featuretype.featuretype_name, wfs_featuretype.fkey_wfs_id, open_wfs.uuid as service_uuid, wfs_featuretype.inspire_download from wfs_featuretype inner join ";
+
+	$sql .= " (SELECT * FROM (SELECT wfs_id, wfs_version, uuid, wfs_termsofuse.fkey_termsofuse_id FROM wfs INNER JOIN wfs_termsofuse ON wfs_id = fkey_wfs_id) AS wfs_tou INNER JOIN termsofuse ON fkey_termsofuse_id = termsofuse_id WHERE isopen = 1) as open_wfs ";
+
+	$sql .= " on wfs_featuretype.fkey_wfs_id = open_wfs.wfs_id WHERE (open_wfs.wfs_version = '2.0.0' OR open_wfs.wfs_version = '2.0.2') AND wfs_featuretype.featuretype_searchable = 1 ORDER BY featuretype_id) as featuretype_wfs2 inner join ";
+
+	$sql .= " (select metadata_id, title, format, uuid, fkey_featuretype_id from mb_metadata inner join ows_relation_metadata on ows_relation_metadata.fkey_metadata_id = mb_metadata.metadata_id) as metadata_relation on metadata_relation.fkey_featuretype_id = featuretype_wfs2.featuretype_id and metadata_relation.uuid = $1";
+	//end for wfs 2.0 linked data proxy **********************************************************************************
+
+
+
+
 	/*
 	$sql = "select service_id, resource_id, resource_type, fkey_datalink_id as datalink from (select fkey_wms_id as service_id, layer_id as resource_id, 'layer' as resource_type from layer inner join (select metadata_id, uuid, fkey_layer_id from mb_metadata inner join ows_relation_metadata on ows_relation_metadata.fkey_metadata_id = mb_metadata.metadata_id) ";
 
@@ -137,6 +160,7 @@
 
 	//initialize array for result
 	//$e = new mb_exception($idList);
+	//$downloadOptions = new stdClass();
 	for ($i = 0; $i < count($idList); $i++) {
 		$v = array($idList[$i]);
 		$t = array('s');
@@ -144,15 +168,24 @@
 		//problem, $res don't give back false if it was not successful!
 		//push rows into associative array
 		$j = 0;
+
+/*while ($row = db_fetch_assoc($res)) {
+echo "j: ".$j."<br>";
+echo $row['service_id']." - ".$row['resource_type']."<br>";
+$j++;
+}
+die();*/
+
 		while ($row = db_fetch_assoc($res)) {
 			//echo "j: ".$j."<br>";
 			switch ($row['resource_type']) {		
 				case "wfs":
 					$serviceIdIndex = false;
+					//check existing options - maybe some option for a wfs already exists 
 					for ($k = 0; $k < count($downloadOptions->{$idList[$i]}->option); $k++) {
 						//echo "k: ".$k."<br>";
 						//echo "service_id: ".$row['service_id']." - searched Id: ".$downloadOptions->{$idList[$i]}->option[$k]->serviceId."<br>";
-						if ($row['service_id'] == $downloadOptions->{$idList[$i]}->option[$k]->serviceId) {
+						if ($row['service_id'] == $downloadOptions->{$idList[$i]}->option[$k]->serviceId && $downloadOptions->{$idList[$i]}->option[$k]->serviceSubType != "REST") {
 							//service_id found at index $k
 							$serviceIdIndex = $k;
 							//echo "Service already found on index: ".$serviceIdIndex."<br>";
@@ -165,11 +198,14 @@
 						$m = count($downloadOptions->{$idList[$i]}->option[$serviceIdIndex]->featureType);
 						//echo "m: ".$m."<br>";
 						$downloadOptions->{$idList[$i]}->option[$serviceIdIndex]->featureType[$m] = $row['resource_id'];
+$downloadOptions->{$idList[$i]}->option[$serviceIdIndex]->featureType[$m]->name = $row['resource_name'];
 					} else {
 						$downloadOptions->{$idList[$i]}->option[$j]->type = "wfsrequest";
 						$downloadOptions->{$idList[$i]}->option[$j]->serviceId = $row['service_id'];
 						$downloadOptions->{$idList[$i]}->option[$j]->serviceUuid = $row['service_uuid'];
 						$downloadOptions->{$idList[$i]}->option[$j]->featureType[0] = $row['resource_id'];
+$downloadOptions->{$idList[$i]}->option[$j]->featureType[0]->name = $row['resource_name'];
+
 						$downloadOptions->{$idList[$i]}->option[$j]->format = $row['format'];
 						//new 2019/07
 						$downloadOptions->{$idList[$i]}->option[$j]->serviceType = "download";
@@ -195,6 +231,7 @@
 					$downloadOptions->{$idList[$i]}->option[$j]->serviceId = $row['service_id'];
 					$downloadOptions->{$idList[$i]}->option[$j]->serviceUuid = $row['service_uuid'];//This is a layer uuid - not a service uuid!!!!
 					$downloadOptions->{$idList[$i]}->option[$j]->resourceId = $row['resource_id'];
+$downloadOptions->{$idList[$i]}->option[$j]->resourceName = $row['resource_name'];
 					$downloadOptions->{$idList[$i]}->option[$j]->format = $row['format'];
 					$downloadOptions->{$idList[$i]}->option[$j]->dataLink = $row['datalink'];
 					//new 2019/07
@@ -208,6 +245,32 @@
 					$downloadOptions->{$idList[$i]}->title = $row['title'];
 					$downloadOptions->{$idList[$i]}->uuid = $idList[$i];
 				break;
+				case "rest":
+					$downloadOptions->{$idList[$i]}->option[$j]->type = "ogcapifeatures";
+				
+					$downloadOptions->{$idList[$i]}->option[$j]->serviceId = $row['service_id'];
+					$downloadOptions->{$idList[$i]}->option[$j]->serviceUuid = $row['service_uuid'];
+					$downloadOptions->{$idList[$i]}->option[$j]->resourceId = $row['resource_id'];
+$downloadOptions->{$idList[$i]}->option[$j]->resourceName = $row['resource_name'];
+					$downloadOptions->{$idList[$i]}->option[$j]->format = $row['format'];
+					//$downloadOptions->{$idList[$i]}->option[$j]->dataLink = $row['datalink'];
+					//new 2019/07
+					$downloadOptions->{$idList[$i]}->option[$j]->serviceType = "download";
+					$downloadOptions->{$idList[$i]}->option[$j]->serviceSubType = "REST";
+					$downloadOptions->{$idList[$i]}->option[$j]->serviceTitle = _mb('OGC API - Features (Draft)').": ".$row['title']." - "._mb("based on WFS 2.0.0+ datasource");
+					if (isset($configObject) && isset($configObject->behind_rewrite) && $configObject->behind_rewrite == true) {
+						if (isset($configObject) && isset($configObject->datasource_url) && $configObject->datasource_url != "") {
+							$downloadOptions->{$idList[$i]}->option[$j]->accessClient = $configObject->datasource_url.$configObject->rewrite_path."/".$row['service_id']."/collections/".$row['resource_name'];//."/items?&f=html";
+						} else {
+							$downloadOptions->{$idList[$i]}->option[$j]->accessClient = "http://".$_SERVER['HTTP_HOST']."/".$configObject->rewrite_path."/".$row['service_id']."/collections/".$row['resource_name'];//."/items?&f=html";
+						}
+                                        } else {
+						$downloadOptions->{$idList[$i]}->option[$j]->accessClient = $webPath."php/mod_linkedDataProxy.php?wfsid=".$row['service_id']."&collection=".$row['resource_name'];
+					}
+					//$downloadOptions->{$idList[$i]}->option[$j]->accessClient = "https://www....";
+					$downloadOptions->{$idList[$i]}->title = $row['title'];
+					$downloadOptions->{$idList[$i]}->uuid = $idList[$i];
+				break;
 				case "metadata":
 					if (isset($row['datalink_text'] ) || $row['datalink_text'] != '') {
 						$downloadLinks = json_decode($row['datalink_text']);
@@ -321,6 +384,9 @@
 					case "downloadlink":
 						$metadataList .=  $iOptions.". "._mb('Download linked data from INSPIRE Download Service').":   <a href='../plugins/mb_downloadFeedClient.php?url=".urlencode($mapbenderUrl."/php/mod_inspireDownloadFeed.php?id=".$currentUuid."&type=SERVICE&generateFrom=metadata")."'><img src='../img/osgeo_graphics/geosilk/link_download.png' title='"._mb('Download linked data from INSPIRE Download Service')."'/></a>";
 						break;
+					case "ogcapifeatures":
+						$metadataList .=  $iOptions.". "._mb('OGC API Features')." (".$option->resourceName."):   <a href='".$option->accessClient."'><img src='../img/osgeo_graphics/geosilk/link_download.png' title='"._mb('Linked Open Data via OGC REST API')."'/></a>";
+						break;
 				}
 				$metadataList .= "<br>";	
 				$iOptions++;



More information about the Mapbender_commits mailing list