Example #1
0
def process_entities(collection_id=None):
    # re-process entities
    q = db.session.query(Entity)
    if collection_id is not None:
        q = q.filter(Entity.collection_id == collection_id)
    for entity in q:
        index_entity(entity)
Example #2
0
def update_entity(entity):
    index_entity(entity)
    update_entity_full.apply_async([entity.id],
                                   queue=USER_QUEUE,
                                   routing_key=USER_ROUTING_KEY)
    # needed to make the call to view() work:
    flush_index()
Example #3
0
 def setUp(self):
     super(EntitiesTestCase, self).setUp()
     self.rolex = self.create_user(foreign_id='user_3')
     self.col = Collection()
     self.col.label = 'Original Collection'
     self.col.foreign_id = 'test_coll_entities'
     db.session.add(self.col)
     self.col_other = Collection()
     self.col_other.label = 'Other Collection'
     self.col_other.foreign_id = 'test_coll_entities_other'
     db.session.add(self.col_other)
     db.session.flush()
     self.ent = Entity.create({
         'schema': 'LegalEntity',
         'properties': {
             'name': 'Winnie the Pooh',
             'country': 'pa',
             'summary': 'a fictional teddy bear created by A. A. Milne',
             'alias': ['Puh der Bär', 'Pooh Bear']
         }
     }, self.col)
     self.other = Entity.create({
         'schema': 'LegalEntity',
         'properties': {
             'name': 'Pu der Bär',
             'country': 'de',
             'description': 'he is a bear',
             'alias': ['Puh der Bär']
         }
     }, self.col)
     db.session.commit()
     index_entity(self.ent)
     index_entity(self.other)
Example #4
0
def reindex_entity(entity, references=True):
    log.info('Index [%s]: %s', entity.id, entity.name)
    if entity.state != Entity.STATE_ACTIVE:
        index_delete(entity.id)
        if references:
            delete_entity_references(entity.id)
    else:
        index_entity(entity)
Example #5
0
def reindex_entity(entity, references=True):
    log.info('Index [%s]: %s', entity.id, entity.name)
    if entity.state != Entity.STATE_ACTIVE:
        index_delete(entity.id)
        if references:
            delete_entity_references(entity.id)
    else:
        index_entity(entity)
Example #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()
    if entity is None:
        log.error("No entity with ID: %r", entity_id)
        return
    Alert.dedupe(entity.id)
    index_entity(entity)
Example #7
0
def reindex_entities(block=5000):
    cq = db.session.query(Collection)
    for collection in cq.yield_per(block):
        log.info("Indexing entities in: %r", collection)
        eq = db.session.query(Entity)
        eq = eq.filter(Entity.collection == collection)
        for entity in eq.yield_per(block):
            # Use the one that's already loaded:
            entity.collection = collection
            index_entity(entity)
        index_collection(collection)
Example #8
0
 def setUp(self):
     super(EntitiesApiTestCase, self).setUp()
     self.rolex = self.create_user(foreign_id='user_3')
     self.col = self.create_collection()
     self.ent = Entity.create({
         'schema': 'LegalEntity',
         'name': 'Winnie the Pooh',
         'properties': {
             'country': 'pa',
         }
     }, self.col)
     db.session.commit()
     index_entity(self.ent)
Example #9
0
 def setUp(self):
     super(EntitiesApiTestCase, self).setUp()
     self.rolex = self.create_user(foreign_id='user_3')
     self.col = self.create_collection()
     self.data = {
         'schema': 'LegalEntity',
         'properties': {
             'name': 'Winnie the Pooh',
             'country': 'pa',
         }
     }
     self.ent = Entity.create(self.data, self.col)
     db.session.commit()
     index_entity(self.ent)
Example #10
0
 def setUp(self):
     super(EntitiesApiTestCase, self).setUp()
     self.rolex = self.create_user(foreign_id='user_3')
     self.col = Collection()
     self.col.label = 'Test Collection'
     self.col.foreign_id = 'test_coll_entities_api'
     db.session.add(self.col)
     db.session.flush()
     self.ent = Entity.save({
         'schema': 'LegalEntity',
         'name': 'Winnie the Pooh',
         'data': {
             'country': 'pa',
         }
     }, self.col)
     db.session.commit()
     index_entity(self.ent)
Example #11
0
 def test_index(self):
     index_entity(self.ent)
     optimize_search()
     res = self.client.get('/api/1/entities?facet=collections')
     assert res.status_code == 200, res
     assert res.json['total'] == 0, res.json
     assert len(res.json['facets']['collections']['values']) == 0, res.json
     self.login(is_admin=True)
     res = self.client.get('/api/1/entities?facet=collections')
     assert res.status_code == 200, res
     assert res.json['total'] == 1, res.json
     assert len(res.json['facets']['collections']['values']) == 1, res.json
     col0 = res.json['facets']['collections']['values'][0]
     assert col0['id'] == self.col.id, res.json
     assert col0['label'] == self.col.label, res.json
     assert len(res.json['facets']) == 1, res.json
     res = self.client.get('/api/1/entities?facet=jurisdiction_code')
     assert len(res.json['facets']) == 2, res.json
     assert 'values' in res.json['facets']['jurisdiction_code'], res.json
Example #12
0
 def test_index(self):
     index_entity(self.ent)
     flush_index()
     res = self.client.get('/api/1/entities?facet=collections')
     assert res.status_code == 200, res
     assert res.json['total'] == 0, res.json
     assert len(res.json['facets']['collections']['values']) == 0, res.json
     self.login(is_admin=True)
     res = self.client.get('/api/1/entities?facet=collections')
     assert res.status_code == 200, res
     assert res.json['total'] == 1, res.json
     assert len(res.json['facets']['collections']['values']) == 1, res.json
     col0 = res.json['facets']['collections']['values'][0]
     assert col0['id'] == str(self.col.id), res.json
     assert col0['label'] == self.col.label, res.json
     assert len(res.json['facets']) == 1, res.json
     res = self.client.get('/api/1/entities?facet=countries')
     assert len(res.json['facets']) == 1, res.json
     assert 'values' in res.json['facets']['countries'], res.json
Example #13
0
    def setUp(self):
        super(XrefApiTestCase, self).setUp()
        self.creator = self.create_user(foreign_id='creator')
        self.outsider = self.create_user(foreign_id='outsider')
        self.guest = self.create_user(foreign_id=Role.SYSTEM_GUEST)

        # First public collection and entities
        self.residents = self.create_collection(
            label='Residents of Habitat Ring',
            foreign_id='test_residents',
            creator=self.creator)
        self.grant(self.residents, self.guest, True, False)

        self.ent = Entity.create({
            'schema': 'Person',
            'name': 'Elim Garak',
        }, self.residents)
        db.session.add(self.ent)

        self.ent2 = Entity.create({
            'schema': 'Person',
            'name': 'Leeta',
        }, self.residents)
        db.session.add(self.ent2)

        # Second public collection and entities
        self.dabo = self.create_collection(label='Dabo Girls',
                                           foreign_id='test_dabo',
                                           creator=self.creator)
        self.grant(self.dabo, self.guest, True, False)

        self.ent3 = Entity.create({
            'schema': 'Person',
            'name': 'MPella',
        }, self.dabo)
        db.session.add(self.ent3)

        self.ent4 = Entity.create({
            'schema': 'Person',
            'name': 'Leeta',
        }, self.dabo)
        db.session.add(self.ent4)

        self.ent5 = Entity.create({
            'schema': 'Person',
            'name': 'Mardah',
        }, self.dabo)
        db.session.add(self.ent5)

        # Private collection and entities
        self.obsidian = self.create_collection(label='Obsidian Order',
                                               foreign_id='test_obsidian',
                                               creator=self.creator)

        self.ent6 = Entity.create({
            'schema': 'Person',
            'name': 'Elim Garack',
        }, self.obsidian)
        db.session.add(self.ent6)

        self.ent7 = Entity.create(
            {
                'schema': 'Person',
                'name': 'Enabran Tain',
            }, self.obsidian)
        db.session.add(self.ent7)

        db.session.commit()
        index_entity(self.ent)
        index_entity(self.ent2)
        index_entity(self.ent3)
        index_entity(self.ent4)
        index_entity(self.ent5)
        index_entity(self.ent6)
        index_entity(self.ent7)
        self.flush_index()
Example #14
0
def update_entity(entity):
    update_entity_full.apply_async([entity.id], priority=7)
    return index_entity(entity)
Example #15
0
def update_entity(entity):
    index_entity(entity)
    update_entity_full.apply_async([entity.id], priority=7)
    # needed to make the call to view() work:
    flush_index()
Example #16
0
def update_entity(entity):
    return index_entity(entity)
Example #17
0
    def setUp(self):
        super(XrefApiTestCase, self).setUp()
        self.creator = self.create_user(foreign_id='creator')
        self.outsider = self.create_user(foreign_id='outsider')

        # First public collection and entities
        self.residents = self.create_collection(
            label='Residents of Habitat Ring',
            foreign_id='test_residents',
            creator=self.creator
        )
        self.grant_publish(self.residents)

        self.ent = Entity.create({
            'schema': 'Person',
            'properties': {
                'name': 'Elim Garak',
            }
        }, self.residents)
        db.session.add(self.ent)

        self.ent2 = Entity.create({
            'schema': 'Person',
            'properties': {
                'name': 'Leeta',
            }
        }, self.residents)
        db.session.add(self.ent2)

        # Second public collection and entities
        self.dabo = self.create_collection(
            label='Dabo Girls',
            foreign_id='test_dabo',
            creator=self.creator
        )
        self.grant_publish(self.dabo)

        self.ent3 = Entity.create({
            'schema': 'Person',
            'properties': {
                'name': 'MPella',
            }
        }, self.dabo)
        db.session.add(self.ent3)

        self.ent4 = Entity.create({
            'schema': 'Person',
            'properties': {
                'name': 'Leeta',
            }
        }, self.dabo)
        db.session.add(self.ent4)

        self.ent5 = Entity.create({
            'schema': 'Person',
            'properties': {
                'name': 'Mardah',
            }
        }, self.dabo)
        db.session.add(self.ent5)

        # Private collection and entities
        self.obsidian = self.create_collection(
            label='Obsidian Order',
            foreign_id='test_obsidian',
            creator=self.creator
        )

        self.ent6 = Entity.create({
            'schema': 'Person',
            'properties': {
                'name': 'Elim Garak',
            }
        }, self.obsidian)
        db.session.add(self.ent6)

        self.ent7 = Entity.create({
            'schema': 'Person',
            'properties': {
                'name': 'Enabran Tain',
            }
        }, self.obsidian)
        db.session.add(self.ent7)

        db.session.commit()
        index_entity(self.ent)
        index_entity(self.ent2)
        index_entity(self.ent3)
        index_entity(self.ent4)
        index_entity(self.ent5)
        index_entity(self.ent6)
        index_entity(self.ent7)