From f2145778721c0c502cc742293fdfaced3e94c51b Mon Sep 17 00:00:00 2001 From: Stefan Oderbolz Date: Tue, 13 Jan 2015 14:46:14 +0100 Subject: [PATCH] Fetch remote organization via action api Organizations used to be returned by /api/2/rest/group, this is what the old implementation used to fetch the information to create the remote organization on the local instance of CKAN. With this commit the Action API is used to fetch the same information. --- ckanext/harvest/harvesters/ckanharvester.py | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/ckanext/harvest/harvesters/ckanharvester.py b/ckanext/harvest/harvesters/ckanharvester.py index 835e27c..2c5c4d9 100644 --- a/ckanext/harvest/harvesters/ckanharvester.py +++ b/ckanext/harvest/harvesters/ckanharvester.py @@ -21,10 +21,14 @@ class CKANHarvester(HarvesterBase): config = None api_version = 2 + action_api_version = 3 def _get_rest_api_offset(self): return '/api/%d/rest' % self.api_version + def _get_action_api_offset(self): + return '/api/%d/action' % self.action_api_version + def _get_search_api_offset(self): return '/api/%d/search' % self.api_version @@ -48,6 +52,15 @@ class CKANHarvester(HarvesterBase): except Exception, e: raise e + def _get_organization(self, base_url, org_name): + url = base_url + self._get_action_api_offset() + '/organization_show?id=' + org_name + try: + content = self._get_content(url) + content_dict = json.loads(content) + return content_dict['result'] + except Exception, e: + raise e + def _set_config(self,config_str): if config_str: self.config = json.loads(config_str) @@ -324,7 +337,7 @@ class CKANHarvester(HarvesterBase): log.info('Organization %s is not available' % remote_org) if remote_orgs == 'create': try: - org = self._get_group(harvest_object.source.url, remote_org) + org = self._get_organization(harvest_object.source.url, remote_org) for key in ['packages', 'created', 'users', 'groups', 'tags', 'extras', 'display_name', 'type']: org.pop(key, None) get_action('organization_create')(context, org)