def update_search_request(search_id, filepath):

    db = get_database()
    try:

        delete_sql = """
        delete from core.search_result_export where search_request_id = %s
        """

        insert_sql = """
        insert into core.search_result_export ( search_request_id, file ) values ( %s, %s )
        """

        update_sql = """
        update core.search_request set status_code = 'C' where id =  %s
        """

        cursor = db.cursor()
        cursor.execute( delete_sql, [search_id] )
        cursor.execute( insert_sql, [search_id, filepath ] )
        cursor.execute( update_sql, [search_id] )

        cursor.close()
        db.commit()
    finally:
        db.close()
Esempio n. 2
0
def get_reference_data(ids):

    db = get_database()
    try:
        sql = """
        select i.ext_reference_id, i.id, r.register_code, i.status, i.detail, r.country_code
          from core.individual i
          join core.register r on ( r.id = i.register_id )
          where i.id in ( %s )
        """

        sql = sql % (','.join(str(i) for i in ids))

        cursor = db.cursor()
        cursor.execute(sql)
        return {
            rs[1]: dict(status=rs[3],
                        ext_reference_id=rs[0],
                        register=rs[2],
                        details=rs[4],
                        country=rs[5])
            for rs in cursor.fetchall()
        }
    finally:
        db.close()
Esempio n. 3
0
def update_search_request(search_id, filepath):

    db = get_database()
    try:

        delete_sql = """
        delete from core.search_result_export where search_request_id = %s
        """

        insert_sql = """
        insert into core.search_result_export ( search_request_id, file ) values ( %s, %s )
        """

        update_sql = """
        update core.search_request set status_code = 'C' where id =  %s
        """

        cursor = db.cursor()
        cursor.execute(delete_sql, [search_id])
        cursor.execute(insert_sql, [search_id, filepath])
        cursor.execute(update_sql, [search_id])

        cursor.close()
        db.commit()
    finally:
        db.close()
def update_status(search_request_id, status_code, status):

    update_sql = """
       update core.search_request set status_code = %s, status  = %s where id = %s 
    """
    
    db = get_database()
    try:

        cursor = db.cursor()
        cursor.execute( update_sql, [status_code, json.dumps(status), search_request_id])
        cursor.close()
        db.commit()
    finally:
        db.close()
    return
Esempio n. 5
0
def process_search(search_request_id):

    logger.info('searching %s' % search_request_id)

    # purge any recent work
    key = 'searchrequest/%s' % search_request_id

    RW = get_worker_cache()
    RW.delete(key)

    db = get_database()

    try:
        find_search_items_sql = """
         select s.id, 
                COALESCE( reg.register_code, 'All'),
                s.namelist_id, 
                si.id as search_item_id,
                si.search_name, 
                si.details 
              from core.search_request s
              left outer join core.register reg on ( reg.id = s.register_id )
              join core.searchitem si on ( si.namelist_id = s.namelist_id )
        where s.id = %s 
        """

        logger.info('searching database')
        cursor = db.cursor('searchCursor')
        cursor.itersize = 1000

        cursor.execute(find_search_items_sql, [search_request_id])
        logger.info('start document ')

        count = 0
        subtasks = []
        for (search_request_id, source, namelist_id, search_item_id,
             search_name, details) in cursor:
            subtasks.append(
                search_name_task.subtask(
                    (search_request_id, source, namelist_id, search_item_id,
                     search_name, details)).set(queue='searchNameQueue'))
    except Exception, e:
        update_status(search_request_id, 'F',
                      dict(message='failed', current=0, total=0))
        return False
def get_reference_data(ids):

    db = get_database()
    try:
        sql = """
        select i.ext_reference_id, i.id, r.register_code, i.status, i.detail, r.country_code
          from core.individual i
          join core.register r on ( r.id = i.register_id )
          where i.id in ( %s )
        """

        sql = sql % (','.join( str(i) for i in ids))

        cursor = db.cursor()
        cursor.execute(sql)
        return { rs[1]:dict(status=rs[3],ext_reference_id=rs[0],register=rs[2], details=rs[4], country=rs[5]) for rs in cursor.fetchall()}
    finally:
        db.close()
Esempio n. 7
0
def update_status(search_request_id, status_code, status):

    update_sql = """
       update core.search_request set status_code = %s, status  = %s where id = %s 
    """

    db = get_database()
    try:

        cursor = db.cursor()
        cursor.execute(
            update_sql,
            [status_code, json.dumps(status), search_request_id])
        cursor.close()
        db.commit()
    finally:
        db.close()
    return
def get_search_request(search_request_id):

    sql = """
    select sr.id, nl.label, nl.user_id
      from core.search_request sr
      join core.namelist nl on ( nl.id = sr.namelist_id )
      where sr.id = %s
    """

    ids = []
    db = get_database()
    try:
        cursor = db.cursor()
        cursor.execute( sql, [search_request_id] )
        ids = [ (rs[0], rs[1], rs[2]) for rs in cursor.fetchall()]
        cursor.close()
        db.commit()
    finally:
        db.close()

    return ids
Esempio n. 9
0
def get_search_request(search_request_id):

    sql = """
    select sr.id, nl.label, nl.user_id
      from core.search_request sr
      join core.namelist nl on ( nl.id = sr.namelist_id )
      where sr.id = %s
    """

    ids = []
    db = get_database()
    try:
        cursor = db.cursor()
        cursor.execute(sql, [search_request_id])
        ids = [(rs[0], rs[1], rs[2]) for rs in cursor.fetchall()]
        cursor.close()
        db.commit()
    finally:
        db.close()

    return ids
Esempio n. 10
0
def process_search(search_request_id):

    logger.info( 'searching %s' % search_request_id )

    # purge any recent work
    key = 'searchrequest/%s' % search_request_id

    RW = get_worker_cache()
    RW.delete(key)

    db = get_database()

    try:
        find_search_items_sql = """
         select s.id, 
                COALESCE( reg.register_code, 'All'),
                s.namelist_id, 
                si.id as search_item_id,
                si.search_name, 
                si.details 
              from core.search_request s
              left outer join core.register reg on ( reg.id = s.register_id )
              join core.searchitem si on ( si.namelist_id = s.namelist_id )
        where s.id = %s 
        """

        logger.info('searching database')
        cursor = db.cursor('searchCursor')
        cursor.itersize = 1000

        cursor.execute(find_search_items_sql, [search_request_id] )
        logger.info('start document ')

        count = 0
        subtasks = []
        for (search_request_id, source, namelist_id, search_item_id, search_name, details ) in cursor:
            subtasks.append( search_name_task.subtask( (search_request_id, source, namelist_id, search_item_id, search_name, details )).set(queue='searchNameQueue') ) 
    except Exception, e:
        update_status(search_request_id, 'F', dict(message='failed', current=0, total=0))
        return False