[Mapbender-commits] r8575 - in trunk/mapbender: conf http/classes http/php

svn_mapbender at osgeo.org svn_mapbender at osgeo.org
Tue Feb 26 08:19:17 PST 2013


Author: armin11
Date: 2013-02-26 08:19:16 -0800 (Tue, 26 Feb 2013)
New Revision: 8575

Modified:
   trunk/mapbender/conf/ckan.conf-dist
   trunk/mapbender/http/classes/class_ckanApi.php
   trunk/mapbender/http/php/mod_syncCkan.php
Log:
Some bugfixes for ckan API

Modified: trunk/mapbender/conf/ckan.conf-dist
===================================================================
--- trunk/mapbender/conf/ckan.conf-dist	2013-02-26 13:44:00 UTC (rev 8574)
+++ trunk/mapbender/conf/ckan.conf-dist	2013-02-26 16:19:16 UTC (rev 8575)
@@ -1,7 +1,13 @@
 <?php
-DEFINE('API_KEY','2d0a9ff9-9538-4b9a-8ceb-c975208986cf');
-DEFINE('CKAN_SERVER_IP','127.0.0.1');
-DEFINE('CKAN_GROUP_NAME','gdi-rp-neu');
+//DEFINE('API_KEY','2d0a9ff9-9538-4b9a-8ceb-c975208986cf');
+//DEFINE('CKAN_SERVER_IP','127.0.0.1');
+//DEFINE('CKAN_SERVER_PORT','5000');
+DEFINE('API_KEY','XXX');
+//DEFINE('API_KEY','XXX');
+DEFINE('CKAN_SERVER_IP','83.243.48.195');
+DEFINE('CKAN_SERVER_PORT','');
+DEFINE('CKAN_GROUP_NAME','gdi-rp');
+//DEFINE('CKAN_GROUP_NAME','gdi-rp-neu');
 DEFINE('CKAN_GROUP_SYMBOL','http://www.geoportal.rlp.de/portal/fileadmin/design/logo_gdi-rp.png');
 DEFINE('CKAN_GROUP_TITLE','GDI-RP');
 DEFINE('CKAN_API_UPDATE',1);
@@ -30,7 +36,25 @@
 	"18" => "transportation",
 	"19" => "utilitiesCommunication"
 );
-//testrp
-//'1083d169-73d7-4472-831a-edd901a550b1';
-//'83.243.48.195';
+$topicCkanCategoryMap = array(
+	"1" => "umwelt_klima,geo,bevoelkerung,wirtschaft_arbeit",//"1" => "farming",
+	"2" => "geo,infrastruktur_bauen_wohnen,umwelt_klima,verwaltung",//"2" => "biota",
+	"3" => "geo,gesetze_justiz,politik_wahlen,verwaltung,umwelt_klima",//"3" => "boundaries",
+	"4" => "geo,umwelt_klima",//"4" => "climatologyMeteorologyAtmosphere",
+	"5" => "wirtschaft_arbeit",//"5" => "economy",
+	"6" => "geo,infrastruktur_bauen_wohnen",//"6" => "elevation",
+	"7" => "umwelt_klima",//"7" => "environment",
+	"8" => "geo,bildung_wissenschaft",//"8" => "geoscientificInformation",
+	"9" => "gesundheit",//"9" => "health",
+	"10" => "geo",//"10" => "imageryBaseMapsEarthCover",
+	"11" => "wirtschaft_arbeit,gesetze_justiz",//"11" => "intelligenceMilitary",
+	"12" => "geo,infrastruktur_bauen_wohnen,transport_verkehr",//"12" => "inlandWaters",
+	"13" => "geo,verwaltung",//"13" => "location",
+	"14" => "umwelt_klima",//"14" => "oceans",
+	"15" => "geo,infrastruktur_bauen_wohnen,transport_verkehr,gesetze_justiz",//"15" => "planningCadastre",
+	"16" => "soziales,verbraucher,bildung_wissenschaft",//"16" => "society",
+	"17" => "geo,infrastruktur_bauen_wohnen",//"17" => "structure",
+	"18" => "transport_verkehr",//"18" => "transportation",
+	"19" => "infrastruktur_bauen_wohnen"//"19" => "utilitiesCommunication"
+);
 ?>

Modified: trunk/mapbender/http/classes/class_ckanApi.php
===================================================================
--- trunk/mapbender/http/classes/class_ckanApi.php	2013-02-26 13:44:00 UTC (rev 8574)
+++ trunk/mapbender/http/classes/class_ckanApi.php	2013-02-26 16:19:16 UTC (rev 8575)
@@ -519,7 +519,7 @@
 	 */
 	public function put_package_entity($packageName, $data)
 	{
-		return $this->make_request('PUT', 
+		return $this->make_request('POST', 
 			$this->resources['package_entity'] . '/' . urlencode($packageName), 
 			$data);
 	}
@@ -857,8 +857,8 @@
 			else
 			{
 				// Add Authorization: header.
-				$this->ch_headers[] = 'Authorization: ' . $this->api_key;
-				$e = new mb_notice("added following to headers: ".'Authorization: ' . $this->api_key);
+				$this->ch_headers[] = 'X-CKAN-API-Key: ' . $this->api_key;
+				$e = new mb_notice("added following to headers: ".'X-CKAN-API-Key: ' . $this->api_key);
 				// Add data to request body.
 				curl_setopt($this->ch, CURLOPT_POSTFIELDS, $data);
 			}

Modified: trunk/mapbender/http/php/mod_syncCkan.php
===================================================================
--- trunk/mapbender/http/php/mod_syncCkan.php	2013-02-26 13:44:00 UTC (rev 8574)
+++ trunk/mapbender/http/php/mod_syncCkan.php	2013-02-26 16:19:16 UTC (rev 8575)
@@ -9,11 +9,17 @@
 require_once(dirname(__FILE__).'/../../conf/ckan.conf');
 // Create CKAN object
 // Takes optional API key parameter. Required for POST and PUT methods.
-$apiKey = API_KEY;
-$serverIp = CKAN_SERVER_IP;
 //initial instantiation of api class
-$ckan = new ckanApi($apiKey, $serverIp);
-$ckan->base_url='http://'.$serverIp.':5000/api/';
+if (defined("CKAN_SERVER_PORT") && CKAN_SERVER_PORT != '') {
+	$serverUrl = CKAN_SERVER_IP.":".CKAN_SERVER_PORT;
+} else {
+	$serverUrl = CKAN_SERVER_IP;
+}
+DEFINE('SERVER_URL',$serverUrl);
+$ckan = new ckanApi(API_KEY, CKAN_SERVER_IP);
+
+$ckan->base_url='http://'.SERVER_URL.'/api/';
+
 //echo "API-key: ".$ckan->api_key."<br>";
 //echo "API-baseUrl: ".$ckan->base_url;
 //get json objects from mapbender json interface
@@ -28,12 +34,13 @@
 if (!$group) {
 	print "No group found, create it via action api!";
 	$ckan = new ckanApi(API_KEY,CKAN_SERVER_IP);
-	$ckan->base_url='http://'.CKAN_SERVER_IP.':5000/api/';
+	$ckan->base_url='http://'.SERVER_URL.'/api/';
+	
 	//create new one
 	$newGroup->name = CKAN_GROUP_NAME;
 	$newGroup->title = CKAN_GROUP_TITLE;
 	$newGroup->image_url = CKAN_GROUP_SYMBOL;
-	$newGroup->description = CKAN_GROUP_DESCRIPTION;
+	//$newGroup->description = CKAN_GROUP_DESCRIPTION;
 	try {
 		$result = $ckan->action_group_create(json_encode($newGroup));
 	}
@@ -195,7 +202,7 @@
 function package_get ($packageName) {
 	try {
 		$ckan = new ckanApi(API_KEY,CKAN_SERVER_IP);
-		$ckan->base_url='http://'.CKAN_SERVER_IP.':5000/api/';
+		$ckan->base_url='http://'.SERVER_URL.'/api/';
 		$idArray = array ('id'=>$packageName);
 		$resultDataset = $ckan->action_package_show(json_encode($idArray));
 		if ($resultDataset->success) {
@@ -214,7 +221,7 @@
 function group_get ($groupName) {
 	try {
 		$ckan = new ckanApi(API_KEY,CKAN_SERVER_IP);
-		$ckan->base_url='http://'.CKAN_SERVER_IP.':5000/api/1/';
+		$ckan->base_url='http://'.SERVER_URL.'/api/1/';
 		$resultDataset = $ckan->get_group_entity($groupName);
 		return $resultDataset;
 	}
@@ -233,7 +240,7 @@
 			case 3:
 				//update it ;-)
 				$ckan = new ckanApi(API_KEY,CKAN_SERVER_IP);
-				$ckan->base_url='http://'.CKAN_SERVER_IP.':5000/api/';
+				$ckan->base_url='http://'.SERVER_URL.'/api/';
 				try {
 					$result = $ckan->action_package_update(json_encode($package));
 				}
@@ -251,7 +258,7 @@
 			case 1:	
 				//update it with api v1 ;-)
 				$ckan = new ckanApi(API_KEY,CKAN_SERVER_IP);
-				$ckan->base_url='http://'.CKAN_SERVER_IP.':5000/api/1/';
+				$ckan->base_url='http://'.SERVER_URL.'/api/1/';
 				try {
 					$result = $ckan->put_package_entity($package->name,json_encode($package));
 				}
@@ -264,7 +271,7 @@
 			case 2:	
 				//update it with api v2 ;-)
 				$ckan = new ckanApi(API_KEY,CKAN_SERVER_IP);
-				$ckan->base_url='http://'.CKAN_SERVER_IP.':5000/api/2/';
+				$ckan->base_url='http://'.SERVER_URL.'/api/2/';
 				$error = new mb_exception('mod_syncCkan.php: '.$package->groups[0]);
 				try {
 					$result = $ckan->post_package_register($existingPackage->id,json_encode($package));
@@ -299,7 +306,7 @@
 		$ckan = new ckanApi(API_KEY,CKAN_SERVER_IP);
 		switch ($apiVersion) {
 			case 1:
-				$ckan->base_url='http://'.CKAN_SERVER_IP.':5000/api/1/';
+				$ckan->base_url='http://'.SERVER_URL.'/api/1/';
 				try {
 					$resultDataset = $ckan->post_package_register(json_encode($package));
 					if ($resultDataset->success) {
@@ -315,7 +322,7 @@
 				}
 			break;
 			case 3:
-				$ckan->base_url='http://'.CKAN_SERVER_IP.':5000/api/';
+				$ckan->base_url='http://'.SERVER_URL.'/api/';
 				try {
 					$resultDataset = $ckan->action_package_create(json_encode($package));
 					if ($resultDataset->success) {
@@ -340,8 +347,9 @@
 }
 
 function get_packages_by_group($groupname) {
+	//by action api
 	$ckan = new ckanApi(API_KEY,CKAN_SERVER_IP);
-	$ckan->base_url='http://'.CKAN_SERVER_IP.':5000/api/';
+	$ckan->base_url='http://'.SERVER_URL.'/api/';
 	$datasetNames = array();
 	try {
 		$groupArray = array ('id'=>$groupname);
@@ -388,7 +396,7 @@
 					//$existingPackage->point_of_contact_url = "http://www.geoportal.rlp.de";
 					try {
 						$ckan = new ckanApi(API_KEY,CKAN_SERVER_IP);
-						$ckan->base_url='http://'.CKAN_SERVER_IP.':5000/api/';
+						$ckan->base_url='http://'.SERVER_URL.'/api/';
 						$result = $ckan->action_package_update(json_encode($existingPackage));
 					}
 					catch (Exception $e) {
@@ -424,7 +432,7 @@
 					$package->name = $existingPackage->name."_".time();
 					//update it with api v2 ;-)
 					$ckan = new ckanApi(API_KEY,CKAN_SERVER_IP);
-					$ckan->base_url='http://'.CKAN_SERVER_IP.':5000/api/2/';
+					$ckan->base_url='http://'.SERVER_URL.'/api/2/';
 					try {
 						$result = $ckan->post_package_register($existingPackage->id,json_encode($package));
 					}
@@ -458,7 +466,7 @@
 					$package->state = "deleted";
 					$package->name = $existingPackage->name."_".time();
 					$ckan = new ckanApi(API_KEY,CKAN_SERVER_IP);
-					$ckan->base_url='http://'.CKAN_SERVER_IP.':5000/api/1/';
+					$ckan->base_url='http://'.SERVER_URL.'/api/1/';
 					try {
 						$result = $ckan->put_package_entity($packageName,json_encode($package));
 					}



More information about the Mapbender_commits mailing list