Пример #1
0
    def _get_view(self,
                  view_name='_design/learningregistry-slice/_view/docs',
                  keys=[],
                  include_docs=False,
                  resumptionToken=None,
                  limit=None):
        db_url = '/'.join(
            [appConfig['couchdb.url'], appConfig['couchdb.db.resourcedata']])

        opts = {"stale": "ok", "reduce": False}

        if include_docs:
            opts["include_docs"] = True

        if self.enable_flow_control and resumptionToken != None:
            if resumptionToken != None:
                opts["skip"] = resumptionToken["offset"]
                opts["keys"] = resumptionToken["keys"]
        else:
            opts["keys"] = keys

        if limit != None:
            opts["limit"] = limit

        if len(opts["keys"]) > 0:
            view = h.getView(database_url=db_url,
                             method="POST",
                             view_name=view_name,
                             **opts)  #,stale='ok'):
        else:
            view = h.getView(database_url=db_url, view_name=view_name,
                             **opts)  #,stale='ok'):
        return view
Пример #2
0
 def _get_view_total(self,view_name = '_design/learningregistry-slice/_view/docs',keys=[], resumptionToken=None):
     
     if resumptionToken and "maxResults" in resumptionToken and resumptionToken["maxResults"] != None :
         return resumptionToken["maxResults"];
         
     
     db_url = '/'.join([appConfig['couchdb.url'],appConfig['couchdb.db.resourcedata']])
     
     opts = {"stale": appConfig['couchdb.stale.flag'], "reduce": True, "group": True }
     
     if self.enable_flow_control and resumptionToken != None:
         opts["keys"] = resumptionToken["keys"]
     else:
         opts["keys"] = keys
         
     if len(opts["keys"]) > 0:
         view = h.getView(database_url=db_url, method="POST", view_name=view_name, **opts)#,stale='ok'):
     else:
         view = h.getView(database_url=db_url,view_name=view_name, **opts)#,stale='ok'):
         
     totalDocs = 0
     for row in view:
         if "value" in row:
             totalDocs += row["value"]
     
     #resumptionToken["maxResults"] = totalDocs;
     return totalDocs
Пример #3
0
 def _get_view_total(self,view_name = '_design/learningregistry-slice/_view/docs',keys=[], resumptionToken=None):
     
     if resumptionToken and "maxResults" in resumptionToken and resumptionToken["maxResults"] != None :
         return resumptionToken["maxResults"];
         
     
     db_url = '/'.join([appConfig['couchdb.url'],appConfig['couchdb.db.resourcedata']])
     
     opts = {"stale": appConfig['couchdb.stale.flag'], "reduce": True, "group": True }
     
     if self.enable_flow_control and resumptionToken != None:
         opts["keys"] = resumptionToken["keys"]
     else:
         opts["keys"] = keys
         
     if len(opts["keys"]) > 0:
         view = h.getView(database_url=db_url, method="POST", view_name=view_name, **opts)#,stale='ok'):
     else:
         view = h.getView(database_url=db_url,view_name=view_name, **opts)#,stale='ok'):
         
     totalDocs = 0
     for row in view:
         if "value" in row:
             totalDocs += row["value"]
     
     #resumptionToken["maxResults"] = totalDocs;
     return totalDocs
Пример #4
0
 def get_view(self,view_name = '_design/learningregistry/_view/resources',keys=[], include_docs = False):                
     db_url = '/'.join([appConfig['couchdb.url'],appConfig['couchdb.db.resourcedata']])
     if len(keys) > 0:
       view = h.getView(database_url=db_url,view_name=view_name,keys=keys,include_docs=include_docs,stale='ok')
     else:
       view = h.getView(database_url=db_url,view_name=view_name,include_docs=include_docs,stale='ok')
     return view
Пример #5
0
 def get_view(self,
              view_name='_design/learningregistry-resources/_view/docs',
              keys=[],
              include_docs=False,
              resumption_token=None):
     db_url = '/'.join(
         [appConfig['couchdb.url'], appConfig['couchdb.db.resourcedata']])
     args = {}
     if len(keys) > 0:
         args['keys'] = keys
     args['stale'] = appConfig['couchdb.stale.flag']
     if self.limit is not None:
         args['limit'] = self.limit
     args['include_docs'] = include_docs
     if resumption_token is not None:
         if 'key' not in args or len(args['keys']) == 0:
             if "key" in resumption_token:
                 args['key'] = resumption_token['key']
             if "keys" in resumption_token:
                 args['keys'] = resumption_token['keys']
         args['startkey'] = resumption_token['startkey']
         args['startkey_docid'] = resumption_token['startkey_docid']
         args['skip'] = 1
     view = h.getView(database_url=db_url,
                      view_name=view_name,
                      method="GET",
                      documentHandler=lambda d: h.document(d),
                      **args)
     return view
Пример #6
0
    def list_identifiers_or_records(self,metadataPrefix,from_date=None, until_date=None, rt=None, fc_limit=None, serviceid=None, include_docs=False):
        '''Returns the list_records as a generator based upon OAI-PMH query'''
        opts = { "stale": appConfig['couchdb.stale.flag'] };
        if include_docs:
            opts["include_docs"] = True

        import logging
        log = logging.getLogger(__name__)

        if rt != None and fc_limit != None:
            opts["startkey"] = rt["startkey"]
            opts["startkey_docid"] = rt["startkey_docid"]
            opts["endkey"] = rt["endkey"]
            opts["limit"] = fc_limit + 1

        else:
            opts.update(self.list_opts(metadataPrefix, from_date, until_date))

        log.info("opts: "+ repr(opts))

        def format_ids(row):
            obj = { "doc_ID": row["id"], "node_timestamp": "%sZ" %(row["key"][1]) }
            log.debug("format: %s\n" %(json.dumps(obj)))
            return obj

        def format_docs(row):
            obj = row["doc"]
            return obj

        if include_docs:
            format = OAIPMHDocumentResolver()
        else:
            format = format_ids

        return h.getView(self.res_data_url, '_design/oai-pmh-list-identifiers/_view/docs', method="GET", documentHandler=format, **opts)
Пример #7
0
    def list_records(self,metadataPrefix,from_date=None, until_date=None):
        '''Returns the list_records as a generator based upon OAI-PMH query'''
        opts = {
                "include_docs": True,
                "stale": "ok"
                };

        if from_date != None:
            from_date = from_date.replace(tzinfo=None)
            opts["startkey"] = [metadataPrefix, from_date.isoformat()]
        else:
            # empty string should sort before anything else.
            opts["startkey"] = [metadataPrefix, None]
        
        if until_date != None:
            until_date = until_date.replace(tzinfo=None)
            opts["endkey"] = [metadataPrefix, until_date.isoformat()]
        else:
            # somewhat of an hack... since I don't know the timestamp, and couch stores things
            # in alphabetical order, a string sequence with all capital Z's should always sort last.
            opts["endkey"] = [metadataPrefix, {}];
        
        def format(row):
            obj = row["doc"]
            return obj
        
        return h.getView(self.res_data_url, '_design/oai-pmh/_view/list-identifiers', method="GET", documentHandler=format, **opts)
Пример #8
0
    def list_identifiers(self,metadataPrefix,from_date=None, until_date=None ):
        '''Returns the list_records as a generator based upon OAI-PMH query'''
        opts = { "stale": "ok" };
        import logging
        log = logging.getLogger(__name__)

        if from_date != None:
            opts["startkey"] = [metadataPrefix, from_date.isoformat()]
        else:
            # empty string should sort before anything else.
            opts["startkey"] = [metadataPrefix, None]
        
        if until_date != None:
            opts["endkey"] = [metadataPrefix, until_date.isoformat()]
        else:
            # somewhat of an hack... since I don't know the timestamp, and couch stores things
            # in alphabetical order, a string sequence with all capital Z's should always sort last.
            opts["endkey"] = [metadataPrefix, {}];
        
        log.info("opts: "+ repr(opts))
        
        def format(row):
            obj = { "doc_ID": row["id"], "node_timestamp": "%sZ" %(row["key"][1]) }
            log.debug("format: %s\n" %(json.dumps(obj)))
            return obj
        
        return h.getView(self.res_data_url, '_design/oai-pmh/_view/list-identifiers', method="GET", documentHandler=format, **opts)
Пример #9
0
 def list_identifiers_or_records(self,metadataPrefix,from_date=None, until_date=None, rt=None, fc_limit=None, serviceid=None, include_docs=False):
     '''Returns the list_records as a generator based upon OAI-PMH query'''
     opts = { "stale": appConfig['couchdb.stale.flag'] };
     if include_docs:
         opts["include_docs"] = True
     
     import logging
     log = logging.getLogger(__name__)
     
     if rt != None and fc_limit != None:
         opts["startkey"] = rt["startkey"]
         opts["startkey_docid"] = rt["startkey_docid"]
         opts["endkey"] = rt["endkey"]
         opts["limit"] = fc_limit + 1
         
     else:
         opts.update(self.list_opts(metadataPrefix, from_date, until_date))
     
     log.info("opts: "+ repr(opts))
     
     def format_ids(row):
         obj = { "doc_ID": row["id"], "node_timestamp": "%sZ" %(row["key"][1]) }
         log.debug("format: %s\n" %(json.dumps(obj)))
         return obj
     
     def format_docs(row):
         obj = row["doc"]
         return obj
     
     if include_docs:
         format = OAIPMHDocumentResolver()
     else:
         format = format_ids
     
     return h.getView(self.res_data_url, '_design/oai-pmh-list-identifiers/_view/docs', method="GET", documentHandler=format, **opts)
Пример #10
0
 def get_records_by_resource(self, resource_locator):
     view_data = h.getView(
         database_url=self.db_url,
         view_name='_design/learningregistry-resource-location/_view/docs',
         method="POST",
         documentHandler=OAIPMHDocumentResolver(),
         include_docs=True,
         keys=[resource_locator],
         stale=appConfig['couchdb.stale.flag'])
     for doc in view_data:
         yield doc
Пример #11
0
 def get_records_by_resource(self, resource_locator):
     view_data = h.getView(
         database_url=self.db_url,
         view_name="_design/learningregistry-resource-location/_view/docs",
         method="POST",
         documentHandler=OAIPMHDocumentResolver(),
         include_docs=True,
         keys=[resource_locator],
         stale=appConfig["couchdb.stale.flag"],
     )
     for doc in view_data:
         yield doc
Пример #12
0
    def _get_view(self,view_name = '_design/learningregistry-slice/_view/docs',keys=[], include_docs = False, resumptionToken=None, limit=None):
        db_url = '/'.join([appConfig['couchdb.url'],appConfig['couchdb.db.resourcedata']])
        
        opts = {"stale": "ok", "reduce": False }
        
        if include_docs:
            opts["include_docs"] = True
        
        if self.enable_flow_control and resumptionToken != None:
            if resumptionToken != None:
                opts["skip"] = resumptionToken["offset"]
                opts["keys"] = resumptionToken["keys"]
        else:
            opts["keys"] = keys

        if limit != None:
                    opts["limit"] = limit
        
        if len(opts["keys"]) > 0:
            view = h.getView(database_url=db_url, method="POST", view_name=view_name, **opts)#,stale='ok'):
        else:
            view = h.getView(database_url=db_url,view_name=view_name, **opts)#,stale='ok'):
        return view
Пример #13
0
 def _get_view_total(self, view_name, params, resumptionToken=None):
     if resumptionToken and "maxResults" in resumptionToken and resumptionToken["maxResults"] != None:
         return resumptionToken["maxResults"]
     db_url = '/'.join([appConfig['couchdb.url'], appConfig['couchdb.db.resourcedata']])
     opts = {"stale": appConfig['couchdb.stale.flag'], "group": True}
     if "startkey" in params and "endkey" in params:
         opts['startkey'] = params['startkey']
         opts['endkey'] = params['endkey']
     totalDocs = 0
     view = h.getView(database_url=db_url, method="POST", view_name=view_name, **opts)
     for row in view:
         if "value" in row:
             totalDocs += row["value"]
     return totalDocs
Пример #14
0
 def get_view(self,view_name = '_design/learningregistry-resources/_view/docs',keys=[], include_docs = False,resumption_token=None):                
     db_url = '/'.join([appConfig['couchdb.url'],appConfig['couchdb.db.resourcedata']])
     args = {}
     if len(keys) > 0:
         args['keys'] = keys
     args['stale'] = 'ok'
     if self.limit is not None:
         args['limit'] = self.limit
     args['include_docs'] = include_docs
     if resumption_token is not None:
         args['startkey'] = resumption_token['startkey']
         args['startkey_docid'] = resumption_token['startkey_docid']
         args['skip'] = 1
     view = h.getView(database_url=db_url,view_name=view_name,documentHandler=lambda d: h.document(d),**args)
     return view
Пример #15
0
    def _get_view(self, view_name, params, include_docs=False, resumptionToken=None, limit=None):
        db_url = '/'.join([appConfig['couchdb.url'], appConfig['couchdb.db.resourcedata']])
        opts = {"stale": appConfig['couchdb.stale.flag'], "reduce": False}
        if include_docs:
            opts["include_docs"] = True
        if self.enable_flow_control and resumptionToken is not None:
            if "startkey_docid" in params:
                opts['startkey_docid'] = params['startkey_docid']
            opts["skip"] = 1
        opts['startkey'] = params['startkey']
        opts['endkey'] = params['endkey']
        if limit is not None:
            opts["limit"] = limit

        return h.getView(database_url=db_url, method="POST", view_name=view_name, **opts)
Пример #16
0
 def _get_view_total(self, view_name, params, resumptionToken=None):
     if resumptionToken and "maxResults" in resumptionToken and resumptionToken[
             "maxResults"] != None:
         return resumptionToken["maxResults"]
     db_url = '/'.join(
         [appConfig['couchdb.url'], appConfig['couchdb.db.resourcedata']])
     opts = {"stale": appConfig['couchdb.stale.flag'], "group": True}
     if "startkey" in params and "endkey" in params:
         opts['startkey'] = params['startkey']
         opts['endkey'] = params['endkey']
     totalDocs = 0
     view = h.getView(database_url=db_url,
                      method="POST",
                      view_name=view_name,
                      **opts)
     for row in view:
         if "value" in row:
             totalDocs += row["value"]
     return totalDocs
Пример #17
0
    def _get_view(self,
                  view_name,
                  params,
                  include_docs=False,
                  resumptionToken=None,
                  limit=None):
        db_url = '/'.join(
            [appConfig['couchdb.url'], appConfig['couchdb.db.resourcedata']])
        opts = {"stale": appConfig['couchdb.stale.flag'], "reduce": False}
        if include_docs:
            opts["include_docs"] = True
        if self.enable_flow_control and resumptionToken is not None:
            if "startkey_docid" in params:
                opts['startkey_docid'] = params['startkey_docid']
            opts["skip"] = 1
        opts['startkey'] = params['startkey']
        opts['endkey'] = params['endkey']
        if limit is not None:
            opts["limit"] = limit

        return h.getView(database_url=db_url,
                         method="POST",
                         view_name=view_name,
                         **opts)