|
| 1 | +# -*- coding: utf-8 -*- |
| 2 | +""" |
| 3 | +/*************************************************************************** |
| 4 | + QgisShogunEditor |
| 5 | + ------------------- |
| 6 | + begin : 2025-09 |
| 7 | + git sha : $Format:%H$ |
| 8 | + copyright : (C) 2025 by terrestris |
| 9 | + email : info@terrestris.de |
| 10 | + ***************************************************************************/ |
| 11 | +
|
| 12 | +/*************************************************************************** |
| 13 | + * * |
| 14 | + * This program is free software; you can redistribute it and/or modify * |
| 15 | + * it under the terms of the GNU General Public License as published by * |
| 16 | + * the Free Software Foundation; either version 2 of the License, or * |
| 17 | + * (at your option) any later version. * |
| 18 | + * * |
| 19 | + ***************************************************************************/ |
| 20 | +""" |
| 21 | +import graphene |
| 22 | +import requests |
| 23 | + |
| 24 | + |
| 25 | +class ApplicationType(graphene.ObjectType): |
| 26 | + id = graphene.ID() |
| 27 | + name = graphene.String() |
| 28 | + description = graphene.String() |
| 29 | + layerTree = graphene.JSONString() |
| 30 | + |
| 31 | +class Query(graphene.ObjectType): |
| 32 | + applications = graphene.List(ApplicationType) |
| 33 | + |
| 34 | + def resolve_applications(self, info): |
| 35 | + # You may want to parameterize the endpoint URL, here it's hardcoded for demo purposes |
| 36 | + shogun_url = info.context.get('shogun_url', '') |
| 37 | + if not shogun_url: |
| 38 | + return [] |
| 39 | + |
| 40 | + # Build the applications URL (same logic as check_url_for_applications) |
| 41 | + if shogun_url.endswith('applications'): |
| 42 | + applications_url = shogun_url |
| 43 | + elif shogun_url.endswith('application'): |
| 44 | + applications_url = shogun_url + 's' |
| 45 | + elif shogun_url.endswith('/'): |
| 46 | + applications_url = shogun_url + 'applications' |
| 47 | + else: |
| 48 | + applications_url = shogun_url + '/applications' |
| 49 | + |
| 50 | + # Use requests to fetch (or replace with QGIS networking if needed) |
| 51 | + try: |
| 52 | + response = requests.get(applications_url, verify=False) # TODO: ssl verification handling |
| 53 | + if response.status_code == 200: |
| 54 | + applications_json = response.json() |
| 55 | + content = applications_json.get('content', []) |
| 56 | + return [ |
| 57 | + ApplicationType( |
| 58 | + id=app.get('id'), |
| 59 | + name=app.get('name'), |
| 60 | + description=app.get('description'), |
| 61 | + layerTree=app.get('layerTree') |
| 62 | + ) |
| 63 | + for app in content |
| 64 | + ] |
| 65 | + except Exception as e: |
| 66 | + print(f"Error fetching applications: {e}") |
| 67 | + return [] |
| 68 | + |
| 69 | +schema = graphene.Schema(query=Query) |
0 commit comments