[Mapbender-commits] r8377 - in trunk/mapbender/http: classes plugins
svn_mapbender at osgeo.org
svn_mapbender at osgeo.org
Thu Jun 14 07:34:38 PDT 2012
Author: armin11
Date: 2012-06-14 07:34:37 -0700 (Thu, 14 Jun 2012)
New Revision: 8377
Added:
trunk/mapbender/http/plugins/mb_metadata_xml_import_wfs.js
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_addon.php
trunk/mapbender/http/plugins/mb_metadata_server.php
trunk/mapbender/http/plugins/mb_metadata_wfs_server.php
Log:
Change of mb_metadata handling for INSPIRE and SDI conformity. Mapbenders mb_metadata table don't store duplicated entries any more. Further TODOs: 1. Test all things, 2. better parsing of iso19139 files in class_iso19139 (more mimetypes, more content), 3. module to delete orphaned metadata entries, 4. allow cross linking of metador entries from mb_metadata
Modified: trunk/mapbender/http/classes/class_iso19139.php
===================================================================
--- trunk/mapbender/http/classes/class_iso19139.php 2012-06-14 11:58:58 UTC (rev 8376)
+++ trunk/mapbender/http/classes/class_iso19139.php 2012-06-14 14:34:37 UTC (rev 8377)
@@ -261,7 +261,7 @@
public function isFileIdentifierAlreadyInDB(){
$sql = <<<SQL
-SELECT metadata_id FROM mb_metadata WHERE uuid = $1 ORDER BY lastchanged DESC
+SELECT metadata_id, createdate FROM mb_metadata WHERE uuid = $1 ORDER BY lastchanged DESC
SQL;
$v = array(
$this->fileIdentifier
@@ -370,6 +370,7 @@
}
public function insertToDB($resourceType, $resourceId){
+ $result = array(); //value/message
switch ($this->origin) {
case "capabilities":
//check if href is given and resource can be parsed
@@ -381,10 +382,15 @@
//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;
+ $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!");
- return true;
+ $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;
}
}
}
@@ -396,10 +402,14 @@
//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;
+ $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!");
- return true;
+ $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;
}
}
break;
@@ -414,8 +424,9 @@
if ($metadata == false) {
//xml could not be parsed
-
- return false;
+ $result['value'] = false;
+ $result['message'] = "Metadata bbject could not be created!";
+ return $result;
}
//else save it into database
break;
@@ -425,7 +436,9 @@
break;*/
default:
$e = new mb_exception( "Metadata origin is not known - please set it before storing values to DB!");
- return false;
+ $result['value'] = false;
+ $result['message'] = "Metadata origin is not known - please set it before storing values to DB!";
+ return $result;
}
//check if metadata record already exists, if not create a new one, else insert relation only and update the metadata itself!
@@ -523,7 +536,9 @@
if(!$res){
db_rollback();
$e = new mb_exception(_mb("Cannot insert or update metadata record into mapbenders mb_metadata table!"));
- return false;
+ $result['value'] = false;
+ $result['message'] = "Cannot insert or update metadata record into mapbenders mb_metadata table!";
+ return $result;
} else {
//insert relation into db
//get inserted metadata_id
@@ -541,7 +556,9 @@
if (!$res) {
//do nothing
$e = new mb_exception(_mb("Cannot get metadata record with following uuid from database: ".$uuid));
- return false;
+ $result['value'] = false;
+ $result['message'] = "Cannot get metadata record with following uuid from database: ".$uuid;
+ return $result;
} else {
//insert relation
$row = db_fetch_assoc($res);
@@ -549,7 +566,9 @@
//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;
+ $result['value'] = true;
+ $result['message'] = "Relation already exists - it will not be generated twice!";
+ return $result;
}
//insert relation to layer/featuretype
$sql = "INSERT INTO ows_relation_metadata (fkey_".$resourceType."_id, fkey_metadata_id, relation_type) values ($1, $2, $3);";
@@ -559,7 +578,9 @@
if(!$res){
db_rollback();
$e = new mb_exception(_mb("Cannot insert metadata relation!"));
- return false;
+ $result['value'] = false;
+ $result['message'] = "Cannot insert metadata relation!";
+ return $result;
} else {
$sql = "UPDATE mb_metadata SET harvestresult = 1 where metadata_id = $1";
$v = array($metadataId);
@@ -568,11 +589,15 @@
if(!$res){
db_rollback();
$e = new mb_exception(_mb("Cannot update mb_metadata table to fill in harvest result!"));
- return false;
+ $result['value'] = false;
+ $result['message'] = "Cannot update mb_metadata table to fill in harvest result!";
+ return $result;
}
}
}
- return true;
+ $result['value'] = true;
+ $result['message'] = "Insert metadata successfully into database!";
+ return $result;
}
}
Modified: trunk/mapbender/http/classes/class_wfsToDb.php
===================================================================
--- trunk/mapbender/http/classes/class_wfsToDb.php 2012-06-14 11:58:58 UTC (rev 8376)
+++ trunk/mapbender/http/classes/class_wfsToDb.php 2012-06-14 14:34:37 UTC (rev 8377)
@@ -386,10 +386,14 @@
$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!");
+
+ $result = $mbMetadata->insertToDB("featuretype",$aWfsFeatureTypeId);
+
+ if ($result['value'] == false){
+ $e = new mb_exception("Problem while storing metadata url from wfs to db");
+ $e = new mb_exception($result['message']);
} else {
- $e = new mb_exception("Stored metadata from capabilities to mapbender database!");
+ $e = new mb_notice("Storing of metadata url from wfs to db was successful");
}
return true;
}
Modified: trunk/mapbender/http/classes/class_wms.php
===================================================================
--- trunk/mapbender/http/classes/class_wms.php 2012-06-14 11:58:58 UTC (rev 8376)
+++ trunk/mapbender/http/classes/class_wms.php 2012-06-14 14:34:37 UTC (rev 8377)
@@ -2377,10 +2377,17 @@
$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!");
+
+ $result = $mbMetadata->insertToDB("layer",$this->objLayer[$i]->db_id);
+
+ if ($result['value'] == false){
+ $e = new mb_exception("Problem while storing metadata url from wms to db");
+ $e = new mb_exception($result['message']);
+
+
} else {
- $e = new mb_exception("Stored metadata from capabilities to mapbender database!");
+ $e = new mb_notice("Storing of metadata url from wms to db was successful");
+ $e = new mb_notice($result['message']);
}
}
}
Modified: trunk/mapbender/http/plugins/mb_metadata_addon.php
===================================================================
--- trunk/mapbender/http/plugins/mb_metadata_addon.php 2012-06-14 11:58:58 UTC (rev 8376)
+++ trunk/mapbender/http/plugins/mb_metadata_addon.php 2012-06-14 14:34:37 UTC (rev 8377)
@@ -118,6 +118,7 @@
<option value="tab"><?php echo _mb("MapInfo Tab file");?></option>
<option value="csv"><?php echo _mb("CSV");?></option>
<option value="gml"><?php echo _mb("GML");?></option>
+ <option value="geotiff"><?php echo _mb("GeoTIFF");?></option>
</select>
</fieldset>
<fieldset id="charset">
Modified: trunk/mapbender/http/plugins/mb_metadata_server.php
===================================================================
--- trunk/mapbender/http/plugins/mb_metadata_server.php 2012-06-14 11:58:58 UTC (rev 8376)
+++ trunk/mapbender/http/plugins/mb_metadata_server.php 2012-06-14 14:34:37 UTC (rev 8377)
@@ -863,21 +863,32 @@
$mbMetadata->type = "ISO19115:2003";
$mbMetadata->origin = "external";
$mbMetadata->owner = $mdOwner;
- if (!$mbMetadata->insertToDB("layer",$layerId)){
+
+ $result = $mbMetadata->insertToDB("layer",$layerId);
+
+ if ($result['value'] == false){
$e = new mb_exception("Problem while storing metadata to mb_metadata table!");
+ $e = new mb_exception($result['message']);
+ abort($result['message']);
} else {
- $e = new mb_exception("Stored metadata from external link to mapbender database!");
+ $ajaxResponse->setMessage("Stored metadata from external link to mapbender database!");
+ $ajaxResponse->setSuccess(true);
+ $e = new mb_notice("Stored metadata from external link to mapbender database!");
}
} else { //fill thru metador
$mbMetadata->origin = "metador";
$mbMetadata->fileIdentifier = $uuid;
$mbMetadata->randomId = $randomid;
- if (!$mbMetadata->insertToDB("layer",$layerId)) {
- $e = new mb_exception("Problem while storing metadata to mb_metadata table!");
- abort("Problem while storing metadata to mb_metadata table!");
+
+ $result = $mbMetadata->insertToDB("layer",$layerId);
+
+ if ($result['value'] == false) {
+ $e = new mb_exception("Problem while storing metadata from editor to mb_metadata table!");
+ $e = new mb_exception($result['message']);
+ abort($result['message']);
} else {
- $e = new mb_notice("Metadata with id ".$randomid." stored to db!");
- $ajaxResponse->setMessage("Metadata object inserted into md_metadata!");
+ $e = new mb_notice("Metadata with id ".$randomid." stored from editor to db!");
+ $ajaxResponse->setMessage("Metadata object from editor inserted into md_metadata!");
$ajaxResponse->setSuccess(true);
}
}
@@ -952,14 +963,20 @@
$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!");
+
+ $result = $mbMetadata->insertToDB("layer",$layerId);
+
+ if ($result['value'] == false){
+ $e = new mb_exception("Problem while storing uploaded metadata xml to mb_metadata table!");
+ $e = new mb_exception($result['message']);
+ abort($result['message']);
+
} else {
- $e = new mb_exception("Metadata with random id ".$randomid." stored to db!");
- abort("Metadata from local file was uploaded!");
+ $e = new mb_notice("Metadata with random id ".$randomid." stored to db!");
+ $ajaxResponse->setMessage("Uploaded metadata object inserted into md_metadata table!");
+ $ajaxResponse->setSuccess(true);
}
- $ajaxResponse->setMessage("Uploaded metadata object inserted into md_metadata table!");
- $ajaxResponse->setSuccess(true);
+
break;
default:
Modified: trunk/mapbender/http/plugins/mb_metadata_wfs_server.php
===================================================================
--- trunk/mapbender/http/plugins/mb_metadata_wfs_server.php 2012-06-14 11:58:58 UTC (rev 8376)
+++ trunk/mapbender/http/plugins/mb_metadata_wfs_server.php 2012-06-14 14:34:37 UTC (rev 8377)
@@ -638,21 +638,32 @@
$mbMetadata->type = "ISO19115:2003";
$mbMetadata->origin = "external";
$mbMetadata->owner = $mdOwner;
- if (!$mbMetadata->insertToDB("featuretype",$featuretypeId)){
+
+ $result = $mbMetadata->insertToDB("featuretype",$featuretypeId);
+
+ if ($result['value'] == false){
$e = new mb_exception("Problem while storing metadata to mb_metadata table!");
+ $e = new mb_exception($result['message']);
+ abort($result['message']);
} else {
- $e = new mb_exception("Stored metadata from external link to mapbender database!");
+ $ajaxResponse->setMessage("Stored metadata from external link to mapbender database!");
+ $ajaxResponse->setSuccess(true);
+ $e = new mb_notice("Stored metadata from external link to mapbender database!");
}
} else { //fill thru metador
$mbMetadata->origin = "metador";
$mbMetadata->fileIdentifier = $uuid;
$mbMetadata->randomId = $randomid;
- if (!$mbMetadata->insertToDB("featuretype",$featuretypeId)) {
- $e = new mb_exception("Problem while storing metadata to mb_metadata table!");
- abort("Problem while storing metadata to mb_metadata table!");
+
+ $result = $mbMetadata->insertToDB("featuretype",$featuretypeId);
+
+ if ($result['value'] == false) {
+ $e = new mb_exception("Problem while storing metadata from editor to mb_metadata table!");
+ $e = new mb_exception($result['message']);
+ abort($result['message']);
} else {
- $e = new mb_notice("Metadata with id ".$randomid." stored to db!");
- $ajaxResponse->setMessage("Metadata object inserted into md_metadata!");
+ $e = new mb_notice("Metadata with id ".$randomid." stored from editor to db!");
+ $ajaxResponse->setMessage("Metadata object from editor inserted into md_metadata!");
$ajaxResponse->setSuccess(true);
}
}
@@ -725,14 +736,19 @@
$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!");
+
+ $result = $mbMetadata->insertToDB("featuretype",$featuretypeId);
+
+ if ($result['value'] == false){
+ $e = new mb_exception("Problem while storing uploaded metadata xml to mb_metadata table!");
+ $e = new mb_exception($result['message']);
+ abort($result['message']);
+
} else {
- $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);
+ $e = new mb_notice("Metadata with random id ".$randomid." stored to db!");
+ $ajaxResponse->setMessage("Uploaded metadata object inserted into md_metadata table!");
+ $ajaxResponse->setSuccess(true);
+ }
break;
case "save":
Added: trunk/mapbender/http/plugins/mb_metadata_xml_import_wfs.js
===================================================================
--- trunk/mapbender/http/plugins/mb_metadata_xml_import_wfs.js (rev 0)
+++ trunk/mapbender/http/plugins/mb_metadata_xml_import_wfs.js 2012-06-14 14:34:37 UTC (rev 8377)
@@ -0,0 +1,88 @@
+var $xmlImport = $(this);
+var importXmlFeaturetypeId;
+
+var XmlImportApi = function () {
+ var that = this;
+ var type;
+
+ this.events = {
+ "uploadComplete" : new Mapbender.Event()
+ };
+
+ this.events.uploadComplete.register(function () {
+ $xmlImport.dialog("close");
+ });
+
+ var importUploadedFile = function(filename, featuretypeId, callback){
+ var req = new Mapbender.Ajax.Request({
+ url: "../plugins/mb_metadata_wfs_server.php",
+ method: "importFeaturetypeXmlAddon",
+ parameters: {
+ filename: filename,
+ featuretypeId: featuretypeId
+ },
+ callback: function (obj, result, message, errorCode) {
+ if (!result) {
+ switch (errorCode) {
+ case -1002:
+ alert("file: "+filename+"has problems: "+message);
+ break;
+ default:
+ alert(message);
+ return;
+ }
+ }
+ alert(message);
+ $xmlImport.dialog("close");
+ //invoke external script from mb_metadata_showMetadataAddon.js
+ //that.fillFeaturetypeForm(featuretypeId);
+ Mapbender.modules.mb_md_showMetadataAddonWfs.fillFeaturetypeForm(featuretypeId);
+ if ($.isFunction(callback)) {
+ callback(obj.id);
+ }
+ }
+ });
+ req.send();
+ };
+
+ $xmlImport.upload({
+ size: 10,
+ timeout: 20000,
+ url: "../plugins/jq_upload.php",
+ callback: function(result,stat,msg){
+ if(!result){
+ alert(msg);
+ return;
+ }
+ var uploadResultName = result.filename;
+ var uploadResultOrigName = result.origFilename;
+
+ importUploadedFile(result.filename, that.importXmlFeaturetypeId, function (id) {
+ that.events.uploadComplete.trigger({
+ "type": type,
+ "id": id
+ });
+ });
+ }
+ }).dialog({
+ title: 'XML Import',
+ autoOpen: false,
+ modal: true,
+ width: 580
+ });
+
+
+ this.init = function (obj) {
+ type = obj.type;
+ $xmlImport.dialog("open");
+ };
+
+ initXmlImport = function (featuretypeId) {
+ that.importXmlFeaturetypeId = featuretypeId;
+ $xmlImport.dialog("open");
+ return true;
+ };
+
+};
+
+$xmlImport.mapbender(new XmlImportApi());
More information about the Mapbender_commits
mailing list