Ejemplo n.º 1
0
 def wrapper(*args, **kwargs):
     try:
         if kwargs['map_object'] is None:
             layer = kwargs['layer']
             logging.debug('Getting layer ' + layer)
             kwargs["layer_obj"] = LayerService.get(layer)
         return func(*args, **kwargs)
     except LayerNotFound as e:
         return error(status=404, detail=e.message)
     except Exception as e:
         return error(detail='Generic error')
Ejemplo n.º 2
0
 def wrapper(*args, **kwargs):
     try:
         layer = kwargs['layer']
         logging.debug(
             "get_layer - loading layer {} from LayerService".format(layer))
         kwargs["layer_obj"] = LayerService.get(layer)
         return func(*args, **kwargs)
     except LayerNotFound as e:
         logging.error("get_layer - LayerNotFound - {}".format(e.message))
         return error(status=404, detail=e.message)
     except Exception as e:
         logging.error("get_layer - Exception - {}".format(e.message))
         return error(detail='Generic error')
Ejemplo n.º 3
0
def get_tile(layer, z, x, y, map_object=None, layer_obj=None):
    """Get tile Endpoint"""
    logging.info('[ROUTER]: Get tile')
    logging.info(map_object)
    try:
        if map_object is None:
            logging.debug('Generating mapid')
            layer_config = layer_obj.get('layerConfig')
            style_type = layer_config.get('body').get('styleType')
            image = None
            if 'isImageCollection' not in layer_config or not layer_config.get(
                    'isImageCollection'):
                image = ee.Image(layer_config.get('assetId'))
            else:
                position = layer_config.get('position')
                image_col = ee.ImageCollection(layer_config.get('assetId'))
                if 'filterDates' in layer_config:
                    dates = layer_config.get('filterDates')
                    image_col = image_col.filterDate(dates[0], dates[1])
                if position == 'first':
                    logging.info('Obtaining first')
                    image = ee.Image(
                        image_col.sort('system:time_start', True).first())
                else:
                    logging.info('Obtaining last')
                    image = ee.Image(
                        image_col.sort('system:time_start', False).first())

            if style_type == 'sld':
                style = layer_config.get('body').get('sldValue')
                map_object = image.sldStyle(style).getMapId()
            else:
                map_object = image.getMapId(layer_config.get('body'))

            logging.debug('Saving in cache')
            RedisService.set_layer_mapid(layer, map_object.get('mapid'),
                                         map_object.get('token'))
    except Exception as e:
        logging.error(str(e))
        return error(status=500, detail='Error generating tile: ' + str(e))
    try:
        url = ee.data.getTileUrl(map_object, int(x), int(y), int(z))
        storage_url = StorageService.upload_file(url, layer,
                                                 map_object.get('mapid'), z, x,
                                                 y)
    except Exception as e:
        logging.error(str(e))
        return error(status=404, detail='Tile Not Found')
    return redirect(storage_url)
Ejemplo n.º 4
0
 def wrapper(*args, **kwargs):
     logging.debug("Checking microservice user")
     logged_user = json.loads(request.args.get("loggedUser", '{}'))
     if logged_user.get("id") == "microservice":
         logging.debug("is microservice")
         return func(*args, **kwargs)
     else:
         return error(status=403, detail="Not authorized")
Ejemplo n.º 5
0
 def wrapper(*args, **kwargs):
     logging.debug("Checking microservice user")
     logged_user = request.json.get("loggedUser", None)
     if (logged_user.get("id")
             == "microservice") or (logged_user.get("role") == "ADMIN"):
         logging.debug("is microservice or admin")
         return func(*args, **kwargs)
     else:
         return error(status=403, detail="Not authorized")
Ejemplo n.º 6
0
def internal_server_error(e):
    return error(status=500, detail='Internal Server Error')
Ejemplo n.º 7
0
def gone(e):
    return error(status=410, detail='Gone')
Ejemplo n.º 8
0
def method_not_allowed(e):
    return error(status=405, detail='Method Not Allowed')
Ejemplo n.º 9
0
def page_not_found(e):
    return error(status=404, detail='Not Found (404)')
Ejemplo n.º 10
0
def forbidden(e):
    return error(status=403, detail='Forbidden')