Skip to content

Commit

Permalink
Add dateStamp to map metadata
Browse files Browse the repository at this point in the history
  • Loading branch information
jirik committed Mar 18, 2020
1 parent 77ff6b4 commit 46f86a2
Show file tree
Hide file tree
Showing 8 changed files with 267 additions and 13 deletions.
2 changes: 1 addition & 1 deletion .env.test
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ OAUTH2_LIFERAY_AUTH_URL=http://localhost:8082/o/oauth2/authorize
CSW_URL=http://micka:80/csw
CSW_BASIC_AUTHN=editor:editor
CSW_RECORD_URL=http://localhost:3080/record/basic/{identifier}
CSW_ORGANISATION_NAME_REQUIRED=true
CSW_ORGANISATION_NAME_REQUIRED=


##############################################################################
Expand Down
2 changes: 1 addition & 1 deletion src/layman/layer/rest_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -376,7 +376,7 @@ def test_post_layers_shp(client):
minus_lines = [l for l in diff_lines if l.startswith('- ')]
assert len(minus_lines) == 2
plus_line = plus_lines[0]
assert plus_line == '+ <gco:CharacterString>m81c0debe-b2ea-4829-9b16-581083b29907</gco:CharacterString>\n'
assert plus_line == '+ <gco:CharacterString>m-81c0debe-b2ea-4829-9b16-581083b29907</gco:CharacterString>\n'
minus_line = minus_lines[0]
assert minus_line.startswith('- <gco:CharacterString>m') and minus_line.endswith('</gco:CharacterString>\n')
plus_line = plus_lines[1]
Expand Down
10 changes: 3 additions & 7 deletions src/layman/layer/rest_test_filled_template.xml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<?xml version='1.0' encoding='UTF-8'?>
<gmd:MD_Metadata xmlns:gco="http://www.isotc211.org/2005/gco" xmlns:gmd="http://www.isotc211.org/2005/gmd" xmlns:gmx="http://www.isotc211.org/2005/gmx" xmlns:xlink="http://www.w3.org/1999/xlink" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.isotc211.org/2005/gmd http://schemas.opengis.net/iso/19139/20060504/gmd/metadataEntity.xsd http://www.isotc211.org/2005/gmx http://schemas.opengis.net/iso/19139/20060504/gmx/gmx.xsd">
<gmd:fileIdentifier>
<gco:CharacterString>m81c0debe-b2ea-4829-9b16-581083b29907</gco:CharacterString>
<gco:CharacterString>m-81c0debe-b2ea-4829-9b16-581083b29907</gco:CharacterString>
</gmd:fileIdentifier>
<gmd:language>
<gmd:LanguageCode codeList="http://www.loc.gov/standards/iso639-2/" codeListValue="cze">cze</gmd:LanguageCode>
Expand All @@ -11,9 +11,7 @@
</gmd:hierarchyLevel>
<gmd:contact>
<gmd:CI_ResponsibleParty>
<gmd:organisationName>
<gco:CharacterString>neznámá hodnota</gco:CharacterString>
</gmd:organisationName>
<gmd:organisationName gco:nilReason="unknown" />
<gmd:contactInfo>
<gmd:CI_Contact>
<gmd:address>
Expand Down Expand Up @@ -91,9 +89,7 @@
<gmd:abstract gco:nilReason="unknown" />
<gmd:pointOfContact>
<gmd:CI_ResponsibleParty>
<gmd:organisationName>
<gco:CharacterString>neznámá hodnota</gco:CharacterString>
</gmd:organisationName>
<gmd:organisationName gco:nilReason="unknown" />
<gmd:contactInfo>
<gmd:CI_Contact>
<gmd:address>
Expand Down
7 changes: 6 additions & 1 deletion src/layman/map/micka/csw.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import os
from datetime import datetime
from datetime import datetime, date, timedelta
from xml.sax.saxutils import escape
from layman import settings, patch_mode
from layman.common.filesystem.uuid import get_publication_uuid_file
Expand Down Expand Up @@ -90,6 +90,7 @@ def get_template_path_and_values(username, mapname):
abstract=map_json['abstract'] or None,
date=publ_datetime.strftime('%Y-%m-%d'),
date_type='publication',
date_stamp=date.today().strftime('%Y-%m-%d'),
data_identifier=url_for_external('rest_map.get', username=username, mapname=mapname),
data_identifier_label=mapname,
extent=[float(c) for c in map_json['extent']],
Expand All @@ -111,6 +112,7 @@ def _get_template_values(
data_organisation_name=None,
date='2007-05-25',
date_type='revision',
date_stamp='2007-05-25',
data_identifier='http://www.env.cz/data/liberec/admin-cleneni',
data_identifier_label='Liberec-AdminUnits',
extent=None, # w, s, e, n
Expand Down Expand Up @@ -161,6 +163,9 @@ def _get_template_values(
</gmd:CI_Date>
""",

# date stamp of metadata
'date_stamp': f"""<gco:Date>{date_stamp}</gco:Date>""",

# it must be URI, but text node is optional (MZP-CORINE)
# it can point to Layman's Layer endpoint
'data_identifier': f'<gmx:Anchor xlink:href="{data_identifier}">{escape(data_identifier_label)}</gmx:Anchor>',
Expand Down
2 changes: 1 addition & 1 deletion src/layman/map/micka/record-template.xml
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ xsi:schemaLocation="http://www.isotc211.org/2005/srv http://schemas.opengis.net/
</gmd:CI_ResponsibleParty>
</gmd:contact>

<gmd:dateStamp gco:nilReason="template" />
<gmd:dateStamp>{date_stamp}</gmd:dateStamp>

<gmd:metadataStandardName>
<gco:CharacterString xmlns:gco="http://www.isotc211.org/2005/gco">ISO 19115/INSPIRE_TG2/CZ4</gco:CharacterString>
Expand Down
4 changes: 3 additions & 1 deletion src/layman/map/micka/util_test_filled_template.xml
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,9 @@
</gmd:role>
</gmd:CI_ResponsibleParty>
</gmd:contact>
<gmd:dateStamp gco:nilReason="template" />
<gmd:dateStamp>
<gco:Date>2007-05-25</gco:Date>
</gmd:dateStamp>
<gmd:metadataStandardName>
<gco:CharacterString>ISO 19115/INSPIRE_TG2/CZ4</gco:CharacterString>
</gmd:metadataStandardName>
Expand Down
30 changes: 29 additions & 1 deletion src/layman/map/rest_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import urllib
import time
from multiprocessing import Process
import difflib

import pytest
from flask import url_for
Expand All @@ -11,8 +12,10 @@
del sys.modules['layman']

from . import MAP_TYPE
from .micka import csw
from .filesystem import uuid as map_uuid
from layman import app, settings, uuid
from layman.map.filesystem import uuid as map_uuid
from layman.common.micka import util as micka_common_util


num_maps_before_test = 0
Expand Down Expand Up @@ -222,6 +225,31 @@ def test_post_maps_simple(client):
resp_json = rv.get_json()
assert resp_json['name'] == mapname

# assert metadata file is the same as filled template except for UUID and dates
template_path, template_values = csw.get_template_path_and_values(username, mapname)
xml_file_object = micka_common_util.fill_template_as_pretty_file_object(template_path, template_values)
expected_path = 'src/layman/map/rest_test_filled_template.xml'
with open(expected_path) as f:
expected_lines = f.readlines()
diff_lines = list(difflib.unified_diff(xml_file_object.readlines(), expected_lines))
assert len(diff_lines) == 29, ''.join(diff_lines)
plus_lines = [l for l in diff_lines if l.startswith('+ ')]
assert len(plus_lines) == 3
minus_lines = [l for l in diff_lines if l.startswith('- ')]
assert len(minus_lines) == 3
plus_line = plus_lines[0]
assert plus_line == '+ <gco:CharacterString>m-91147a27-1ff4-4242-ba6d-faffb92224c6</gco:CharacterString>\n'
minus_line = minus_lines[0]
assert minus_line.startswith('- <gco:CharacterString>m') and minus_line.endswith('</gco:CharacterString>\n')
plus_line = plus_lines[1]
assert plus_line == '+ <gco:Date>2007-05-25</gco:Date>\n'
minus_line = minus_lines[1]
assert minus_line.startswith('- <gco:Date>') and minus_line.endswith('</gco:Date>\n')
plus_line = plus_lines[2]
assert plus_line == '+ <gco:Date>2007-05-25</gco:Date>\n'
minus_line = minus_lines[2]
assert minus_line.startswith('- <gco:Date>') and minus_line.endswith('</gco:Date>\n')


def test_post_maps_complex(client):
with app.app_context():
Expand Down
223 changes: 223 additions & 0 deletions src/layman/map/rest_test_filled_template.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,223 @@
<?xml version='1.0' encoding='UTF-8'?>
<gmd:MD_Metadata xmlns:gco="http://www.isotc211.org/2005/gco" xmlns:gmd="http://www.isotc211.org/2005/gmd" xmlns:gmx="http://www.isotc211.org/2005/gmx" xmlns:srv="http://www.isotc211.org/2005/srv" xmlns:xlink="http://www.w3.org/1999/xlink" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.isotc211.org/2005/srv http://schemas.opengis.net/iso/19139/20060504/srv/srv.xsd http://www.isotc211.org/2005/gmx http://schemas.opengis.net/iso/19139/20060504/gmx/gmx.xsd">
<gmd:fileIdentifier>
<gco:CharacterString>m-91147a27-1ff4-4242-ba6d-faffb92224c6</gco:CharacterString>
</gmd:fileIdentifier>
<gmd:language>
<gmd:LanguageCode codeList="http://www.loc.gov/standards/iso639-2/" codeListValue="cze">cze</gmd:LanguageCode>
</gmd:language>
<gmd:hierarchyLevel>
<gmd:MD_ScopeCode codeList="http://standards.iso.org/iso/19139/resources/gmxCodelists.xml#MD_ScopeCode" codeListValue="application">application</gmd:MD_ScopeCode>
</gmd:hierarchyLevel>
<gmd:contact>
<gmd:CI_ResponsibleParty>
<gmd:organisationName gco:nilReason="unknown" />
<gmd:contactInfo>
<gmd:CI_Contact>
<gmd:address>
<gmd:CI_Address>
<gmd:electronicMailAddress gco:nilReason="unknown" />
</gmd:CI_Address>
</gmd:address>
<gmd:onlineResource>
<gmd:CI_OnlineResource>
<gmd:linkage gco:nilReason="unknown" />
</gmd:CI_OnlineResource>
</gmd:onlineResource>
</gmd:CI_Contact>
</gmd:contactInfo>
<gmd:role>
<gmd:CI_RoleCode codeList="http://standards.iso.org/iso/19139/resources/gmxCodelists.xml#CI_RoleCode" codeListValue="pointOfContact">pointOfContact</gmd:CI_RoleCode>
</gmd:role>
</gmd:CI_ResponsibleParty>
</gmd:contact>
<gmd:dateStamp>
<gco:Date>2007-05-25</gco:Date>
</gmd:dateStamp>
<gmd:metadataStandardName>
<gco:CharacterString>ISO 19115/INSPIRE_TG2/CZ4</gco:CharacterString>
</gmd:metadataStandardName>
<gmd:metadataStandardVersion>
<gco:CharacterString>2003/cor.1/2006</gco:CharacterString>
</gmd:metadataStandardVersion>
<gmd:referenceSystemInfo>
<gmd:MD_ReferenceSystem>
<gmd:referenceSystemIdentifier>
<gmd:RS_Identifier>
<gmd:code>
<gmx:Anchor xlink:href="http://www.opengis.net/def/crs/EPSG/0/3857">EPSG:3857</gmx:Anchor>
</gmd:code>
</gmd:RS_Identifier>
</gmd:referenceSystemIdentifier>
</gmd:MD_ReferenceSystem>
</gmd:referenceSystemInfo>
<gmd:identificationInfo>
<srv:SV_ServiceIdentification>
<gmd:citation>
<gmd:CI_Citation>
<gmd:title>
<gco:CharacterString>Administrativní členění Libereckého kraje</gco:CharacterString>
</gmd:title>
<gmd:date>
<gmd:CI_Date>
<gmd:date>
<gco:Date>2007-05-25</gco:Date>
</gmd:date>
<gmd:dateType>
<gmd:CI_DateTypeCode codeList="http://standards.iso.org/iso/19139/resources/gmxCodelists.xml#CI_DateTypeCode" codeListValue="publication">publication</gmd:CI_DateTypeCode>
</gmd:dateType>
</gmd:CI_Date>
</gmd:date>
<gmd:identifier>
<gmd:MD_Identifier>
<gmd:code>
<gmx:Anchor xlink:href="http://layman_test_run_1:8000/rest/testuser1/maps/administrativni_cleneni_libereckeho_kraje">administrativni_cleneni_libereckeho_kraje</gmx:Anchor>
</gmd:code>
</gmd:MD_Identifier>
</gmd:identifier>
<gmd:presentationForm>
<gmd:CI_PresentationFormCode codeList="http://standards.iso.org/iso/19139/resources/gmxCodelists.xml#CI_PresentationFormCode" codeListValue="documentDigital">documentDigital</gmd:CI_PresentationFormCode>
</gmd:presentationForm>
<gmd:presentationForm>
<gmd:CI_PresentationFormCode codeList="http://standards.iso.org/iso/19139/resources/gmxCodelists.xml#CI_PresentationFormCode" codeListValue="mapDigital">mapDigital</gmd:CI_PresentationFormCode>
</gmd:presentationForm>
</gmd:CI_Citation>
</gmd:citation>
<gmd:abstract>
<gco:CharacterString>Na tematické mapě při přiblížení jsou postupně zobrazované administrativní celky Libereckého kraje : okresy, OPÚ, ORP a obce.</gco:CharacterString>
</gmd:abstract>
<gmd:pointOfContact>
<gmd:CI_ResponsibleParty>
<gmd:organisationName gco:nilReason="unknown" />
<gmd:contactInfo>
<gmd:CI_Contact>
<gmd:address>
<gmd:CI_Address>
<gmd:electronicMailAddress gco:nilReason="unknown" />
</gmd:CI_Address>
</gmd:address>
<gmd:onlineResource>
<gmd:CI_OnlineResource>
<gmd:linkage gco:nilReason="unknown" />
</gmd:CI_OnlineResource>
</gmd:onlineResource>
</gmd:CI_Contact>
</gmd:contactInfo>
<gmd:role>
<gmd:CI_RoleCode codeList="http://standards.iso.org/iso/19139/resources/gmxCodelists.xml#CI_RoleCode" codeListValue="custodian">custodian</gmd:CI_RoleCode>
</gmd:role>
</gmd:CI_ResponsibleParty>
</gmd:pointOfContact>
<gmd:graphicOverview>
<gmd:MD_BrowseGraphic>
<gmd:fileName>
<gco:CharacterString>http://layman_test_run_1:8000/rest/testuser1/maps/administrativni_cleneni_libereckeho_kraje/thumbnail</gco:CharacterString>
</gmd:fileName>
<gmd:fileType>
<gco:CharacterString>PNG</gco:CharacterString>
</gmd:fileType>
</gmd:MD_BrowseGraphic>
</gmd:graphicOverview>
<gmd:descriptiveKeywords>
<gmd:MD_Keywords>
<gmd:keyword gco:nilReason="unknown" />
<gmd:thesaurusName>
<gmd:CI_Citation>
<gmd:title>
<gmx:Anchor xlink:href="http://www.eionet.europa.eu/gemet/inspire_themes">GEMET - INSPIRE themes, version 1.0</gmx:Anchor>
</gmd:title>
<gmd:date>
<gmd:CI_Date>
<gmd:date>
<gco:Date>2008-06-01</gco:Date>
</gmd:date>
<gmd:dateType>
<gmd:CI_DateTypeCode codeList="http://standards.iso.org/iso/19139/resources/gmxCodelists.xml#CI_DateTypeCode" codeListValue="publication">publication</gmd:CI_DateTypeCode>
</gmd:dateType>
</gmd:CI_Date>
</gmd:date>
</gmd:CI_Citation>
</gmd:thesaurusName>
</gmd:MD_Keywords>
</gmd:descriptiveKeywords>
<gmd:resourceConstraints>
<gmd:MD_LegalConstraints>
<gmd:accessConstraints>
<gmd:MD_RestrictionCode codeList="http://standards.iso.org/iso/19139/resources/gmxCodelists.xml#MD_RestrictionCode" codeListValue="otherRestrictions">otherRestrictions</gmd:MD_RestrictionCode>
</gmd:accessConstraints>
<gmd:otherConstraints>
<gmx:Anchor xlink:href="http://inspire.ec.europa.eu/metadata-codelist/LimitationsOnPublicAccess/noLimitations">Bez omezení</gmx:Anchor>
</gmd:otherConstraints>
</gmd:MD_LegalConstraints>
</gmd:resourceConstraints>
<gmd:resourceConstraints>
<gmd:MD_LegalConstraints>
<gmd:useConstraints>
<gmd:MD_RestrictionCode codeList="http://standards.iso.org/iso/19139/resources/gmxCodelists.xml#MD_RestrictionCode" codeListValue="otherRestrictions">otherRestrictions</gmd:MD_RestrictionCode>
</gmd:useConstraints>
<gmd:otherConstraints>
<gmx:Anchor xlink:href="http://inspire.ec.europa.eu/metadata-codelist/ConditionsApplyingToAccessAndUse/noConditionsApply">Žádné podmínky neplatí</gmx:Anchor>
</gmd:otherConstraints>
</gmd:MD_LegalConstraints>
</gmd:resourceConstraints>
<srv:serviceType>
<gco:LocalName codeSpace="http://inspire.ec.europa.eu/metadata-codelist/SpatialDataServiceType">Map</gco:LocalName>
</srv:serviceType>
<gmd:language gco:nilReason="unknown" />
<srv:extent>
<gmd:EX_Extent>
<gmd:geographicElement>
<gmd:EX_GeographicBoundingBox>
<gmd:westBoundLongitude>
<gco:Decimal>14.62</gco:Decimal>
</gmd:westBoundLongitude>
<gmd:eastBoundLongitude>
<gco:Decimal>15.42</gco:Decimal>
</gmd:eastBoundLongitude>
<gmd:southBoundLatitude>
<gco:Decimal>50.58</gco:Decimal>
</gmd:southBoundLatitude>
<gmd:northBoundLatitude>
<gco:Decimal>50.82</gco:Decimal>
</gmd:northBoundLatitude>
</gmd:EX_GeographicBoundingBox>
</gmd:geographicElement>
</gmd:EX_Extent>
</srv:extent>
</srv:SV_ServiceIdentification>
</gmd:identificationInfo>
<gmd:distributionInfo>
<gmd:MD_Distribution>
<gmd:transferOptions>
<gmd:MD_DigitalTransferOptions>
<gmd:onLine>
<gmd:CI_OnlineResource>
<gmd:linkage>
<gmd:URL>http://layman_test_run_1:8000/rest/testuser1/maps/administrativni_cleneni_libereckeho_kraje</gmd:URL>
</gmd:linkage>
<gmd:protocol>
<gmx:Anchor xlink:href="https://services.cuzk.cz/registry/codelist/OnlineResourceProtocolValue/WWW:LINK-1.0-http--link">WWW:LINK-1.0-http--link</gmx:Anchor>
</gmd:protocol>
<gmd:function>
<gmd:CI_OnLineFunctionCode codeList="http://standards.iso.org/iso/19139/resources/gmxCodelists.xml#CI_OnLineFunctionCode" codeListValue="information">information</gmd:CI_OnLineFunctionCode>
</gmd:function>
</gmd:CI_OnlineResource>
</gmd:onLine>
<gmd:onLine>
<gmd:CI_OnlineResource>
<gmd:linkage>
<gmd:URL>http://layman_test_run_1:8000/rest/testuser1/maps/administrativni_cleneni_libereckeho_kraje/file</gmd:URL>
</gmd:linkage>
<gmd:protocol>
<gmx:Anchor xlink:href="https://services.cuzk.cz/registry/codelist/OnlineResourceProtocolValue/WWW:LINK-1.0-http--link">WWW:LINK-1.0-http--link</gmx:Anchor>
</gmd:protocol>
<gmd:function>
<gmd:CI_OnLineFunctionCode codeList="http://standards.iso.org/iso/19139/resources/gmxCodelists.xml#CI_OnLineFunctionCode" codeListValue="download">download</gmd:CI_OnLineFunctionCode>
</gmd:function>
</gmd:CI_OnlineResource>
</gmd:onLine>
</gmd:MD_DigitalTransferOptions>
</gmd:transferOptions>
</gmd:MD_Distribution>
</gmd:distributionInfo>
</gmd:MD_Metadata>

0 comments on commit 46f86a2

Please sign in to comment.