Search in sources :

Example 1 with StorageUsageSummary

use of org.sagebionetworks.repo.model.storage.StorageUsageSummary in project Synapse-Repository-Services by Sage-Bionetworks.

the class StorageLocationDAOImpl method getAggregatedResults.

/**
 * Gets aggregated results. The results will be sorted in descending order.
 * Gets the specific type of aggregations (sum, count, etc.)
 * by passing in the appropriate SQL parts.
 */
private StorageUsageSummaryList getAggregatedResults(String column, String sqlPart1, String sqlPart2, long beginIncl, long endExcl) {
    assert column != null;
    assert sqlPart1 != null;
    assert sqlPart2 != null;
    assert beginIncl < endExcl;
    List<String> columnList = new ArrayList<String>(1);
    columnList.add(column);
    String sql = getAggregateSql(sqlPart1, sqlPart2, columnList);
    sql = sql + ORDER_BY_DESC_LIMIT;
    MapSqlParameterSource paramMap = new MapSqlParameterSource();
    paramMap.addValue(OFFSET_PARAM_NAME, beginIncl);
    paramMap.addValue(LIMIT_PARAM_NAME, endExcl - beginIncl);
    List<Map<String, Object>> rows = simpleJdbcTemplate.queryForList(sql, paramMap);
    StorageUsageSummaryList summaryList = createEmptySummaryList(null);
    List<StorageUsageSummary> summaries = summaryList.getSummaryList();
    fillSummaryList(columnList, summaries, rows);
    return summaryList;
}
Also used : MapSqlParameterSource(org.springframework.jdbc.core.namedparam.MapSqlParameterSource) StorageUsageSummaryList(org.sagebionetworks.repo.model.storage.StorageUsageSummaryList) ArrayList(java.util.ArrayList) Map(java.util.Map) StorageUsageSummary(org.sagebionetworks.repo.model.storage.StorageUsageSummary)

Example 2 with StorageUsageSummary

use of org.sagebionetworks.repo.model.storage.StorageUsageSummary in project Synapse-Repository-Services by Sage-Bionetworks.

the class StorageLocationDAOImpl method fillSummaryList.

private void fillSummaryList(List<String> columnList, List<StorageUsageSummary> summaryList, List<Map<String, Object>> rowList) {
    assert columnList != null;
    assert columnList.size() > 0;
    assert summaryList != null;
    assert rowList != null;
    for (Map<String, Object> row : rowList) {
        StorageUsageSummary summary = new StorageUsageSummary();
        Object size = row.get(COL_SUM_SIZE);
        if (size == null) {
            summary.setAggregatedSize(0L);
        } else if (size instanceof BigDecimal) {
            summary.setAggregatedSize(((BigDecimal) size).longValue());
        } else if (size instanceof Long) {
            summary.setAggregatedSize(((Long) size).longValue());
        } else {
            throw new DatastoreException("Unknown type of 'size': " + size.getClass().getName());
        }
        size = null;
        Object count = row.get(COL_COUNT_ID);
        if (count == null) {
            summary.setAggregatedCount(0L);
        } else if (count instanceof BigDecimal) {
            summary.setAggregatedCount(((BigDecimal) count).longValue());
        } else if (count instanceof Long) {
            summary.setAggregatedCount(((Long) count).longValue());
        } else {
            throw new DatastoreException("Unknown type of 'size': " + count.getClass().getName());
        }
        count = null;
        List<StorageUsageDimensionValue> dValList = new ArrayList<StorageUsageDimensionValue>();
        for (String column : columnList) {
            Object valObj = row.get(column);
            String value = (valObj == null ? "UNKNOWN" : valObj.toString());
            StorageUsageDimensionValue val = new StorageUsageDimensionValue();
            val.setDimension(StorageUsageDimension.valueOf(column));
            val.setValue(value);
            dValList.add(val);
        }
        summary.setDimensionList(dValList);
        summaryList.add(summary);
    }
    assert summaryList.size() == rowList.size();
}
Also used : StorageUsageDimensionValue(org.sagebionetworks.repo.model.storage.StorageUsageDimensionValue) ArrayList(java.util.ArrayList) DatastoreException(org.sagebionetworks.repo.model.DatastoreException) BigDecimal(java.math.BigDecimal) StorageUsageSummary(org.sagebionetworks.repo.model.storage.StorageUsageSummary)

Example 3 with StorageUsageSummary

use of org.sagebionetworks.repo.model.storage.StorageUsageSummary in project Synapse-Repository-Services by Sage-Bionetworks.

the class StorageLocationDAOImpl method getAggregatedResults.

/**
 * Gets aggregated results. Gets the specific type of aggregations (sum, count, etc.)
 * by passing in the appropriate SQL parts.
 */
private StorageUsageSummaryList getAggregatedResults(List<StorageUsageDimension> dimensionList, String sqlPart1, String sqlPart2) {
    assert dimensionList != null;
    assert sqlPart1 != null;
    assert sqlPart2 != null;
    StorageUsageSummaryList summaryList = createEmptySummaryList(null);
    if (dimensionList.isEmpty()) {
        return summaryList;
    }
    List<String> columnList = getGroupByColumns(dimensionList);
    assert columnList.size() > 0 : "We should have returned otherwise.";
    String sql = getAggregateSql(sqlPart1, sqlPart2, columnList);
    List<Map<String, Object>> rows = simpleJdbcTemplate.queryForList(sql);
    List<StorageUsageSummary> summaries = summaryList.getSummaryList();
    fillSummaryList(columnList, summaries, rows);
    return summaryList;
}
Also used : StorageUsageSummaryList(org.sagebionetworks.repo.model.storage.StorageUsageSummaryList) Map(java.util.Map) StorageUsageSummary(org.sagebionetworks.repo.model.storage.StorageUsageSummary)

Example 4 with StorageUsageSummary

use of org.sagebionetworks.repo.model.storage.StorageUsageSummary in project Synapse-Repository-Services by Sage-Bionetworks.

the class StorageLocationDAOImpl method getAggregatedResultsForUser.

/**
 * Gets aggregated results for user. Gets the specific type of aggregations (sum, count, etc.)
 * by passing in the appropriate SQL parts.
 */
private StorageUsageSummaryList getAggregatedResultsForUser(String userId, List<StorageUsageDimension> dimensionList, String sqlPart1, String sqlPart2) throws DatastoreException, InvalidModelException {
    assert userId != null;
    assert dimensionList != null;
    assert sqlPart1 != null;
    assert sqlPart2 != null;
    StorageUsageSummaryList summaryList = createEmptySummaryList(userId);
    if (dimensionList.isEmpty()) {
        return summaryList;
    }
    List<String> columnList = getGroupByColumns(dimensionList);
    assert columnList.size() > 0 : "We should have returned otherwise.";
    String sql = getAggregateSql(sqlPart1, sqlPart2, columnList);
    MapSqlParameterSource paramMap = new MapSqlParameterSource();
    Long userIdLong = KeyFactory.stringToKey(userId);
    paramMap.addValue(COL_STORAGE_LOCATION_USER_ID, userIdLong);
    List<Map<String, Object>> rows = simpleJdbcTemplate.queryForList(sql, paramMap);
    List<StorageUsageSummary> summaries = summaryList.getSummaryList();
    fillSummaryList(columnList, summaries, rows);
    return summaryList;
}
Also used : MapSqlParameterSource(org.springframework.jdbc.core.namedparam.MapSqlParameterSource) StorageUsageSummaryList(org.sagebionetworks.repo.model.storage.StorageUsageSummaryList) Map(java.util.Map) StorageUsageSummary(org.sagebionetworks.repo.model.storage.StorageUsageSummary)

Example 5 with StorageUsageSummary

use of org.sagebionetworks.repo.model.storage.StorageUsageSummary in project Synapse-Repository-Services by Sage-Bionetworks.

the class StorageLocationDAOImpl method createEmptySummaryList.

private StorageUsageSummaryList createEmptySummaryList(String userId) {
    StorageUsageSummaryList summaryList = new StorageUsageSummaryList();
    if (userId != null) {
        Long usage = getTotalSizeForUser(userId);
        summaryList.setTotalSize(usage);
        Long count = getTotalCountForUser(userId);
        summaryList.setTotalCount(count);
    } else {
        Long usage = getTotalSize();
        summaryList.setTotalSize(usage);
        Long count = getTotalCount();
        summaryList.setTotalCount(count);
    }
    List<StorageUsageSummary> susList = new ArrayList<StorageUsageSummary>();
    summaryList.setSummaryList(susList);
    return summaryList;
}
Also used : StorageUsageSummaryList(org.sagebionetworks.repo.model.storage.StorageUsageSummaryList) ArrayList(java.util.ArrayList) StorageUsageSummary(org.sagebionetworks.repo.model.storage.StorageUsageSummary)

Aggregations

StorageUsageSummary (org.sagebionetworks.repo.model.storage.StorageUsageSummary)9 StorageUsageSummaryList (org.sagebionetworks.repo.model.storage.StorageUsageSummaryList)8 ArrayList (java.util.ArrayList)5 StorageUsageDimensionValue (org.sagebionetworks.repo.model.storage.StorageUsageDimensionValue)5 Test (org.junit.Test)4 Map (java.util.Map)3 StorageUsageDimension (org.sagebionetworks.repo.model.storage.StorageUsageDimension)2 MapSqlParameterSource (org.springframework.jdbc.core.namedparam.MapSqlParameterSource)2 BigDecimal (java.math.BigDecimal)1 DatastoreException (org.sagebionetworks.repo.model.DatastoreException)1