Esempio n. 1
0
def marcxml_filter(record):
    from inspirehep.dojson.hep import hep2marc
    from inspirehep.dojson.hepnames import hepnames2marc
    from inspirehep.dojson.utils import legacy_export_as_marc

    collections = [
        collection['primary'] for collection in record["collections"]
    ]

    if "HEP" in collections:
        return legacy_export_as_marc(hep2marc.do(record))
    elif "HEPNAMES" in collections:
        return legacy_export_as_marc(hepnames2marc.do(record))
Esempio n. 2
0
    def _send_robotupload(obj, eng):
        from inspirehep.dojson.utils import legacy_export_as_marc
        from inspirehep.utils.robotupload import make_robotupload_marcxml

        combined_callback_url = os.path.join(
            current_app.config["SERVER_NAME"],
            callback_url
        )
        marc_json = marcxml_processor.do(obj.data)
        marcxml = legacy_export_as_marc(marc_json)
        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")
                obj.log.error(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)
            eng.halt("Waiting for robotupload: {0}".format(result.text))
        obj.log.info("end of upload")
Esempio n. 3
0
def test_legacy_export_as_marc_falsy_value():
    falsy_value = {'001': ''}

    expected = '<record>\n</record>\n'
    result = legacy_export_as_marc(falsy_value)

    assert expected == result
Esempio n. 4
0
def test_legacy_export_as_marc_empty_json():
    empty_json = {}

    expected = '<record>\n</record>\n'
    result = legacy_export_as_marc(empty_json)

    assert expected == result
Esempio n. 5
0
def test_legacy_export_as_marc_empty_json():
    empty_json = {}

    expected = '<record>\n</record>\n'
    result = legacy_export_as_marc(empty_json)

    assert expected == result
Esempio n. 6
0
def test_legacy_export_as_marc_falsy_value():
    falsy_value = {'001': ''}

    expected = '<record>\n</record>\n'
    result = legacy_export_as_marc(falsy_value)

    assert expected == result
Esempio n. 7
0
    def _send_robotupload(obj, eng):
        from inspirehep.dojson.utils import legacy_export_as_marc
        from inspirehep.utils.robotupload import make_robotupload_marcxml

        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
        marc_json = marcxml_processor.do(data)
        marcxml = legacy_export_as_marc(marc_json)

        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")
                obj.log.error(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)
            eng.halt("Waiting for robotupload: {0}".format(result.text))

        obj.log.info("end of upload")
Esempio n. 8
0
 def _create_marcxml_record(obj, eng):
     from inspirehep.dojson.hepnames import hepnames2marc
     from inspirehep.dojson.utils import legacy_export_as_marc
     obj.extra_data["marcxml"] = legacy_export_as_marc(
         hepnames2marc.do(obj.data)
     )
     obj.log.info("Produced MarcXML: \n {}".format(
         obj.extra_data["marcxml"])
     )
Esempio n. 9
0
def test_legacy_export_as_marc_json_with_controlfield():
    json_with_controlfield = {'001': '4328'}

    expected = ('<record>\n'
                '    <controlfield tag="001">4328</controlfield>\n'
                '</record>\n')
    result = legacy_export_as_marc(json_with_controlfield)

    assert expected == result
Esempio n. 10
0
 def _create_marcxml_record(obj, eng):
     from inspirehep.dojson.hepnames import hepnames2marc
     from inspirehep.dojson.utils import legacy_export_as_marc
     obj.extra_data["marcxml"] = legacy_export_as_marc(
         hepnames2marc.do(obj.data)
     )
     obj.log.info("Produced MarcXML: \n {}".format(
         obj.extra_data["marcxml"])
     )
Esempio n. 11
0
 def formatter(cls, obj, **kwargs):
     """Nicely format the record."""
     if not obj.data:
         return ""
     if kwargs and kwargs.get('of') == 'xm':
         return legacy_export_as_marc(hep2marc.do(obj.data))
     return render_template(
         'inspirehep_theme/format/record/Holding_Pen_HTML_detailed.tpl',
         record=obj.data
     )
Esempio n. 12
0
def test_legacy_export_as_marc_json_with_controlfield():
    json_with_controlfield = {'001': '4328'}

    expected = (
        '<record>\n'
        '    <controlfield tag="001">4328</controlfield>\n'
        '</record>\n'
    )
    result = legacy_export_as_marc(json_with_controlfield)

    assert expected == result
Esempio n. 13
0
    def _send_robotupload(obj, eng):
        from inspirehep.dojson.utils import legacy_export_as_marc
        from inspirehep.utils.robotupload import make_robotupload_marcxml

        combined_callback_url = os.path.join(
            current_app.config["SERVER_NAME"],
            callback_url
        )
        if not combined_callback_url.startswith('http'):
            combined_callback_url = "http://{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
        marc_json = marcxml_processor.do(data)
        marcxml = legacy_export_as_marc(marc_json)

        if not url and current_app.debug:
            # Log what we would send
            current_app.logger.debug(
                "Going to robotupload {mode} to {url}:\n{marcxml}\n".format(
                    url=url,
                    marcxml=marcxml,
                    callback_url=combined_callback_url,
                    mode=mode,
                    nonce=obj.id,
                    priority=5,
                )
            )
            return
        else:
            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")
                obj.log.error(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)
            eng.halt("Waiting for robotupload: {0}".format(result.text))
        obj.log.info("end of upload")
Esempio n. 14
0
def migrate_workflow_object(obj_id):
    try:
        obj = BibWorkflowObject.query.get(obj_id)
        rename_object_action(obj)
        if obj.workflow.name == "process_record_arxiv":
            metadata = obj.get_data()
            if isinstance(metadata, string_types):
                # Ignore records that have string as data
                return
            if 'drafts' in metadata:
                # New data model detected, just save and exit
                obj.save()
                return
            if hasattr(metadata, 'dumps'):
                metadata = metadata.dumps(clean=True)
            obj.data = bibfield.do(metadata)
            payload = Payload.create(
                type=obj.workflow.name,
                workflow_object=obj
            )
            payload.save()
        elif obj.workflow.name == "literature":
            d = Deposition(obj)
            sip = d.get_latest_sip()
            if sip:
                sip.metadata = bibfield.do(sip.metadata)
                sip.package = legacy_export_as_marc(hep2marc.do(sip.metadata))
                d.save()
        elif obj.workflow.name in ("authornew", "authorupdate"):
            data = obj.get_data()
            obj.set_data(author_bibfield.do(data))
            obj.save()
        else:
            obj.save()  # To update and trigger indexing
        reset_workflow_object_states(obj)
    except Exception as err:
        current_app.logger.error("Problem migrating record {0}".format(obj_id))
        current_app.logger.exception(err)
        msg = "Error: %r\n%s" % \
              (err, traceback.format_exc())
        obj.set_error_message(msg)
        obj.save(version=ObjectVersion.ERROR)
        raise
Esempio n. 15
0
 def _finalize_sip(obj, eng):
     from inspirehep.dojson.utils import legacy_export_as_marc
     model = eng.workflow_definition.model(obj)
     sip = model.get_latest_sip()
     sip.package = legacy_export_as_marc(processor.do(sip.metadata))
     model.update()
def save_changes(sip, model):
    """Saves the changes in the record."""
    sip.package = legacy_export_as_marc(hep2marc.do(sip.metadata))
    model.save()