Complex Example of hierarchical content
The newly created resource should meet the following requirements:
publishScheme and accessScheme should be private
Metadata are in LRMI Schema
Resource should be assigned to an existing user in the Drupal frontend
Structure of the Resource:
orca:50
├── lrmiData
└── orca:51
└── document.pdf
For the below curl command to work from your local computer it is convenient to put some often used data
into environment variables. Prepare a simple textfile e.g. example
with the following content. The
DRUPAL_USERID
is the numeric id which is automatically assigned to the user account by the Drupal CMS.
1export TOSCIENCE_API=https://api.example.com
2export DRUPAL_USERID="2"
3export API_USER=toscience-admin
4export PASSWORD=***********
Make the variables available by sourcing the file:
$ source example
Creating resource
Initially we create a yet empty resource with the desired accessScheme, publishSchem and user id:
$ curl -i -u$API_USER:$PASSWORD -XPUT $TOSCIENCE_API/resource/orca:50 -d'{"contentType":"researchData","accessScheme":"private", "publishScheme":"private", "isDescribedBy":{"createdBy":"'"$DRUPAL_USERID"'"}}' -H'Content-type:application/json' ; echo
The Metadata are given in a special LRMI-Format and passed to a didicated endpoint:
$ curl -i -u$API_USER:$PASSWORD -XPOST $TOSCIENCE_API/resource/orca:50/lrmiData --data-binary '@lrmi.json' -H'Content-Type:application/json;charset=utf-8'; echo
The data are stored in a separate resource of contentType file
. At this point there is no relation between the two newly created resources:
$ curl -i -u$API_USER:$PASSWORD -XPUT $TOSCIENCE_API/resource/orca:51 -d'{"contentType":"file","accessScheme":"private", "publishScheme":"private", "isDescribedBy":{"createdBy":"'"$DRUPAL_USERID"'"}}' -H'Content-type:application/json' ; echo
Adding the actual data, a pdf-file in this case:
$ curl -i -u$API_USER:$PASSWORD -XPUT $TOSCIENCE_API/resource/orca:51/data -F"data=@document.pdf;type=application/pdf" ; echo
In a final step we tell the data resource about it’s parent resource:
$ curl -i -u$API_USER:$PASSWORD -XPUT $TOSCIENCE_API/resource/orca:51 -H'Content-Type:application/json;charset=utf-8' -d'{"parentPid":"orca:50","contentType":"file"}' ; echo
Retrieving the resource
Reading the metadata in standard json format:
$ curl -i -u$API_USER:$PASSWORD -XGET $TOSCIENCE_API/resource/orca:51.json2 ; echo
The LRMI Metadata are again available via the dedicated endpoint:
$ curl -i -u$API_USER:$PASSWORD -XGET $TOSCIENCE_API/resource/orca:51/lrmiData ; echo
Downloading the data
$curl -i -u$API_USER:$PASSWORD -XGET $TOSCIENCE_API/resource/orca:51/data --output data.pdf; echo