diff --git a/application/src/main/java/org/thingsboard/server/controller/DeviceController.java b/application/src/main/java/org/thingsboard/server/controller/DeviceController.java
index ff06ce7..5743321 100644
--- a/application/src/main/java/org/thingsboard/server/controller/DeviceController.java
+++ b/application/src/main/java/org/thingsboard/server/controller/DeviceController.java
@@ -156,6 +156,19 @@ public class DeviceController extends BaseController {
}
}
+ @PreAuthorize("hasAuthority('TENANT_ADMIN')")
+ @RequestMapping(value = "/tenant/devices", params = {"deviceName"}, method = RequestMethod.GET)
+ @ResponseBody
+ public Device getTenantDevice(
+ @RequestParam String deviceName) throws ThingsboardException {
+ try {
+ TenantId tenantId = getCurrentUser().getTenantId();
+ return checkNotNull(deviceService.findDeviceByTenantIdAndName(tenantId, deviceName));
+ } catch (Exception e) {
+ throw handleException(e);
+ }
+ }
+
@PreAuthorize("hasAnyAuthority('TENANT_ADMIN', 'CUSTOMER_USER')")
@RequestMapping(value = "/customer/{customerId}/devices", params = {"limit"}, method = RequestMethod.GET)
@ResponseBody
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 e3e1793..f742e61 100644
--- a/tools/src/main/java/org/thingsboard/client/tools/RestClient.java
+++ b/tools/src/main/java/org/thingsboard/client/tools/RestClient.java
@@ -18,11 +18,13 @@ package org.thingsboard.client.tools;
import com.fasterxml.jackson.databind.JsonNode;
import lombok.RequiredArgsConstructor;
import org.springframework.http.HttpRequest;
+import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.http.client.ClientHttpRequestExecution;
import org.springframework.http.client.ClientHttpRequestInterceptor;
import org.springframework.http.client.ClientHttpResponse;
import org.springframework.http.client.support.HttpRequestWrapper;
+import org.springframework.web.client.HttpClientErrorException;
import org.springframework.web.client.RestTemplate;
import org.thingsboard.server.common.data.Device;
import org.thingsboard.server.common.data.id.DeviceId;
@@ -32,6 +34,7 @@ import java.io.IOException;
import java.util.Collections;
import java.util.HashMap;
import java.util.Map;
+import java.util.Optional;
/**
* @author Andrew Shvayka
@@ -52,6 +55,21 @@ public class RestClient implements ClientHttpRequestInterceptor {
restTemplate.setInterceptors(Collections.singletonList(this));
}
+ public Optional<Device> findDevice(String name) {
+ Map<String, String> params = new HashMap<String, String>();
+ params.put("deviceName", name);
+ try {
+ ResponseEntity<Device> deviceEntity = restTemplate.getForEntity(baseURL + "/api/tenant/devices?deviceName={deviceName}", Device.class, params);
+ return Optional.of(deviceEntity.getBody());
+ } catch (HttpClientErrorException exception) {
+ if (exception.getStatusCode() == HttpStatus.NOT_FOUND) {
+ return Optional.empty();
+ } else {
+ throw exception;
+ }
+ }
+ }
+
public Device createDevice(String name) {
Device device = new Device();
device.setName(name);