src/dirbs/api/v2/resources/catalog.py
def catalog_api(**kwargs: dict) -> jsonify:
    """
    Defines handler for Catalog API (version 2.0) GET method.

    Arguments:
        kwargs: required arguments dictionary
    Returns:
        JSON response
    """
    sort_order = kwargs.get('order')
    data_offset = kwargs.get('offset')
    data_limit = kwargs.get('limit')

    # Build filters to be applied to the SQL query
    filters, filter_params = _build_sql_query_filters(**kwargs)

    query = sql.SQL("""SELECT array_agg(status ORDER BY run_id DESC)::TEXT[] AS status_list, dc.*,
                              count(*) OVER() AS total_count
                                     FROM (SELECT file_id,
                                                  filename,
                                                  file_type,
                                                  compressed_size_bytes,
                                                  modified_time,
                                                  is_valid_zip,
                                                  is_valid_format,
                                                  md5,
                                                  extra_attributes,
                                                  first_seen,
                                                  last_seen,
                                                  uncompressed_size_bytes,
                                                  num_records
                                             FROM data_catalog
                                                  {filters}
                                         ORDER BY last_seen DESC, file_id DESC
                                            LIMIT ALL) dc
                                LEFT JOIN (SELECT run_id, status, extra_metadata
                                             FROM job_metadata
                                            WHERE command = 'dirbs-import') jm
                                           ON md5 = (extra_metadata->>'input_file_md5')::uuid
                                 GROUP BY file_id,
                                          filename,
                                          file_type,
                                          compressed_size_bytes,
                                          modified_time,
                                          is_valid_zip,
                                          is_valid_format,
                                          md5,
                                          extra_attributes,
                                          first_seen,
                                          last_seen,
                                          uncompressed_size_bytes,
                                          num_records
                                 ORDER BY last_seen DESC, file_id {sort_order} 
                                 OFFSET {data_offset} 
                                 LIMIT {data_limit}""")  # noqa Q444

    where_clause = sql.SQL('')
    if len(filters) > 0:
        where_clause = sql.SQL('WHERE {0}').format(sql.SQL(' AND ').join(filters))

    with get_db_connection() as conn, conn.cursor() as cursor:
        cursor.execute(cursor.mogrify(query.format(filters=where_clause,
                                                   sort_order=sql.SQL(sort_order),
                                                   data_offset=sql.SQL(str(data_offset)),
                                                   data_limit=sql.SQL(str(data_limit))),
                                      filter_params))

        result = cursor.fetchall()
        result_size = result[0][-1] if result else 0
        resp = [CatalogFile().dump(rec._asdict()).data for rec in result]
        keys = {'current_key': data_offset,
                'next_key': data_offset + data_limit if resp else '',
                'result_size': result_size}

        return jsonify({
            '_keys': Keys().dump(dict(keys)).data,
            'files': resp
        })

    Defines handler for Catalog API (version 2.0) GET method.

    Arguments:
        kwargs: required arguments dictionary
    Returns:
        JSON response
    
Defines handler for Catalog API (version 2.0) GET method.
Defines handler for Catalog API ( version 2 . 0 ) GET method .
def catalog_api(**kwargs: dict) -> jsonify:
    sort_order = kwargs.get('order')
    data_offset = kwargs.get('offset')
    data_limit = kwargs.get('limit')
    filters, filter_params = _build_sql_query_filters(**kwargs)
    query = sql.SQL("""SELECT array_agg(status ORDER BY run_id DESC)::TEXT[] AS status_list, dc.*,
                              count(*) OVER() AS total_count
                                     FROM (SELECT file_id,
                                                  filename,
                                                  file_type,
                                                  compressed_size_bytes,
                                                  modified_time,
                                                  is_valid_zip,
                                                  is_valid_format,
                                                  md5,
                                                  extra_attributes,
                                                  first_seen,
                                                  last_seen,
                                                  uncompressed_size_bytes,
                                                  num_records
                                             FROM data_catalog
                                                  {filters}
                                         ORDER BY last_seen DESC, file_id DESC
                                            LIMIT ALL) dc
                                LEFT JOIN (SELECT run_id, status, extra_metadata
                                             FROM job_metadata
                                            WHERE command = 'dirbs-import') jm
                                           ON md5 = (extra_metadata->>'input_file_md5')::uuid
                                 GROUP BY file_id,
                                          filename,
                                          file_type,
                                          compressed_size_bytes,
                                          modified_time,
                                          is_valid_zip,
                                          is_valid_format,
                                          md5,
                                          extra_attributes,
                                          first_seen,
                                          last_seen,
                                          uncompressed_size_bytes,
                                          num_records
                                 ORDER BY last_seen DESC, file_id {sort_order} 
                                 OFFSET {data_offset} 
                                 LIMIT {data_limit}""")  
    where_clause = sql.SQL('')
    if len(filters) > 0:
        where_clause = sql.SQL('WHERE {0}').format(sql.SQL(' AND ').join(filters))
    with get_db_connection() as conn, conn.cursor() as cursor:
        cursor.execute(cursor.mogrify(query.format(filters=where_clause,
                                                   sort_order=sql.SQL(sort_order),
                                                   data_offset=sql.SQL(str(data_offset)),
                                                   data_limit=sql.SQL(str(data_limit))),
                                      filter_params))
        result = cursor.fetchall()
        result_size = result[0][-1] if result else 0
        resp = [CatalogFile().dump(rec._asdict()).data for rec in result]
        keys = {'current_key': data_offset,
                'next_key': data_offset + data_limit if resp else '',
                'result_size': result_size}
        return jsonify({
            '_keys': Keys().dump(dict(keys)).data,
            'files': resp
        })
def catalog_api ( ** kwargs : dict ) -> jsonify : sort_order = kwargs . get ( 'order' ) data_offset = kwargs . get ( 'offset' ) data_limit = kwargs . get ( 'limit' ) filters , filter_params = _build_sql_query_filters ( ** kwargs ) query = sql . SQL ( """SELECT array_agg(status ORDER BY run_id DESC)::TEXT[] AS status_list, dc.*,
                              count(*) OVER() AS total_count
                                     FROM (SELECT file_id,
                                                  filename,
                                                  file_type,
                                                  compressed_size_bytes,
                                                  modified_time,
                                                  is_valid_zip,
                                                  is_valid_format,
                                                  md5,
                                                  extra_attributes,
                                                  first_seen,
                                                  last_seen,
                                                  uncompressed_size_bytes,
                                                  num_records
                                             FROM data_catalog
                                                  {filters}
                                         ORDER BY last_seen DESC, file_id DESC
                                            LIMIT ALL) dc
                                LEFT JOIN (SELECT run_id, status, extra_metadata
                                             FROM job_metadata
                                            WHERE command = 'dirbs-import') jm
                                           ON md5 = (extra_metadata->>'input_file_md5')::uuid
                                 GROUP BY file_id,
                                          filename,
                                          file_type,
                                          compressed_size_bytes,
                                          modified_time,
                                          is_valid_zip,
                                          is_valid_format,
                                          md5,
                                          extra_attributes,
                                          first_seen,
                                          last_seen,
                                          uncompressed_size_bytes,
                                          num_records
                                 ORDER BY last_seen DESC, file_id {sort_order} 
                                 OFFSET {data_offset} 
                                 LIMIT {data_limit}""" ) where_clause = sql . SQL ( '' ) if len ( filters ) > 0 : where_clause = sql . SQL ( 'WHERE {0}' ) . format ( sql . SQL ( ' AND ' ) . join ( filters ) ) with get_db_connection ( ) as conn , conn . cursor ( ) as cursor : cursor . execute ( cursor . mogrify ( query . format ( filters = where_clause , sort_order = sql . SQL ( sort_order ) , data_offset = sql . SQL ( str ( data_offset ) ) , data_limit = sql . SQL ( str ( data_limit ) ) ) , filter_params ) ) result = cursor . fetchall ( ) result_size = result [ 0 ] [ - 1 ] if result else 0 resp = [ CatalogFile ( ) . dump ( rec . _asdict ( ) ) . data for rec in result ] keys = { 'current_key' : data_offset , 'next_key' : data_offset + data_limit if resp else '' , 'result_size' : result_size } return jsonify ( { '_keys' : Keys ( ) . dump ( dict ( keys ) ) . data , 'files' : resp } )
Defines handler for Catalog API (version 2.0) GET method.
Defines handler for Catalog API ( version 2 . 0 ) GET method .
"""
    Defines handler for Catalog API (version 2.0) GET method.

    Arguments:
        kwargs: required arguments dictionary
    Returns:
        JSON response
    """ # Build filters to be applied to the SQL query # noqa Q444
None
kwargs
dict
required arguments dictionary
required arguments dictionary