{ "cells": [ { "cell_type": "markdown", "metadata": {}, "source": [ "# Uuid command" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Help\n", "The help text for the `uuid` subcommand can be shown by passing the `-h` flag." ] }, { "cell_type": "code", "execution_count": 1, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "usage: metacatalog uuid [-h] [--version] [--connection CONNECTION] [--verbose]\n", " [--quiet] [--dev] [--logfile LOGFILE] [--json]\n", " uuid\n", "\n", "positional arguments:\n", " uuid Version 4 UUID of the requested resource\n", "\n", "optional arguments:\n", " -h, --help show this help message and exit\n", " --version, -v Returns the module version\n", " --connection CONNECTION, -C CONNECTION\n", " Connection string to the database instance.Follows the\n", " syntax: driver://user:password@host:port/database\n", " --verbose, -V Activate extended output.\n", " --quiet, -q Suppress any kind of output.\n", " --dev Development mode. Unexpected errors will not be\n", " handled and the full traceback is printed to the\n", " screen.\n", " --logfile LOGFILE If a file is given, output will be written to that\n", " file instead of printed to StdOut.\n", " --json If set, the object will be returned as JSON\n" ] } ], "source": [ "%%bash\n", "metacatalog uuid -h" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Prerequisites\n", "\n", "The `uuid` command assumes that metadata records have been added using [`add`](cli_add.ipynb). " ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Usage\n", "\n", "The `uuid` command can be used to search the database for an object of given UUID. `metacatalog` always refers to UUID version 4. The command will search records across models for the reqeusted resource. Currently, the following model instances can be found:\n", "\n", "* `Entry`\n", "* `EntryGroup`\n", "* `Keyword`" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Example\n", "\n", "The following example shows how a keyword can be found by UUID and related keywords can be searched.\n", "If the database included the GCMD `Keywords` on [`init`](cli_init.ipynb), there will be an controlled keyword of UUID `885735f3-121e-4ca0-ac8b-f37dbc972f03`, which tags the hydrosphere." ] }, { "cell_type": "code", "execution_count": 2, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "Using session: Engine(postgresql://postgres:***@localhost:5432/metacatalog)\n", "EARTH SCIENCE > TERRESTRIAL HYDROSPHERE\n" ] } ], "source": [ "%%bash\n", "metacatalog uuid 885735f3-121e-4ca0-ac8b-f37dbc972f03" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "By passing the `--json` flag, the output can be transformed to json, giving us more information" ] }, { "cell_type": "code", "execution_count": 3, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "Using session: Engine(postgresql://postgres:***@localhost:5432/metacatalog)\n", "{\n", " \"id\": 25,\n", " \"uuid\": \"885735f3-121e-4ca0-ac8b-f37dbc972f03\",\n", " \"value\": \"TERRESTRIAL HYDROSPHERE\",\n", " \"path\": \"EARTH SCIENCE > TERRESTRIAL HYDROSPHERE\",\n", " \"children\": [\n", " \"099ab1ae-f4d2-48cc-be2f-86bd58ffc4ca\",\n", " \"734f8f27-6976-4b67-8794-c7fc79d6161e\",\n", " \"50b8fe04-9149-4b7f-a8b2-b33b1e3aa192\",\n", " \"5debb283-51e4-435e-b2a2-e8e2a977220d\",\n", " \"8c02f5d1-ce86-4bf5-84d5-b3496cdba6ad\"\n", " ],\n", " \"thesaurus_id\": 1\n", "}\n" ] } ], "source": [ "%%bash\n", "metacatalog uuid --json 885735f3-121e-4ca0-ac8b-f37dbc972f03" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Now we can easily check the children keywords:" ] }, { "cell_type": "code", "execution_count": 4, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "Using session: Engine(postgresql://postgres:***@localhost:5432/metacatalog)\n", "{\n", " \"id\": 214,\n", " \"uuid\": \"5debb283-51e4-435e-b2a2-e8e2a977220d\",\n", " \"value\": \"SURFACE WATER\",\n", " \"path\": \"EARTH SCIENCE > TERRESTRIAL HYDROSPHERE > SURFACE WATER\",\n", " \"children\": [\n", " \"1baa552d-c563-43fb-b618-54651f8b07e6\",\n", " \"959f1861-a776-41b1-ba6b-d23c71d4d1eb\",\n", " \"9d86cd70-062a-4c39-b3f3-226abebc07f7\",\n", " \"c84b61fe-720a-4240-b6c8-8dcc9ae24a36\"\n", " ],\n", " \"thesaurus_id\": 1\n", "}\n" ] } ], "source": [ "%%bash \n", "metacatalog uuid --json 5debb283-51e4-435e-b2a2-e8e2a977220d" ] }, { "cell_type": "code", "execution_count": 5, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "Using session: Engine(postgresql://postgres:***@localhost:5432/metacatalog)\n", "{\n", " \"id\": 6220,\n", " \"uuid\": \"9d86cd70-062a-4c39-b3f3-226abebc07f7\",\n", " \"value\": \"SURFACE WATER PROCESSES/MEASUREMENTS\",\n", " \"path\": \"EARTH SCIENCE > TERRESTRIAL HYDROSPHERE > SURFACE WATER > SURFACE WATER PROCESSES/MEASUREMENTS\",\n", " \"children\": [\n", " \"3609b843-d840-460c-b1a3-d4fcc69a32f6\",\n", " \"36a2999b-2255-4d4e-a249-40df3b7b3aaf\",\n", " \"269c7277-fa8f-4c1c-bd8b-ab772c1df4e5\",\n", " \"7fdc339e-017f-4e4b-89a3-12e441a40bad\",\n", " \"960037c5-57b1-4cdf-84be-4542beee7d5a\",\n", " \"d4e8b5c5-9203-4982-82bc-2611b517ffdb\",\n", " \"c6c0c5dd-c0ca-4670-bbaa-c22d39e73570\",\n", " \"5cb5d5b9-0c0b-497f-a4ea-a8cece52d13d\",\n", " \"6f52de55-f5f2-45c0-b83f-59dbfb1fe221\",\n", " \"42aa1fa1-56a9-4e96-8063-077bd7ba88d8\",\n", " \"84784fef-5b76-45a0-91e0-28788e09fea6\",\n", " \"04922ba6-8f00-4f54-b80c-ce2414c91e2e\",\n", " \"f6a54329-486b-4d5f-b105-c639cec42351\"\n", " ],\n", " \"thesaurus_id\": 1\n", "}\n" ] } ], "source": [ "%%bash \n", "metacatalog uuid --json 9d86cd70-062a-4c39-b3f3-226abebc07f7" ] } ], "metadata": { "kernelspec": { "display_name": "Python 3", "language": "python", "name": "python3" }, "language_info": { "codemirror_mode": { "name": "ipython", "version": 3 }, "file_extension": ".py", "mimetype": "text/x-python", "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", "version": "3.7.7" } }, "nbformat": 4, "nbformat_minor": 4 }