Search in sources :

Example 1 with StorageUsageSummaryList

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

the class StorageUsageServiceImplTest method testGetUsageForUserSameUser.

@Test
public void testGetUsageForUserSameUser() throws Exception {
    StorageUsageSummaryList results = suService.getUsageForUser(userId, userId, dList);
    Assert.assertNotNull(results);
}
Also used : StorageUsageSummaryList(org.sagebionetworks.repo.model.storage.StorageUsageSummaryList) Test(org.junit.Test)

Example 2 with StorageUsageSummaryList

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

the class StorageLocationDAOImpl method getAggregatedUsageByUserInRange.

@Override
public StorageUsageSummaryList getAggregatedUsageByUserInRange(long beginIncl, long endExcl) {
    if (beginIncl >= endExcl) {
        String msg = "begin must be greater than end (begin = " + beginIncl;
        msg += "; end = ";
        msg += endExcl;
        msg += ")";
        throw new IllegalArgumentException(msg);
    }
    StorageUsageSummaryList summaryList = getAggregatedResults(COL_STORAGE_LOCATION_USER_ID, SELECT_AGGREGATED_USAGE_PART_1, SELECT_AGGREGATED_USAGE_PART_2, beginIncl, endExcl);
    return summaryList;
}
Also used : StorageUsageSummaryList(org.sagebionetworks.repo.model.storage.StorageUsageSummaryList)

Example 3 with StorageUsageSummaryList

use of org.sagebionetworks.repo.model.storage.StorageUsageSummaryList 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 4 with StorageUsageSummaryList

use of org.sagebionetworks.repo.model.storage.StorageUsageSummaryList 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 5 with StorageUsageSummaryList

use of org.sagebionetworks.repo.model.storage.StorageUsageSummaryList 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)

Aggregations

StorageUsageSummaryList (org.sagebionetworks.repo.model.storage.StorageUsageSummaryList)21 Test (org.junit.Test)8 StorageUsageSummary (org.sagebionetworks.repo.model.storage.StorageUsageSummary)8 StorageUsageDimension (org.sagebionetworks.repo.model.storage.StorageUsageDimension)5 ArrayList (java.util.ArrayList)4 StorageUsageDimensionValue (org.sagebionetworks.repo.model.storage.StorageUsageDimensionValue)4 Map (java.util.Map)3 UnauthorizedException (org.sagebionetworks.repo.model.UnauthorizedException)3 StorageUsageService (org.sagebionetworks.repo.web.service.StorageUsageService)3 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)3 ResponseBody (org.springframework.web.bind.annotation.ResponseBody)3 ResponseStatus (org.springframework.web.bind.annotation.ResponseStatus)3 HttpServlet (javax.servlet.http.HttpServlet)2 JSONObjectAdapter (org.sagebionetworks.schema.adapter.JSONObjectAdapter)2 JSONObjectAdapterImpl (org.sagebionetworks.schema.adapter.org.json.JSONObjectAdapterImpl)2 MapSqlParameterSource (org.springframework.jdbc.core.namedparam.MapSqlParameterSource)2 MockHttpServletRequest (org.springframework.mock.web.MockHttpServletRequest)2 MockHttpServletResponse (org.springframework.mock.web.MockHttpServletResponse)2