|
16 | 16 | # along with this program. If not, see <http://www.gnu.org/licenses/>.
|
17 | 17 | #
|
18 | 18 | #########################################################################
|
| 19 | +import logging |
19 | 20 |
|
20 |
| -from .handler import get_service_handler # noqa |
| 21 | +from collections import OrderedDict |
| 22 | +from django.utils.translation import ugettext as _ |
| 23 | + |
| 24 | +from geonode.services import enumerations |
| 25 | +from geonode.services.utils import parse_services_types |
| 26 | + |
| 27 | +logger = logging.getLogger(__name__) |
| 28 | + |
| 29 | + |
| 30 | +def get_available_service_types(): |
| 31 | + # LGTM: Fixes - Module uses member of cyclically imported module, which can lead to failure at import time. |
| 32 | + from geonode.services.serviceprocessors.wms import GeoNodeServiceHandler, WmsServiceHandler |
| 33 | + from geonode.services.serviceprocessors.arcgis import ArcImageServiceHandler, ArcMapServiceHandler |
| 34 | + |
| 35 | + default = OrderedDict({ |
| 36 | + enumerations.WMS: {"OWS": True, "handler": WmsServiceHandler, "label": _('Web Map Service')}, |
| 37 | + enumerations.GN_WMS: {"OWS": True, "handler": GeoNodeServiceHandler, "label": _('GeoNode (Web Map Service)')}, |
| 38 | + # enumerations.WFS: {"OWS": True, "handler": ServiceHandlerBase, "label": _('Paired WMS/WFS/WCS'}, |
| 39 | + # enumerations.TMS: {"OWS": False, "handler": ServiceHandlerBase, "label": _('Paired WMS/WFS/WCS'}, |
| 40 | + enumerations.REST_MAP: {"OWS": False, "handler": ArcMapServiceHandler, "label": _('ArcGIS REST MapServer')}, |
| 41 | + enumerations.REST_IMG: {"OWS": False, "handler": ArcImageServiceHandler, "label": _('ArcGIS REST ImageServer')}, |
| 42 | + # enumerations.CSW: {"OWS": False, "handler": ServiceHandlerBase, "label": _('Catalogue Service')}, |
| 43 | + # enumerations.OGP: {"OWS": True, "handler": ServiceHandlerBase, "label": _('OpenGeoPortal')}, # TODO: verify this |
| 44 | + # enumerations.HGL: {"OWS": False, "handler": ServiceHandlerBase, "label": _('Harvard Geospatial Library')}, # TODO: verify this |
| 45 | + }) |
| 46 | + |
| 47 | + return OrderedDict({**default, **parse_services_types()}) |
| 48 | + |
| 49 | + |
| 50 | +def get_service_handler(base_url, service_type=enumerations.AUTO, service_id=None): |
| 51 | + """Return the appropriate remote service handler for the input URL. |
| 52 | + If the service type is not explicitly passed in it will be guessed from |
| 53 | + """ |
| 54 | + handlers = get_available_service_types() |
| 55 | + |
| 56 | + handler = handlers.get(service_type, {}).get("handler") |
| 57 | + try: |
| 58 | + service = handler(base_url, service_id) |
| 59 | + except Exception: |
| 60 | + logger.exception( |
| 61 | + msg=f"Could not parse service {base_url}") |
| 62 | + raise |
| 63 | + return service |
0 commit comments