예제 #1
0
def import_from_doi(identifier, importdir, req=None):
    def handle_error(req, error_msgstr):
        if req:
            errormsg = translation_t(req, error_msgstr)
            req.request["Location"] = build_url_from_path_and_params(
                "content", {
                    "id": importdir.id,
                    "error": errormsg
                })
            req.params["error"] = errormsg

    import schema.citeproc as citeproc
    import schema.importbase as importbase
    from requests.exceptions import ConnectionError
    doi = identifier
    logg.info("processing DOI import for: %s", doi)
    try:
        doi_extracted = citeproc.extract_and_check_doi(doi)
        new_node = citeproc.import_doi(doi_extracted, importdir)
        return new_node

    except citeproc.InvalidDOI:
        logg.error("Invalid DOI: '%s'", doi)
        handle_error(req, "doi_invalid")

    except citeproc.DOINotFound:
        logg.error("DOI not found: '%s'", doi)
        handle_error(req, "doi_unknown")

    except citeproc.DOINotImported:
        logg.error("no metadata imported for DOI: '%s'", doi)
        handle_error(req, "doi_no_metadata_imported")

    except importbase.NoMappingFound as e:
        logg.error("no mapping found for DOI: '%s', type '%s'", doi, e.typ)
        handle_error(req, "doi_type_not_mapped")

    except ConnectionError as e:
        logg.error("Connection to external server failed with error '%s'", e)
        handle_error(req, "doi_error_connecting_external_server")
    else:
        if req:
            req.request["Location"] = req.makeLink("content",
                                                   {"id": importdir.id})
예제 #2
0
파일: upload.py 프로젝트: mediatum/mediatum
def import_from_doi(identifier, importdir, req=None):

    def handle_error(req, error_msgstr):
        if req:
            errormsg = translation_t(req, error_msgstr)
            req.request["Location"] = build_url_from_path_and_params("content", {"id": importdir.id, "error": errormsg})
            req.params["error"] = errormsg

    import schema.citeproc as citeproc
    import schema.importbase as importbase
    from requests.exceptions import ConnectionError
    doi = identifier
    logg.info("processing DOI import for: %s", doi)
    try:
        doi_extracted = citeproc.extract_and_check_doi(doi)
        new_node = citeproc.import_doi(doi_extracted, importdir)
        return new_node

    except citeproc.InvalidDOI:
        logg.error("Invalid DOI: '%s'", doi)
        handle_error(req, "doi_invalid")

    except citeproc.DOINotFound:
        logg.error("DOI not found: '%s'", doi)
        handle_error(req, "doi_unknown")

    except citeproc.DOINotImported:
        logg.error("no metadata imported for DOI: '%s'", doi)
        handle_error(req, "doi_no_metadata_imported")

    except importbase.NoMappingFound as e:
        logg.error("no mapping found for DOI: '%s', type '%s'", doi, e.typ)
        handle_error(req, "doi_type_not_mapped")

    except ConnectionError as e:
        logg.error("Connection to external server failed with error '%s'", e)
        handle_error(req, "doi_error_connecting_external_server")
    else:
        if req:
            req.request["Location"] = req.makeLink("content", {"id": importdir.id})
예제 #3
0
파일: upload.py 프로젝트: hibozzy/mediatum
def import_from_doi(identifier, importdir, req=None):
    import schema.citeproc as citeproc
    import schema.importbase as importbase
    from requests.exceptions import ConnectionError
    doi = identifier
    logger.info("processing DOI import for: %s", doi)
    try:
        doi_extracted = citeproc.extract_and_check_doi(doi)
        new_node = citeproc.import_doi(doi_extracted, importdir)
        return new_node
    except citeproc.InvalidDOI:
        logger.error("Invalid DOI: '%s'", doi)
        if req:
            req.request["Location"] = req.makeLink("content", {"id": importdir.id, "error": translation_t(req, "doi_invalid")})
            req.params["error"] = translation_t(req, "doi_invalid")
    except citeproc.DOINotFound:
        logger.error("DOI not found: '%s'", doi)
        if req:
            req.request["Location"] = req.makeLink("content", {"id": importdir.id, "error": translation_t(req, "doi_unknown")})
            req.params["error"] = translation_t(req, "doi_unknown")
    except importbase.NoMappingFound as e:
        logger.error("no mapping found for DOI: '%s', type '%s'", doi, e.typ)
        if req:
            req.request["Location"] = req.makeLink("content", {"id": importdir.id, "error": translation_t(req, "doi_type_not_mapped")})
            req.params["error"] = translation_t(req, "doi_type_not_mapped")
    except ConnectionError as e:
        msg = "Connection to external server failed: '%s', type '%s'" % (
            doi, e)
        logger.error(msg)
        if req:
            req.request["Location"] = req.makeLink("content", { "id": importdir.id, "error": translation_t(req, "error_connecting_external_server")})
            req.params["error"] = translation_t(req, "doi_error_connecting_external_server")
            req.params["connect_error_msg"] = msg
    else:
        if req:
            req.request["Location"] = req.makeLink("content", {"id": importdir.id})
예제 #4
0
                req.params["error"] = str(e)
            except:
                logException("error during upload")
                req.request["Location"] = req.makeLink("content", {"id":importdir.id, "error":"PostprocessingError"})
                req.params["error"] = "file_processingerror"
            msg_t = (user.getName(), importdir.id, importdir.name, importdir.type, req.params)
            msg = "%s used import module for bibtex import for node %r (%r, %r): %r" % msg_t
            logg.info(msg)
            return getContent(req, [importdir.id])

    elif req.params["doi"]:
        doi = req.params["doi"]
        logg.info("processing DOI import for: %s", doi)
        try:
            doi_extracted = citeproc.extract_and_check_doi(doi)
            citeproc.import_doi(doi_extracted, importdir)
        except citeproc.InvalidDOI:
            logg.error("Invalid DOI: '%s'", doi)
            req.request["Location"] = req.makeLink("content", {"id":importdir.id, "error":"doi_invalid"})
            req.params["error"] = "doi_invalid"
        except citeproc.DOINotFound:
            logg.error("DOI not found: '%s'", doi)
            req.request["Location"] = req.makeLink("content", {"id":importdir.id, "error":"doi_unknown"})
            req.params["error"] = "doi_unknown"
        except importbase.NoMappingFound as e:
            logg.error("no mapping found for DOI: '%s', type '%s'", doi, e.typ)
            req.request["Location"] = req.makeLink("content", {"id":importdir.id, "error":"doi_type_not_mapped"})
            req.params["error"] = "doi_type_not_mapped"
        else:
            req.request["Location"] = req.makeLink("content", {"id":importdir.id})
        msg_t = (user.getName(), importdir.id, importdir.name, importdir.type, req.params)