[Mapbender-commits] r8429 - trunk/mapbender/http/classes
svn_mapbender at osgeo.org
svn_mapbender at osgeo.org
Fri Jul 6 02:55:35 PDT 2012
Author: armin11
Date: 2012-07-06 02:55:35 -0700 (Fri, 06 Jul 2012)
New Revision: 8429
Modified:
trunk/mapbender/http/classes/class_iso19139.php
Log:
Bugfix for metadataurl handling
Modified: trunk/mapbender/http/classes/class_iso19139.php
===================================================================
--- trunk/mapbender/http/classes/class_iso19139.php 2012-07-06 09:54:57 UTC (rev 8428)
+++ trunk/mapbender/http/classes/class_iso19139.php 2012-07-06 09:55:35 UTC (rev 8429)
@@ -108,18 +108,19 @@
$iso19139Xml = simplexml_load_string($this->metadata);
if ($iso19139Xml === false) {
foreach(libxml_get_errors() as $error) {
- $err = new mb_exception($error->message);
+ $err = new mb_exception("class_Iso19139:".$error->message);
}
- throw new Exception('Cannot parse Metadata XML!');
+ throw new Exception("class_Iso19139:".'Cannot parse Metadata XML!');
return false;
}
}
catch (Exception $e) {
- $err = new mb_exception($e->getMessage());
+ $err = new mb_exception("class_Iso19139:".$e->getMessage());
return false;
}
//if parsing was successful
if ($iso19139Xml != false) {
+ //add namespaces to xml if not given - how? - it is to late now - maybe they were given in the csw tag!
$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];
@@ -189,7 +190,353 @@
$mbMetadata = $this->createMapbenderMetadataFromXML($xml);
return $mbMetadata;
}
-
+
+ public function readFromUrl($url){
+ $this->href = $url;
+ $metadataConnector = new connector($url);
+ $metadataConnector->set("timeOut", "10");
+ $xml = $metadataConnector->file;
+ $this->metadata = $xml;
+ }
+
+ public function transformToHtml($layout,$languageCode){
+ //TODO!
+ //$this->metadata = $this->removeGetRecordTag($this->metadata);
+ libxml_use_internal_errors(true);
+
+ try {
+ $iso19139Xml = simplexml_load_string($this->metadata);
+ if ($iso19139Xml === false) {
+ foreach(libxml_get_errors() as $error) {
+ $err = new mb_exception("class_Iso19139:".$error->message);
+ }
+ throw new Exception("class_Iso19139:".'Cannot parse Metadata XML!');
+ return "error";
+ }
+ }
+ catch (Exception $e) {
+ $err = new mb_exception("class_Iso19139:".$e->getMessage());
+ return "error";
+ }
+
+ //if parsing was successful
+ if ($iso19139Xml != false) {
+ return "ok";/*
+ $e = new mb_exception("Parsing of xml metadata file was successfull");
+ //register namespaces for parsing content
+ $iso19139Xml->registerXPathNamespace("csw", "http://www.opengis.net/cat/csw/2.0.2");
+ $iso19139Xml->registerXPathNamespace("gml", "http://www.opengis.net/gml");
+ $iso19139Xml->registerXPathNamespace("gco", "http://www.isotc211.org/2005/gco");
+ $iso19139Xml->registerXPathNamespace("gmd", "http://www.isotc211.org/2005/gmd");
+ $iso19139Xml->registerXPathNamespace("gts", "http://www.isotc211.org/2005/gts");
+ $iso19139Xml->registerXPathNamespace("srv", "http://www.isotc211.org/2005/srv");
+ $iso19139Xml->registerXPathNamespace("xlink", "http://www.w3.org/1999/xlink");
+ require_once(dirname(__FILE__)."/../../conf/isoMetadata.conf");
+ for($a = 0; $a < count($iso19139Hash); $a++) {
+ //TODO delete csw:... from following - only parse the metadata record itself
+ $resultOfXpath = $iso19139Xml->xpath('/csw:GetRecordByIdResponse'.$iso19139Hash[$a]['iso19139']);
+ for ($i = 0; $i < count($resultOfXpath); $i++) {
+ $iso19139Hash[$a]['value'] = $iso19139Hash[$a]['value'].",".$resultOfXpath[$i];
+ }
+ $iso19139Hash[$a]['value'] = ltrim($iso19139Hash[$a]['value'],',');
+ }
+ //generate html
+ $html = '<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="'.$languageCode.'">';
+ $html .= '<body>';
+ $metadataStr .= '<head>' .
+ '<title>'._mb("Metadata").'</title>' .
+ '<meta name="description" content="'._mb("Metadata").'" xml:lang="'.$languageCode.'" />'.
+ '<meta name="keywords" content="'._mb("Metadata").'" xml:lang="'.$languageCode.'" />' .
+ '<meta http-equiv="cache-control" content="no-cache">'.
+ '<meta http-equiv="pragma" content="no-cache">'.
+ '<meta http-equiv="expires" content="0">'.
+ '<meta http-equiv="content-language" content="'.$languageCode.'" />'.
+ '<meta http-equiv="content-style-type" content="text/css" />'.
+ '<meta http-equiv="Content-Type" content="text/html; charset='.CHARSET.'">' .
+ '</head>';
+ $html .= $metadataStr;
+ //define the javascripts to include
+ $html .= '<link type="text/css" href="../css/metadata.css" rel="Stylesheet" />';
+ if ($layout == 'tabs') {
+ $html .= '<link type="text/css" href="../extensions/jquery-ui-1.8.1.custom/css/custom-theme/jquery-ui-1.8.5.custom.css" rel="Stylesheet" />';
+ $html .= '<script type="text/javascript" src="../extensions/jquery-ui-1.8.1.custom/js/jquery-1.4.2.min.js"></script>';
+ $html .= '<script type="text/javascript" src="../extensions/jquery-ui-1.8.1.custom/js/jquery-ui-1.8.1.custom.min.js"></script>';
+ //initialize tabs
+ $html .= '<script type="text/javascript">';
+ $html .= '$(function() {';
+ $html .= ' $("#tabs").tabs();';
+ $html .= '});';
+ $html .= '</script>';
+ //independently define the headers of the parts
+ $html .= '<div class="demo">';
+ $html .= '<div id="tabs">';
+ $html .= '<ul>';
+ $html .= '<li><a href="#tabs-1">'._mb("Overview").'</a></li>';
+ $html .= '<li><a href="#tabs-2">'._mb("Properties").'</a></li>';
+ $html .= '<li><a href="#tabs-3">'._mb("Contact").'</a></li>';
+ $html .= '<li><a href="#tabs-4">'._mb("Terms of use").'</a></li>';
+ $html .= '<li><a href="#tabs-5">'._mb("Quality").'</a></li>';
+ $html .= '<li><a href="#tabs-6">'._mb("Interfaces").'</a></li>';
+ $html .= '</ul>';
+ }
+ if ($layout == 'accordion') {
+ $html .= '<link type="text/css" href="../extensions/jquery-ui-1.8.1.custom/css/custom-theme/jquery-ui-1.8.4.custom.css" rel="Stylesheet" />';
+ $html .= '<script type="text/javascript" src="../extensions/jquery-ui-1.8.1.custom/js/jquery-1.4.2.min.js"></script>';
+ $html .= '<script type="text/javascript" src="../extensions/jquery-ui-1.8.1.custom/js/jquery-ui-1.8.1.custom.min.js"></script>';
+ //define the javascript functions
+ $html .= '<script type="text/javascript">';
+ $html .= ' $(function() {';
+ $html .= ' $("#accordion").accordion();';
+ //$html .= ' $("#accordion").accordion({ autoHeight: false});';
+ //$html .= ' $("#accordion").accordion({ autoHeight: false , clearStyle: true });';
+ $html .= ' });';
+ $html .= ' </script>';
+ $html .= '<div class="demo">';
+ $html .= '<div id="accordion">';
+ }
+ if ($layout == 'plain') {
+ $html .= '<div class="demo">';
+ $html .= '<div id="plain">';
+ }
+ //some placeholders
+ $tableBegin = "<table>\n";
+ $t_a = "\t<tr>\n\t\t<th>\n\t\t\t";
+ $t_b = "\n\t\t</th>\n\t\t<td>\n\t\t\t";
+ $t_c = "\n\t\t</td>\n\t</tr>\n";
+ $tableEnd = "</table>\n";
+ //**************************overview part begin******************************
+ //generate div tags for the content - the divs are defined in the array
+ if ($layout == 'accordion') {
+ $html .= '<h3><a href="#">'._mb("Overview").'</a></h3>';
+ $html .= '<div style="height:300px">';
+ }
+ if ($layout == 'tabs') {
+ $html .= '<div id="tabs-1">';
+ }
+ if ($layout == 'plain') {
+ $html .= '<h3>'._mb("overview").'</h3>';
+ $html .= '<div>';
+ }
+ $html .= '<p>';
+ $html .= '<fieldset><legend>'._mb("Metadata").'</legend>';
+ $html .= $tableBegin;
+ $html .= $t_a."<b>".$iso19139Hash[0]['html']."</b>: ".$t_b.$iso19139Hash[0]['value'].$t_c;
+ $html .= $t_a."<b>".$iso19139Hash[31]['html']."</b>: ".$t_b.$iso19139Hash[31]['value'].$t_c;
+ $html .= $t_a."<b>".$iso19139Hash[32]['html']."</b>: ".$t_b.$iso19139Hash[32]['value'].$t_c;
+ $html .= $tableEnd;
+ $html .= '</fieldset>';
+ $html .= '<fieldset><legend>'._mb("Identification").'</legend>';
+ $html .= $tableBegin;
+ $html .= $t_a."<b>".$iso19139Hash[1]['html']."</b>: ".$t_b.$iso19139Hash[1]['value'].$t_c;
+ $html .= $t_a."<b>".$iso19139Hash[2]['html']."</b>: ".$t_b.$iso19139Hash[2]['value'].$t_c;
+ $html .= $t_a."<b>".$iso19139Hash[3]['html']."</b>: ".$t_b.$iso19139Hash[3]['value'].$t_c;
+ if ($iso19139Hash[36]['value'] != "") {
+ $html .= $t_a."<b>".$iso19139Hash[36]['html']."</b>: ".$t_b."<img width=120 height=120 src = '".$iso19139Hash[36]['value']."'>".$t_c;//preview
+ }
+ $html .= $t_a."<b>".$iso19139Hash[5]['html']."</b>: ".$t_b.$iso19139Hash[5]['value'].$t_c;
+ $html .= $t_a."<b>".$iso19139Hash[6]['html']."</b>: ".$t_b.$iso19139Hash[6]['value'].$t_c;
+ $html .= $t_a."<b>".$iso19139Hash[26]['html']."</b>: ".$t_b.$iso19139Hash[26]['value'].$t_c;
+ $html .= $t_a."<b>".$iso19139Hash[27]['html']."</b>: ".$t_b.$iso19139Hash[27]['value'].$t_c;
+ $html .= $tableEnd;
+ $html .= '</fieldset>';
+
+ $bbox = explode(',',$iso19139Hash[12]['value']);
+
+ if (count($bbox) == 4) {
+ $wgs84Bbox = $bbox[0].",".$bbox[2].",".$bbox[1].",".$bbox[3];
+ $getMapUrl = getExtentGraphic(explode(",", $wgs84Bbox));
+ $html .= '<fieldset><legend>'._mb("Extent").'</legend>';
+ if (defined('EXTENTSERVICEURL')) {
+ $html .= "<img src='".$getMapUrl."'>";
+ } else {
+ $html .= _mb('Graphic unavailable');
+ }
+ $html .= '</fieldset>';
+ }
+ $html .= '<fieldset><legend>'._mb("Contact").'</legend>';
+ $html .= $tableBegin;
+ $html .= $t_a."<b>".$iso19139Hash[26]['html']."</b>: ".$t_b.$iso19139Hash[26]['value'].$t_c;
+ $html .= $t_a."<b>".$iso19139Hash[27]['html']."</b>: ".$t_b.$iso19139Hash[27]['value'].$t_c;
+ $html .= $tableEnd;
+ $html .= '</fieldset>';
+ $html .= '</p>';
+ $html .= '</div>';//element
+ //***************************************************************************
+ //**************************properties part begin******************************
+ //generate div tags for the content - the divs are defined in the array
+ if ($layout == 'accordion') {
+ $html .= '<h3><a href="#">'._mb("Properties").'</a></h3>';
+ $html .= '<div style="height:300px">';
+ }
+ if ($layout == 'tabs') {
+ $html .= '<div id="tabs-2">';
+ }
+ if ($layout == 'plain') {
+ $html .= '<h3>'._mb("Properties").'</h3>';
+ $html .= '<div>';
+ }
+ $html .= '<p>';
+ $html .= '<fieldset><legend>'._mb("Common").'</legend>';
+ $html .= $tableBegin;
+ $html .= $t_a."<b>".$iso19139Hash[8]['html']."</b>: ".$t_b.$iso19139Hash[8]['value'].$t_c;
+ $html .= $t_a."<b>".$iso19139Hash[9]['html']."</b>: ".$t_b.$iso19139Hash[9]['value'].$t_c;
+ $html .= $t_a."<b>".$iso19139Hash[11]['html']."</b>: ".$t_b.$iso19139Hash[11]['value'].$t_c;
+ $html .= $tableEnd;
+ $html .= '</fieldset>';
+ $html .= '<fieldset><legend>'._mb("Geographic extent").'</legend>';
+ $html .= $tableBegin;
+ $html .= $t_a."<b>".$iso19139Hash[33]['html']."</b>: ".$t_b.$iso19139Hash[33]['value'].$t_c;
+ $html .= $t_a."<b>".$iso19139Hash[12]['html']."</b>: ".$t_b.$iso19139Hash[12]['value'].$t_c;
+ $html .= $tableEnd;
+ $html .= '</fieldset>';
+ $html .= '<fieldset><legend>'._mb("Temporal extent").'</legend>';
+ $html .= $tableBegin;
+ $html .= $t_a."<b>".$iso19139Hash[13]['html']."</b>: ".$t_b.$iso19139Hash[13]['value'].$t_c;
+ $html .= $t_a."<b>".$iso19139Hash[14]['html']."</b>: ".$t_b.$iso19139Hash[14]['value'].$t_c;
+ $html .= $t_a."<b>".$iso19139Hash[15]['html']."</b>: ".$t_b.$iso19139Hash[15]['value'].$t_c;
+ $html .= $t_a."<b>".$iso19139Hash[16]['html']."</b>: ".$t_b.$iso19139Hash[16]['value'].$t_c;
+ $html .= $tableEnd;
+ $html .= '</fieldset>';
+ $html .= '<fieldset><legend>'._mb("Format").'</legend>';
+ $html .= $tableBegin;
+ $html .= $t_a."<b>".$iso19139Hash[34]['html']."</b>: ".$t_b.$iso19139Hash[34]['value'].$t_c;
+ $html .= $t_a."<b>".$iso19139Hash[35]['html']."</b>: ".$t_b.$iso19139Hash[35]['value'].$t_c;
+ $html .= $tableEnd;
+ $html .= '</fieldset>';
+ $html .= '<fieldset><legend>'._mb("Service information").'</legend>';
+ $html .= $tableBegin;
+ $html .= $t_a."<b>".$iso19139Hash[10]['html']."</b>: ".$t_b.$iso19139Hash[10]['value'].$t_c;
+ $html .= $t_a."<b>".$iso19139Hash[7]['html']."</b>: ".$t_b.$iso19139Hash[7]['value'].$t_c;
+ $html .= $tableEnd;
+ $html .= '</fieldset>';
+ $html .= '</p>';
+ $html .= '</div>';//element
+ //***************************************************************************
+ //**************************contact part begin******************************
+ //generate div tags for the content - the divs are defined in the array
+ if ($layout == 'accordion') {
+ $html .= '<h3><a href="#">'._mb("Properties").'</a></h3>';
+ $html .= '<div style="height:300px">';
+ }
+ if ($layout == 'tabs') {
+ $html .= '<div id="tabs-3">';
+ }
+ if ($layout == 'plain') {
+ $html .= '<h3>'._mb("Properties").'</h3>';
+ $html .= '<div>';
+ }
+ $html .= '<p>';
+ $html .= '<fieldset><legend>'._mb("Data/Service provider").'</legend>';
+ $html .= $tableBegin;
+ $html .= $t_a."<b>".$iso19139Hash[26]['html']."</b>: ".$t_b.$iso19139Hash[26]['value'].$t_c;
+ $html .= $t_a."<b>".$iso19139Hash[28]['html']."</b>: ".$t_b.$iso19139Hash[28]['value'].$t_c;
+ $html .= $t_a."<b>".$iso19139Hash[27]['html']."</b>: ".$t_b.$iso19139Hash[27]['value'].$t_c;
+ $html .= $tableEnd;
+ $html .= '</fieldset>';
+ $html .= '<fieldset><legend>'._mb("Metadata provider").'</legend>';
+ $html .= $tableBegin;
+ $html .= $t_a."<b>".$iso19139Hash[29]['html']."</b>: ".$t_b.$iso19139Hash[29]['value'].$t_c;
+ $html .= $t_a."<b>".$iso19139Hash[30]['html']."</b>: ".$t_b.$iso19139Hash[30]['value'].$t_c;
+ $html .= $tableEnd;
+ $html .= '</fieldset>';
+ $html .= '</p>';
+ $html .= '</div>';//element
+ //***************************************************************************
+ //**************************terms of use part begin******************************
+ //generate div tags for the content - the divs are defined in the array
+ if ($layout == 'accordion') {
+ $html .= '<h3><a href="#">'._mb("Terms of use").'</a></h3>';
+ $html .= '<div style="height:300px">';
+ }
+ if ($layout == 'tabs') {
+ $html .= '<div id="tabs-4">';
+ }
+ if ($layout == 'plain') {
+ $html .= '<h3>'._mb("Terms of use").'</h3>';
+ $html .= '<div>';
+ }
+ $html .= '<p>';
+ $html .= '<fieldset><legend>'._mb("Conditions").'</legend>';
+ $html .= $tableBegin;
+ $html .= $t_a."<b>".$iso19139Hash[23]['html']."</b>: ".$t_b.$iso19139Hash[23]['value'].$t_c;
+ $html .= $tableEnd;
+ $html .= '</fieldset>';
+ $html .= '<fieldset><legend>'._mb("Access constraints").'</legend>';
+ $html .= $tableBegin;
+ $html .= $t_a."<b>".$iso19139Hash[24]['html']."</b>: ".$t_b.$iso19139Hash[24]['value'].$t_c;
+ $html .= $t_a."<b>".$iso19139Hash[25]['html']."</b>: ".$t_b.$iso19139Hash[25]['value'].$t_c;
+ $html .= $tableEnd;
+ $html .= '</fieldset>';
+ $html .= '</p>';
+ $html .= '</div>';//element
+ //***************************************************************************
+ //**************************quality part begin******************************
+ //generate div tags for the content - the divs are defined in the array
+ if ($layout == 'accordion') {
+ $html .= '<h3><a href="#">'._mb("Quality").'</a></h3>';
+ $html .= '<div style="height:300px">';
+ }
+ if ($layout == 'tabs') {
+ $html .= '<div id="tabs-5">';
+ }
+ if ($layout == 'plain') {
+ $html .= '<h3>'._mb("Quality").'</h3>';
+ $html .= '<div>';
+ }
+ $html .= '<p>';
+ $html .= '<fieldset><legend>'._mb("Lineage").'</legend>';
+ $html .= $tableBegin;
+ $html .= $t_a."<b>".$iso19139Hash[17]['html']."</b>: ".$t_b.$iso19139Hash[17]['value'].$t_c;
+ $html .= $tableEnd;
+ $html .= '</fieldset>';
+ $html .= '<fieldset><legend>'._mb("Resolution").'</legend>';
+ $html .= $tableBegin;
+ $html .= $t_a."<b>".$iso19139Hash[18]['html']."</b>: ".$t_b.$iso19139Hash[18]['value'].$t_c;
+ $html .= $t_a."<b>".$iso19139Hash[19]['html']."</b>: ".$t_b.$iso19139Hash[19]['value'].$t_c;
+ $html .= $tableEnd;
+ $html .= '</fieldset>';
+ $html .= '<fieldset><legend>'._mb("Validity").'</legend>';
+ $html .= $tableBegin;
+ $html .= $t_a."<b>".$iso19139Hash[20]['html']."</b>: ".$t_b.$iso19139Hash[20]['value'].$t_c;
+ $html .= $t_a."<b>".$iso19139Hash[21]['html']."</b>: ".$t_b.$iso19139Hash[21]['value'].$t_c;
+ $html .= $t_a."<b>".$iso19139Hash[22]['html']."</b>: ".$t_b.$iso19139Hash[22]['value'].$t_c;
+ $html .= $tableEnd;
+ $html .= '</fieldset>';
+ $html .= '</p>';
+ $html .= '</div>';//element
+ //***************************************************************************
+ //**************************quality part begin******************************
+ //generate div tags for the content - the divs are defined in the array
+ if ($layout == 'accordion') {
+ $html .= '<h3><a href="#">'._mb("Interfaces").'</a></h3>';
+ $html .= '<div style="height:300px">';
+ }
+ if ($layout == 'tabs') {
+ $html .= '<div id="tabs-6">';
+ }
+ if ($layout == 'plain') {
+ $html .= '<h3>'._mb("Interfaces").'</h3>';
+ $html .= '<div>';
+ }
+ $html .= '<p>';
+ $html .= '<fieldset><legend>'._mb("Metadata").'</legend>';
+ $html .= $tableBegin;
+ //exchange mdtype html with iso19139
+ //$queryNew = str_replace("mdtype=html","mdtype=iso19139",$_SERVER['QUERY_STRING']);
+ //$html .= $t_a."<b>"._mb("ISO19139")."</b>: <a href='".$url."' target='_blank'>"._mb("Metadata")."</a><a href='".$_SERVER['PHP_SELF']."?".$queryNew."&validate=true' target='_blank'><img style='border: none;' src = '../img/misc/icn_inspire_validate.png' title='"._mb("INSPIRE Validator")."'></a>".$t_c;
+ $html .= $tableEnd;
+ $html .= '</fieldset>';
+ $html .= '</p>';
+ $html .= '</div>';//element
+ //***************************************************************************
+ $html .= '</div>'; //accordion
+ $html .= '</div>'; //demo
+ $html .= '</body>';
+ $html .= '</html>';
+ return $html;*/
+ }
+ }
+
public function createFromDB($fileIdentifier){
return $this;
}
@@ -202,7 +549,7 @@
$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);
+ $e = new mb_exception("class_Iso19139:"."Cannot delete metadata relations for resource ".$resourceType." with id: ".$resourceId);
return false;
} else {
return true;
@@ -217,7 +564,7 @@
$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);
+ $e = new mb_exception("class_Iso19139:"."Cannot delete metadata relations for resource ".$resourceType." with id: ".$resourceId);
return false;
} else {
return true;
@@ -263,6 +610,10 @@
$sql = <<<SQL
SELECT metadata_id, createdate FROM mb_metadata WHERE uuid = $1 ORDER BY lastchanged DESC
SQL;
+ if (!isset($this->fileIdentifier) || $this->fileIdentifier == '') {
+ $e = new mb_exception("class_Iso19139:"."Empty or no fileIdentifier found in the metadata! No metadataset will be updated");
+ return false;
+ }
$v = array(
$this->fileIdentifier
);
@@ -284,7 +635,7 @@
$metadataId = $this->isLinkAlreadyInDB();
if ($metadataId != false) {
//update the metadataURL entry
- $e = new mb_exception("existing metadata link(s) found: ".$metadataId[0]." - update will be performed");
+ $e = new mb_exception("class_Iso19139:"."existing metadata link(s) found: ".$metadataId[0]." - update will be performed");
$sql = "UPDATE mb_metadata SET link = $1, origin = $2, md_format = $3, linktype = $4, changedate = now(), export2csw = $5, randomid = $6, harvestresult = $8, harvestexception = $9 WHERE metadata_id = $7";
$v = array(
$this->href,
@@ -318,7 +669,7 @@
$res = db_prep_query($sql,$v,$t);
if(!$res){
db_rollback();
- $e = new mb_exception(_mb("Cannot insert or update metadataUrl in database!"));
+ $e = new mb_exception("class_Iso19139:"._mb("Cannot insert or update metadataUrl in database!"));
return false;
} else {
//insert relation into db
@@ -333,11 +684,11 @@
$res = db_prep_query($sql,$v,$t);
}
catch (Exception $e){
- $e = new mb_exception(_mb("Cannot get metadata record with following random id from database: ".$this->randomId));
+ $e = new mb_exception("class_Iso19139:"._mb("Cannot get metadata record with following random id from database: ".$this->randomId));
}
if (!$res) {
//do nothing
- $e = new mb_exception(_mb("Cannot find inserted metadata entry to store relation."));
+ $e = new mb_exception("class_Iso19139:"._mb("Cannot find inserted metadata entry to store relation."));
return false;
} else {
//insert relation
@@ -350,7 +701,7 @@
$res = db_prep_query($sql,$v,$t);
if(!$res){
db_rollback();
- $e = new mb_exception(_mb("Cannot insert metadata relation!"));
+ $e = new mb_exception("class_Iso19139:"._mb("Cannot insert metadata relation!"));
return false;
} else {
$sql = "UPDATE mb_metadata SET harvestresult = 0, harvestexception = 'Linked metadata could not be interpreted, only linkage is stored to mb_metadata!' where metadata_id = $1";
@@ -359,7 +710,7 @@
$res = db_prep_query($sql,$v,$t);
if(!$res){
db_rollback();
- $e = new mb_exception(_mb("Cannot update mb_metadata table!"));
+ $e = new mb_exception("class_Iso19139:"._mb("Cannot update mb_metadata table!"));
return false;
}
}
@@ -376,23 +727,28 @@
//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....')) {
+ //TODO: that empty identifier not identified - see comparing linkage
+ if (($this->type == 'ISO19115:2003' && $this->format =='text/xml') || ($this->type == 'TC211' && $this->format =='text/xml') || ($this->type == 'ISO19115:2003' && $this->format =='application/vnd.iso.19139+xml')) {
+ $e = new mb_notice("class_Iso19139:"."try to parse: ".$this->href);
$metadata = $this->createFromUrl($this->href); //will alter object itself
+ $e = new mb_notice("class_Iso19139:"."Metadata found: ".$this->metadata);
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!");
+ $e = new mb_exception("class_Iso19139:"."Problem while storing MetadataURL entry from wms capabilities to mb_metadata table!");
$result['value'] = false;
$result['message'] = "Problem while storing MetadataURL entry from wms capabilities to mb_metadata table!";
return $result;
} else {
- $e = new mb_exception("Storing only MetadataURL ".$metadata->href." from capabilities to mb database cause the target could not be accessed or parsed!");
+ $e = new mb_exception("class_Iso19139:"."Storing only MetadataURL ".$metadata->href." from capabilities to mb database cause the target could not be accessed or parsed!");
$result['value'] = true;
$result['message'] = "Storing only MetadataURL ".$metadata->href." from capabilities to mb database cause the target could not be accessed or parsed!";
return $result;
}
}
+ } else {
+ $e = new mb_exception("class_Iso19139:"."MetadataURL format or type of following url is not supported: Format: ".$this->format." | type: ".$this->type);
}
break;
case "external":
@@ -401,12 +757,12 @@
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!");
+ $e = new mb_exception("class_Iso19139:"."Problem while storing MetadataURL entry from wms capabilities to mb_metadata table!");
$result['value'] = false;
$result['message'] = "Problem while storing MetadataURL entry from wms capabilities to mb_metadata table!";
return $result;
} else {
- $e = new mb_exception("Storing only MetadataURL ".$metadata->href." from capabilities to mb database cause the target could not be accessed or parsed!");
+ $e = new mb_exception("class_Iso19139:"."Storing only MetadataURL ".$metadata->href." from capabilities to mb database cause the target could not be accessed or parsed!");
$result['value'] = true;
$result['message'] = "Storing only MetadataURL ".$metadata->href." from capabilities to mb database cause the target could not be accessed or parsed!";
return $result;
@@ -418,7 +774,7 @@
break;
case "upload":
//nothing to do at all?
- $e = new mb_exception("upload found");
+ $e = new mb_exception("class_Iso19139:"."upload found");
//$e = new mb_exception($this->metadata);
$metadata = $this->createMapbenderMetadataFromXML($this->metadata);
@@ -435,7 +791,7 @@
//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!");
+ $e = new mb_exception("class_Iso19139:"."Metadata origin is not known - please set it before storing values to DB!");
$result['value'] = false;
$result['message'] = "Metadata origin is not known - please set it before storing values to DB!";
return $result;
@@ -491,51 +847,100 @@
$res = db_prep_query($sql,$v,$t);
} else {
- //insert new record
- $e = new mb_exception("No existing metadata fileIdentifier found in mapbender metadata table. New record will be inserted with uuid: ".$this->fileIdentifier);
+ //check if href already exists
+ $metadataId = $this->isLinkAlreadyInDB();
+ //if so, the metadataset will be the same - (same url same metadataset) - update this one
+ if ($metadataId != false) {
+ //the link to an existing metadataset already exists - don't store it again or insert anything
+ $e = new mb_exception("existing metadata linkage 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(), ";
+ $sql .= "abstract = $9, searchtext = $10, type = $11, tmp_reference_1 = $12, tmp_reference_2 = $13, export2csw = $14, datasetid = $15, ";
+ $sql .= "datasetid_codespace = $16, randomid = $17, harvestresult = $20, harvestexception = $21, lineage = $22, inspire_top_consistence = $23, ";
+ $sql .= "spatial_res_type = $24, spatial_res_value = $25, update_frequency = $26, format = $27, inspire_charset = $28 WHERE metadata_id = $19";
- $sql = <<<SQL
+ $v = array(
+ $this->href,
+ $this->format,
+ $this->metadata,
+ $this->type,
+ $this->fileIdentifier,
+ $this->title,
+ $this->createDate,
+ $this->changeDate,
+ $this->abstract,
+ $this->keywords[0],
+ $this->hierachyLevel,
+ $this->tmpExtentBegin,
+ $this->tmpExtentEnd,
+ $this->export2Csw,
+ $this->datasetId,
+ $this->datasetIdCodeSpace,
+ $this->randomId,
+ $this->origin,
+ //$this->owner, //owner is the old one - maybe here we have something TODO!
+ $metadataId[0], //The first metadataId which was found will be selected!
+ $this->harvestResult,
+ $this->harvestException,
+ $this->lineage,
+ $this->inspireTopConsistence,
+ $this->spatialResType,
+ $this->spatialResValue,
+ $this->updateFrequency,
+ $this->dataFormat,
+ $this->inspireCharset
+ );
+ $t = array('s','s','s','s','s','s','s','s','s','s','s','s','s','b','s','s','s','s','i','i','s','s','b','s','s','s','s','s');
+ $res = db_prep_query($sql,$v,$t);
+ } else {
+ //insert new record
+ $e = new mb_exception("class_Iso19139:"."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)
SQL;
- $v = array(
- $this->href,
- $this->format,
- $this->metadata,
- $this->type,
- $this->fileIdentifier,
- $this->title,
- $this->createDate,
- $this->changeDate,
- $this->abstract,
- $this->keywords[0],
- $this->hierachyLevel,
- $this->tmpExtentBegin,
- $this->tmpExtentEnd,
- $this->export2Csw,
- $this->datasetId,
- $this->datasetIdCodeSpace,
- $this->randomId,
- $this->origin,
- $this->owner,
- $this->harvestResult,
- $this->harvestException,
- $this->lineage,
- $this->inspireTopConsistence,
- $this->spatialResType,
- $this->spatialResValue,
- $this->updateFrequency,
- $this->dataFormat,
- $this->inspireCharset
+ $v = array(
+ $this->href,
+ $this->format,
+ $this->metadata,
+ $this->type,
+ $this->fileIdentifier,
+ $this->title,
+ $this->createDate,
+ $this->changeDate,
+ $this->abstract,
+ $this->keywords[0],
+ $this->hierachyLevel,
+ $this->tmpExtentBegin,
+ $this->tmpExtentEnd,
+ $this->export2Csw,
+ $this->datasetId,
+ $this->datasetIdCodeSpace,
+ $this->randomId,
+ $this->origin,
+ $this->owner,
+ $this->harvestResult,
+ $this->harvestException,
+ $this->lineage,
+ $this->inspireTopConsistence,
+ $this->spatialResType,
+ $this->spatialResValue,
+ $this->updateFrequency,
+ $this->dataFormat,
+ $this->inspireCharset
- );
- $t = array('s','s','s','s','s','s','s','s','s','s','s','s','s','b','s','s','s','s','i','i','s','s','b','s','s','s','s','s');
- $res = db_prep_query($sql,$v,$t);
+ );
+ $t = array('s','s','s','s','s','s','s','s','s','s','s','s','s','b','s','s','s','s','i','i','s','s','b','s','s','s','s','s');
+ $res = db_prep_query($sql,$v,$t);
+ }
+
}
-
-
if(!$res){
db_rollback();
- $e = new mb_exception(_mb("Cannot insert or update metadata record into mapbenders mb_metadata table!"));
+ $e = new mb_exception("class_Iso19139:"._mb("Cannot insert or update metadata record into mapbenders mb_metadata table!"));
$result['value'] = false;
$result['message'] = "Cannot insert or update metadata record into mapbenders mb_metadata table!";
return $result;
@@ -551,11 +956,11 @@
$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("class_Iso19139:"._mb("Cannot get metadata record with following uuid from database: ".$uuid));
}
if (!$res) {
//do nothing
- $e = new mb_exception(_mb("Cannot get metadata record with following uuid from database: ".$uuid));
+ $e = new mb_exception("class_Iso19139:"._mb("Cannot get metadata record with following uuid from database: ".$uuid));
$result['value'] = false;
$result['message'] = "Cannot get metadata record with following uuid from database: ".$uuid;
return $result;
@@ -565,7 +970,7 @@
$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!"));
+ $e = new mb_exception("class_Iso19139:"._mb("Relation already exists - it will not be generated twice!"));
$result['value'] = true;
$result['message'] = "Relation already exists - it will not be generated twice!";
return $result;
@@ -577,7 +982,7 @@
$res = db_prep_query($sql,$v,$t);
if(!$res){
db_rollback();
- $e = new mb_exception(_mb("Cannot insert metadata relation!"));
+ $e = new mb_exception("class_Iso19139:"._mb("Cannot insert metadata relation!"));
$result['value'] = false;
$result['message'] = "Cannot insert metadata relation!";
return $result;
@@ -588,7 +993,7 @@
$res = db_prep_query($sql,$v,$t);
if(!$res){
db_rollback();
- $e = new mb_exception(_mb("Cannot update mb_metadata table to fill in harvest result!"));
+ $e = new mb_exception("class_Iso19139:"._mb("Cannot update mb_metadata table to fill in harvest result!"));
$result['value'] = false;
$result['message'] = "Cannot update mb_metadata table to fill in harvest result!";
return $result;
More information about the Mapbender_commits
mailing list