-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
4cb998e
commit 12f4c73
Showing
12 changed files
with
257 additions
and
88 deletions.
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
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 |
---|---|---|
@@ -0,0 +1,78 @@ | ||
from typing import Any | ||
|
||
from geoservercloud.models import EntityModel, ReferencedObjectModel | ||
from geoservercloud.models.styles import Styles | ||
|
||
|
||
class Layer(EntityModel): | ||
def __init__( | ||
self, | ||
name: str, | ||
resource_name: str | None = None, | ||
type: str | None = None, | ||
default_style_name: str | None = None, | ||
styles: list | None = None, | ||
queryable: bool | None = None, | ||
attribution: dict[str, int] | None = None, | ||
) -> None: | ||
self.name: str = name | ||
self.type: str | None = type | ||
self.resource: ReferencedObjectModel | None = None | ||
if resource_name: | ||
self.resource = ReferencedObjectModel(resource_name) | ||
self.default_style: ReferencedObjectModel | None = None | ||
if default_style_name: | ||
self.default_style = ReferencedObjectModel(default_style_name) | ||
self.styles: list | None = styles | ||
self.queryable: bool | None = queryable | ||
self.attribution: dict[str, Any] | None = attribution | ||
|
||
@property | ||
def resource_name(self) -> str | None: | ||
return self.resource.name if self.resource else None | ||
|
||
@property | ||
def default_style_name(self) -> str | None: | ||
return self.default_style.name if self.default_style else None | ||
|
||
@classmethod | ||
def from_get_response_payload(cls, content: dict): | ||
layer = content["layer"] | ||
if layer.get("styles"): | ||
styles = Styles.from_get_response_payload(layer).aslist() | ||
else: | ||
styles = None | ||
return cls( | ||
name=layer["name"], | ||
resource_name=layer["resource"]["name"], | ||
type=layer["type"], | ||
default_style_name=layer["defaultStyle"]["name"], | ||
styles=styles, | ||
attribution=layer["attribution"], | ||
queryable=layer.get("queryable"), | ||
) | ||
|
||
def asdict(self) -> dict[str, Any]: | ||
content: dict[str, Any] = {"name": self.name} | ||
if self.styles is not None: | ||
content.update(Styles(self.styles).post_payload()) | ||
optional_items = { | ||
"name": self.name, | ||
"type": self.type, | ||
"resource": self.resource_name, | ||
"defaultStyle": self.default_style_name, | ||
"attribution": self.attribution, | ||
"queryable": self.queryable, | ||
} | ||
return EntityModel.add_items_to_dict(content, optional_items) | ||
|
||
def post_payload(self) -> dict[str, dict[str, Any]]: | ||
content = self.asdict() | ||
if self.resource: | ||
content["resource"] = self.resource.asdict() | ||
if self.default_style: | ||
content["defaultStyle"] = self.default_style.asdict() | ||
return {"layer": content} | ||
|
||
def put_payload(self) -> dict[str, dict[str, Any]]: | ||
return self.post_payload() |
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 |
---|---|---|
@@ -0,0 +1,78 @@ | ||
from geoservercloud.models.layer import Layer | ||
|
||
|
||
def test_layer_post_payload(): | ||
layer = Layer( | ||
name="test_point", | ||
resource_name="test_workspace:test_point", | ||
type="VECTOR", | ||
default_style_name="point", | ||
styles=["burg", "capitals"], | ||
queryable=True, | ||
attribution={"logoWidth": 0, "logoHeight": 0}, | ||
) | ||
|
||
content = layer.post_payload() | ||
|
||
assert content == { | ||
"layer": { | ||
"name": "test_point", | ||
"type": "VECTOR", | ||
"defaultStyle": {"name": "point"}, | ||
"styles": { | ||
"style": [ | ||
{"name": "burg"}, | ||
{"name": "capitals"}, | ||
], | ||
}, | ||
"resource": { | ||
"name": "test_workspace:test_point", | ||
}, | ||
"queryable": True, | ||
"attribution": {"logoWidth": 0, "logoHeight": 0}, | ||
} | ||
} | ||
|
||
|
||
def test_from_get_response_payload(): | ||
content = { | ||
"layer": { | ||
"name": "test_point", | ||
"type": "VECTOR", | ||
"defaultStyle": { | ||
"name": "point", | ||
"href": "http://localhost:9099/geoserver/rest/styles/point.json", | ||
}, | ||
"styles": { | ||
"@class": "linked-hash-set", | ||
"style": [ | ||
{ | ||
"name": "burg", | ||
"href": "http://localhost:9099/geoserver/rest/styles/burg.json", | ||
}, | ||
{ | ||
"name": "capitals", | ||
"href": "http://localhost:9099/geoserver/rest/styles/capitals.json", | ||
}, | ||
], | ||
}, | ||
"resource": { | ||
"@class": "featureType", | ||
"name": "test_workspace:test_point", | ||
"href": "http://localhost:9099/geoserver/rest/workspaces/elden/datastores/elden/featuretypes/test_point.json", | ||
}, | ||
"attribution": {"logoWidth": 0, "logoHeight": 0}, | ||
"dateCreated": "2024-11-06 10:16:07.328 UTC", | ||
"dateModified": "2024-11-06 14:48:09.460 UTC", | ||
} | ||
} | ||
|
||
layer = Layer.from_get_response_payload(content) | ||
|
||
assert layer.name == "test_point" | ||
assert layer.resource_name == "test_workspace:test_point" | ||
assert layer.type == "VECTOR" | ||
assert layer.default_style_name == "point" | ||
assert layer.styles == ["burg", "capitals"] | ||
assert layer.attribution == {"logoWidth": 0, "logoHeight": 0} | ||
assert layer.queryable is None |
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
Oops, something went wrong.