|
|
|
@ -31,7 +31,7 @@ import org.springframework.http.client.support.HttpRequestWrapper; |
|
|
|
import org.springframework.util.StringUtils; |
|
|
|
import org.springframework.web.client.HttpClientErrorException; |
|
|
|
import org.springframework.web.client.RestTemplate; |
|
|
|
import org.springframework.web.context.request.async.DeferredResult; |
|
|
|
import org.thingsboard.client.tools.utils.RestJsonConverter; |
|
|
|
import org.thingsboard.server.common.data.AdminSettings; |
|
|
|
import org.thingsboard.server.common.data.ClaimRequest; |
|
|
|
import org.thingsboard.server.common.data.Customer; |
|
|
|
@ -57,6 +57,8 @@ import org.thingsboard.server.common.data.id.CustomerId; |
|
|
|
import org.thingsboard.server.common.data.id.DashboardId; |
|
|
|
import org.thingsboard.server.common.data.id.DeviceId; |
|
|
|
import org.thingsboard.server.common.data.id.EntityId; |
|
|
|
import org.thingsboard.server.common.data.kv.AttributeKvEntry; |
|
|
|
import org.thingsboard.server.common.data.kv.TsKvEntry; |
|
|
|
import org.thingsboard.server.common.data.page.TextPageData; |
|
|
|
import org.thingsboard.server.common.data.page.TextPageLink; |
|
|
|
import org.thingsboard.server.common.data.page.TimePageData; |
|
|
|
@ -74,6 +76,7 @@ import org.thingsboard.server.common.data.security.model.UserPasswordPolicy; |
|
|
|
import org.thingsboard.server.common.data.widget.WidgetType; |
|
|
|
import org.thingsboard.server.common.data.widget.WidgetsBundle; |
|
|
|
|
|
|
|
import java.io.Closeable; |
|
|
|
import java.io.IOException; |
|
|
|
import java.net.URI; |
|
|
|
import java.util.Collections; |
|
|
|
@ -81,19 +84,23 @@ import java.util.HashMap; |
|
|
|
import java.util.List; |
|
|
|
import java.util.Map; |
|
|
|
import java.util.Optional; |
|
|
|
import java.util.concurrent.ExecutorService; |
|
|
|
import java.util.concurrent.Executors; |
|
|
|
import java.util.concurrent.Future; |
|
|
|
|
|
|
|
import static org.springframework.util.StringUtils.isEmpty; |
|
|
|
|
|
|
|
/** |
|
|
|
* @author Andrew Shvayka |
|
|
|
*/ |
|
|
|
public class RestClient implements ClientHttpRequestInterceptor { |
|
|
|
public class RestClient implements ClientHttpRequestInterceptor, Closeable { |
|
|
|
private static final String JWT_TOKEN_HEADER_PARAM = "X-Authorization"; |
|
|
|
protected final RestTemplate restTemplate; |
|
|
|
protected final String baseURL; |
|
|
|
private String token; |
|
|
|
private String refreshToken; |
|
|
|
private final ObjectMapper objectMapper = new ObjectMapper(); |
|
|
|
private ExecutorService service = Executors.newWorkStealingPool(10); |
|
|
|
|
|
|
|
|
|
|
|
protected static final String ACTIVATE_TOKEN_REGEX = "/api/noauth/activate?activateToken="; |
|
|
|
@ -256,6 +263,7 @@ public class RestClient implements ClientHttpRequestInterceptor { |
|
|
|
} |
|
|
|
return restTemplate.postForEntity(baseURL + deviceCreationUrl, device, Device.class, params).getBody(); |
|
|
|
} |
|
|
|
|
|
|
|
public Asset createAsset(Asset asset) { |
|
|
|
return restTemplate.postForEntity(baseURL + "/api/asset", asset, Asset.class).getBody(); |
|
|
|
} |
|
|
|
@ -418,17 +426,17 @@ public class RestClient implements ClientHttpRequestInterceptor { |
|
|
|
} |
|
|
|
|
|
|
|
public void ackAlarm(String alarmId) { |
|
|
|
restTemplate.postForObject(baseURL + "/api/alarm/{alarmId}/ack", new Object(), Object.class, alarmId); |
|
|
|
restTemplate.postForLocation(baseURL + "/api/alarm/{alarmId}/ack", null, alarmId); |
|
|
|
} |
|
|
|
|
|
|
|
public void clearAlarm(String alarmId) { |
|
|
|
restTemplate.postForObject(baseURL + "/api/alarm/{alarmId}/clear", new Object(), Object.class, alarmId); |
|
|
|
restTemplate.postForLocation(baseURL + "/api/alarm/{alarmId}/clear", null, alarmId); |
|
|
|
} |
|
|
|
|
|
|
|
public TimePageData<AlarmInfo> getAlarms(String entityType, String entityId, String searchStatus, String status, TimePageLink pageLink, Boolean fetchOriginator) { |
|
|
|
public TimePageData<AlarmInfo> getAlarms(EntityId entityId, String searchStatus, String status, TimePageLink pageLink, Boolean fetchOriginator) { |
|
|
|
Map<String, String> params = new HashMap<>(); |
|
|
|
params.put("entityType", entityType); |
|
|
|
params.put("entityId", entityId); |
|
|
|
params.put("entityType", entityId.getEntityType().name()); |
|
|
|
params.put("entityId", entityId.getId().toString()); |
|
|
|
params.put("searchStatus", searchStatus); |
|
|
|
params.put("status", status); |
|
|
|
params.put("fetchOriginator", String.valueOf(fetchOriginator)); |
|
|
|
@ -471,10 +479,10 @@ public class RestClient implements ClientHttpRequestInterceptor { |
|
|
|
return urlParams; |
|
|
|
} |
|
|
|
|
|
|
|
public Optional<AlarmSeverity> getHighestAlarmSeverity(String entityType, String entityId, String searchStatus, String status) { |
|
|
|
public Optional<AlarmSeverity> getHighestAlarmSeverity(EntityId entityId, String searchStatus, String status) { |
|
|
|
Map<String, String> params = new HashMap<>(); |
|
|
|
params.put("entityType", entityType); |
|
|
|
params.put("entityId", entityId); |
|
|
|
params.put("entityType", entityId.getEntityType().name()); |
|
|
|
params.put("entityId", entityId.getId().toString()); |
|
|
|
params.put("searchStatus", searchStatus); |
|
|
|
params.put("status", status); |
|
|
|
try { |
|
|
|
@ -597,14 +605,14 @@ public class RestClient implements ClientHttpRequestInterceptor { |
|
|
|
return assets.getBody(); |
|
|
|
} |
|
|
|
|
|
|
|
public List<Asset> getAssetsByIds(String[] assetIds) { |
|
|
|
public List<Asset> getAssetsByIds(List<String> assetIds) { |
|
|
|
return restTemplate.exchange( |
|
|
|
baseURL + "/api/assets?assetIds={assetIds}", |
|
|
|
HttpMethod.GET, |
|
|
|
HttpEntity.EMPTY, |
|
|
|
new ParameterizedTypeReference<List<Asset>>() { |
|
|
|
}, |
|
|
|
String.join(",", assetIds)).getBody(); |
|
|
|
listToString(assetIds)).getBody(); |
|
|
|
} |
|
|
|
|
|
|
|
public List<Asset> findByQuery(AssetSearchQuery query) { |
|
|
|
@ -657,10 +665,10 @@ public class RestClient implements ClientHttpRequestInterceptor { |
|
|
|
return auditLog.getBody(); |
|
|
|
} |
|
|
|
|
|
|
|
public TimePageData<AuditLog> getAuditLogsByEntityId(String entityType, String entityId, String actionTypes, TimePageLink pageLink) { |
|
|
|
public TimePageData<AuditLog> getAuditLogsByEntityId(EntityId entityId, String actionTypes, TimePageLink pageLink) { |
|
|
|
Map<String, String> params = new HashMap<>(); |
|
|
|
params.put("entityType", entityType); |
|
|
|
params.put("entityId", entityId); |
|
|
|
params.put("entityType", entityId.getEntityType().name()); |
|
|
|
params.put("entityId", entityId.getId().toString()); |
|
|
|
params.put("actionTypes", actionTypes); |
|
|
|
addPageLinkToParam(params, pageLink); |
|
|
|
|
|
|
|
@ -700,14 +708,14 @@ public class RestClient implements ClientHttpRequestInterceptor { |
|
|
|
} |
|
|
|
|
|
|
|
public void logout() { |
|
|
|
restTemplate.exchange(URI.create(baseURL + "/api/auth/logout"), HttpMethod.POST, HttpEntity.EMPTY, Object.class); |
|
|
|
restTemplate.postForLocation(baseURL + "/api/auth/logout", null); |
|
|
|
} |
|
|
|
|
|
|
|
public void changePassword(String currentPassword, String newPassword) { |
|
|
|
ObjectNode changePasswordRequest = objectMapper.createObjectNode(); |
|
|
|
changePasswordRequest.put("currentPassword", currentPassword); |
|
|
|
changePasswordRequest.put("newPassword", newPassword); |
|
|
|
restTemplate.exchange(URI.create(baseURL + "/api/auth/changePassword"), HttpMethod.POST, new HttpEntity<>(changePasswordRequest), Object.class); |
|
|
|
restTemplate.postForLocation(baseURL + "/api/auth/changePassword", changePasswordRequest); |
|
|
|
} |
|
|
|
|
|
|
|
public Optional<UserPasswordPolicy> getUserPasswordPolicy() { |
|
|
|
@ -731,7 +739,7 @@ public class RestClient implements ClientHttpRequestInterceptor { |
|
|
|
public void requestResetPasswordByEmail(String email) { |
|
|
|
ObjectNode resetPasswordByEmailRequest = objectMapper.createObjectNode(); |
|
|
|
resetPasswordByEmailRequest.put("email", email); |
|
|
|
restTemplate.exchange(URI.create(baseURL + "/api/noauth/resetPasswordByEmail"), HttpMethod.POST, new HttpEntity<>(resetPasswordByEmailRequest), Object.class); |
|
|
|
restTemplate.postForLocation(baseURL + "/api/noauth/resetPasswordByEmail", resetPasswordByEmailRequest); |
|
|
|
} |
|
|
|
|
|
|
|
public Optional<JsonNode> activateUser(String userId, String password) { |
|
|
|
@ -772,14 +780,14 @@ public class RestClient implements ClientHttpRequestInterceptor { |
|
|
|
componentType).getBody(); |
|
|
|
} |
|
|
|
|
|
|
|
public List<ComponentDescriptor> getComponentDescriptorsByTypes(String[] componentTypes) { |
|
|
|
public List<ComponentDescriptor> getComponentDescriptorsByTypes(List<String> componentTypes) { |
|
|
|
return restTemplate.exchange( |
|
|
|
baseURL + "/api/components?componentTypes={componentTypes}", |
|
|
|
HttpMethod.GET, |
|
|
|
HttpEntity.EMPTY, |
|
|
|
new ParameterizedTypeReference<List<ComponentDescriptor>>() { |
|
|
|
}, |
|
|
|
String.join(",", componentTypes)).getBody(); |
|
|
|
listToString(componentTypes)).getBody(); |
|
|
|
} |
|
|
|
|
|
|
|
public Optional<Customer> getCustomerById(String customerId) { |
|
|
|
@ -915,7 +923,7 @@ public class RestClient implements ClientHttpRequestInterceptor { |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
public Optional<Dashboard> updateDashboardCustomers(String dashboardId, String[] customerIds) { |
|
|
|
public Optional<Dashboard> updateDashboardCustomers(String dashboardId, List<String> customerIds) { |
|
|
|
try { |
|
|
|
ResponseEntity<Dashboard> dashboard = restTemplate.postForEntity(baseURL + "/api/dashboard/{dashboardId}/customers", customerIds, Dashboard.class, dashboardId); |
|
|
|
return Optional.ofNullable(dashboard.getBody()); |
|
|
|
@ -928,7 +936,7 @@ public class RestClient implements ClientHttpRequestInterceptor { |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
public Optional<Dashboard> addDashboardCustomers(String dashboardId, String[] customerIds) { |
|
|
|
public Optional<Dashboard> addDashboardCustomers(String dashboardId, List<String> customerIds) { |
|
|
|
try { |
|
|
|
ResponseEntity<Dashboard> dashboard = restTemplate.postForEntity(baseURL + "/api/dashboard/{dashboardId}/customers/add", customerIds, Dashboard.class, dashboardId); |
|
|
|
return Optional.ofNullable(dashboard.getBody()); |
|
|
|
@ -941,7 +949,7 @@ public class RestClient implements ClientHttpRequestInterceptor { |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
public Optional<Dashboard> removeDashboardCustomers(String dashboardId, String[] customerIds) { |
|
|
|
public Optional<Dashboard> removeDashboardCustomers(String dashboardId, List<String> customerIds) { |
|
|
|
try { |
|
|
|
ResponseEntity<Dashboard> dashboard = restTemplate.postForEntity(baseURL + "/api/dashboard/{dashboardId}/customers/remove", customerIds, Dashboard.class, dashboardId); |
|
|
|
return Optional.ofNullable(dashboard.getBody()); |
|
|
|
@ -1135,12 +1143,12 @@ public class RestClient implements ClientHttpRequestInterceptor { |
|
|
|
.getBody(); |
|
|
|
} |
|
|
|
|
|
|
|
public List<Device> getDevicesByIds(String[] deviceIds) { |
|
|
|
public List<Device> getDevicesByIds(List<String> deviceIds) { |
|
|
|
return restTemplate.exchange(baseURL + "/api/devices?deviceIds={deviceIds}", |
|
|
|
HttpMethod.GET, |
|
|
|
HttpEntity.EMPTY, new ParameterizedTypeReference<List<Device>>() { |
|
|
|
}, |
|
|
|
String.join(",", deviceIds)).getBody(); |
|
|
|
listToString(deviceIds)).getBody(); |
|
|
|
} |
|
|
|
|
|
|
|
public List<Device> findByQuery(DeviceSearchQuery query) { |
|
|
|
@ -1161,28 +1169,22 @@ public class RestClient implements ClientHttpRequestInterceptor { |
|
|
|
}).getBody(); |
|
|
|
} |
|
|
|
|
|
|
|
public DeferredResult<ResponseEntity> claimDevice(String deviceName, ClaimRequest claimRequest) { |
|
|
|
public JsonNode claimDevice(String deviceName, ClaimRequest claimRequest) { |
|
|
|
return restTemplate.exchange( |
|
|
|
baseURL + "/api/customer/device/{deviceName}/claim", |
|
|
|
HttpMethod.POST, |
|
|
|
new HttpEntity<>(claimRequest), |
|
|
|
new ParameterizedTypeReference<DeferredResult<ResponseEntity>>() { |
|
|
|
new ParameterizedTypeReference<JsonNode>() { |
|
|
|
}, |
|
|
|
deviceName).getBody(); |
|
|
|
} |
|
|
|
|
|
|
|
public DeferredResult<ResponseEntity> reClaimDevice(String deviceName) { |
|
|
|
return restTemplate.exchange( |
|
|
|
baseURL + "/api/customer/device/{deviceName}/claim", |
|
|
|
HttpMethod.DELETE, |
|
|
|
HttpEntity.EMPTY, |
|
|
|
new ParameterizedTypeReference<DeferredResult<ResponseEntity>>() { |
|
|
|
}, |
|
|
|
deviceName).getBody(); |
|
|
|
public void reClaimDevice(String deviceName) { |
|
|
|
restTemplate.delete(baseURL + "/api/customer/device/{deviceName}/claim", deviceName); |
|
|
|
} |
|
|
|
|
|
|
|
public void saveRelation(EntityRelation relation) { |
|
|
|
restTemplate.postForEntity(baseURL + "/api/relation", relation, Object.class); |
|
|
|
restTemplate.postForLocation(baseURL + "/api/relation", null); |
|
|
|
} |
|
|
|
|
|
|
|
public void deleteRelation(String fromId, String fromType, String relationType, String relationTypeGroup, String toId, String toType) { |
|
|
|
@ -1196,8 +1198,8 @@ public class RestClient implements ClientHttpRequestInterceptor { |
|
|
|
restTemplate.delete(baseURL + "/api/relation?fromId={fromId}&fromType={fromType}&relationType={relationType}&relationTypeGroup={relationTypeGroup}&toId={toId}&toType={toType}", params); |
|
|
|
} |
|
|
|
|
|
|
|
public void deleteRelations(String entityId, String entityType) { |
|
|
|
restTemplate.delete(baseURL + "/api/relations?entityId={entityId}&entityType={entityType}", entityId, entityType); |
|
|
|
public void deleteRelations(EntityId entityId) { |
|
|
|
restTemplate.delete(baseURL + "/api/relations?entityId={entityId}&entityType={entityType}", entityId.getId().toString(), entityId.getEntityType().name()); |
|
|
|
} |
|
|
|
|
|
|
|
public Optional<EntityRelation> getRelation(String fromId, String fromType, String relationType, String relationTypeGroup, String toId, String toType) { |
|
|
|
@ -1448,10 +1450,10 @@ public class RestClient implements ClientHttpRequestInterceptor { |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
public TimePageData<Event> getEvents(String entityType, String entityId, String eventType, String tenantId, TimePageLink pageLink) { |
|
|
|
public TimePageData<Event> getEvents(EntityId entityId, String eventType, String tenantId, TimePageLink pageLink) { |
|
|
|
Map<String, String> params = new HashMap<>(); |
|
|
|
params.put("entityType", entityType); |
|
|
|
params.put("entityId", entityId); |
|
|
|
params.put("entityType", entityId.getEntityType().name()); |
|
|
|
params.put("entityId", entityId.getId().toString()); |
|
|
|
params.put("eventType", eventType); |
|
|
|
params.put("tenantId", tenantId); |
|
|
|
addPageLinkToParam(params, pageLink); |
|
|
|
@ -1465,10 +1467,10 @@ public class RestClient implements ClientHttpRequestInterceptor { |
|
|
|
params).getBody(); |
|
|
|
} |
|
|
|
|
|
|
|
public TimePageData<Event> getEvents(String entityType, String entityId, String tenantId, TimePageLink pageLink) { |
|
|
|
public TimePageData<Event> getEvents(EntityId entityId, String tenantId, TimePageLink pageLink) { |
|
|
|
Map<String, String> params = new HashMap<>(); |
|
|
|
params.put("entityType", entityType); |
|
|
|
params.put("entityId", entityId); |
|
|
|
params.put("entityType", entityId.getEntityType().name()); |
|
|
|
params.put("entityId", entityId.getId().toString()); |
|
|
|
params.put("tenantId", tenantId); |
|
|
|
addPageLinkToParam(params, pageLink); |
|
|
|
|
|
|
|
@ -1481,22 +1483,16 @@ public class RestClient implements ClientHttpRequestInterceptor { |
|
|
|
params).getBody(); |
|
|
|
} |
|
|
|
|
|
|
|
public DeferredResult<ResponseEntity> handleOneWayDeviceRPCRequest(String deviceId, String requestBody) { |
|
|
|
return restTemplate.exchange( |
|
|
|
baseURL + "/api/plugins/rpc/oneway/{deviceId}", |
|
|
|
HttpMethod.POST, |
|
|
|
new HttpEntity<>(requestBody), |
|
|
|
new ParameterizedTypeReference<DeferredResult<ResponseEntity>>() { |
|
|
|
}, |
|
|
|
deviceId).getBody(); |
|
|
|
public void handleOneWayDeviceRPCRequest(String deviceId, JsonNode requestBody) { |
|
|
|
restTemplate.postForLocation(baseURL + "/api/plugins/rpc/oneway/{deviceId}", requestBody, deviceId); |
|
|
|
} |
|
|
|
|
|
|
|
public DeferredResult<ResponseEntity> handleTwoWayDeviceRPCRequest(String deviceId, String requestBody) { |
|
|
|
public JsonNode handleTwoWayDeviceRPCRequest(String deviceId, JsonNode requestBody) { |
|
|
|
return restTemplate.exchange( |
|
|
|
baseURL + "/api/plugins/rpc/twoway/{deviceId}", |
|
|
|
HttpMethod.POST, |
|
|
|
new HttpEntity<>(requestBody), |
|
|
|
new ParameterizedTypeReference<DeferredResult<ResponseEntity>>() { |
|
|
|
new ParameterizedTypeReference<JsonNode>() { |
|
|
|
}, |
|
|
|
deviceId).getBody(); |
|
|
|
} |
|
|
|
@ -1590,206 +1586,233 @@ public class RestClient implements ClientHttpRequestInterceptor { |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
public DeferredResult<ResponseEntity> getAttributeKeys(String entityType, String entityId) { |
|
|
|
public List<String> getAttributeKeys(EntityId entityId) { |
|
|
|
return restTemplate.exchange( |
|
|
|
baseURL + "/api/plugins/telemetry/{entityType}/{entityId}/keys/attributes", |
|
|
|
HttpMethod.GET, |
|
|
|
HttpEntity.EMPTY, |
|
|
|
new ParameterizedTypeReference<DeferredResult<ResponseEntity>>() { |
|
|
|
new ParameterizedTypeReference<List<String>>() { |
|
|
|
}, |
|
|
|
entityType, |
|
|
|
entityId).getBody(); |
|
|
|
entityId.getEntityType().name(), |
|
|
|
entityId.getId().toString()).getBody(); |
|
|
|
} |
|
|
|
|
|
|
|
public DeferredResult<ResponseEntity> getAttributeKeysByScope(String entityType, String entityId, String scope) { |
|
|
|
public List<String> getAttributeKeysByScope(EntityId entityId, String scope) { |
|
|
|
return restTemplate.exchange( |
|
|
|
baseURL + "/api/plugins/telemetry/{entityType}/{entityId}/keys/attributes/{scope}", |
|
|
|
HttpMethod.GET, |
|
|
|
HttpEntity.EMPTY, |
|
|
|
new ParameterizedTypeReference<DeferredResult<ResponseEntity>>() { |
|
|
|
new ParameterizedTypeReference<List<String>>() { |
|
|
|
}, |
|
|
|
entityType, |
|
|
|
entityId, |
|
|
|
entityId.getEntityType().name(), |
|
|
|
entityId.getId().toString(), |
|
|
|
scope).getBody(); |
|
|
|
} |
|
|
|
|
|
|
|
public DeferredResult<ResponseEntity> getAttributesResponseEntity(String entityType, String entityId, String keys) { |
|
|
|
return restTemplate.exchange( |
|
|
|
public List<AttributeKvEntry> getAttributeKvEntries(EntityId entityId, List<String> keys) { |
|
|
|
List<JsonNode> attributes = restTemplate.exchange( |
|
|
|
baseURL + "/api/plugins/telemetry/{entityType}/{entityId}/values/attributes?keys={keys}", |
|
|
|
HttpMethod.GET, |
|
|
|
HttpEntity.EMPTY, |
|
|
|
new ParameterizedTypeReference<DeferredResult<ResponseEntity>>() { |
|
|
|
new ParameterizedTypeReference<List<JsonNode>>() { |
|
|
|
}, |
|
|
|
entityType, |
|
|
|
entityId, |
|
|
|
keys).getBody(); |
|
|
|
entityId.getEntityType().name(), |
|
|
|
entityId.getId(), |
|
|
|
listToString(keys)).getBody(); |
|
|
|
|
|
|
|
return RestJsonConverter.toAttributes(attributes); |
|
|
|
} |
|
|
|
|
|
|
|
public DeferredResult<ResponseEntity> getAttributesByScope(String entityType, String entityId, String scope, String keys) { |
|
|
|
return restTemplate.exchange( |
|
|
|
public Future<List<AttributeKvEntry>> getAttributeKvEntriesAsync(EntityId entityId, List<String> keys) { |
|
|
|
return service.submit(() -> getAttributeKvEntries(entityId, keys)); |
|
|
|
} |
|
|
|
|
|
|
|
public List<AttributeKvEntry> getAttributesByScope(EntityId entityId, String scope, List<String> keys) { |
|
|
|
List<JsonNode> attributes = restTemplate.exchange( |
|
|
|
baseURL + "/api/plugins/telemetry/{entityType}/{entityId}/values/attributes/{scope}?keys={keys}", |
|
|
|
HttpMethod.GET, |
|
|
|
HttpEntity.EMPTY, |
|
|
|
new ParameterizedTypeReference<DeferredResult<ResponseEntity>>() { |
|
|
|
new ParameterizedTypeReference<List<JsonNode>>() { |
|
|
|
}, |
|
|
|
entityType, |
|
|
|
entityId, |
|
|
|
entityId.getEntityType().name(), |
|
|
|
entityId.getId().toString(), |
|
|
|
scope, |
|
|
|
keys).getBody(); |
|
|
|
listToString(keys)).getBody(); |
|
|
|
|
|
|
|
return RestJsonConverter.toAttributes(attributes); |
|
|
|
} |
|
|
|
|
|
|
|
public DeferredResult<ResponseEntity> getTimeseriesKeys(String entityType, String entityId) { |
|
|
|
public List<String> getTimeseriesKeys(EntityId entityId) { |
|
|
|
return restTemplate.exchange( |
|
|
|
baseURL + "/api/plugins/telemetry/{entityType}/{entityId}/keys/timeseries", |
|
|
|
HttpMethod.GET, |
|
|
|
HttpEntity.EMPTY, |
|
|
|
new ParameterizedTypeReference<DeferredResult<ResponseEntity>>() { |
|
|
|
new ParameterizedTypeReference<List<String>>() { |
|
|
|
}, |
|
|
|
entityType, |
|
|
|
entityId).getBody(); |
|
|
|
entityId.getEntityType().name(), |
|
|
|
entityId.getId().toString()).getBody(); |
|
|
|
} |
|
|
|
|
|
|
|
public DeferredResult<ResponseEntity> getLatestTimeseries(String entityType, String entityId, String keys) { |
|
|
|
return restTemplate.exchange( |
|
|
|
public List<TsKvEntry> getLatestTimeseries(EntityId entityId, List<String> keys) { |
|
|
|
Map<String, List<JsonNode>> timeseries = restTemplate.exchange( |
|
|
|
baseURL + "/api/plugins/telemetry/{entityType}/{entityId}/values/timeseries?keys={keys}", |
|
|
|
HttpMethod.GET, |
|
|
|
HttpEntity.EMPTY, |
|
|
|
new ParameterizedTypeReference<DeferredResult<ResponseEntity>>() { |
|
|
|
new ParameterizedTypeReference<Map<String, List<JsonNode>>>() { |
|
|
|
}, |
|
|
|
entityType, |
|
|
|
entityId, |
|
|
|
keys).getBody(); |
|
|
|
entityId.getEntityType().name(), |
|
|
|
entityId.getId().toString(), |
|
|
|
listToString(keys)).getBody(); |
|
|
|
|
|
|
|
return RestJsonConverter.toTimeseries(timeseries); |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
public DeferredResult<ResponseEntity> getTimeseries(String entityType, String entityId, String keys, Long startTs, Long endTs, Long interval, Integer limit, String agg) { |
|
|
|
public List<TsKvEntry> getTimeseries(EntityId entityId, List<String> keys, Long startTs, Long endTs, Long interval, Integer limit, String agg) { |
|
|
|
Map<String, String> params = new HashMap<>(); |
|
|
|
params.put("entityType", entityType); |
|
|
|
params.put("entityId", entityId); |
|
|
|
params.put("keys", keys); |
|
|
|
params.put("entityType", entityId.getEntityType().name()); |
|
|
|
params.put("entityId", entityId.getId().toString()); |
|
|
|
params.put("keys", listToString(keys)); |
|
|
|
params.put("startTs", startTs.toString()); |
|
|
|
params.put("endTs", endTs.toString()); |
|
|
|
params.put("interval", interval == null ? "0" : interval.toString()); |
|
|
|
params.put("limit", limit == null ? "100" : limit.toString()); |
|
|
|
params.put("agg", agg == null ? "NONE" : agg); |
|
|
|
|
|
|
|
return restTemplate.exchange( |
|
|
|
Map<String, List<JsonNode>> timeseries = restTemplate.exchange( |
|
|
|
baseURL + "/api/plugins/telemetry/{entityType}/{entityId}/values/timeseries?keys={keys}&startTs={startTs}&endTs={endTs}&interval={interval}&limit={limit}&agg={agg}", |
|
|
|
HttpMethod.GET, |
|
|
|
HttpEntity.EMPTY, |
|
|
|
new ParameterizedTypeReference<DeferredResult<ResponseEntity>>() { |
|
|
|
new ParameterizedTypeReference<Map<String, List<JsonNode>>>() { |
|
|
|
}, |
|
|
|
params).getBody(); |
|
|
|
|
|
|
|
return RestJsonConverter.toTimeseries(timeseries); |
|
|
|
} |
|
|
|
|
|
|
|
public DeferredResult<ResponseEntity> saveDeviceAttributes(String deviceId, String scope, JsonNode request) { |
|
|
|
return restTemplate.exchange( |
|
|
|
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<DeferredResult<ResponseEntity>>() { |
|
|
|
new ParameterizedTypeReference<List<JsonNode>>() { |
|
|
|
}, |
|
|
|
deviceId, |
|
|
|
scope).getBody(); |
|
|
|
|
|
|
|
return RestJsonConverter.toAttributes(attributes); |
|
|
|
} |
|
|
|
|
|
|
|
public DeferredResult<ResponseEntity> saveEntityAttributesV1(String entityType, String entityId, String scope, JsonNode request) { |
|
|
|
return restTemplate.exchange( |
|
|
|
public List<AttributeKvEntry> saveEntityAttributesV1(EntityId entityId, String scope, JsonNode request) { |
|
|
|
List<JsonNode> attributes = restTemplate.exchange( |
|
|
|
baseURL + "/api/plugins/telemetry/{entityType}/{entityId}/{scope}", |
|
|
|
HttpMethod.POST, |
|
|
|
new HttpEntity<>(request), |
|
|
|
new ParameterizedTypeReference<DeferredResult<ResponseEntity>>() { |
|
|
|
new ParameterizedTypeReference<List<JsonNode>>() { |
|
|
|
}, |
|
|
|
entityType, |
|
|
|
entityId, |
|
|
|
entityId.getEntityType().name(), |
|
|
|
entityId.getId().toString(), |
|
|
|
scope).getBody(); |
|
|
|
|
|
|
|
return RestJsonConverter.toAttributes(attributes); |
|
|
|
} |
|
|
|
|
|
|
|
public DeferredResult<ResponseEntity> saveEntityAttributesV2(String entityType, String entityId, String scope, JsonNode request) { |
|
|
|
return restTemplate.exchange( |
|
|
|
public List<AttributeKvEntry> saveEntityAttributesV2(EntityId entityId, String scope, JsonNode request) { |
|
|
|
List<JsonNode> attributes = restTemplate.exchange( |
|
|
|
baseURL + "/api/plugins/telemetry/{entityType}/{entityId}/attributes/{scope}", |
|
|
|
HttpMethod.POST, |
|
|
|
new HttpEntity<>(request), |
|
|
|
new ParameterizedTypeReference<DeferredResult<ResponseEntity>>() { |
|
|
|
new ParameterizedTypeReference<List<JsonNode>>() { |
|
|
|
}, |
|
|
|
entityType, |
|
|
|
entityId, |
|
|
|
entityId.getEntityType().name(), |
|
|
|
entityId.getId().toString(), |
|
|
|
scope).getBody(); |
|
|
|
|
|
|
|
return RestJsonConverter.toAttributes(attributes); |
|
|
|
} |
|
|
|
|
|
|
|
public DeferredResult<ResponseEntity> saveEntityTelemetry(String entityType, String entityId, String scope, String requestBody) { |
|
|
|
return restTemplate.exchange( |
|
|
|
public List<TsKvEntry> saveEntityTelemetry(EntityId entityId, String scope, String requestBody) { |
|
|
|
Map<String, List<JsonNode>> timeseries = restTemplate.exchange( |
|
|
|
baseURL + "/api/plugins/telemetry/{entityType}/{entityId}/timeseries/{scope}", |
|
|
|
HttpMethod.POST, |
|
|
|
new HttpEntity<>(requestBody), |
|
|
|
new ParameterizedTypeReference<DeferredResult<ResponseEntity>>() { |
|
|
|
new ParameterizedTypeReference<Map<String, List<JsonNode>>>() { |
|
|
|
}, |
|
|
|
entityType, |
|
|
|
entityId, |
|
|
|
entityId.getEntityType().name(), |
|
|
|
entityId.getId().toString(), |
|
|
|
scope).getBody(); |
|
|
|
|
|
|
|
return RestJsonConverter.toTimeseries(timeseries); |
|
|
|
} |
|
|
|
|
|
|
|
public DeferredResult<ResponseEntity> saveEntityTelemetryWithTTL(String entityType, String entityId, String scope, Long ttl, String requestBody) { |
|
|
|
return restTemplate.exchange( |
|
|
|
public List<TsKvEntry> saveEntityTelemetryWithTTL(EntityId entityId, String scope, Long ttl, String requestBody) { |
|
|
|
Map<String, List<JsonNode>> timeseries = restTemplate.exchange( |
|
|
|
baseURL + "/api/plugins/telemetry/{entityType}/{entityId}/timeseries/{scope}/{ttl}", |
|
|
|
HttpMethod.POST, |
|
|
|
new HttpEntity<>(requestBody), |
|
|
|
new ParameterizedTypeReference<DeferredResult<ResponseEntity>>() { |
|
|
|
new ParameterizedTypeReference<Map<String, List<JsonNode>>>() { |
|
|
|
}, |
|
|
|
entityType, |
|
|
|
entityId, |
|
|
|
entityId.getEntityType().name(), |
|
|
|
entityId.getId().toString(), |
|
|
|
scope, |
|
|
|
ttl).getBody(); |
|
|
|
|
|
|
|
return RestJsonConverter.toTimeseries(timeseries); |
|
|
|
} |
|
|
|
|
|
|
|
public DeferredResult<ResponseEntity> deleteEntityTimeseries(String entityType, |
|
|
|
String entityId, |
|
|
|
String keys, |
|
|
|
boolean deleteAllDataForKeys, |
|
|
|
Long startTs, |
|
|
|
Long endTs, |
|
|
|
boolean rewriteLatestIfDeleted) { |
|
|
|
public List<TsKvEntry> deleteEntityTimeseries(EntityId entityId, |
|
|
|
List<String> keys, |
|
|
|
boolean deleteAllDataForKeys, |
|
|
|
Long startTs, |
|
|
|
Long endTs, |
|
|
|
boolean rewriteLatestIfDeleted) { |
|
|
|
Map<String, String> params = new HashMap<>(); |
|
|
|
params.put("entityType", entityType); |
|
|
|
params.put("entityId", entityId); |
|
|
|
params.put("keys", keys); |
|
|
|
params.put("entityType", entityId.getEntityType().name()); |
|
|
|
params.put("entityId", entityId.getId().toString()); |
|
|
|
params.put("keys", listToString(keys)); |
|
|
|
params.put("deleteAllDataForKeys", String.valueOf(deleteAllDataForKeys)); |
|
|
|
params.put("startTs", startTs.toString()); |
|
|
|
params.put("endTs", endTs.toString()); |
|
|
|
params.put("rewriteLatestIfDeleted", String.valueOf(rewriteLatestIfDeleted)); |
|
|
|
|
|
|
|
return restTemplate.exchange( |
|
|
|
Map<String, List<JsonNode>> 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<DeferredResult<ResponseEntity>>() { |
|
|
|
new ParameterizedTypeReference<Map<String, List<JsonNode>>>() { |
|
|
|
}, |
|
|
|
params).getBody(); |
|
|
|
|
|
|
|
return RestJsonConverter.toTimeseries(timeseries); |
|
|
|
} |
|
|
|
|
|
|
|
public DeferredResult<ResponseEntity> deleteEntityAttributes(String deviceId, String scope, String keys) { |
|
|
|
return restTemplate.exchange( |
|
|
|
public List<AttributeKvEntry> deleteEntityAttributes(String deviceId, String scope, List<String> keys) { |
|
|
|
List<JsonNode> attributes = restTemplate.exchange( |
|
|
|
baseURL + "/api/plugins/telemetry/{deviceId}/{scope}?keys={keys}", |
|
|
|
HttpMethod.DELETE, |
|
|
|
HttpEntity.EMPTY, |
|
|
|
new ParameterizedTypeReference<DeferredResult<ResponseEntity>>() { |
|
|
|
new ParameterizedTypeReference<List<JsonNode>>() { |
|
|
|
}, |
|
|
|
deviceId, |
|
|
|
scope, |
|
|
|
keys).getBody(); |
|
|
|
listToString(keys)).getBody(); |
|
|
|
|
|
|
|
return RestJsonConverter.toAttributes(attributes); |
|
|
|
} |
|
|
|
|
|
|
|
public DeferredResult<ResponseEntity> deleteEntityAttributes(String entityType, String entityId, String scope, String keys) { |
|
|
|
return restTemplate.exchange( |
|
|
|
public List<AttributeKvEntry> deleteEntityAttributes(EntityId entityId, String scope, List<String> keys) { |
|
|
|
List<JsonNode> attributes = restTemplate.exchange( |
|
|
|
baseURL + "/api/plugins/telemetry/{entityType}/{entityId}/{scope}?keys={keys}", |
|
|
|
HttpMethod.DELETE, |
|
|
|
HttpEntity.EMPTY, |
|
|
|
new ParameterizedTypeReference<DeferredResult<ResponseEntity>>() { |
|
|
|
new ParameterizedTypeReference<List<JsonNode>>() { |
|
|
|
}, |
|
|
|
entityType, |
|
|
|
entityId, |
|
|
|
entityId.getEntityType().name(), |
|
|
|
entityId.getId().toString(), |
|
|
|
scope, |
|
|
|
keys).getBody(); |
|
|
|
listToString(keys)).getBody(); |
|
|
|
|
|
|
|
return RestJsonConverter.toAttributes(attributes); |
|
|
|
} |
|
|
|
|
|
|
|
public Optional<Tenant> getTenantById(String tenantId) { |
|
|
|
@ -1860,7 +1883,7 @@ public class RestClient implements ClientHttpRequestInterceptor { |
|
|
|
} |
|
|
|
|
|
|
|
public void sendActivationEmail(String email) { |
|
|
|
restTemplate.postForEntity(baseURL + "/api/user/sendActivationMail?email={email}", null, Object.class, email); |
|
|
|
restTemplate.postForLocation(baseURL + "/api/user/sendActivationMail?email={email}", null, email); |
|
|
|
} |
|
|
|
|
|
|
|
public String getActivationLink(String userId) { |
|
|
|
@ -1900,10 +1923,9 @@ public class RestClient implements ClientHttpRequestInterceptor { |
|
|
|
} |
|
|
|
|
|
|
|
public void setUserCredentialsEnabled(String userId, boolean userCredentialsEnabled) { |
|
|
|
restTemplate.postForEntity( |
|
|
|
restTemplate.postForLocation( |
|
|
|
baseURL + "/api/user/{userId}/userCredentialsEnabled?serCredentialsEnabled={serCredentialsEnabled}", |
|
|
|
null, |
|
|
|
Object.class, |
|
|
|
userId, |
|
|
|
userCredentialsEnabled); |
|
|
|
} |
|
|
|
@ -2030,4 +2052,15 @@ public class RestClient implements ClientHttpRequestInterceptor { |
|
|
|
params.put("textOffset", pageLink.getTextOffset()); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
private String listToString(List<String> list) { |
|
|
|
return String.join(",", list); |
|
|
|
} |
|
|
|
|
|
|
|
@Override |
|
|
|
public void close() { |
|
|
|
if (service != null) { |
|
|
|
service.shutdown(); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|