Target release2.1.0
Source (e.g. Github)https://github.com/tum-gis/ckanext-relation
Main featuresThis extension provides an UI for creating, deleting and viewing relationships between datasets.
Prerequisite / Dependencies

This extension is tested with CKAN 2.8.0

License Apache License, Version 2.0
Installed by
Document status

COMPLETED

Background and strategic fit

Installations and Requirements

To install ckanext-relation on a production site:

  1. Activate your CKAN virtual environment, for example:

    ENV /usr/lib/ckan/default/bin/activate
  2. Install the ckanext-relation Python package into your virtual environment:

    pip install ckanext-relation
    
    // or
    
    pip install -e git+https://github.com/tum-gis/ckanext-relation#egg=ckanext-relation
  3. Add the relevant plugins to the ckan.plugins setting in your CKAN config file.

  4. Restart CKAN. For example, if you've deployed CKAN with Apache on Ubuntu:

    sudo service apache2 reload

User interaction and design

The design of this extension is basically based on the concept of Distributed Digital Twins and CKAN access control which includes separation of incoming and outgoing relationships.
The UI design is an on-going process which is being improved based on users feedback. 

1. How to populate a metadata schema (@user):

This part is described in the tutorial video. Please refer to the page: User Guideline - HEF AgriHUB

In addition, for each field in the metadata, an info icon is added. By hovering your mouse on the info icon a help text will pup-up.

2. How to deal with design and backend code (@developer):

This extension is tested with CKAN 2.8.0. You may have a problem with the deleting if you use this version. You may need to upgrade/update the delete function to purge all deleted datasets. Have a look at this: https://github.com/ckan/ckan/blob/ckan-2.8.0/ckan/controllers/package.py#L1024

Here is the correct code:

def delete(self, id):

        if 'cancel' in request.params:
            h.redirect_to(controller='package', action='edit', id=id)

        context = {'model': model, 'session': model.Session,
                   'user': c.user, 'auth_user_obj': c.userobj}

        try:
            if request.method == 'POST':
				# Newly added block to delete the relationship if there exists
                # It only includes three types of relationship 
				for rel in ['depends_on', 'links_to', 'child_of']: 
					print('test:'+ rel)
					rel_exist = []
					try:
						rel_exist = get_action('package_relationships_list')(data_dict={'id': id, 'rel':rel})
						print('done with action')
						print(rel_exist)
						if len(rel_exist)!=0:
							print(rel, 'exists')
							for ds in rel_exist:
								data_dict={"subject": id, "object": ds['object'], "type": rel}								
								get_action('package_relationship_delete')({}, data_dict)
								print('hier ist ds:')
					except:
						pass
                ####### till here############
				get_action('package_delete')(context, {'id': id})             
				h.flash_notice(_('Dataset has been deleted.'))
				h.redirect_to(controller='package', action='search')							
            c.pkg_dict = get_action('package_show')(context, {'id': id})
            dataset_type = c.pkg_dict['type'] or 'dataset'
        except NotAuthorized:
            abort(403, _('Unauthorized to delete package %s') % '')
        except NotFound:
            abort(404, _('Dataset not found'))
        return render('package/confirm_delete.html',
                      extra_vars={'dataset_type': dataset_type})

The javascript is also directly included in the main.min.js and not in this ckanext. Here is the Javascript code used for this extension:

$(document).ready(function() {
    $(".glyphicon").click(function() {
        $(this).toggleClass("glyphicon-chevron-down").toggleClass("glyphicon-chevron-up")
    })
});

Questions and Answers

Below is a list of Q&A from user sides:

QuestionAnswers
1. Is it necessary that after the search I go again under each relationship type and add the dataset as a relationship? why not directly on the search result boxThe purpose is that the user thinks again about the type of the relationship and then when s/he is sure to choose the right type and under that type adds the dataset.

Further steps

  • Add help text to the UI
  • Add automatically an infobox in the dataset page when an outgoing relationship exists
  • Add group labelling into the relationship page