Example #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):
            entity.delete(deleted_at=deleted_at)
        reindex_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):
            document.delete(deleted_at=deleted_at)
            delete_document(document.id)
        else:
            if collection_id == document.source_collection_id:
                document.source_collection_id = None
            db.session.add(document)
            index_document(document)

    collection.delete(deleted_at=deleted_at)
    db.session.commit()
    index_delete(collection_id)
Example #2
0
def delete_collection(collection_id, wait=False):
    # Deleting a collection affects many associated objects and requires
    # checks, so this is done manually and in detail here.
    q = db.session.query(Collection)
    q = q.filter(Collection.id == collection_id)
    collection = q.first()
    if collection is None:
        log.error("No collection with ID: %r", collection_id)
        return

    log.info("Deleting collection [%r]: %r", collection.id, collection.label)
    deleted_at = datetime.utcnow()
    index_delete(collection_id, wait=wait)

    log.info("Deleting cross-referencing matches...")
    Match.delete_by_collection(collection_id)

    log.info("Deleting permissions...")
    Permission.delete_by_collection(collection_id, deleted_at=deleted_at)

    delete_documents(collection_id, wait=wait)
    delete_entities(collection_id, wait=wait)

    collection.delete(deleted_at=deleted_at)
    db.session.commit()
Example #3
0
def delete_collection(collection_id):
    # 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)
        return

    log.info("Deleting collection [%r]: %r", collection.id, collection.label)
    deleted_at = datetime.utcnow()
    for entity in collection.entities:
        # TODO: consider hard-deleting entities because the polyglot tagger
        # cannot tell if a deleted match on a tagged term on a revived
        # collection means not to tag this entity any more.
        log.info("Delete entity: %r", entity)
        delete_entity(entity, deleted_at=deleted_at)

    for document in collection.documents:
        log.info("Delete document: %r", document)
        delete_document(document, deleted_at=deleted_at)

    db.session.refresh(collection)
    collection.delete(deleted_at=deleted_at)
    db.session.commit()
    index_delete(collection_id)
Example #4
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):
            entity.delete(deleted_at=deleted_at)
        reindex_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):
            document.delete(deleted_at=deleted_at)
            delete_document(document.id)
        else:
            if collection_id == document.source_collection_id:
                document.source_collection_id = None
            db.session.add(document)
            index_document(document)

    collection.delete(deleted_at=deleted_at)
    db.session.commit()
    index_delete(collection_id)
Example #5
0
def delete_collection(collection_id):
    # 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)
        return

    log.info("Deleting collection [%r]: %r", collection.id, collection.label)
    index_delete(collection_id)
    deleted_at = datetime.utcnow()

    q = db.session.query(Entity)
    q = q.filter(Entity.collection_id == collection.id)
    for entity in q.yield_per(5000):
        log.info("Delete entity: %r", entity)
        delete_entity(entity, deleted_at=deleted_at)

    q = db.session.query(Document)
    q = q.filter(Document.collection_id == collection.id)
    for document in q.yield_per(5000):
        log.info("Delete document: %r", document)
        delete_document(document, deleted_at=deleted_at)

    collection.delete(deleted_at=deleted_at)
    db.session.commit()
Example #6
0
def update_collection(collection):
    """Create or update a collection."""
    if collection.deleted_at is not None:
        index_delete(collection.id)
        return

    log.info("Updating: %r", collection)
    index_collection(collection)
Example #7
0
def update_collection(collection):
    """Create or update a collection."""
    if collection.deleted_at is not None:
        index_delete(collection.id)
        return

    collection.updated_at = datetime.utcnow()
    db.session.add(collection)
    db.session.commit()

    log.info("Updating: %r", collection)
    index_collection(collection)
    flush_index()
Example #8
0
def update_collection(collection):
    """Create or update a collection."""
    log.info("Updating: %r", collection)

    if collection.deleted_at is not None:
        index_delete(collection.id)
        return

    if collection.casefile:
        xref_collection.apply_async([collection.id], priority=2)
        # TODO: rebuild dossiers

    eq = db.session.query(Entity.id)
    eq = eq.filter(Entity.collection_id == collection.id)
    for entity in eq:
        update_entity_full.apply_async([entity.id], priority=1)

    return index_collection(collection)
Example #9
0
def update_collection(collection, roles=False):
    """Create or update a collection."""
    if collection.deleted_at is not None:
        index_delete(collection.id)
        return

    collection.updated_at = datetime.utcnow()
    db.session.add(collection)
    db.session.commit()

    log.info("Updating: %r", collection)
    index_collection(collection)
    if roles:
        update_roles(collection)

    if not collection.managed:
        xref_collection.apply_async([collection.id], priority=2)

    eq = db.session.query(Entity.id)
    eq = eq.filter(Entity.collection_id == collection.id)
    for entity in eq.all():
        update_entity_full.apply_async([entity.id], priority=2)

    flush_index()