Feature/rest client (#2368)
* refactored URLs * refactored * refactored * refactored * refactored * refactored rest client * changed executorService from RestClient * refactored rest client and JsonConverter * refactored rest client
This commit is contained in:
parent
23919b3d5f
commit
fbed56555f
@ -1690,77 +1690,67 @@ public class RestClient implements ClientHttpRequestInterceptor, Closeable {
|
||||
return RestJsonConverter.toTimeseries(timeseries);
|
||||
}
|
||||
|
||||
public List<AttributeKvEntry> saveDeviceAttributes(String deviceId, String scope, JsonNode request) {
|
||||
List<JsonNode> attributes = restTemplate.exchange(
|
||||
baseURL + "/api/plugins/telemetry/{deviceId}/{scope}",
|
||||
HttpMethod.POST,
|
||||
new HttpEntity<>(request),
|
||||
new ParameterizedTypeReference<List<JsonNode>>() {
|
||||
},
|
||||
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<AttributeKvEntry> saveEntityAttributesV1(EntityId entityId, String scope, JsonNode request) {
|
||||
List<JsonNode> attributes = restTemplate.exchange(
|
||||
public boolean saveEntityAttributesV1(EntityId entityId, String scope, JsonNode request) {
|
||||
return restTemplate
|
||||
.postForEntity(
|
||||
baseURL + "/api/plugins/telemetry/{entityType}/{entityId}/{scope}",
|
||||
HttpMethod.POST,
|
||||
new HttpEntity<>(request),
|
||||
new ParameterizedTypeReference<List<JsonNode>>() {
|
||||
},
|
||||
request,
|
||||
Object.class,
|
||||
entityId.getEntityType().name(),
|
||||
entityId.getId().toString(),
|
||||
scope).getBody();
|
||||
|
||||
return RestJsonConverter.toAttributes(attributes);
|
||||
scope)
|
||||
.getStatusCode()
|
||||
.is2xxSuccessful();
|
||||
}
|
||||
|
||||
public List<AttributeKvEntry> saveEntityAttributesV2(EntityId entityId, String scope, JsonNode request) {
|
||||
List<JsonNode> attributes = restTemplate.exchange(
|
||||
public boolean saveEntityAttributesV2(EntityId entityId, String scope, JsonNode request) {
|
||||
return restTemplate
|
||||
.postForEntity(
|
||||
baseURL + "/api/plugins/telemetry/{entityType}/{entityId}/attributes/{scope}",
|
||||
HttpMethod.POST,
|
||||
new HttpEntity<>(request),
|
||||
new ParameterizedTypeReference<List<JsonNode>>() {
|
||||
},
|
||||
request,
|
||||
Object.class,
|
||||
entityId.getEntityType().name(),
|
||||
entityId.getId().toString(),
|
||||
scope).getBody();
|
||||
|
||||
return RestJsonConverter.toAttributes(attributes);
|
||||
scope)
|
||||
.getStatusCode()
|
||||
.is2xxSuccessful();
|
||||
}
|
||||
|
||||
public List<TsKvEntry> saveEntityTelemetry(EntityId entityId, String scope, String requestBody) {
|
||||
Map<String, List<JsonNode>> timeseries = restTemplate.exchange(
|
||||
public boolean saveEntityTelemetry(EntityId entityId, String scope, JsonNode request) {
|
||||
return restTemplate
|
||||
.postForEntity(
|
||||
baseURL + "/api/plugins/telemetry/{entityType}/{entityId}/timeseries/{scope}",
|
||||
HttpMethod.POST,
|
||||
new HttpEntity<>(requestBody),
|
||||
new ParameterizedTypeReference<Map<String, List<JsonNode>>>() {
|
||||
},
|
||||
request,
|
||||
Object.class,
|
||||
entityId.getEntityType().name(),
|
||||
entityId.getId().toString(),
|
||||
scope).getBody();
|
||||
|
||||
return RestJsonConverter.toTimeseries(timeseries);
|
||||
scope)
|
||||
.getStatusCode()
|
||||
.is2xxSuccessful();
|
||||
}
|
||||
|
||||
public List<TsKvEntry> saveEntityTelemetryWithTTL(EntityId entityId, String scope, Long ttl, String requestBody) {
|
||||
Map<String, List<JsonNode>> timeseries = restTemplate.exchange(
|
||||
public boolean saveEntityTelemetryWithTTL(EntityId entityId, String scope, Long ttl, JsonNode request) {
|
||||
return restTemplate
|
||||
.postForEntity(
|
||||
baseURL + "/api/plugins/telemetry/{entityType}/{entityId}/timeseries/{scope}/{ttl}",
|
||||
HttpMethod.POST,
|
||||
new HttpEntity<>(requestBody),
|
||||
new ParameterizedTypeReference<Map<String, List<JsonNode>>>() {
|
||||
},
|
||||
request,
|
||||
Object.class,
|
||||
entityId.getEntityType().name(),
|
||||
entityId.getId().toString(),
|
||||
scope,
|
||||
ttl).getBody();
|
||||
|
||||
return RestJsonConverter.toTimeseries(timeseries);
|
||||
ttl)
|
||||
.getStatusCode()
|
||||
.is2xxSuccessful();
|
||||
}
|
||||
|
||||
public List<TsKvEntry> deleteEntityTimeseries(EntityId entityId,
|
||||
public boolean deleteEntityTimeseries(EntityId entityId,
|
||||
List<String> keys,
|
||||
boolean deleteAllDataForKeys,
|
||||
Long startTs,
|
||||
@ -1775,44 +1765,46 @@ public class RestClient implements ClientHttpRequestInterceptor, Closeable {
|
||||
params.put("endTs", endTs.toString());
|
||||
params.put("rewriteLatestIfDeleted", String.valueOf(rewriteLatestIfDeleted));
|
||||
|
||||
Map<String, List<JsonNode>> timeseries = restTemplate.exchange(
|
||||
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,
|
||||
new ParameterizedTypeReference<Map<String, List<JsonNode>>>() {
|
||||
},
|
||||
params).getBody();
|
||||
Object.class,
|
||||
params)
|
||||
.getStatusCode()
|
||||
.is2xxSuccessful();
|
||||
|
||||
return RestJsonConverter.toTimeseries(timeseries);
|
||||
}
|
||||
|
||||
public List<AttributeKvEntry> deleteEntityAttributes(String deviceId, String scope, List<String> keys) {
|
||||
List<JsonNode> attributes = restTemplate.exchange(
|
||||
public boolean deleteEntityAttributes(DeviceId deviceId, String scope, List<String> keys) {
|
||||
return restTemplate
|
||||
.exchange(
|
||||
baseURL + "/api/plugins/telemetry/{deviceId}/{scope}?keys={keys}",
|
||||
HttpMethod.DELETE,
|
||||
HttpEntity.EMPTY,
|
||||
new ParameterizedTypeReference<List<JsonNode>>() {
|
||||
},
|
||||
deviceId,
|
||||
Object.class,
|
||||
deviceId.getId().toString(),
|
||||
scope,
|
||||
listToString(keys)).getBody();
|
||||
|
||||
return RestJsonConverter.toAttributes(attributes);
|
||||
listToString(keys))
|
||||
.getStatusCode()
|
||||
.is2xxSuccessful();
|
||||
}
|
||||
|
||||
public List<AttributeKvEntry> deleteEntityAttributes(EntityId entityId, String scope, List<String> keys) {
|
||||
List<JsonNode> attributes = restTemplate.exchange(
|
||||
public boolean deleteEntityAttributes(EntityId entityId, String scope, List<String> keys) {
|
||||
return restTemplate
|
||||
.exchange(
|
||||
baseURL + "/api/plugins/telemetry/{entityType}/{entityId}/{scope}?keys={keys}",
|
||||
HttpMethod.DELETE,
|
||||
HttpEntity.EMPTY,
|
||||
new ParameterizedTypeReference<List<JsonNode>>() {
|
||||
},
|
||||
Object.class,
|
||||
entityId.getEntityType().name(),
|
||||
entityId.getId().toString(),
|
||||
scope,
|
||||
listToString(keys)).getBody();
|
||||
listToString(keys))
|
||||
.getStatusCode()
|
||||
.is2xxSuccessful();
|
||||
|
||||
return RestJsonConverter.toAttributes(attributes);
|
||||
}
|
||||
|
||||
public Optional<Tenant> getTenantById(String tenantId) {
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user