Beispiel #1
0
def forwards_func(apps, schema_editor):
    from geonode.services.enumerations import WMS, GN_WMS
    from geonode.harvesting.harvesters.wms import WebMapService
    from geonode.services.serviceprocessors.wms import WmsServiceHandler
    MyModel = apps.get_model('services', 'Service')
    _services_with_empty_params = MyModel.objects.filter(
        models.Q(type__in=(WMS, GN_WMS))
        & (models.Q(extra_queryparams__isnull=True)
           | models.Q(extra_queryparams__exact='')))
    for _service in _services_with_empty_params:
        try:
            operations = {}
            cleaned_url, service, version, request = WmsServiceHandler.get_cleaned_url_params(
                _service.base_url)
            try:
                logger.error(f" -- parsing service URL: {_service.base_url}")
                _url, _parsed_service = WebMapService(_service.base_url,
                                                      version=version,
                                                      proxy_base=None)
                for _op in _parsed_service.operations:
                    _methods = []
                    for _op_method in (getattr(_op, 'methods', []) if hasattr(
                            _op, 'methods') else _op.get('methods', [])):
                        _methods.append({
                            'type': _op_method.get('type', None),
                            'url': _op_method.get('url', None)
                        })

                    _name = getattr(_op, 'name', None) if hasattr(
                        _op, 'name') else _op.get('name', None)
                    _formatOptions = getattr(
                        _op, 'formatOptions', []) if hasattr(
                            _op, 'formatOptions') else _op.get(
                                'formatOptions', [])
                    if _name:
                        operations[_name] = {
                            'name': _name,
                            'methods': _methods,
                            'formatOptions': _formatOptions
                        }
            except Exception:
                logger.error(
                    f"It was not possible to parse the GetCapabilities document for the Service: {_service.name}. 'operations' won't be stored!"
                )
            MyModel.objects.filter(id=_service.id).update(
                base_url=
                f"{cleaned_url.scheme}://{cleaned_url.netloc}{cleaned_url.path}"
                .encode("utf-8", "ignore").decode('utf-8'),
                extra_queryparams=cleaned_url.query,
                operations=operations)
        except Exception:
            logger.error(
                f"There were errors migrating the Service: {_service.name}. 'extra_queryparams' won't be stored!"
            )
Beispiel #2
0
 def parsed_service(self):
     cleaned_url, service, version, request = WmsServiceHandler.get_cleaned_url_params(self.url)
     _url, _parsed_service = WebMapService(
         cleaned_url.geturl(),
         version=version)
     return _parsed_service