[Mapbender-commits] r8376 - in trunk/mapbender: http/classes http/plugins resources/db/pgsql/UTF-8/update

svn_mapbender at osgeo.org svn_mapbender at osgeo.org
Thu Jun 14 04:58:58 PDT 2012


Author: armin11
Date: 2012-06-14 04:58:58 -0700 (Thu, 14 Jun 2012)
New Revision: 8376

Modified:
   trunk/mapbender/http/classes/class_iso19139.php
   trunk/mapbender/http/classes/class_wfsToDb.php
   trunk/mapbender/http/classes/class_wms.php
   trunk/mapbender/http/plugins/mb_metadata_layer.js
   trunk/mapbender/http/plugins/mb_metadata_server.php
   trunk/mapbender/http/plugins/mb_metadata_wfs_server.php
   trunk/mapbender/resources/db/pgsql/UTF-8/update/update_2.7.2_to_2.7.3_pgsql_UTF-8.sql
Log:
Change of mb_metadata handling for INSPIRE and SDI conformity. Further TODOs: 1.  give back messages from class_iso19139 to metadata_server components. 2. control functions, 3. less debug messages, 4. Test all things

Modified: trunk/mapbender/http/classes/class_iso19139.php
===================================================================
--- trunk/mapbender/http/classes/class_iso19139.php	2012-06-12 12:12:46 UTC (rev 8375)
+++ trunk/mapbender/http/classes/class_iso19139.php	2012-06-14 11:58:58 UTC (rev 8376)
@@ -43,14 +43,17 @@
 	var $harvestException;
 	//new
 	var $lineage;
-	var $inspireTopConsistence; //bool
+	var $inspireTopConsistence; //db bool, 't' or 'f'
 	var $spatialResType;
 	var $spatialResValue;
-	var $export2Csw; //bool
+	var $export2Csw; //db bool, 't' or 'f'
 	var $updateFrequency;
 	var $dataFormat;
 	var $inspireCharset;
 
+	var $linkAlreadyInDB; //bool
+	var $fileIdentifierAlreadyInDB; //bool
+
 	function __construct() {
 		//initialize empty iso19139 object
 		$this->fileIdentifier = "";
@@ -83,6 +86,9 @@
 		$this->updateFrequency = "";
 		$this->dataFormat = "";
 		$this->inspireCharset = "";
+
+		$this->linkAlreadyInDB = false;
+		$this->fileIdentifierAlreadyInDB = false;
 	}
 
 	public function removeGetRecordTag ($xml) {
@@ -96,6 +102,7 @@
 	public function createMapbenderMetadataFromXML($xml){
 		$this->metadata = $xml;
 		$this->metadata = $this->removeGetRecordTag($this->metadata);
+		//$e = new mb_exception($this->metadata);
 		libxml_use_internal_errors(true);
 		try {
 			$iso19139Xml = simplexml_load_string($this->metadata);
@@ -113,6 +120,7 @@
 		}
 		//if parsing was successful
 		if ($iso19139Xml != false) {
+			$e = new mb_exception("Parsing of xml metadata file was successfull"); 
 			$this->fileIdentifier = $iso19139Xml->xpath('/gmd:MD_Metadata/gmd:fileIdentifier/gco:CharacterString');
 			$this->fileIdentifier = $this->fileIdentifier[0];
 			$this->createDate = $iso19139Xml->xpath('/gmd:MD_Metadata/gmd:dateStamp/gco:Date');
@@ -169,6 +177,12 @@
 	}
 	
 	public function createFromUrl($url){
+		$this->href = $url;
+		if ($this->isLinkAlreadyInDB() == false) {
+			$this->linkAlreadyInDB = false;
+		} else {
+			$this->linkAlreadyInDB = true;
+		}
 		$metadataConnector = new connector($url);
 		$metadataConnector->set("timeOut", "5");
 		$xml = $metadataConnector->file;
@@ -179,7 +193,7 @@
 	public function createFromDB($fileIdentifier){
 		return $this;
 	}
-
+	//TODO: following 2 classes are not used til now - check plugins mb_metadata_server scripts to exchange handling
 	public function deleteMetadataRelation($resourceType, $resourceId, $relationType){
 		//delete all relations which are defined from capabilities - this don't delete the metadata entries themself!
 		//all other relations stay alive
@@ -195,10 +209,37 @@
 		}
 	}
 
-public function checkMetadataRelation($resourceType, $resourceId, $metadataId){
-	//check if one relation already exists - if so no new one should be generated!!!
+	public function insertMetadataRelation($resourceType, $resourceId, $relationType){
+		//delete all relations which are defined from capabilities - this don't delete the metadata entries themself!
+		//all other relations stay alive
+		$sql = "DELETE FROM ows_relation_metadata WHERE fkey_".$resourceType."_id = $1 AND relation_type = '".$relationType."'";
+		$v = array($resourceId);
+		$t = array('i');
+		$res = db_prep_query($sql,$v,$t);
+		if(!$res){
+			$e = new mb_exception("Cannot delete metadata relations for resource ".$resourceType." with id: ".$resourceId);
+			return false;
+		} else {
+			return true;
+		}
 	}
 
+	public function checkMetadataRelation($resourceType, $resourceId, $metadataId){
+		//check if one relation already exists - if so no new one should be generated!!!
+		$sql = "SELECT count(fkey_metadata_id) FROM ows_relation_metadata WHERE fkey_".$resourceType."_id = $1 AND fkey_metadata_id = $2 AND relation_type = $3";
+		$v = array($resourceId, $metadataId, $this->origin);
+		$t = array('i','i','s');
+		$res = db_prep_query($sql,$v,$t);
+		while ($row = db_fetch_array($res)){
+			$numberOfRelations = $row['count'];	
+		}
+		if ($numberOfRelations > 0) {
+			return true;
+		} else {	
+			return false;
+		}
+	}
+
 	public function isLinkAlreadyInDB(){
 		$sql = <<<SQL
 SELECT metadata_id FROM mb_metadata WHERE link = $1 ORDER BY lastchanged DESC
@@ -292,23 +333,18 @@
 				$res = db_prep_query($sql,$v,$t);
 			}
 			catch (Exception $e){
-				$e = new mb_exception(_mb("Cannot get metadata record with following uuid from database: ".$uuid));
+				$e = new mb_exception(_mb("Cannot get metadata record with following random id from database: ".$this->randomId));
 			}
 			if (!$res) {
 				//do nothing
-				$e = new mb_exception(_mb("Cannot get metadata record with following uuid from database: ".$uuid));
+				$e = new mb_exception(_mb("Cannot find inserted metadata entry to store relation."));
 				return false;
 			} else {
 				//insert relation
 				$row = db_fetch_assoc($res);
 				$metadataId = $row['metadata_id'];
 				//insert relation to layer/featuretype
-				if ($resourceType == 'layer') {
-					$sql = "INSERT INTO ows_relation_metadata (fkey_layer_id, fkey_metadata_id, relation_type) values ($1, $2, $3);";
-				}
-				if ($resourceType == 'featuretype') {
-					$sql = "INSERT INTO ows_relation_metadata (fkey_featuretype_id, fkey_metadata_id, relation_type) values ($1, $2, $3);";
-				}
+				$sql = "INSERT INTO ows_relation_metadata (fkey_".$resourceType."_id, fkey_metadata_id, relation_type) values ($1, $2, $3);";	
 				$v = array($resourceId, $metadataId, $this->origin);
 				$t = array('i','i', 's');
 				$res = db_prep_query($sql,$v,$t);
@@ -334,12 +370,72 @@
 	}
 	
 	public function insertToDB($resourceType, $resourceId){
-		//check if metadata record already exists, if not create a new one, else insert relation only!
+		switch ($this->origin) {
+			case "capabilities":
+				//check if href is given and resource can be parsed
+				//following information must be given:
+				//randomId, href, format, type, origin, owner
+				if (($this->type == 'ISO19115:2003' && $this->format =='text/xml') || ($this->type == 'TC211' && $this->format =='text/xml') || ($this->type == 'ISO19115:2003' && $this->format =='text/vnd....')) {
+					$metadata = $this->createFromUrl($this->href); //will alter object itself
+					if ($metadata == false) {
+						//try to insert only MetadataURL elements
+						if (!$this->insertMetadataUrlToDB($resourceType, $resourceId)) {
+							$e = new mb_exception("Problem while storing MetadataURL entry from wms capabilities to mb_metadata table!");
+							return false;
+						} else {
+							$e = new mb_exception("Storing only MetadataURL ".$metadata->href." from capabilities to mb database cause the target could not be accessed or parsed!");
+							return true;
+						}
+					} 
+				}
+				break;
+			case "external":
+				//don't check format and type -cause they are not given. Otherwise the same as in case of capabilities
+				$metadata = $this->createFromUrl($this->href); //will alter object itself
+				if ($metadata == false) {
+					//try to insert only MetadataURL elements
+					if (!$this->insertMetadataUrlToDB($resourceType, $resourceId)) {
+						$e = new mb_exception("Problem while storing MetadataURL entry from wms capabilities to mb_metadata table!");
+						return false;
+					} else {
+						$e = new mb_exception("Storing only MetadataURL ".$metadata->href." from capabilities to mb database cause the target could not be accessed or parsed!");
+						return true;
+					}
+				} 
+				break;
+			case "metador":
+				//nothing to do at all?
+				break;
+			case "upload":
+				//nothing to do at all?
+				$e = new mb_exception("upload found");
+				//$e = new mb_exception($this->metadata);
+				$metadata = $this->createMapbenderMetadataFromXML($this->metadata);
+				
+				if ($metadata == false) {
+					//xml could not be parsed
+					
+					return false;
+				}
+				//else save it into database
+				break;
+			/*case "internal":
+				//only set relation to existing record - return true;
+				//is actually handled thru plugins/mn_metadata_server* 
+				break;*/
+			default:
+       				$e = new mb_exception( "Metadata origin is not known - please set it before storing values to DB!");
+				return false;
+		}
+
+		//check if metadata record already exists, if not create a new one, else insert relation only and update the metadata itself!
 		$metadataId = $this->isFileIdentifierAlreadyInDB();
 
 		if ($metadataId != false) {
 			//update the metadata - new random id set therefor there is no problem when setting the relation afterwards
 			$e = new mb_exception("existing metadata fileIdentifier found at metadata with id: ".$metadataId[0]." - update will be performed");
+			//check if the timestamp of an existing metadata element is not newer than the timestamp of the current metadata object!!!!
+			//TODO
 			//problem: <<<SQL have a limited number of chars!
 			$sql = "UPDATE mb_metadata SET link = $1, origin = $18, md_format = $2, data = $3, ";
 			$sql .= "linktype = $4, uuid = $5, title = $6, createdate = $7, changedate = $8, lastchanged = now(), ";
@@ -383,7 +479,7 @@
 
 		} else {
 			//insert new record
-			$e = new mb_exception("existing metadata fileIdentifier found at metadata with id: ".$metadataId[0]);
+			$e = new mb_exception("No existing metadata fileIdentifier found in mapbender metadata table. New record will be inserted with uuid: ".$this->fileIdentifier);
 
 			$sql = <<<SQL
 INSERT INTO mb_metadata (lastchanged, link, origin, md_format, data, linktype, uuid, title, createdate, changedate, abstract, searchtext, type, tmp_reference_1, tmp_reference_2, export2csw, datasetid, datasetid_codespace, randomid, fkey_mb_user_id, harvestresult, harvestexception, lineage, inspire_top_consistence, spatial_res_type, spatial_res_value, update_frequency, format, inspire_charset)  VALUES(now(), $1, $18, $2, $3, $4, $5, $6, $7, $8, $9, $10, $11, $12, $13, $14, $15, $16, $17, $19, $20, $21, $22, $23, $24, $25, $26, $27, $28)
@@ -434,7 +530,6 @@
 			$sql = <<<SQL
 SELECT metadata_id FROM mb_metadata WHERE randomid = $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($this->randomId);
 			$t = array('s');
 			try {
@@ -451,13 +546,13 @@
 				//insert relation
 				$row = db_fetch_assoc($res);
 				$metadataId = $row['metadata_id'];
+				//check if current relation already exists in case of upload
+				if ($this->checkMetadataRelation($resourceType, $resourceId, $metadataId)) {
+					$e = new mb_exception(_mb("Relation already exists - it will not be generated twice!"));
+					return true;
+				}
 				//insert relation to layer/featuretype
-				if ($resourceType == 'layer') {
-					$sql = "INSERT INTO ows_relation_metadata (fkey_layer_id, fkey_metadata_id, relation_type) values ($1, $2, $3);";
-				}
-				if ($resourceType == 'featuretype') {
-					$sql = "INSERT INTO ows_relation_metadata (fkey_featuretype_id, fkey_metadata_id, relation_type) values ($1, $2, $3);";
-				}
+				$sql = "INSERT INTO ows_relation_metadata (fkey_".$resourceType."_id, fkey_metadata_id, relation_type) values ($1, $2, $3);";
 				$v = array($resourceId, $metadataId, $this->origin);
 				$t = array('i','i','s');
 				$res = db_prep_query($sql,$v,$t);

Modified: trunk/mapbender/http/classes/class_wfsToDb.php
===================================================================
--- trunk/mapbender/http/classes/class_wfsToDb.php	2012-06-12 12:12:46 UTC (rev 8375)
+++ trunk/mapbender/http/classes/class_wfsToDb.php	2012-06-14 11:58:58 UTC (rev 8376)
@@ -376,60 +376,20 @@
 		//delete old relations for this resource - only those which are from 'capabilities'
 		$mbMetadata_1 = new Iso19139();
 		$mbMetadata_1->deleteMetadataRelation("featuretype", $aWfsFeatureTypeId,"capabilities");
-		//check for returned format?
-		if (($metadataUrl->type == 'ISO19115:2003' && $metadataUrl->format =='text/xml') || ($metadataUrl->type == 'TC211' && $metadataUrl->format =='text/xml')) {
-			//load metadata from link
-			$mbMetadata = new Iso19139();
-			$randomid = new Uuid();
-			$mbMetadata = $mbMetadata->createFromUrl($metadataUrl->href);
-			$mdOwner = Mapbender::session()->get("mb_user_id");
-			$e = new mb_exception("owner: ".$mdOwner);
-				
-			if ($mbMetadata != false) { //metadata has been parsed
-				//set randomId for metadata
-				$mbMetadata->randomId = $randomid;
-				$mbMetadata->href = $metadataUrl->href;
-				$mbMetadata->format = $metadataUrl->format;
-				$mbMetadata->type = $metadataUrl->type;
-				$mbMetadata->origin = "capabilities";
-				$mbMetadata->owner = $mdOwner;
-				//push metadata object into database
-				if (!$mbMetadata->insertToDB("featuretype",$aWfsFeatureTypeId)) {
-					$e = new mb_exception("Problem while storing metadata to mb_metadata table!");
-				} else {
-					$e = new mb_notice("Metadata with id ".$randomid." stored to db!");
-				}
-			} else {
-				//parsing had problems - fill only the urls into database and give a reasonable error message	
-				$mbMetadata = new Iso19139();
-				$mbMetadata->randomId = $randomid;
-				$mbMetadata->href = $metadataUrl->href;
-				$mbMetadata->format = $metadataUrl->format;
-				$mbMetadata->type = $metadataUrl->type;
-				$mbMetadata->origin = "capabilities";
-				$mbMetadata->owner = $mdOwner;
-				if (!$mbMetadata->insertMetadataUrlToDB("featuretype",$aWfsFeatureTypeId)) {
-					$e = new mb_exception("Problem while storing MetadataURL entry from wfs capabilities to mb_metadata table!");
-				} else {
-					$e = new mb_exception("Stored MetadataURL ".$mbMetadata->href." from wfs capabilities to mb database cause the target could not be accessed or parsed!");
-				}
-			}	
+		//delete object?
+		$mbMetadata = new Iso19139();
+		$randomid = new Uuid();
+		$mdOwner = Mapbender::session()->get("mb_user_id");
+		$mbMetadata->randomId = $randomid;
+		$mbMetadata->href = $metadataUrl->href;
+		$mbMetadata->format = $metadataUrl->format;
+		$mbMetadata->type = $metadataUrl->type;
+		$mbMetadata->origin = "capabilities";
+		$mbMetadata->owner = $mdOwner;
+		if (!$mbMetadata->insertToDB("featuretype",$aWfsFeatureTypeId)){
+			$e = new mb_exception("Problem while storing metadata to mb_metadata table!");
 		} else {
-			//insert link into database but do not try to parse the metadata
-			$mbMetadata = new Iso19139();
-			$mbMetadata->randomId = $randomid;
-			$mbMetadata->href = $metadataUrl->href;
-			$mbMetadata->format = $metadataUrl->format;
-			$mbMetadata->type = $metadataUrl->type;
-			$mbMetadata->origin = "capabilities";
-			$mbMetadata->owner = $mdOwner;
-			$mbMetadata->harvestException = "Metadata format is not known to mapbender!";
-			$mbMetadata->harvestResult = 0;
-			if (!$mbMetadata->insertMetadataUrlToDB("featuretype",$aWfsFeatureTypeId)) {
-				$e = new mb_exception("Problem while storing MetadataURL entry from wfs capabilities to mb_metadata table!");
-			} else {
-				$e = new mb_exception("Stored MetadataURL ".$mbMetadata->href." from wfs capabilities to mb database cause the target could not be accessed or parsed!");
-			}		
+			$e = new mb_exception("Stored metadata from capabilities to mapbender database!");
 		}
 		return true;
 	}

Modified: trunk/mapbender/http/classes/class_wms.php
===================================================================
--- trunk/mapbender/http/classes/class_wms.php	2012-06-12 12:12:46 UTC (rev 8375)
+++ trunk/mapbender/http/classes/class_wms.php	2012-06-14 11:58:58 UTC (rev 8376)
@@ -12,7 +12,6 @@
 require_once dirname(__FILE__) . "/class_administration.php";
 require_once dirname(__FILE__) . "/class_georss_factory.php";
 require_once dirname(__FILE__) . "/class_mb_exception.php";
-$e = new mb_exception("test");
 require_once dirname(__FILE__) . "/class_iso19139.php";
 require_once dirname(__FILE__) . "/../classes/class_universal_wms_factory.php";
 
@@ -2369,68 +2368,23 @@
 		$mbMetadata_1->deleteMetadataRelation("layer", $this->objLayer[$i]->db_id,"capabilities");
 		//delete object?
 		for($j=0; $j<count($this->objLayer[$i]->layer_metadataurl);$j++){
-			//check for returned format?
-			if (($this->objLayer[$i]->layer_metadataurl[$j]->type == 'ISO19115:2003' && $this->objLayer[$i]->layer_metadataurl[$j]->format =='text/xml') || ($this->objLayer[$i]->layer_metadataurl[$j]->type == 'TC211' && $this->objLayer[$i]->layer_metadataurl[$j]->format =='text/xml')) {
-				//load metadata from link
-				$mbMetadata = new Iso19139();
-				$randomid = new Uuid();
-				$mbMetadata = $mbMetadata->createFromUrl($this->objLayer[$i]->layer_metadataurl[$j]->href);
-				$mdOwner = Mapbender::session()->get("mb_user_id");
-				$e = new mb_exception("owner: ".$mdOwner);
-				
-				if ($mbMetadata != false) { //metadata has been parsed
-					//set randomId for metadata
-					$mbMetadata->randomId = $randomid;
-					$mbMetadata->href = $this->objLayer[$i]->layer_metadataurl[$j]->href;
-					$mbMetadata->format = $this->objLayer[$i]->layer_metadataurl[$j]->format;
-					$mbMetadata->type = $this->objLayer[$i]->layer_metadataurl[$j]->type;
-					$mbMetadata->origin = "capabilities";
-					$mbMetadata->owner = $mdOwner;
-
-
-					//push metadata object into database
-					if (!$mbMetadata->insertToDB("layer",$this->objLayer[$i]->db_id)) {
-						$e = new mb_exception("Problem while storing metadata to mb_metadata table!");
-					} else {
-						$e = new mb_notice("Metadata with id ".$randomid." stored to db!");
-					}
-				} else {
-					//parsing had problems - fill only the urls into database and give a reasonable error message	
-					$mbMetadata = new Iso19139();
-					$mbMetadata->randomId = $randomid;
-					$mbMetadata->href = $this->objLayer[$i]->layer_metadataurl[$j]->href;
-					$mbMetadata->format = $this->objLayer[$i]->layer_metadataurl[$j]->format;
-					$mbMetadata->type = $this->objLayer[$i]->layer_metadataurl[$j]->type;
-					$mbMetadata->origin = "capabilities";
-					$mbMetadata->owner = $mdOwner;
-					if (!$mbMetadata->insertMetadataUrlToDB("layer",$this->objLayer[$i]->db_id)) {
-						$e = new mb_exception("Problem while storing MetadataURL entry from wms capabilities to mb_metadata table!");
-					} else {
-						$e = new mb_notice("Stored MetadataURL ".$mbMetadata->href." from wms capabilities to mb database cause the target could not be accessed or parsed!");
-					}
-				}	
+			$mbMetadata = new Iso19139();
+			$randomid = new Uuid();
+			$mdOwner = Mapbender::session()->get("mb_user_id");
+			$mbMetadata->randomId = $randomid;
+			$mbMetadata->href = $this->objLayer[$i]->layer_metadataurl[$j]->href;
+			$mbMetadata->format = $this->objLayer[$i]->layer_metadataurl[$j]->format;
+			$mbMetadata->type = $this->objLayer[$i]->layer_metadataurl[$j]->type;
+			$mbMetadata->origin = "capabilities";
+			$mbMetadata->owner = $mdOwner;
+			if (!$mbMetadata->insertToDB("layer",$this->objLayer[$i]->db_id)){
+				$e = new mb_exception("Problem while storing metadata to mb_metadata table!");
 			} else {
-				//insert link into database but do not try to parse the metadata
-				$mbMetadata = new Iso19139();
-				$mbMetadata->randomId = $randomid;
-				$mbMetadata->href = $this->objLayer[$i]->layer_metadataurl[$j]->href;
-				$mbMetadata->format = $this->objLayer[$i]->layer_metadataurl[$j]->format;
-				$mbMetadata->type = $this->objLayer[$i]->layer_metadataurl[$j]->type;
-				$mbMetadata->origin = "capabilities";
-				$mbMetadata->owner = $mdOwner;
-				$mbMetadata->harvestException = "Metadata format is not known to mapbender!";
-				$mbMetadata->harvestResult = 0;
-				if (!$mbMetadata->insertMetadataUrlToDB("layer",$this->objLayer[$i]->db_id)) {
-					$e = new mb_exception("Problem while storing MetadataURL entry from wms capabilities to mb_metadata table!");
-				} else {
-					$e = new mb_notice("Stored MetadataURL ".$mbMetadata->href." from wms capabilities to mb database cause the target could not be accessed or parsed!");
-				}
-				
+				$e = new mb_exception("Stored metadata from capabilities to mapbender database!");
 			}
 		}
 	}
 
-
 	function updateObjInDB($myWMS,$updateMetadataOnly=false){ //TODO give return true or false to allow feedback to user!!!
 		if (!isset($this->wms_network_access) || ($this->wms_network_access == '')) {
 			$this->wms_network_access = intval('0');

Modified: trunk/mapbender/http/plugins/mb_metadata_layer.js
===================================================================
--- trunk/mapbender/http/plugins/mb_metadata_layer.js	2012-06-12 12:12:46 UTC (rev 8375)
+++ trunk/mapbender/http/plugins/mb_metadata_layer.js	2012-06-14 11:58:58 UTC (rev 8376)
@@ -131,6 +131,7 @@
 						$("<tr class='metadataEntry'><td>"+obj.md_metadata.metadata_id[i]+"</td><td><img src='../img/edit-select-all-ilink.png' title='link to external edited metadata'/><td><a href='../php/mod_dataISOMetadata.php?outputFormat=iso19139&id="+obj.md_metadata.uuid[i]+"' target='_blank'>"+obj.md_metadata.uuid[i]+"</a></td><td><a href='../php/mod_dataISOMetadata.php?outputFormat=iso19139&id="+obj.md_metadata.uuid[i]+"&validate=true' target='_blank'>validate</a></td><td><img  class='' title='edit' src='../img/pencil.png' onclick='initMetadataAddon("+obj.md_metadata.metadata_id[i]+","+layerId+",false);return false;'/></td><td><img class='' title='delete' src='../img/cross.png' onclick='deleteInternalMetadataLinkage("+obj.md_metadata.metadata_id[i]+","+layerId+");return false;'/></td></tr>").appendTo($("#metadataTable"));
 					} else {
 						$("<tr class='metadataEntry'><td>"+obj.md_metadata.metadata_id[i]+"</td><td><img src='../img/gnome/edit-select-all.png' title='metadata'/><td><a href='../php/mod_dataISOMetadata.php?outputFormat=iso19139&id="+obj.md_metadata.uuid[i]+"' target='_blank'>"+obj.md_metadata.uuid[i]+"</a></td><td><a href='../php/mod_dataISOMetadata.php?outputFormat=iso19139&id="+obj.md_metadata.uuid[i]+"&validate=true' target='_blank'>validate</a></td><td><img  class='' title='edit' src='../img/pencil.png' onclick='initMetadataAddon("+obj.md_metadata.metadata_id[i]+","+layerId+",false);return false;'/></td><td><img class='' title='delete' src='../img/cross.png' onclick='deleteAddedMetadata("+obj.md_metadata.metadata_id[i]+","+layerId+");return false;'/></td></tr>").appendTo($("#metadataTable"));
+
 					}
 				}
 		}

Modified: trunk/mapbender/http/plugins/mb_metadata_server.php
===================================================================
--- trunk/mapbender/http/plugins/mb_metadata_server.php	2012-06-12 12:12:46 UTC (rev 8375)
+++ trunk/mapbender/http/plugins/mb_metadata_server.php	2012-06-14 11:58:58 UTC (rev 8376)
@@ -282,12 +282,12 @@
 
 
 
-		//get MetadataURLs from md_metadata table
+		//get coupled MetadataURLs from md_metadata and ows_relation_metadata table
 		$sql = <<<SQL
-SELECT metadata_id, uuid, link, linktype, md_format, origin, relation.internal FROM mb_metadata 
+SELECT metadata_id, uuid, link, linktype, md_format, relation.relation_type, origin FROM mb_metadata 
 INNER JOIN (SELECT * from ows_relation_metadata 
 WHERE fkey_layer_id = $layerId ) as relation ON 
-mb_metadata.metadata_id = relation.fkey_metadata_id WHERE mb_metadata.origin IN ('capabilities','external','metador','upload')
+mb_metadata.metadata_id = relation.fkey_metadata_id WHERE relation.relation_type IN ('capabilities','external','metador','upload', 'internal')
 SQL;
 		$res = db_query($sql);
 		$resultObj["md_metadata"]->metadata_id = array();
@@ -303,7 +303,11 @@
 			$resultObj["md_metadata"]->uuid[$i]= $row["uuid"];
 			$resultObj["md_metadata"]->origin[$i]= $row["origin"];
 			$resultObj["md_metadata"]->linktype[$i]= $row["linktype"];
-			$resultObj["md_metadata"]->internal[$i]= $row["internal"]; 
+			if ($row["relation_type"] == "internal") {
+				$resultObj["md_metadata"]->internal[$i] = 1;
+			} else {
+				$resultObj["md_metadata"]->internal[$i] = 0;
+			}
 			$i++;
 		}
 		$ajaxResponse->setResult($resultObj);
@@ -721,11 +725,22 @@
 		
 		$user = new User(Mapbender::session()->get("mb_user_id"));
 		//$e = new mb_exception("plugins/mb_metadata_wfs_server.php: user_id: ".$user->id);
-		$sql = <<<SQL
+		//Here a new handling is needed. Get coupled metadata entries from owned services - ows / content /md_relation / title of the coupled metadata maybe extented with union on owned metadata entries from big metador
 
-SELECT metadata_id, title, fkey_layer_id FROM mb_metadata INNER JOIN ows_relation_metadata ON ows_relation_metadata.fkey_metadata_id = mb_metadata.metadata_id WHERE fkey_mb_user_id = $1 AND fkey_layer_id IS DISTINCT FROM $2 ORDER BY metadata_id ASC
+$sql = <<<SQL
 
+select metadata_id, title from (select fkey_metadata_id from (select layer_id from
+ (select wms_id from wms where wms_owner = $1) wms inner join layer on wms.wms_id = layer.fkey_wms_id) layer 
+inner join ows_relation_metadata on layer.layer_id = ows_relation_metadata.fkey_layer_id where layer.layer_id <> $2) ows_r_m inner 
+join mb_metadata on ows_r_m.fkey_metadata_id = mb_metadata.metadata_id union 
+select distinct metadata_id, title from (select fkey_metadata_id from (select featuretype_id 
+from (select wfs_id from wfs where wfs_owner = $1) wfs inner join wfs_featuretype on 
+wfs.wfs_id = wfs_featuretype.fkey_wfs_id) featuretype inner join ows_relation_metadata on 
+featuretype.featuretype_id = ows_relation_metadata.fkey_featuretype_id) ows_r_m inner 
+join mb_metadata on ows_r_m.fkey_metadata_id = mb_metadata.metadata_id
+
 SQL;
+
 		$v = array($user->id, $layerId);
 		$t = array('i','i');
 		$res = db_prep_query($sql,$v,$t);
@@ -842,37 +857,17 @@
 		//Check if origin is external and export2csw is activated!
 		if ($origin == 'external' ) {
 			//harvest link from location, parse the content for datasetid and push xml into data column
-			$mbMetadata = $mbMetadata->createFromUrl($mbMetadata->href);
 			$mdOwner = Mapbender::session()->get("mb_user_id");
-			$e = new mb_exception("owner: ".$mdOwner);	
-			if ($mbMetadata != false) { //metadata has been parsed
-				//set randomId for metadata
-				$mbMetadata->randomId = $randomid;
-				$mbMetadata->format = "text/xml";
-				$mbMetadata->type = "ISO19115:2003";
-				$mbMetadata->origin = "external";
-				$mbMetadata->owner = $mdOwner;
-				//push metadata object into database
-				if (!$mbMetadata->insertToDB("layer",$layerId)) {
-					$e = new mb_exception("Problem while storing metadata to mb_metadata table!");
-				} else {
-					$e = new mb_notice("Metadata with id ".$randomid." stored to db!");
-				}
+			$mbMetadata->randomId = $randomid;
+			$mbMetadata->format = "text/xml";
+			$mbMetadata->type = "ISO19115:2003";
+			$mbMetadata->origin = "external";
+			$mbMetadata->owner = $mdOwner;
+			if (!$mbMetadata->insertToDB("layer",$layerId)){
+				$e = new mb_exception("Problem while storing metadata to mb_metadata table!");
 			} else {
-				//parsing had problems - fill only the urls into database and give a reasonable error message	
-				$mbMetadata = new Iso19139();
-				$mbMetadata->randomId = $randomid;
-				$mbMetadata->format = "text/xml";
-				$mbMetadata->type = "ISO19115:2003";
-				$mbMetadata->origin = "external";
-				$mbMetadata->owner = $mdOwner;
-				if (!$mbMetadata->insertMetadataUrlToDB("layer",$layerId)) {
-					$e = new mb_exception("Problem while storing MetadataURL entry from wms capabilities to mb_metadata table!");
-				} else {
-					$e = new mb_exception("Stored MetadataURL ".$mbMetadata->href." from wms capabilities to mb database cause the target could not be accessed or parsed!");
-				}
+				$e = new mb_exception("Stored metadata from external link to mapbender database!");
 			}	
-			
 		} else { //fill thru metador
 			$mbMetadata->origin = "metador";
 			$mbMetadata->fileIdentifier = $uuid;
@@ -893,7 +888,7 @@
 		$layerId = $ajaxResponse->getParameter("layerId");
 		$sql = <<<SQL
 
-DELETE FROM ows_relation_metadata WHERE fkey_metadata_id = $1 and fkey_layer_id = $2 and internal = 1
+DELETE FROM ows_relation_metadata WHERE fkey_metadata_id = $1 and fkey_layer_id = $2 and relation_type  = 'internal'
 		
 SQL;
 		$v = array($metadataId, $layerId);
@@ -934,16 +929,15 @@
 		$ajaxResponse->setMessage("Metadata deleted!");
 		$ajaxResponse->setSuccess(true);
 		break;
-//***********************
+
 	case "importLayerXmlAddon" :
-	//this case is similar to insert the metadata from external link, but came from internal file from tmp folder which has been uploaded before
+		//this case is similar to insert the metadata from external link, but came from internal file from tmp folder which has been uploaded before
 		$layerId = $ajaxResponse->getParameter("layerId");
 		$filename = $ajaxResponse->getParameter("filename");
 		//normaly the link is only set if a link has been created
 		//if a record has been created, the link element will be empty 
 		//use this to distinguish between the to different inserts!
 		//this insert should also push one entry in the ows_relation_metadata table! - after the insert into md_metadata
-		$uuid = new Uuid();
 		$randomid = new Uuid();	
 		$e = new mb_notice("File to load: ".$filename);
 		$metaData = file_get_contents($filename);
@@ -952,28 +946,21 @@
 		}
 		$mbMetadata = new Iso19139();
 		$mdOwner = Mapbender::session()->get("mb_user_id");
-		$mbMetadata = $mbMetadata->createMapbenderMetadataFromXML($metaData);	
-		$e = new mb_exception("Result of parsing: ".$mbMetadata);
-		if ($mbMetadata != false) { //metadata has been parsed
-			//set randomId for metadata
-			$mbMetadata->randomId = $randomid;
-			$mbMetadata->format = "text/xml";
-			$mbMetadata->type = "ISO19115:2003";
-			$mbMetadata->origin = "upload";
-			$mbMetadata->owner = $mdOwner;
-			//push metadata object into database
-			if (!$mbMetadata->insertToDB("layer",$layerId)) {
-				$e = new mb_exception("Problem while storing uploaded metadata xml to mb_metadata table!");			abort("Problem while storing uploaded metadata xml to mb_metadata table!");
-			} else {
-				$e = new mb_exception("Metadata with id ".$randomid." stored to db!");
-			}
+		$mbMetadata->randomId = $randomid;
+		$mbMetadata->metadata = $metaData;
+		$mbMetadata->format = "text/xml";
+		$mbMetadata->type = "ISO19115:2003";
+		$mbMetadata->origin = "upload";
+		$mbMetadata->owner = $mdOwner;
+		if (!$mbMetadata->insertToDB("layer",$layerId)) {
+			$e = new mb_exception("Problem while storing uploaded metadata xml to mb_metadata table!");		abort("Problem while storing uploaded metadata xml to mb_metadata table!");
 		} else {
-			abort("Could not parse metadata from local file!");
-		}				
+			$e = new mb_exception("Metadata with random id ".$randomid." stored to db!");
+			abort("Metadata from local file was uploaded!");
+		}
 		$ajaxResponse->setMessage("Uploaded metadata object inserted into md_metadata table!");
 		$ajaxResponse->setSuccess(true);		
-	break;		
-//***********************
+		break;		
 
 	default: 
 		$ajaxResponse->setSuccess(false);

Modified: trunk/mapbender/http/plugins/mb_metadata_wfs_server.php
===================================================================
--- trunk/mapbender/http/plugins/mb_metadata_wfs_server.php	2012-06-12 12:12:46 UTC (rev 8375)
+++ trunk/mapbender/http/plugins/mb_metadata_wfs_server.php	2012-06-14 11:58:58 UTC (rev 8376)
@@ -266,12 +266,12 @@
 		$resultObj['inspire_download'] = $resultObj['inspire_download'] == 1 ? true : false;
 
 
-		//get MetadataURLs from md_metadata table
+		//get MetadataURLs from md_metadata and ows_relation_metadata table
 		$sql = <<<SQL
-SELECT metadata_id, uuid, link, linktype, md_format, origin, relation.internal FROM mb_metadata 
+SELECT metadata_id, uuid, link, linktype, md_format, relation.relation_type, origin FROM mb_metadata 
 INNER JOIN (SELECT * from ows_relation_metadata 
 WHERE fkey_featuretype_id = $featuretypeId ) as relation ON 
-mb_metadata.metadata_id = relation.fkey_metadata_id WHERE mb_metadata.origin IN ('capabilities','external','metador','upload')
+mb_metadata.metadata_id = relation.fkey_metadata_id WHERE relation.relation_type IN ('capabilities','external','metador','upload', 'internal')
 SQL;
 		$res = db_query($sql);
 		$resultObj["md_metadata"]->metadata_id = array();
@@ -287,7 +287,13 @@
 			$resultObj["md_metadata"]->uuid[$i]= $row["uuid"];
 			$resultObj["md_metadata"]->origin[$i]= $row["origin"];
 			$resultObj["md_metadata"]->linktype[$i]= $row["linktype"];
-			$resultObj["md_metadata"]->internal[$i]= $row["internal"];
+			if ( $row["relation_type"] == "internal") {
+				$resultObj["md_metadata"]->internal[$i] = 1;
+			}
+			else {
+				$resultObj["md_metadata"]->internal[$i] = 0;
+			}
+			//$resultObj["md_metadata"]->internal[$i]= $row["internal"];
 			$i++;
 		}
 
@@ -494,14 +500,24 @@
 		$featuretypeId = $ajaxResponse->getParameter("featuretypeId");
 		
 		$user = new User(Mapbender::session()->get("mb_user_id"));
-		//$e = new mb_exception("plugins/mb_metadata_wfs_server.php: user_id: ".$user->id);
-		$sql = <<<SQL
+		//Here a new handling is needed. Get coupled metadata entries from owned services - ows / content /md_relation / title of the coupled metadata maybe extented with union on owned metadata entries from big metador
 
-SELECT metadata_id, title, fkey_featuretype_id FROM mb_metadata INNER JOIN ows_relation_metadata ON ows_relation_metadata.fkey_metadata_id = mb_metadata.metadata_id WHERE fkey_mb_user_id = $1 AND fkey_featuretype_id IS DISTINCT FROM $2 ORDER BY metadata_id ASC
+$sql = <<<SQL
 
+select metadata_id, title from (select fkey_metadata_id from (select layer_id from
+ (select wms_id from wms where wms_owner = $1) wms inner join layer on wms.wms_id = layer.fkey_wms_id) layer 
+inner join ows_relation_metadata on layer.layer_id = ows_relation_metadata.fkey_layer_id) ows_r_m inner 
+join mb_metadata on ows_r_m.fkey_metadata_id = mb_metadata.metadata_id union 
+select distinct metadata_id, title from (select fkey_metadata_id from (select featuretype_id 
+from (select wfs_id from wfs where wfs_owner = $1) wfs inner join wfs_featuretype on 
+wfs.wfs_id = wfs_featuretype.fkey_wfs_id) featuretype inner join ows_relation_metadata on 
+featuretype.featuretype_id = ows_relation_metadata.fkey_featuretype_id) ows_r_m inner 
+join mb_metadata on ows_r_m.fkey_metadata_id = mb_metadata.metadata_id
+
 SQL;
-		$v = array($user->id, $featuretypeId);
-		$t = array('i','i');
+
+		$v = array($user->id);
+		$t = array('i');
 		$res = db_prep_query($sql,$v,$t);
 		$row = array();
 		$resultObj = array();
@@ -616,37 +632,17 @@
 		//Check if origin is external and export2csw is activated!
 		if ($origin == 'external' ) {
 			//harvest link from location, parse the content for datasetid and push xml into data column
-			$mbMetadata = $mbMetadata->createFromUrl($mbMetadata->href);
 			$mdOwner = Mapbender::session()->get("mb_user_id");
-			$e = new mb_exception("owner: ".$mdOwner);	
-			if ($mbMetadata != false) { //metadata has been parsed
-				//set randomId for metadata
-				$mbMetadata->randomId = $randomid;
-				$mbMetadata->format = "text/xml";
-				$mbMetadata->type = "ISO19115:2003";
-				$mbMetadata->origin = "external";
-				$mbMetadata->owner = $mdOwner;
-				//push metadata object into database
-				if (!$mbMetadata->insertToDB("featuretype",$featuretypeId)) {
-					$e = new mb_exception("Problem while storing metadata to mb_metadata table!");
-				} else {
-					$e = new mb_notice("Metadata with id ".$randomid." stored to db!");
-				}
+			$mbMetadata->randomId = $randomid;
+			$mbMetadata->format = "text/xml";
+			$mbMetadata->type = "ISO19115:2003";
+			$mbMetadata->origin = "external";
+			$mbMetadata->owner = $mdOwner;
+			if (!$mbMetadata->insertToDB("featuretype",$featuretypeId)){
+				$e = new mb_exception("Problem while storing metadata to mb_metadata table!");
 			} else {
-				//parsing had problems - fill only the urls into database and give a reasonable error message	
-				$mbMetadata = new Iso19139();
-				$mbMetadata->randomId = $randomid;
-				$mbMetadata->format = "text/xml";
-				$mbMetadata->type = "ISO19115:2003";
-				$mbMetadata->origin = "external";
-				$mbMetadata->owner = $mdOwner;
-				if (!$mbMetadata->insertMetadataUrlToDB("featuretype",$featuretypeId)) {
-					$e = new mb_exception("Problem while storing MetadataURL entry from wfs capabilities to mb_metadata table!");
-				} else {
-					$e = new mb_exception("Stored MetadataURL ".$mbMetadata->href." from wfs capabilities to mb database cause the target could not be accessed or parsed!");
-				}
+				$e = new mb_exception("Stored metadata from external link to mapbender database!");
 			}	
-			
 		} else { //fill thru metador
 			$mbMetadata->origin = "metador";
 			$mbMetadata->fileIdentifier = $uuid;
@@ -667,7 +663,7 @@
 		$featuretypeId = $ajaxResponse->getParameter("featuretypeId");
 		$sql = <<<SQL
 
-DELETE FROM ows_relation_metadata WHERE fkey_metadata_id = $1 and fkey_featuretype_id = $2 and internal = 1
+DELETE FROM ows_relation_metadata WHERE fkey_metadata_id = $1 and fkey_featuretype_id = $2 and relation_type = 'internal'
 
 SQL;
 		$v = array($metadataId, $featuretypeId);
@@ -708,14 +704,13 @@
 		$ajaxResponse->setSuccess(true);
 		break;
 	case "importFeaturetypeXmlAddon" :
-	//this case is similar to insert the metadata from external link, but came from internal file from tmp folder which has been uploaded before
+		//this case is similar to insert the metadata from external link, but came from internal file from tmp folder which has been uploaded before
 		$featuretypeId = $ajaxResponse->getParameter("featuretypeId");
 		$filename = $ajaxResponse->getParameter("filename");
 		//normaly the link is only set if a link has been created
 		//if a record has been created, the link element will be empty 
 		//use this to distinguish between the to different inserts!
 		//this insert should also push one entry in the ows_relation_metadata table! - after the insert into md_metadata
-		$uuid = new Uuid();
 		$randomid = new Uuid();	
 		$e = new mb_notice("File to load: ".$filename);
 		$metaData = file_get_contents($filename);
@@ -724,27 +719,21 @@
 		}
 		$mbMetadata = new Iso19139();
 		$mdOwner = Mapbender::session()->get("mb_user_id");
-		$mbMetadata = $mbMetadata->createMapbenderMetadataFromXML($metaData);	
-		$e = new mb_exception("Result of parsing: ".$mbMetadata);
-		if ($mbMetadata != false) { //metadata has been parsed
-			//set randomId for metadata
-			$mbMetadata->randomId = $randomid;
-			$mbMetadata->format = "text/xml";
-			$mbMetadata->type = "ISO19115:2003";
-			$mbMetadata->origin = "upload";
-			$mbMetadata->owner = $mdOwner;
-			//push metadata object into database
-			if (!$mbMetadata->insertToDB("featuretype",$featuretypeId)) {
-				$e = new mb_exception("Problem while storing uploaded metadata xml to mb_metadata table!");			abort("Problem while storing uploaded metadata xml to mb_metadata table!");
-			} else {
-				$e = new mb_exception("Metadata with id ".$randomid." stored to db!");
-			}
+		$mbMetadata->randomId = $randomid;
+		$mbMetadata->metadata = $metaData;
+		$mbMetadata->format = "text/xml";
+		$mbMetadata->type = "ISO19115:2003";
+		$mbMetadata->origin = "upload";
+		$mbMetadata->owner = $mdOwner;
+		if (!$mbMetadata->insertToDB("featuretype",$featuretypeId)) {
+			$e = new mb_exception("Problem while storing uploaded metadata xml to mb_metadata table!");		abort("Problem while storing uploaded metadata xml to mb_metadata table!");
 		} else {
-			abort("Could not parse metadata from local file!");
-		}				
+			$e = new mb_exception("Metadata with random id ".$randomid." stored to db!");
+			abort("Could not upload metadata from local file!");
+		}
 		$ajaxResponse->setMessage("Uploaded metadata object inserted into md_metadata table!");
-		$ajaxResponse->setSuccess(true);		
-	break;		
+		$ajaxResponse->setSuccess(true);	
+		break;		
 
 	case "save":
 		$data = $ajaxResponse->getParameter("data");

Modified: trunk/mapbender/resources/db/pgsql/UTF-8/update/update_2.7.2_to_2.7.3_pgsql_UTF-8.sql
===================================================================
--- trunk/mapbender/resources/db/pgsql/UTF-8/update/update_2.7.2_to_2.7.3_pgsql_UTF-8.sql	2012-06-12 12:12:46 UTC (rev 8375)
+++ trunk/mapbender/resources/db/pgsql/UTF-8/update/update_2.7.2_to_2.7.3_pgsql_UTF-8.sql	2012-06-14 11:58:58 UTC (rev 8376)
@@ -441,6 +441,8 @@
 ALTER TABLE mb_metadata ADD COLUMN datasetid_codespace TEXT;
 
 ALTER TABLE ows_relation_metadata ADD COLUMN relation_type TEXT;
---update table ows_relation_metadata set type from table mb_metadata -- it is better to have it for relation not for instance
+--update table ows_relation_metadata set type from table mb_metadata -- it is better to have it for relation not for instance - this is only a initial filling, afterwards the code handles the updates and inserts automatical
+UPDATE ows_relation_metadata SET relation_type = origin FROM  mb_metadata WHERE ows_relation_metadata.fkey_metadata_id = mb_metadata.metadata_id AND ows_relation_metadata.relation_type IS NULL;
 
 
+



More information about the Mapbender_commits mailing list