def test_filteroverdo_handles_exceptions_in_non_dicts(): record = { '$schema': 'hep.json', 'titles': None, } # synthetic data with pytest.raises(DoJsonError) as exc: record2marcxml(record) assert 'Error in rule "246" for field "titles"' in str(exc.value)
def dumps_etree(pid, record, **kwargs): """Dump MARC21 compatible record. :param pid: The :class:`invenio_pidstore.models.PersistentIdentifier` instance. :param record: The :class:`invenio_records.api.Record` instance. :returns: A LXML Element instance. """ r = record['_source'] # adding legacy version (controlfield 005) acquisition_date = parse_date(r['acquisition_source']['date']) r['legacy_version'] = acquisition_date.strftime("%Y%m%d%H%M%S.0") # adding number of pages (datafield 300) page_nr = get_value(r, 'page_nr[0]') if page_nr: r['number_of_pages'] = page_nr # create and add download url if 'urls' not in r and '_files' in r: files = [] for f in r['_files']: url = 'http://%s/api/files/%s/%s' % (current_app.config.get('SERVER_NAME'), f['bucket'], f['key']) files.append({ 'value': url, 'description': f.get('filetype', '') }) r['urls'] = files return etree.fromstring(record2marcxml(r))
def _send_robotupload(obj, eng): combined_callback_url = '' if callback_url: combined_callback_url = os.path.join( current_app.config["SERVER_NAME"], callback_url) if not combined_callback_url.startswith('http'): combined_callback_url = "https://{0}".format( combined_callback_url) if extra_data_key is not None: data = obj.extra_data.get(extra_data_key) or {} else: data = obj.data marcxml = record2marcxml(data) if current_app.debug: # Log what we are sending LOGGER.debug( "Going to robotupload mode:%s to url:%s:\n%s\n", mode, url, marcxml, ) if not in_production_mode(): obj.log.debug( "Going to robotupload %s to %s:\n%s\n", mode, url, marcxml, ) obj.log.debug("Base object data:\n%s", pformat(data)) return result = make_robotupload_marcxml( url=url, marcxml=marcxml, callback_url=combined_callback_url, mode=mode, nonce=obj.id, priority=5, ) if "[INFO]" not in result.text: if "cannot use the service" in result.text: # IP not in the list obj.log.error( "Your IP is not in " "app.config_BATCHUPLOADER_WEB_ROBOT_RIGHTS " "on host: %s", result.text) txt = "Error while submitting robotupload: {0}".format(result.text) raise Exception(txt) else: obj.log.info("Robotupload sent!") obj.log.info(result.text) if callback_url: eng.halt("Waiting for robotupload: {0}".format(result.text)) obj.log.info("end of upload")
def serialize_search(self, pid_fetcher, search_result, links=None, item_links_factory=None): """Serialize a search result as MARCXML.""" result = [ record2marcxml(el['_source']) for el in search_result['hits']['hits'] ] return MARCXML_TEMPLATE.format(''.join(result))
def serialize_search(self, pid_fetcher, search_result, links=None, item_links_factory=None): """Serialize a search result as MARCXML.""" result = [record2marcxml(el['_source']) for el in search_result['hits']['hits']] return MARCXML_TEMPLATE.format(''.join(result))
def serialize(self, pid, record, links_factory=None): """Serialize a single record as MARCXML.""" return MARCXML_TEMPLATE.format(record2marcxml(record))
def _send_robotupload(obj, eng): is_update = obj.extra_data.get('is-update') is_authors = eng.workflow_definition.data_type == 'authors' if not is_authors and is_update and not current_app.config.get( 'FEATURE_FLAG_ENABLE_UPDATE_TO_LEGACY', False): obj.log.info( 'skipping upload to legacy, feature flag ``FEATURE_FLAG_ENABLE_UPDATE_TO_LEGACY`` is disabled.' ) return combined_callback_url = '' if callback_url: combined_callback_url = os.path.join( current_app.config["SERVER_NAME"], callback_url) if not combined_callback_url.startswith('http'): combined_callback_url = "https://{0}".format( combined_callback_url) if extra_data_key is not None: data = obj.extra_data.get(extra_data_key) or {} else: data = obj.data if not current_app.config.get( 'FEATURE_FLAG_ENABLE_SENDING_REFERENCES_TO_LEGACY'): data = copy(data) data.pop('references', None) marcxml = record2marcxml(data) if current_app.debug: # Log what we are sending LOGGER.debug( "Going to robotupload mode:%s to url:%s:\n%s\n", mode, url, marcxml, ) if not in_production_mode(): obj.log.debug( "Going to robotupload %s to %s:\n%s\n", mode, url, marcxml, ) obj.log.debug("Base object data:\n%s", pformat(data)) return result = make_robotupload_marcxml( url=url, marcxml=marcxml, callback_url=combined_callback_url, mode=mode, nonce=obj.id, priority=5, ) if "[INFO]" not in result.text: if "cannot use the service" in result.text: # IP not in the list obj.log.error( "Your IP is not in " "app.config_BATCHUPLOADER_WEB_ROBOT_RIGHTS " "on host: %s", result.text) txt = "Error while submitting robotupload: {0}".format(result.text) raise Exception(txt) else: obj.log.info("Robotupload sent!") obj.log.info(result.text) if callback_url: eng.halt("Waiting for robotupload: {0}".format(result.text)) obj.log.info("end of upload")