Publish metadata on the Terradue catalog

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.

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).

1. Set the necessary variables

The following section defines all the necessary information as variables so the code below can be easily reused.

[ ]:
import getpass

# Set the credentials (Ellip username and API key)
username = raw_input("What is your Ellip username? ")
api_key = getpass.getpass("What is your Ellip API key? ")

# Set the name of the destination repository on the Terradue storage
repo_name = raw_input("What is the destination respository name? (press Enter to confirm default [{0}]) ".format(username))
if not repo_name:
    repo_name = username

# Set the name of the destination index on the Terradue catalog
index_name = raw_input("What is the destination index name? (press Enter to confirm default [{0}]) ".format(username))

if not index_name:
    index_name = username

# Set the URL of the Web Processing Service instance that provides the recast and data publication services
wps_url = "https://recast.terradue.com/t2api/ows"

# Set the directory on store containing the data
folder_path = "data-publication-sample"

# Set the result identifier in the destination index
identifier = "data-publication-sample"

2. Set the inputs and invoke the analyzeResults (recast) process

[ ]:
from owslib.wps import WebProcessingService
from owslib.wps import monitorExecution
from lxml import etree

wps_process_id = "analyzeResults"

wps_inputs = [
    ('repoKey', repo_name),
    ('folderPath', folder_path),
    ('mode', 'extended'),
    ('_T2Username', username),
    ('_T2ApiKey', api_key)
]

try:
    wps = WebProcessingService(wps_url)

    wps_execution = wps.execute(wps_process_id,
                                wps_inputs,
                                output = [('result_osd', True)]
    )

    monitorExecution(wps_execution, sleepSecs=10)

    if wps_execution.isSucceded():
        result_osd = wps_execution.processOutputs[0].reference
        if result_osd == None:
            result_osd = etree.fromstring(wps_execution.processOutputs[0].data[0]).xpath('./@href')[0]
        print("Result OSDD (recast): {0}".format(result_osd))

    else:
        print("Status: {0} {1}".format(wps_execution.status, wps_execution.statusMessage))
        for output in wps_execution.processOutputs:
            print("identifier={0}, dataType={1}, data={2}, reference={3}".format(output.identifier, output.dataType, output.data, output.reference))
        for error in wps_execution.errors:
            print("Code: {0}, locator: {1}, text: {2}".format(error.code,error.locator,error.text))

except Exception as e:
    print("Exception: {0}".format(e))

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.

3. Set the inputs and invoke the dataPublication process

[ ]:
wps_process_id = "dataPublication"

wps_inputs = [('items', result_osd),
              ('index', index_name),
              ('category', identifier),
              ('_T2ApiKey', api_key),
              ('_T2Username', username)
]

try:
    wps = WebProcessingService(wps_url)

    wps_execution = wps.execute(wps_process_id,
                                wps_inputs,
                                output = [('result_osd', True)]
    )

    monitorExecution(wps_execution, sleepSecs=10)

    if wps_execution.isSucceded():
        try:
            final_osd = wps_execution.processOutputs[0].reference
            if final_osd == None:
                final_osd = etree.fromstring(wps_execution.processOutputs[0].data[0]).xpath('./@href')[0]
            print("Result OSDD (final): {0}".format(final_osd))

        except IndexError:
            print("ERROR: Results Publication execution failed, no results")
        except Exception as e:
            print("ERROR: Unexpected error: {0}".format(e))
    else:
        print("Status: {0} {1}".format(wps_execution.status, wps_execution.statusMessage))

except Exception as e:
    print("Exception: {0}".format(e))

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.

END