예제 #1
0
def delete_collection(collection_id=None):
    # Deleting a collection affects many associated objects and requires
    # checks, so this is done manually and in detail here.
    q = db.session.query(Collection).filter(Collection.id == collection_id)
    collection = q.first()
    if collection is None:
        log.error("No collection with ID: %r", collection_id)

    log.info("Deleting collection [%r]: %r", collection.id, collection.label)
    deleted_at = datetime.utcnow()
    for entity in collection.entities:
        entity.collections = [c for c in entity.collections
                              if c.id != collection.id]
        db.session.add(entity)
        if not len(entity.collections):
            delete_entity(entity)
        else:
            update_entity(entity)

    for document in collection.documents:
        document.collections = [c for c in document.collections
                                if c.id != collection.id]
        if not len(document.collections):
            delete_document(document, deleted_at=deleted_at)
        else:
            if collection_id == document.source_collection_id:
                document.source_collection_id = None
            db.session.add(document)
            update_document(document)

    collection.delete(deleted_at=deleted_at)
    db.session.commit()
    index_delete(collection_id)
    with graph.transaction() as tx:
        graph.remove_collection(tx, collection_id)
예제 #2
0
def update_document(document):
    # These are operations that should be executed after each
    # write to a document or its metadata.
    analyze_document_id.delay(document.id)
    index_document(document, index_records=False)
    with graph.transaction() as tx:
        graph.load_document(tx, document)
예제 #3
0
def update_document(document):
    # These are operations that should be executed after each
    # write to a document or its metadata.
    analyze_document_id.apply_async([document.id], queue=USER_QUEUE,
                                    routing_key=USER_ROUTING_KEY)
    index_document(document, index_records=False)
    with graph.transaction() as tx:
        graph.load_document(tx, document)
예제 #4
0
def update_document(document):
    # These are operations that should be executed after each
    # write to a document or its metadata.
    analyze_document_id.apply_async([document.id],
                                    queue=USER_QUEUE,
                                    routing_key=USER_ROUTING_KEY)
    index_document(document, index_records=False)
    with graph.transaction() as tx:
        graph.load_document(tx, document)
예제 #5
0
파일: entities.py 프로젝트: correctiv/aleph
def update_entity_full(entity_id):
    """Perform update operations on entities."""
    query = db.session.query(Entity).filter(Entity.id == entity_id)
    entity = query.first()
    generate_entity_references(entity)
    with graph.transaction() as tx:
        graph.load_entity(tx, entity)
        graph.generate_paths(tx, entity)
    reindex_entity(entity)
    Alert.dedupe(entity.id)
예제 #6
0
def update_entity_full(entity_id):
    """Perform update operations on entities."""
    query = db.session.query(Entity).filter(Entity.id == entity_id)
    entity = query.first()
    generate_entity_references(entity)
    with graph.transaction() as tx:
        graph.load_entity(tx, entity)
        graph.generate_paths(tx, entity)
    reindex_entity(entity)
    Alert.dedupe(entity.id)
예제 #7
0
파일: __init__.py 프로젝트: correctiv/aleph
def analyze_document(document):
    log.info("Analyze document: %r", document)
    analyzers = []
    meta = document.meta
    for cls in get_analyzers():
        analyzer = cls(document, meta)
        analyzer.prepare()
        analyzers.append(analyzer)

    for text in document.text_parts():
        for analyzer in analyzers:
            analyzer.on_text(text)

    for analyzer in analyzers:
        analyzer.finalize()
    document.meta = meta
    db.session.add(document)
    db.session.commit()
    index_document(document)
    with graph.transaction() as tx:
        graph.load_document(tx, document)
예제 #8
0
파일: __init__.py 프로젝트: nivertech/aleph
def analyze_document(document):
    log.info("Analyze document: %r", document)
    analyzers = []
    meta = document.meta
    for cls in get_analyzers():
        analyzer = cls(document, meta)
        analyzer.prepare()
        analyzers.append(analyzer)

    for text in document.text_parts():
        for analyzer in analyzers:
            analyzer.on_text(text)

    for analyzer in analyzers:
        analyzer.finalize()
    document.meta = meta
    db.session.add(document)
    db.session.commit()
    index_document(document)
    with graph.transaction() as tx:
        graph.load_document(tx, document)
예제 #9
0
def delete_collection(collection_id=None):
    # Deleting a collection affects many associated objects and requires
    # checks, so this is done manually and in detail here.
    q = db.session.query(Collection).filter(Collection.id == collection_id)
    collection = q.first()
    if collection is None:
        log.error("No collection with ID: %r", collection_id)

    log.info("Deleting collection [%r]: %r", collection.id, collection.label)
    deleted_at = datetime.utcnow()
    for entity in collection.entities:
        entity.collections = [
            c for c in entity.collections if c.id != collection.id
        ]
        db.session.add(entity)
        if not len(entity.collections):
            delete_entity(entity)
        else:
            update_entity(entity)

    for document in collection.documents:
        document.collections = [
            c for c in document.collections if c.id != collection.id
        ]
        if not len(document.collections):
            delete_document(document, deleted_at=deleted_at)
        else:
            if collection_id == document.source_collection_id:
                document.source_collection_id = None
            db.session.add(document)
            update_document(document)

    collection.delete(deleted_at=deleted_at)
    db.session.commit()
    index_delete(collection_id)
    with graph.transaction() as tx:
        graph.remove_collection(tx, collection_id)
예제 #10
0
def update_collection(collection):
    """Create or update a collection."""
    with graph.transaction() as tx:
        graph.load_collection(tx, collection)
예제 #11
0
파일: entities.py 프로젝트: correctiv/aleph
def delete_entity(entity, deleted_at=None):
    update_entity(entity)
    with graph.transaction() as tx:
        graph.remove_entity(tx, entity.id)
        graph.delete_paths(entity.id)
    entity.delete(deleted_at=deleted_at)
예제 #12
0
def delete_document(document, deleted_at=None):
    with graph.transaction() as tx:
        graph.remove_document(tx, document.id)
    index_delete(document.id)
    document.delete(deleted_at=deleted_at)
예제 #13
0
def delete_document(document, deleted_at=None):
    with graph.transaction() as tx:
        graph.remove_document(tx, document.id)
    index_delete(document.id)
    document.delete(deleted_at=deleted_at)
예제 #14
0
def delete_entity(entity, deleted_at=None):
    update_entity(entity)
    with graph.transaction() as tx:
        graph.remove_entity(tx, entity.id)
        graph.delete_paths(entity.id)
    entity.delete(deleted_at=deleted_at)
예제 #15
0
def update_collection(collection):
    """Create or update a collection."""
    with graph.transaction() as tx:
        graph.load_collection(tx, collection)
예제 #16
0
def update_collection(collection):
    with graph.transaction() as tx:
        graph.load_collection(tx, collection)
예제 #17
0
파일: entities.py 프로젝트: nivertech/aleph
def update_entity(entity):
    reindex_entity(entity, references=False)
    with graph.transaction() as tx:
        graph.load_entity(tx, entity)
    update_entity_full.delay(entity.id)