[Mapbender-commits] r9761 - trunk/mapbender/http/classes

svn_mapbender at osgeo.org svn_mapbender at osgeo.org
Fri Aug 18 03:56:29 PDT 2017


Author: armin11
Date: 2017-08-18 03:56:28 -0700 (Fri, 18 Aug 2017)
New Revision: 9761

Modified:
   trunk/mapbender/http/classes/class_syncCkan.php
Log:
Fix for ckan exporthandler - map dcat-ap categories

Modified: trunk/mapbender/http/classes/class_syncCkan.php
===================================================================
--- trunk/mapbender/http/classes/class_syncCkan.php	2017-08-17 14:57:19 UTC (rev 9760)
+++ trunk/mapbender/http/classes/class_syncCkan.php	2017-08-18 10:56:28 UTC (rev 9761)
@@ -36,6 +36,7 @@
     var $syncOrgaId;
     var $mapbenderUserId;
     var $topicCkanCategoryMap;
+    var $topicDataThemeCategoryMap;
     var $compareTimestamps;
 
     public function __construct() {
@@ -58,7 +59,29 @@
 	$this->syncOrgaId = 0;
 	$this->topicCkanCategoryMap = $topicCkanCategoryMap; //from ckan.conf
 	//Mapping of DCAT-AP categories to iso topic categories
-	$this->topicDataThemeCategoryMap = $topicDataThemeCategoryMap; //from ckan.conf
+	//$this->topicDataThemeCategoryMap = $topicDataThemeCategoryMap; //from ckan.conf
+$this->topicDataThemeCategoryMap = array(
+	"1" => "AGRI,ENVI,HEAL",//"1" => "farming",
+	"2" => "AGRI,ENVI,HEAL",//"2" => "biota",
+	"3" => "GOVE,JUST,SOCI",//"3" => "boundaries",
+	"4" => "AGRI,ENVI,HEAL,TECH",//"4" => "climatologyMeteorologyAtmosphere",
+	"5" => "ECON,ENER,INTR",//"5" => "economy",
+	"6" => "ENVI,TRAN,REGI",//"6" => "elevation",
+	"7" => "ENVI",//"7" => "environment",
+	"8" => "AGRI,ENVI,ENER,REGI,TECH,TRAN",//"8" => "geoscientificInformation",
+	"9" => "HEAL",//"9" => "health",
+	"10" => "AGRI,ENVI,TRAN",//"10" => "imageryBaseMapsEarthCover",
+	"11" => "AGRI,ECON,GOVE,TRAN",//"11" => "intelligenceMilitary",
+	"12" => "ENVI,REGI,AGRI",//"12" => "inlandWaters",
+	"13" => "REGI",//"13" => "location",
+	"14" => "ENVI",//"14" => "oceans",
+	"15" => "TRAN,ENVI,ECON,AGRI,GOVE,SOCI,JUST",//"15" => "planningCadastre",
+	"16" => "SOCI,EDUC,JUST",//"16" => "society",
+	"17" => "AGRI,REGI,ENER,HEAL,GOVE",//"17" => "structure",
+	"18" => "TRAN",//"18" => "transportation",
+	"19" => "ECON,EDUC,ENER,TECH"//"19" => "utilitiesCommunication"
+);
+
 	$this->compareTimestamps = false; //default to update each dataset, because the ckan index for metadata_modified may not be up to date !!!
     }
 
@@ -712,7 +735,7 @@
                         $result = $ckan->action_package_show(json_encode($resourceJson));
                         if ($result->success == true) {
                             //update existing package
-                            $resultCkanRepresentation = $this->getCkanRepresentation($datasetMetadata->id, $layerArrayMetadata, $featuretypeArrayMetadata, $syncList->ckan_orga_ident, $syncList->title, $syncList->email, $this->topicCkanCategoryMap);
+                            $resultCkanRepresentation = $this->getCkanRepresentation($datasetMetadata->id, $layerArrayMetadata, $featuretypeArrayMetadata, $syncList->ckan_orga_ident, $syncList->title, $syncList->email, $this->topicDataThemeCategoryMap);
                             if ($resultCkanRepresentation != false) {
                                 $result = $ckan->action_package_update($resultCkanRepresentation['json']);
                                 if ($result->success == true) {
@@ -730,7 +753,7 @@
                         } else {
                             //create new package
                             //echo "Package ".$datasetMetadata['uuid']." does not exist and has to be created!"."<br>";
-                            $resultCkanRepresentation = $this->getCkanRepresentation($datasetMetadata->id, $layerArrayMetadata, $featuretypeArrayMetadata, $syncList->ckan_orga_ident, $syncList->title, $syncList->email, $this->topicCkanCategoryMap);
+                            $resultCkanRepresentation = $this->getCkanRepresentation($datasetMetadata->id, $layerArrayMetadata, $featuretypeArrayMetadata, $syncList->ckan_orga_ident, $syncList->title, $syncList->email, $this->topicDataThemeCategoryMap);
                             if ($resultCkanRepresentation != false) {
                                 $result = $ckan->action_package_create($resultCkanRepresentation['json']);
                                 if ($result->success == true) {
@@ -866,7 +889,8 @@
 	}
 	//all or only those which have standardized licenses?
 	//$sql = "SELECT *, f_get_coupled_resources(metadata_id) from mb_metadata LEFT JOIN md_termsofuse ON mb_metadata.metadata_id = md_termsofuse.fkey_metadata_id WHERE mb_metadata.uuid = $1";
-	$sql = "SELECT * , st_asgeojson(the_geom) as geojson from mb_metadata JOIN md_termsofuse ON mb_metadata.metadata_id = md_termsofuse.fkey_metadata_id JOIN termsofuse ON md_termsofuse.fkey_termsofuse_id = termsofuse.termsofuse_id WHERE mb_metadata.uuid = $1 AND export2csw IS true";
+	//$sql = "SELECT * , st_asgeojson(the_geom) as geojson from mb_metadata JOIN md_termsofuse ON mb_metadata.metadata_id = md_termsofuse.fkey_metadata_id JOIN termsofuse ON md_termsofuse.fkey_termsofuse_id = termsofuse.termsofuse_id WHERE mb_metadata.uuid = $1 AND export2csw IS true";
+	$sql = "SELECT * , st_asgeojson(the_geom) as geojson from mb_metadata LEFT OUTER JOIN md_termsofuse ON mb_metadata.metadata_id = md_termsofuse.fkey_metadata_id LEFT OUTER JOIN termsofuse ON md_termsofuse.fkey_termsofuse_id = termsofuse.termsofuse_id WHERE mb_metadata.uuid = $1 AND export2csw IS true";
 	$v = array($uuid);
 	$t = array('s');
 	$res = db_prep_query($sql, $v, $t);
@@ -899,10 +923,15 @@
 	$ckanPackage->author = $orgaTitle;
 	$ckanPackage->author_email = $orgaEmail;
 	$ckanPackage->state = "active";
-	$ckanPackage->license_id = $row['name'];
-	//$ckanPackage->license_id = "odc_odbl";
-	$ckanPackage->license_title = $row['description'];
-	$ckanPackage->license_url = $row['descriptionlink'];
+	if (isset($row['name']) && $row['name'] !== '') {
+		$ckanPackage->license_id = $row['name'];
+		//$ckanPackage->license_id = "odc_odbl";
+		$ckanPackage->license_title = $row['description'];
+		$ckanPackage->license_url = $row['descriptionlink'];
+	} else {
+		$ckanPackage->license_id = 'notspecified';
+		$ckanPackage->license_title = "Keine definierte Lizenz";
+	}
 	$ckanPackage->spatial = $row['geojson'];
         //$ckanPackage->url = "";
 	//special categories
@@ -915,6 +944,8 @@
 	$viewArray = array();
 	$indexResourceArray = 0;
 	$indexViewArray = 0;
+	//add html preview for metadata
+	
 	if (count($layerArray) > 0) {
 	    //select relevant layer information
 	    $sql = "SELECT layer_id, layer_title, uuid from layer WHERE layer_id IN (".implode(",", $layerArray).")";
@@ -1051,6 +1082,7 @@
         //arrays
         //$ckanPackage->tags = [];
         $ckanPackage->govdata_categories[] = "geo";
+	$ckanPackage->dcat_ap_eu_data_theme[] = "GOVE";
         //and further categories and keywords
         $keywordIdArray = array();
         $topicIdArray = array();
@@ -1060,27 +1092,28 @@
         if (count($layerArray) > 0) {
             $sql = "SELECT fkey_md_topic_category_id FROM layer_md_topic_category WHERE (fkey_metadata_id = ".$metadataId." OR fkey_layer_id IN (".implode(",", $layerArray).") ) UNION SELECT fkey_md_topic_category_id FROM mb_metadata_md_topic_category WHERE fkey_metadata_id = ".$metadataId;
         } else {
-            $sql = "SELECT fkey_md_topic_category_id FROM layer_md_topic_category WHERE (fkey_metadata_id = ".$metadataId.") UNION SELECT fkey_md_topic_category_id FROM mb_metadata_md_topic_category WHERE fkey_metadata_id = ".$metadataId;
+            $sql = "SELECT fkey_md_topic_category_id FROM mb_metadata_md_topic_category WHERE fkey_metadata_id = ".$metadataId;
         }
         $res = db_query($sql);
         while($row = db_fetch_array($res)){
             $topicIdArray[] = $row['fkey_md_topic_category_id'];
         }
-        //push govdata categories into ckan package
+
+        //push categories into ckan package
         $numberOfCategories = 0;
         for ($i=0; $i < count($topicIdArray); $i++){
-            if (array_key_exists((string)$topicIdArray[$i],$topicCkanCategoryMap)) {
+            if (array_key_exists((string)$topicIdArray[$i],$this->topicDataThemeCategoryMap)) {
             //check if categories should be exploded
             //check if one comma is in string
-                if (strpos($topicCkanCategoryMap[$topicIdArray[$i]], ",") !== false) {
-                    $newCategories = explode(",",$topicCkanCategoryMap[$topicIdArray[$i]]);
+                if (strpos($this->topicDataThemeCategoryMap[$topicIdArray[$i]], ",") !== false) {
+                    $newCategories = explode(",",$this->topicDataThemeCategoryMap[$topicIdArray[$i]]);
                 } else {
                     //single category
-                    $newCategories[0] = $topicCkanCategoryMap[$topicIdArray[$i]];
+                    $newCategories[0] = $this->topicDataThemeCategoryMap[$topicIdArray[$i]];
                 }
                 foreach ($newCategories as $cat) {
                     //explode categories if 
-                    $categories[$numberOfCategories] = $cat;
+                    $categories[$numberOfCategories] = $cat;    
                     $numberOfCategories++;
                 }
             } else {
@@ -1090,8 +1123,9 @@
         if (count($categories) > 0) {
             $categories = array_unique($categories);
             for ($i=0; $i < count($categories); $i++){
-                if ($categories[$i] !== "geo" && $categories[$i] !== null) {
-                    $ckanPackage->govdata_categories[] = $categories[$i];
+                if ($categories[$i] !== "GOVE" && $categories[$i] !== null) {
+                    //$ckanPackage->govdata_categories[] = $categories[$i];
+		    $ckanPackage->dcat_ap_eu_data_theme[] = $categories[$i];
                 }
             }
         }



More information about the Mapbender_commits mailing list