[Mapbender-commits] r9866 - trunk/mapbender/http/classes
svn_mapbender at osgeo.org
svn_mapbender at osgeo.org
Fri Feb 16 01:56:21 PST 2018
Author: armin11
Date: 2018-02-16 01:56:20 -0800 (Fri, 16 Feb 2018)
New Revision: 9866
Modified:
trunk/mapbender/http/classes/class_ckanApi.php
trunk/mapbender/http/classes/class_syncCkan.php
Log:
Some enhancements for ckan sync interface
Modified: trunk/mapbender/http/classes/class_ckanApi.php
===================================================================
--- trunk/mapbender/http/classes/class_ckanApi.php 2018-02-14 12:16:39 UTC (rev 9865)
+++ trunk/mapbender/http/classes/class_ckanApi.php 2018-02-16 09:56:20 UTC (rev 9866)
@@ -498,11 +498,11 @@
* @return the organizations of the user to show as dictionary
* @link http://docs.ckan.org/en/latest/api/index.html
*/
- public function action_organization_list_for_user($id)
+ public function action_organization_list_for_user($data)
{
return $this->make_request('POST',
$this->actionList['organization_list_for_user'],
- $id);
+ $data);
}
// organization delete
@@ -1028,7 +1028,7 @@
if ($method === 'POST' || $method === 'PUT') {
// We needs a key and some data, yo!
//don't need post data for organization_list_for_user, api_key may be enough
- if (strpos($url,"organization_list_for_user") !== false) {
+ /*if (strpos($url,"organization_list_for_user") !== false) {
if ( !($this->api_key)) {
// throw exception
$e = new mb_exception("Missing an API key.");
@@ -1038,7 +1038,7 @@
// Add data to request body.
curl_setopt($this->ch, CURLOPT_POSTFIELDS, $data);
}
- } else {
+ } else {*/
if ( !($this->api_key) && !($data)) {
// throw exception
$e = new mb_exception("Missing either an API key or POST data or both.");
@@ -1048,7 +1048,7 @@
// Add data to request body.
curl_setopt($this->ch, CURLOPT_POSTFIELDS, $data);
}
- }
+ //}
//other method than post or put
} else {
// Since we can't use HTTPS,
@@ -1080,9 +1080,11 @@
} else {
$e = new mb_notice("CKAN API request returned 200 - OK");
}
- //$e = new mb_exception("response: ".$response);
- //$e = new mb_exception("content_type: ".$info['content_type']);
- //$e = new mb_exception("send data: ".$data);
+ /*$e = new mb_exception("url: ".$curlUrl);
+ $e = new mb_exception("send data: ".$data);
+ $e = new mb_exception("response: ".$response);
+ $e = new mb_exception("content_type: ".$info['content_type']);*/
+
// Determine how to parse
if (isset($info['content_type']) && $info['content_type']) {
$content_type = str_replace('application/', '',
Modified: trunk/mapbender/http/classes/class_syncCkan.php
===================================================================
--- trunk/mapbender/http/classes/class_syncCkan.php 2018-02-14 12:16:39 UTC (rev 9865)
+++ trunk/mapbender/http/classes/class_syncCkan.php 2018-02-16 09:56:20 UTC (rev 9866)
@@ -37,6 +37,7 @@
var $mapbenderUserId;
var $topicCkanCategoryMap;
var $topicDataThemeCategoryMap;
+ var $frequencyMap;
var $compareTimestamps;
public function __construct() {
@@ -82,6 +83,20 @@
"19" => "ECON,EDUC,ENER,TECH"//"19" => "utilitiesCommunication"
);
+$this->frequencyMap = array(
+ "continual" => "CONT",
+ "daily" => "DAILY",
+ "weekly" => "WEEKLY",
+ "fortnightly" => "WEEKLY_2",
+ "monthly" => "MONTHLY",
+ "quarterly" => "QUARTERLY",
+ "biannually" => "BIENNIAL",
+ "annually" => "ANNUAL",
+ "asNeeded" => "OTHER",
+ "irregular" => "IRREG",
+ "notPlanned" => "NEVER",
+ "unknown" => "UNKNOWN"
+);
$this->compareTimestamps = false; //default to update each dataset, because the ckan index for metadata_modified may not be up to date !!!
}
@@ -371,15 +386,20 @@
$ckan->base_url = $this->ckanApiProtocol.'://'.$this->ckanApiUrl.'/api/3/';
$ckan->api_version = $this->ckanApiVersion;
- $result = $ckan->action_organization_list_for_user();
+ //$result = $ckan->action_organization_list_for_user();
+ //new for ckan 2.7.X
+ //$orgaQuery->id = $organization["ckan_api_key"];
+ $orgaQuery->permission = "create_dataset";
+ $orgaQuery->include_dataset_count = true;
+ $result = $ckan->action_organization_list_for_user(json_encode($orgaQuery));
foreach($result->result as $orga) {
if ($orga->id == $organization["ckan_uuid"]) {
//foreach catalogue entry to sync
$syncListResultRemoteCkan->external_ckan[$numberOfCatalogue]->ckan_orga_ident = $organization["ckan_uuid"];
//echo "Corresponding ckan organization ".$orga->display_name." found for geoportal group ".$organization["name"]." with id ".$organization["id"]."!<br>";
//get list of ids for existing spatial datasets - category spatial should be defined!!!!!!
- //http://localhost:5000/api/3/action/package_search?fq=transparency_category_de_rp:spatial_data
- //with org: http://localhost:5000/api/3/action/package_search?fq=transparency_category_de_rp:spatial_data%20AND%20owner_org:81476cf5-6c52-4e99-8b9f-6150d63fcb32
+ //http://localhost:5000/api/3/action/package_search?fq=extras_transparency_category_de_rp:spatial_data
+ //with org: http://localhost:5000/api/3/action/package_search?fq=extras_transparency_category_de_rp:spatial_data%20AND%20owner_org:81476cf5-6c52-4e99-8b9f-6150d63fcb32
//TODO: define standard category filter in ckan.conf!
//$queryObject->fq = STANDARD_CKAN_FILTER." AND owner_org:".$organization["ckan_uuid"];
@@ -528,7 +548,13 @@
$ckan->base_url = $this->ckanApiProtocol.'://'.$this->ckanApiUrl.'/api/3/';
$ckan->api_version = $this->ckanApiVersion;
- $result = $ckan->action_organization_list_for_user();
+ //new for ckan 2.7.X
+ //$orgaQuery->id = $organization["ckan_api_key"];
+ $orgaQuery->permission = "create_dataset";
+ $orgaQuery->include_dataset_count = true;
+ $result = $ckan->action_organization_list_for_user(json_encode($orgaQuery));
+ //$e = new mb_exception("orga list: ". json_encode($result));
+ //$result = $ckan->action_organization_list_for_user();
foreach($result->result as $orga) {
if ($orga->id == $organization["ckan_uuid"]) {
//foreach catalogue entry to sync
@@ -676,7 +702,13 @@
$ckan = new ckanApi($organization["ckan_api_key"], CKAN_SERVER_IP);
$ckan->base_url = $this->ckanApiProtocol.'://'.$this->ckanApiUrl.'/api/3/';
$ckan->api_version = $this->ckanApiVersion;
- $result = $ckan->action_organization_list_for_user();
+ //new for ckan 2.7.X
+ //$orgaQuery->id = $organization["ckan_api_key"];
+ $orgaQuery->permission = "create_dataset";
+ $orgaQuery->include_dataset_count = true;
+ $result = $ckan->action_organization_list_for_user(json_encode($orgaQuery));
+ //$e = new mb_exception("orga list: ". json_encode($result));
+ // $result = $ckan->action_organization_list_for_user();
foreach($result->result as $orga) {
if ($orga->id == $organization["ckan_uuid"]) {
$syncListResult->geoportal_organization[$numberGeoportalOrga]->ckan_orga_ident = $organization["ckan_uuid"];
@@ -1035,7 +1067,7 @@
$ckanPackage->state = "active";
$ckanPackage->private = false;
//TODO - define one central category from dcat-ap for environmental data
- $ckanPackage->dcat_ap_eu_data_theme = "ENVI";
+ $ckanPackage->dcat_ap_eu_data_category = "ENVI";
//convert bbox - if available to geojson
//TODO - use key of ckan category from conf!
$ckanCategoryFilter = explode(":",$ckanCategoryFilter);
@@ -1113,6 +1145,7 @@
//$e = new mb_exception(json_encode($ckanPackage, true));
}
+ //function to get ckan representation from mapbender metadata
private function getCkanRepresentation($uuid, $layerArray, $featuretypeArray, $orgaId, $orgaTitle, $orgaEmail, $topicCkanCategoryMap) {
if (defined("MAPBENDER_PATH") && MAPBENDER_PATH != '') {
$mapbenderUrl = MAPBENDER_PATH;
@@ -1124,7 +1157,7 @@
//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 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";#7aeacc93-6b0d-da7f-1f86-80eea9e188b2
+ $sql = "SELECT * , st_asgeojson(the_geom) as geojson, f_get_responsible_organization_for_ressource(metadata_id, 'metadata') as resp_party_id 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";#7aeacc93-6b0d-da7f-1f86-80eea9e188b2
$v = array($uuid);
$t = array('s');
$res = db_prep_query($sql, $v, $t);
@@ -1134,6 +1167,26 @@
$e = new mb_exception("classes/class_syncCkan.php: No metadata found for uuid: ".$uuid);
return false;
}
+ //get responsible organisation information
+ if ((!isset($row['responsible_party_name']) || $row['responsible_party_name'] == '') || (!isset($row['responsible_party_email']) || $row['responsible_party_email'] == '')) {
+ //get info from mb_group_table
+ $sql = "SELECT mb_group_name, mb_group_email FROM mb_group WHERE mb_group_id = $1";
+ $groupId = $row['resp_party_id'];
+ $v = array($groupId);
+ $t = array('i');
+ $res = db_prep_query($sql, $v, $t);
+ if ($res) {
+ $row = db_fetch_assoc($res);
+ } else {
+ $e = new mb_exception("classes/class_syncCkan.php: No group found for id: ".$groupId);
+ return false;
+ }
+ $respPartyName = $row['mb_group_name'];
+ $respPartyEmail = $row['mb_group_email'];
+ } else {
+ $respPartyName = $row['responsible_party_name'];
+ $respPartyEmail = $row['responsible_party_email'];
+ }
//title
$metadataId = $row['metadata_id'];
$metadataUuid = $row['uuid'];
@@ -1150,8 +1203,9 @@
}
$ckanPackage->name = $row['uuid'];
$ckanPackage->owner_org = $orgaId;
- //$ckanPackage->maintainer = "";
- //$ckanPackage->maintainer_email = "";
+ $ckanPackage->maintainer = $respPartyName;
+ $ckanPackage->dataresponsibleauthorities = $respPartyName;
+ $ckanPackage->maintainer_email = $respPartyEmail;
$ckanPackage->private = false;
//$ckanPackage->id = $row['uuid'];
$ckanPackage->author = $orgaTitle;
@@ -1171,7 +1225,14 @@
//special categories
//$ckanPackage->govdata_categories = [];
$ckanPackage->transparency_category_de_rp = "spatial_data";
- $ckanPackage->type = "dataset";
+$ckanPackage->registerobject_type = "Par_7_1_9";
+
+//$e = new mb_exception("update_frequency from db: ".$row['update_frequency']." - frequency for dcat: ".$this->frequencyMap[$row['update_frequency']]);
+
+if (array_key_exists($row['update_frequency'],$this->frequencyMap)) {
+ $ckanPackage->frequency = $this->frequencyMap[$row['update_frequency']];
+}
+ $ckanPackage->type = "geodata";
//build resources:
$resourcesArray = array();
//initialize views - things for which a preview should be available
@@ -1330,8 +1391,8 @@
$ckanPackage->resources = $resourcesArray;
//arrays
//$ckanPackage->tags = [];
- $ckanPackage->govdata_categories[] = "geo";
- $ckanPackage->dcat_ap_eu_data_theme[] = "GOVE";
+ //$ckanPackage->govdata_categories[] = "geo";
+ $ckanPackage->dcat_ap_eu_data_category[] = "GOVE";
//and further categories and keywords
$keywordIdArray = array();
$topicIdArray = array();
@@ -1374,7 +1435,7 @@
for ($i=0; $i < count($categories); $i++){
if ($categories[$i] !== "GOVE" && $categories[$i] !== null) {
//$ckanPackage->govdata_categories[] = $categories[$i];
- $ckanPackage->dcat_ap_eu_data_theme[] = $categories[$i];
+ $ckanPackage->dcat_ap_eu_data_category[] = $categories[$i];
}
}
}
More information about the Mapbender_commits
mailing list