2626
2727from jsonschema .validators import Draft202012Validator
2828from owslib .ogcapi .records import Records
29+ from pygeoapi .process .base import BaseProcessor , ProcessorExecuteError
30+ from pygeometa .schemas .ogcapi_records import OGCAPIRecordOutputSchema
2931import requests
32+ import yaml
33+
34+ from registration_api .parsers .cwl import from_cwl
3035
31- from pygeoapi .process .base import BaseProcessor , ProcessorExecuteError
3236
3337LOGGER = logging .getLogger (__name__ )
3438
@@ -248,6 +252,7 @@ def execute(self, data: dict, outputs: dict = None) -> tuple:
248252
249253 self .auth = None
250254 mimetype = 'application/json'
255+ resource_mimetype = 'application/geo+json'
251256
252257 LOGGER .debug ('Validating request payload against schema' )
253258 validation_errors = validate_json (REGISTER_SCHEMA , data )
@@ -266,7 +271,13 @@ def execute(self, data: dict, outputs: dict = None) -> tuple:
266271
267272 if 'href' in source :
268273 LOGGER .debug ('Source is a URL' )
269- content = requests .get (source ['href' ]).json ()
274+ try :
275+ content = requests .get (source ['href' ]).json ()
276+ except json .decoder .JSONDecodeError as err :
277+ LOGGER .debug (f'Error parsing JSON: { err } ' )
278+ LOGGER .debug ('Attempting YAML parsing' )
279+ content = yaml .safe_load (requests .get (source ['href' ]).text )
280+
270281 LOGGER .debug ('Performing source validation' )
271282 validation_errors = validate_json (
272283 REGISTER_SCHEMA ['properties' ]['source' ]['properties' ]['oneOf' ][0 ]['content' ], # noqa
@@ -282,6 +293,12 @@ def execute(self, data: dict, outputs: dict = None) -> tuple:
282293 LOGGER .error (f'{ msg } : { content } ' )
283294 raise ProcessorExecuteError (msg )
284295
296+ if 'cwlVersion' in content :
297+ LOGGER .debug ('Parsing CWL' )
298+ content = from_cwl (content , url = source .get ('href' ))
299+ content = OGCAPIRecordOutputSchema ().write (
300+ content , stringify = False )
301+
285302 for stac_extension in content .get ('stac_extensions' , []):
286303 LOGGER .debug (f'Validating against STAC Extension { stac_extension } ' )
287304 stac_extension_schema = requests .get (stac_extension )
@@ -373,12 +390,13 @@ def execute(self, data: dict, outputs: dict = None) -> tuple:
373390 url = f"{ target ['href' ]} /collections/{ collection } /items/{ id_ } "
374391 elif source ['rel' ] == 'collection' :
375392 url = f"{ target ['href' ]} /collections/{ collection } "
393+ resource_mimetype = 'application/json'
376394 produced_outputs = {
377395 'id' : PROCESS_REGISTER_METADATA ['id' ],
378396 'resource-and-data-catalogue-link' : {
379397 'href' : url ,
380398 'rel' : 'item' ,
381- 'type' : 'application/geo+json'
399+ 'type' : resource_mimetype
382400 }
383401 }
384402
@@ -504,6 +522,8 @@ def validate_json(schema: dict, instance: dict) -> list:
504522
505523 validation_errors = []
506524 LOGGER .debug ('Validating input against schema' )
525+ LOGGER .debug (f'Input: { instance } ' )
526+ LOGGER .debug (f'Schema: { schema } ' )
507527 validator = Draft202012Validator (schema )
508528
509529 for error in validator .iter_errors (instance ):
0 commit comments