Skip to content

Commit

Permalink
- Correct management of SLDs / Add GWC filterParameter to SLDs
Browse files Browse the repository at this point in the history
  • Loading branch information
afabiani committed May 16, 2018
1 parent 7b32bb1 commit ddeebf5
Show file tree
Hide file tree
Showing 8 changed files with 66 additions and 34 deletions.
19 changes: 13 additions & 6 deletions geonode/geoserver/views.py
Expand Up @@ -54,9 +54,9 @@
from .tasks import geoserver_update_layers
from geonode.utils import json_response, _get_basic_auth_info
from geoserver.catalog import FailedRequestError, ConflictingDataError
from .helpers import (get_stores, ogc_server_settings,
extract_name_from_sld, set_styles, style_update,
create_gs_thumbnail, _invalidate_geowebcache_layer)
from .helpers import (get_stores, ogc_server_settings, extract_name_from_sld, set_styles,
style_update, create_gs_thumbnail,
_stylefilterparams_geowebcache_layer, _invalidate_geowebcache_layer)

from django_basic_auth import logged_in_or_basicauth
from django.views.decorators.csrf import csrf_exempt
Expand Down Expand Up @@ -189,7 +189,11 @@ def respond(*args, **kw):
return respond(errors="""A layer with this name exists. Select
the update option if you want to update.""")
# Invalidate GeoWebCache for the updated resource
_invalidate_geowebcache_layer(layer.alternate)
try:
_stylefilterparams_geowebcache_layer(layer.alternate)
_invalidate_geowebcache_layer(layer.alternate)
except:
pass
return respond(
body={
'success': True,
Expand Down Expand Up @@ -305,8 +309,11 @@ def layer_style_manage(request, layername):
set_styles(layer, cat)

# Invalidate GeoWebCache for the updated resource
_invalidate_geowebcache_layer(layer.alternate)

try:
_stylefilterparams_geowebcache_layer(layer.alternate)
_invalidate_geowebcache_layer(layer.alternate)
except:
pass
return HttpResponseRedirect(
reverse(
'layer_detail',
Expand Down
26 changes: 19 additions & 7 deletions geonode/static/geonode/js/upload/FileType.js
Expand Up @@ -20,8 +20,25 @@ define(function (require, exports) {
};


FileType.prototype.isType = function (file) {
return (this.main === getExt(file));
FileType.prototype.isType = function (file, extensions) {
var main_matches = (this.main === getExt(file));
var aux_matches = this.findAuxiliaryFiles(extensions);
return main_matches && aux_matches;
};

FileType.prototype.findAuxiliaryFiles = function (extensions) {
if (this.aux === undefined || this.aux === null || this.aux.length === 0) {
return true;
}

var matches = false;
$.each(this.aux, function (idx, req) {
idx = $.inArray(req, extensions);
if (idx !== -1) {
matches = true;
}
});
return matches;
};

FileType.prototype.findTypeErrors = function (extensions) {
Expand All @@ -34,13 +51,8 @@ define(function (require, exports) {
}
});
return errors;

};

return FileType;

});




13 changes: 7 additions & 6 deletions geonode/static/geonode/js/upload/FileTypes.js
Expand Up @@ -36,14 +36,15 @@ define(['./FileType'], function (FileType) {
main: 'kml'
});
file_types['KML_GROUND_OVERLAY'] = new FileType({
name: gettext('Google Earth KML with a GroundOverlay'),
format: 'raster',
main: 'kml'
name: gettext('Google Earth KML with a GroundOverlay'),
format: 'raster',
main: 'kml',
aux: ['png', 'gif', 'tiff', 'tif', 'jpg']
});
file_types['KMZ'] = new FileType({
name: gettext('Google Earth KMZ'),
format: 'archive',
main: 'kmz'
name: gettext('Google Earth KMZ'),
format: 'archive',
main: 'kmz'
});
file_types['GEOJSON'] = new FileType({
name: gettext('GeoJSON'),
Expand Down
20 changes: 13 additions & 7 deletions geonode/static/geonode/js/upload/LayerInfo.js
Expand Up @@ -65,10 +65,11 @@ define(function (require, exports) {
*/
LayerInfo.prototype.findFileType = function (file) {
var i, type, res;
var extensions = this.getExtensions();
$.each(fileTypes, function (name, type) {
if (type.isType(file)) {
if (type.isType(file, extensions)) {
res = {type: type, file: file};
return false;
// return false;
}
});
return res;
Expand All @@ -83,14 +84,19 @@ define(function (require, exports) {
var self = this;
$.each(this.files, function (idx, file) {
var results = self.findFileType(file);
// if we find the type of the file, we also find the "main"
// file

// if we find the type of the file, we also find the "main" file
if (results) {
// Avoid assuming the metadata file as main one
if ((results.type.main == 'xml' || results.type.main == 'sld') && self.main != undefined) {
if (results.type.main == 'kml') {
// Assume the kml file always as main one
self.type = results.type;
self.main = results.file;
} else if ((results.type.main == 'xml' || results.type.main == 'sld') &&
self.main != undefined) {
// Do not assume the metadata or sld file as main one
self.type = self.type;
self.main = self.main;
} else {
} else if ((self.type == undefined) || (self.type != undefined && self.type.main != 'kml')) {
self.type = results.type;
self.main = results.file;
}
Expand Down
9 changes: 6 additions & 3 deletions geonode/upload/files.py
Expand Up @@ -233,9 +233,11 @@ def get_scan_hint(valid_extensions):
either vector or raster formats, like the KML type.
"""

if "kml" in valid_extensions and len(valid_extensions) > 1:
result = "kml-overlay"
if "kml" in valid_extensions:
if len(valid_extensions) == 2 and valid_extensions[1] == 'sld':
result = "kml"
else:
result = "kml-overlay"
elif "kmz" in valid_extensions:
result = "kmz"
else:
Expand All @@ -257,6 +259,7 @@ def scan_file(file_name, scan_hint=None):
safe_paths = _rename_files(paths)
else:
safe_paths = []

found = []
for file_type in types:
for path in safe_paths:
Expand Down
4 changes: 3 additions & 1 deletion geonode/upload/upload_preprocessing.py
Expand Up @@ -95,8 +95,10 @@ def preprocess_files(spatial_files):
result = []
for spatial_file in spatial_files:
if spatial_file.file_type == get_type("KML Ground Overlay"):
auxillary_file = spatial_file.auxillary_files[0] if\
len(spatial_file.auxillary_files) > 0 else None
preprocessed = convert_kml_ground_overlay_to_geotiff(
spatial_file.base_file, spatial_file.auxillary_files[0])
spatial_file.base_file, auxillary_file)
result.append(preprocessed)
else:
result.extend(spatial_file.all_files())
Expand Down
6 changes: 3 additions & 3 deletions geonode/upload/upload_validators.py
Expand Up @@ -47,6 +47,7 @@ def _supported_type(ext, supported_types):


def validate_uploaded_files(cleaned, uploaded_files, field_spatial_types):
logger.info("uploaded_files: {}".format(uploaded_files))
requires_datastore = () if ogc_server_settings.DATASTORE else (
'csv',
'kml')
Expand Down Expand Up @@ -145,7 +146,6 @@ def validate_kml(possible_files):
uploaded together with a raster file.
"""

kml_file = [
f for f in possible_files if f.name.lower().endswith(".kml")][0]
other = [
Expand Down Expand Up @@ -199,7 +199,7 @@ def _validate_kml_bytes(kml_bytes, other_files):
if image_path not in other_files:
raise forms.ValidationError(
_("Ground overlay image declared in kml file cannot be found"))
result = ("kml", os.path.splitext(image_path)[-1][1:])
result = ("kml", "sld", os.path.splitext(image_path)[-1][1:])
else:
result = ("kml", )
result = ("kml", "sld", )
return result
3 changes: 2 additions & 1 deletion geonode/upload/views.py
Expand Up @@ -131,7 +131,6 @@ def _select_relevant_files(allowed_extensions, files):
:param files: list of django files with the files to be filtered
"""

result = []
for django_file in files:
extension = os.path.splitext(django_file.name)[-1].lower()[1:]
Expand All @@ -156,10 +155,12 @@ def save_step_view(req, session):
form = LayerUploadForm(req.POST, req.FILES)
if form.is_valid():
tempdir = tempfile.mkdtemp(dir=settings.FILE_UPLOAD_TEMP_DIR)
logger.info("valid_extensions: {}".format(form.cleaned_data["valid_extensions"]))
relevant_files = _select_relevant_files(
form.cleaned_data["valid_extensions"],
req.FILES.itervalues()
)
logger.info("relevant_files: {}".format(relevant_files))
_write_uploaded_files_to_disk(tempdir, relevant_files)
base_file = os.path.join(tempdir, form.cleaned_data["base_file"].name)
name, ext = os.path.splitext(os.path.basename(base_file))
Expand Down

0 comments on commit ddeebf5

Please sign in to comment.