Esempio n. 1
0
    def compareDistributedResources(self,
                                    destination,
                                    filter_description=None):
        """This method considered this node as source node.
        It compares its resource_data document with the destionation node to
        verify that data was distributed.  This comparison assumes that distribute/
        replication is done and that there is no other additions or deletions the
        nodes that are being compared"""

        sourceResults = self.getResourceDataDocs(filter_description)
        destinationResults = destination.getResourceDataDocs()

        #check the number of source document is the same at destination.
        #otherwise the nodes resource distribution failed somehow.
        if len(destinationResults) != len(sourceResults):
            return False

        #Sort the documents by doc id for easy comparison
        sourceDocs = sorted(sourceResults, key=lambda doc: doc["id"])
        destinationDocs = sorted(destinationResults, key=lambda doc: doc["id"])

        # compare documents by documents and check that the destionation time is
        # greater than the source node time.
        for i in range(len(sourceDocs)):
            sourceDoc = {}
            sourceDoc.update(sourceDocs[i]["doc"])
            destDoc = {}
            destDoc.update(destinationDocs[i]["doc"])
            if (h.convertToISO8601UTC(destDoc["node_timestamp"]) <=
                    h.convertToISO8601UTC(sourceDoc["node_timestamp"])):
                log.debug("{0} and {1} error".format(sourceDoc['doc_ID'],
                                                     destDoc['doc_ID']))
                return False
            #remove the node_timestamp and _rev then compare  the docs
            del sourceDoc["node_timestamp"]
            del destDoc["node_timestamp"]
            del destDoc["_rev"]
            del sourceDoc["_rev"]
            if sourceDoc != destDoc:
                log.debug("{0} and {1} error".format(sourceDoc['doc_ID'],
                                                     destDoc['doc_ID']))
                return False
        return True
Esempio n. 2
0
    def compareDistributedResources(self, destination, filter_description=None):
        """This method considers this node as source node.
        It compares its resource_data document with the destionation node to
        verify that data was distributed.  This comparison assumes that distribute/
        replication is done and that there is no other additions or deletions the
        nodes that are being compared"""

        sourceResults = self.getResourceDataDocs(filter_description)
        destinationResults = destination.getResourceDataDocs() 
        
        #check the number of source document is the same at destination.
        #otherwise the nodes resource distribution failed somehow.
        if len(destinationResults) != len(sourceResults):
            return False
                
        #Sort the documents by doc id for easy comparison
        sourceDocs = sorted(sourceResults, key= lambda doc: doc["id"])
        destinationDocs = sorted(destinationResults, key= lambda doc: doc["id"])
        
        # compare documents by documents and check that the destionation time is
        # greater than the source node time.
        for i  in range(len(sourceDocs)):
            sourceDoc = {}
            sourceDoc.update(sourceDocs[i]["doc"])
            destDoc ={}
            destDoc.update(destinationDocs[i]["doc"])
            if (h.convertToISO8601UTC(destDoc["node_timestamp"]) <= h.convertToISO8601UTC(sourceDoc["node_timestamp"])):
                log.debug("{0} and {1} error".format(sourceDoc['doc_ID'], destDoc['doc_ID']))
                return False
            #remove the node_timestamp and _rev then compare  the docs
            del sourceDoc["node_timestamp"]
            del destDoc["node_timestamp"]
            del destDoc["_rev"]
            del sourceDoc["_rev"]
            if sourceDoc != destDoc:
                 log.debug("{0} and {1} error".format(sourceDoc['doc_ID'], destDoc['doc_ID']))
                 return False
        return True
Esempio n. 3
0
 def __parse_date(self,date):
     last_update = helpers.convertToISO8601UTC(date)    
     last_update_date = iso8601.parse_date(date)
     return helpers.harvestTimeFormat(last_update)
Esempio n. 4
0
    def _parseParams(self, flow_control=False, serviceid=None):
        params = {}
        req_params = self._getParams()
        if (req_params.has_key('verb') == False):
            raise BadVerbError()

        verb = params["verb"] = req_params['verb']

        if verb not in [
                "GetRecord", "ListRecords", "ListIdentifiers", "Identify",
                "ListMetadataFormats", "ListSets"
        ]:
            raise BadVerbError()

        if verb == 'GetRecord' or verb == 'ListRecords' or verb == 'ListIdentifiers':
            if req_params.has_key('metadataPrefix') == False:
                raise BadArgumentError(
                    'metadataPrefix is a required parameter.', verb)
            params["metadataPrefix"] = metadataPrefix = req_params[
                'metadataPrefix']

            if metadataPrefix != o_mod.getMetadataPrefix(metadataPrefix):
                raise CannotDisseminateFormatError(verb)

        if verb == 'GetRecord' or verb == 'ListMetadataFormats':
            if req_params.has_key('by_doc_ID') and req_params.has_key(
                    'by_resource_ID'):
                if self._isTrue(req_params['by_doc_ID']) == self._isTrue(
                        req_params['by_resource_ID']):
                    raise BadArgumentError(
                        'by_doc_ID and by_resource_ID have conflicting values.',
                        verb)

            if req_params.has_key('by_doc_ID'):
                params['by_doc_ID'] = self._isTrue(req_params['by_doc_ID'])
                params['by_resource_ID'] = not params['by_doc_ID']
            else:
                params['by_doc_ID'] = False
                params['by_resource_ID'] = not params['by_doc_ID']

            if req_params.has_key('by_resource_ID'):
                params['by_resource_ID'] = self._isTrue(
                    req_params['by_resource_ID'])
                params['by_doc_ID'] = not params['by_resource_ID']

        if verb == 'ListRecords' or verb == 'ListIdentifiers':
            if flow_control and req_params.has_key('resumptionToken'):
                from lr.lib import resumption_token
                token = req_params['resumptionToken']
                log.debug("resumptionToken: %s" % token)
                try:
                    parsed = resumption_token.parse_token(serviceid, token)
                    if 'error' in parsed:
                        raise BadResumptionTokenError(
                            verb, msg=params['resumptionToken']['error'])
                    params['resumptionToken'] = parsed

                    if "from_date" in parsed:
                        req_params["from"] = parsed["from_date"]
                    if "until_date" in parsed:
                        req_params["until"] = parsed["until_date"]
                except Exception as e:
                    raise BadResumptionTokenError(verb, msg=e.message)

            from_date_gran = None
            until_date_gran = None
            if req_params.has_key('from'):
                try:
                    log.error("From 0: {0}".format(req_params['from']))
                    from_date = iso8601.parse_date(req_params['from'])
                    log.error("From 1: {0}".format(from_date))
                    params['from'] = h.convertToISO8601UTC(from_date)
                    log.error("From 2: {0}".format(params['from']))
                    from_date_gran = h.getISO8601Granularity(
                        req_params['from'])
                except:
                    log.error("from: uhh ohh!")
                    raise BadArgumentError('from does not parse to ISO 8601.',
                                           verb)
            else:
                params['from'] = None

            if req_params.has_key('until'):
                try:
                    log.error("Until 0: {0}".format(req_params['until']))
                    until_date = iso8601.parse_date(req_params['until'])
                    log.error("Until 1: {0}".format(until_date))
                    params['until'] = h.convertToISO8601UTC(until_date)
                    log.error("Until 2: {0}".format(params['until']))
                    until_date_gran = h.getISO8601Granularity(
                        req_params['until'])
                except:
                    raise BadArgumentError('until does not parse to ISO 8601.',
                                           verb)
            else:
                params['until'] = None

            if params['from'] != None and params['until'] != None:
                if params['from'] > params['until']:
                    raise BadArgumentError('until cannot preceed from.', verb)
                if from_date_gran != until_date_gran:
                    raise BadArgumentError(
                        'from and until parameters do not use the same granularity.',
                        verb)

            harvestServiceGranularity = h.getOAIPMHServiceGranularity()

            if params[
                    'from'] != None and from_date_gran > harvestServiceGranularity:
                raise BadArgumentError(
                    'from is more granular than Harvest service permits', verb)

            if params[
                    'until'] != None and until_date_gran > harvestServiceGranularity:
                raise BadArgumentError(
                    'until is more granular than Harvest service permits',
                    verb)

            if (from_date_gran != None and from_date_gran.granule != "day" and from_date_gran.granule != "second") or \
                (until_date_gran != None and until_date_gran.granule != "day" and until_date_gran.granule != "second"):
                formatSupport = "YYYY-MM-DD"
                if harvestServiceGranularity.granule == "second":
                    formatSupport = "YYYY-MM-DD and YYYY-MM-DDThh:mm:ssZ"
                raise BadArgumentError(
                    'from and until support {0} formats' % (formatSupport, ),
                    verb)

        if verb in ['ListMetadataFormats', 'GetRecord'
                    ] and req_params.has_key('identifier'):
            params['identifier'] = req_params['identifier']
        elif verb == 'ListMetadataFormats':
            params['identifier'] = None
            params['by_doc_ID'] = None
            params['by_resource_ID'] = None

        if verb == 'GetRecord' and req_params.has_key('identifier') == False:
            raise BadArgumentError('identifier is a required parameter.', verb)

        return params
Esempio n. 5
0
        def ListGeneric(params, showDocs=False, record_limit=None):
            if not showDocs:
                from lr.mustache.oaipmh import ListIdentifiers as must_ListID
                mustache = must_ListID()
            else:
                from lr.mustache.oaipmh import ListRecords as must_ListRec
                mustache = must_ListRec()

            try:

                doc_index = 0
                err_count = 0
                metadataPrefix = params["metadataPrefix"]
                from_date = params["from"]
                until_date = params["until"]
                doc_err = None
                rendered_init = False
                resumptionToken = None if "resumptionToken" not in params else params[
                    'resumptionToken']
                records = o.list_identifiers_or_records(metadataPrefix,
                                                        from_date=from_date,
                                                        until_date=until_date,
                                                        rt=resumptionToken,
                                                        fc_limit=record_limit,
                                                        include_docs=showDocs)
                for ident in records:
                    doc_index += 1
                    doc_err = False

                    if OAIPMHDocumentResolver.PAYLOAD_ERROR in ident:
                        err_count += 1
                        doc_err = True
                        log.debug(
                            "Payload Error detected, doc_index: {0}, err_count: {1}"
                            .format(doc_index, err_count))

                    if doc_index - err_count == 1:
                        rendered_init = True
                        part = mustache.prefix(
                            **self._initMustache(args=params, req=t_req))
                        yield h.fixUtf8(self._returnResponse(part, res=t_res))

                    if doc_err is False and (record_limit is None
                                             or doc_index <= record_limit):
                        part = mustache.doc(ident)
                        yield h.fixUtf8(part)
                    elif enable_flow_control:
                        from lr.lib import resumption_token
                        if doc_index - err_count > 0 and doc_index > record_limit:
                            opts = o.list_opts(
                                metadataPrefix,
                                h.convertToISO8601UTC(ident["node_timestamp"]),
                                until_date)
                            opts["startkey_docid"] = ident["doc_ID"]
                            token = resumption_token.get_token(
                                serviceid=service_id,
                                from_date=from_date,
                                until_date=until_date,
                                **opts)
                            part = mustache.resumptionToken(token)
                            yield h.fixUtf8(part)
                            break
                        elif doc_index - err_count == 0 and doc_index > record_limit:
                            opts = o.list_opts(
                                metadataPrefix,
                                h.convertToISO8601UTC(ident["node_timestamp"]),
                                until_date)
                            opts["startkey_docid"] = ident["doc_ID"]
                            payload = resumption_token.get_payload(
                                from_date=from_date,
                                until_date=until_date,
                                **opts)
                            records = o.list_identifiers_or_records(
                                metadataPrefix,
                                from_date=from_date,
                                until_date=until_date,
                                rt=payload,
                                fc_limit=record_limit,
                                include_docs=showDocs)
                            doc_index = 0
                            err_count = 0

                if doc_index == 0 and err_count == 0:
                    raise NoRecordsMatchError(params['verb'], req=t_req)
                elif (doc_index - err_count) == 0:
                    raise CannotDisseminateFormatError(params['verb'],
                                                       req=t_req)
                else:
                    if enable_flow_control and doc_index <= record_limit:
                        yield h.fixUtf8(mustache.resumptionToken())
                    yield h.fixUtf8(mustache.suffix())

            except oaipmherrors.Error as e:
                if not rendered_init:
                    from lr.mustache.oaipmh import Error as err_stache
                    err = err_stache()
                    yield h.fixUtf8(self._returnResponse(err.xml(e),
                                                         res=t_res))
                else:
                    from lr.mustache.oaipmh import ErrorOnly as err_stache
                    err = err_stache()
                    yield h.fixUtf8(
                        self._returnResponse(err.xml(e) + mustache.suffix(),
                                             res=t_res))
            except:
                log.exception("Unknown Error Occurred")
Esempio n. 6
0
 def _parseParams(self):
     params = {}
     req_params = self._getParams()
     if (req_params.has_key('verb') == False) :
         raise BadVerbError()
     
     verb = params["verb"] = req_params['verb']
     
     if verb not in ["GetRecord", "ListRecords", "ListIdentifiers", "Identify", "ListMetadataFormats", "ListSets"]:
         raise BadVerbError()
     
     if verb == 'GetRecord' or verb == 'ListRecords' or verb == 'ListIdentifiers':        
         if req_params.has_key('metadataPrefix') == False:
             raise BadArgumentError('metadataPrefix is a required parameter.', verb)
         params["metadataPrefix"] = metadataPrefix = req_params['metadataPrefix']
     
     if verb == 'GetRecord' or verb == 'ListMetadataFormats':
         if req_params.has_key('by_doc_ID') and req_params.has_key('by_resource_ID'):
             if self._isTrue(req_params['by_doc_ID']) == self._isTrue(req_params['by_resource_ID']):
                 raise BadArgumentError('by_doc_ID and by_resource_ID have conflicting values.', verb)
             
         if req_params.has_key('by_doc_ID'):
             params['by_doc_ID'] = self._isTrue(req_params['by_doc_ID'])
             params['by_resource_ID'] = not params['by_doc_ID']
         else:
             params['by_doc_ID'] = False
             params['by_resource_ID'] = not params['by_doc_ID']
         
         if req_params.has_key('by_resource_ID'):
             params['by_resource_ID'] = self._isTrue(req_params['by_resource_ID'])
             params['by_doc_ID'] = not params['by_resource_ID']
     
     if verb == 'ListRecords' or verb == 'ListIdentifiers':
         from_date_gran = None
         until_date_gran = None
         if req_params.has_key('from'):
             try:
                 from_date = iso8601.parse_date(req_params['from'])
                 params['from'] = h.convertToISO8601UTC(from_date)
                 from_date_gran = h.getISO8601Granularity(req_params['from'])
             except:
                 raise BadArgumentError('from does not parse to ISO 8601.', verb)
         else:
             params['from'] = None
         
         if req_params.has_key('until'):
             try:
                 until_date = iso8601.parse_date(req_params['until'])
                 params['until'] = h.convertToISO8601UTC(until_date)
                 until_date_gran = h.getISO8601Granularity(req_params['until'])
             except:
                 raise BadArgumentError('until does not parse to ISO 8601.', verb)
         else:
             params['until'] = None
             
         if params['from'] != None and params['until'] != None:
             if params['from'] > params['until']:
                 raise BadArgumentError('until cannot preceed from.', verb)
             if from_date_gran != until_date_gran:
                 raise BadArgumentError('from and until parameters do not use the same granularity.', verb)
         
         harvestServiceGranularity = h.getHarvestServiceGranularity()
         
         if params['from'] != None and from_date_gran > harvestServiceGranularity:
             raise BadArgumentError('from is more granular than Harvest service permits', verb)
     
         if params['until'] != None and until_date_gran > harvestServiceGranularity:
             raise BadArgumentError('until is more granular than Harvest service permits', verb)
         
         if (from_date_gran != None and from_date_gran.granule != "day" and from_date_gran.granule != "second") or \
             (until_date_gran != None and until_date_gran.granule != "day" and until_date_gran.granule != "second"):
             formatSupport = "YYYY-MM-DD"
             if harvestServiceGranularity.granule == "second":
                 formatSupport = "YYYY-MM-DD and YYYY-MM-DDThh:mm:ssZ"
             raise BadArgumentError('from and until support {0} formats' % (formatSupport, ), verb)
         
     
     if verb in ['ListMetadataFormats', 'GetRecord']  and req_params.has_key('identifier'):
         params['identifier'] = req_params['identifier']
     elif verb == 'ListMetadataFormats':
         params['identifier'] = None
         params['by_doc_ID'] = None
         params['by_resource_ID'] = None
     
     if verb == 'GetRecord' and req_params.has_key('identifier') == False:
         raise BadArgumentError('identifier is a required parameter.', verb)
     
     return params
 def _parseParams(self, flow_control=False, serviceid=None):
     params = {}
     req_params = self._getParams()
     if (req_params.has_key('verb') == False) :
         raise BadVerbError()
     
     verb = params["verb"] = req_params['verb']
     
     if verb not in ["GetRecord", "ListRecords", "ListIdentifiers", "Identify", "ListMetadataFormats", "ListSets"]:
         raise BadVerbError()
     
     if verb == 'GetRecord' or verb == 'ListRecords' or verb == 'ListIdentifiers':        
         if req_params.has_key('metadataPrefix') == False:
             raise BadArgumentError('metadataPrefix is a required parameter.', verb)
         params["metadataPrefix"] = metadataPrefix = req_params['metadataPrefix']
         
         if metadataPrefix != o_mod.getMetadataPrefix(metadataPrefix):
             raise CannotDisseminateFormatError(verb)
     
     if verb == 'GetRecord' or verb == 'ListMetadataFormats':
         if req_params.has_key('by_doc_ID') and req_params.has_key('by_resource_ID'):
             if self._isTrue(req_params['by_doc_ID']) == self._isTrue(req_params['by_resource_ID']):
                 raise BadArgumentError('by_doc_ID and by_resource_ID have conflicting values.', verb)
             
         if req_params.has_key('by_doc_ID'):
             params['by_doc_ID'] = self._isTrue(req_params['by_doc_ID'])
             params['by_resource_ID'] = not params['by_doc_ID']
         else:
             params['by_doc_ID'] = False
             params['by_resource_ID'] = not params['by_doc_ID']
         
         if req_params.has_key('by_resource_ID'):
             params['by_resource_ID'] = self._isTrue(req_params['by_resource_ID'])
             params['by_doc_ID'] = not params['by_resource_ID']
     
     if verb == 'ListRecords' or verb == 'ListIdentifiers':
         if flow_control and req_params.has_key('resumptionToken'):
             from lr.lib import resumption_token
             token = req_params['resumptionToken']
             log.debug("resumptionToken: %s" % token)
             try:
                 parsed = resumption_token.parse_token(serviceid, token)
                 if 'error' in parsed:
                     raise BadResumptionTokenError(verb, msg=params['resumptionToken']['error'])  
                 params['resumptionToken'] = parsed
                 
                 if "from_date" in parsed:
                     req_params["from"] = parsed["from_date"]
                 if "until_date" in parsed:
                     req_params["until"] = parsed["until_date"]
             except Exception as e:
                 raise BadResumptionTokenError(verb, msg=e.message)
             
         
         from_date_gran = None
         until_date_gran = None
         if req_params.has_key('from') :
             try:
                 log.error("From 0: {0}".format(req_params['from']))
                 from_date = iso8601.parse_date(req_params['from'])
                 log.error("From 1: {0}".format(from_date))
                 params['from'] = h.convertToISO8601UTC(from_date)
                 log.error("From 2: {0}".format(params['from']))
                 from_date_gran = h.getISO8601Granularity(req_params['from'])
             except:
                 log.error("from: uhh ohh!")
                 raise BadArgumentError('from does not parse to ISO 8601.', verb)
         else:
             params['from'] = None
         
         if req_params.has_key('until'):
             try:
                 log.error("Until 0: {0}".format(req_params['until']))
                 until_date = iso8601.parse_date(req_params['until'])
                 log.error("Until 1: {0}".format(until_date))
                 params['until'] = h.convertToISO8601UTC(until_date)
                 log.error("Until 2: {0}".format(params['until']))
                 until_date_gran = h.getISO8601Granularity(req_params['until'])
             except:
                 raise BadArgumentError('until does not parse to ISO 8601.', verb)
         else:
             params['until'] = None
             
         if params['from'] != None and params['until'] != None:
             if params['from'] > params['until']:
                 raise BadArgumentError('until cannot preceed from.', verb)
             if from_date_gran != until_date_gran:
                 raise BadArgumentError('from and until parameters do not use the same granularity.', verb)
         
         harvestServiceGranularity = h.getOAIPMHServiceGranularity()
         
         if params['from'] != None and from_date_gran > harvestServiceGranularity:
             raise BadArgumentError('from is more granular than Harvest service permits', verb)
     
         if params['until'] != None and until_date_gran > harvestServiceGranularity:
             raise BadArgumentError('until is more granular than Harvest service permits', verb)
         
         if (from_date_gran != None and from_date_gran.granule != "day" and from_date_gran.granule != "second") or \
             (until_date_gran != None and until_date_gran.granule != "day" and until_date_gran.granule != "second"):
             formatSupport = "YYYY-MM-DD"
             if harvestServiceGranularity.granule == "second":
                 formatSupport = "YYYY-MM-DD and YYYY-MM-DDThh:mm:ssZ"
             raise BadArgumentError('from and until support {0} formats' % (formatSupport, ), verb)
         
     
     if verb in ['ListMetadataFormats', 'GetRecord']  and req_params.has_key('identifier'):
         params['identifier'] = req_params['identifier']
     elif verb == 'ListMetadataFormats':
         params['identifier'] = None
         params['by_doc_ID'] = None
         params['by_resource_ID'] = None
     
     if verb == 'GetRecord' and req_params.has_key('identifier') == False:
         raise BadArgumentError('identifier is a required parameter.', verb)
     
     return params
        def ListGeneric(params, showDocs=False, record_limit=None):
            if not showDocs:
                from lr.mustache.oaipmh import ListIdentifiers as must_ListID
                mustache = must_ListID()
            else:
                from lr.mustache.oaipmh import ListRecords as must_ListRec
                mustache = must_ListRec()
                
            try:
                
                doc_index = 0
                err_count = 0
                metadataPrefix=params["metadataPrefix"]
                from_date=params["from"]
                until_date=params["until"]
                doc_err = None
                rendered_init = False
                resumptionToken = None if "resumptionToken" not in params else params['resumptionToken']
                records = o.list_identifiers_or_records(metadataPrefix,
                                                from_date=from_date, 
                                                until_date=until_date, 
                                                rt=resumptionToken, 
                                                fc_limit=record_limit, 
                                                include_docs=showDocs )
                for ident in records:
                    doc_index += 1
                    doc_err = False
                    
                    if OAIPMHDocumentResolver.PAYLOAD_ERROR in ident:
                        err_count += 1
                        doc_err = True
                        log.debug("Payload Error detected, doc_index: {0}, err_count: {1}".format(doc_index, err_count))
                    
                    if doc_index - err_count == 1:
                        rendered_init = True
                        part = mustache.prefix(**self._initMustache(args=params, req=t_req))
                        yield h.fixUtf8(self._returnResponse(part, res=t_res))

                    if doc_err is False and (record_limit is None or doc_index <= record_limit):
                        part = mustache.doc(ident)
                        yield h.fixUtf8(part)
                    elif enable_flow_control:
                        from lr.lib import resumption_token
                        if doc_index - err_count > 0 and doc_index > record_limit:
                            opts = o.list_opts(metadataPrefix, h.convertToISO8601UTC(ident["node_timestamp"]), until_date)
                            opts["startkey_docid"] = ident["doc_ID"]
                            token = resumption_token.get_token(serviceid=service_id, from_date=from_date, until_date=until_date, **opts)
                            part = mustache.resumptionToken(token)
                            yield h.fixUtf8(part)
                            break
                        elif doc_index - err_count == 0 and doc_index > record_limit:
                            opts = o.list_opts(metadataPrefix, h.convertToISO8601UTC(ident["node_timestamp"]), until_date)
                            opts["startkey_docid"] = ident["doc_ID"]
                            payload = resumption_token.get_payload(from_date=from_date, until_date=until_date, **opts)
                            records = o.list_identifiers_or_records(metadataPrefix,
                                                from_date=from_date, 
                                                until_date=until_date, 
                                                rt=payload, 
                                                fc_limit=record_limit, 
                                                include_docs=showDocs )
                            doc_index = 0
                            err_count = 0
                
                if doc_index == 0 and err_count == 0:
                    raise NoRecordsMatchError(params['verb'], req=t_req)
                elif (doc_index - err_count) == 0:
                    raise CannotDisseminateFormatError(params['verb'], req=t_req)
                else:
                    if enable_flow_control and doc_index <= record_limit:
                        yield h.fixUtf8(mustache.resumptionToken())
                    yield h.fixUtf8(mustache.suffix())
                    
            except oaipmherrors.Error as e:
                if not rendered_init:
                    from lr.mustache.oaipmh import Error as err_stache
                    err = err_stache()
                    yield h.fixUtf8(self._returnResponse(err.xml(e), res=t_res))
                else:
                    from lr.mustache.oaipmh import ErrorOnly as err_stache
                    err = err_stache()
                    yield h.fixUtf8(self._returnResponse(err.xml(e)+mustache.suffix(), res=t_res))
            except:
                log.exception("Unknown Error Occurred")
Esempio n. 9
0
 def __parse_date(self, date):
     last_update = helpers.convertToISO8601UTC(date)
     last_update_date = iso8601.parse_date(date)
     return helpers.harvestTimeFormat(last_update)
Esempio n. 10
0
 def __parse_date(self,date):
     last_update_date = iso8601.parse_date(date)
     last_update = helpers.convertToISO8601UTC(last_update_date)    
     return last_update
Esempio n. 11
0
 def __parse_date(self, date):
     last_update_date = iso8601.parse_date(date)
     last_update = helpers.convertToISO8601UTC(last_update_date)
     return last_update
Esempio n. 12
0
    def _parseParams(self):
        params = {}
        req_params = self._getParams()
        if (req_params.has_key('verb') == False):
            raise BadVerbError()

        verb = params["verb"] = req_params['verb']

        if verb not in [
                "GetRecord", "ListRecords", "ListIdentifiers", "Identify",
                "ListMetadataFormats", "ListSets"
        ]:
            raise BadVerbError()

        if verb == 'GetRecord' or verb == 'ListRecords' or verb == 'ListIdentifiers':
            if req_params.has_key('metadataPrefix') == False:
                raise BadArgumentError(
                    'metadataPrefix is a required parameter.', verb)
            params["metadataPrefix"] = metadataPrefix = req_params[
                'metadataPrefix']

        if verb == 'GetRecord' or verb == 'ListMetadataFormats':
            if req_params.has_key('by_doc_ID') and req_params.has_key(
                    'by_resource_ID'):
                if self._isTrue(req_params['by_doc_ID']) == self._isTrue(
                        req_params['by_resource_ID']):
                    raise BadArgumentError(
                        'by_doc_ID and by_resource_ID have conflicting values.',
                        verb)

            if req_params.has_key('by_doc_ID'):
                params['by_doc_ID'] = self._isTrue(req_params['by_doc_ID'])
                params['by_resource_ID'] = not params['by_doc_ID']
            else:
                params['by_doc_ID'] = False
                params['by_resource_ID'] = not params['by_doc_ID']

            if req_params.has_key('by_resource_ID'):
                params['by_resource_ID'] = self._isTrue(
                    req_params['by_resource_ID'])
                params['by_doc_ID'] = not params['by_resource_ID']

        if verb == 'ListRecords' or verb == 'ListIdentifiers':
            from_date_gran = None
            until_date_gran = None
            if req_params.has_key('from'):
                try:
                    from_date = iso8601.parse_date(req_params['from'])
                    params['from'] = h.convertToISO8601UTC(from_date)
                    from_date_gran = h.getISO8601Granularity(
                        req_params['from'])
                except:
                    raise BadArgumentError('from does not parse to ISO 8601.',
                                           verb)
            else:
                params['from'] = None

            if req_params.has_key('until'):
                try:
                    until_date = iso8601.parse_date(req_params['until'])
                    params['until'] = h.convertToISO8601UTC(until_date)
                    until_date_gran = h.getISO8601Granularity(
                        req_params['until'])
                except:
                    raise BadArgumentError('until does not parse to ISO 8601.',
                                           verb)
            else:
                params['until'] = None

            if params['from'] != None and params['until'] != None:
                if params['from'] > params['until']:
                    raise BadArgumentError('until cannot preceed from.', verb)
                if from_date_gran != until_date_gran:
                    raise BadArgumentError(
                        'from and until parameters do not use the same granularity.',
                        verb)

            harvestServiceGranularity = h.getHarvestServiceGranularity()

            if params[
                    'from'] != None and from_date_gran > harvestServiceGranularity:
                raise BadArgumentError(
                    'from is more granular than Harvest service permits', verb)

            if params[
                    'until'] != None and until_date_gran > harvestServiceGranularity:
                raise BadArgumentError(
                    'until is more granular than Harvest service permits',
                    verb)

            if (from_date_gran != None and from_date_gran.granule != "day" and from_date_gran.granule != "second") or \
                (until_date_gran != None and until_date_gran.granule != "day" and until_date_gran.granule != "second"):
                formatSupport = "YYYY-MM-DD"
                if harvestServiceGranularity.granule == "second":
                    formatSupport = "YYYY-MM-DD and YYYY-MM-DDThh:mm:ssZ"
                raise BadArgumentError(
                    'from and until support {0} formats' % (formatSupport, ),
                    verb)

        if verb in ['ListMetadataFormats', 'GetRecord'
                    ] and req_params.has_key('identifier'):
            params['identifier'] = req_params['identifier']
        elif verb == 'ListMetadataFormats':
            params['identifier'] = None
            params['by_doc_ID'] = None
            params['by_resource_ID'] = None

        if verb == 'GetRecord' and req_params.has_key('identifier') == False:
            raise BadArgumentError('identifier is a required parameter.', verb)

        return params