Search in sources :

Example 1 with AnalyticsDataResponse

use of org.wso2.carbon.analytics.dataservice.commons.AnalyticsDataResponse in project product-iots by wso2.

the class APIUtil method getAllEventsForDevice.

public static List<SensorRecord> getAllEventsForDevice(String tableName, String query, List<SortByField> sortByFields) throws AnalyticsException {
    int tenantId = CarbonContext.getThreadLocalCarbonContext().getTenantId();
    AnalyticsDataAPI analyticsDataAPI = getAnalyticsDataAPI();
    int eventCount = analyticsDataAPI.searchCount(tenantId, tableName, query);
    // limiting the data read from the server
    int start = 0;
    int dataCount = 100;
    if (eventCount == 0) {
        return null;
    } else if (eventCount >= dataCount) {
        start = eventCount - dataCount;
    }
    List<SearchResultEntry> resultEntries = analyticsDataAPI.search(tenantId, tableName, query, start, eventCount, sortByFields);
    List<String> recordIds = getRecordIds(resultEntries);
    AnalyticsDataResponse response = analyticsDataAPI.get(tenantId, tableName, 1, null, recordIds);
    Map<String, SensorRecord> sensorDatas = createSensorData(AnalyticsDataAPIUtil.listRecords(analyticsDataAPI, response));
    List<SensorRecord> sortedSensorData = getSortedSensorData(sensorDatas, resultEntries);
    return sortedSensorData;
}
Also used : AnalyticsDataResponse(org.wso2.carbon.analytics.dataservice.commons.AnalyticsDataResponse) AnalyticsDataAPI(org.wso2.carbon.analytics.api.AnalyticsDataAPI) SearchResultEntry(org.wso2.carbon.analytics.dataservice.commons.SearchResultEntry)

Example 2 with AnalyticsDataResponse

use of org.wso2.carbon.analytics.dataservice.commons.AnalyticsDataResponse in project product-iots by wso2.

the class APIUtil method getAllEventsForDevice.

/**
 * Get sensor data for a device.
 *
 * @param tableName    table name of the data source
 * @param query        query for the table
 * @param sortByFields list of fields to sort the data by
 * @return List of SensorRecords that is sorted by the fields provided
 * @throws AnalyticsException
 */
public static List<SensorRecord> getAllEventsForDevice(String tableName, String query, List<SortByField> sortByFields) throws AnalyticsException {
    int tenantId = CarbonContext.getThreadLocalCarbonContext().getTenantId();
    AnalyticsDataAPI analyticsDataAPI = getAnalyticsDataAPI();
    int eventCount = analyticsDataAPI.searchCount(tenantId, tableName, query);
    if (eventCount == 0) {
        return null;
    }
    List<SearchResultEntry> resultEntries = analyticsDataAPI.search(tenantId, tableName, query, 0, eventCount, sortByFields);
    List<String> recordIds = getRecordIds(resultEntries);
    AnalyticsDataResponse response = analyticsDataAPI.get(tenantId, tableName, 1, null, recordIds);
    Map<String, SensorRecord> sensorDatas = createSensorData(AnalyticsDataAPIUtil.listRecords(analyticsDataAPI, response));
    List<SensorRecord> sortedSensorData = getSortedSensorData(sensorDatas, resultEntries);
    return sortedSensorData;
}
Also used : SensorRecord(org.wso2.iot.sampledevice.api.dto.SensorRecord) AnalyticsDataResponse(org.wso2.carbon.analytics.dataservice.commons.AnalyticsDataResponse) AnalyticsDataAPI(org.wso2.carbon.analytics.api.AnalyticsDataAPI) SearchResultEntry(org.wso2.carbon.analytics.dataservice.commons.SearchResultEntry)

Aggregations

AnalyticsDataAPI (org.wso2.carbon.analytics.api.AnalyticsDataAPI)2 AnalyticsDataResponse (org.wso2.carbon.analytics.dataservice.commons.AnalyticsDataResponse)2 SearchResultEntry (org.wso2.carbon.analytics.dataservice.commons.SearchResultEntry)2 SensorRecord (org.wso2.iot.sampledevice.api.dto.SensorRecord)1