-
Notifications
You must be signed in to change notification settings - Fork 16
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
* [Fixes #201] Refactor metadata common and add SLD handler * Fix SLD file handler and black formatting
- Loading branch information
1 parent
e29c70e
commit b2b038c
Showing
27 changed files
with
243 additions
and
91 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -20,7 +20,7 @@ | |
|
||
project_dir = os.path.dirname(os.path.abspath(__file__)) | ||
|
||
VERSION = (1, 0, 7) | ||
VERSION = (1, 0, 8) | ||
__version__ = ".".join([str(i) for i in VERSION]) | ||
__author__ = "geosolutions-it" | ||
__email__ = "[email protected]" | ||
|
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
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
Empty file.
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,9 @@ | ||
from rest_framework.exceptions import APIException | ||
from rest_framework import status | ||
|
||
|
||
class InvalidSldException(APIException): | ||
status_code = status.HTTP_400_BAD_REQUEST | ||
default_detail = "The sld provided is invalid" | ||
default_code = "invalid_sld" | ||
category = "importer" |
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,62 @@ | ||
import logging | ||
|
||
from geonode.resource.manager import resource_manager | ||
from importer.handlers.common.metadata import MetadataFileHandler | ||
from importer.handlers.sld.exceptions import InvalidSldException | ||
from owslib.etree import etree as dlxml | ||
|
||
logger = logging.getLogger(__name__) | ||
|
||
|
||
class SLDFileHandler(MetadataFileHandler): | ||
""" | ||
Handler to import SLD files into GeoNode data db | ||
It must provide the task_lists required to comple the upload | ||
""" | ||
|
||
@staticmethod | ||
def can_handle(_data) -> bool: | ||
""" | ||
This endpoint will return True or False if with the info provided | ||
the handler is able to handle the file or not | ||
""" | ||
base = _data.get("base_file") | ||
if not base: | ||
return False | ||
return ( | ||
base.endswith(".sld") | ||
if isinstance(base, str) | ||
else base.name.endswith(".sld") | ||
) | ||
|
||
@staticmethod | ||
def is_valid(files, user): | ||
""" | ||
Define basic validation steps | ||
""" | ||
# calling base validation checks | ||
|
||
try: | ||
with open(files.get("base_file")) as _xml: | ||
dlxml.fromstring(_xml.read().encode()) | ||
except Exception as err: | ||
raise InvalidSldException( | ||
f"Uploaded document is not SLD or is invalid: {str(err)}" | ||
) | ||
return True | ||
|
||
def handle_metadata_resource(self, _exec, dataset, original_handler): | ||
if original_handler.can_handle_sld_file: | ||
original_handler.handle_sld_file(dataset, _exec) | ||
else: | ||
_path = _exec.input_params.get("files", {}).get( | ||
"sld_file", _exec.input_params.get("base_file", {}) | ||
) | ||
resource_manager.exec( | ||
"set_style", | ||
None, | ||
instance=dataset, | ||
sld_file=_exec.input_params.get("files", {}).get("sld_file", ""), | ||
sld_uploaded=True if _path else False, | ||
vals={"dirty_state": True}, | ||
) |
Oops, something went wrong.