Пример #1
0
def applyDoi(pkg):
    # get the current package DOI status
    doiStatus = getDoiStatus(pkg)

    # make sure it's set to accepted
    if doiStatus.get('status').get('value') != DOI_STATUS["ACCEPTED"]:
        return

    # set the new status to REQUESTING DOI
    setPackageExtra('EcoSIS DOI Status', json.dumps({'value':DOI_STATUS["REQUESTING"]}), pkg)

    # update the dataset
    context = {'model': model, 'user': c.user}
    logic.get_action('package_update')(context, pkg)

    # Request DOI from EZID
    doiResponse = requestDoi(pkg)

    # If request failed, reset DOI status, return new error
    if doiResponse.get('status') != 'success':
        status = {
            'value': DOI_STATUS["ACCEPTED"],
            'error' : True,
            'message': 'Failed to request DOI from service',
            'serverResponseStatus' : doiResponse.get('status')
        }
        setPackageExtra('EcoSIS DOI Status', json.dumps(status), pkg)
        logic.get_action('package_update')(context, pkg)
        return status

    # set the returned DOI ARK and new DOI Status
    status = {
        'value' : DOI_STATUS["APPLIED"],
        'ark' : doiResponse.get('ark'),
        'applied' : datetime.datetime.utcnow().isoformat()
    }
    setPackageExtra('EcoSIS DOI Status', json.dumps(status), pkg)
    setPackageExtra('EcoSIS DOI', doiResponse.get('doi'),  pkg)

    # now that it's applied, re-push to search so updates are visible
    push = Push()
    push.run(pkg)

    # final dataset update with new DOI status
    logic.get_action('package_update')(context, pkg)

    return {'success': True}
Пример #2
0
def pushToSearch():
    response.headers["Content-Type"] = "application/json"

    package_id = request.params.get('package_id')
    email = request.params.get('email')
    if email is None:
        email = "false"

    context = {'model': model, 'user': c.user}
    ckanPackage = logic.get_action('package_show')(context, {"id": package_id})

    if email == True or email.lower() == "true":
        email = True
    else:
        email = False

    push = Push()

    return jsonStringify(push.run(ckanPackage, email, c.userobj.email, c.userobj.display_name))