Exemplo n.º 1
0
def callback_to_dataset(body):
    config = {
        'uri': '/dataset/' + request.get_json().get('connector').get('id'),
        'method': 'PATCH',
        'body': body
    }
    return request_to_microservice(config)
Exemplo n.º 2
0
    def execute(config):
        response = request_to_microservice(config)
        if not response or response.get('errors'):
            raise LayerNotFound(message='Layer not found')

        layer = response.get('data', None).get('attributes', None)
        return layer
Exemplo n.º 3
0
def query_microservice(uri):
    config_alerts = {'uri': uri, 'method': 'GET'}

    response = request_to_microservice(config_alerts)

    if response.get('errors'):
        raise Error(**response['errors'][0])

    else:
        return response
Exemplo n.º 4
0
 def execute(config):
     try:
         response = request_to_microservice(config)
         if not response or response.get('errors'):
             raise GeostoreNotFound
         geostore = response.get('data', None).get('attributes', None)
         geojson = geostore.get('geojson', None)
         bbox = geostore.get('bbox', None)
     except Exception as e:
         raise GeostoreNotFound(message=str(e))
     return geojson, bbox
Exemplo n.º 5
0
def getDataset(indicator, scenario, temporal_res):
    logging.info('[NEXGDDP-ROUTER] Get info of indicator')
    datasets = request_to_microservice({
        'uri':
        '/dataset?includes=layer&tableName=' + indicator + '/' + scenario +
        '_' + temporal_res + '&env=' + request.args.get("env", 'production'),
        'method':
        'GET'
    })
    if datasets.get('data') and len(datasets.get('data')) > 0:
        return jsonify({"data": datasets.get('data')[0]}), 200
    return jsonify(
        {"errors": [{
            "status": 404,
            "detail": "Dataset doesn't exist"
        }]}), 404
Exemplo n.º 6
0
    def convert(query):
        logging.info('Converting Query: ' + query)
        try:
            config = {'uri': '/convert/sql2SQL?sql=' + query, 'method': 'GET'}
            response = request_to_microservice(config)
        except Exception as error:
            raise error

        if response.get('errors'):
            errors = response.get('errors')
            raise SqlFormatError(message=errors[0].get('detail'))

        query = response.get('data', None)
        s_query = query.get('attributes', {}).get('query')
        json_sql = query.get('attributes', {}).get('jsonSql')
        return s_query, json_sql
Exemplo n.º 7
0
    def execute(config):
        try:
            response = request_to_microservice(config)
        except Exception as e:
            raise Exception(str(e))
        if response.get('errors'):
            error = response.get('errors')[0]
            if error.get('status') == 404:
                raise GeostoreNotFound(message='')
            else:
                raise Exception(error.get('detail'))

        geostore = response.get('data', None).get('attributes', None)
        geojson = geostore.get('geojson', None)
        area_ha = geostore.get('areaHa', None)

        return geojson, area_ha
Exemplo n.º 8
0
def query_microservice(sql, analysis_type):

    if analysis_type == 'glad':
        dataset_id = os.getenv('GLAD_DATASET_ID')
    elif analysis_type == 'fires':
        dataset_id = os.getenv('FIRES_DATASET_ID')
    else:
        raise Error('unknown analyis type: {}'.format(analysis_type))

    config = {
        'uri': '/query/{}?sql={}'.format(dataset_id, sql),
        'method': 'GET',
    }

    response = request_to_microservice(config)

    if response.get('errors'):
        raise Error(**response['errors'][0])

    else:
        return response
Exemplo n.º 9
0
 def execute(config):
     response = request_to_microservice(config)
     if not response or response.get('errors'):
         raise DatasetNotFound(message='Dataset not found')
     dataset = response.get('data', None).get('attributes', None)
     return dataset