diff --git a/bin/ckan_pycsw.py b/bin/ckan_pycsw.py index 471c71c6..49f63c33 100644 --- a/bin/ckan_pycsw.py +++ b/bin/ckan_pycsw.py @@ -17,7 +17,7 @@ def setup_db(pycsw_config): """Setup database tables and indexes""" - from sqlalchemy import Column, Text + from sqlalchemy import Boolean, Column, Text database = pycsw_config.get('repository', 'database') table_name = pycsw_config.get('repository', 'table', 'records') @@ -25,6 +25,7 @@ def setup_db(pycsw_config): ckan_columns = [ Column('ckan_id', Text, index=True), Column('ckan_modified', Text), + Column('ckan_collection', Boolean), ] pycsw.admin.setup_db(database, @@ -63,7 +64,7 @@ def load(pycsw_config, ckan_url): log.info('Started gathering CKAN datasets identifiers: {0}'.format(str(datetime.datetime.now()))) - query = 'api/search/dataset?qjson={"fl":"id,metadata_modified,extras_harvest_object_id,extras_metadata_source", "q":"harvest_object_id:[\\"\\" TO *]", "limit":1000, "start":%s}' + query = 'api/search/dataset?qjson={"fl":"id,metadata_modified,extras_harvest_object_id,extras_metadata_source,extras_collection_package_id", "q":"harvest_object_id:[\\"\\" TO *]", "limit":1000, "start":%s}' start = 0 @@ -85,6 +86,10 @@ def load(pycsw_config, ckan_url): 'harvest_object_id': result['extras']['harvest_object_id'], 'source': result['extras'].get('metadata_source') } + is_collection = True + if 'collection_package_id' in result['extras']: + is_collection = False + gathered_records[result['id']]['ckan_collection'] = is_collection start = start + 1000 log.debug('Gathered %s' % start) @@ -188,6 +193,7 @@ def get_record(context, repo, ckan_url, ckan_id, ckan_info): record.identifier = ckan_id record.ckan_id = ckan_id record.ckan_modified = ckan_info['metadata_modified'] + record.ckan_collection = ckan_info['ckan_collection'] return record