Search in sources :

Example 1 with SuccessfulResponse

use of com.arm.mbed.cloud.sdk.internal.statistics.model.SuccessfulResponse in project mbed-cloud-sdk-java by ARMmbed.

the class Connect method listMetrics.

/**
 * Lists metrics.
 * <p>
 * Example:
 *
 * <pre>
 * {@code
 * try {
 *     Calendar startDate = GregorianCalendar(2017,10,30,10,20,56);
 *     Calendar endDate = GregorianCalendar(2017,11,31,10,20,56);
 *
 *     MetricsStartEndListOptions listOptions = new MetricsStartEndListOptions();
 *     listOptions.setStart(startDate.getTime());
 *     listOptions.setEnd(endDate.getTime());
 *     listOptions.setInterval(new TimePeriod(360)); //Once an hour
 *
 *     ListResponse<Metric> metrics = connectApi.listMetrics(listOptions);
 *     //Iterates over a page
 *     for (Metric metric : metrics.getData()) {
 *         System.out.println("Time: " + dateFormat.format(metric.getTimestamp()));
 *         System.out.println("Successful bootstraps: " + metric.getSuccessfulBootstraps());
 *         System.out.println("Successful api calls: " + metric.getSuccessfulApiCalls());
 *         System.out.println("");
 *     }
 * } catch (MbedCloudException e) {
 *     e.printStackTrace();
 * }
 * }
 * </pre>
 *
 * @param options
 *            metrics options.
 * @param <T>
 *            Type of metrics list options
 * @return list of metrics for the corresponding options.
 * @throws MbedCloudException
 *             if a problem occurred during request processing.
 */
@API
@Nullable
public <T extends AbstractMetricsListOptions> ListResponse<Metric> listMetrics(@NonNull T options) throws MbedCloudException {
    checkNotNull(options, TAG_METRIC_OPTIONS);
    final T finalOptions = options;
    final Date finalStart = options instanceof MetricsStartEndListOptions ? ((MetricsStartEndListOptions) options).getStart() : null;
    final Date finalEnd = options instanceof MetricsStartEndListOptions ? ((MetricsStartEndListOptions) options).getEnd() : null;
    final String finalPeriod = options instanceof MetricsPeriodListOptions ? ((MetricsPeriodListOptions) options).getPeriod().toString() : null;
    return CloudCaller.call(this, "listMetrics()", MetricAdapter.getListMapper(), new CloudCall<SuccessfulResponse>() {

        @Override
        public Call<SuccessfulResponse> call() {
            return endpoint.getStatistic().v3MetricsGet(MetricAdapter.mapIncludes(finalOptions.getInclude()), finalOptions.getInterval().toString(), TranslationUtils.toLocalDate(finalStart), TranslationUtils.toLocalDate(finalEnd), finalPeriod, finalOptions.getLimit(), finalOptions.getAfter(), finalOptions.getOrder().toString());
        }
    });
}
Also used : SuccessfulResponse(com.arm.mbed.cloud.sdk.internal.statistics.model.SuccessfulResponse) Call(retrofit2.Call) CloudCall(com.arm.mbed.cloud.sdk.common.CloudCaller.CloudCall) MetricsPeriodListOptions(com.arm.mbed.cloud.sdk.connect.model.MetricsPeriodListOptions) MetricsStartEndListOptions(com.arm.mbed.cloud.sdk.connect.model.MetricsStartEndListOptions) Date(java.util.Date) API(com.arm.mbed.cloud.sdk.annotations.API) Nullable(com.arm.mbed.cloud.sdk.annotations.Nullable)

Example 2 with SuccessfulResponse

use of com.arm.mbed.cloud.sdk.internal.statistics.model.SuccessfulResponse in project mbed-cloud-sdk-java by ARMmbed.

the class MetricAdapter method mapList.

/**
 * Maps a list of metrics.
 *
 * @param list
 *            of metrics.
 * @return list of metrics
 */
public static ListResponse<Metric> mapList(SuccessfulResponse list) {
    final SuccessfulResponse metricsList = list;
    final RespList<com.arm.mbed.cloud.sdk.internal.statistics.model.Metric> respList = new RespList<com.arm.mbed.cloud.sdk.internal.statistics.model.Metric>() {

        @Override
        public Boolean getHasMore() {
            return (metricsList == null) ? null : metricsList.isHasMore();
        }

        @Override
        public Integer getTotalCount() {
            return (metricsList == null) ? null : metricsList.getTotalCount();
        }

        @Override
        public String getAfter() {
            return (metricsList == null) ? null : metricsList.getAfter();
        }

        @Override
        public Integer getLimit() {
            return (metricsList == null) ? null : metricsList.getLimit();
        }

        @Override
        public String getOrder() {
            return Order.getDefault().getString();
        }

        @Override
        public List<com.arm.mbed.cloud.sdk.internal.statistics.model.Metric> getData() {
            return (metricsList == null) ? null : metricsList.getData();
        }
    };
    return GenericAdapter.mapList(respList, getMapper());
}
Also used : SuccessfulResponse(com.arm.mbed.cloud.sdk.internal.statistics.model.SuccessfulResponse) Metric(com.arm.mbed.cloud.sdk.connect.model.Metric) RespList(com.arm.mbed.cloud.sdk.common.GenericAdapter.RespList)

Aggregations

SuccessfulResponse (com.arm.mbed.cloud.sdk.internal.statistics.model.SuccessfulResponse)2 API (com.arm.mbed.cloud.sdk.annotations.API)1 Nullable (com.arm.mbed.cloud.sdk.annotations.Nullable)1 CloudCall (com.arm.mbed.cloud.sdk.common.CloudCaller.CloudCall)1 RespList (com.arm.mbed.cloud.sdk.common.GenericAdapter.RespList)1 Metric (com.arm.mbed.cloud.sdk.connect.model.Metric)1 MetricsPeriodListOptions (com.arm.mbed.cloud.sdk.connect.model.MetricsPeriodListOptions)1 MetricsStartEndListOptions (com.arm.mbed.cloud.sdk.connect.model.MetricsStartEndListOptions)1 Date (java.util.Date)1 Call (retrofit2.Call)1