Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for collection column in pycsw db #49

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 8 additions & 2 deletions bin/ckan_pycsw.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,15 @@
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')

ckan_columns = [
Column('ckan_id', Text, index=True),
Column('ckan_modified', Text),
Column('ckan_collection', Boolean),
]

pycsw.admin.setup_db(database,
Expand Down Expand Up @@ -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

Expand All @@ -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)
Expand Down Expand Up @@ -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

Expand Down