Last active
February 8, 2017 21:45
-
-
Save tomkralidis/53dfd592e4ed99a3358407304acc1000 to your computer and use it in GitHub Desktop.
pycsw bare repository plugin
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#-*- coding: utf-8 -*- | |
# set pycsw configuration like: | |
# [repository] | |
# source=ogr_repository.OGRRepository | |
from pycsw.core.repository import Repository | |
class OGRRepository(Repository): | |
''' Class to interact with underlying repository ''' | |
def __init__(self, context, repo_filter=None): | |
''' Initialize repository ''' | |
self.context = context | |
self.filter = repo_filter | |
self.fts = False | |
self.dbtype = 'elasticsearch' | |
# generate core queryables db and obj bindings | |
self.queryables = {} | |
for tname in self.context.model['typenames']: | |
for qname in self.context.model['typenames'][tname]['queryables']: | |
self.queryables[qname] = {} | |
for qkey, qvalue in \ | |
self.context.model['typenames'][tname]['queryables'][qname].items(): | |
self.queryables[qname][qkey] = qvalue | |
# flatten all queryables | |
# TODO smarter way of doing this | |
self.queryables['_all'] = {} | |
for qbl in self.queryables: | |
self.queryables['_all'].update(self.queryables[qbl]) | |
self.queryables['_all'].update(self.context.md_core_model['mappings']) | |
def query_ids(self, ids): | |
''' Return a list of dataset objects from a list of identifiers ''' | |
# return [list_of_dataset_objects] | |
return [] | |
def query_domain(self, domain, typenames, domainquerytype='list', | |
count=False): | |
''' return a list of tuples (value, count) of domain values ''' | |
if domainquerytype == 'range': | |
# return list like [(minvalue, maxvalue)] | |
return [('value1', 3), ('value2', 2)] | |
else: | |
if count: | |
# return list of tuples like [(val1, count), (val2, count)] | |
return [('value1', 3), ('value2', 2), ('value3', 9)] | |
else: | |
# return list of values like [val1, val2, val3] | |
return [('value1',), ('value2',), ('value3',)] | |
def query_insert(self, direction='max'): | |
''' return an ISO 8601 string ('%Y-%m-%dT%H:%M:%SZ') of the earliest or latest insert ''' | |
if direction == 'min': | |
# return first insert | |
return '2017-01-01T11:11:11Z' | |
else: | |
# return last insert | |
return '2017-02-01T11:11:11Z' | |
def query_source(self, source): | |
''' Query by source ''' | |
# not required for CSW basic (non CSW-T) / readonly workflows | |
return NotImplementedError | |
def query(self, constraint, sortby=None, typenames=None, maxrecords=10, startposition=0): | |
''' Query records from underlying repository | |
constraint: dict of: | |
where: SQL where clause (set with bind variables) | |
values: values as passed in by upstream query (OGC FES XML) which match up with bind variables defined in the where key | |
sortby: property (column) to sort resultset on | |
maxrecords: limit to be applied for paging | |
startposition: offset to be applied for paging | |
returns a list of [total, list_of_dataset_objects] | |
''' | |
return ['0', []] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment