Search in sources :

Example 1 with MetadataEnumeration

use of bio.terra.common.MetadataEnumeration in project jade-data-repo by DataBiosphere.

the class DatasetDao method enumerate.

/**
 * Fetch a list of all the available datasets.
 * This method returns summary objects, which do not include sub-objects associated with datasets (e.g. tables).
 * Note that this method will only return datasets that are NOT exclusively locked.
 * @param offset skip this many datasets from the beginning of the list (intended for "scrolling" behavior)
 * @param limit only return this many datasets in the list
 * @param sort field for order by clause. possible values are: name, description, created_date
 * @param direction asc or desc
 * @param filter string to match (SQL ILIKE) in dataset name or description
 * @param accessibleDatasetIds list of dataset ids that caller has access to (fetched from IAM service)
 * @return a list of dataset summary objects
 */
public MetadataEnumeration<DatasetSummary> enumerate(int offset, int limit, String sort, String direction, String filter, List<UUID> accessibleDatasetIds) {
    MapSqlParameterSource params = new MapSqlParameterSource();
    List<String> whereClauses = new ArrayList<>();
    DaoUtils.addAuthzIdsClause(accessibleDatasetIds, params, whereClauses);
    // exclude datasets that are exclusively locked
    whereClauses.add(" flightid IS NULL");
    // get total count of objects
    String countSql = "SELECT count(id) AS total FROM dataset WHERE " + StringUtils.join(whereClauses, " AND ");
    Integer total = jdbcTemplate.queryForObject(countSql, params, Integer.class);
    // add the filter to the clause to get the actual items
    DaoUtils.addFilterClause(filter, params, whereClauses);
    String whereSql = "";
    if (!whereClauses.isEmpty()) {
        whereSql = " WHERE " + StringUtils.join(whereClauses, " AND ");
    }
    String sql = "SELECT " + "id, name, description, default_profile_id, additional_profile_ids, created_date " + "FROM dataset " + whereSql + DaoUtils.orderByClause(sort, direction) + " OFFSET :offset LIMIT :limit";
    params.addValue("offset", offset).addValue("limit", limit);
    List<DatasetSummary> summaries = jdbcTemplate.query(sql, params, new DatasetSummaryMapper());
    return new MetadataEnumeration<DatasetSummary>().items(summaries).total(total == null ? -1 : total);
}
Also used : MapSqlParameterSource(org.springframework.jdbc.core.namedparam.MapSqlParameterSource) MetadataEnumeration(bio.terra.common.MetadataEnumeration) ArrayList(java.util.ArrayList)

Example 2 with MetadataEnumeration

use of bio.terra.common.MetadataEnumeration in project jade-data-repo by DataBiosphere.

the class ProfileDao method enumerateBillingProfiles.

public MetadataEnumeration<BillingProfile> enumerateBillingProfiles(Integer offset, Integer limit) {
    String sql = "SELECT id, name, biller, billing_account_id FROM billing_profile OFFSET :offset LIMIT :limit";
    MapSqlParameterSource params = new MapSqlParameterSource().addValue("offset", offset).addValue("limit", limit);
    List<BillingProfile> profiles = jdbcTemplate.query(sql, params, new BillingProfileMapper());
    sql = "SELECT count(id) AS total FROM billing_profile";
    params = new MapSqlParameterSource();
    Integer total = jdbcTemplate.queryForObject(sql, params, Integer.class);
    return new MetadataEnumeration<BillingProfile>().items(profiles).total(total == null ? -1 : total);
}
Also used : MapSqlParameterSource(org.springframework.jdbc.core.namedparam.MapSqlParameterSource) MetadataEnumeration(bio.terra.common.MetadataEnumeration)

Example 3 with MetadataEnumeration

use of bio.terra.common.MetadataEnumeration in project jade-data-repo by DataBiosphere.

the class SnapshotDao method retrieveSnapshots.

/**
 * Fetch a list of all the available snapshots.
 * This method returns summary objects, which do not include sub-objects associated with snapshots (e.g. tables).
 * Note that this method will only return snapshots that are NOT exclusively locked.
 * @param offset skip this many snapshots from the beginning of the list (intended for "scrolling" behavior)
 * @param limit only return this many snapshots in the list
 * @param sort field for order by clause. possible values are: name, description, created_date
 * @param direction asc or desc
 * @param filter string to match (SQL ILIKE) in snapshots name or description
 * @param accessibleSnapshotIds list of snapshots ids that caller has access to (fetched from IAM service)
 * @return a list of dataset summary objects
 */
public MetadataEnumeration<SnapshotSummary> retrieveSnapshots(int offset, int limit, String sort, String direction, String filter, List<UUID> accessibleSnapshotIds) {
    logger.debug("retrieve snapshots offset: " + offset + " limit: " + limit + " sort: " + sort + " direction: " + direction + " filter:" + filter);
    MapSqlParameterSource params = new MapSqlParameterSource();
    List<String> whereClauses = new ArrayList<>();
    DaoUtils.addAuthzIdsClause(accessibleSnapshotIds, params, whereClauses);
    // exclude snapshots that are exclusively locked
    whereClauses.add(" flightid IS NULL");
    // add the filter to the clause to get the actual items
    DaoUtils.addFilterClause(filter, params, whereClauses);
    String whereSql = "";
    if (!whereClauses.isEmpty()) {
        whereSql = " WHERE " + StringUtils.join(whereClauses, " AND ");
    }
    // get total count of objects
    String countSql = "SELECT count(id) AS total FROM snapshot " + whereSql;
    Integer total = jdbcTemplate.queryForObject(countSql, params, Integer.class);
    String sql = "SELECT id, name, description, created_date, profile_id FROM snapshot " + whereSql + DaoUtils.orderByClause(sort, direction) + " OFFSET :offset LIMIT :limit";
    params.addValue("offset", offset).addValue("limit", limit);
    List<SnapshotSummary> summaries = jdbcTemplate.query(sql, params, new SnapshotSummaryMapper());
    return new MetadataEnumeration<SnapshotSummary>().items(summaries).total(total == null ? -1 : total);
}
Also used : MapSqlParameterSource(org.springframework.jdbc.core.namedparam.MapSqlParameterSource) MetadataEnumeration(bio.terra.common.MetadataEnumeration) ArrayList(java.util.ArrayList)

Aggregations

MetadataEnumeration (bio.terra.common.MetadataEnumeration)3 MapSqlParameterSource (org.springframework.jdbc.core.namedparam.MapSqlParameterSource)3 ArrayList (java.util.ArrayList)2