[Mapbender-commits] r8365 - in trunk/mapbender/http: classes plugins

svn_mapbender at osgeo.org svn_mapbender at osgeo.org
Fri May 25 05:52:16 PDT 2012


Author: armin11
Date: 2012-05-25 05:52:15 -0700 (Fri, 25 May 2012)
New Revision: 8365

Modified:
   trunk/mapbender/http/classes/class_wfs.php
   trunk/mapbender/http/classes/class_wfsToDb.php
   trunk/mapbender/http/classes/class_wfs_1_0_factory.php
   trunk/mapbender/http/classes/class_wfs_1_1_factory.php
   trunk/mapbender/http/classes/class_wfs_factory.php
   trunk/mapbender/http/classes/class_wms.php
   trunk/mapbender/http/plugins/mb_metadata_wfs_server.php
Log:
Handling of MetadataURL for WFS featuretypes - have to be enhanced

Modified: trunk/mapbender/http/classes/class_wfs.php
===================================================================
--- trunk/mapbender/http/classes/class_wfs.php	2012-05-24 14:00:54 UTC (rev 8364)
+++ trunk/mapbender/http/classes/class_wfs.php	2012-05-25 12:52:15 UTC (rev 8365)
@@ -508,8 +508,8 @@
 	 * 
 	 * @return Boolean
 	 */
-	public function update () {
-		return WfsToDb::update($this);
+	public function update ($updateMetadataOnly=false) {
+		return WfsToDb::update($this,$updateMetadataOnly);
 	}
 	
 	/**

Modified: trunk/mapbender/http/classes/class_wfsToDb.php
===================================================================
--- trunk/mapbender/http/classes/class_wfsToDb.php	2012-05-24 14:00:54 UTC (rev 8364)
+++ trunk/mapbender/http/classes/class_wfsToDb.php	2012-05-25 12:52:15 UTC (rev 8365)
@@ -21,7 +21,8 @@
 require_once(dirname(__FILE__)."/class_connector.php");
 require_once(dirname(__FILE__)."/class_administration.php");
 require_once(dirname(__FILE__)."/class_wfs.php");
-require_once dirname(__FILE__) . "//class_Uuid.php";
+require_once dirname(__FILE__) . "/class_Uuid.php";
+//require_once dirname(__FILE__) . "//class_Uuid.php";
 
 class WfsToDb {
 
@@ -118,7 +119,7 @@
 	 * @return Boolean
 	 * @param $aWfs Wfs
 	 */
-	public static function update ($aWfs) {
+	public static function update ($aWfs,$updateMetadataOnly=false) {
 		db_begin();
 		
 		// update WFS
@@ -190,7 +191,7 @@
 			if (WfsToDb::featureTypeExists($currentFeatureType)) {
 				// update existing WFS feature types
 				$e = new mb_notice("class_wfsToDb.php: FT exists");
-				if (!WfsToDb::updateFeatureType($currentFeatureType)) {
+				if (!WfsToDb::updateFeatureType($currentFeatureType,$updateMetadataOnly)) {
 					db_rollback();
 					return false;
 				}
@@ -264,6 +265,9 @@
 	 * @param $aWfs Wfs
 	 */
 	public static function delete ($aWfs) {
+		//first delete coupled metadata, cause there is no contraints in the database to do so
+		$this->deleteFeatureTypeMetadataUrls($aWfs->id);
+		//then delete wfs itself
 		$sql = "DELETE FROM wfs WHERE wfs_id = $1";
 		$v = array($aWfs->id);
 		$t = array('i');
@@ -352,7 +356,109 @@
 		
 		return true;
 	}
+
 	/**
+	 * Inserts a new WFS feature type MetadataURL into the database.
+	 * 
+	 * @return Boolean
+	 * @param $aWfsFeatureTypeId Integer
+	 * @param $metadataUrl object
+	 */
+	private static function insertFeatureTypeMetadataUrl ($aWfsFeatureTypeId, $metadataUrl, $withParsing = false) {
+		$randomid = new Uuid();
+		if ($withParsing == true) {
+			//check if format can be parsed - possible only for one format (INSPIRE)
+			if (($metadataUrl->type == 'ISO19115:2003' && $metadataUrl->format =='text/xml') || ($metadataUrl->type == 'TC211' && $metadataUrl->format =='text/xml')) {
+				//extract all relevant information - maybe mapbender metadata object! TODO!!!
+				$metaData = "";
+				$uuid = "";
+				$title = "";
+				$createdate = "1900-01-01";
+				$changedate = "1900-01-01";
+				$abstract = "";
+				$keywords = "";
+				$type = "";
+				$tmp_reference_1 = "1900-01-01";
+				$tmp_reference_2 = "1900-01-01";
+				$export2csw = 't';
+				$datasetid = "";
+				//harvest metadata thru web
+				//harvest = 1;
+			}
+		} else {
+			$metaData = "";
+			$uuid = "";
+			$title = "";
+			$createdate = "1900-01-01";
+			$changedate = "1900-01-01";
+			$abstract = "";
+			$keywords = "";
+			$type = "";
+			$tmp_reference_1 = "1900-01-01";
+			$tmp_reference_2 = "1900-01-01";
+			$export2csw = 't';
+			$datasetid = "";		
+		}
+		//insert result into database
+		$sql = "INSERT INTO mb_metadata (link, origin, md_format, data, linktype, uuid, title, createdate, changedate, abstract, searchtext, type, tmp_reference_1, tmp_reference_2, export2csw, datasetid, randomid) ";
+		$sql .= "VALUES($1, 'capabilities', $2, $3, $4, $5, $6, $7, $8, $9, $10, $11, $12, $13, $14, $15, $16)";
+		$v = array($metadataUrl->href,
+			$metadataUrl->format,
+			$metaData,
+			$metadataUrl->type,
+			$uuid,
+			$title,
+			$createdate,
+			$changedate,
+			$abstract,
+			$keywords,
+			$type,
+			$tmp_reference_1,
+			$tmp_reference_2,
+			$export2csw,
+			$datasetid,
+			$randomid
+		);
+		$t = array('s','s','s','s','s','s','s','s','s','s','s','s','s','b','s','s');
+		$res = db_prep_query($sql,$v,$t);
+		if(!$res){
+			db_rollback();	
+		}
+		//get metadata id with uuid which was generated
+		$sql = <<<SQL
+
+SELECT metadata_id FROM mb_metadata WHERE randomid = $1 ORDER BY lastchanged DESC LIMIT 1
+
+SQL;
+		//maybe there are more than one results - which should be used??? case of creating new linkage with old metadata TODO TODO
+		$v = array($randomid);
+		$t = array('s');
+		try {
+			$res = db_prep_query($sql,$v,$t);
+		}
+		catch (Exception $e){
+			abort(_mb("Cannot get metadata record with following uuid from database: ".$uuid));
+		}
+		if ($res) {
+			$row = db_fetch_assoc($res);
+			$mdId = $row['metadata_id'];
+		}
+		//insert into ows_relation_metadata (fkey_layer_id, fkey_metadata_id) values (20131,3);
+		$sql = "INSERT INTO ows_relation_metadata (fkey_featuretype_id, fkey_metadata_id) values ($1, $2);";
+		$v = array($aWfsFeatureTypeId, $mdId);
+		$t = array('i','i');
+		$res = db_prep_query($sql,$v,$t);
+		if(!$res){
+			db_rollback();
+			$e = new mb_exception("MetadataURL of featuretype with id: ".$aWfsFeatureTypeId." cannot be stored to database!");
+		}
+		$e = new mb_exception("INSERTING FT MetadataURL (FT: ".$aWfsFeatureTypeId.", MetadataURL: ".$metadataUrl->href);
+		return true;
+	}
+
+
+
+	/**
 	 * Inserts a new WFS feature type element into the database.
 	 * 
 	 * @return Boolean
@@ -522,7 +628,14 @@
 				return false;	
 			}
 		}
-
+		// insert feature type MetadataURL
+		$e = new mb_exception("Number of metadataurls for featuretype ".$aWfsFeatureType->id." : ".count($aWfsFeatureType->metadataUrlArray));
+		for ($i = 0; $i < count($aWfsFeatureType->metadataUrlArray); $i++) {
+			$metadataUrl = $aWfsFeatureType->metadataUrlArray[$i];
+			if (!WfsToDb::insertFeatureTypeMetadataUrl($aWfsFeatureType->id, $metadataUrl)) {
+				return false;	
+			}
+		}
 		// insert feature type namespaces
 		for ($i = 0; $i < count($aWfsFeatureType->namespaceArray); $i++) {
 			$namespace = $aWfsFeatureType->namespaceArray[$i];
@@ -539,7 +652,7 @@
 	 * @return Boolean
 	 * @param $aWfsFeatureType WfsFeatureType
 	 */
-	private static function updateFeatureType ($aWfsFeatureType) {
+	private static function updateFeatureType ($aWfsFeatureType, $updateMetadataOnly=false) {
 
 		$aWfsFeatureType->id = WfsToDb::getFeatureTypeId($aWfsFeatureType);
 
@@ -665,9 +778,41 @@
 					}
 				}
 			}	
-		}	
-		
-		
+		}
+
+		//update CRS and MetadataURLs only if update is not started via Metadata Editor
+		if (!$updateMetadataOnly) {
+			//update CRS
+			//delete supported CRS
+			$sql = "DELETE FROM wfs_featuretype_epsg WHERE fkey_featuretype_id = $1";
+			$v = array($aWfsFeatureType->id);
+			$t = array('i');
+			$res = db_prep_query($sql,$v,$t);
+			//insert new supported CRS
+			for ($i = 0; $i < count($aWfsFeatureType->crsArray); $i++) {
+				$crs = $aWfsFeatureType->crsArray[$i];
+				if (!WfsToDb::insertFeatureTypeCrs($aWfsFeatureType->id, $crs)) {
+					return false;	
+				}
+			}
+			//update MetadataURLs
+			//delete old MetadataURLs from caps
+			$sql = <<<SQL
+
+			DELETE FROM mb_metadata WHERE metadata_id IN (SELECT metadata_id FROM mb_metadata INNER JOIN (SELECT * from ows_relation_metadata WHERE fkey_featuretype_id = $1) as relation ON  mb_metadata.metadata_id = relation.fkey_metadata_id AND mb_metadata.origin = 'capabilities')
+
+SQL;
+			$v = array($aWfsFeatureType->id);
+			$t = array('i');
+			$res = db_prep_query($sql,$v,$t);
+			// insert feature type MetadataURL from caps
+			for ($i = 0; $i < count($aWfsFeatureType->metadataUrlArray); $i++) {
+				$metadataUrl = $aWfsFeatureType->metadataUrlArray[$i];
+				if (!WfsToDb::insertFeatureTypeMetadataUrl($aWfsFeatureType->id, $metadataUrl)) {
+					return false;	
+				}
+			}
+		}
 		// update keywords
 		$sql = "DELETE FROM wfs_featuretype_keyword WHERE fkey_featuretype_id = $1";
 		$v = array($aWfsFeatureType->id);
@@ -745,6 +890,37 @@
 	}
 	
 	/**
+	 * Deletes an implicitly coupled metadata of a wfs from the database.
+	 * 
+	 * 
+	 * @return Boolean
+	 * @param $wfsId integer
+	 */
+	private static function deleteFeatureTypeMetadataUrls ($wfsId) {
+
+
+		$sql = "DELETE FROM mb_metadata INNER JOIN (select * from ows_relation_metadata where (internal is NULL OR internal != 1) and fkey_featuretype_id in ";
+		$sql .= "(select fkey_featuretype_id from wfs_featuretype where fkey_wfs_id = $1)) as relation on ";
+		$sql .= "mb_metadata.metadata_id = relation.fkey_metadata_id where mb_metadata.origin = 'capabilities'";
+
+		$sql = "DELETE FROM mb_metadata WHERE metadata_id IN (SELECT metadata_id FROM mb_metadata INNER JOIN (SELECT * from ows_relation_metadata WHERE fkey_featuretype_id IN " ;
+		$sql .= "(SELECT featuretype_id FROM wfs_featuretype WHERE fkey_wfs_id = $1 ";
+		$sql .= ") AND ows_relation_metadata.internal != 1 )";
+		$sql .= " as relation ON  mb_metadata.metadata_id = relation.fkey_metadata_id AND mb_metadata.origin = 'capabilities')";
+
+		$v = array($wfsId);
+		$t = array('i');
+
+		$res = db_prep_query($sql, $v, $t);
+		if (!$res) {
+			$e = new mb_exception("Error while deleting coupled WFS MetadataURLs from database.");
+			return false;
+		}
+		return true;
+	}
+
+
+	/**
 	 * Checks if a featuretype exists in the database. It selects the rows
 	 * that match the WFS id and the featuretype name.
 	 * 

Modified: trunk/mapbender/http/classes/class_wfs_1_0_factory.php
===================================================================
--- trunk/mapbender/http/classes/class_wfs_1_0_factory.php	2012-05-24 14:00:54 UTC (rev 8364)
+++ trunk/mapbender/http/classes/class_wfs_1_0_factory.php	2012-05-25 12:52:15 UTC (rev 8365)
@@ -198,6 +198,20 @@
 					$featuretype_latlon_maxy = $LatLongBoundingBox->xpath('@maxy');
 					$featuretype_latlon_maxy = $featuretype_latlon_maxy[0];
 
+					//<wfs:MetadataURL type="FGDC" format="text/xml">http://www.ogccatservice.com/csw.cgi?service=CSW&amp;version=2.0.0&amp;request=GetRecords&amp;constraintlanguage=CQL&amp;constraint="recordid=urn:uuid:4ee8b2d3-9409-4a1d-b26b-6782e4fa3d59"</wfs:MetadataURL>
+					$metadataURLArray = $featureType->MetadataURL;
+					$featuretype_metadataUrl = array();
+					$i_mdu = 0;
+					foreach ($metadataURLArray as $metadataURL) {
+						//$e = new mb_exception("other srs: ".$otherSRS);
+						$featuretype_metadataUrl[$i_mdu]->href = $metadataURL;
+						$e = new mb_exception("metadataurl: ".$metadataURL);
+						$featuretype_metadataUrl[$i_mdu]->type = $metadataURL->attributes()->type;
+						$e = new mb_exception("type: ".$featuretype_metadataUrl[$i_mdu]->type);
+						$featuretype_metadataUrl[$i_mdu]->format = $metadataURL->attributes()->format;
+						$e = new mb_exception("format: ".$featuretype_metadataUrl[$i_mdu]->format);
+						$i_mdu++;
+					}
 					//do not add defective featuretypes - first request them via net
 					try {
 						$currentFeatureType = $this->createFeatureTypeFromUrl($myWfs, $featuretype_name);
@@ -210,6 +224,7 @@
 							$currentFeatureType->latLonBboxArray['miny'] = $featuretype_latlon_miny;
 							$currentFeatureType->latLonBboxArray['maxx'] = $featuretype_latlon_maxx;
 							$currentFeatureType->latLonBboxArray['maxy'] = $featuretype_latlon_maxy;
+							$currentFeatureType->metadataUrlArray = $featuretype_metadataUrl;
 							$myWfs->addFeatureType($currentFeatureType);
 						}
 					}

Modified: trunk/mapbender/http/classes/class_wfs_1_1_factory.php
===================================================================
--- trunk/mapbender/http/classes/class_wfs_1_1_factory.php	2012-05-24 14:00:54 UTC (rev 8364)
+++ trunk/mapbender/http/classes/class_wfs_1_1_factory.php	2012-05-25 12:52:15 UTC (rev 8365)
@@ -159,7 +159,7 @@
 	}
 
 	/**
-	 * Creates WFS 1.0 objects from a capabilities documents.
+	 * Creates a WFS 1.1 object from a capabilities document.
 	 *
 	 * @return Wfs_1_1
 	 * @param $xml String
@@ -275,7 +275,8 @@
 				$capFeatureTypes = $wfs11Cap->xpath('/wfs:WFS_Capabilities/wfs:FeatureTypeList/wfs:FeatureType');
 				$i = 1; //cause index of xml objects begin with 1
 				foreach ($capFeatureTypes as $featureType) {
-
+					//debug
+					$e = new mb_exception("ft: ".$featureType->asXML());
 					$featuretype_name = $featureType->Name[0];
 					$featuretype_title = $featureType->Title[0];
 					$featuretype_abstract = $featureType->Abstract[0];
@@ -283,10 +284,24 @@
 					$featuretype_srs = $featureType->DefaultSRS[0];
 					$otherSRSArray = $featureType->OtherSRS;
 					foreach ($otherSRSArray as $otherSRS) {
-						//$e = new mb_exception("other srs: ".$otherSRS);
+						$e = new mb_exception("other srs: ".$otherSRS);
 						$featuretype_crsArray[] = $otherSRS;
 						
 					}
+					//<wfs:MetadataURL type="FGDC" format="text/xml">http://www.ogccatservice.com/csw.cgi?service=CSW&amp;version=2.0.0&amp;request=GetRecords&amp;constraintlanguage=CQL&amp;constraint="recordid=urn:uuid:4ee8b2d3-9409-4a1d-b26b-6782e4fa3d59"</wfs:MetadataURL>
+					$metadataURLArray = $featureType->MetadataURL;
+					$featuretype_metadataUrl = array();
+					$i_mdu = 0;
+					foreach ($metadataURLArray as $metadataURL) {
+						//$e = new mb_exception("other srs: ".$otherSRS);
+						$featuretype_metadataUrl[$i_mdu]->href = $metadataURL;
+						$e = new mb_exception("metadataurl: ".$metadataURL);
+						$featuretype_metadataUrl[$i_mdu]->type = $metadataURL->attributes()->type;
+						$e = new mb_exception("type: ".$featuretype_metadataUrl[$i_mdu]->type);
+						$featuretype_metadataUrl[$i_mdu]->format = $metadataURL->attributes()->format;
+						$e = new mb_exception("format: ".$featuretype_metadataUrl[$i_mdu]->format);
+						$i_mdu++;
+					}
 					//<ows:WGS84BoundingBox dimensions="2"><ows:LowerCorner>-9.16611817848171e+15 -3.4016616708962e+32</ows:LowerCorner><ows:UpperCorner>464605646503609 3.4016616708962e+32</ows:UpperCorner></ows:WGS84BoundingBox>
 					$lowerCorner = $wfs11Cap->xpath('/wfs:WFS_Capabilities/wfs:FeatureTypeList/wfs:FeatureType['.$i.']/ows:WGS84BoundingBox/ows:LowerCorner');
 					$lowerCorner = $lowerCorner[0];
@@ -313,6 +328,7 @@
 							$currentFeatureType->latLonBboxArray['maxx'] = $featuretype_latlon_maxx;
 							$currentFeatureType->latLonBboxArray['maxy'] = $featuretype_latlon_maxy;
 							$currentFeatureType->crsArray = $featuretype_crsArray;
+							$currentFeatureType->metadataUrlArray = $featuretype_metadataUrl;
 							$myWfs->addFeatureType($currentFeatureType);
 						}
 					}

Modified: trunk/mapbender/http/classes/class_wfs_factory.php
===================================================================
--- trunk/mapbender/http/classes/class_wfs_factory.php	2012-05-24 14:00:54 UTC (rev 8364)
+++ trunk/mapbender/http/classes/class_wfs_factory.php	2012-05-25 12:52:15 UTC (rev 8365)
@@ -166,7 +166,24 @@
 					);
 					$cnt_crs++;
 				}
-
+				
+				// MetadataURLs
+				$sql_metadata = "SELECT link, linktype, md_format FROM mb_metadata WHERE metadata_id IN ";
+				$sql_metadata .= "(SELECT metadata_id FROM mb_metadata INNER JOIN (SELECT * from ows_relation_metadata WHERE ";
+				$sql_metadata .= "fkey_featuretype_id = $1) as relation ON  mb_metadata.metadata_id = relation.fkey_metadata_id AND ";
+				$sql_metadata .= "mb_metadata.origin = 'capabilities')";
+				$v = array($ft->id);
+				$t = array("i");
+				$res_metadata = db_prep_query($sql_metadata, $v, $t);
+				$cnt_metadata = 0;
+				while(db_fetch_row($res_metadata)){
+					$metadataURL->href = db_result($res_metadata, $cnt_metadata, "link");
+					$metadataURL->type = db_result($res_metadata, $cnt_metadata, "linktype");		
+					$metadataURL->format = db_result($res_metadata, $cnt_metadata, "md_format");	
+					$ft->addMetadataUrl($metadataURL);
+					$cnt_metadata++;
+				}
+				
 				//Namespaces
 				$sql_ns = "SELECT * FROM wfs_featuretype_namespace WHERE fkey_featuretype_id = $1 ORDER BY namespace";
 				$v = array($ft->id);

Modified: trunk/mapbender/http/classes/class_wms.php
===================================================================
--- trunk/mapbender/http/classes/class_wms.php	2012-05-24 14:00:54 UTC (rev 8364)
+++ trunk/mapbender/http/classes/class_wms.php	2012-05-25 12:52:15 UTC (rev 8365)
@@ -2499,7 +2499,7 @@
 						$res = db_prep_query($sql,$v,$t);
 					}		
 				} else {
-				//paring was not ok - fill only the urls into database and give a reasonable error message
+				//parsing was not ok - fill only the urls into database and give a reasonable error message
 					$sql = "INSERT INTO mb_metadata (link, origin, md_format, linktype) ";
 					$sql .= "VALUES($1, 'capabilities', $2, $3)";
 					$v = array($this->objLayer[$i]->layer_metadataurl[$j]->href,

Modified: trunk/mapbender/http/plugins/mb_metadata_wfs_server.php
===================================================================
--- trunk/mapbender/http/plugins/mb_metadata_wfs_server.php	2012-05-24 14:00:54 UTC (rev 8364)
+++ trunk/mapbender/http/plugins/mb_metadata_wfs_server.php	2012-05-25 12:52:15 UTC (rev 8365)
@@ -1185,7 +1185,7 @@
 		} else {
 			$wfs->network_access = intval('0');
 		}
-		$wfs->update();
+		$wfs->update(true); //parameter for metadata only update - some things are not pulled when creating object from database and some things need not to be updated.
 
 		
 		$ajaxResponse->setMessage("Updated WFS metadata for ID " . $wfsId);



More information about the Mapbender_commits mailing list