Skip to content

Action

create_doi(context, data_dict) ΒΆ

Creates a DOI using the given parameters and returns it.

Parameters:

Name Type Description Default
email_address string

the email address of the DOI requester

required
query dict

the query to associate with the DOI

required
query_version string

the query schema version for the query

required
version int, number of milliseconds (not seconds!) since UNIX epoch

the version to search the data at

required
resource_ids list of strings

the resource ids to search

required
doi string

the doi that was created (prefix/suffix)

required
is_new bool

whether the doi was newly created or whether an existing DOI for the query parameters already existed

required
email_sent bool

whether the email was sent successfully or not

required
Source code in ckanext/query_dois/logic/action.py
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
def create_doi(context, data_dict):
    """
    Creates a DOI using the given parameters and returns it.

    :param email_address: the email address of the DOI requester
    :type email_address: string
    :param query: the query to associate with the DOI
    :type query: dict
    :param query_version: the query schema version for the query
    :type query_version: string
    :param version: the version to search the data at
    :type version: int, number of milliseconds (not seconds!) since UNIX epoch
    :param resource_ids: the resource ids to search
    :type resource_ids: list of strings
    :param doi: the doi that was created (prefix/suffix)
    :type doi: string
    :param is_new: whether the doi was newly created or whether an existing DOI for the
        query parameters already existed
    :type is_new: bool
    :param email_sent: whether the email was sent successfully or not
    :type email_sent: bool
    :rtype: dict
    """
    # validate the data dict first
    schema = context.get('schema', schema_lib.create_doi())
    data_dict, errors = toolkit.navl_validate(data_dict, schema, context)
    if errors:
        raise toolkit.ValidationError(errors)

    email_address = data_dict['email_address']
    query = Query.create(
        data_dict['resource_ids'],
        data_dict.get('version'),
        data_dict.get('query'),
        data_dict.get('query_version'),
    )

    # create a new DOI or retrieve an existing one
    created, doi = mint_multisearch_doi(query)
    # record a stat for this action
    record_stat(doi, SAVE_ACTION, email_address)
    # send the email to the requesting user
    email_sent = send_saved_search_email(email_address, doi)

    return {'is_new': created, 'doi': doi.doi, 'email_sent': email_sent}