diff --git a/tools/src/main/java/org/thingsboard/client/tools/RestClient.java b/tools/src/main/java/org/thingsboard/client/tools/RestClient.java index 9b64f2292a..179902d1d3 100644 --- a/tools/src/main/java/org/thingsboard/client/tools/RestClient.java +++ b/tools/src/main/java/org/thingsboard/client/tools/RestClient.java @@ -1690,82 +1690,72 @@ public class RestClient implements ClientHttpRequestInterceptor, Closeable { return RestJsonConverter.toTimeseries(timeseries); } - public List saveDeviceAttributes(String deviceId, String scope, JsonNode request) { - List attributes = restTemplate.exchange( - baseURL + "/api/plugins/telemetry/{deviceId}/{scope}", - HttpMethod.POST, - new HttpEntity<>(request), - new ParameterizedTypeReference>() { - }, - deviceId, - scope).getBody(); - - return RestJsonConverter.toAttributes(attributes); + public boolean saveDeviceAttributes(DeviceId deviceId, String scope, JsonNode request) { + return restTemplate + .postForEntity(baseURL + "/api/plugins/telemetry/{deviceId}/{scope}", request, Object.class, deviceId.getId().toString(), scope) + .getStatusCode() + .is2xxSuccessful(); } - public List saveEntityAttributesV1(EntityId entityId, String scope, JsonNode request) { - List attributes = restTemplate.exchange( - baseURL + "/api/plugins/telemetry/{entityType}/{entityId}/{scope}", - HttpMethod.POST, - new HttpEntity<>(request), - new ParameterizedTypeReference>() { - }, - entityId.getEntityType().name(), - entityId.getId().toString(), - scope).getBody(); - - return RestJsonConverter.toAttributes(attributes); + public boolean saveEntityAttributesV1(EntityId entityId, String scope, JsonNode request) { + return restTemplate + .postForEntity( + baseURL + "/api/plugins/telemetry/{entityType}/{entityId}/{scope}", + request, + Object.class, + entityId.getEntityType().name(), + entityId.getId().toString(), + scope) + .getStatusCode() + .is2xxSuccessful(); } - public List saveEntityAttributesV2(EntityId entityId, String scope, JsonNode request) { - List attributes = restTemplate.exchange( - baseURL + "/api/plugins/telemetry/{entityType}/{entityId}/attributes/{scope}", - HttpMethod.POST, - new HttpEntity<>(request), - new ParameterizedTypeReference>() { - }, - entityId.getEntityType().name(), - entityId.getId().toString(), - scope).getBody(); - - return RestJsonConverter.toAttributes(attributes); + public boolean saveEntityAttributesV2(EntityId entityId, String scope, JsonNode request) { + return restTemplate + .postForEntity( + baseURL + "/api/plugins/telemetry/{entityType}/{entityId}/attributes/{scope}", + request, + Object.class, + entityId.getEntityType().name(), + entityId.getId().toString(), + scope) + .getStatusCode() + .is2xxSuccessful(); } - public List saveEntityTelemetry(EntityId entityId, String scope, String requestBody) { - Map> timeseries = restTemplate.exchange( - baseURL + "/api/plugins/telemetry/{entityType}/{entityId}/timeseries/{scope}", - HttpMethod.POST, - new HttpEntity<>(requestBody), - new ParameterizedTypeReference>>() { - }, - entityId.getEntityType().name(), - entityId.getId().toString(), - scope).getBody(); - - return RestJsonConverter.toTimeseries(timeseries); + public boolean saveEntityTelemetry(EntityId entityId, String scope, JsonNode request) { + return restTemplate + .postForEntity( + baseURL + "/api/plugins/telemetry/{entityType}/{entityId}/timeseries/{scope}", + request, + Object.class, + entityId.getEntityType().name(), + entityId.getId().toString(), + scope) + .getStatusCode() + .is2xxSuccessful(); } - public List saveEntityTelemetryWithTTL(EntityId entityId, String scope, Long ttl, String requestBody) { - Map> timeseries = restTemplate.exchange( - baseURL + "/api/plugins/telemetry/{entityType}/{entityId}/timeseries/{scope}/{ttl}", - HttpMethod.POST, - new HttpEntity<>(requestBody), - new ParameterizedTypeReference>>() { - }, - entityId.getEntityType().name(), - entityId.getId().toString(), - scope, - ttl).getBody(); - - return RestJsonConverter.toTimeseries(timeseries); + public boolean saveEntityTelemetryWithTTL(EntityId entityId, String scope, Long ttl, JsonNode request) { + return restTemplate + .postForEntity( + baseURL + "/api/plugins/telemetry/{entityType}/{entityId}/timeseries/{scope}/{ttl}", + request, + Object.class, + entityId.getEntityType().name(), + entityId.getId().toString(), + scope, + ttl) + .getStatusCode() + .is2xxSuccessful(); } - public List deleteEntityTimeseries(EntityId entityId, - List keys, - boolean deleteAllDataForKeys, - Long startTs, - Long endTs, - boolean rewriteLatestIfDeleted) { + public boolean deleteEntityTimeseries(EntityId entityId, + List keys, + boolean deleteAllDataForKeys, + Long startTs, + Long endTs, + boolean rewriteLatestIfDeleted) { Map params = new HashMap<>(); params.put("entityType", entityId.getEntityType().name()); params.put("entityId", entityId.getId().toString()); @@ -1775,44 +1765,46 @@ public class RestClient implements ClientHttpRequestInterceptor, Closeable { params.put("endTs", endTs.toString()); params.put("rewriteLatestIfDeleted", String.valueOf(rewriteLatestIfDeleted)); - Map> timeseries = restTemplate.exchange( - baseURL + "/api/plugins/telemetry/{entityType}/{entityId}/timeseries/delete?keys={keys}&deleteAllDataForKeys={deleteAllDataForKeys}&startTs={startTs}&endTs={endTs}&rewriteLatestIfDeleted={rewriteLatestIfDeleted}", - HttpMethod.DELETE, - HttpEntity.EMPTY, - new ParameterizedTypeReference>>() { - }, - params).getBody(); + return restTemplate + .exchange( + baseURL + "/api/plugins/telemetry/{entityType}/{entityId}/timeseries/delete?keys={keys}&deleteAllDataForKeys={deleteAllDataForKeys}&startTs={startTs}&endTs={endTs}&rewriteLatestIfDeleted={rewriteLatestIfDeleted}", + HttpMethod.DELETE, + HttpEntity.EMPTY, + Object.class, + params) + .getStatusCode() + .is2xxSuccessful(); - return RestJsonConverter.toTimeseries(timeseries); } - public List deleteEntityAttributes(String deviceId, String scope, List keys) { - List attributes = restTemplate.exchange( - baseURL + "/api/plugins/telemetry/{deviceId}/{scope}?keys={keys}", - HttpMethod.DELETE, - HttpEntity.EMPTY, - new ParameterizedTypeReference>() { - }, - deviceId, - scope, - listToString(keys)).getBody(); - - return RestJsonConverter.toAttributes(attributes); + public boolean deleteEntityAttributes(DeviceId deviceId, String scope, List keys) { + return restTemplate + .exchange( + baseURL + "/api/plugins/telemetry/{deviceId}/{scope}?keys={keys}", + HttpMethod.DELETE, + HttpEntity.EMPTY, + Object.class, + deviceId.getId().toString(), + scope, + listToString(keys)) + .getStatusCode() + .is2xxSuccessful(); } - public List deleteEntityAttributes(EntityId entityId, String scope, List keys) { - List attributes = restTemplate.exchange( - baseURL + "/api/plugins/telemetry/{entityType}/{entityId}/{scope}?keys={keys}", - HttpMethod.DELETE, - HttpEntity.EMPTY, - new ParameterizedTypeReference>() { - }, - entityId.getEntityType().name(), - entityId.getId().toString(), - scope, - listToString(keys)).getBody(); + public boolean deleteEntityAttributes(EntityId entityId, String scope, List keys) { + return restTemplate + .exchange( + baseURL + "/api/plugins/telemetry/{entityType}/{entityId}/{scope}?keys={keys}", + HttpMethod.DELETE, + HttpEntity.EMPTY, + Object.class, + entityId.getEntityType().name(), + entityId.getId().toString(), + scope, + listToString(keys)) + .getStatusCode() + .is2xxSuccessful(); - return RestJsonConverter.toAttributes(attributes); } public Optional getTenantById(String tenantId) {