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,82 +1690,72 @@ public class RestClient implements ClientHttpRequestInterceptor, Closeable {
|
|||||||
return RestJsonConverter.toTimeseries(timeseries);
|
return RestJsonConverter.toTimeseries(timeseries);
|
||||||
}
|
}
|
||||||
|
|
||||||
public List<AttributeKvEntry> saveDeviceAttributes(String deviceId, String scope, JsonNode request) {
|
public boolean saveDeviceAttributes(DeviceId deviceId, String scope, JsonNode request) {
|
||||||
List<JsonNode> attributes = restTemplate.exchange(
|
return restTemplate
|
||||||
baseURL + "/api/plugins/telemetry/{deviceId}/{scope}",
|
.postForEntity(baseURL + "/api/plugins/telemetry/{deviceId}/{scope}", request, Object.class, deviceId.getId().toString(), scope)
|
||||||
HttpMethod.POST,
|
.getStatusCode()
|
||||||
new HttpEntity<>(request),
|
.is2xxSuccessful();
|
||||||
new ParameterizedTypeReference<List<JsonNode>>() {
|
|
||||||
},
|
|
||||||
deviceId,
|
|
||||||
scope).getBody();
|
|
||||||
|
|
||||||
return RestJsonConverter.toAttributes(attributes);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public List<AttributeKvEntry> saveEntityAttributesV1(EntityId entityId, String scope, JsonNode request) {
|
public boolean saveEntityAttributesV1(EntityId entityId, String scope, JsonNode request) {
|
||||||
List<JsonNode> attributes = restTemplate.exchange(
|
return restTemplate
|
||||||
baseURL + "/api/plugins/telemetry/{entityType}/{entityId}/{scope}",
|
.postForEntity(
|
||||||
HttpMethod.POST,
|
baseURL + "/api/plugins/telemetry/{entityType}/{entityId}/{scope}",
|
||||||
new HttpEntity<>(request),
|
request,
|
||||||
new ParameterizedTypeReference<List<JsonNode>>() {
|
Object.class,
|
||||||
},
|
entityId.getEntityType().name(),
|
||||||
entityId.getEntityType().name(),
|
entityId.getId().toString(),
|
||||||
entityId.getId().toString(),
|
scope)
|
||||||
scope).getBody();
|
.getStatusCode()
|
||||||
|
.is2xxSuccessful();
|
||||||
return RestJsonConverter.toAttributes(attributes);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public List<AttributeKvEntry> saveEntityAttributesV2(EntityId entityId, String scope, JsonNode request) {
|
public boolean saveEntityAttributesV2(EntityId entityId, String scope, JsonNode request) {
|
||||||
List<JsonNode> attributes = restTemplate.exchange(
|
return restTemplate
|
||||||
baseURL + "/api/plugins/telemetry/{entityType}/{entityId}/attributes/{scope}",
|
.postForEntity(
|
||||||
HttpMethod.POST,
|
baseURL + "/api/plugins/telemetry/{entityType}/{entityId}/attributes/{scope}",
|
||||||
new HttpEntity<>(request),
|
request,
|
||||||
new ParameterizedTypeReference<List<JsonNode>>() {
|
Object.class,
|
||||||
},
|
entityId.getEntityType().name(),
|
||||||
entityId.getEntityType().name(),
|
entityId.getId().toString(),
|
||||||
entityId.getId().toString(),
|
scope)
|
||||||
scope).getBody();
|
.getStatusCode()
|
||||||
|
.is2xxSuccessful();
|
||||||
return RestJsonConverter.toAttributes(attributes);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public List<TsKvEntry> saveEntityTelemetry(EntityId entityId, String scope, String requestBody) {
|
public boolean saveEntityTelemetry(EntityId entityId, String scope, JsonNode request) {
|
||||||
Map<String, List<JsonNode>> timeseries = restTemplate.exchange(
|
return restTemplate
|
||||||
baseURL + "/api/plugins/telemetry/{entityType}/{entityId}/timeseries/{scope}",
|
.postForEntity(
|
||||||
HttpMethod.POST,
|
baseURL + "/api/plugins/telemetry/{entityType}/{entityId}/timeseries/{scope}",
|
||||||
new HttpEntity<>(requestBody),
|
request,
|
||||||
new ParameterizedTypeReference<Map<String, List<JsonNode>>>() {
|
Object.class,
|
||||||
},
|
entityId.getEntityType().name(),
|
||||||
entityId.getEntityType().name(),
|
entityId.getId().toString(),
|
||||||
entityId.getId().toString(),
|
scope)
|
||||||
scope).getBody();
|
.getStatusCode()
|
||||||
|
.is2xxSuccessful();
|
||||||
return RestJsonConverter.toTimeseries(timeseries);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public List<TsKvEntry> saveEntityTelemetryWithTTL(EntityId entityId, String scope, Long ttl, String requestBody) {
|
public boolean saveEntityTelemetryWithTTL(EntityId entityId, String scope, Long ttl, JsonNode request) {
|
||||||
Map<String, List<JsonNode>> timeseries = restTemplate.exchange(
|
return restTemplate
|
||||||
baseURL + "/api/plugins/telemetry/{entityType}/{entityId}/timeseries/{scope}/{ttl}",
|
.postForEntity(
|
||||||
HttpMethod.POST,
|
baseURL + "/api/plugins/telemetry/{entityType}/{entityId}/timeseries/{scope}/{ttl}",
|
||||||
new HttpEntity<>(requestBody),
|
request,
|
||||||
new ParameterizedTypeReference<Map<String, List<JsonNode>>>() {
|
Object.class,
|
||||||
},
|
entityId.getEntityType().name(),
|
||||||
entityId.getEntityType().name(),
|
entityId.getId().toString(),
|
||||||
entityId.getId().toString(),
|
scope,
|
||||||
scope,
|
ttl)
|
||||||
ttl).getBody();
|
.getStatusCode()
|
||||||
|
.is2xxSuccessful();
|
||||||
return RestJsonConverter.toTimeseries(timeseries);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public List<TsKvEntry> deleteEntityTimeseries(EntityId entityId,
|
public boolean deleteEntityTimeseries(EntityId entityId,
|
||||||
List<String> keys,
|
List<String> keys,
|
||||||
boolean deleteAllDataForKeys,
|
boolean deleteAllDataForKeys,
|
||||||
Long startTs,
|
Long startTs,
|
||||||
Long endTs,
|
Long endTs,
|
||||||
boolean rewriteLatestIfDeleted) {
|
boolean rewriteLatestIfDeleted) {
|
||||||
Map<String, String> params = new HashMap<>();
|
Map<String, String> params = new HashMap<>();
|
||||||
params.put("entityType", entityId.getEntityType().name());
|
params.put("entityType", entityId.getEntityType().name());
|
||||||
params.put("entityId", entityId.getId().toString());
|
params.put("entityId", entityId.getId().toString());
|
||||||
@ -1775,44 +1765,46 @@ public class RestClient implements ClientHttpRequestInterceptor, Closeable {
|
|||||||
params.put("endTs", endTs.toString());
|
params.put("endTs", endTs.toString());
|
||||||
params.put("rewriteLatestIfDeleted", String.valueOf(rewriteLatestIfDeleted));
|
params.put("rewriteLatestIfDeleted", String.valueOf(rewriteLatestIfDeleted));
|
||||||
|
|
||||||
Map<String, List<JsonNode>> timeseries = restTemplate.exchange(
|
return restTemplate
|
||||||
baseURL + "/api/plugins/telemetry/{entityType}/{entityId}/timeseries/delete?keys={keys}&deleteAllDataForKeys={deleteAllDataForKeys}&startTs={startTs}&endTs={endTs}&rewriteLatestIfDeleted={rewriteLatestIfDeleted}",
|
.exchange(
|
||||||
HttpMethod.DELETE,
|
baseURL + "/api/plugins/telemetry/{entityType}/{entityId}/timeseries/delete?keys={keys}&deleteAllDataForKeys={deleteAllDataForKeys}&startTs={startTs}&endTs={endTs}&rewriteLatestIfDeleted={rewriteLatestIfDeleted}",
|
||||||
HttpEntity.EMPTY,
|
HttpMethod.DELETE,
|
||||||
new ParameterizedTypeReference<Map<String, List<JsonNode>>>() {
|
HttpEntity.EMPTY,
|
||||||
},
|
Object.class,
|
||||||
params).getBody();
|
params)
|
||||||
|
.getStatusCode()
|
||||||
|
.is2xxSuccessful();
|
||||||
|
|
||||||
return RestJsonConverter.toTimeseries(timeseries);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public List<AttributeKvEntry> deleteEntityAttributes(String deviceId, String scope, List<String> keys) {
|
public boolean deleteEntityAttributes(DeviceId deviceId, String scope, List<String> keys) {
|
||||||
List<JsonNode> attributes = restTemplate.exchange(
|
return restTemplate
|
||||||
baseURL + "/api/plugins/telemetry/{deviceId}/{scope}?keys={keys}",
|
.exchange(
|
||||||
HttpMethod.DELETE,
|
baseURL + "/api/plugins/telemetry/{deviceId}/{scope}?keys={keys}",
|
||||||
HttpEntity.EMPTY,
|
HttpMethod.DELETE,
|
||||||
new ParameterizedTypeReference<List<JsonNode>>() {
|
HttpEntity.EMPTY,
|
||||||
},
|
Object.class,
|
||||||
deviceId,
|
deviceId.getId().toString(),
|
||||||
scope,
|
scope,
|
||||||
listToString(keys)).getBody();
|
listToString(keys))
|
||||||
|
.getStatusCode()
|
||||||
return RestJsonConverter.toAttributes(attributes);
|
.is2xxSuccessful();
|
||||||
}
|
}
|
||||||
|
|
||||||
public List<AttributeKvEntry> deleteEntityAttributes(EntityId entityId, String scope, List<String> keys) {
|
public boolean deleteEntityAttributes(EntityId entityId, String scope, List<String> keys) {
|
||||||
List<JsonNode> attributes = restTemplate.exchange(
|
return restTemplate
|
||||||
baseURL + "/api/plugins/telemetry/{entityType}/{entityId}/{scope}?keys={keys}",
|
.exchange(
|
||||||
HttpMethod.DELETE,
|
baseURL + "/api/plugins/telemetry/{entityType}/{entityId}/{scope}?keys={keys}",
|
||||||
HttpEntity.EMPTY,
|
HttpMethod.DELETE,
|
||||||
new ParameterizedTypeReference<List<JsonNode>>() {
|
HttpEntity.EMPTY,
|
||||||
},
|
Object.class,
|
||||||
entityId.getEntityType().name(),
|
entityId.getEntityType().name(),
|
||||||
entityId.getId().toString(),
|
entityId.getId().toString(),
|
||||||
scope,
|
scope,
|
||||||
listToString(keys)).getBody();
|
listToString(keys))
|
||||||
|
.getStatusCode()
|
||||||
|
.is2xxSuccessful();
|
||||||
|
|
||||||
return RestJsonConverter.toAttributes(attributes);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public Optional<Tenant> getTenantById(String tenantId) {
|
public Optional<Tenant> getTenantById(String tenantId) {
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user