Skip to content

Commit

Permalink
Post metadata record if no one found during patch
Browse files Browse the repository at this point in the history
Fix #52
  • Loading branch information
jirik committed Mar 30, 2020
1 parent c6d609f commit 1785e37
Show file tree
Hide file tree
Showing 6 changed files with 83 additions and 2 deletions.
7 changes: 7 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,12 @@
# Changelog


## v1.3.1
2020-03-30
- Post metadata record if no one found during patch, fix #52
- Use EPSG:3857 bbox when generating thumbnail, fix #53


## v1.3.0
2020-03-29
### Upgrade requirements
Expand Down
6 changes: 4 additions & 2 deletions src/layman/common/micka/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -534,5 +534,7 @@ def adjust_operates_on(prop_el, prop_value):
def get_record_element_by_id(csw, id):
csw.getrecordbyid(id=[id], esn='full', outputschema=NAMESPACES['gmd'])
xml = csw._exml
el = xml.xpath('//gmd:MD_Metadata', namespaces=NAMESPACES)[0]
return el
els = xml.xpath(f"//gmd:MD_Metadata[gmd:fileIdentifier/gco:CharacterString/text() = '{id}']", namespaces=NAMESPACES)
# current_app.logger.info(f"Number of md records id={id}: {len(els)}")
result = els[0] if len(els) > 0 else None
return result
4 changes: 4 additions & 0 deletions src/layman/layer/micka/csw.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,8 @@ def update_layer(username, layername, layerinfo):
return {}
muuid = get_metadata_uuid(uuid)
el = common_util.get_record_element_by_id(csw, muuid)
if el is None:
return csw_insert(username, layername)
# current_app.logger.info(f"Current element=\n{ET.tostring(el, encoding='unicode', pretty_print=True)}")

_, prop_values = get_template_path_and_values(username, layername, http_method='patch')
Expand Down Expand Up @@ -340,6 +342,8 @@ def get_metadata_comparison(username, layername):
return {}
muuid = get_metadata_uuid(uuid)
el = common_util.get_record_element_by_id(csw, muuid)
if el is None:
return

# current_app.logger.info(f"xml\n{ET.tostring(el)}")

Expand Down
32 changes: 32 additions & 0 deletions src/layman/layer/micka/csw_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,31 @@ def provide_layer(client):
assert rv.status_code == 200


def patch_layer(client):
with app.app_context():
username = TEST_USER
layername = TEST_LAYER
rest_path = url_for('rest_layer.patch', username=username, layername=layername)
file_paths = [
'tmp/naturalearth/110m/cultural/ne_110m_admin_0_countries.geojson',
]
for fp in file_paths:
assert os.path.isfile(fp)
files = []
try:
files = [(open(fp, 'rb'), os.path.basename(fp)) for fp in file_paths]
rv = client.patch(rest_path, data={
'file': files,
'title': 'patched layer',
})
assert rv.status_code == 200
finally:
for fp in files:
fp[0].close()

wait_till_ready(username, layername)


@pytest.fixture(scope="module")
def broken_micka():
server = create_server(MICKA_PORT)
Expand Down Expand Up @@ -163,3 +188,10 @@ def test_delete_layer_no_micka():
with app.app_context():
delete_layer(TEST_USER, TEST_LAYER)
assert exc_info.value.code == 38


@pytest.mark.usefixtures('provide_layer')
def test_patch_layer_without_metadata(client):
with app.app_context():
delete_layer(TEST_USER, TEST_LAYER)
patch_layer(client)
4 changes: 4 additions & 0 deletions src/layman/map/micka/csw.py
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,8 @@ def patch_map(username, mapname, metadata_properties_to_refresh=None):
return {}
muuid = get_metadata_uuid(uuid)
el = common_util.get_record_element_by_id(csw, muuid)
if el is None:
return csw_insert(username, mapname)
# current_app.logger.info(f"Current element=\n{ET.tostring(el, encoding='unicode', pretty_print=True)}")

_, prop_values = get_template_path_and_values(username, mapname, http_method='patch')
Expand Down Expand Up @@ -404,6 +406,8 @@ def get_metadata_comparison(username, mapname):
return {}
muuid = get_metadata_uuid(uuid)
el = common_util.get_record_element_by_id(csw, muuid)
if el is None:
return

# current_app.logger.info(f"xml\n{ET.tostring(el)}")

Expand Down
32 changes: 32 additions & 0 deletions src/layman/map/micka/csw_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,31 @@ def provide_map(client):
assert rv.status_code == 200


def patch_map(client):
with app.app_context():
username = TEST_USER
mapname = TEST_MAP
rest_path = url_for('rest_map.patch', username=username, mapname=mapname)
file_paths = [
'sample/layman.map/full.json',
]
for fp in file_paths:
assert os.path.isfile(fp)
files = []
try:
files = [(open(fp, 'rb'), os.path.basename(fp)) for fp in file_paths]
rv = client.patch(rest_path, data={
'file': files,
'title': 'patched map',
})
assert rv.status_code == 200
finally:
for fp in files:
fp[0].close()

wait_till_ready(username, mapname)


@pytest.fixture(scope="module")
def broken_micka():
server = create_server(MICKA_PORT)
Expand Down Expand Up @@ -163,3 +188,10 @@ def test_delete_map_no_micka():
with app.app_context():
delete_map(TEST_USER, TEST_MAP)
assert exc_info.value.code == 38


@pytest.mark.usefixtures('provide_map')
def test_patch_map_without_metadata(client):
with app.app_context():
delete_map(TEST_USER, TEST_MAP)
patch_map(client)

0 comments on commit 1785e37

Please sign in to comment.