{ "cells": [ { "cell_type": "markdown", "metadata": {}, "source": [ "# Publish metadata on the Terradue catalog\n", "\n", "In this scenario, we use of the *analyzeResults* (recast) web service to extract formatted metadata information from the uploaded data and publish the metadata on the catalog via the *dataPublication* web service.\n", "\n", "This notebook relies on the availability of the sample data in a repository on the Terradue storage (this is obtained by executing the notebook *upload-data.ipynb*).\n", "\n", "## 1. Set the necessary variables\n", "\n", "The following section defines all the necessary information as variables so the code below can be easily reused." ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "import getpass\n", "\n", "# Set the credentials (Ellip username and API key)\n", "username = raw_input(\"What is your Ellip username? \")\n", "api_key = getpass.getpass(\"What is your Ellip API key? \")\n", "\n", "# Set the name of the destination repository on the Terradue storage\n", "repo_name = raw_input(\"What is the destination respository name? (press Enter to confirm default [{0}]) \".format(username))\n", "if not repo_name:\n", " repo_name = username\n", "\n", "# Set the name of the destination index on the Terradue catalog\n", "index_name = raw_input(\"What is the destination index name? (press Enter to confirm default [{0}]) \".format(username))\n", "\n", "if not index_name:\n", " index_name = username\n", "\n", "# Set the URL of the Web Processing Service instance that provides the recast and data publication services\n", "wps_url = \"https://recast.terradue.com/t2api/ows\"\n", "\n", "# Set the directory on store containing the data\n", "folder_path = \"data-publication-sample\"\n", "\n", "# Set the result identifier in the destination index\n", "identifier = \"data-publication-sample\"" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## 2. Set the inputs and invoke the *analyzeResults* (recast) process" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "from owslib.wps import WebProcessingService\n", "from owslib.wps import monitorExecution\n", "from lxml import etree\n", "\n", "wps_process_id = \"analyzeResults\"\n", "\n", "wps_inputs = [\n", " ('repoKey', repo_name),\n", " ('folderPath', folder_path),\n", " ('mode', 'extended'),\n", " ('_T2Username', username),\n", " ('_T2ApiKey', api_key)\n", "]\n", "\n", "try:\n", " wps = WebProcessingService(wps_url)\n", "\n", " wps_execution = wps.execute(wps_process_id, \n", " wps_inputs, \n", " output = [('result_osd', True)]\n", " )\n", "\n", " monitorExecution(wps_execution, sleepSecs=10)\n", "\n", " if wps_execution.isSucceded():\n", " result_osd = wps_execution.processOutputs[0].reference\n", " if result_osd == None:\n", " result_osd = etree.fromstring(wps_execution.processOutputs[0].data[0]).xpath('./@href')[0]\n", " print(\"Result OSDD (recast): {0}\".format(result_osd))\n", " \n", " else:\n", " print(\"Status: {0} {1}\".format(wps_execution.status, wps_execution.statusMessage))\n", " for output in wps_execution.processOutputs:\n", " print(\"identifier={0}, dataType={1}, data={2}, reference={3}\".format(output.identifier, output.dataType, output.data, output.reference))\n", " for error in wps_execution.errors:\n", " print(\"Code: {0}, locator: {1}, text: {2}\".format(error.code,error.locator,error.text))\n", " \n", "except Exception as e:\n", " print(\"Exception: {0}\".format(e))" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "If successful, the OpenSearch description document URL that is displayed as the output the above cell can be used as input for the data publication." ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## 3. Set the inputs and invoke the *dataPublication* process" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "wps_process_id = \"dataPublication\"\n", "\n", "wps_inputs = [('items', result_osd),\n", " ('index', index_name),\n", " ('category', identifier),\n", " ('_T2ApiKey', api_key),\n", " ('_T2Username', username)\n", "]\n", "\n", "try:\n", " wps = WebProcessingService(wps_url)\n", "\n", " wps_execution = wps.execute(wps_process_id, \n", " wps_inputs, \n", " output = [('result_osd', True)]\n", " )\n", "\n", " monitorExecution(wps_execution, sleepSecs=10)\n", "\n", " if wps_execution.isSucceded():\n", " try:\n", " final_osd = wps_execution.processOutputs[0].reference\n", " if final_osd == None:\n", " final_osd = etree.fromstring(wps_execution.processOutputs[0].data[0]).xpath('./@href')[0]\n", " print(\"Result OSDD (final): {0}\".format(final_osd))\n", "\n", " except IndexError:\n", " print(\"ERROR: Results Publication execution failed, no results\")\n", " except Exception as e:\n", " print(\"ERROR: Unexpected error: {0}\".format(e))\n", " else:\n", " print(\"Status: {0} {1}\".format(wps_execution.status, wps_execution.statusMessage))\n", " \n", "except Exception as e:\n", " print(\"Exception: {0}\".format(e))" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "If successful, the OpenSearch description document URL displayed as the output the above cell is the final description URL on the destination index on the Terradue catalog.\n", "\n", "**END**" ] } ], "metadata": { "kernelspec": { "display_name": "Python 2", "language": "python", "name": "python2" }, "language_info": { "codemirror_mode": { "name": "ipython", "version": 2 }, "file_extension": ".py", "mimetype": "text/x-python", "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython2", "version": "2.7.12" } }, "nbformat": 4, "nbformat_minor": 2 }