Skip to content

Commit

Permalink
[Closes #4106] [Remote Services] Add the possibility of filtering the…
Browse files Browse the repository at this point in the history
… list of resources
  • Loading branch information
afabiani committed Mar 14, 2019
1 parent b2a48ad commit 17e061b
Show file tree
Hide file tree
Showing 32 changed files with 674 additions and 280 deletions.
32 changes: 19 additions & 13 deletions geonode/geoserver/signals.py
Original file line number Diff line number Diff line change
Expand Up @@ -89,15 +89,16 @@ def geoserver_post_save(instance, sender, **kwargs):
instance_dict = model_to_dict(instance)
payload = json_serializer_producer(instance_dict)
producer.geoserver_upload_layer(payload)
logger.info("... Creating Thumbnail for Layer [%s]" % (instance.alternate))
try:
thumbnail_task.delay(
instance.id,
instance.__class__.__name__,
overwrite=True,
check_bbox=True)
except BaseException:
logger.warn("!WARNING! - Failure while Creating Thumbnail for Layer [%s]" % (instance.alternate))
if instance.storeType != 'remoteStore':
logger.info("... Creating Thumbnail for Layer [%s]" % (instance))
try:
thumbnail_task.delay(
instance.id,
instance.__class__.__name__,
overwrite=True,
check_bbox=True)
except BaseException:
logger.warn("!WARNING! - Failure while Creating Thumbnail for Layer [%s]" % (instance))


def geoserver_post_save_local(instance, *args, **kwargs):
Expand Down Expand Up @@ -517,10 +518,15 @@ def command_url(command):
# some thumbnail generators will update thumbnail_url. If so, don't
# immediately re-generate the thumbnail here. use layer#save(update_fields=['thumbnail_url'])
if 'update_fields' in kwargs and kwargs['update_fields'] is not None and \
'thumbnail_url' in kwargs['update_fields']:
logger.info("... Creating Thumbnail for Layer [%s]" % (instance.alternate))
thumbnail_task.delay(
instance.id, instance.__class__.__name__, overwrite=True)
'thumbnail_url' in kwargs['update_fields'] and instance.storeType != "remoteStore":
logger.info("... Creating Thumbnail for Layer [%s]" % (instance))
try:
thumbnail_task.delay(
instance.id,
instance.__class__.__name__,
overwrite=True)
except BaseException:
logger.warn("!WARNING! - Failure while Creating Thumbnail for Layer [%s]" % (instance))

try:
Link.objects.filter(resource=instance.resourcebase_ptr, name='Legend').delete()
Expand Down
2 changes: 1 addition & 1 deletion geonode/geoserver/tasks.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ def geoserver_update_layers(self, *args, **kwargs):
return gs_slurp(*args, **kwargs)


@shared_task(bind=True, queue='update')
@shared_task(bind=True, queue='update', expires=30)
def thumbnail_task(self,
instance_id,
instance_type,
Expand Down
6 changes: 1 addition & 5 deletions geonode/geoserver/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -557,11 +557,7 @@ def strip_prefix(path, prefix):
kwargs = {'affected_layers': affected_layers}
import urllib
raw_url = urllib.unquote(raw_url).decode('utf8')
try:
if ogc_server_settings.LOCATION in raw_url:
raw_url = raw_url.replace(ogc_server_settings.LOCATION, ogc_server_settings.WEB_UI_LOCATION)
except BaseException:
pass

return proxy(request, url=raw_url, response_callback=_response_callback, timeout=3, **kwargs)


Expand Down
6 changes: 6 additions & 0 deletions geonode/layers/templates/layers/layer_detail.html
Original file line number Diff line number Diff line change
Expand Up @@ -564,6 +564,7 @@ <h5 class="modal-title" id="myModalLabel">Attribute Information</h5>
{% if resource.get_legend %}
<li class="list-group-item">
<h4 class="list-group-item-heading">{%trans "Legend" %}</h4>
{% if resource.default_style %}
{% for style in resource.styles.all %}
{% if resource.default_style == style %}
{% for legend in resource.get_legend %}
Expand All @@ -582,6 +583,11 @@ <h4 class="list-group-item-heading">{%trans "Legend" %}</h4>
{% endfor %}
{% endif %}
{% endfor %}
{% else %}
{% for legend in resource.get_legend %}
<p><img id="legend_icon" src="{{ legend.url }}"></p>
{% endfor %}
{% endif %}
</li>
{% endif %}
<li class="list-group-item">
Expand Down
54 changes: 28 additions & 26 deletions geonode/layers/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -930,7 +930,7 @@ def create_thumbnail(instance, thumbnail_remote_url, thumbnail_create_url=None,
.update(thumbnail_url=thumbnail_remote_url)

# Download thumbnail and save it locally.
if not ogc_client and not check_ogc_backend(geoserver.BACKEND_PACKAGE):
if not ogc_client:
ogc_client = http_client

if ogc_client:
Expand All @@ -945,10 +945,12 @@ def create_thumbnail(instance, thumbnail_remote_url, thumbnail_create_url=None,
params['bbox'] = instance.bbox_string
params['crs'] = instance.srid

_p = "&".join("%s=%s" % item for item in params.items())
resp, image = ogc_client.request(thumbnail_create_url + '&' + _p)
for _p in params.keys():
if _p.lower() not in thumbnail_create_url.lower():
thumbnail_create_url = thumbnail_create_url + '&%s=%s' % (_p, params[_p])
resp, image = ogc_client.request(thumbnail_create_url)
if 'ServiceException' in image or \
resp.status < 200 or resp.status > 299:
resp.status_code < 200 or resp.status_code > 299:
msg = 'Unable to obtain thumbnail: %s' % image
raise Exception(msg)
except BaseException:
Expand All @@ -957,28 +959,28 @@ def create_thumbnail(instance, thumbnail_remote_url, thumbnail_create_url=None,

# Replace error message with None.
image = None
elif check_ogc_backend(geoserver.BACKEND_PACKAGE) and instance.bbox:
instance_bbox = instance.bbox[0:4]
request_body = {
'bbox': [str(coord) for coord in instance_bbox],
'srid': instance.srid,
'width': width,
'height': height
}

if thumbnail_create_url:
request_body['thumbnail_create_url'] = thumbnail_create_url
elif instance.alternate:
request_body['layers'] = instance.alternate

image = _prepare_thumbnail_body_from_opts(request_body)

if image is not None:
instance.save_thumbnail(thumbnail_name, image=image)
else:
msg = 'Unable to obtain thumbnail for: %s' % instance
logger.error(msg)
# raise Exception(msg)

if check_ogc_backend(geoserver.BACKEND_PACKAGE):
if image is None and instance.bbox:
instance_bbox = instance.bbox[0:4]
request_body = {
'bbox': [str(coord) for coord in instance_bbox],
'srid': instance.srid,
'width': width,
'height': height
}
if thumbnail_create_url:
request_body['thumbnail_create_url'] = thumbnail_create_url
elif instance.alternate:
request_body['layers'] = instance.alternate
image = _prepare_thumbnail_body_from_opts(request_body)

if image is not None:
instance.save_thumbnail(thumbnail_name, image=image)
else:
msg = 'Unable to obtain thumbnail for: %s' % instance
logger.error(msg)
# raise Exception(msg)


# this is the original implementation of create_gs_thumbnail()
Expand Down
6 changes: 3 additions & 3 deletions geonode/maps/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -1078,7 +1078,7 @@ def perm_filter(layer):
# the path to geoserver backend continue here
resp, content = http_client.request(url, 'POST', body=mapJson)

status = int(resp.status)
status = int(resp.status_code)

if status == 200:
map_status = json.loads(content)
Expand Down Expand Up @@ -1129,8 +1129,8 @@ def map_download_check(request):
url = "%srest/process/batchDownload/status/%s" % (
ogc_server_settings.LOCATION, layer["id"])
resp, content = http_client.request(url, 'GET')
status = resp.status
if resp.status == 400:
status = resp.status_code
if resp.status_code == 400:
return HttpResponse(
content="Something went wrong",
status=status)
Expand Down
11 changes: 0 additions & 11 deletions geonode/security/tasks.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@
from django.contrib.auth.models import Group

from geonode.layers.models import Layer
from geonode.geoserver.tasks import thumbnail_task

from .utils import (purge_geofence_layer_rules,
sync_geofence_with_guardian) # set_geofence_invalidate_cache
Expand Down Expand Up @@ -71,16 +70,6 @@ def synch_guardian():
# Set the GeoFence Group Rules
sync_geofence_with_guardian(layer, perms, group=group)

try:
thumbnail_task.delay(
layer.id,
layer.__class__.__name__,
overwrite=True,
check_bbox=True)
except BaseException:
logger.warn("!WARNING! - Failure while Creating Thumbnail \
for Layer [%s]" % (layer.alternate))

r.clear_dirty_state()
except BaseException:
logger.warn("!WARNING! - Failure Synching-up Security Rules for Resource [%s]" % (r))
Expand Down
41 changes: 16 additions & 25 deletions geonode/services/serviceprocessors/wms.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,11 @@

import json
import logging
import requests
import traceback

from uuid import uuid4
from urlparse import urlsplit, urljoin
from httplib import HTTPConnection, HTTPSConnection

from django.conf import settings
from django.core.urlresolvers import reverse
Expand Down Expand Up @@ -268,7 +268,6 @@ def _create_layer_legend_link(self, geonode_layer):
service.
"""

params = {
"service": "WMS",
"version": self.parsed_service.version,
Expand Down Expand Up @@ -491,16 +490,11 @@ def harvest_resource(self, resource_id, geonode_service):

def _probe_geonode_wms(self, raw_url):
url = urlsplit(raw_url)

if url.scheme == 'https':
conn = HTTPSConnection(url.hostname, url.port)
else:
conn = HTTPConnection(url.hostname, url.port)
conn.request('GET', '/api/ows_endpoints/', '', {})
response = conn.getresponse()
content = response.read()
status = response.status
content_type = response.getheader("Content-Type", "text/plain")
base_url = '%s://%s/' % (url.scheme, url.netloc)
response = requests.get('%sapi/ows_endpoints/' % base_url, {}, timeout=30)
content = response.content
status = response.status_code
content_type = response.headers['Content-Type']

# NEW-style OWS Enabled GeoNode
if status == 200 and 'application/json' == content_type:
Expand All @@ -519,20 +513,15 @@ def _probe_geonode_wms(self, raw_url):
return _url

def _enrich_layer_metadata(self, geonode_layer):
url = urlsplit(self.url)

if url.scheme == 'https':
conn = HTTPSConnection(url.hostname, url.port)
else:
conn = HTTPConnection(url.hostname, url.port)

workspace, layername = geonode_layer.name.split(
":") if ":" in geonode_layer.name else (None, geonode_layer.name)
conn.request('GET', '/api/layers/?name=%s' % layername, '', {})
response = conn.getresponse()
content = response.read()
status = response.status
content_type = response.getheader("Content-Type", "text/plain")
url = urlsplit(self.url)
base_url = '%s://%s/' % (url.scheme, url.netloc)
response = requests.get(
'%sapi/layers/?name=%s' % (base_url, layername), {}, timeout=10)
content = response.content
status = response.status_code
content_type = response.headers['Content-Type']

if status == 200 and 'application/json' == content_type:
try:
Expand Down Expand Up @@ -562,7 +551,7 @@ def _enrich_layer_metadata(self, geonode_layer):
resp, image = http_client.request(
thumbnail_remote_url)
if 'ServiceException' in image or \
resp.status < 200 or resp.status > 299:
resp.status_code < 200 or resp.status_code > 299:
msg = 'Unable to obtain thumbnail: %s' % image
logger.debug(msg)

Expand All @@ -575,6 +564,8 @@ def _enrich_layer_metadata(self, geonode_layer):
thumbnail_name, image=image)
else:
self._create_layer_thumbnail(geonode_layer)
else:
self._create_layer_thumbnail(geonode_layer)

# Add Keywords
if "keywords" in _layer and _layer["keywords"]:
Expand Down
33 changes: 0 additions & 33 deletions geonode/services/templates/services/service_detail.html
Original file line number Diff line number Diff line change
@@ -1,39 +1,6 @@
{% extends "services/services_base.html" %}
{% load i18n %}
{% load guardian_tags %}
{% block head %}

{{ block.super }}
<script type="text/javascript" xmlns="http://www.w3.org/1999/html">
var app;
{% autoescape off %}
Ext.onReady(function() {

{% if can_change_permissions %}
new GeoNode.WorldMapPermissionsEditor({
renderTo: "permissions_form",
submitTo: "{% url "geonode.services.views.ajax_service_permissions" service.id %}",
userLookup: "{% url "account_ajax_lookup" %}",
customGroup: "{{ customGroup }}",
permissions: {{ permissions_json }},
levels: {
'admin': 'layer_admin',
'readwrite': 'layer_readwrite',
'readonly': 'layer_readonly',
'none': '_none'
},
listeners: {
updated: function(perms) {
var submitTo = "{% url "geonode.services.views.ajax_service_permissions" service.id %}";
Ext.Ajax.request({ url: submitTo, jsonData: perms.writePermissions() });
}
}
});
{% endif %}
});
{% endautoescape %}
</script>
{% endblock %}

{% block body %}
<div class="twocol">
Expand Down

0 comments on commit 17e061b

Please sign in to comment.