-
Notifications
You must be signed in to change notification settings - Fork 46
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
UI metadata and server needed to query the background #2263
Merged
Merged
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -57,7 +57,7 @@ | |
from c2cgeoportal.lib.wmstparsing import parse_extent, TimeInformation | ||
from c2cgeoportal.lib.email_ import send_email | ||
from c2cgeoportal.models import DBSession, User, Role, \ | ||
Theme, LayerGroup, RestrictionArea, Interface, \ | ||
Theme, LayerGroup, RestrictionArea, Interface, ServerOGC, \ | ||
Layer, LayerV1, LayerWMS, LayerWMTS, FullTextSearch | ||
|
||
|
||
|
@@ -237,7 +237,7 @@ def _get_child_layers_info(self, layer): | |
if hasattr(layer, "queryable") else True | ||
return layer_info | ||
|
||
def _layer(self, layer, wms, wms_layers, time, role_id): | ||
def _layer(self, layer, wms, wms_layers, time, role_id, mixed=True): | ||
errors = set() | ||
l = { | ||
"id": layer.id, | ||
|
@@ -284,7 +284,7 @@ def _layer(self, layer, wms, wms_layers, time, role_id): | |
return None, errors | ||
l["type"] = "WMS" | ||
l["layers"] = layer.layer | ||
if not self._fill_wms(l, layer, errors, role_id): | ||
if not self._fill_wms(l, layer, errors, role_id, mixed=mixed): | ||
return None, errors | ||
errors |= self._merge_time(time, l, layer, wms, wms_layers) | ||
|
||
|
@@ -336,7 +336,7 @@ def _fill_editable(self, l, layer): | |
if c > 0: | ||
l["editable"] = True | ||
|
||
def _fill_wms(self, l, layer, errors, role_id): | ||
def _fill_wms(self, l, layer, errors, role_id, mixed): | ||
wms, wms_layers = self._wms_layers(role_id, layer.server_ogc) | ||
|
||
l["imageType"] = layer.server_ogc.image_type | ||
|
@@ -383,6 +383,9 @@ def _fill_wms(self, l, layer, errors, role_id): | |
if len(max_resolutions_hint) > 0: | ||
l["maxResolutionHint"] = max(max_resolutions_hint) | ||
|
||
if mixed: | ||
l["serverOGC"] = layer.server_ogc.name | ||
# deprecated | ||
l["url"] = get_url( | ||
layer.server_ogc.url, self.request, | ||
default=self.request.route_url("mapserverproxy"), errors=errors) | ||
|
@@ -393,6 +396,7 @@ def _fill_wms(self, l, layer, errors, role_id): | |
layer.server_ogc.url_wfs, self.request, | ||
default=l["url"], errors=errors) | ||
l["serverType"] = layer.server_ogc.type | ||
# end deprecated | ||
|
||
return True | ||
|
||
|
@@ -562,28 +566,31 @@ def _is_internal_wms(self, layer): | |
return \ | ||
isinstance(layer, LayerV1) and layer.layer_type == "internal WMS" | ||
|
||
def _get_layer_identifiers(self, group): | ||
"""Recurse on all children to get unique identifier for each child.""" | ||
identifier = [] | ||
def _get_ogc_servers(self, group, depth=1): | ||
""" Recurse on all children to get unique identifier for each child. """ | ||
ogc_servers = set() | ||
|
||
# escape loop | ||
if depth > 30: | ||
log.error("Error: too many recursions with group '%s'" % group.name) | ||
return ogc_servers | ||
|
||
# recurse on children | ||
if isinstance(group, LayerGroup) and group.children > 0: | ||
for tree_item in group.children: | ||
child_identifier = self._get_layer_identifiers(tree_item) | ||
identifier = identifier + child_identifier | ||
ogc_servers.update(self._get_ogc_servers(tree_item, depth=depth + 1)) | ||
|
||
if isinstance(group, LayerWMS): | ||
identifier.append(group.server_ogc_id) | ||
ogc_servers.add(group.server_ogc) | ||
|
||
if isinstance(group, LayerWMTS): | ||
# add 2 different values to force the mixed state | ||
identifier = identifier + ["wmts1", "wmts2"] | ||
ogc_servers.add(False) | ||
|
||
return identifier | ||
return ogc_servers | ||
|
||
def _group( | ||
self, path, group, layers, depth=1, min_levels=1, | ||
catalogue=True, role_id=None, version=1, **kwargs | ||
catalogue=True, role_id=None, version=1, mixed=True, **kwargs | ||
): | ||
children = [] | ||
errors = set() | ||
|
@@ -595,6 +602,13 @@ def _group( | |
) | ||
return None, errors | ||
|
||
ogc_servers = None | ||
org_depth = depth | ||
if depth == 1: | ||
ogc_servers = list(self._get_ogc_servers(group)) | ||
# check if mixed content | ||
mixed = len(ogc_servers) != 1 or ogc_servers[0] is False | ||
|
||
for tree_item in group.children: | ||
if type(tree_item) == LayerGroup: | ||
depth += 1 | ||
|
@@ -603,7 +617,7 @@ def _group( | |
gp, gp_errors = self._group( | ||
"%s/%s" % (path, tree_item.name), | ||
tree_item, layers, depth=depth, min_levels=min_levels, | ||
catalogue=catalogue, role_id=role_id, version=version, **kwargs | ||
catalogue=catalogue, role_id=role_id, version=version, mixed=mixed, **kwargs | ||
) | ||
errors |= gp_errors | ||
if gp is not None: | ||
|
@@ -619,7 +633,7 @@ def _group( | |
(isinstance(tree_item, LayerV1) and group.is_internal_wms == | ||
self._is_internal_wms(tree_item))): | ||
|
||
l, l_errors = self._layer(tree_item, role_id=role_id, **kwargs) | ||
l, l_errors = self._layer(tree_item, role_id=role_id, mixed=mixed, **kwargs) | ||
errors |= l_errors | ||
if l is not None: | ||
if depth < min_levels: | ||
|
@@ -640,7 +654,6 @@ def _group( | |
"name": group.name, | ||
"children": children, | ||
"metadata": {}, | ||
"mixed": False, | ||
} | ||
if version == 1: | ||
g.update({ | ||
|
@@ -649,11 +662,10 @@ def _group( | |
"isBaseLayer": group.is_base_layer, | ||
}) | ||
else: | ||
# check if mixed content | ||
identifier = self._get_layer_identifiers(group) | ||
# Use set() to remove duplicates | ||
if len(set(identifier)) > 1: | ||
g["mixed"] = True | ||
if org_depth == 1: | ||
g["mixed"] = mixed | ||
if not mixed: | ||
g["serverOGC"] = ogc_servers[0].name | ||
|
||
for metadata in group.ui_metadatas: | ||
g["metadata"][metadata.name] = get_url(metadata.value, self.request, errors=errors) | ||
|
@@ -1305,6 +1317,27 @@ def themes(self): | |
|
||
result = {} | ||
all_errors = set() | ||
if version == 2: | ||
|
||
result["serversOGC"] = {} | ||
for server_ogc in DBSession.query(ServerOGC).all(): | ||
url = get_url( | ||
server_ogc.url, self.request, | ||
default=self.request.route_url("mapserverproxy"), errors=all_errors | ||
) | ||
url_wfs = get_url( | ||
server_ogc.url_wfs, self.request, | ||
default=url, errors=all_errors | ||
) | ||
result["serversOGC"][server_ogc.name] = { | ||
"url": url, | ||
"urlWfs": url_wfs, | ||
"type": server_ogc.type, | ||
"imageType": server_ogc.image_type, | ||
"auth": server_ogc.auth, | ||
"wtsSupport": server_ogc.wfs_support, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This should be There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. oups, thanks :-) |
||
"isSingleTile": server_ogc.is_single_tile, | ||
} | ||
if export_themes: | ||
themes, errors = self._themes( | ||
role_id, interface, True, version, catalogue, min_levels | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
forgotten debug statement