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

svn_mapbender at osgeo.org svn_mapbender at osgeo.org
Sun Feb 24 11:11:39 PST 2013


Author: armin11
Date: 2013-02-24 11:11:38 -0800 (Sun, 24 Feb 2013)
New Revision: 8572

Modified:
   trunk/mapbender/conf/ckan.conf-dist
   trunk/mapbender/http/classes/class_ckanApi.php
   trunk/mapbender/http/php/mod_exportMapbenderLayer2CkanObjects.php
   trunk/mapbender/http/php/mod_syncCkan.php
Log:
Some further enhancements

Modified: trunk/mapbender/conf/ckan.conf-dist
===================================================================
--- trunk/mapbender/conf/ckan.conf-dist	2013-02-24 11:57:48 UTC (rev 8571)
+++ trunk/mapbender/conf/ckan.conf-dist	2013-02-24 19:11:38 UTC (rev 8572)
@@ -7,6 +7,8 @@
 DEFINE('CKAN_API_UPDATE',1);
 DEFINE('CKAN_API_CREATE',3);
 DEFINE('OPEN_LICENCES','2,3,4,5');
+DEFINE('CKAN_EXPORT_URL','http://www.geoportal.rlp.de/mapbender/php/mod_exportMapbenderLayer2CkanObjects.php');
+
 $topicCkanCategoryMap = array(
 	"1" => "farming",
 	"2" => "biota",

Modified: trunk/mapbender/http/classes/class_ckanApi.php
===================================================================
--- trunk/mapbender/http/classes/class_ckanApi.php	2013-02-24 11:57:48 UTC (rev 8571)
+++ trunk/mapbender/http/classes/class_ckanApi.php	2013-02-24 19:11:38 UTC (rev 8572)
@@ -858,7 +858,7 @@
 			{
 				// Add Authorization: header.
 				$this->ch_headers[] = 'Authorization: ' . $this->api_key;
-				$e = new mb_exception("added following to headers: ".'Authorization: ' . $this->api_key);
+				$e = new mb_notice("added following to headers: ".'Authorization: ' . $this->api_key);
 				// Add data to request body.
 				curl_setopt($this->ch, CURLOPT_POSTFIELDS, $data);
 			}

Modified: trunk/mapbender/http/php/mod_exportMapbenderLayer2CkanObjects.php
===================================================================
--- trunk/mapbender/http/php/mod_exportMapbenderLayer2CkanObjects.php	2013-02-24 11:57:48 UTC (rev 8571)
+++ trunk/mapbender/http/php/mod_exportMapbenderLayer2CkanObjects.php	2013-02-24 19:11:38 UTC (rev 8572)
@@ -2,20 +2,11 @@
 //mod_exportMapbenderLayer2CkanObjects.php
 require_once(dirname(__FILE__)."/../../core/globalSettings.php");
 require_once(dirname(__FILE__).'/../../conf/ckan.conf');
-
-//metadata columns of wms table
-/*contactorganization
-contactperson
-address
-city
-postcode
-contactvoicetelephone
-contactelectronicmailaddress*/
 $openLicences = OPEN_LICENCES;
 //select open data information from mapbenders database
 $sql = <<<SQL
 
-select wms_id, layer_id, f_collect_topic_cat_layer(layer_id) as category, layer.uuid as uuid, wms_title || ':' || layer_title as title, wms_abstract || ':' || layer_abstract as notes, tou_licence_title, tou_licence_url, tou_licence_id, isopen, to_timestamp(wms_timestamp) as wms_timestamp, to_timestamp(wms_timestamp_create) as wms_timestamp_create, wms_owner as service_owner,fees,accessconstraints, fkey_mb_group_id as service_group, contactperson, address, city, postcode, contactvoicetelephone, contactelectronicmailaddress from (select termsofuse_id, description as tou_licence_title, descriptionlink as tou_licence_url, wms_tou.name as tou_licence_id, wms_tou.isopen as isopen, wms_id, wms_title, wms_timestamp, wms_timestamp_create, wms.wms_abstract, wms.wms_owner,fees,accessconstraints,wms.fkey_mb_group_id, contactperson, address, city, postcode, contactvoicetelephone, contactelectronicmailaddress from (select * from termsofuse inner join wms_termsofuse on termsofuse.termsofus
 e_id = wms_termsofuse.fkey_termsofuse_id and termsofuse.termsofuse_id in ($openLicences)) as wms_tou inner join wms on wms_tou.fkey_wms_id = wms.wms_id) as wms_tou2 inner join layer on wms_tou2.wms_id = layer.fkey_wms_id and layer_searchable=1; 
+select wms_id, layer_id, f_collect_topic_cat_layer(layer_id) as category, layer.uuid as uuid, wms_title || ':' || layer_title as title, wms_abstract || '\r\n' || layer_abstract as notes, tou_licence_title, tou_licence_url, tou_licence_id, isopen, to_timestamp(wms_timestamp) as wms_timestamp, to_timestamp(wms_timestamp_create) as wms_timestamp_create, wms_owner as service_owner,fees,accessconstraints, fkey_mb_group_id as service_group, contactperson, address, city, postcode, contactvoicetelephone, contactelectronicmailaddress from (select termsofuse_id, description as tou_licence_title, descriptionlink as tou_licence_url, wms_tou.name as tou_licence_id, wms_tou.isopen as isopen, wms_id, wms_title, wms_timestamp, wms_timestamp_create, wms.wms_abstract, wms.wms_owner,fees,accessconstraints,wms.fkey_mb_group_id, contactperson, address, city, postcode, contactvoicetelephone, contactelectronicmailaddress from (select * from termsofuse inner join wms_termsofuse on termsofuse.termso
 fuse_id = wms_termsofuse.fkey_termsofuse_id and termsofuse.termsofuse_id in ($openLicences)) as wms_tou inner join wms on wms_tou.fkey_wms_id = wms.wms_id) as wms_tou2 inner join layer on wms_tou2.wms_id = layer.fkey_wms_id and layer_searchable=1; 
 
 SQL;
 $result = db_query($sql);
@@ -54,12 +45,13 @@
 				$categories[$i] = $topicCkanCategoryMap[$categories[$i]];
 			}
 		}
-		$e = new mb_exception('mod_exportMapbenderLayer2CkanObjects.php: categories from db: '.$categories[1]);
+		$e = new mb_notice('mod_exportMapbenderLayer2CkanObjects.php: categories from db: '.$categories[1]);
 		$sqlTable['categories'][] = $categories;
 	} else {
 		$sqlTable['categories'][] = false;
 	}
 }
+
 $groupOwnerArray = array();
 $groupOwnerArray[0] = $sqlTable['service_group'];
 $groupOwnerArray[1] = $sqlTable['service_owner'];
@@ -79,26 +71,22 @@
 $sqlTable['group_city'] = $groupOwnerArray[9];
 $sqlTable['group_logo'] = $groupOwnerArray[10];
 $sqlTable['group_homepage'] = $groupOwnerArray[12];
-//echo "test";
 //test output
 /*for ($i=0; $i < count($sqlTable['name']); $i++){
 		echo $sqlTable['name'][$i]." - ".$sqlTable['title'][$i]." - ".$sqlTable['service_id'][$i]." - ".$sqlTable['resource_id'][$i]." - ".$sqlTable['organization'][$i]." - ".$sqlTable['orgaId'][$i]."<br>";
 	}*/
 $transpSqlTable = array_transpose($sqlTable);
-/*echo "<br>".$test[0]['name']."<br>";
-$test2 = $test[0];
-echo "<br>".$test2['name']." - ".$test2['title']."<br>";
-echo "<br>".$sqlTable['name'][0]."<br>";*/
-
 $ckanPackages = new stdClass();
 $ckanPackages->result = array();
+//invoke creation of ckan package objects
 for ($i=0; $i < count($sqlTable['name']); $i++){
 	$ckanPackages->result[] = buildCkanPackage($transpSqlTable[$i]);
 }
 header('Content-Type: application/json; charset='.CHARSET);
+//give out result object in json format
 echo json_encode($ckanPackages);
+//functions *******************************************************************************************************************************
 //build json objects!
-
 function buildCkanPackage ($mbArray) {
 	//use urls from mapbender.conf if available!
 	if (defined("MAPBENDER_PATH") && MAPBENDER_PATH != '') {
@@ -138,13 +126,19 @@
 	$package->other_terms_of_use = "other terms of use";//$mbArray['mb_user_id'];// "test tou"; //null or ""
 	//TODO: problem date format
 	$package->temporal_coverage_to = substr($mbArray['temporal_coverage_to'],0,10);// "2012-01-01"; // last update ? wms.wms_timestamp - OK
-	$package->temporal_coverage_from = substr($mbArray['temporal_coverage_from'],0,10);// "2011-01-01"; // last update ? wms.wms_timestamp_create - OK
+
+	if ($mbArray['temporal_coverage_from']) {
+		$package->temporal_coverage_from = substr($mbArray['temporal_coverage_from'],0,10);// "2011-01-01"; // last update ? wms.wms_timestamp_create - OK
+	} else {
+		$package->temporal_coverage_from = "2000-01-01";
+	}	
 	//$package->temporal_coverage_to = "2012-01-01"; // last update ? wms.wms_timestamp - OK
 	//$package->temporal_coverage_from = "2011-01-01"; // last update ? wms.wms_timestamp_create - OK
 
 	$package->content_type = $mbArray['resource_type'];// "testcontenttype"; //constant: Service
 	if ($mbArray['isopen'] == 1) {
 		$package->isopen = true;//true; //termsofuse.isopen - OK
+		$package->is_free_of_charge = true;
 	} else {
 		$package->isopen = false;
 	}

Modified: trunk/mapbender/http/php/mod_syncCkan.php
===================================================================
--- trunk/mapbender/http/php/mod_syncCkan.php	2013-02-24 11:57:48 UTC (rev 8571)
+++ trunk/mapbender/http/php/mod_syncCkan.php	2013-02-24 19:11:38 UTC (rev 8572)
@@ -7,7 +7,6 @@
 require_once(dirname(__FILE__).'/../classes/class_ckan.php');
 require_once(dirname(__FILE__).'/../classes/class_connector.php');
 require_once(dirname(__FILE__).'/../../conf/ckan.conf');
-
 // Create CKAN object
 // Takes optional API key parameter. Required for POST and PUT methods.
 $apiKey = API_KEY;
@@ -15,22 +14,8 @@
 //initial instantiation of api class
 $ckan = new ckanApi($apiKey, $serverIp);
 $ckan->base_url='http://'.$serverIp.':5000/api/';
-
 //echo "API-key: ".$ckan->api_key."<br>";
 //echo "API-baseUrl: ".$ckan->base_url;
-
-//parse request parameters
-if (isset($_REQUEST["action"]) & $_REQUEST["action"] != "") {
-	$testMatch = $_REQUEST["action"];	
- 	if (!($testMatch == 'package_delete' or $testMatch == 'package_create' or $testMatch == 'package_show' or $testMatch == 'group_create' or $testMatch == 'group_delete' or $testMatch == 'group_package_show' or $testMatch == 'delete_all_packages_by_group' or $testMatch == 'group_show')){ 
-		echo 'action: <b>'.$testMatch.'</b> is not valid.<br/>'; 
-		die(); 		
- 	}
-	$action = $testMatch;
-	$testMatch = NULL;
-}
-
-
 //get json objects from mapbender json interface
 /*$mapbenderCkanUrl = "http://localhost/mapbender_trunk/php/mod_exportMapbenderLayer2CkanObjects.php";
 $ckanObjectConnector = new connector($mapbenderCkanUrl);
@@ -38,12 +23,40 @@
 header('Content-Type: application/json; charset='.CHARSET);
 echo json_encode($ckanObjects);
 */
+//first check if group with given name exists - if not create it in the ckan instance via action api, if it exists - update title and link to logo
 
-//get current dataset names from mapbenders ckan object interface
-$mapbenderCkanUrl = "http://localhost/mapbender_trunk/php/mod_exportMapbenderLayer2CkanObjects.php";
+$group = group_get(CKAN_GROUP_NAME);
+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/';
+	//create new one
+	$newGroup->name = CKAN_GROUP_NAME;
+	$newGroup->title = CKAN_GROUP_TITLE;
+	$newGroup->image_url = CKAN_GROUP_SYMBOL;
+	try {
+		$result = $ckan->action_group_create(json_encode($newGroup));
+	}
+	catch (Exception $e) {
+		print '<p><strong>Caught exception: ' . $e->getMessage() . '</strong></p><br>';
+	}
+	if ($result->success) {
+		print '<p>Group created successfully!</p><br>';
+	}
+	unset($ckan);
+} else {
+	print "Group <b>".$group->name."</b> found. Datasets will be pushed into this group.";
+}
+
+if (defined("CKAN_EXPORT_URL") && CKAN_EXPORT_URL != "") {
+	$mapbenderCkanUrl = CKAN_EXPORT_URL;
+} else {
+	$mapbenderCkanUrl = "http://localhost/mapbender_trunk/php/mod_exportMapbenderLayer2CkanObjects.php";
+}
+//read ckan objects from source into variable
 $ckanObjectConnector = new connector($mapbenderCkanUrl);
 $ckanObjects = json_decode($ckanObjectConnector->file);
-
+//build dataset array for source datasets
 foreach ($ckanObjects->result as $dataset) {
 	$mbDatasetArray[] =  $dataset->name;
 }
@@ -51,7 +64,6 @@
 if (count($mbDatasetArray) == 0) {
 	$mbDatasetArray = false;
 }
-
 if ($mbDatasetArray) {
 	foreach ($mbDatasetArray as $dataset) {
 		print $dataset."<br>";
@@ -67,7 +79,6 @@
 		print $dataset."<br>";
 	}
 }
-
 //compare the arrays
 //first those which can be deleted
 if ($ckanDatasetArray && $mbDatasetArray) {
@@ -184,31 +195,8 @@
 	} 
 }
 
-$datasetName = $_REQUEST["name"];
-
 print time()."<br>";
 
-die();
-
-switch ($action) {
-	case 'package_show': 
-		$result = package_get ($_REQUEST["name"]);
-		if ($result) {
-			print json_encode($result);
-		} else {
-			print "Dataset with name ".$_REQUEST["name"]." not found!";
-		}
-	break;
-	case 'package_create': 
-		$result = package_create ($newDataset,3);
-		if ($result) {
-			print json_encode($result);
-		} else {
-			print "Dataset could not be created!";
-		}
-	break;
-}
-
 //functions for interacting with ckan apis
 function package_get ($packageName) {
 	try {
@@ -229,6 +217,20 @@
 	}
 }
 
+function group_get ($groupName) {
+	try {
+		$ckan = new ckanApi(API_KEY,CKAN_SERVER_IP);
+		$ckan->base_url='http://'.CKAN_SERVER_IP.':5000/api/1/';
+		$resultDataset = $ckan->get_group_entity($groupName);
+		return $resultDataset;
+	}
+	catch (Exception $e)
+	{
+		$error = new mb_exception('mod_syncCkan.php: Caught exception: '.$e->getMessage());
+		return false;
+	}
+}
+
 function package_update ($package, $apiVersion) {
 	//check if package already exists
 	$existingPackage = package_get ($package->name);
@@ -476,8 +478,8 @@
 		return true;
 	}
 }
+
 function create_dummy_object() {
-
 	return $dummyObject;
 }
 ?>



More information about the Mapbender_commits mailing list