Search in sources :

Example 1 with TsData

use of org.thingsboard.server.extensions.core.plugin.telemetry.TsData in project thingsboard by thingsboard.

the class TelemetryRestMsgHandler method getTsKvListCallback.

private PluginCallback<List<TsKvEntry>> getTsKvListCallback(final PluginRestMsg msg) {
    return new PluginCallback<List<TsKvEntry>>() {

        @Override
        public void onSuccess(PluginContext ctx, List<TsKvEntry> data) {
            Map<String, List<TsData>> result = new LinkedHashMap<>();
            for (TsKvEntry entry : data) {
                List<TsData> vList = result.get(entry.getKey());
                if (vList == null) {
                    vList = new ArrayList<>();
                    result.put(entry.getKey(), vList);
                }
                vList.add(new TsData(entry.getTs(), entry.getValueAsString()));
            }
            msg.getResponseHolder().setResult(new ResponseEntity<>(result, HttpStatus.OK));
        }

        @Override
        public void onFailure(PluginContext ctx, Exception e) {
            log.error("Failed to fetch historical data", e);
            handleError(e, msg, HttpStatus.INTERNAL_SERVER_ERROR);
        }
    };
}
Also used : PluginContext(org.thingsboard.server.extensions.api.plugins.PluginContext) TsData(org.thingsboard.server.extensions.core.plugin.telemetry.TsData) ServletException(javax.servlet.ServletException) UncheckedApiException(org.thingsboard.server.extensions.api.exception.UncheckedApiException) JsonSyntaxException(com.google.gson.JsonSyntaxException) IOException(java.io.IOException) InvalidParametersException(org.thingsboard.server.extensions.api.exception.InvalidParametersException) PluginCallback(org.thingsboard.server.extensions.api.plugins.PluginCallback)

Aggregations

JsonSyntaxException (com.google.gson.JsonSyntaxException)1 IOException (java.io.IOException)1 ServletException (javax.servlet.ServletException)1 InvalidParametersException (org.thingsboard.server.extensions.api.exception.InvalidParametersException)1 UncheckedApiException (org.thingsboard.server.extensions.api.exception.UncheckedApiException)1 PluginCallback (org.thingsboard.server.extensions.api.plugins.PluginCallback)1 PluginContext (org.thingsboard.server.extensions.api.plugins.PluginContext)1 TsData (org.thingsboard.server.extensions.core.plugin.telemetry.TsData)1