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

svn_mapbender at osgeo.org svn_mapbender at osgeo.org
Thu Dec 3 08:35:54 PST 2015


Author: armin11
Date: 2015-12-03 08:35:54 -0800 (Thu, 03 Dec 2015)
New Revision: 9330

Modified:
   trunk/mapbender/http/classes/class_metadata_new.php
   trunk/mapbender/http/php/mod_callMetadata.php
Log:
First draft of resolving data service metadata coupling otf while searching for datasets

Modified: trunk/mapbender/http/classes/class_metadata_new.php
===================================================================
--- trunk/mapbender/http/classes/class_metadata_new.php	2015-12-03 16:03:10 UTC (rev 9329)
+++ trunk/mapbender/http/classes/class_metadata_new.php	2015-12-03 16:35:54 UTC (rev 9330)
@@ -54,15 +54,16 @@
 	var $searchResources;
 	var $searchPages;
 	var $outputFormat;
-	var $resultTarget;
+	var $resultTarget; //web,webclient,file,internal
 	var $tempFolder;
 	var $orderBy;
 	var $hostName;
 	var $resourceIds;
 	var $restrictToOpenData;
 	var $originFromHeader;
+	var $resolveCoupledResources;
 
-	function __construct($userId, $searchId, $searchText, $registratingDepartments, $isoCategories, $inspireThemes, $timeBegin, $timeEnd, $regTimeBegin, $regTimeEnd, $maxResults, $searchBbox, $searchTypeBbox, $accessRestrictions, $languageCode, $searchEPSG, $searchResources, $searchPages, $outputFormat, $resultTarget, $searchURL, $customCategories, $hostName, $orderBy, $resourceIds, $restrictToOpenData, $originFromHeader){
+	function __construct($userId, $searchId, $searchText, $registratingDepartments, $isoCategories, $inspireThemes, $timeBegin, $timeEnd, $regTimeBegin, $regTimeEnd, $maxResults, $searchBbox, $searchTypeBbox, $accessRestrictions, $languageCode, $searchEPSG, $searchResources, $searchPages, $outputFormat, $resultTarget, $searchURL, $customCategories, $hostName, $orderBy, $resourceIds, $restrictToOpenData, $originFromHeader, $resolveCoupledResources = false){
 		$this->userId = (integer)$userId;
 		$this->searchId = $searchId;
 		$this->searchText = $searchText;
@@ -95,6 +96,8 @@
 			$this->restrictToOpenData = false;
 		}
 		$this->originFromHeader = $originFromHeader;
+		$this->internalResult = null; //will only be filled, if resultTarget = 'internal', includes json for wms or wfs
+		$this->resolveCoupledResources = $resolveCoupledResources;
 		//definitions for generating tagClouds
 		$this->maxObjects = 15;
 		$this->maxFontSize = 30;
@@ -164,7 +167,7 @@
 		$this->resourceClassifications[2]['relation_wms'] = 'layer_custom_category';
 		$this->resourceClassifications[2]['relation_wfs'] = 'featuretype_custom_category';
 		$this->resourceClassifications[2]['relation_wmc'] = 'wmc_custom_category';
-		$this->resourceClassifications[1]['relation_dataset'] = 'mb_metadata_custom_category';
+		$this->resourceClassifications[2]['relation_dataset'] = 'mb_metadata_custom_category';
 		//TODO: define this in mapbender
 
 		//Defining of the different result categories		
@@ -314,7 +317,7 @@
 				$this->generateWMCMetadata($this->wmcDoc);
 			}
 			if (isset($this->searchResources) & strtolower($this->searchResources) === "dataset") {
-				$this->databaseIdColumnName = 'metadata_id';
+				$this->databaseIdColumnName = 'metadata_id'; //not metadata_id as in original table!
 				$this->databaseTableName = 'mb_metadata';
 				//$this->keywordRelation = 'layer_keyword';
 				//$this->searchView = 'wms_search_table';
@@ -581,6 +584,8 @@
 		#array_multisort($wfsMatrix['wfs_id'], SORT_ASC,$wfsMatrix['featuretype_id'], SORT_ASC,$wfsMatrix['wfs_conf_id'], SORT_ASC); //have some problems - the database version is more stable
 		#print_r($wfsMatrix);
 		$datasetMatrix = $this->flipDiagonally($datasetMatrix);
+		$allCoupledLayers = array();
+		$allCoupledFeaturetypes = array();
 		//read out first server entry - maybe this a little bit timeconsuming TODO
 		for($i=0; $i<count($datasetMatrix);$i++){
 			$this->datasetJSON->dataset->srv[$i]->id = $datasetMatrix[$i]['dataset_id'];
@@ -600,17 +605,50 @@
 			} else {
 				$spatialSource = $datasetMatrix[$i]['mb_group_stateorprovince'];
 			}
-			$this->datasetJSON->dataset->srv[$i-$j]->iso3166 = $spatialSource;
+			$this->datasetJSON->dataset->srv[$i]->iso3166 = $spatialSource;
 				
-			$this->datasetJSON->dataset->srv[$i-$j]->bbox = array($datasetMatrix[$i]['bbox']); //TODO: read out bbox from wmc $datasetMatrix[$i][''];
-
-			#$equalEPSG = $wmcMatrix[$i]['srs'];
-                       	#$isEqual = true;
-			//control if EPSG is supported by Client
-		        #if ($equalEPSG == $this->searchEPSG){
-			#	$isEqual = false;		
-		        #}	
+			$this->datasetJSON->dataset->srv[$i]->bbox = array($datasetMatrix[$i]['bbox']); //TODO: read out bbox from wmc $datasetMatrix[$i][''];
+			//search for coupled resources!!!!
+			if ($this->resolveCoupledResources == true) {
+			//maybe generate uuid first to find search!!
+			//http://localhost/mb_trunk/php/mod_callMetadata.php?searchId=test2&searchText=wald&outputFormat=json&resultTarget=web&searchResources=dataset&resolveCoupledResources=true
+				$coupledResources = json_decode($datasetMatrix[$i]['coupled_resources']);
+				foreach ($coupledResources->coupledResources->layerIds as $layer_id) {
+					$this->datasetJSON->dataset->srv[$i]->coupledResources->layer[] = $layer_id;
+					$allCoupledLayers[] = $layer_id;
+		$allCoupledFeaturetypes = array();
+				}
+				foreach ($coupledResources->featuretypeIds as $featuretype_id) {
+					$this->datasetJSON->dataset->srv[$i]->coupledResources->featuretype[] = $featuretype_id;
+					$allCoupledFeaturetypes[] = $featuretype_id;
+				}
+				//$coupledLayers = new self($this->userId, 'dummysearch', '*', null, null, null, null, null, null, null, 10, null, null, null, $this->languageCode, null, 'wms', 1, 'json', 'internal', null, null, $this->hostName, 'rank', '13751,13752' ,false , null);
+				//$this->datasetJSON->dataset->srv[$i-$j]->coupledLayer = json_decode($coupledLayers->internalResult);
+				//$coupledFeaturetypes = new self($this->userId, 'dummysearch', '*', null, null, null, null, null, null, null, 10, null, null, null, $this->languageCode, null, 'wfs', 1, 'json', 'internal', null, null, $this->hostName, 'rank', '13751,13752' ,false , null);
+				//$this->datasetJSON->dataset->srv[$i-$j]->coupledFeaturetypes = json_decode($coupledFeaturetypes->internalResult);
+				//pull downloadoptions directly from layer downloadoptions cause they are the same !!!!
+			}
+		}
+		//search for coupled resources and push them into dataset json !
+		if ($this->resolveCoupledResources == true) {
+			//$e = new mb_exception("count of all layers:".count(array_unique($allCoupledLayers)));
+			//$e = new mb_exception("cs of all layers:".implode(',',array_unique($allCoupledLayers)));
+			//$e = new mb_exception("count layers: ".time());
+			//$csLayerIds = implode(',',array_unique($allCoupledLayers));
+			//$countLayerIds = (integer)count(array_unique($allCoupledLayers));
+			if (count($allCoupledLayers) >= 1) {
+				//$e = new mb_exception("invoke search");
+				//$coupledLayers = new self($this->userId, 'dummysearch', '*', null, null, null, null, null, null, null, count(array_unique($allCoupledLayers)), null, null, null, $this->languageCode, null, 'wms', 1, 'json', 'internal', null, null, $this->hostName, 'rank', implode(',',array_unique($allCoupledLayers))$csLayerIds ,false , null);
+				$coupledLayers = new self($this->userId, 'dummysearch', '*', null, null, null, null, null, null, null, count(array_unique($allCoupledLayers)), null, null, null, $this->languageCode, null, 'wms', 1, 'json', 'internal', null, null, $this->hostName, 'rank',implode(',',array_unique($allCoupledLayers)) ,false , null);
+				//$test = json_decode($coupledLayers->internalResult);
+				//$e = new mb_exception($coupledLayers->internalResult);
+			}
+			//$e = new mb_exception("count featuretypes: ".time());
+			if (count($allCoupledFeaturetypes) >= 1) {
+				$coupledFeaturetypes = new self($this->userId, 'dummysearch', '*', null, null, null, null, null, null, null, count(array_unique($allCoupledFeaturetypes)), null, null, null, $this->languageCode, null, 'wfs', 1, 'json', 'internal', null, null, $this->hostName, 'rank', implode(',',array_unique($allCoupledFeaturetypes)) ,false , null);
+			//$e = new mb_exception("end counting: ".time());
 				
+			}
 		}
 			
 	}
@@ -840,6 +878,9 @@
 			if ($this->resultTarget == 'web' or $this->resultTarget == 'debug') {
 				echo $this->wmsJSON;
 			}
+			if ($this->resultTarget == 'internal') {
+				$this->internalResult = $this->wmsJSON;
+			}
 			if ($this->resultTarget == 'webclient') {
 				$this->allJSON = new stdClass;
 				$this->allJSON->categories = $this->json->decode($this->keyJSON);
@@ -900,6 +941,9 @@
 			if ($this->resultTarget == 'web'or $this->resultTarget == 'debug') {
 				echo $this->wfsJSON;
 			}
+			if ($this->resultTarget == 'internal') {
+				$this->internalResult = $this->wfsJSON;
+			}
 		}
 		
 		$e = new mb_notice("Time to generate WFS-Metadata: ".$usedTime);
@@ -1237,7 +1281,10 @@
 			//filename to search for:
 			$filename = $this->tempFolder."/".$this->searchId."_".$this->searchResources."_cat.json";
 			$keyFilename = $this->tempFolder."/".$this->searchId."_".$this->searchResources."_keywords.json";
-			if (!file_exists($filename)  or $this->resultTarget == 'debug') { //TODO at the moment the cat file will be overwritten - change this in production system
+			//check filename exists in storage
+			$admin = new administration();
+			$fileExists = $admin->getFromStorage($filename,TMP_SEARCH_RESULT_STORAGE);
+			if ($fileExists == false  or $this->resultTarget == 'debug') { //TODO at the moment the cat file will be overwritten - change this in production system
 				//open category file for results
 				$this->catJSON = new stdClass;
 				$this->catJSON->searchMD = (object) array(

Modified: trunk/mapbender/http/php/mod_callMetadata.php
===================================================================
--- trunk/mapbender/http/php/mod_callMetadata.php	2015-12-03 16:03:10 UTC (rev 9329)
+++ trunk/mapbender/http/php/mod_callMetadata.php	2015-12-03 16:35:54 UTC (rev 9330)
@@ -47,6 +47,7 @@
 $resultTarget = "web";
 $preDefinedMaxResults = array(5,10,15,20,25,30);
 $searchEPSG = "EPSG:31466";
+$resolveCoupledResources = false;
 $classJSON = new Mapbender_JSON;
 
 if (defined('ABSOLUTE_TMPDIR')){
@@ -296,6 +297,24 @@
 	}
 	$testMatch = NULL;
 }
+
+if (isset($_REQUEST["resolveCoupledResources"]) & $_REQUEST["resolveCoupledResources"] != "") {
+	$testMatch = $_REQUEST["resolveCoupledResources"];	
+ 	if (!($testMatch == 'true' or $testMatch == 'false')){ 
+		echo 'Parameter <b>resolveCoupledResources</b> is not valid (true,false (default to false)).<br/>'; 
+		die(); 		
+ 	}
+	switch ($testMatch) {
+		case "true":
+			$resolveCoupledResources = "true";
+		break;
+		case "false":
+			$resolveCoupledResources = "false";
+		break;	
+	}
+	$testMatch = NULL;
+}
+
 if (isset($_REQUEST["hostName"]) & $_REQUEST["hostName"] != "") {
 	//validate to some hosts
 	$testMatch = $_REQUEST["hostName"];	
@@ -370,9 +389,9 @@
 if (isset($_REQUEST["resultTarget"]) & $_REQUEST["resultTarget"] != "") {
 	//validate to web,debug,file
 	$testMatch = $_REQUEST["resultTarget"];	
- 	if (!($testMatch == 'web' or $testMatch == 'debug' or $testMatch == 'file'  or $testMatch == 'webclient')){ 
+ 	if (!($testMatch == 'web' or $testMatch == 'debug' or $testMatch == 'file'  or $testMatch == 'webclient' or $testMatch == 'internal')){ 
 		//echo 'resultTarget: <b>'.$testMatch.'</b> is not valid.<br/>';
-		echo 'Parameter <b>resultTarget</b> is not valid (file,web,debug,webclient).<br/>'; 
+		echo 'Parameter <b>resultTarget</b> is not valid (file,web,debug,webclient,internal).<br/>'; 
 		die(); 		
  	}
 	$resultTarget = $testMatch;
@@ -402,14 +421,11 @@
     }
 }
 
-
-
 #$searchResources = array('wms','wfs','wmc','georss');
 #$searchPages = array(1,1,1,1);
 
 //TODO: if class is called directly
 
-
 if ($resultTarget == 'debug') {
 	echo "<br>DEBUG: searchURL: ".$searchURL."<br>";
 	#echo "<br>DEBUG: languageCode: ".$languageCode."<br>";
@@ -1012,16 +1028,17 @@
 		$str .= "'".$orderBy."' ";
 		$str .= "'".$resourceIds."' ";		
 		$str .= "'".$restrictToOpenData."' ";
+		$str .= "'".$resolveCoupledResources."' ";
 		$str .= " & ";
 		$e = new mb_notice($str);
 		exec($str);*/
-		$metadata = new searchMetadata($userId, $searchId, $searchText, $registratingDepartments, $isoCategories, $inspireThemes, $timeBegin, $timeEnd, $regTimeBegin, $regTimeEnd, $maxResults, $searchBbox, $searchTypeBbox, $accessRestrictions, $languageCode, $searchEPSG, $searchResources[$i], $searchPages[$i], $outputFormat, $resultTarget, $searchURL, $customCategories, $hostName, $orderBy, $resourceIds, $restrictToOpenData, $originFromHeader);
+		$metadata = new searchMetadata($userId, $searchId, $searchText, $registratingDepartments, $isoCategories, $inspireThemes, $timeBegin, $timeEnd, $regTimeBegin, $regTimeEnd, $maxResults, $searchBbox, $searchTypeBbox, $accessRestrictions, $languageCode, $searchEPSG, $searchResources[$i], $searchPages[$i], $outputFormat, $resultTarget, $searchURL, $customCategories, $hostName, $orderBy, $resourceIds, $restrictToOpenData, $originFromHeader, $resolveCoupledResources);
 	}
 }
 if ($resultTarget == 'web' or $resultTarget == 'debug' or $resultTarget == 'webclient') {
 	if (count($searchResources) == 1) {
 		//$e = new mb_exception("originFromHeader: ".$originFromHeader);
-		$metadata = new searchMetadata($userId, $searchId, $searchText, $registratingDepartments, $isoCategories, $inspireThemes, $timeBegin, $timeEnd, $regTimeBegin, $regTimeEnd, $maxResults, $searchBbox, $searchTypeBbox, $accessRestrictions, $languageCode, $searchEPSG, $searchResources[0], $searchPages[0], $outputFormat, $resultTarget, $searchURL, $customCategories, $hostName, $orderBy, $resourceIds, $restrictToOpenData, $originFromHeader);
+		$metadata = new searchMetadata($userId, $searchId, $searchText, $registratingDepartments, $isoCategories, $inspireThemes, $timeBegin, $timeEnd, $regTimeBegin, $regTimeEnd, $maxResults, $searchBbox, $searchTypeBbox, $accessRestrictions, $languageCode, $searchEPSG, $searchResources[0], $searchPages[0], $outputFormat, $resultTarget, $searchURL, $customCategories, $hostName, $orderBy, $resourceIds, $restrictToOpenData, $originFromHeader, $resolveCoupledResources);
 		#if ($outputFormat == 'xml') {
 		#	header("Content-type: application/xhtml+xml; charset=UTF-8");		
 		#}



More information about the Mapbender_commits mailing list