From 7398ddeeef63e9af0618dcd063ccc4f0dbc2bcf4 Mon Sep 17 00:00:00 2001 From: Tom Kralidis Date: Sun, 19 Feb 2023 01:55:32 -0500 Subject: [PATCH 1/3] improve ISO contact parsing (#210) --- pygeometa/schemas/iso19139/__init__.py | 62 ++++++++++++++------------ 1 file changed, 33 insertions(+), 29 deletions(-) diff --git a/pygeometa/schemas/iso19139/__init__.py b/pygeometa/schemas/iso19139/__init__.py index 47e4198..e48fe96 100644 --- a/pygeometa/schemas/iso19139/__init__.py +++ b/pygeometa/schemas/iso19139/__init__.py @@ -99,58 +99,62 @@ def import_(self, metadata: str) -> dict: mcf['metadata']['hierarchylevel'] = m.hierarchy mcf['metadata']['datestamp'] = m.datestamp + LOGGER.debug('Setting language') + if m.language: + mcf['metadata']['language'] = m.language + elif m.languagecode: + mcf['metadata']['language'] = m.languagecode + + identification = m.identificationinfo[0] + LOGGER.debug('Setting identification') - mcf['identification']['title'] = m.identification.title - mcf['identification']['abstract'] = m.identification.abstract + mcf['identification']['title'] = identification.title + mcf['identification']['abstract'] = identification.abstract - if m.identification.date: + if identification.date: mcf['identification']['dates'] = {} - for date_ in m.identification.date: + for date_ in identification.date: mcf['identification']['dates'][date_.type] = date_.date - if m.identification.keywords2: + if identification.keywords: mcf['identification']['keywords'] = {} - for count, value in enumerate(m.identification.keywords2): + for count, value in enumerate(identification.keywords): key = f'keywords-{count}' mcf['identification']['keywords'][key] = { 'type': value.type, - 'keywords': value.keywords + 'keywords': [k.name for k in value.keywords] } - mcf['identification']['topiccategory'] = m.identification.topiccategory # noqa + mcf['identification']['topiccategory'] = identification.topiccategory # noqa mcf['identification']['extents'] = { 'spatial': [{ 'bbox': [ - ast.literal_eval(m.identification.extent.boundingBox.minx), - ast.literal_eval(m.identification.extent.boundingBox.miny), - ast.literal_eval(m.identification.extent.boundingBox.maxx), - ast.literal_eval(m.identification.extent.boundingBox.maxy) + ast.literal_eval(identification.extent.boundingBox.minx), + ast.literal_eval(identification.extent.boundingBox.miny), + ast.literal_eval(identification.extent.boundingBox.maxx), + ast.literal_eval(identification.extent.boundingBox.maxy) ] }], 'temporal': [] } temp_extent = {} - if m.identification.temporalextent_start: - temp_extent['begin'] = m.identification.temporalextent_start - if m.identification.temporalextent_end: - temp_extent['end'] = m.identification.temporalextent_end + if identification.temporalextent_start: + temp_extent['begin'] = identification.temporalextent_start + if identification.temporalextent_end: + temp_extent['end'] = identification.temporalextent_end mcf['identification']['extents']['temporal'].append(temp_extent) - if m.identification.accessconstraints: - mcf['identification']['accessconstraints'] = m.identification.accessconstraints[0] # noqa - - mcf['identification']['status'] = m.identification.status + if identification.accessconstraints: + mcf['identification']['accessconstraints'] = identification.accessconstraints[0] # noqa - LOGGER.debug('Setting contact') - if m.contact: - for c in m.contact: - mcf['contact'].update(get_contact(c)) + mcf['identification']['status'] = identification.status - if m.distribution.distributor: - for d in m.distribution.distributor: - mcf['contact'].update(get_contact(d.contact)) + LOGGER.debug('Setting contacts') +# for contact in m.get_all_contacts(): +# mcf['contact'].update(get_contact(contact)) + mcf['contact'].update(get_contact(m.contact[0])) LOGGER.debug('Setting distribution') if m.distribution: @@ -173,8 +177,8 @@ def get_contact(contact: CI_ResponsibleParty) -> dict: mcf_contact = {contact.role: {}} cm_lookup = { + 'name': 'name', 'organization': 'organization', - 'individualname': 'name', 'positionname': 'position', 'phone': 'phone', 'fax': 'fax', @@ -187,7 +191,7 @@ def get_contact(contact: CI_ResponsibleParty) -> dict: } for key, value in cm_lookup.items(): - if hasattr(contact, value): + if getattr(contact, value) is not None: mcf_contact[contact.role][key] = getattr(contact, value) if hasattr(contact.onlineresource, 'url'): From 07622c1503574845aaee21e4fa8a8d524847a934 Mon Sep 17 00:00:00 2001 From: Tom Kralidis Date: Sun, 19 Feb 2023 01:56:11 -0500 Subject: [PATCH 2/3] improve OARec contact serialization (#210) --- pygeometa/schemas/ogcapi_records/__init__.py | 21 ++++++++++---------- 1 file changed, 11 insertions(+), 10 deletions(-) diff --git a/pygeometa/schemas/ogcapi_records/__init__.py b/pygeometa/schemas/ogcapi_records/__init__.py index 3287e46..5f6791f 100644 --- a/pygeometa/schemas/ogcapi_records/__init__.py +++ b/pygeometa/schemas/ogcapi_records/__init__.py @@ -244,16 +244,20 @@ def generate_responsible_party(self, contact: dict, country = get_charstring(contact.get('country'), self.lang1, self.lang2) - rp = { - 'name': organization_name[0], - 'individual': contact['individualname'], + rp = {} + + if organization_name[0] == contact.get('organization'): + LOGGER.debug('Contact name is organization') + rp['name'] = organization_name[0] + + rp.update({ 'positionName': position_name[0], 'contactInfo': { 'phone': { - 'office': contact['phone'] + 'office': contact.get('phone') }, 'email': { - 'office': contact['fax'] + 'office': contact.get('email') }, 'address': { 'office': { @@ -262,10 +266,7 @@ def generate_responsible_party(self, contact: dict, 'administrativeArea': administrative_area[0], 'postalCode': postalcode[0], 'country': country[0] - }, - 'onlineResource': { - 'href': contact['url'] - }, + } }, 'hoursOfService': hours_of_service[0], 'contactInstructions': contact_instructions[0] @@ -273,7 +274,7 @@ def generate_responsible_party(self, contact: dict, 'roles': [{ 'name': role }] - } + }) if 'url' in contact: rp['contactInfo']['url'] = { From 9315c9e0e1af3f6a8627453ce9927be33ac976a0 Mon Sep 17 00:00:00 2001 From: Tom Kralidis Date: Mon, 20 Feb 2023 06:25:12 -0500 Subject: [PATCH 3/3] pin to OWSLib master for CI --- .github/workflows/main.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 2433bfd..dc7f5ff 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -21,6 +21,7 @@ jobs: python3 -m pip install --upgrade pip pip3 install "pyproj < 3.3.0" pip3 install -r requirements-dev.txt + pip3 install -U https://github.com/geopython/OWSLib/archive/master.zip - name: Install package 📦 run: python3 setup.py install - name: run tests ⚙️