Merge pull request #117 from geopython/wps-fixes
add HTML pages for processes, add raw mode option for process execution
This commit is contained in:
+29
-1
@@ -38,6 +38,7 @@ from pygeoapi import __version__
|
||||
from pygeoapi.log import setup_logger
|
||||
from pygeoapi.plugin import load_plugin, PLUGINS
|
||||
from pygeoapi.provider.base import ProviderConnectionError, ProviderQueryError
|
||||
from pygeoapi.util import str2bool
|
||||
|
||||
LOGGER = logging.getLogger(__name__)
|
||||
|
||||
@@ -669,6 +670,16 @@ class API(object):
|
||||
|
||||
headers_ = HEADERS.copy()
|
||||
|
||||
format_ = check_format(args, headers)
|
||||
|
||||
if format_ is not None and format_ not in FORMATS:
|
||||
exception = {
|
||||
'code': 'InvalidParameterValue',
|
||||
'description': 'Invalid format'
|
||||
}
|
||||
LOGGER.error(exception)
|
||||
return headers_, 400, json.dumps(exception)
|
||||
|
||||
processes_config = self.config['processes']
|
||||
|
||||
if process is not None:
|
||||
@@ -695,6 +706,17 @@ class API(object):
|
||||
'processes': processes
|
||||
}
|
||||
|
||||
if format_ == 'html': # render
|
||||
headers_['Content-Type'] = 'text/html'
|
||||
if process is not None:
|
||||
response = _render_j2_template(self.config, 'process.html',
|
||||
p.metadata)
|
||||
else:
|
||||
response = _render_j2_template(self.config, 'processes.html',
|
||||
{'processes': processes})
|
||||
|
||||
return headers_, 200, response
|
||||
|
||||
return headers_, 200, json.dumps(response)
|
||||
|
||||
def execute_process(self, headers, args, data, process):
|
||||
@@ -739,7 +761,13 @@ class API(object):
|
||||
|
||||
try:
|
||||
outputs = p.execute(data_dict)
|
||||
response['outputs'] = outputs
|
||||
m = p.metadata
|
||||
if 'raw' in args and str2bool(args['raw']):
|
||||
headers_['Content-Type'] = \
|
||||
m['outputs'][0]['output']['formats'][0]['mimeType']
|
||||
response = outputs
|
||||
else:
|
||||
response['outputs'] = outputs
|
||||
return headers_, 201, json.dumps(response)
|
||||
except Exception as err:
|
||||
exception = {
|
||||
|
||||
+7
-1
@@ -36,6 +36,10 @@ from pygeoapi.plugin import load_plugin
|
||||
|
||||
LOGGER = logging.getLogger(__name__)
|
||||
|
||||
SCHEMAS = {
|
||||
'wps': 'https://raw.githubusercontent.com/opengeospatial/wps-rest-binding/master/core/openapi/schemas' # noqa
|
||||
}
|
||||
|
||||
|
||||
def get_oas_30(cfg):
|
||||
"""
|
||||
@@ -334,13 +338,15 @@ def get_oas_30(cfg):
|
||||
'content': {
|
||||
'application/json': {
|
||||
'schema': {
|
||||
'$ref': 'execute.yaml'
|
||||
'$ref': '{}/{}'.format(SCHEMAS['wps'], 'execute.yaml') # noqa
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
if 'example' in p.metadata:
|
||||
paths['{}/jobs'.format(process_name_path)]['post']['requestBody']['content']['application/json']['example'] = p.metadata['example'] # noqa
|
||||
|
||||
oas['paths'] = paths
|
||||
|
||||
|
||||
@@ -68,7 +68,14 @@ PROCESS_METADATA = {
|
||||
'mimeType': 'application/json'
|
||||
}]
|
||||
}
|
||||
}]
|
||||
}],
|
||||
'example': {
|
||||
'inputs': [{
|
||||
'id': 'name',
|
||||
'value': 'hi there',
|
||||
'type': 'text/plain'
|
||||
}]
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -6,11 +6,11 @@
|
||||
{% endblock %}
|
||||
{% block body %}
|
||||
<section id="collections" itemprop="dataset" itemscope itemtype="http://schema.org/Dataset">
|
||||
<meta itemprop="includedInDataCatalog" content="{{ config['server']['url'] }}" />
|
||||
<meta itemprop="includedInDataCatalog" content="{{ config['server']['url'] }}" />
|
||||
<h2 itemprop="name">{{ data['title'] }}</h2>
|
||||
<div itemprop="description">{{ data['description'] }}</div>
|
||||
<div itemprop="distribution" itemscope itemtype="http://schema.org/DataDownload">
|
||||
<meta itemprop="encodingFormat" content="text/html" />
|
||||
<meta itemprop="encodingFormat" content="text/html" />
|
||||
<a title="Browse Items" itemprop="contentURL" href="{{ config['server']['url'] }}/collections/{{ data['name'] }}/items">
|
||||
Browse through the items of collection {{ data['title'] }}</a></div>
|
||||
<h2>Links</h2>
|
||||
@@ -18,7 +18,7 @@
|
||||
{% for link in data['links'] %}
|
||||
<li itemprop="distribution" itemscope itemtype="http://schema.org/DataDownload">
|
||||
<a itemprop="contentURL" title="{{ link['rel'] }}" href="{{ link['href'] }}">
|
||||
<span itemprop="name">{{ link['title'] }}</span> (<span itemprop="encodingFormat">{{ link['type'] }}</span>)
|
||||
<span itemprop="name">{{ link['title'] }}</span> (<span itemprop="encodingFormat">{{ link['type'] }}</span>)
|
||||
<meta itemprop="inLanguage" content="{{ link['hreflang'] }}" />
|
||||
</a></li>
|
||||
{% endfor %}
|
||||
|
||||
@@ -0,0 +1,50 @@
|
||||
{% extends "base.html" %}
|
||||
{% block title %}{{ super() }} {{ data['title'] }} {% endblock %}
|
||||
{% block crumbs %}{{ super() }}
|
||||
/ <a href="../processes">Processes</a>
|
||||
/ <a href="./{{ data['id'] }}">{{ data['title'] }}</a>
|
||||
{% endblock %}
|
||||
{% block body %}
|
||||
<section id="processes" itemprop="dataset" itemscope itemtype="http://schema.org/Dataset">
|
||||
<meta itemprop="includedInDataCatalog" content="{{ config['server']['url'] }}" />
|
||||
<h2 itemprop="name">{{ data['title'] }}</h2>
|
||||
<div itemprop="description">{{ data['description'] }}</div>
|
||||
<div itemprop="distribution" itemscope itemtype="http://schema.org/WebAPI">
|
||||
<meta itemprop="encodingFormat" content="text/html" />
|
||||
</div>
|
||||
<div class="row">
|
||||
<div class="col-sm-12 col-md-6">
|
||||
<table class="striped">
|
||||
<caption>Inputs</caption>
|
||||
<thead>
|
||||
<tr>
|
||||
<th>Name</th>
|
||||
<th>Description</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
{% for input_ in data['inputs'] %}
|
||||
<tr>
|
||||
<td itemprop="name" data-label="name">{{ input_['id'] }}</td>
|
||||
<td itemprop="title" data-label="title">{{ input_['title'] }}</td>
|
||||
<td itemprop="description" data-label="description">
|
||||
{{ input_['description'] | striptags | truncate }}
|
||||
</td>
|
||||
</tr>
|
||||
{% endfor %}
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
</div>
|
||||
<h2>Links</h2>
|
||||
<ul>
|
||||
{% for link in data['links'] %}
|
||||
<li itemprop="distribution" itemscope itemtype="http://schema.org/DataDownload">
|
||||
<a itemprop="contentURL" title="{{ link['rel'] }}" href="{{ link['href'] }}">
|
||||
<span itemprop="name">{{ link['title'] }}</span> (<span itemprop="encodingFormat">{{ link['type'] }}</span>)
|
||||
<meta itemprop="inLanguage" content="{{ link['hreflang'] }}" />
|
||||
</a></li>
|
||||
{% endfor %}
|
||||
</ul>
|
||||
</section>
|
||||
{% endblock %}
|
||||
@@ -0,0 +1,37 @@
|
||||
{% extends "base.html" %}
|
||||
{% block title %}{{ super() }} Processes {% endblock %}
|
||||
{% block crumbs %}{{ super() }}
|
||||
/ <a href="./processes">Processes</a>
|
||||
{% endblock %}
|
||||
{% block body %}
|
||||
<section id="processes">
|
||||
<h2>Processes in this service</h2>
|
||||
|
||||
<div class="row">
|
||||
<div class="col-sm-12 col-md-6">
|
||||
<table class="striped">
|
||||
<caption>Processes</caption>
|
||||
<thead>
|
||||
<tr>
|
||||
<th>Name</th>
|
||||
<th>Description</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
{% for p in data['processes'] %}
|
||||
<tr itemprop="dataset" itemscope itemtype="http://schema.org/WebAPI">
|
||||
<td itemprop="name" data-label="name">
|
||||
<meta itemprop="url" content="{{ config['server']['url'] }}/processes/{{ p['id'] }}" />
|
||||
<a title="{{ p['title'] | striptags | truncate }}" href="{{ config['server']['url'] }}/processes/{{ p['id'] }}">{{ p['title'] | striptags | truncate }}</a>
|
||||
</td>
|
||||
<td itemprop="description" data-label="description">
|
||||
{{ p['description'] | striptags | truncate }}
|
||||
</td>
|
||||
</tr>
|
||||
{% endfor %}
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
</div>
|
||||
</section>
|
||||
{% endblock %}
|
||||
@@ -54,6 +54,10 @@
|
||||
<h2>Collections</h2>
|
||||
<a href="{{ config['server']['url'] }}/collections?f=html">View the collections in this service</a>
|
||||
</section>
|
||||
<section id="processes">
|
||||
<h2>Processes</h2>
|
||||
<a href="{{ config['server']['url'] }}/processes?f=html">View the processes in this service</a>
|
||||
</section>
|
||||
<section id="links">
|
||||
<h2>Links</h2>
|
||||
<ul>
|
||||
|
||||
@@ -47,3 +47,23 @@ def get_url(scheme, host, port, basepath):
|
||||
url = '{}{}'.format(url, basepath)
|
||||
|
||||
return url
|
||||
|
||||
|
||||
def str2bool(value):
|
||||
"""
|
||||
helper function to return Python boolean
|
||||
type (source: https://stackoverflow.com/a/715468)
|
||||
|
||||
:param value: value to be evaluated
|
||||
|
||||
:returns: `bool` of whether the value is boolean-ish
|
||||
"""
|
||||
|
||||
value2 = False
|
||||
|
||||
if isinstance(value, bool):
|
||||
value2 = value
|
||||
else:
|
||||
value2 = value.lower() in ('yes', 'true', 't', '1', 'on')
|
||||
|
||||
return value2
|
||||
|
||||
Reference in New Issue
Block a user