[Mapbender-commits] r9546 - trunk/mapbender/http/classes

svn_mapbender at osgeo.org svn_mapbender at osgeo.org
Fri Jul 15 04:57:58 PDT 2016


Author: armin11
Date: 2016-07-15 04:57:58 -0700 (Fri, 15 Jul 2016)
New Revision: 9546

Added:
   trunk/mapbender/http/classes/class_propagateMetadata.php
Modified:
   trunk/mapbender/http/classes/class_wms.php
Log:
New handling for propagate metadata to external catalogues - works for wms/layer resources

Added: trunk/mapbender/http/classes/class_propagateMetadata.php
===================================================================
--- trunk/mapbender/http/classes/class_propagateMetadata.php	                        (rev 0)
+++ trunk/mapbender/http/classes/class_propagateMetadata.php	2016-07-15 11:57:58 UTC (rev 9546)
@@ -0,0 +1,97 @@
+<?php
+# $Id$
+# http://www.mapbender.org/index.php/class_propagateMetadata.php
+# Copyright (C) 2002 CCGIS 
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2, or (at your option)
+# any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program; if not, write to the Free Software
+# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+
+require_once(dirname(__FILE__)."/../../core/globalSettings.php");
+require_once(dirname(__FILE__)."/class_cswClient.php");
+require_once(dirname(__FILE__)."/class_iso19139.php");
+/**
+ * Class to propagate metadata from mapbender to connected metadata catalogues
+ * @author armin11
+ *
+ */
+class propagateMetadata {
+	var $cswId;
+	var $resourceType;
+	//var $operation; // 'push' or 'delete'
+	var $resourceIds = array();
+	var $resourceUuids = array();
+	var $active = false;
+	var $absolutePath;
+	var $cswClient;
+	
+	public function __construct() {
+				if (defined("SYNC_CHANGES_TO_CSW") && SYNC_CHANGES_TO_CSW == true && defined("SYNC_CATALOGUE_ID") && is_int(SYNC_CATALOGUE_ID)) {
+					$this->cswId = SYNC_CATALOGUE_ID;
+					$this->active = true;
+					$this->cswClient = new cswClient();
+					$this->cswClient->cswId = $this->cswId;
+					
+				} else {
+					$this->cswId = null;
+					$this->active = false;
+				}
+				if (defined("MAPBENDER_PATH") && MAPBENDER_PATH !== "") {
+					$this->absolutePath = MAPBENDER_PATH;
+				} else {
+					$this->absolutePath = "http://".$_SERVER['HTTP_HOST']."/mapbender";
+				}
+	}
+	
+	public function doPropagation($resourceType, $resourceIds, $operation, $resourceUuids=false) {
+		if ($this->active == true) {
+			//$e = new mb_exception("classes/class_propagateMetadata.php: try to propagate metadata!");
+			switch ($resourceType) {
+				case "layer":
+					$mapbenderMetadataUrl = $this->absolutePath."/php/mod_layerISOMetadata.php?SERVICE=WMS&outputFormat=iso19139&Id=";
+					$metadataIds = $resourceIds;
+					break;
+				case "metadata":
+					$mapbenderMetadataUrl = $this->absolutePath."/php/mod_dataISOMetadata.php?outputformat=iso19139&id=";
+					$metadataIds = $resourceUuids;
+					break;
+			}
+			$isoMetadata = new Iso19139();
+			switch ($operation) {
+				case "push":
+					foreach ($metadataIds as $id) {
+						$metadata = $isoMetadata->createFromUrl($mapbenderMetadataUrl.$id);
+						$e = new mb_exception("classes/class_propagateMetadata.php: try to push metadata for ".$resourceType." - ".$id);
+						$result = $this->cswClient->pushRecord($metadata);
+						$e = new mb_exception("classes/class_propagateMetadata.php: ".$result);
+					}
+					break;
+				case "delete":
+					$metadataIds = $resourceUuids;
+					$e = new mb_exception("classes/class_propagateMetadata.php: count of array to delete: ".count($metadataIds));
+					foreach ($metadataIds as $id) {
+						
+						$e = new mb_exception("classes/class_propagateMetadata.php: try to delete metadata for ".$resourceType." - ".$id);
+						$result = $this->cswClient->deleteRecord($id);
+						$e = new mb_exception("classes/class_propagateMetadata.php: ".$result);
+					}
+					break;
+			}	
+		} else {
+			$e = new mb_exception("classes/class_propagateMetadata.php: Metadata propagation not yet configured!");
+		}
+		return true;	
+	}
+
+
+}

Modified: trunk/mapbender/http/classes/class_wms.php
===================================================================
--- trunk/mapbender/http/classes/class_wms.php	2016-07-14 15:03:36 UTC (rev 9545)
+++ trunk/mapbender/http/classes/class_wms.php	2016-07-15 11:57:58 UTC (rev 9546)
@@ -14,7 +14,7 @@
 require_once dirname(__FILE__) . "/class_georss_factory.php";
 require_once dirname(__FILE__) . "/class_mb_exception.php";
 require_once dirname(__FILE__) . "/class_iso19139.php";
-require_once(dirname(__FILE__) . "/class_cswClient.php");
+require_once(dirname(__FILE__) . "/class_propagateMetadata.php");
 require_once dirname(__FILE__) . "/../classes/class_universal_wms_factory.php";
 class wms {
 	var $lastURL;
@@ -1906,41 +1906,23 @@
 				$e = new mb_exception("class_wms.php: Twitter API give back error code: ".$result);
 			}
 		}
-		//Propagate information for each new layer to csw if configured
-		if (defined("SYNC_CHANGES_TO_CSW") && SYNC_CHANGES_TO_CSW == true && defined("SYNC_CATALOGUE_ID") && is_int(SYNC_CATALOGUE_ID)) {
-			if (defined("MAPBENDER_PATH") && MAPBENDER_PATH !== "") {
-				//layer service metadata generator 
-				$servMdPath = MAPBENDER_PATH."/php/mod_layerISOMetadata.php?SERVICE=WMS&outputFormat=iso19139&Id=";
-			} else {
-				$servMdPath = "http://".$_SERVER['HTTP_HOST']."/mapbender"."/php/mod_layerISOMetadata.php?SERVICE=WMS&outputFormat=iso19139&Id=";
-			}
-			$cswClient = new cswClient();
-			$cswClient->cswId = SYNC_CATALOGUE_ID;
-			$isoMetadata = new Iso19139();
-			//select all layer which are searchable
-			$sql = "SELECT layer_id, uuid FROM layer WHERE fkey_wms_id = $1 and layer_searchable = 1";
-			$v = array($myWMS);
-			$t = array('i');
-			$res = db_prep_query($sql,$v,$t);
-			$insertedLayerArray = array();
-			while($row = db_fetch_array($res)){
-				$insertedLayerArray[] = array(
-						"id" => $row['layer_id'],
-						"uuid" => $row['uuid']
-				);
-			}
-			//update existing layer
-			foreach ($insertedLayerArray as $insertedLayer) {
-					//$e = new mb_exception("classes/class_wms.php: try to push metadata for layer ".$insertedLayer['id']." into csw");
-					$metadata = $isoMetadata->createFromUrl($servMdPath.$insertedLayer['id']);
-					$result = $cswClient->pushRecord($metadata);
-					//$e = new mb_exception("classes/class_wms.php: result of pushing: ".$result);
-			}
+		//Propagate information for each new layer to csw if configured***************************
+		//select all layer which are searchable
+		$sql = "SELECT layer_id, uuid FROM layer WHERE fkey_wms_id = $1 and layer_searchable = 1";
+		$v = array($myWMS);
+		$t = array('i');
+		$res = db_prep_query($sql,$v,$t);
+		$insertedLayerArray = array();
+		while($row = db_fetch_array($res)){
+			$insertedLayerArray[] = $row['layer_id'];
 		}
-			    
-	    //Changes JW
-	    $this->wms_id = $myWMS;
+		$propagation = new propagateMetadata();
+		$result = $propagation->doPropagation("layer", $insertedLayerArray, "push", false);
+		//****************************************************************************************    
+	    	//Changes JW
+	    	$this->wms_id = $myWMS;
 	}
+
 	function insertLayer($i,$myWMS){
 		global $con;
 		$uuid = new Uuid();
@@ -3089,44 +3071,28 @@
 				}
 			}
 		}
-		//sync to metadatacatalogue (service metadata for each layer by uuid) if configured - use uuid 
-		//TODO need absolute url to srv metadata generator! - possible if invoked via shell (scheduler)? 
-		//
-		if (defined("SYNC_CHANGES_TO_CSW") && SYNC_CHANGES_TO_CSW == true && defined("SYNC_CATALOGUE_ID") && is_int(SYNC_CATALOGUE_ID)) {
-			if (defined("MAPBENDER_PATH") && MAPBENDER_PATH !== "") {
-				//layer service metadata generator 
-				$servMdPath = MAPBENDER_PATH."/php/mod_layerISOMetadata.php?SERVICE=WMS&outputFormat=iso19139&Id=";
+		//sync to metadatacatalogue (service metadata for each layer by uuid) if configured - use uuid*******
+		//delete old orphaned layer
+		$layerUuidsToDelete = array();
+		$layerIdsToPush = array();
+		foreach ($oldLayerNameArray as $oldLayer) {
+			if ($oldLayer['layer_searchable'] == "1") {
+				$layerUuidsToDelete[] = $oldLayer['uuid'];
+			}
+		}
+		//update existing layer
+		foreach ($updatedInsertedLayerArray as $updatedInsertedLayer) {
+			if ($updatedInsertedLayer['layer_searchable'] !== "1") {
+				$layerUuidsToDelete[] = $updatedInsertedLayer['uuid'];
 			} else {
-				$servMdPath = "http://".$_SERVER['HTTP_HOST']."/mapbender"."/php/mod_layerISOMetadata.php?SERVICE=WMS&outputFormat=iso19139&Id=";
+				$layerIdsToPush[] = $updatedInsertedLayer['id'];
 			}
-			$cswClient = new cswClient();
-			$cswClient->cswId = SYNC_CATALOGUE_ID;
-			//delete old orphaned layer
-			foreach ($oldLayerNameArray as $oldLayer) {
-				if ($oldLayer['layer_searchable'] == "1") {
-					//$e = new mb_exception("classes/class_wms.php: try to delete: ".$oldLayer['uuid']);
-					$result = $cswClient->deleteRecord($oldLayer['uuid']);
-					//$e = new mb_exception("classes/class_wms.php: delete metadata in csw: ".$result);
-				}
-			}
-			$isoMetadata = new Iso19139();
-			//update existing layer
-			foreach ($updatedInsertedLayerArray as $updatedInsertedLayer) {
-				//$e = new mb_exception("classes/class_wms.php: layer_searchable: ".gettype($updatedInsertedLayer['layer_searchable'])." - value: ".$updatedInsertedLayer['layer_searchable']);
-				if ($updatedInsertedLayer['layer_searchable'] !== "1") {
-					//$e = new mb_exception("classes/class_wms.php: try to delete: ".$updatedInsertedLayer['uuid']);
-					$result = $cswClient->deleteRecord($updatedInsertedLayer['uuid']);
-					//$e = new mb_exception("classes/class_wms.php: delete metadata in csw: ".$result);
-				} else {
-					//$e = new mb_exception("classes/class_wms.php: try to insert or update: ".$updatedInsertedLayer['uuid']);
-					$metadata = $isoMetadata->createFromUrl($servMdPath.$updatedInsertedLayer['id']);
-					//$e = new mb_exception("classes/class_wms.php: metadata url: ".$servMdPath.$updatedInsertedLayer['id']);
-					$result = $cswClient->pushRecord($metadata);
-					//$e = new mb_exception("classes/class_wms.php: insert or update metadata in csw: ".$result);
-				}
-			}
 		}
-		//
+		//do delete and push
+		$propagation = new propagateMetadata();
+		$result = $propagation->doPropagation("layer", false, "delete", $layerUuidsToDelete);
+		$result = $propagation->doPropagation("layer", $layerIdsToPush, "push", false);
+		//****************************************************************************************************
 		if ($authType != '') { //some authentication is needed! 
  			$admin = new administration(); 
  			echo "WMS ID: ".$myWMS; 



More information about the Mapbender_commits mailing list