Difference between revisions of "Ckan 2 zenodo library"

From Gcube Wiki
Jump to: navigation, search
(Created page with "{| align="right" ||__TOC__ |} The ''org.gcube.data.publishing.ckan2Zenodo'' gCube component is a Java library which translates CKAN items into Zenodo depositions, allowing to...")
 
(Source Code)
 
(6 intermediate revisions by the same user not shown)
Line 6: Line 6:
  
 
==Overview==
 
==Overview==
 +
[[File:Ckan2_zenodo.png]]
  
 
The library is invoked by the client (in this case the gCube CKAN GUI), which relies on the '''gCat''' service for interacting with CKAN.  
 
The library is invoked by the client (in this case the gCube CKAN GUI), which relies on the '''gCat''' service for interacting with CKAN.  
Line 16: Line 17:
 
The Final Deposition is then returned to the client for further editing, which can eventually ask for its publication (the new Zenodo Doi will be then applied to the CKAN item through gCat).
 
The Final Deposition is then returned to the client for further editing, which can eventually ask for its publication (the new Zenodo Doi will be then applied to the CKAN item through gCat).
  
===Configuration===
+
===IS Configuration===
===Mappings===
+
*'''Zenodo Credentials''' ServiceEndpoint
====Directives====
+
<source lang="xml">
 +
..
 +
<Category>Repository</Category>
 +
..
 +
<Platform>
 +
  <Name>Zenodo</Name>
 +
...
 +
</source>
 +
 
 +
*'''XML Mapping''' Generic Resource
 +
:'''NB:''' one '''XML Mapping''' per profile is supported
 +
<source lang="xml">
 +
..
 +
<SecondaryType>Ckan-Zenodo-Mappings</SecondaryType>
 +
 
 +
<Name>[***PROFILE_ID***]</Name>
 +
..
 +
</source>
 +
 
 +
===XML Mappings===
 +
Each mapping directive selects a source value list and applies them to a specific deposition field.
 +
 
 +
Several options and features are supported on both source values and target values directives.
 +
 
 +
Field are selected using JSON paths (see [[[https://github.com/json-path/JsonPath JsonPath library]]]).
 +
 
 +
Following is a simple directive setting a ''constan'' value to path ''$.metadata.upload_type''.
 +
 
 +
<source lang="xml">
 +
<mapping>
 +
  <source>
 +
  <value type="constant">dataset</value>
 +
  <//source>
 +
  <targetPath>$.metadata</targetPath>
 +
  <targetElement>upload_type</targetElement>
 +
</mapping>
 +
</source>
 +
 
 +
====Directives Options====
 +
=====Source=====
 +
*'''Type''' : can be either '''constant''' or '''jsonPath'''
 +
*'''Split''' : [optional] is used to split found values
 +
*Multiple '''value''' directives can be declared. The first one to actual produce values is used.
 +
<source lang="xml">
 +
<mapping>
 +
<source>
 +
  <value type="jsonPath">$.extras[?(@.key=='Author')].value</value>
 +
  <value type="jsonPath" split=";">$.author</value>
 +
<//source>
 +
<targetPath>$.metadata.creators[0]</targetPath>
 +
<targetElement>name</targetElement>
 +
</mapping>
 +
</source>
 +
=====Target=====
 +
*'''Append''' : [optional, default = false] append the value to the existing one instead of overwriting it.
 +
=====Regexp=====
 +
* The use of '''Regexp''' directive is optional.
 +
* Multiple '''Regexp''' directives can be declared.
 +
*'''Extract''' : Extract only matching string from processed ''values''
 +
<source lang="xml">
 +
<mapping>
 +
<source type="jsonPath">
 +
  <value>$.extras[?(@.key=='Author')].value</value>
 +
<//source>
 +
<targetPath>$.metadata.contributors[0]</targetPath>
 +
<targetElement>orcid</targetElement>
 +
<regexp type="extract">
 +
  <target>(https://)?orcid.org/.*</target>
 +
</regexp>
 +
</mapping>
 +
</source>
 +
 
 +
*'''Replace''' : Replace ''matching pattern'' with ''replacementString''
 +
<source lang="xml">
 +
<mapping>
 +
<source>
 +
  <value type="jsonPath">$.extras[?(@.key=='AccessMode:Accessibility')].value</value>
 +
<//source>
 +
<targetPath>$.metadata</targetPath>
 +
<targetElement append="true">access_conditions</targetElement>
 +
<regexp type="replace">
 +
  <target>^</target>
 +
  <replacement>AccessMode.Accessibility : </replacement>
 +
</regexp>
 +
<regexp type="replace">
 +
  <target>$</target>
 +
  <replacement>; </replacement>
 +
</regexp>
 +
</mapping>
 +
</source>
 +
 
 
== Integration ==
 
== Integration ==
 
===Maven coordinates===
 
===Maven coordinates===
 +
<source lang="xml">
 +
<groupId>org.gcube.data.publishing</groupId>
 +
<artifactId>ckan2zenodo-library</artifactId>
 +
<version>0.0.2-SNAPSHOT</version>
 +
</source>
 +
 
===Source Code===
 
===Source Code===
 +
Source code available [[[https://code-repo.d4science.org/gCubeSystem/ckan2zenodo-library.git here]]].

Latest revision as of 17:31, 26 June 2020

The org.gcube.data.publishing.ckan2Zenodo gCube component is a Java library which translates CKAN items into Zenodo depositions, allowing to further editing and publication.

Overview

Ckan2 zenodo.png

The library is invoked by the client (in this case the gCube CKAN GUI), which relies on the gCat service for interacting with CKAN. After the ckan item is loaded, a default translation is then applied on the item's core fields generating in a Draft Zenodo Deposition. NB If the item has already a linked Zenodo DOI, the Draft Deposition overrides its specified informations.

A XML Mapping associated with item's profile, is then loaded from the IS (token must be specified by the client). The XML Mapping extracts data from the CKAN item and applies them to the Draft Deposition, resulting in a Final Deposition.

The Final Deposition is then returned to the client for further editing, which can eventually ask for its publication (the new Zenodo Doi will be then applied to the CKAN item through gCat).

IS Configuration

  • Zenodo Credentials ServiceEndpoint
..
<Category>Repository</Category>
..
<Platform>
  <Name>Zenodo</Name>
...
  • XML Mapping Generic Resource
NB: one XML Mapping per profile is supported
..
<SecondaryType>Ckan-Zenodo-Mappings</SecondaryType>
 
<Name>[***PROFILE_ID***]</Name>
..

XML Mappings

Each mapping directive selects a source value list and applies them to a specific deposition field.

Several options and features are supported on both source values and target values directives.

Field are selected using JSON paths (see [[JsonPath library]]).

Following is a simple directive setting a constan value to path $.metadata.upload_type.

<mapping>
  <source>
   <value type="constant">dataset</value>					
  <//source>					
  <targetPath>$.metadata</targetPath>
  <targetElement>upload_type</targetElement>
</mapping>

Directives Options

Source
  • Type : can be either constant or jsonPath
  • Split : [optional] is used to split found values
  • Multiple value directives can be declared. The first one to actual produce values is used.
<mapping>
 <source>
  <value type="jsonPath">$.extras[?(@.key=='Author')].value</value>
  <value type="jsonPath" split=";">$.author</value>						
 <//source>
 <targetPath>$.metadata.creators[0]</targetPath>
 <targetElement>name</targetElement>
</mapping>
Target
  • Append : [optional, default = false] append the value to the existing one instead of overwriting it.
Regexp
  • The use of Regexp directive is optional.
  • Multiple Regexp directives can be declared.
  • Extract : Extract only matching string from processed values
<mapping>
 <source type="jsonPath">
  <value>$.extras[?(@.key=='Author')].value</value>
 <//source>
 <targetPath>$.metadata.contributors[0]</targetPath>
 <targetElement>orcid</targetElement>
 <regexp type="extract">
  <target>(https://)?orcid.org/.*</target>
 </regexp>
</mapping>
  • Replace : Replace matching pattern with replacementString
<mapping>
 <source>
  <value type="jsonPath">$.extras[?(@.key=='AccessMode:Accessibility')].value</value>
 <//source>
 <targetPath>$.metadata</targetPath>
 <targetElement append="true">access_conditions</targetElement>
 <regexp type="replace">
  <target>^</target>
  <replacement>AccessMode.Accessibility : </replacement>
 </regexp>
 <regexp type="replace">
  <target>$</target>
  <replacement>; </replacement>
 </regexp>
</mapping>

Integration

Maven coordinates

<groupId>org.gcube.data.publishing</groupId>
<artifactId>ckan2zenodo-library</artifactId>
<version>0.0.2-SNAPSHOT</version>

Source Code

Source code available [[here]].