[Mapbender-commits] r9334 - trunk/mapbender/http/classes
svn_mapbender at osgeo.org
svn_mapbender at osgeo.org
Wed Dec 9 04:02:26 PST 2015
Author: armin11
Date: 2015-12-09 04:02:26 -0800 (Wed, 09 Dec 2015)
New Revision: 9334
Modified:
trunk/mapbender/http/classes/class_iso19139.php
Log:
New possibility to manage licenses at dataset metadata level
Modified: trunk/mapbender/http/classes/class_iso19139.php
===================================================================
--- trunk/mapbender/http/classes/class_iso19139.php 2015-12-09 09:00:15 UTC (rev 9333)
+++ trunk/mapbender/http/classes/class_iso19139.php 2015-12-09 12:02:26 UTC (rev 9334)
@@ -61,6 +61,7 @@
var $inspireCharset;
var $licenseSourceNote;
var $licenseJson;
+ //the following attribute is specific to predefined terms of use as they are managed by the mapbender database - it is the identifier (fkey) of an entry in the termsofuse table
var $termsOfUseRef;
var $accessConstraints;
var $fees;
@@ -416,7 +417,7 @@
//Look for source
$this->licenseSourceNote = $standardizedLicense->quelle;
$this->licenseJson = stripslashes($otherConstraints[1]);
- //search in the second entry for a freetxt object
+ //search in the second entry for a freetext object
if ($otherConstraints[1] != ''){
$this->fees = $otherConstraints[1];
}
@@ -1077,6 +1078,21 @@
$this->keywordsThesaurusName[] = "";
}
}
+ //get predefined license if given in mapbender database
+ $sql = <<<SQL
+SELECT fkey_termsofuse_id FROM md_termsofuse WHERE fkey_metadata_id = $1
+SQL;
+ $v = array($metadataId);
+ $t = array('i');
+ $res = db_prep_query($sql,$v,$t);
+ //pull first entry
+ $row = db_fetch_assoc($res);
+ $this->termsOfUseRef = $row['fkey_termsofuse_id'];
+ if ($this->termsOfUseRef == null) {
+ $e = new mb_exception("no predefined license set");
+ } else {
+ $e = new mb_exception("Predefined license found: ".$this->termsOfUseRef);
+ }
} else {
$e = new mb_exception("Could not get metadata with id ".$metadataId." from DB!");
return false;
@@ -1352,6 +1368,7 @@
public function insertKeywordsAndCategoriesIntoDB($metadataId,$resourceType,$resourceId){
//first delete old classifications - after that create new ones
+ //$e = new mb_exception($metadataId." - ".$resourceType." - ".$resourceId);
$this->deleteKeywordsAndCategoriesFromDB($metadataId,$resourceType,$resourceId);
//insert keywords and categories into tables!
//parse keywords and isoCategories
@@ -1532,14 +1549,69 @@
//delete relations from database
//recreate relation to license
//relation is set via json id
- if ($this->licenseJson != null) {
+ //check for defined license id via editor or s.th. else
+ if ($this->termsOfUseRef == null) {
+ //search for given json lincense
+ if ($this->licenseJson != null) {
+ $licenseName = json_decode($this->licenseJson)->id;
+ if ($licenseName != null) {
+ //search for same license name in database - if not given create it!
+ $sql = <<<SQL
+ SELECT termsofuse_id from termsofuse WHERE name = $1
+SQL;
+ $v = array($licenseName);
+ $t = array('s');
+ $res = db_prep_query($sql,$v,$t);
+ $row = db_fetch_assoc($res);
+ $licenseId = $row['termsofuse_id'];
+ if ($licenseId == null) {
+ //if all relevant information is given in json - create a new entry in termsofuse table (id, name, url
+ $licenseJson = json_decode($this->licenseJson);
+ if ($licenseJson->id != null && $licenseJson->id != "" && $licenseJson->name != null && $licenseJson->name != "" && $licenseJson->url != null && $licenseJson->url != "") {
+ //insert entry into db - license should be open
+ $sql = <<<SQL
+ INSERT INTO termsofuse (name, description, descriptionlink) VALUES ($1, $2, $3);
+SQL;
+ $v = array($licenseJson->id,$licenseJson->name,$licenseJson->url);
+ $t = array('s','s','s');
+ $res = db_prep_query($sql,$v,$t);
+ if (!$res) {
+ $e = new mb_exception("classes/class_iso19139.php: Cannot create termsofuse entry from given json license in metadata!");
+ $licenseId = null;
+ } else {
+ $sql = <<<SQL
+ SELECT termsofuse_id from termsofuse WHERE name = $1
+SQL;
+ $v = array($licenseJson->id);
+ $t = array('s');
+ $res = db_prep_query($sql,$v,$t);
+ $row = db_fetch_assoc($res);
+ $licenseId = $row['termsofuse_id'];
+ }
+ }
+
+ }
+ } else {
+ $licenseId = null;
+ }
+ } else {
+ $licenseId = $this->termsOfUseRef;
+ }
+ //do the sql job
}
-
- if ($this->licenseJson != null) {
-
+ if ($licenseId != null) {
+ $sql = <<<SQL
+ INSERT INTO md_termsofuse (fkey_termsofuse_id, fkey_metadata_id) VALUES ($1, $2);
+SQL;
+ $v = array((integer)$licenseId,(integer)$metadataId);
+ $t = array('i','i');
+ $res = db_prep_query($sql,$v,$t);
+ if (!$res){
+ $e = new mb_exception("classes/class_Iso19139.php: "._mb("Cannot insert termsofuse relation!"));
+ }
}
- //relation is set via metadata editor
+
}
public function deleteCategoriesFromCoupledResource($metadataId,$resourceType,$resourceId) {
@@ -1645,6 +1717,16 @@
} else {
$e = new mb_notice("class_Iso19139: keyword relations deleted from database!");
}
+ //delete license relation from db
+ $sql = "DELETE FROM md_termsofuse where fkey_metadata_id = $1 ";
+ $v = array($metadataId);
+ $t = array('i');
+ $res = db_prep_query($sql,$v,$t);
+ if (!$res) {
+ $e = new mb_exception("class_Iso19139.php:"._mb("Cannot delete termsofuse relation for metadata with id ".$metadataId));
+ } else {
+ $e = new mb_notice("class_Iso19139.php: termsofuse relation deleted from database!");
+ }
$this->deleteCategoriesFromCoupledResource($metadataId,$resourceType,$resourceId);
}
@@ -1918,6 +2000,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
@@ -2001,6 +2084,7 @@
$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]);
+ $this->insertKeywordsAndCategoriesIntoDB($metadataId[0],$resourceType,$resourceId);
} else {
//check if href already exists
$metadataId = $this->isLinkAlreadyInDB();
@@ -2010,6 +2094,7 @@
$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]);
+ $this->insertKeywordsAndCategoriesIntoDB($metadataId[0],$resourceType,$resourceId);
} else {
//insert new record
$e = new mb_notice("class_Iso19139:"."No existing metadata fileIdentifier found in mapbender metadata table. New record will be inserted with uuid: ".$this->fileIdentifier);
More information about the Mapbender_commits
mailing list