コード例 #1
0
        def GetRecord(params):
            try:
                from lr.mustache.oaipmh import GetRecord as must_GetRecord
                identifier = params["identifier"]
                if params["by_doc_ID"] == True:
                    resolver = OAIPMHDocumentResolver()
                    single_doc = o.get_record(params["identifier"])
                    if single_doc is not None:
                        docList = [resolver.process({"doc": single_doc})]
                    else:
                        docList = []
                else:
                    docList = o.get_records_by_resource(params["identifier"])

                doc_idx = 0
                valid_docs = 0
                mustache = must_GetRecord()
                for doc in docList:
                    if doc is not None:
                        doc_idx += 1

                        if "payload_schema" in doc and params[
                                "metadataPrefix"] in map(
                                    lambda x: o_mod.getMetadataPrefix(x),
                                    doc["payload_schema"]
                                ) and OAIPMHDocumentResolver.PAYLOAD_ERROR not in doc:
                            valid_docs += 1

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

                            part = mustache.doc(doc)
                            yield h.fixUtf8(
                                self._returnResponse(part, res=t_res))

                if doc_idx == 0:
                    raise IdDoesNotExistError(params['verb'], req=t_req)
                elif valid_docs == 0:
                    raise CannotDisseminateFormatError(params['verb'],
                                                       req=t_req)
                else:
                    yield h.fixUtf8(
                        self._returnResponse(mustache.suffix(), res=t_res))

            except oaipmherrors.Error as e:
                from lr.mustache.oaipmh import Error as err_stache
                err = err_stache()
                yield h.fixUtf8(self._returnResponse(err.xml(e), res=t_res))
コード例 #2
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
コード例 #3
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
コード例 #4
0
        def GetRecord(params):
            try:
                from lr.mustache.oaipmh import GetRecord as must_GetRecord
                identifier = params["identifier"]
                if params["by_doc_ID"] == True:
                    resolver = OAIPMHDocumentResolver()
                    single_doc = o.get_record(params["identifier"])
                    if single_doc is not None: 
                        docList = [resolver.process({ "doc": single_doc })]
                    else:
                        docList = []
                else:
                    docList = o.get_records_by_resource(params["identifier"])

                doc_idx = 0
                valid_docs = 0
                mustache = must_GetRecord()
                for doc in docList:
                    if doc is not None:
                        doc_idx += 1
                        
                        if "payload_schema" in doc and params["metadataPrefix"] in map(lambda x: o_mod.getMetadataPrefix(x), doc["payload_schema"]) and OAIPMHDocumentResolver.PAYLOAD_ERROR not in doc:
                            valid_docs += 1
                        
                            if valid_docs == 1:
                                part = mustache.prefix(**self._initMustache(args=params, req=t_req))
                                yield h.fixUtf8(self._returnResponse(part, res=t_res))
                                
                            part = mustache.doc(doc)
                            yield h.fixUtf8(self._returnResponse(part, res=t_res))
                        
                if doc_idx == 0:
                    raise IdDoesNotExistError(params['verb'], req=t_req)
                elif valid_docs == 0:
                    raise CannotDisseminateFormatError(params['verb'], req=t_req)
                else:
                    yield h.fixUtf8(self._returnResponse(mustache.suffix(), res=t_res))
                
            except oaipmherrors.Error as e:
                from lr.mustache.oaipmh import Error as err_stache
                err = err_stache()
                yield h.fixUtf8(self._returnResponse(err.xml(e), res=t_res))