Removing Content


Sometimes it is necessary to delete documents from the NFDI-MatWerk Data Repository. Detailed documentation is available here.

Here, a short script is suggested for Mac and Linux, which can be used for deleting a data resource from the NFDI-MatWerk Data Repository using its UID. Authentication via REST-API is required for deleting a data resource, so we need to have the scripts environment.sh and get_token.sh already in the working directory.

  1. First, open command prompt and navigate to the directory which contains environment.sh and get_token.sh. Then copy the following code and press enter. Now save the shell script br_remove_object.sh by pressing Ctrl+D. This step is required only when the script is created for the first time. If it exists already as an executable, go directly to Step 3.

     #!/bin/bash
     cat >> br_remove_object.sh
     help()
     {
       # Display Help
       echo "This script is to remove entries from the NFDI-MatWerk Data Repository."
       echo "EDIT: MYHOST Variable to point to your base-repo instance, here NFDI-MatWerk Data Repository"
       echo
       echo "Syntax: scriptTemplate"
       echo "options:"
       echo "-h|--help     Print this Help."
       echo "--uid    UID to delete (--id 99f30db6-[...]-f3f2cad6c12e)"
       echo "--url   full url to remove"
       echo "usage: ./br_remove_object.sh --url http://127.0.0.1:8081/api/v1/dataresources/5d113e5a-[...]-d176be897801"
       echo "       ./br_remove_object.sh --uid c546db10-4df3-4dd8-9ca4-e57d4510a3c1"
     }
    
     source environment.sh
    
     while true; do
       case "$1" in
         -h | --help )
             help
             exit ;;
         -v | --verbose )
             VERBOSE=1
             shift ;;
         --uid)
             uid=$2
             shift 2 ;;
         --url)
             url=$2
             shift 2 ;;
         * ) break ;;
       esac
     done
    
     MYHOST=${BRHOST}
    
     TOKEN=$(./get_token.sh)
    
     QUERY_CALL="${MYHOST}/api/v1/dataresources/"
    
     if [ ${uid} ]; then
       QUERY_CALL="${QUERY_CALL}/$uid"
     elif [ ${url} ]; then
       QUERY_CALL="$url"
     else
       help
       exit
     fi
    
     echo "Removing ${QUERY_CALL}"
    
     echo "##################################"
     echo "getting Etag"
     ETAG=`curl "$QUERY_CALL" --oauth2-bearer ${TOKEN} -s -i | grep ETag | gawk -F\  '{print $2}'`
     echo "##################################"
     echo "revoking  ETAG: $ETAG"
     curl "$QUERY_CALL" --oauth2-bearer ${TOKEN} -i -X DELETE -H 'If-Match: '$ETAG''
    
     echo "##################################"
     echo "getting Etag of revoked"
     sleep 1
     ETAGREVOKED=`curl "$QUERY_CALL" --oauth2-bearer ${TOKEN} -s -i | grep ETag | gawk -F\  '{print $2}'`
     echo "##################################"
     echo "removing ETAG: $ETAGREVOKED"
     curl "$QUERY_CALL" --oauth2-bearer ${TOKEN} -i -X DELETE -H 'If-Match: '$ETAGREVOKED''
    
  2. Once the script is saved, it needs to be converted to an executable using the chmod command.
    Type the following command and press enter:

     chmod +x br_remove_object.sh
    

    This step only needs to be undertaken once.
    If the script has already been made executable, this step can be skipped.

  3. Deleting a resource is done in two steps using this script.
    First, the resource is revoked, and in the second step, it is deleted.

    It is possible to specify the data resource to be deleted by its UID or its full URL.

    • To delete the data resource with its full URL, type:

      ./br_remove_object.sh --url https://matwerk.datamanager.kit.edu/api/v1/dataresources/<UID>
      
    • To delete the data resource with its UID, type:

      ./br_remove_object.sh --uid <UID>
      

    Then press Enter to execute the command.