Ejemplo n.º 1
0
 def setUp(self):
     self.app = create_app('tests.config')
     self.db_name = self.app.config['ARANGO_DB']
     with self.app.app_context():
         self.db_inst = DB()
         self._cleanup()
         self.db_inst.get_database()
Ejemplo n.º 2
0
def list_collections(kind, page, per_page):
    """Return all collections or edges from Database"""

    db_inst = DB()
    db_inst.get_database()
    data = [[{
        'field': 'kind',
        'operator': '==',
        'value': kind,
    }]]
    cursor = db_inst.search_in_collection(
        config.META_COLLECTION, data, page, per_page)

    total_pages = int(math.ceil(cursor.statistics()[
                      'fullCount'] / (per_page * 1.0)))
    total_collections = cursor.statistics()['fullCount']

    collections = util.filter_collections(cursor)
    res = {
        'total_pages': total_pages,
        'total': len(collections),
        'total_collections': total_collections,
        'collections': collections
    }

    return res
Ejemplo n.º 3
0
def search_collections(collections, data, page, per_page):
    """Search in Database"""

    spec = app.config['SPECS'].get('search')
    util.json_validate(spec).validate(data)

    db_inst = DB()

    db_inst.get_database()
    cursor = db_inst.search_in_collections(collections, data, page, per_page)

    total_pages = int(math.ceil(cursor.statistics()[
                      'fullCount'] / (per_page * 1.0)))
    total_documents = cursor.statistics()['fullCount']

    docs = [doc for doc in cursor]

    res = {
        'total_pages': total_pages,
        'total': len(docs),
        'total_documents': total_documents,
        'documents': docs
    }

    return res
Ejemplo n.º 4
0
def search_traversal(**kwargs):
    """Search Traversal in Database"""

    db_inst = DB()
    db_inst.get_database()
    graph = db_inst.get_graph(kwargs.get('graph_name'))

    traversal_results = graph.traverse(
        start_vertex=kwargs.get('start_vertex'),
        direction=kwargs.get('direction'),
        item_order=kwargs.get('item_order'),
        strategy=kwargs.get('strategy'),
        order=kwargs.get('order'),
        edge_uniqueness=kwargs.get('edge_uniqueness'),
        vertex_uniqueness=kwargs.get('vertex_uniqueness'),
        max_iter=kwargs.get('max_iter'),
        min_depth=kwargs.get('min_depth'),
        max_depth=kwargs.get('max_depth'),
        init_func=kwargs.get('init_func'),
        sort_func=kwargs.get('sort_func'),
        filter_func=kwargs.get('filter_func'),
        visitor_func=kwargs.get('visitor_func'),
        expander_func=kwargs.get('expander_func')
    )

    traversal_results = util.filter_transversal(traversal_results)
    traversal_results.update({'graph': kwargs.get('graph_name')})

    return traversal_results
Ejemplo n.º 5
0
def cleanup():
    app = create_app('tests.config')
    db_inst = DB(app.config)
    db_name = app.config['ARANGO_DB']
    db_inst.conn_database(db_name)
    for col in db_inst.database.collections():
        if 'meta' not in col['name'] and col['system'] is False:
            db_inst.database.delete_collection(col['name'])
    db_inst.database.collection('meta_collection').truncate()
Ejemplo n.º 6
0
def list_graphs():
    """Return all graph from Database"""

    db_inst = DB()
    db_inst.get_database()
    graphs = db_inst.database.graphs()
    graphs = util.filter_graphs(graphs)

    return graphs
Ejemplo n.º 7
0
def clear_collection(name, data):
    """Clear document in Collection"""

    db_inst = DB()

    db_inst.get_database()
    db_inst.clear_collection(name, data)

    return {}
Ejemplo n.º 8
0
def list_collections(kind):
    """Return all collections or edges from Database"""

    db_inst = DB()
    db_inst.get_database()
    collections = db_inst.database.collections()
    collections = util.filter_collections(collections, kind)

    return collections
Ejemplo n.º 9
0
    def setUp(self):
        self.app = create_app('tests.config')
        self.db_inst = DB(self.app.config)

        self.conn_db()
        self.cleanup()
        self.db_inst.database.create_database('test')

        self.db_inst.conn_database('test')
Ejemplo n.º 10
0
def search_document(name, field, value, offset=0, count=100):
    """Search in Database"""

    db_inst = DB()
    db_inst.get_database()
    cursor = db_inst.search_in_database(
        name, field, value, offset, count)
    docs = [doc for doc in cursor]

    return docs
Ejemplo n.º 11
0
def execute_query(key, variable):
    query = get_query(key)
    query['params']['variable'] = variable

    db_inst = DB()

    db_inst.get_database()
    cursor = db_inst.execute_aql(query['query'], query['params'])

    docs = [doc for doc in cursor]

    return docs
Ejemplo n.º 12
0
def search_traversal(**kwargs):
    """Search Traversal in Database"""

    db_inst = DB()
    db_inst.get_database()
    graph = db_inst.get_graph(kwargs.get('graph_name'))
    try:
        traversal_results = graph.traverse(
            start_vertex=kwargs.get('start_vertex'),
            direction=kwargs.get('direction'),
            item_order=kwargs.get('item_order'),
            strategy=kwargs.get('strategy'),
            order=kwargs.get('order'),
            edge_uniqueness=kwargs.get('edge_uniqueness'),
            vertex_uniqueness=kwargs.get('vertex_uniqueness'),
            max_iter=kwargs.get('max_iter'),
            min_depth=kwargs.get('min_depth'),
            max_depth=kwargs.get('max_depth'),
            init_func=kwargs.get('init_func'),
            sort_func=kwargs.get('sort_func'),
            filter_func=kwargs.get('filter_func'),
            visitor_func=kwargs.get('visitor_func'),
            expander_func=kwargs.get('expander_func')
        )
    except GraphTraverseError as err:

        if traverse_err.get(err.error_code):
            if err.error_code == 1202:
                msg = traverse_err.get(1202)
                raise gmap_exceptions.GraphTraverseException(msg)
            raise gmap_exceptions.GraphTraverseException(
                traverse_err.get(err.error_code).format(err.message))

        else:
            raise gmap_exceptions.GraphTraverseException(
                traverse_err.get(0).format(
                    kwargs.get('graph_name'), err.message))

    except Exception as err:
        raise gmap_exceptions.GraphTraverseException(
            traverse_err.get(0).format(kwargs.get('graph_name'), err.message))

    traversal_results = util.filter_transversal(traversal_results)
    traversal_results.update({'graph': kwargs.get('graph_name')})

    return traversal_results
Ejemplo n.º 13
0
def list_deps():
    deps = {
        'arango': {}
    }
    try:
        db = DB()
        db.get_database()
        graphs = facade.list_graphs()
        collections = facade.list_collections('document')
        edges = facade.list_collections('edge')
    except:
        deps['arango']['status'] = False
    else:
        deps['arango']['status'] = True
        deps['arango']['graphs'] = graphs
        deps['arango']['collections'] = collections
        deps['arango']['edges'] = edges

    return deps
Ejemplo n.º 14
0
def make_query(data):
    """Validate query and make document"""

    query = data
    key = 'query_{}'.format(data.get('name'))
    query = {
        '_key': key,
        'name': data.get('name'),
        'description': data['description'],
        'query': data['query'],
        'params': data.get('params'),
        'collection': data.get('collection')
    }

    db_inst = DB()
    db_inst.get_database()
    db_inst.validate_aql(data['query'])

    return query
Ejemplo n.º 15
0
def _is_arango_ok():
    try:
        db = DB()
        db.get_database()
        graphs = facade.list_graphs()
        collections = facade.list_collections('document')
        edges = facade.list_collections('edge')
    except:
        app.logger.error('Failed to healthcheck arango.')
        deps = {'status': False}
    else:
        deps = {
            'status': True,
            'graphs': graphs,
            'collections': collections,
            'edges': edges
        }

    return deps
Ejemplo n.º 16
0
def search_collections(collections, data, page, per_page):
    """Search in Database"""

    db_inst = DB()

    db_inst.get_database()
    cursor = db_inst.search_in_collections(collections, data, page, per_page)

    total_pages = int(math.ceil(cursor.statistics()[
                      'fullCount'] / (per_page * 1.0)))
    total_documents = cursor.statistics()['fullCount']

    docs = [doc for doc in cursor]

    res = {
        'total_pages': total_pages,
        'total': len(docs),
        'total_documents': total_documents,
        'documents': docs
    }

    return res
Ejemplo n.º 17
0
def create_app(config_module=None):
    app = Flask(__name__)
    app.secret_key = binascii.hexlify(os.urandom(24))
    app.config.from_object(config_module or os.environ.get('FLASK_CONFIG')
                           or 'globomap_api.config')
    app.config['LOGGER_HANDLER_POLICY'] = 'default'
    app.config['LOGGER_NAME'] = 'api'
    app.config['BUNDLE_ERRORS'] = True
    app.config['RESTPLUS_VALIDATE'] = True

    app.logger

    with app.app_context():
        from globomap_api.api.v2.api import blueprint as api_v2
        from globomap_api.models.db import DB

        config.dictConfig(app.config['LOGGING'])

        app.config['ARANGO_CONN'] = DB(app.config)

        app.register_blueprint(api_v2)

    return app
Ejemplo n.º 18
0
 def setUp(self):
     self.app = create_app('tests.config')
     with self.app.app_context():
         self.db_inst = DB()
         self._cleanup()
         self.db_inst.get_database()