Skip to content

Commit

Permalink
Implement POST layer with .zip file
Browse files Browse the repository at this point in the history
  • Loading branch information
index-git committed Oct 20, 2021
1 parent 1bc7d27 commit 7b61410
Show file tree
Hide file tree
Showing 4 changed files with 41 additions and 4 deletions.
Binary file added sample/layman.layer/small_layer.zip
Binary file not shown.
2 changes: 1 addition & 1 deletion src/layman/layer/db/tasks.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ def refresh_table(
if self.is_aborted():
raise AbortedException

main_filepath = get_layer_main_file_path(workspace, layername)
main_filepath = get_layer_main_file_path(workspace, layername, gdal_format=True)
process = db.import_layer_vector_file_async(workspace, layername, main_filepath, crs_id)
while process.poll() is None and not self.is_aborted():
pass
Expand Down
17 changes: 14 additions & 3 deletions src/layman/layer/rest_workspace_layers.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
from layman.authz import authorize_workspace_publications_decorator
from layman.common import redis as redis_util, rest as rest_common
from . import util, LAYER_TYPE, LAYER_REST_PATH_NAME
from .filesystem import input_file, input_style, input_chunk, uuid
from .filesystem import input_file, input_style, input_chunk, uuid, util as fs_util

bp = Blueprint('rest_workspace_layers', __name__)

Expand Down Expand Up @@ -41,12 +41,15 @@ def post(workspace):

# FILE
use_chunk_upload = False
zipped_file = None
files = []
if 'file' in request.files:
files = [
f for f in request.files.getlist("file")
if len(f.filename) > 0
]
if len(files) == 1 and input_file.get_compressed_main_file_extension(files[0].filename):
zipped_file = files[0]
if len(files) == 0 and len(request.form.getlist('file')) > 0:
files = [
filename for filename in request.form.getlist('file')
Expand Down Expand Up @@ -79,6 +82,8 @@ def post(workspace):
# FILE NAMES
if use_chunk_upload:
filenames = files
elif zipped_file:
filenames = fs_util.get_filenames_from_zip_storage(zipped_file)
else:
filenames = [f.filename for f in files]
file_type = input_file.get_file_type(input_file.get_main_file_name(filenames))
Expand Down Expand Up @@ -153,8 +158,14 @@ def post(workspace):
})
else:
try:
input_file.save_layer_files(
workspace, layername, files, check_crs)
if zipped_file:
input_file.save_layer_zip_file(
workspace, layername, zipped_file,
)
else:
input_file.save_layer_files(
workspace, layername, files, check_crs
)
except BaseException as exc:
uuid.delete_layer(workspace, layername)
input_file.delete_layer(workspace, layername)
Expand Down
26 changes: 26 additions & 0 deletions tests/dynamic_data/publications.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,4 +37,30 @@
],
},
],
Publication(consts.COMMON_WORKSPACE, consts.LAYER_TYPE, 'zipped_sld'): [
{
consts.KEY_ACTION: {
consts.KEY_CALL: Action(process_client.publish_workspace_publication, {
'file_paths': ['sample/layman.layer/small_layer.zip'],
}),
consts.KEY_RESPONSE_ASSERTS: [
Action(processing.response.valid_post, dict()),
],
},
consts.KEY_FINAL_ASSERTS: [
*publication.IS_LAYER_COMPLETE_AND_CONSISTENT,
Action(publication.internal.correct_values_in_detail, {
'exp_publication_detail': {
**predefined_infos.BASIC_SLD_LAYER,
'_file': {
'path': '/layman_data_test/workspaces/dynamic_test_workspace/layers/zipped_sld/input_file/zipped_sld.zip/small_layer.geojson'
},
'file': {
'path': 'layers/zipped_sld/input_file/zipped_sld.zip/small_layer.geojson'
},
},
}),
],
},
]
}

0 comments on commit 7b61410

Please sign in to comment.