[Mapbender-commits] r8690 - in trunk/mapbender: conf http/classes http/plugins
svn_mapbender at osgeo.org
svn_mapbender at osgeo.org
Thu Aug 22 06:51:41 PDT 2013
Author: armin11
Date: 2013-08-22 06:51:41 -0700 (Thu, 22 Aug 2013)
New Revision: 8690
Modified:
trunk/mapbender/conf/isoMetadata.conf
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_server.php
trunk/mapbender/http/plugins/mb_metadata_showMetadataAddon.js
trunk/mapbender/http/plugins/mb_metadata_showMetadataAddonWfs.js
trunk/mapbender/http/plugins/mb_metadata_wfs_server.php
Log:
Enhancement to allow that the layer and featuretypes inherit the classification from coupled iso19139 datasets.
Modified: trunk/mapbender/conf/isoMetadata.conf
===================================================================
--- trunk/mapbender/conf/isoMetadata.conf 2013-08-22 13:33:25 UTC (rev 8689)
+++ trunk/mapbender/conf/isoMetadata.conf 2013-08-22 13:51:41 UTC (rev 8690)
@@ -241,7 +241,7 @@
//B 6.2.2 ground distance
//B 6.2.2.1 ground distance value (18)
array( ibus => "t01_object.obj_id",
- iso19139 => "/gmd:MD_Metadata/gmd:identificationInfo/gmd:MD_DataIdentification/gmd:spatialResolution/gmd:MD_Resolution/gmd:distancegco:Distance",
+ iso19139 => "/gmd:MD_Metadata/gmd:identificationInfo/gmd:MD_DataIdentification/gmd:spatialResolution/gmd:MD_Resolution/gmd:distance/gco:Distance",
iso19139explode => "false" ,
inspire => "ground distance value",
inspiremandatory => "true",
Modified: trunk/mapbender/http/classes/class_iso19139.php
===================================================================
--- trunk/mapbender/http/classes/class_iso19139.php 2013-08-22 13:33:25 UTC (rev 8689)
+++ trunk/mapbender/http/classes/class_iso19139.php 2013-08-22 13:51:41 UTC (rev 8690)
@@ -311,7 +311,7 @@
$err = new mb_exception("class_Iso19139:".$e->getMessage());
return "error";
}
- $err = new mb_exception("class_Iso19139: result of iso19139Xml: ". gettype($iso19139Xml));
+ $err = new mb_notice("class_Iso19139: result of iso19139Xml: ". gettype($iso19139Xml));
//if parsing was successful
if ($iso19139Xml !== false) {
$e = new mb_notice("Parsing of xml metadata file was successfull");
@@ -783,7 +783,7 @@
}
- //TODO: following 2 functions are not used til now - check plugins mb_metadata_server scripts to exchange handling
+ //following function is e.g. used by class_wms.php and class_wfsToDb.php
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
@@ -799,7 +799,7 @@
}
}
- public function insertMetadataRelation($resourceType, $resourceId, $relationType){
+ /*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."'";
@@ -812,12 +812,12 @@
} else {
return true;
}
- }
+ }*/
- public function checkMetadataRelation($resourceType, $resourceId, $metadataId){
+ public function checkMetadataRelation($resourceType, $resourceId, $metadataId, $origin){
//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);
+ $v = array($resourceId, $metadataId, $origin);
$t = array('i','i','s');
$res = db_prep_query($sql,$v,$t);
while ($row = db_fetch_array($res)){
@@ -830,6 +830,35 @@
}
}
+ public function setInternalMetadataLinkage($metadataId,$resourceType, $resourceId){
+ //check if internal linkage already exists
+ if ($this->checkMetadataRelation($resourceType, $resourceId, $metadataId, 'internal')) {
+ $returnObject['success'] = false;
+ $returnObject['message'] = _mb("Internal link already exists in database - it will not be created twice!");
+ return $returnObject;
+ } else {
+ //if not create it
+ $returnObject = array();
+ $sql = "INSERT INTO ows_relation_metadata (fkey_metadata_id, fkey_".$resourceType."_id, internal, relation_type) VALUES ( $1, $2, $3, 'internal')";
+ $v = array($metadataId,$resourceId, 1);
+ $t = array('i','i','i');
+ try {
+ $res = db_prep_query($sql,$v,$t);
+ }
+ catch (Exception $E){
+ $returnObject['success'] = false;
+ $returnObject['message'] = _mb("Could not insert internal metadatalink into database!");
+ return $returnObject;
+ }
+ //bequeath categories from coupled resources
+ $this->bequeathCategoriesToCoupledResource($metadataId,$resourceType,$resourceId);
+ $e = new mb_exception("iso19139.php: bequeathed categories to ".$resourceType." : ".$resourceId);
+ $returnObject['success'] = true;
+ $returnObject['message'] = _mb("Internal metadata linkage inserted!");
+ return $returnObject;
+ }
+ }
+
public function deleteInternalMetadataLinkage($resourceType, $resourceId, $metadataId){
$returnObject = array();
$sql = "DELETE FROM ows_relation_metadata WHERE fkey_metadata_id = $1 and fkey_".$resourceType."_id = $2 and relation_type = 'internal'";
@@ -843,11 +872,15 @@
$returnObject['message'] = _mb("Could not delete internal metadata linkage from database!");
return $returnObject;
}
+ //delete categories from coupled resources
+ $this->deleteCategoriesFromCoupledResource($metadataId,$resourceType,$resourceId);
$returnObject['success'] = true;
$returnObject['message'] = _mb("Internal metadata linkage deleted!");
return $returnObject;
}
+
+
public function deleteMetadataAddon($resourceType, $resourceId, $metadataId){
$returnObject = array();
$sql = "SELECT count(*) as count FROM ows_relation_metadata WHERE fkey_metadata_id = $1";
@@ -894,6 +927,8 @@
$returnObject['message'] = _mb("Could not delete internal metadata linkage from database!");
return $returnObject;
}
+ //delete categories from coupled resources
+ $this->deleteCategoriesFromCoupledResource($metadataId,$resourceType,$resourceId);
$returnObject['success'] = true;
$returnObject['message'] = _mb("Metadata and/or linkage was deleted from database!");
return $returnObject;
@@ -910,6 +945,8 @@
$returnObject['message'] = _mb("Could not delete metadata linkage from database!");
return $returnObject;
}
+ //delete categories from coupled resources
+ $this->deleteCategoriesFromCoupledResource($metadataId,$resourceType,$resourceId);
$returnObject['success'] = true;
$returnObject['message'] = _mb("Metadata linkage deleted!");
return $returnObject;
@@ -959,9 +996,9 @@
}
}
- public function insertKeywordsAndCategoriesIntoDB($metadataId){
+ public function insertKeywordsAndCategoriesIntoDB($metadataId,$resourceType,$resourceId){
//first delete old classifications - after that create new ones
- $this->deleteKeywordsAndCategoriesFromDB($metadataId);
+ $this->deleteKeywordsAndCategoriesFromDB($metadataId,$resourceType,$resourceId);
//insert keywords and categories into tables!
//parse keywords and isoCategories
//INSERT INTO films (code, title, did, date_prod, kind) VALUES
@@ -971,7 +1008,14 @@
//map category name to id before insert them into db!
//read maptable from db
//iso - code in xml
-
+ switch ($resourceType) {
+ case "featuretype":
+ $tablePrefix = 'wfs_featuretype';
+ break;
+ case "layer":
+ $tablePrefix = 'layer';
+ break;
+ }
//map keys into relevant ids
$sqlInsert = "";
if (count($this->isoCategories) > 0) {
@@ -1021,6 +1065,7 @@
$e = new mb_exception("class_Iso19139:"._mb("Cannot insert custom categories for this metadata!"));
}
}
+ $this->bequeathCategoriesToCoupledResource($metadataId,$resourceType,$resourceId);
$sqlInsert = "";
//insert keywords into keyword table
//foreach keyword look for an id or create it newly - made for postgres > 8.2 with returning option for insert statement
@@ -1036,7 +1081,7 @@
$countExistingKeywords = 0;
while ($row = db_fetch_assoc($res)) {
$existingKeywords[$countExistingKeywords]['keyword'] = $row['keyword'];
- $e = new mb_exception("existing keyword: ".$row['keyword']);
+ //$e = new mb_exception("existing keyword: ".$row['keyword']);
$existingKeywords[$countExistingKeywords]['id'] = $row['keyword_id'];
$existingKeywordsArray[$countExistingKeywords] = $row['keyword'];
$countExistingKeywords++;
@@ -1056,12 +1101,12 @@
}
$sqlInsert = rtrim($sqlInsert,",");
$sql = "INSERT INTO mb_metadata_keyword (fkey_metadata_id, fkey_keyword_id) VALUES ".$sqlInsert;
- $e = new mb_exception("class_Iso19139.php: sql for keywords: ".$sql);
+ //$e = new mb_exception("class_Iso19139.php: sql for keywords: ".$sql);
$res = db_query($sql);
if (!$res) {
$e = new mb_exception("class_Iso19139:"._mb("Cannot insert keyword relations for this metadata!"));
} else {
- $e = new mb_exception("class_Iso19139:"._mb("Inserted keyword relations for existing keywords!"));
+ $e = new mb_notice("class_Iso19139:"._mb("Inserted keyword relations for existing keywords!"));
}
}
//insert those keywords, that are not already in the keyword table
@@ -1082,13 +1127,13 @@
$otherKeywords = $this->keywords;
}
//debug
- foreach ($otherKeywords as $test) {
+ /*foreach ($otherKeywords as $test) {
$e = new mb_exception("otherKeywords: ".$test);
}
- $e = new mb_exception("otherKeywords: ".$otherKeywords);
+ $e = new mb_exception("otherKeywords: ".$otherKeywords);*/
if (count($otherKeywords) > 0) {
if (count($otherKeywords) == 1) {
- $e = new mb_exception("Only one new keyword found: ".$otherKeywords[0]);
+ //$e = new mb_exception("Only one new keyword found: ".$otherKeywords[0]);
//keyword table
$sqlInsert .= "('".$otherKeywords[0]."')";
} else {
@@ -1098,7 +1143,7 @@
}
$sqlInsert = rtrim($sqlInsert,",");
$sql = "INSERT INTO keyword (keyword) VALUES ".$sqlInsert." RETURNING keyword_id" ;
- $e = new mb_exception("class_Iso19139.php: sql for keywords: ".$sql);
+ //$e = new mb_exception("class_Iso19139.php: sql for keywords: ".$sql);
$res = db_query($sql);
if (!$res) {
$e = new mb_exception("class_Iso19139:"._mb("Cannot insert new keywords into keyword table!"));
@@ -1119,7 +1164,7 @@
}
$sqlInsert = rtrim($sqlInsert,",");
$sql = "INSERT INTO mb_metadata_keyword (fkey_metadata_id, fkey_keyword_id) VALUES ".$sqlInsert;
- $e = new mb_notice("class_Iso19139.php: sql for keyword relation: ".$sql);
+ //$e = new mb_notice("class_Iso19139.php: sql for keyword relation: ".$sql);
$res = db_query($sql);
if (!$res) {
$e = new mb_exception("class_Iso19139:"._mb("Cannot insert metadata keyword relations into db!"));
@@ -1128,7 +1173,71 @@
}
}
- public function deleteKeywordsAndCategoriesFromDB($metadataId) {
+ public function deleteCategoriesFromCoupledResource($metadataId,$resourceType,$resourceId) {
+ //delete inherited categories from coupled resources: layer/featuretype
+ switch ($resourceType) {
+ case "featuretype":
+ $tablePrefix = 'wfs_featuretype';
+ break;
+ case "layer":
+ $tablePrefix = 'layer';
+ break;
+ }
+ $types = array("md_topic", "inspire", "custom");
+ foreach ($types as $cat) {
+ $sql = "DELETE FROM ".$tablePrefix."_{$cat}_category WHERE fkey_metadata_id = $1 AND fkey_".$resourceType."_id = $2";
+ $v = array($metadataId,$resourceId);
+ $t = array('i','i');
+ $res = db_prep_query($sql,$v,$t);
+ if(!$res){
+ $e = new mb_exception("class_Iso19139:"._mb("Cannot delete categories from ".$resourceType." with id ".$resourceId));
+ }
+ }
+ }
+
+ public function bequeathCategoriesToCoupledResource($metadataId,$resourceType,$resourceId) {
+ //delete inherited categories from coupled resources: layer/featuretype
+ switch ($resourceType) {
+ case "featuretype":
+ $tablePrefix = 'wfs_featuretype';
+ break;
+ case "layer":
+ $tablePrefix = 'layer';
+ break;
+ }
+ //all categories
+ $types = array("md_topic", "inspire", "custom");
+
+ foreach ($types as $cat) {
+ switch ($cat) {
+ case "md_topic":
+ $objectPrefix = 'iso';
+ break;
+ default:
+ $objectPrefix = $cat;
+ break;
+ }
+ $sqlInsertCoupledResource = "";
+ if (count($this->{$objectPrefix."Categories"}) > 0) {
+ if (count($this->{$objectPrefix."Categories"}) == 1) {
+ $sqlInsertCoupledResource .= "(".(integer)$metadataId.",".(integer)$this->{$objectPrefix."Categories"}.",".$resourceId.")";
+ } else {
+ foreach ($this->{$objectPrefix."Categories"} as ${$objectPrefix."Category"}) {
+ $sqlInsertCoupledResource .= "(".(integer)$metadataId.",".(integer)${$objectPrefix."Category"}.",".$resourceId."),";
+
+ }
+ }
+ $sqlInsertCoupledResource = rtrim($sqlInsertCoupledResource,",");
+ $sqlCoupledResource = "INSERT INTO ".$tablePrefix."_{$cat}_category (fkey_metadata_id, fkey_{$cat}_category_id, fkey_".$resourceType."_id) VALUES ".$sqlInsertCoupledResource;
+ $res = db_query($sqlCoupledResource);
+ if (!$res) {
+ $e = new mb_exception("class_Iso19139:"._mb("Cannot insert $cat categories to coupled resource!"));
+ }
+ }
+ }
+ }
+
+ public function deleteKeywordsAndCategoriesFromDB($metadataId,$resourceType,$resourceId) {
$sql = "DELETE FROM mb_metadata_md_topic_category where fkey_metadata_id = $1 ";
$v = array($metadataId);
$t = array('i');
@@ -1136,7 +1245,7 @@
if (!$res) {
$e = new mb_exception("class_Iso19139:"._mb("Cannot delete topic category relations for metadata with id ".$metadataId));
} else {
- $e = new mb_exception("class_Iso19139: topic category relations deleted from database!");
+ $e = new mb_notice("class_Iso19139: topic category relations deleted from database!");
}
$sql = "DELETE FROM mb_metadata_inspire_category where fkey_metadata_id = $1 ";
$v = array($metadataId);
@@ -1145,7 +1254,7 @@
if (!$res) {
$e = new mb_exception("class_Iso19139:"._mb("Cannot delete inspire category relations for metadata with id ".$metadataId));
} else {
- $e = new mb_exception("class_Iso19139: inspire category relations deleted from database!");
+ $e = new mb_notice("class_Iso19139: inspire category relations deleted from database!");
}
$sql = "DELETE FROM mb_metadata_custom_category where fkey_metadata_id = $1 ";
$v = array($metadataId);
@@ -1154,7 +1263,7 @@
if (!$res) {
$e = new mb_exception("class_Iso19139:"._mb("Cannot delete custom category relations for metadata with id ".$metadataId));
} else {
- $e = new mb_exception("class_Iso19139: custom category relations deleted from database!");
+ $e = new mb_notice("class_Iso19139: custom category relations deleted from database!");
}
//delete keyword relations - problem, that keywords are referenced from more than one table. We can only delete the relations but there may be orphaned keywords, which have to be deleted by cronjob - maybe - TODO
$sql = "DELETE FROM mb_metadata_keyword where fkey_metadata_id = $1 ";
@@ -1164,8 +1273,9 @@
if (!$res) {
$e = new mb_exception("class_Iso19139:"._mb("Cannot delete keyword relations for metadata with id ".$metadataId));
} else {
- $e = new mb_exception("class_Iso19139: keyword relations deleted from database!");
+ $e = new mb_notice("class_Iso19139: keyword relations deleted from database!");
}
+ $this->deleteCategoriesFromCoupledResource($metadataId,$resourceType,$resourceId);
}
public function insertMetadataIntoDB() {
@@ -1264,7 +1374,7 @@
$metadataId = $this->isLinkAlreadyInDB();
if ($metadataId != false) {
//update the metadataURL entry
- $e = new mb_exception("class_Iso19139:"."existing metadata link(s) found: ".$metadataId[0]." - update will be performed");
+ $e = new mb_notice("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,
@@ -1437,7 +1547,7 @@
break;
case "upload":
//nothing to do at all?
- $e = new mb_exception("class_Iso19139:"."upload found");
+ $e = new mb_notice("class_Iso19139:"."upload found");
//$e = new mb_exception($this->metadata);
$metadata = $this->createMapbenderMetadataFromXML($this->metadata);
@@ -1449,10 +1559,10 @@
}
//else save it into database
break;
- /*case "internal":
+ case "internal":
//only set relation to existing record - return true;
//is actually handled thru plugins/mn_metadata_server*
- break;*/
+ break;
default:
$e = new mb_exception("class_Iso19139:"."Metadata origin is not known - please set it before storing values to DB!");
$result['value'] = false;
@@ -1465,7 +1575,7 @@
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");
+ $e = new mb_notice("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!!!!
$res = $this->updateMetadataById($metadataId[0]);
} else {
@@ -1474,15 +1584,16 @@
//if so, the metadataset will be the same - (same url same metadataset) - update this as before
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");
+ $e = new mb_notice("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!!!!
$res = $this->updateMetadataById($metadataId[0]);
} 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);
+ $e = new mb_notice("class_Iso19139:"."No existing metadata fileIdentifier found in mapbender metadata table. New record will be inserted with uuid: ".$this->fileIdentifier);
$res = $this->insertMetadataIntoDB();
}
}
+ //after insert/update metadata do the relational things
if(!$res){
db_rollback();
$e = new mb_exception("class_Iso19139:"._mb("Cannot insert or update metadata record into mapbenders mb_metadata table!"));
@@ -1514,8 +1625,8 @@
$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("class_Iso19139:"._mb("Relation already exists - it will not be generated twice!"));
+ if ($this->checkMetadataRelation($resourceType, $resourceId, $metadataId,$this->origin)) {
+ $e = new mb_notice("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;
@@ -1543,7 +1654,8 @@
$result['message'] = "Cannot update mb_metadata table to fill in harvest result!";
return $result;
} else {
- $this->insertKeywordsAndCategoriesIntoDB($metadataId);
+ $this->insertKeywordsAndCategoriesIntoDB($metadataId,$resourceType,$resourceId);
+ //if this was ok, lat the resource (layer/featuretype) inherit the classification from the coupled metadata to support better catalogue search
}
}
}
Modified: trunk/mapbender/http/classes/class_wfsToDb.php
===================================================================
--- trunk/mapbender/http/classes/class_wfsToDb.php 2013-08-22 13:33:25 UTC (rev 8689)
+++ trunk/mapbender/http/classes/class_wfsToDb.php 2013-08-22 13:51:41 UTC (rev 8690)
@@ -1224,7 +1224,7 @@
if ($overwrite) {
$types = array("md_topic", "inspire", "custom");
foreach ($types as $cat) {
- $sql = "DELETE FROM wfs_featuretype_{$cat}_category WHERE fkey_featuretype_id = $1";
+ $sql = "DELETE FROM wfs_featuretype_{$cat}_category WHERE fkey_featuretype_id = $1 AND fkey_metadata_id ISNULL";
$v = array($aWfsFeatureType->id);
$t = array('i');
$res = db_prep_query($sql,$v,$t);
Modified: trunk/mapbender/http/classes/class_wms.php
===================================================================
--- trunk/mapbender/http/classes/class_wms.php 2013-08-22 13:33:25 UTC (rev 8689)
+++ trunk/mapbender/http/classes/class_wms.php 2013-08-22 13:51:41 UTC (rev 8690)
@@ -2322,7 +2322,7 @@
$types = array("md_topic", "inspire", "custom");
foreach ($types as $cat) {
- $sql = "DELETE FROM layer_{$cat}_category WHERE fkey_layer_id = $1";
+ $sql = "DELETE FROM layer_{$cat}_category WHERE fkey_layer_id = $1 AND fkey_metadata_id ISNULL";
$v = array($this->objLayer[$i]->db_id);
$t = array('i');
$res = db_prep_query($sql,$v,$t);
@@ -3469,7 +3469,7 @@
$count_layer_keywords++;
}
### read out layer_md_topic_category_id
- $sql = "SELECT fkey_md_topic_category_id FROM layer_md_topic_category WHERE fkey_layer_id = $1";
+ $sql = "SELECT fkey_md_topic_category_id FROM layer_md_topic_category WHERE fkey_layer_id = $1 AND fkey_metadata_id ISNULL";
$v = array($this->objLayer[$layer_cnt]->layer_uid);
$t = array('i');
$res_layer_md_topic_category = db_prep_query($sql,$v,$t);
@@ -3480,7 +3480,7 @@
$count_layer_md_topic_category++;
}
### read out layer_inspire_category_id
- $sql = "SELECT fkey_inspire_category_id FROM layer_inspire_category WHERE fkey_layer_id = $1";
+ $sql = "SELECT fkey_inspire_category_id FROM layer_inspire_category WHERE fkey_layer_id = $1 AND fkey_metadata_id ISNULL";
$v = array($this->objLayer[$layer_cnt]->layer_uid);
$t = array('i');
$res_layer_inspire_category = db_prep_query($sql,$v,$t);
@@ -3491,7 +3491,7 @@
$count_layer_inspire_category++;
}
### read out layer_custom_category_id
- $sql = "SELECT fkey_custom_category_id FROM layer_custom_category WHERE fkey_layer_id = $1";
+ $sql = "SELECT fkey_custom_category_id FROM layer_custom_category WHERE fkey_layer_id = $1 AND fkey_metadata_id ISNULL";
$v = array($this->objLayer[$layer_cnt]->layer_uid);
$t = array('i');
$res_layer_custom_category = db_prep_query($sql,$v,$t);
Modified: trunk/mapbender/http/plugins/mb_metadata_server.php
===================================================================
--- trunk/mapbender/http/plugins/mb_metadata_server.php 2013-08-22 13:33:25 UTC (rev 8689)
+++ trunk/mapbender/http/plugins/mb_metadata_server.php 2013-08-22 13:51:41 UTC (rev 8690)
@@ -241,7 +241,7 @@
$sql = <<<SQL
SELECT fkey_md_topic_category_id
FROM layer_md_topic_category
-WHERE fkey_layer_id = $layerId
+WHERE fkey_layer_id = $layerId AND fkey_metadata_id ISNULL
SQL;
$res = db_query($sql);
while ($row = db_fetch_assoc($res)) {
@@ -251,7 +251,7 @@
$sql = <<<SQL
SELECT fkey_inspire_category_id
FROM layer_inspire_category
-WHERE fkey_layer_id = $layerId
+WHERE fkey_layer_id = $layerId AND fkey_metadata_id ISNULL
SQL;
$res = db_query($sql);
while ($row = db_fetch_assoc($res)) {
@@ -261,7 +261,7 @@
$sql = <<<SQL
SELECT fkey_custom_category_id
FROM layer_custom_category
-WHERE fkey_layer_id = $layerId
+WHERE fkey_layer_id = $layerId AND fkey_metadata_id ISNULL
SQL;
$res = db_query($sql);
while ($row = db_fetch_assoc($res)) {
@@ -723,6 +723,8 @@
break;
case "updateMetadataAddon" :
$metadataId = $ajaxResponse->getParameter("metadataId");
+ $resourceId = $ajaxResponse->getParameter("resourceId");
+ $resourceType = $ajaxResponse->getParameter("resourceType");
//get json data from ajax call
$data = $ajaxResponse->getParameter("data");
//initialize actual metadata object from db!
@@ -778,7 +780,7 @@
$ajaxResponse->setSuccess(false);
} else {
//update relations for keywords and categories
- $mbMetadata->insertKeywordsAndCategoriesIntoDB($metadataId);
+ $mbMetadata->insertKeywordsAndCategoriesIntoDB($metadataId,$resourceType,$resourceId);
$ajaxResponse->setMessage(_mb("Edited metadata was updated in the mapbender database!"));
$ajaxResponse->setSuccess(true);
}
@@ -795,6 +797,7 @@
//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
$sql = <<<SQL
+select distinct metadata_id, title from (
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
@@ -803,7 +806,7 @@
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
+join mb_metadata on ows_r_m.fkey_metadata_id = mb_metadata.metadata_id) as foo order by metadata_id
SQL;
$v = array($user->id, $layerId);
$t = array('i','i');
@@ -829,20 +832,19 @@
//this insert should also push one entry in the ows_relation_metadata table! - after the insert into md_metadata
//origin
if ($data->kindOfMetadataAddOn == 'internallink') {
+ //instantiate existing metadata
+ $mbMetadata = new Iso19139();
+ $mbMetadata->createFromDBInternalId($data->internal_relation);
+ //$e = new mb_exception("plugins/mb_metadata_server.php: created object from db with id: ".$data->internal_relation);
+ $result = $mbMetadata->setInternalMetadataLinkage($data->internal_relation,$resourceType,$resourceId);
//insert a simple relation to an internal metadata entry - but how can this be distinguished?
//we need a new column with type of relation - maybe called internal
-
- $sql = "INSERT INTO ows_relation_metadata (fkey_metadata_id, fkey_".$resourceType."_id, internal, relation_type) VALUES ( $1, $2, $3, 'internal')";
- $v = array($data->internal_relation,$resourceId, 1);
- $t = array('i','i','i');
- $res = db_prep_query($sql,$v,$t);
- if (!$res){
- abort(_mb("Could not insert internal metadatalink into database!"));
- }
- $ajaxResponse->setMessage("Metadatalink inserted!");
- $ajaxResponse->setSuccess(true);
+ $ajaxResponse->setMessage($result['message']);
+ $ajaxResponse->setSuccess($result['success']);
+ //go out here
break;
}
+ //$e = new mb_exception("outside case");
if ($data->kindOfMetadataAddOn == 'link') {
//generate metador entry
$origin = 'external';
Modified: trunk/mapbender/http/plugins/mb_metadata_showMetadataAddon.js
===================================================================
--- trunk/mapbender/http/plugins/mb_metadata_showMetadataAddon.js 2013-08-22 13:33:25 UTC (rev 8689)
+++ trunk/mapbender/http/plugins/mb_metadata_showMetadataAddon.js 2013-08-22 13:51:41 UTC (rev 8690)
@@ -165,6 +165,8 @@
method: "updateMetadataAddon",
parameters: {
"metadataId": metadataId,
+ "resourceId": layerId,
+ "resourceType": "layer",
"data": data
},
callback: function (obj, result, message) {
Modified: trunk/mapbender/http/plugins/mb_metadata_showMetadataAddonWfs.js
===================================================================
--- trunk/mapbender/http/plugins/mb_metadata_showMetadataAddonWfs.js 2013-08-22 13:33:25 UTC (rev 8689)
+++ trunk/mapbender/http/plugins/mb_metadata_showMetadataAddonWfs.js 2013-08-22 13:51:41 UTC (rev 8690)
@@ -164,6 +164,8 @@
method: "updateMetadataAddon",
parameters: {
"metadataId": metadataId,
+ "resourceId": featuretypeId,
+ "resourceType": "featuretype",
"data": data
},
callback: function (obj, result, message) {
Modified: trunk/mapbender/http/plugins/mb_metadata_wfs_server.php
===================================================================
--- trunk/mapbender/http/plugins/mb_metadata_wfs_server.php 2013-08-22 13:33:25 UTC (rev 8689)
+++ trunk/mapbender/http/plugins/mb_metadata_wfs_server.php 2013-08-22 13:51:41 UTC (rev 8690)
@@ -131,7 +131,6 @@
//check if primary group is set
$user = new User;
$userId = $user->id;
- $e = new mb_exception("user id:".$userId);
$sql = <<<SQL
SELECT fkey_mb_group_id, mb_group_name, mb_group_title, mb_group_address, mb_group_email, mb_group_postcode, mb_group_city, mb_group_logo_path, mb_group_voicetelephone FROM (SELECT fkey_mb_group_id FROM mb_user_mb_group WHERE fkey_mb_user_id = $1 AND mb_user_mb_group_type = 2) AS a LEFT JOIN mb_group ON a.fkey_mb_group_id = mb_group.mb_group_id
SQL;
@@ -193,7 +192,7 @@
$sql = <<<SQL
SELECT fkey_md_topic_category_id
FROM wfs_featuretype_md_topic_category
-WHERE fkey_featuretype_id = $featuretypeId
+WHERE fkey_featuretype_id = $featuretypeId AND fkey_metadata_id ISNULL
SQL;
$res = db_query($sql);
while ($row = db_fetch_assoc($res)) {
@@ -202,7 +201,7 @@
$sql = <<<SQL
SELECT fkey_inspire_category_id
FROM wfs_featuretype_inspire_category
-WHERE fkey_featuretype_id = $featuretypeId
+WHERE fkey_featuretype_id = $featuretypeId AND fkey_metadata_id ISNULL
SQL;
$res = db_query($sql);
while ($row = db_fetch_assoc($res)) {
@@ -211,7 +210,7 @@
$sql = <<<SQL
SELECT fkey_custom_category_id
FROM wfs_featuretype_custom_category
-WHERE fkey_featuretype_id = $featuretypeId
+WHERE fkey_featuretype_id = $featuretypeId AND fkey_metadata_id ISNULL
SQL;
$res = db_query($sql);
while ($row = db_fetch_assoc($res)) {
More information about the Mapbender_commits
mailing list