Skip to content

Commit 57263bc

Browse files
authored
update ISO/WCMP2/OARec import/export (#228)
1 parent adb2037 commit 57263bc

File tree

3 files changed

+50
-29
lines changed

3 files changed

+50
-29
lines changed

pygeometa/schemas/iso19139/__init__.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -146,7 +146,11 @@ def import_(self, metadata: str) -> dict:
146146
'temporal': []
147147
}
148148

149-
temp_extent = {}
149+
temp_extent = {
150+
'begin': None,
151+
'end': None
152+
}
153+
150154
if identification.temporalextent_start:
151155
temp_extent['begin'] = identification.temporalextent_start
152156
if identification.temporalextent_end:

pygeometa/schemas/ogcapi_records/__init__.py

Lines changed: 44 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@
4343
#
4444
# =================================================================
4545

46+
from datetime import datetime
4647
import json
4748
import logging
4849
import os
@@ -140,9 +141,12 @@ def write(self, mcf: dict, stringify: str = True) -> Union[dict, str]:
140141
else:
141142
end = str(end)
142143

143-
record['time'] = {
144-
'interval': [begin, end]
145-
}
144+
if [begin, end] == [None, None]:
145+
record['time'] = None
146+
else:
147+
record['time'] = {
148+
'interval': [begin, end]
149+
}
146150

147151
if 'resolution' in mcf['identification']['extents']['temporal'][0]: # noqa
148152
record['time']['resolution'] = mcf['identification']['extents']['temporal'][0]['resolution'] # noqa
@@ -153,10 +157,12 @@ def write(self, mcf: dict, stringify: str = True) -> Union[dict, str]:
153157
record['properties']['created'] = str(mcf['identification']['dates']['creation']) # noqa
154158
if 'revision' in mcf['identification']['dates']:
155159
record['properties']['updated'] = str(mcf['identification']['dates']['revision']) # noqa
156-
157160
if 'publication' in mcf['identification']['dates']:
158161
record['properties']['updated'] = normalize_datestring(mcf['identification']['dates']['publication']) # noqa
159162

163+
if record['properties'].get('created') is None:
164+
record['properties']['created'] = datetime.now().strftime('%Y-%m-%dT%H:%M:%SZ') # noqa
165+
160166
rights = get_charstring(mcf['identification'].get('rights'),
161167
self.lang1, self.lang2)
162168

@@ -260,31 +266,40 @@ def generate_party(self, contact: dict,
260266
country = get_charstring(contact.get('country'),
261267
self.lang1, self.lang2)
262268

263-
rp = {}
269+
rp = {
270+
'addresses': [{}],
271+
'roles': []
272+
}
264273

265274
if organization_name[0] == contact.get('organization'):
266275
LOGGER.debug('Contact name is organization')
267276
rp['name'] = organization_name[0]
268277

269-
rp.update({
270-
'positionName': position_name[0],
271-
'phones': [{
272-
'value': contact.get('phone')
273-
}],
274-
'emails': [{
275-
'value': contact.get('email')
276-
}],
277-
'addresses': [{
278-
'deliveryPoint': [address[0]],
279-
'city': city[0],
280-
'administrativeArea': administrative_area[0],
281-
'postalCode': postalcode[0],
282-
'country': country[0]
283-
}],
284-
'hoursOfService': hours_of_service[0],
285-
'contactInstructions': contact_instructions[0],
286-
'roles': []
287-
})
278+
if position_name[0] is not None:
279+
rp['positionName'] = position_name[0]
280+
if hours_of_service[0] is not None:
281+
rp['positionName'] = hours_of_service[0]
282+
if contact_instructions[0] is not None:
283+
rp['contactInstructions'] = contact_instructions[0]
284+
285+
if address[0] is not None:
286+
rp['addresses'][0]['deliveryPoint'] = [address[0]]
287+
if city[0] is not None:
288+
rp['addresses'][0]['city'] = city[0]
289+
if administrative_area[0] is not None:
290+
rp['addresses'][0]['administrativeArea'] = administrative_area[0]
291+
if postalcode[0] is not None:
292+
rp['addresses'][0]['postalCode'] = postalcode[0]
293+
if country[0] is not None:
294+
rp['addresses'][0]['country'] = country[0]
295+
296+
if contact.get('phone') is not None:
297+
rp['phones'] = [{'value': contact.get('phone')}]
298+
if contact.get('email') is not None:
299+
rp['emails'] = [{'value': contact.get('email')}]
300+
301+
if rp['addresses'][0] == {}:
302+
rp.pop('addresses')
288303

289304
for r in set(roles):
290305
rp['roles'].append(r)
@@ -350,13 +365,15 @@ def generate_link(self, distribution: dict) -> dict:
350365

351366
name = get_charstring(distribution.get('name'), self.lang1, self.lang2)
352367

353-
reltype = distribution.get('rel') or distribution.get('function')
354-
355368
link = {
356-
'rel': reltype,
357369
'href': distribution['url'],
358370
'type': distribution['type']
359371
}
372+
373+
reltype = distribution.get('rel') or distribution.get('function')
374+
if reltype is not None:
375+
link['rel'] = reltype
376+
360377
if title != [None, None]:
361378
link['title'] = title[0]
362379
elif name != [None, None]:

pygeometa/schemas/wmo_wcmp2/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ def write(self, mcf: dict, stringify: str = True) -> Union[dict, str]:
8888
record = super().write(mcf, stringify=False)
8989

9090
LOGGER.debug('Setting WCMP2 conformance')
91-
record['conformsTo'] = ['http://wis.wmo.int/spec/wcmp/2.0']
91+
record['conformsTo'] = ['http://wis.wmo.int/spec/wcmp/2/conf/core']
9292

9393
if 'edition' in mcf['identification']:
9494
record['properties']['version'] = mcf['identification']['version']

0 commit comments

Comments
 (0)