Skip to content

URI Customization Interface

The DCAT extension provides an interface (IDCATURIGenerator) that allows other plugins to customize how URIs are generated for RDF serializations. This is useful when you need to:

  • Use custom URI patterns for dataset, resources, and organizations. This is useful when you have decoupled frontend running in different domains or need to follow specific URI schemes.
  • Integrate with external authority systems
  • Use persistent identifiers like DOIs or handles etc.

Interface Methods

The IDCATURIGenerator interface provides four methods that can be implemented:

catalog_uri(default_uri)

Customize the catalog URI used to identify the entire CKAN instance.

Parameters:

  • default_uri (string): The default catalog URI generated by ckanext-dcat

Returns: - string or None: The catalog URI to use, or None to use the default

Example:

def catalog_uri(self, default_uri):
    custom_domain = toolkit.config.get('ckanext.my_extension.catalog_domain')
    if custom_domain:
        return f"https://{custom_domain}/{default_uri}"
    return None 

dataset_uri(dataset_dict, default_uri)

Customize the dataset URI used to identify individual datasets.

Parameters:

  • dataset_dict (dict): The dataset dictionary containing metadata
  • default_uri (string): The default dataset URI generated by ckanext-dcat

Returns: - string or None: The dataset URI to use, or None to use the default

Example:

def dataset_uri(self, dataset_dict, default_uri):
    # Use DOI if available
    doi = dataset_dict.get('doi')
    if doi:
        return f"https://doi.org/{doi}"
    return None  # Use default

resource_uri(resource_dict, default_uri)

Customize the resource URI used to identify individual resources.

Parameters:

  • resource_dict (dict): The resource dictionary containing metadata
  • default_uri (string): The default resource URI generated by ckanext-dcat

Returns: - string or None: The resource URI to use, or None to use the default

Example:

def resource_uri(self, resource_dict, default_uri):
    # Use the actual URL for API resources
    resource_format = resource_dict.get('format', '').lower()
    if resource_format == 'api':
        return resource_dict.get('url')
    return None  # Use default

publisher_uri(dataset_dict, default_uri)

Customize the publisher URI used to identify the organization that published the dataset.

Parameters:

  • dataset_dict (dict): The dataset dictionary containing metadata
  • default_uri (string): The default publisher URI generated by ckanext-dcat

Returns: - string or None: The publisher URI to use, or None to use the default

Example:

def publisher_uri(self, dataset_dict, default_uri):
    organization = dataset_dict.get('organization', {})
    # Use ROR ID if available
    ror_id = organization.get('ror_id')
    if ror_id:
        return f"https://ror.org/{ror_id}"
    return None  # Use default

Multiple Plugins

If multiple plugins implement the IDCATURIGenerator interface, only the first plugin that returns a non-None value will be used for each URI type. Plugins are called in the order they are loaded.

Backward Compatibility

This interface is completely backward compatible. Existing installations will continue to work unchanged, and the interface only affects URI generation when plugins explicitly implement it.