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

svn_mapbender at osgeo.org svn_mapbender at osgeo.org
Wed May 11 03:01:19 EDT 2011


Author: armin11
Date: 2011-05-11 00:01:19 -0700 (Wed, 11 May 2011)
New Revision: 7811

Modified:
   trunk/mapbender/http/plugins/mb_metadata_server.php
   trunk/mapbender/resources/db/pgsql/UTF-8/update/update_2.7rc1_to_2.7rc2_pgsql_UTF-8.sql
Log:
Possibility to store (cache) the metadata which was added es alink to the layer.

Modified: trunk/mapbender/http/plugins/mb_metadata_server.php
===================================================================
--- trunk/mapbender/http/plugins/mb_metadata_server.php	2011-05-10 19:27:37 UTC (rev 7810)
+++ trunk/mapbender/http/plugins/mb_metadata_server.php	2011-05-11 07:01:19 UTC (rev 7811)
@@ -726,38 +726,127 @@
 			$spatial_res_type = $data->spatial_res_type;
 		}
 		if (isset($data->spatial_res_value)) {
-			$spatial_res_valu = $data->spatial_res_value;
+			$spatial_res_value = $data->spatial_res_value;
 		}
 		if (isset($data->inspire_charset)) {
 			$inspire_charset = $data->inspire_charset;
 		}
-		$dbInsertFailed = false;
-		$sql = <<<SQL
+		$randomid = new Uuid();
+		//Check if origin is external and export2csw is activated!
+		if ($origin == 'external' && $export2csw = 't' ) {
+			//harvest link from location, parse the content for datasetid and push xml into data column
+			//load metadata from link TODO: function from class_wms - generate a class for metadata management and include it here and in class_wms
+			$metadataConnector = new connector($link);
+			$metaData = $metadataConnector->file;
+			//parse metadata
+			try {
+				$iso19139Xml =  new SimpleXMLElement($metaData);
+				if ($iso19139Xml == false) {
+					throw new Exception('Cannot parse Metadata XML!');
+				}
+			}
+			catch (Exception $e) {
+    				$e = new mb_exception($e->getMessage());
+			}
+			if ($iso19139Xml != false) {
+				//get elements for database from xml by using xpath
+				//uuid
+				$uuid = $iso19139Xml->xpath('/gmd:MD_Metadata/gmd:fileIdentifier/gco:CharacterString');
+				//createdate
+				$createdate = $iso19139Xml->xpath('/gmd:MD_Metadata/gmd:dateStamp/gco:Date');
+				//changedate
+				$changedate = $iso19139Xml->xpath('/gmd:MD_Metadata/gmd:dateStamp/gco:Date');
+				//TODO: check if this is set, maybe DateTime must be searched instead?
+				//title
+				$title = $iso19139Xml->xpath('/gmd:MD_Metadata/gmd:identificationInfo/gmd:MD_DataIdentification/gmd:citation/gmd:CI_Citation/gmd:title/gco:CharacterString');
+				//dataset identifier - howto model into md_metadata?
+				//check where datasetid is defined - maybe as RS_Identifier or as MD_Identifier see http://inspire.jrc.ec.europa.eu/documents/Metadata/INSPIRE_MD_IR_and_ISO_v1_2_20100616.pdf page 18
+				$code = $iso19139Xml->xpath('/gmd:MD_Metadata/gmd:identificationInfo/gmd:MD_DataIdentification/gmd:citation/gmd:CI_Citation/gmd:identifier/gmd:RS_Identifier/gmd:code/gco:CharacterString');
+				$codeSpace = $iso19139Xml->xpath('/gmd:MD_Metadata/gmd:identificationInfo/gmd:MD_DataIdentification/gmd:citation/gmd:CI_Citation/gmd:identifier/gmd:RS_Identifier/gmd:codeSpace/gco:CharacterString');
+				$e = new mb_notice("class_wms.php: code: ".$code[0]);
+				$e = new mb_notice("class_wms.php: codeSpace: ".$codeSpace[0]);
+				if (isset($codeSpace[0]) && isset($code[0]) && $codeSpace[0] != '' && $code[0] != '') {
+						
+					$datasetid = $codeSpace[0]."#".$code[0];
+					$e = new mb_notice("class_wms.php: datasetid: ".$datasetid);
+				} else {
+						
+					$datasetid = 'undefined';# in sense of INSPIRE TODO control MD_Identifier too!
+					$e = new mb_notice("class_wms.php: datasetid: ".$datasetid);
+				}
+				//abstract
+				$abstract = $iso19139Xml->xpath('/gmd:MD_Metadata/gmd:identificationInfo/gmd:MD_DataIdentification/gmd:abstract/gco:CharacterString');
+				//searchtext -- use keywords!
+				$keywords = $iso19139Xml->xpath('/gmd:MD_Metadata/gmd:identificationInfo/gmd:MD_DataIdentification/gmd:descriptiveKeywords/gmd:MD_Keywords/gmd:keyword/gco:CharacterString');
+				//type 
+				$type = $iso19139Xml->xpath('/gmd:MD_Metadata/gmd:hierarchyLevel/gmd:MD_ScopeCode');
+				//tmp_reference_1
+				$tmp_reference_1 = $iso19139Xml->xpath('/gmd:MD_Metadata/gmd:identificationInfo/gmd:MD_DataIdentification/gmd:extent/gmd:EX_Extent/gmd:temporalElement/gmd:EX_TemporalExtent/gmd:extent/gml:TimePeriod/gml:beginPosition');
+				//tmp_reference_2
+				$tmp_reference_2 = $iso19139Xml->xpath('/gmd:MD_Metadata/gmd:identificationInfo/gmd:MD_DataIdentification/gmd:extent/gmd:EX_Extent/gmd:temporalElement/gmd:EX_TemporalExtent/gmd:extent/gml:TimePeriod/gml:endPosition');		//spatial_res_type
+				//spatial_res_value
+				//ref_system
+				//format
+				//inspire_charset
+				//inspire_top_consistence
+				//responsible_party
+				//fees
+				//"constraints"	
+				//fill database with elements:
+				$dbInsertFailed = false;
 
-INSERT INTO mb_metadata (link, uuid, origin, title, abstract, format, ref_system, export2csw, inspire_top_consistence, tmp_reference_1, tmp_reference_2, lineage, spatial_res_type, spatial_res_value, inspire_charset, createdate) VALUES ($1, $2, $3, $4, $5, $6, $7, $8, $9, $10, $11, $12, $13, $14, $15, now())
+				$sql = <<<SQL
 
+INSERT INTO mb_metadata (link, uuid, origin, title, abstract, format, ref_system, export2csw, inspire_top_consistence, tmp_reference_1, tmp_reference_2, lineage, spatial_res_type, spatial_res_value, inspire_charset, createdate, datasetid, randomid, data, harvestresult) VALUES ($1, $2, $3, $4, $5, $6, $7, $8, $9, $10, $11, $12, $13, $14, $15, now(), $16, $17, $18, 1)
+
 SQL;
-		$v = array($link, $uuid, $origin, $title, $abstract, $format, $ref_system, $export2csw,$inspire_top_consistence,$tmp_reference_1,$tmp_reference_2,$lineage,$spatial_res_type,$spatial_res_value,$inspire_charset);
-		$t = array('s','s','s','s','s','s','s','b','b','s','s','s','s','s','s');
+				$v = array($link, $uuid[0], $origin, $title[0], $abstract[0], $format, $ref_system, $export2csw,$inspire_top_consistence,$tmp_reference_1[0],$tmp_reference_2[0],$lineage,$spatial_res_type,$spatial_res_value,$inspire_charset, $datasetid, $randomid, $metaData);
+				$t = array('s','s','s','s','s','s','s','b','b','s','s','s','s','s','s','s','s','s');
 		
-		try {
-			$res = db_prep_query($sql,$v,$t);
+				try {
+					$res = db_prep_query($sql,$v,$t);
+				}
+				catch (Exception $e){
+					$ajaxResponse->setSuccess(false);
+					$ajaxResponse->setMessage(_mb("Could not insert metadata object into database!"));	
+					$dbInsertFailed = true;	
+					$e = new mb_exception($dbInsertFailed);
+				}
+			
+			} else {
+				//give back error message - cause parsing has problems
+			}
+		} else {
+
+			$dbInsertFailed = false;
+			$sql = <<<SQL
+
+INSERT INTO mb_metadata (link, uuid, origin, title, abstract, format, ref_system, export2csw, inspire_top_consistence, tmp_reference_1, tmp_reference_2, lineage, spatial_res_type, spatial_res_value, inspire_charset, createdate, randomid) VALUES ($1, $2, $3, $4, $5, $6, $7, $8, $9, $10, $11, $12, $13, $14, $15, now(), $16)
+
+SQL;
+			$v = array($link, $uuid, $origin, $title, $abstract, $format, $ref_system, $export2csw,$inspire_top_consistence,$tmp_reference_1,$tmp_reference_2,$lineage,$spatial_res_type,$spatial_res_value,$inspire_charset, $randomid);
+			$t = array('s','s','s','s','s','s','s','b','b','s','s','s','s','s','s','s');
+		
+			try {
+				$res = db_prep_query($sql,$v,$t);
+			}
+			catch (Exception $e){
+				$ajaxResponse->setSuccess(false);
+				$ajaxResponse->setMessage(_mb("Could not insert metadata object into database!"));	
+				$dbInsertFailed = true;	
+				$e = new mb_exception($dbInsertFailed);
+			}
 		}
-		catch (Exception $e){
-			$ajaxResponse->setSuccess(false);
-			$ajaxResponse->setMessage(_mb("Could not insert metadata object into database!"));	
-			$dbInsertFailed = true;	
-			$e = new mb_exception($dbInsertFailed);
-		}
 		//set relation into relation table
 		//get metadata_id of record which have been inserted before
 		if ($dbInsertFailed != true) {	
 			$sql = <<<SQL
 
-	SELECT metadata_id FROM mb_metadata WHERE uuid = $1
+	SELECT metadata_id FROM mb_metadata WHERE randomid = $1
 
 SQL;
-			$v = array($uuid);
+			//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);

Modified: trunk/mapbender/resources/db/pgsql/UTF-8/update/update_2.7rc1_to_2.7rc2_pgsql_UTF-8.sql
===================================================================
--- trunk/mapbender/resources/db/pgsql/UTF-8/update/update_2.7rc1_to_2.7rc2_pgsql_UTF-8.sql	2011-05-10 19:27:37 UTC (rev 7810)
+++ trunk/mapbender/resources/db/pgsql/UTF-8/update/update_2.7rc1_to_2.7rc2_pgsql_UTF-8.sql	2011-05-11 07:01:19 UTC (rev 7811)
@@ -1915,6 +1915,9 @@
 ALTER TABLE mb_metadata ADD COLUMN lineage text;
 ALTER TABLE mb_metadata ALTER COLUMN spatial_res_type TYPE varchar(20);
 ALTER TABLE mb_metadata ADD COLUMN datasetid text; --needed for service data coupling!
+ALTER TABLE mb_metadata ADD COLUMN randomid character varying(100); --needed to identify inserted record!
+ALTER TABLE mb_metadata ALTER COLUMN randomid SET STORAGE EXTENDED;
+
 -- activate datepicker for forms
 INSERT INTO gui_element(fkey_gui_id, e_id, e_pos, e_public, e_comment, e_title, e_element, e_src, e_attributes, e_left, e_top, e_width, e_height, e_z_index, e_more_styles, e_content, e_closetag, e_js_file, e_mb_mod, e_target, e_requires, e_url) VALUES('admin_wms_metadata','jq_ui_datepicker',5,1,'Datepicker from jQuery UI framework','','','','',NULL ,NULL ,NULL ,NULL ,NULL ,'','','','../plugins/jq_ui_datepicker.js','../extensions/jquery-ui-1.8.1.custom/development-bundle/ui/jquery.ui.datepicker.js','','jq_ui','');
 



More information about the Mapbender_commits mailing list