Skip to content
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

[Fixes #29] Obtain layer default style with original format #30

Merged
merged 1 commit into from
Feb 21, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 14 additions & 6 deletions src/geoserver/layer.py
Original file line number Diff line number Diff line change
Expand Up @@ -143,16 +143,16 @@ def resource(self):
_resources = self.catalog.get_resources(names=[name], stores=[store_name], workspaces=[ws_name])
return _resources[0] if len(_resources) > 0 else _resources

def _get_default_style(self):
def _get_default_style(self, recursive=False):
if 'default_style' in self.dirty:
return self.dirty['default_style']
if self.dom is None:
self.fetch()
element = self.dom.find("defaultStyle")
# aborted data uploads can result in no default style
return self._resolve_style(element) if element is not None else None
return self._resolve_style(element, recursive) if element is not None else None

def _resolve_style(self, element):
def _resolve_style(self, element, recursive=False):
if ":" in element.find('name').text:
ws_name, style_name = element.find('name').text.split(':')
else:
Expand All @@ -161,20 +161,20 @@ def _resolve_style(self, element):
atom_link = [n for n in element if 'href' in n.attrib]
if atom_link and ws_name is None:
ws_name = workspace_from_url(atom_link[0].get("href"))
return self.catalog.get_styles(names=style_name, workspaces=ws_name)[0]
return self.catalog.get_styles(names=style_name, workspaces=ws_name, recursive=recursive)[0]

def _set_default_style(self, style):
if isinstance(style, Style):
style = style.fqn
self.dirty["default_style"] = style

def _get_alternate_styles(self):
def _get_alternate_styles(self, recursive=False):
if "alternate_styles" in self.dirty:
return self.dirty["alternate_styles"]
if self.dom is None:
self.fetch()
styles_list = self.dom.findall("styles/style")
return [self._resolve_style(s) for s in styles_list]
return [self._resolve_style(s, recursive) for s in styles_list]

def _set_alternate_styles(self, styles):
self.dirty["alternate_styles"] = styles
Expand All @@ -187,6 +187,14 @@ def _set_alternate_styles(self, styles):
advertised = xml_property("advertised", lambda x: x.text == "true", default=True)
type = xml_property("type")

# obtains uncached default style with original format (recursive retrieval)
def get_full_default_style(self):
return self._get_default_style(True)

# obtains uncached alternate styles with original format (recursive retrieval)
def get_full_styles(self):
return self._get_alternate_styles(True)

def _get_attr_attribution(self):
obj = {
'title': self.attribution_object.title,
Expand Down