def get_protected_layers(role_id, ogc_server_ids): q = get_protected_layers_query(role_id, ogc_server_ids, what=LayerWMS, version=2) results = q.all() DBSession.expunge_all() return {r.id: r for r in results}
def _create_layer_query(self, role_id): """ Create an SQLAlchemy query for Layer and for the role identified to by ``role_id``. """ q = DBSession.query(Layer).filter(Layer.public == True) # NOQA if role_id: q = q.union(get_protected_layers_query(role_id)) return q
def _create_layer_query(self, role_id): """ Create an SQLAlchemy query for Layer and for the role identified to by ``role_id``. """ q = DBSession.query(Layer).filter(Layer.public == True) # NOQA if role_id: q = q.union(get_protected_layers_query(role_id)) return q
def _wfs_types(self, wfs_url, role_id=None): errors = [] # retrieve layers metadata via GetCapabilities params = ( ('SERVICE', 'WFS'), ('VERSION', '1.0.0'), ('REQUEST', 'GetCapabilities'), ) if wfs_url.find('?') < 0: wfs_url += '?' wfsgc_url = wfs_url + '&'.join(['='.join(p) for p in params]) if role_id: q = get_protected_layers_query(role_id) for layer in q.all(): wfsgc_url += '&s_enable_' + str(layer.name) + '=*' log.info("WFS GetCapabilities for base url: %s" % wfsgc_url) # forward request to target (without Host Header) http = httplib2.Http() h = dict(self.request.headers) if urlparse(wfsgc_url).hostname != 'localhost': # pragma: no cover h.pop('Host') try: resp, getCapabilities_xml = http.request(wfsgc_url, method='GET', headers=h) except: # pragma: no cover errors.append("Unable to GetCapabilities from url %s" % wfsgc_url) return None, errors if resp.status < 200 or resp.status >= 300: # pragma: no cover errors.append( "GetCapabilities from url %s return the error: %i %s" % (wfsgc_url, resp.status, resp.reason)) return None, errors try: getCapabilities_dom = parseString(getCapabilities_xml) featuretypes = [] for featureType in getCapabilities_dom.getElementsByTagNameNS( self.WFS_NS, "FeatureType"): # don't includes FeatureType without name name = featureType.getElementsByTagNameNS(self.WFS_NS, "Name").item(0) if name: nameValue = name.childNodes[0].data # ignore namespace if nameValue.find(':') >= 0: nameValue = nameValue.split(':')[1] # pragma nocover featuretypes.append(nameValue) else: # pragma nocover log.warn("Feature type without name: %s" % featureType.toxml()) return featuretypes, errors except: # pragma: no cover return getCapabilities_xml, errors
def _wms_getcap(self, url, role_id=None): errors = [] wms = None params = ( ('SERVICE', 'WMS'), ('VERSION', '1.1.1'), ('REQUEST', 'GetCapabilities'), ) if url.find('?') < 0: url += '?' url = url + '&'.join(['='.join(p) for p in params]) if role_id: q = get_protected_layers_query(role_id) for layer in q.all(): url += '&s_enable_' + str(layer.name) + '=*' log.info("WMS GetCapabilities for base url: %s" % url) # forward request to target (without Host Header) http = httplib2.Http() h = dict(self.request.headers) if urlparse(url).hostname != 'localhost': # pragma: no cover h.pop('Host') try: resp, content = http.request(url, method='GET', headers=h) except: # pragma: no cover errors.append("Unable to GetCapabilities from url %s" % url) return None, errors if resp.status < 200 or resp.status >= 300: # pragma: no cover errors.append( "GetCapabilities from url %s return the error: %i %s" % (url, resp.status, resp.reason) ) return None, errors try: wms = WebMapService(None, xml=content) except AttributeError: error = _( "WARNING! an error occured while trying to " "read the mapfile and recover the themes." ) error = "%s\nurl: %s\nxml:\n%s" % (error, url, content) errors.append(error) log.exception(error) return wms, errors
def _wms_getcap(self, url, role_id=None): errors = [] wms = None params = ( ('SERVICE', 'WMS'), ('VERSION', '1.1.1'), ('REQUEST', 'GetCapabilities'), ) if url.find('?') < 0: url += '?' url = url + '&'.join(['='.join(p) for p in params]) if role_id: q = get_protected_layers_query(role_id) for layer in q.all(): url += '&s_enable_' + str(layer.name) + '=*' log.info("WMS GetCapabilities for base url: %s" % url) # forward request to target (without Host Header) http = httplib2.Http() h = dict(self.request.headers) if urlparse(url).hostname != 'localhost': # pragma: no cover h.pop('Host') try: resp, content = http.request(url, method='GET', headers=h) except: # pragma: no cover errors.append("Unable to GetCapabilities from url %s" % url) return None, errors if resp.status < 200 or resp.status >= 300: # pragma: no cover errors.append( "GetCapabilities from url %s return the error: %i %s" % (url, resp.status, resp.reason)) return None, errors try: wms = WebMapService(None, xml=content) except AttributeError: error = _("WARNING! an error occured while trying to " "read the mapfile and recover the themes.") error = "%s\nurl: %s\nxml:\n%s" % (error, url, content) errors.append(error) log.exception(error) return wms, errors
def _create_layer_query(self, role_id, version): """ Create an SQLAlchemy query for Layer and for the role identified to by ``role_id``. """ if version == 1: q = DBSession.query(LayerV1) else: q = DBSession.query(Layer).with_polymorphic( [LayerInternalWMS, LayerExternalWMS, LayerWMTS] ) q = q.filter(Layer.public.is_(True)) if role_id is not None: q = q.union(get_protected_layers_query(role_id, version=version)) return q
def get_protected_layers(role_id): q = get_protected_layers_query(role_id, distinct(Layer.name)) return [r for r, in q.all()]
def _get_protected_layers(self, role_id): from c2cgeoportal.models import Layer q = get_protected_layers_query(role_id, Layer.name) return [r for r, in q.all()]
def _get_protected_layers(self, role_id): from c2cgeoportal.models import Layer q = get_protected_layers_query(role_id, Layer.name) return [r for r, in q.all()]