# Introduction to metadata

**LABDRIVE** allows users to add metadata to any file, folder or data container preserved in the system. Functions can be used to automatically generate metadata on ingest, or it can be added manually, or both.

Metadata can be used for searching (even using complex queries), exported or consumed by other systems. Metadata can be associated with the objects in the following ways:&#x20;

* Manually, using the LABDRIVE Management Interface (for a single item or in bulk),&#x20;
* Loaded from a CSV, XML or JSON file,&#x20;
* Using the LABDRIVE API,&#x20;
* Using the LABDRIVE Lambda Functions (you can define code functions that will do rich and advanced extraction and processing to your metadata)
* Using the [LABDRIVE Python library](https://public.docs.libnova.com/labdrive/python/) in conjunction with a [Jupyter Notebook](https://docs.libnova.com/labdrive/get-started/jupyter-notebooks).

## Add metadata using the Management Interface

### Add metadata for a single item manually

1\. Locate the data container you would like to add metadata to using the **Containers menu** section or by searching. This guide assumes metadata is properly configured for the data container. See [Configuration\Metadata](https://docs.libnova.com/labdrive/configuration/metadata) for more details or [Working with data containers](https://docs.libnova.com/labdrive/get-started/working-with-data-containers) to see how to create them.

2\. Select **Check-in** in case you are not checked in the container and you have the check-in/out enabled for the data container.

3\. In the data container page, choose **Explore content**:

![](https://2290386118-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-MVFE6MnOK93sACDCxxx%2F-MVaNm-XFEuXNvAq7xfZ%2F-MVaQrhG8X-H72fzbynC%2Fimage.png?alt=media\&token=392be951-cf87-455d-96ca-addd61a0e539)

4\. **Right click** the item you would like to add metadata to and select **Properties**

5\. In the dialog, select the **Metadata** tab, and the metadata fields that are part of the metadata schema linked to your container are shown. You can add or remove metadata from them. When you have finished, do not forget to select **Save.**&#x20;

![](https://2290386118-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-MVFE6MnOK93sACDCxxx%2F-MWZwO73cLa0geapHCXa%2F-MW_Br6psKasKG25Azo2%2Fimage.png?alt=media\&token=9e8f5030-bd2c-43d6-be67-df8f4015df73)

### Add metadata to multiple items in bulk

It is possible to add metadata to multiple items at once.

1\. Locate the data container you would like to add metadata to using the **Containers menu** section or by searching. This guide assumes metadata is properly configured for the data container. See [Configuration\Metadata](https://docs.libnova.com/labdrive/configuration/metadata) for more details or [Working with data containers](https://docs.libnova.com/labdrive/get-started/working-with-data-containers) to see how to create them.

2\. Select **Check-in** in case you are not checked in the container and you have the check-in/out enabled for the data container.

3\. In the data container page, choose **Explore content**:

![](https://2290386118-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-MVFE6MnOK93sACDCxxx%2F-MVaNm-XFEuXNvAq7xfZ%2F-MVaQrhG8X-H72fzbynC%2Fimage.png?alt=media\&token=392be951-cf87-455d-96ca-addd61a0e539)

4\. Select multiple items using your mouse to **click-and-drag a box around the files or folders** you want to select. You can also use **Ctrl** and **Shift** and use the **Select all**, **Select none** or **Invert selection** in the file browser top bar.

![](https://2290386118-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-MVFE6MnOK93sACDCxxx%2F-MWblfdiNa2NYrnPRZo0%2F-MWbniJsyQt1RGN_zX21%2F2021-03-25_061443.gif?alt=media\&token=be279928-11bd-45eb-98b8-837af30362c4)

You can also **filter the files** in the folder you are looking at by file name, for instance, for selecting all XML or JPG files:

![](https://2290386118-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-MVFE6MnOK93sACDCxxx%2F-MWblfdiNa2NYrnPRZo0%2F-MWbp-B7esiyOg0UfMnF%2F2021-03-25_062021.gif?alt=media\&token=1f28bc94-c9a9-4545-97e8-f78ef5d87647)

5\. When the items to which you want to apply metadata have been selected, select the Function **Bulk Metadata Editor** in your functions side bar. If you have folders selected, LABDRIVE will also apply your metadata to the files contained in them:

![](https://2290386118-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-MVFE6MnOK93sACDCxxx%2F-MWblfdiNa2NYrnPRZo0%2F-MWbr1z6scJsnSmx4cWG%2Fimage.png?alt=media\&token=420afeeb-bc9f-46d2-b2f8-539e1e9061cf)

### Exporting and Importing metadata

Object's metadata can be exported in XML, JSON or CSV format. To export metadata, select the object, right click and select **Properties**. Then select the **Metadata** tab. The export option is at the bottom of the form, in the **Download** button:

![](https://2290386118-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-MVFE6MnOK93sACDCxxx%2Fuploads%2FINJcztWKg0XdBpcrKf28%2Fimage.png?alt=media\&token=62957bd6-0596-47fe-b852-71da8c57b307)

For instance, exporting it in JSON format produces the following output:

![](https://2290386118-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-MVFE6MnOK93sACDCxxx%2Fuploads%2FMgswRdeW2vxlLRJRLz29%2Fimage.png?alt=media\&token=e41e8c01-b605-4a4e-bf3c-87b37333e74e)

For importing metadata back, select the **Import metadata** option:

![](https://2290386118-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-MVFE6MnOK93sACDCxxx%2Fuploads%2F1Y97zrc8YOiuaji2N93E%2Fimage.png?alt=media\&token=10311cc6-6f2d-4dd5-b5fd-08acc7bf128a)

### Metadata recommendations and safe characters

#### XML Related Object Key Constraints

As specified by the [XML standard on end-of-line handling](https://www.w3.org/TR/REC-xml/#sec-line-ends), the following special characters will be normalized and replaced by [their equivalent SML entity code](https://www.w3.org/TR/xml/#syntax) when they are inserted within XML tags:

<table><thead><tr><th width="188" align="center">Special Character</th><th>XML replacement</th></tr></thead><tbody><tr><td align="center">'</td><td><code>&#x26;apos;</code></td></tr><tr><td align="center">"</td><td><code>&#x26;quot;</code></td></tr><tr><td align="center">&#x26;</td><td><code>&#x26;amp;</code></td></tr><tr><td align="center">&#x3C;</td><td><code>&#x26;lt;</code></td></tr><tr><td align="center">></td><td><code>&#x26;gt;</code></td></tr><tr><td align="center">\r</td><td><code>&#x26;#13;</code> or <code>&#x26;#x0D;</code></td></tr><tr><td align="center">\n</td><td><code>&#x26;#10;</code> or <code>&#x26;#x0A;</code></td></tr></tbody></table>

#### Reserved symbols and codes

The platform uses a pre-defined set of characters as prefixes across the different functions and services offered. Therefore, it is recommended to avoid these combinations and reserve them for the required functions and events run within the platform:

<table><thead><tr><th width="312" align="center">Set of Characters</th><th width="430">Usage</th></tr></thead><tbody><tr><td align="center">[|] (pipe between square brackets) </td><td>Separator for more than one metadata value (i.e., <code>Author 1[|]Author 2[|]Author 3</code>)</td></tr><tr><td align="center">[|||] (three pipes between square brackets)</td><td>Setting a link metadata value (API only)<br>(i.e., <code>type:%type%[|||]description:%description%[|||]link:%link%</code>)</td></tr><tr><td align="center">.. (two consecutive periods)</td><td><a href="https://docs.libnova.com/libsafe-go/get-started/openaccess-integration/multilanguage">Multilanguage prefix</a> (Transfer Connector) (i.e., <code>es..title, es..author</code>)</td></tr></tbody></table>

## Add metadata using the API

{% hint style="warning" %}
When users are uploading files to the platform, search results may not show the new file for a while. Consider this in your code when you are uploading and immediately after the upload, you need to search for the uploaded file or alter its metadata. See [Tips when working with the API.](https://docs.libnova.com/get-started/api-extended-documentation#tips-when-working-with-the-api)
{% endhint %}

{% hint style="info" %}
API examples here are just illustrative. Check the [LABDRIVE API documentation](https://docs.libnova.com/labdrive/developers-guide/api-extended-documentation) for additional information and all available methods.
{% endhint %}

1\. Sign in to the LABDRIVE Management Interface

2\. Obtain your LABDRIVE API key selecting your name and then **Access Methods:**

![](https://2290386118-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-MVFE6MnOK93sACDCxxx%2F-MVaHSX-G_bFFXPQn-Od%2F-MVaJWnwSfyMMFbO42X1%2Fimage.png?alt=media\&token=7047e304-094c-4c46-a50e-102ba2513abe)

3\. To change metadata for an item using the LABDRIVE API, you need to know the **unique file identifier** (**LABDRIVE File id)** for it. You can do that by using the API search methods. LABDRIVE API for searching is rich on features and it accepts complex queries.&#x20;

In this guide we are going to search for the items matching a file name:

{% tabs %}
{% tab title="Curl" %}

```bash
curl --request POST \
  --url "$your_labdrive_url/api/file/elastic" \
  --header "Authorization: Bearer $your_labdrive_api_key" \
  --data '{
  "must": [
    {
      "term": {
        "filename.keyword": "my_filename.txt"
      }
    },
    {
      "term": {
        "container_id": 100
      }
    }
  ]
}'

```

{% endtab %}
{% endtabs %}

{% hint style="info" %}
Use:

* **url**: Your LABDRIVE address
* **header**: Your LABDRIVE API Token (add Bearer prefix)
* **filename.keyword**: The filename you are searching for
  * It is important to add ".keyword" to this field, to allow for exact matches. LABDRIVE will not provide accurate results for the "filename" field without the ".keyword"
* **container\_id**: (optional) The id of the container to filter by.&#x20;
  {% endhint %}

4\. With your **unique file identifier** (**LABDRIVE File id)** you can **list** your item's metadata:

{% tabs %}
{% tab title="Curl" %}

```bash
curl --request GET \
  --url "$your_labdrive_url/api/file/<FileID>/metadata" \
  --header "authorization: Bearer $your_labdrive_api_key"
```

{% endtab %}
{% endtabs %}

{% hint style="info" %}
Use:

* **url**: Your LABDRIVE address
* **ID**: The LABDRIFE File ID from the previous step
* **header**: Your LABDRIVE API Token (add Bearer prefix)
  {% endhint %}

Or you can **update** it: If you would like to set the metadata field **title** to "Experiment result 188/12", you can do it in the following way:

{% tabs %}
{% tab title="Curl" %}

```bash
    curl --request PUT \
    --url "$your_labdrive_url/api/file/<FileID>/metadata" \
    --header 'Content-Type: application/json' \
    --header "authorization: Bearer $your_labdrive_api_key" \
    --data '{
      "metadata": [
   	      {
   		        "iecode": "title",
   		        "value": "Experiment result 188/12",
   		        "action": "replace"
   	      }
       ]
    }'

```

{% endtab %}
{% endtabs %}

You can also add **multiple** values to a descriptor by sending an array of values:

{% tabs %}
{% tab title="Curl" %}

```bash
    curl --request PUT \
    --url "$your_labdrive_url/api/file/<FileID>/metadata" \
    --header 'Content-Type: application/json' \
    --header "authorization: Bearer $your_labdrive_api_key" \
    --data '{
      "metadata": [
   	      {
   		       "iecode": "dc.creator",
   		       "value": ["Emmanuelle Charpentier", "Jennifer Doudna"],
   		       "action": "replace"
   	      }
       ]
    }'
```

{% endtab %}
{% endtabs %}

{% hint style="info" %}
Use:

* **url**: Your LABDRIVE address
* **ID**: The LABDRIFE File ID from the previous step
* **header**: Your LABDRIVE API Token (add Bearer prefix)
* **iecode:** The metadata field to edit
* **value:** The metadata value to edit (string *or* array of strings)
* **action:** replace (remove existing value/s and add the new ones), add (add a new one, leaving the existing value/s) or delete (will clear any value)
  {% endhint %}

{% hint style="warning" %}
**CAUTION:** If you include no action parameter **IN ANY** of the request parameters, **LABDRIVE will remove EVERY metadata field value from the object** and will just add the last one you included (not just the one you are including in your request). This is designed for the case in which you want to make a single query and replace every metadata field in the item.

This means that if the file has title="new dataset" and author="Mike" and you launch a method without specifying an action with author="David", the author will be set to "David", but the title will be removed.
{% endhint %}

Metadata which is specified in the OAIS Reference Model Information Model is described in  [labdrive-support-for-oais-conformance](https://docs.libnova.com/labdrive/concepts/oais-and-iso-16363/labdrive-support-for-oais-conformance "mention").
